diff --git a/eos/db/saveddata/fit.py b/eos/db/saveddata/fit.py index 9701d5d6b..7e3c76f5f 100644 --- a/eos/db/saveddata/fit.py +++ b/eos/db/saveddata/fit.py @@ -132,7 +132,7 @@ class CommandFit(object): ) -es_Fit._Fit__projectedFits = association_proxy( +es_Fit.projectedFitDict = association_proxy( "victimOf", # look at the victimOf association... "source_fit", # .. and return the source fits creator=lambda sourceID, source_fit: ProjectedFit(sourceID, source_fit) diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 56c4df1a2..ad4a48ebf 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -257,7 +257,7 @@ class Fit(object): def projectedFits(self): # only in extreme edge cases will the fit be invalid, but to be sure do # not return them. - return [fit for fit in list(self.__projectedFits.values()) if not fit.isInvalid] + return [fit for fit in list(self.projectedFitDict.values()) if not fit.isInvalid] @property def commandFits(self): @@ -1615,7 +1615,7 @@ class Fit(object): forceUpdateSavedata(fit) for fit in self.projectedFits: - copy_ship.__projectedFits[fit.ID] = fit + copy_ship.projectedFitDict[fit.ID] = fit forceUpdateSavedata(fit) copyProjectionInfo = fit.getProjectionInfo(copy_ship.ID) originalProjectionInfo = fit.getProjectionInfo(self.ID) diff --git a/gui/fitCommands/calc/fitAddProjectedEnv.py b/gui/fitCommands/calc/fitAddProjectedEnv.py new file mode 100644 index 000000000..974f8efa5 --- /dev/null +++ b/gui/fitCommands/calc/fitAddProjectedEnv.py @@ -0,0 +1,59 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from eos.saveddata.module import Module +from eos.saveddata.drone import Drone +from eos.saveddata.fighter import Fighter +from .fitRemoveProjectedModule import FitRemoveProjectedModuleCommand +pyfalog = Logger(__name__) + + +class FitAddProjectedEnvCommand(wx.Command): + """" + from sFit.project + """ + def __init__(self, fitID, itemID): + wx.Command.__init__(self, True) + self.fitID = fitID + self.itemID = itemID + self.new_index = None + self.old_item = None + + def Do(self): + pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.itemID) + fit = eos.db.getFit(self.fitID) + item = eos.db.getItem(self.itemID, eager=("attributes", "group.category")) + + try: + module = Module(item) + except ValueError: + return False + + # todo: thing to check for existing environmental effects + + self.old_item = fit.projectedModules.makeRoom(module) + + module.state = State.ONLINE + fit.projectedModules.append(module) + + eos.db.commit() + self.new_index = fit.projectedModules.index(module) + return True + + def Undo(self): + if self.old_item: + # If we had an item in the slot previously, add it back. + cmd = FitAddProjectedEnvCommand(self.fitID, self.old_item) + cmd.Do() + return True + from gui.fitCommands.calc.fitRemoveProjectedEnv import FitRemoveProjectedEnvCommand # avoids circular import + cmd = FitRemoveProjectedEnvCommand(self.fitID, self.itemID) + cmd.Do() + + return True diff --git a/gui/fitCommands/calc/fitAddProjectedFit.py b/gui/fitCommands/calc/fitAddProjectedFit.py new file mode 100644 index 000000000..70fdece0a --- /dev/null +++ b/gui/fitCommands/calc/fitAddProjectedFit.py @@ -0,0 +1,49 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from eos.saveddata.module import Module +from eos.saveddata.drone import Drone +from eos.saveddata.fighter import Fighter +from .fitRemoveProjectedModule import FitRemoveProjectedModuleCommand +pyfalog = Logger(__name__) + + +class FitAddProjectedFitCommand(wx.Command): + """" + from sFit.project + """ + def __init__(self, fitID, projectedFitID): + wx.Command.__init__(self, True) + self.fitID = fitID + self.projectedFitID = projectedFitID + self.new_index = None + self.old_item = None + + def Do(self): + pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.projectedFitID) + fit = eos.db.getFit(self.fitID) + projectedFit = eos.db.getFit(self.projectedFitID) + + if projectedFit is None or projectedFit in fit.projectedFits: + return False + + fit.projectedFitDict[projectedFit.ID] = projectedFit + + # this bit is required -- see GH issue # 83 + eos.db.saveddata_session.flush() + eos.db.saveddata_session.refresh(projectedFit) + + eos.db.commit() + return True + + def Undo(self): + from gui.fitCommands.calc.fitRemoveProjectedFit import FitRemoveProjectedFitCommand # avoids circular import + cmd = FitRemoveProjectedFitCommand(self.fitID, self.projectedFitID) + cmd.Do() + return True diff --git a/gui/fitCommands/calc/fitRemoveProjectedEnv.py b/gui/fitCommands/calc/fitRemoveProjectedEnv.py new file mode 100644 index 000000000..b53f40ab0 --- /dev/null +++ b/gui/fitCommands/calc/fitRemoveProjectedEnv.py @@ -0,0 +1,44 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from eos.saveddata.module import Module +from eos.saveddata.drone import Drone +from eos.saveddata.fighter import Fighter +from .fitRemoveProjectedModule import FitRemoveProjectedModuleCommand +pyfalog = Logger(__name__) + + +# this has the same exact definition that regular rpojected modules, besides the undo +class FitRemoveProjectedEnvCommand(FitRemoveProjectedModuleCommand): + """" + from sFit.project + """ + + def __init__(self, fitID, itemID): + wx.Command.__init__(self, True) + self.fitID = fitID + self.itemID = itemID + self.removed_item = None + + def Do(self): + pyfalog.debug("Removing ({0}) onto: {1}", self.fitID, self.itemID) + fit = eos.db.getFit(self.fitID) + + item = next((x for x in fit.projectedModules if x.itemID == self.itemID), None) + self.removed_item = item.itemID + fit.projectedModules.remove(item) + + eos.db.commit() + return True + + def Undo(self): + from gui.fitCommands.calc.fitAddProjectedEnv import FitAddProjectedEnvCommand + cmd = FitAddProjectedEnvCommand(self.fitID, self.removed_item) + cmd.Do() + return True diff --git a/gui/fitCommands/calc/fitRemoveProjectedFit.py b/gui/fitCommands/calc/fitRemoveProjectedFit.py new file mode 100644 index 000000000..829c7d3ea --- /dev/null +++ b/gui/fitCommands/calc/fitRemoveProjectedFit.py @@ -0,0 +1,46 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from eos.saveddata.module import Module +from eos.saveddata.drone import Drone +from eos.saveddata.fighter import Fighter +from .fitRemoveProjectedModule import FitRemoveProjectedModuleCommand +pyfalog = Logger(__name__) + + +# this has the same exact definition that regular rpojected modules, besides the undo +class FitRemoveProjectedFitCommand(FitRemoveProjectedModuleCommand): + """" + from sFit.project + """ + + def __init__(self, fitID, projectedFitID): + wx.Command.__init__(self, True) + self.fitID = fitID + self.projectedFitID = projectedFitID + + def Do(self): + pyfalog.debug("Removing ({0}) onto: {1}", self.fitID, self.projectedFitID) + fit = eos.db.getFit(self.fitID) + projectedFit = eos.db.getFit(self.projectedFitID) + + if projectedFit is None: + return False + + del fit.projectedFitDict[projectedFit.ID] + + eos.db.commit() + return True + + def Undo(self): + # todo: figure out if I need to return false here if the fit doesn't return true (means it was deleted) + from gui.fitCommands.calc.fitAddProjectedFit import FitAddProjectedFitCommand + cmd = FitAddProjectedFitCommand(self.fitID, self.projectedFitID) + cmd.Do() + return True diff --git a/gui/fitCommands/guiAddProjected.py b/gui/fitCommands/guiAddProjected.py index cc556f32c..ac6c65c23 100644 --- a/gui/fitCommands/guiAddProjected.py +++ b/gui/fitCommands/guiAddProjected.py @@ -6,6 +6,7 @@ from gui import globalEvents as GE from eos.saveddata.module import Module from .calc.fitAddProjectedModule import FitAddProjectedModuleCommand from .calc.fitAddProjectedEnv import FitAddProjectedEnvCommand +from .calc.fitAddProjectedFit import FitAddProjectedFitCommand from logbook import Logger import eos.db pyfalog = Logger(__name__) @@ -52,7 +53,7 @@ class GuiAddProjectedCommand(wx.Command): # attempt a regular module projection result = self.internal_history.Submit(FitAddProjectedModuleCommand(self.fitID, self.id)) elif self.type == 'fit': - pyfalog.warn("FIT PROJECTION NOT IMPLEMENTED") + result = self.internal_history.Submit(FitAddProjectedFitCommand(self.fitID, self.id)) if result: self.sFit.recalc(self.fitID) diff --git a/gui/fitCommands/guiRemoveProjected.py b/gui/fitCommands/guiRemoveProjected.py new file mode 100644 index 000000000..f3b36478c --- /dev/null +++ b/gui/fitCommands/guiRemoveProjected.py @@ -0,0 +1,82 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +from eos.saveddata.module import Module +from .calc.fitRemoveProjectedModule import FitRemoveProjectedModuleCommand +from .calc.fitRemoveProjectedEnv import FitRemoveProjectedEnvCommand +from .calc.fitRemoveProjectedFit import FitRemoveProjectedFitCommand +from logbook import Logger +import eos.db +pyfalog = Logger(__name__) + +from eos.saveddata.drone import Drone +from eos.saveddata.module import Module +from eos.saveddata.fighter import Fighter + + +class GuiRemoveProjectedCommand(wx.Command): + def __init__(self, fitID, thing): + wx.Command.__init__(self, True, "Projected Add") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.internal_history = wx.CommandProcessor() + self.fitID = fitID + fit = self.sFit.getFit(fitID) + + if isinstance(thing, Drone): + self.data = fit.projectedDrones.index(thing) + self.type = 'drone' + elif isinstance(thing, Module): + # todo: projected stuff should be wrapped in a projected class wrapper for easier maintainence + if thing.item.group.name in Module.SYSTEM_GROUPS: + self.type = 'env' + self.data = thing.itemID + else: + self.type = 'module' + self.data = fit.projectedModules.index(thing) + elif isinstance(thing, Fighter): + self.data = fit.projectedFighters.index(thing) + self.type = 'fighter' + else: + # todo: fix! + self.data = thing.ID + self.type = 'fit' + + def Do(self): + result = False + # since we can project various types, we need to switch of the fit command. We can't do this switch easily in + # the fit command since each type might have a different kind of undo, easier to split it out + if self.type == 'module': + result = self.internal_history.Submit(FitRemoveProjectedModuleCommand(self.fitID, self.data)) + elif self.type == 'env': + result = self.internal_history.Submit(FitRemoveProjectedEnvCommand(self.fitID, self.data)) + elif self.type == 'fit': + result = self.internal_history.Submit(FitRemoveProjectedFitCommand(self.fitID, self.data)) + + # if item.category.name == "Drone": + # pyfalog.warn("DRONE REMOVE PROJECTION NOT IMPLEMENTED") + # elif item.category.name == "Fighter": + # pyfalog.warn("FIGHTER REMOVE PROJECTION NOT IMPLEMENTED") + # elif item.group.name in Module.SYSTEM_GROUPS: + # result = self.internal_history.Submit(FitRemoveProjectedEnvCommand(self.fitID, self.id)) + # else: + # # attempt a regular module projection + # + # elif self.type == 'fit': + # pyfalog.warn("FIT REMOVE PROJECTION NOT IMPLEMENTED") + + if result: + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + for _ in self.internal_history.Commands: + self.internal_history.Undo() + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + diff --git a/service/fit.py b/service/fit.py index d1fab9dbe..c19513dd0 100644 --- a/service/fit.py +++ b/service/fit.py @@ -416,7 +416,7 @@ class Fit(object): if thing in fit.projectedFits: return - fit.__projectedFits[thing.ID] = thing + fit.projectedFitDict[thing.ID] = thing # this bit is required -- see GH issue # 83 eos.db.saveddata_session.flush() @@ -539,7 +539,7 @@ class Fit(object): elif isinstance(thing, es_Fighter): fit.projectedFighters.remove(thing) else: - del fit.__projectedFits[thing.ID] + del fit.projectedFitDict[thing.ID] # fit.projectedFits.remove(thing) eos.db.commit()