Make projected states undo'able

This commit is contained in:
DarkPhoenix
2019-04-10 15:44:03 +03:00
parent fbb192404f
commit dca2db5a6d
15 changed files with 205 additions and 51 deletions

View File

@@ -110,13 +110,8 @@ class ProjectedView(d.Display):
# Gather module information to get position
module = fit.modules[int(data[1])]
self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, module.itemID, 'item'))
# sFit.project(fit.ID, module)
# wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID))
elif data[0] == "market":
# sFit = Fit.getInstance()
self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, int(data[1]), 'item'))
# sFit.project(fit.ID, int(data[1]))
# wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID))
def kbEvent(self, event):
keycode = event.GetKeyCode()
@@ -262,10 +257,10 @@ class ProjectedView(d.Display):
item = self.get(row)
col = self.getColumn(event.Position)
if col == self.getColIndex(State):
fitID = self.mainFrame.getActiveFit()
sFit = Fit.getInstance()
sFit.toggleProjected(fitID, item, "right" if event.Button == 3 else "left")
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
self.mainFrame.command.Submit(cmd.GuiToggleProjectedCommand(
fitID=self.mainFrame.getActiveFit(),
thing=item,
click="right" if event.Button == 3 else "left"))
def spawnMenu(self, event):
fitID = self.mainFrame.getActiveFit()

View File

@@ -39,3 +39,4 @@ from .guiSetSpoolup import GuiSetSpoolup
from .guiRebaseItems import GuiRebaseItemsCommand
from .guiMutaConvert import GuiMutaConvertCommand
from .guiMutaRevert import GuiMutaRevertCommand
from .guiToggleProjected import GuiToggleProjectedCommand

View File

@@ -34,6 +34,7 @@ class FitAddProjectedDroneCommand(wx.Command):
self.index = fit.projectedDrones.index(drone)
drone.amount += 1
drone.amountActive = drone.amount
eos.db.commit()
return True

View File

@@ -9,7 +9,7 @@ class FitToggleBoosterCommand(wx.Command):
from sFit.toggleBooster
"""
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Cargo add")
wx.Command.__init__(self, True, "Toggle Booster")
self.fitID = fitID
self.position = position

View File

@@ -9,7 +9,7 @@ class FitToggleCommandCommand(wx.Command):
from sFit.toggleCommandFit
"""
def __init__(self, fitID, commandFitId):
wx.Command.__init__(self, True, "Cargo add")
wx.Command.__init__(self, True, "Toggle Command")
self.fitID = fitID
self.commandFitID = commandFitId

View File

@@ -9,7 +9,7 @@ class FitToggleDroneCommand(wx.Command):
from sFit.toggleDrone
"""
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Cargo add")
wx.Command.__init__(self, True, "Toggle Drone")
self.fitID = fitID
self.position = position

View File

@@ -9,7 +9,7 @@ class FitToggleFighterCommand(wx.Command):
from sFit.toggleFighter
"""
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Cargo add")
wx.Command.__init__(self, True, "Toggle Fighter")
self.fitID = fitID
self.position = position

View File

@@ -1,6 +1,9 @@
import wx
import eos.db
from logbook import Logger
import eos.db
pyfalog = Logger(__name__)
@@ -9,7 +12,7 @@ class FitToggleImplantCommand(wx.Command):
from sFit.toggleImplant
"""
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Cargo add")
wx.Command.__init__(self, True, "Toggle Implant")
self.fitID = fitID
self.position = position

View File

@@ -0,0 +1,35 @@
import wx
from logbook import Logger
import eos.db
from service.fit import Fit
pyfalog = Logger(__name__)
class FitToggleProjectedDroneCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Toggle Projected Drone")
self.fitID = fitID
self.position = position
def Do(self):
pyfalog.debug("Toggling projected drone for fit ID: {}".format(self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
drone = fit.projectedDrones[self.position]
if drone.amountActive == 0:
if not drone.canBeApplied(fit):
return False
drone.amountActive = drone.amount
else:
drone.amountActive = 0
eos.db.commit()
return True
def Undo(self):
cmd = FitToggleProjectedDroneCommand(self.fitID, self.position)
return cmd.Do()

View File

@@ -0,0 +1,29 @@
import wx
from logbook import Logger
import eos.db
from service.fit import Fit
pyfalog = Logger(__name__)
class FitToggleProjectedFighterCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Toggle Projected Fighter")
self.fitID = fitID
self.position = position
def Do(self):
pyfalog.debug("Toggling projected fighter for fit ID: {}".format(self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
fighter = fit.projectedFighters[self.position]
fighter.active = not fighter.active
eos.db.commit()
return True
def Undo(self):
cmd = FitToggleProjectedFighterCommand(self.fitID, self.position)
return cmd.Do()

View File

@@ -0,0 +1,31 @@
import wx
from logbook import Logger
import eos.db
from service.fit import Fit
pyfalog = Logger(__name__)
class FitToggleProjectedFitCommand(wx.Command):
def __init__(self, fitID, projectingFitID):
wx.Command.__init__(self, True, "Toggle Projected Fit")
self.fitID = fitID
self.projectingFitID = projectingFitID
def Do(self):
pyfalog.debug("Toggling projected fit {} for fit ID: {}".format(self.projectingFitID, self.fitID))
projector = Fit.getInstance().getFit(self.projectingFitID)
projectionInfo = projector.getProjectionInfo(self.fitID)
if not projectionInfo:
return False
projectionInfo.active = not projectionInfo.active
eos.db.commit()
return True
def Undo(self):
cmd = FitToggleProjectedFitCommand(self.fitID, self.projectingFitID)
return cmd.Do()

View File

@@ -0,0 +1,42 @@
import wx
from logbook import Logger
import eos.db
from service.fit import Fit
pyfalog = Logger(__name__)
class FitToggleProjectedModuleCommand(wx.Command):
def __init__(self, fitID, position, click):
wx.Command.__init__(self, True, "Toggle Projected Module")
self.fitID = fitID
self.position = position
self.click = click
self.oldState = None
def Do(self):
pyfalog.debug("Toggling projected module for fit ID: {}".format(self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
mod = fit.projectedModules[self.position]
self.oldState = mod.state
proposedState = mod.getProposedState(mod, self.click)
if mod.state == proposedState:
return False
if not mod.canHaveState(proposedState, fit):
return False
mod.state = proposedState
eos.db.commit()
return True
def Undo(self):
pyfalog.debug("Toggling projected module for fit ID: {}".format(self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
mod = fit.projectedModules[self.position]
mod.state = self.oldState
return True

View File

@@ -63,18 +63,6 @@ class GuiRemoveProjectedCommand(wx.Command):
cmd = cls(self.fitID, self.data)
result = self.internal_history.Submit(cmd)
# 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))

View File

@@ -0,0 +1,53 @@
import wx
import gui.mainFrame
from eos.saveddata.drone import Drone as DroneType
from eos.saveddata.fighter import Fighter as FighterType
from eos.saveddata.fit import Fit as FitType
from eos.saveddata.module import Module as ModuleType
from gui import globalEvents as GE
from service.fit import Fit
from .calc.fitToggleProjectedDrone import FitToggleProjectedDroneCommand
from .calc.fitToggleProjectedFighter import FitToggleProjectedFighterCommand
from .calc.fitToggleProjectedFit import FitToggleProjectedFitCommand
from .calc.fitToggleProjectedModule import FitToggleProjectedModuleCommand
class GuiToggleProjectedCommand(wx.Command):
def __init__(self, fitID, thing, click):
wx.Command.__init__(self, True, "Toggle Projected Item")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.internal_history = wx.CommandProcessor()
self.fitID = fitID
self.thing = thing
self.click = click
def Do(self):
fit = Fit.getInstance().getFit(self.fitID)
if isinstance(self.thing, FitType):
success = self.internal_history.Submit(FitToggleProjectedFitCommand(self.fitID, self.thing.ID))
elif isinstance(self.thing, ModuleType):
position = fit.projectedModules.index(self.thing)
success = self.internal_history.Submit(FitToggleProjectedModuleCommand(self.fitID, position, self.click))
elif isinstance(self.thing, DroneType):
position = fit.projectedDrones.index(self.thing)
success = self.internal_history.Submit(FitToggleProjectedDroneCommand(self.fitID, position))
elif isinstance(self.thing, FighterType):
position = fit.projectedFighters.index(self.thing)
success = self.internal_history.Submit(FitToggleProjectedFighterCommand(self.fitID, position))
else:
success = False
if not success:
return False
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
def Undo(self):
for _ in self.internal_history.Commands:
self.internal_history.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -29,10 +29,8 @@ from eos.saveddata.character import Character as saveddata_Character
from eos.saveddata.citadel import Citadel as es_Citadel
from eos.saveddata.damagePattern import DamagePattern as es_DamagePattern
from eos.saveddata.drone import Drone as es_Drone
from eos.saveddata.fighter import Fighter as es_Fighter
from eos.const import ImplantLocation, FittingModuleState
from eos.saveddata.fit import Fit as FitType
from eos.saveddata.module import Module as es_Module
from eos.saveddata.ship import Ship as es_Ship
from service.character import Character
from service.damagePattern import DamagePattern
@@ -340,28 +338,6 @@ class Fit(FitDeprecated):
fit.notes))
return fits
def toggleProjected(self, fitID, thing, click):
pyfalog.debug("Toggling projected on fit ({0}) for: {1}", fitID, thing)
fit = eos.db.getFit(fitID)
if isinstance(thing, es_Drone):
if thing.amountActive == 0 and thing.canBeApplied(fit):
thing.amountActive = thing.amount
else:
thing.amountActive = 0
elif isinstance(thing, es_Fighter):
thing.active = not thing.active
elif isinstance(thing, es_Module):
thing.state = es_Module.getProposedState(thing, click)
if not thing.canHaveState(thing.state, fit):
thing.state = FittingModuleState.OFFLINE
elif isinstance(thing, FitType):
projectionInfo = thing.getProjectionInfo(fitID)
if projectionInfo:
projectionInfo.active = not projectionInfo.active
eos.db.commit()
self.recalc(fit)
def changeMutatedValue(self, mutator, value):
pyfalog.debug("Changing mutated value for {} / {}: {} => {}".format(mutator.module, mutator.module.mutaplasmid, mutator.value, value))
mutator.value = value