Some documentation

This commit is contained in:
blitzmann
2018-08-02 23:23:52 -04:00
parent fc153915b6
commit 36b158637c
6 changed files with 36 additions and 8 deletions

View File

@@ -18,6 +18,7 @@
# ===============================================================================
from logbook import Logger
from utils.deprecated import deprecated
pyfalog = Logger(__name__)
@@ -163,6 +164,7 @@ class HandledModuleList(HandledList):
mod.position = index
self[index] = mod
@deprecated
def freeSlot(self, slot):
for i in range(len(self)):
mod = self[i]

View File

@@ -12,23 +12,24 @@ pyfalog = Logger(__name__)
class FitAddModuleCommand(wx.Command):
""""
Fitting command that appends a module to a fit using the first available slot.
Fitting command that appends a module to a fit using the first available slot. In the case of a Subsystem, it checks
if there is already a subsystem with the same slot, and runs the replace command instead.
from sFit.appendModule
"""
def __init__(self, fitID, itemID, mutaplasmidID=None, baseID=None):
wx.Command.__init__(self, True, "Module Add")
wx.Command.__init__(self, True)
self.fitID = fitID
self.itemID = itemID
self.mutaplasmidID = mutaplasmidID
self.baseID = baseID
self.new_position = None
self.change = None
self.replace_cmd = None
def Do(self):
fitID = self.fitID
itemID = self.itemID
pyfalog.debug("Appending module for fit ({0}) using item: {1}", fitID, itemID)
fit = eos.db.getFit(fitID)
item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
@@ -38,13 +39,19 @@ class FitAddModuleCommand(wx.Command):
try:
self.module = Module(item, bItem, mItem)
except ValueError:
pyfalog.warning("Invalid item: {0}", itemID)
pyfalog.warning("Invalid module: {}", item)
return False
# If subsystem and we need to replace, run the replace command instead and bypass the rest of this command
if self.module.item.category.name == "Subsystem":
fit.modules.freeSlot(self.module.getModifiedItemAttr("subSystemSlot"))
for mod in fit.modules:
if mod.getModifiedItemAttr("subSystemSlot") == self.module.getModifiedItemAttr("subSystemSlot"):
from .fitReplaceModule import FitReplaceModuleCommand
self.replace_cmd = FitReplaceModuleCommand(self.fitID, mod.modPosition, itemID)
return self.replace_cmd.Do()
if self.module.fits(fit):
pyfalog.debug("Adding {} as module for fit {}", self.module, fit)
self.module.owner = fit
numSlots = len(fit.modules)
fit.modules.append(self.module)
@@ -68,6 +75,10 @@ class FitAddModuleCommand(wx.Command):
return True
def Undo(self):
# We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead
if self.replace_cmd:
return self.replace_cmd.Undo()
from .fitRemoveModule import FitRemoveModuleCommand # Avoid circular import
if self.new_position:
cmd = FitRemoveModuleCommand(self.fitID, [self.new_position])

View File

@@ -13,7 +13,7 @@ class FitRemoveModuleCommand(wx.Command):
from sFit.removeModule
"""
def __init__(self, fitID: int, positions: list = None):
wx.Command.__init__(self, True, "Module Remove")
wx.Command.__init__(self, True)
self.fitID = fitID
self.positions = positions
self.modCache = []
@@ -21,12 +21,14 @@ class FitRemoveModuleCommand(wx.Command):
def Do(self):
fitID = self.fitID
pyfalog.debug("Removing module from position ({0}) for fit ID: {1}", self.positions, fitID)
fit = eos.db.getFit(fitID)
pyfalog.debug("Removing module from position ({0}) for fit ID: {1}", self.positions, fitID)
for x in self.positions:
mod = fit.modules[x]
if not mod.isEmpty:
pyfalog.debug(" -- Removing {}", mod)
self.modCache.append(ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge, mod.baseItemID, mod.mutaplasmidID))
fit.modules.toDummy(x)
@@ -44,8 +46,11 @@ class FitRemoveModuleCommand(wx.Command):
return True
def Undo(self):
pyfalog.debug("Reapplying {} removed module(s) for {}", len(self.modCache), self.fitID)
from gui.fitCommands.calc.fitAddModule import FitAddModuleCommand # avoids circular import
for mod in self.modCache:
pyfalog.debug(" -- {}", mod)
# todo, send the state and charge?
cmd = FitAddModuleCommand(self.fitID, mod.itemID, mod.mutaplasmidID, mod.baseID)
cmd.Do()

View File

@@ -20,7 +20,6 @@ class FitSetChargeCommand(wx.Command):
self.cache = None
def Do(self):
pyfalog.debug("Set ammo for fit ID: {0}", self.fitID)
return self.__setAmmo(self.positions, self.chargeID)
def Undo(self):
@@ -40,6 +39,7 @@ class FitSetChargeCommand(wx.Command):
for pos in positions:
mod = fit.modules[pos]
if not mod.isEmpty and mod.isValidCharge(ammo):
pyfalog.debug("Set ammo {} for {} on fit {}", ammo, mod, self.fitID)
result = True
mod.charge = ammo
eos.db.commit()

View File

@@ -6,6 +6,8 @@ from .calc.fitAddModule import FitAddModuleCommand
from .calc.fitReplaceModule import FitReplaceModuleCommand
from .calc.fitSetCharge import FitSetChargeCommand
from service.fit import Fit
from logbook import Logger
pyfalog = Logger(__name__)
class GuiModuleAddCommand(wx.Command):
@@ -28,21 +30,27 @@ class GuiModuleAddCommand(wx.Command):
self.old_mod = None
def Do(self):
pyfalog.debug("{} Do()".format(self))
success = False
item = eos.db.getItem(self.itemID)
if item.isCharge and self.position is not None:
pyfalog.debug("Trying to add a charge")
success = self.internal_history.Submit(FitSetChargeCommand(self.fitID, [self.position], self.itemID))
if not success:
pyfalog.debug(" Failed")
return False # if it's a charge item and this failed, nothing more we can try.
# if we have a position set, try to apply the module to that position
elif self.position is not None:
pyfalog.debug("Trying to add a module to a specific position")
success = self.internal_history.Submit(FitReplaceModuleCommand(self.fitID, self.position, self.itemID))
if not success:
pyfalog.debug(" Failed")
# something went wrong with trying to fit the module into specific location, attempt to append it
self.position = None
# if we're not trying to set module to a position, simply append
if self.position is None:
pyfalog.debug("Trying to append a module")
success = self.internal_history.Submit(FitAddModuleCommand(self.fitID, self.itemID))
if success:
@@ -53,6 +61,7 @@ class GuiModuleAddCommand(wx.Command):
def Undo(self):
pyfalog.debug("{} Undo()".format(self))
for _ in self.internal_history.Commands:
self.internal_history.Undo()
self.sFit.recalc(self.fitID)

View File

@@ -11,6 +11,7 @@ from .calc.fitRemoveModule import FitRemoveModuleCommand
class GuiModuleRemoveCommand(wx.Command):
def __init__(self, fitID, modules):
"""
Handles removing modules from fit.modules,
:param fitID: The fit ID that we are modifying
:param modules: A list of Module objects that we are attempting to remove.