diff --git a/eos/db/saveddata/fit.py b/eos/db/saveddata/fit.py index 0c5edaee9..3b5fc0e3e 100644 --- a/eos/db/saveddata/fit.py +++ b/eos/db/saveddata/fit.py @@ -17,9 +17,10 @@ # along with eos. If not, see . #=============================================================================== -from sqlalchemy import Table, Column, Integer, ForeignKey, String, Boolean -from sqlalchemy.orm import relation, mapper +from sqlalchemy import * +from sqlalchemy.orm import * from sqlalchemy.sql import and_ +from sqlalchemy.ext.associationproxy import association_proxy from eos.db import saveddata_meta from eos.db.saveddata.module import modules_table @@ -46,32 +47,94 @@ projectedFits_table = Table("projectedFits", saveddata_meta, Column("sourceID", ForeignKey("fits.ID"), primary_key = True), Column("victimID", ForeignKey("fits.ID"), primary_key = True), Column("amount", Integer)) + +class ProjectedFit(object): + def __init__(self, source_item, dest_item, enabled): + print "init projected item", source_item, dest_item, enabled + self.source_item = source_item + self.dest_item = dest_item + self.amount = enabled + + @reconstructor + def init(self): + print "db init" + print "\t source:",self.source_item + print "\t dest:", self.dest_item + self.dest_item.projectionInfo = self + +Fit._Fit__projectedFits = association_proxy( + "projected_items", + "dest_item", + creator=lambda dest_item: ProjectedFit(None, dest_item, True) +) + mapper(Fit, fits_table, - properties = {"_Fit__modules" : relation(Module, collection_class = HandledModuleList, - primaryjoin = and_(modules_table.c.fitID == fits_table.c.ID, modules_table.c.projected == False), - order_by = modules_table.c.position, cascade='all, delete, delete-orphan'), - "_Fit__projectedModules" : relation(Module, collection_class = HandledProjectedModList, cascade='all, delete, delete-orphan', single_parent=True, - primaryjoin = and_(modules_table.c.fitID == fits_table.c.ID, modules_table.c.projected == True)), - "owner" : relation(User, backref = "fits"), - "itemID" : fits_table.c.shipID, - "shipID" : fits_table.c.shipID, - "_Fit__boosters" : relation(Booster, collection_class = HandledImplantBoosterList, cascade='all, delete, delete-orphan', single_parent=True), - "_Fit__drones" : relation(Drone, collection_class = HandledDroneCargoList, cascade='all, delete, delete-orphan', single_parent=True, - primaryjoin = and_(drones_table.c.fitID == fits_table.c.ID, drones_table.c.projected == False)), - "_Fit__cargo" : relation(Cargo, collection_class = HandledDroneCargoList, cascade='all, delete, delete-orphan', single_parent=True, - primaryjoin = and_(cargo_table.c.fitID == fits_table.c.ID)), - "_Fit__projectedDrones" : relation(Drone, collection_class = HandledProjectedDroneList, cascade='all, delete, delete-orphan', single_parent=True, - primaryjoin = and_(drones_table.c.fitID == fits_table.c.ID, drones_table.c.projected == True)), - "_Fit__implants" : relation(Implant, collection_class = HandledImplantBoosterList, cascade='all, delete, delete-orphan', backref='fit', single_parent=True, - primaryjoin = fitImplants_table.c.fitID == fits_table.c.ID, - secondaryjoin = fitImplants_table.c.implantID == Implant.ID, - secondary = fitImplants_table), - "_Fit__character" : relation(Character, backref = "fits"), - "_Fit__damagePattern" : relation(DamagePattern), - "_Fit__targetResists" : relation(TargetResists), - "_Fit__projectedFits" : relation(Fit, - primaryjoin = projectedFits_table.c.victimID == fits_table.c.ID, - secondaryjoin = fits_table.c.ID == projectedFits_table.c.sourceID, - secondary = projectedFits_table, - collection_class = HandledProjectedFitList) - }) + properties = { + "_Fit__modules": relation( + Module, + collection_class=HandledModuleList, + primaryjoin=and_(modules_table.c.fitID == fits_table.c.ID, modules_table.c.projected == False), + order_by=modules_table.c.position, + cascade='all, delete, delete-orphan'), + "_Fit__projectedModules": relation( + Module, + collection_class=HandledProjectedModList, + cascade='all, delete, delete-orphan', + single_parent=True, + primaryjoin=and_(modules_table.c.fitID == fits_table.c.ID, modules_table.c.projected == True)), + "owner": relation( + User, + backref="fits"), + "itemID": fits_table.c.shipID, + "shipID": fits_table.c.shipID, + "_Fit__boosters": relation( + Booster, + collection_class=HandledImplantBoosterList, + cascade='all, delete, delete-orphan', + single_parent=True), + "_Fit__drones": relation( + Drone, + collection_class=HandledDroneCargoList, + cascade='all, delete, delete-orphan', + single_parent=True, + primaryjoin=and_(drones_table.c.fitID == fits_table.c.ID, drones_table.c.projected == False)), + "_Fit__cargo": relation( + Cargo, + collection_class=HandledDroneCargoList, + cascade='all, delete, delete-orphan', + single_parent=True, + primaryjoin=and_(cargo_table.c.fitID == fits_table.c.ID)), + "_Fit__projectedDrones": relation( + Drone, + collection_class=HandledProjectedDroneList, + cascade='all, delete, delete-orphan', + single_parent=True, + primaryjoin=and_(drones_table.c.fitID == fits_table.c.ID, drones_table.c.projected == True)), + "_Fit__implants": relation( + Implant, + collection_class=HandledImplantBoosterList, + cascade='all, delete, delete-orphan', + backref='fit', + single_parent=True, + primaryjoin=fitImplants_table.c.fitID == fits_table.c.ID, + secondaryjoin=fitImplants_table.c.implantID == Implant.ID, + secondary=fitImplants_table), + "_Fit__character": relation( + Character, + backref="fits"), + "_Fit__damagePattern": relation(DamagePattern), + "_Fit__targetResists": relation(TargetResists), + "dest_items": relationship( + ProjectedFit, + primaryjoin=projectedFits_table.c.victimID == fits_table.c.ID, + backref='dest_item', + cascade='all, delete, delete-orphan'), + "projected_items": relationship( + ProjectedFit, + primaryjoin=fits_table.c.ID == projectedFits_table.c.sourceID, + backref='source_item', + cascade='all, delete, delete-orphan'), + } +) + +mapper(ProjectedFit, projectedFits_table) diff --git a/eos/effectHandlerHelpers.py b/eos/effectHandlerHelpers.py index c658cf0a9..fee65fad0 100644 --- a/eos/effectHandlerHelpers.py +++ b/eos/effectHandlerHelpers.py @@ -228,8 +228,10 @@ class HandledProjectedDroneList(HandledDroneCargoList): if proj.isInvalid or not proj.item.isType("projected"): self.remove(proj) +# @todo: remove this once we are sure we no longer need it class HandledProjectedFitList(HandledList): def append(self, proj): + print "apppending projected fit", proj proj.projected = True list.append(self, proj) diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 5c03d6a2a..12d9b4cd8 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -452,7 +452,8 @@ class Fit(object): item.calculateModifiedAttributes(targetFit, runTime, True) for fit in self.projectedFits: - fit.calculateModifiedAttributes(self, withBoosters=withBoosters, dirtyStorage=dirtyStorage) + if fit.projectionInfo.amount: + fit.calculateModifiedAttributes(self, withBoosters=withBoosters, dirtyStorage=dirtyStorage) def fill(self): """ diff --git a/service/fit.py b/service/fit.py index f20d9183a..9ce47ad62 100644 --- a/service/fit.py +++ b/service/fit.py @@ -363,6 +363,9 @@ class Fit(object): thing.state = self.__getProposedState(thing, click) if not thing.canHaveState(thing.state, fit): thing.state = State.OFFLINE + elif isinstance(thing, eos.types.Fit): + print "toggle fit" + thing.projectionInfo.amount = not thing.projectionInfo.amount eos.db.commit() self.recalc(fit)