Do some work on mutated module commands to support new parsing format
This commit is contained in:
@@ -33,4 +33,4 @@ from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
from .guiToggleDrone import GuiToggleDroneCommand
|
||||
from .guiFitRename import GuiFitRenameCommand
|
||||
from .guiChangeImplantLocation import GuiChangeImplantLocation
|
||||
from .guiImportAbyssalModule import GuiImportAbyssalModuleCommand
|
||||
from .guiImportMutatedModule import GuiImportMutatedModuleCommand
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import wx
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitImportAbyssalCommand(wx.Command):
|
||||
""""
|
||||
Fitting command that takes in a complete Abyssal module and adds it to a fit
|
||||
"""
|
||||
def __init__(self, fitID, module):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.module = module
|
||||
self.new_position = None
|
||||
self.change = None
|
||||
self.replace_cmd = None
|
||||
|
||||
def Do(self):
|
||||
sFit = Fit.getInstance()
|
||||
fitID = self.fitID
|
||||
fit = eos.db.getFit(fitID)
|
||||
|
||||
# this is essentially the same as the FitAddModule command. possibly look into centralizing this functionality somewhere?
|
||||
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)
|
||||
if self.module.isValidState(State.ACTIVE):
|
||||
self.module.state = State.ACTIVE
|
||||
|
||||
# todo: fix these
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
# self.recalc(fit)
|
||||
# Then, check states of all modules and change where needed. This will recalc if needed
|
||||
sFit.checkStates(fit, self.module)
|
||||
|
||||
# fit.fill()
|
||||
eos.db.commit()
|
||||
|
||||
self.change = numSlots != len(fit.modules)
|
||||
self.new_position = self.module.modPosition
|
||||
else:
|
||||
return False
|
||||
|
||||
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 is not None:
|
||||
cmd = FitRemoveModuleCommand(self.fitID, [self.new_position])
|
||||
cmd.Do()
|
||||
return True
|
||||
86
gui/fitCommands/calc/fitImportMutatedModule.py
Normal file
86
gui/fitCommands/calc/fitImportMutatedModule.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import wx
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from eos.db.gamedata.queries import getDynamicItem
|
||||
from logbook import Logger
|
||||
from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitImportMutatedCommand(wx.Command):
|
||||
""""
|
||||
Fitting command that takes info about mutated module, composes it and adds it to a fit
|
||||
"""
|
||||
def __init__(self, fitID, baseItem, mutaItem, attrMap):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.baseItem = baseItem
|
||||
self.mutaItem = mutaItem
|
||||
self.attrMap = attrMap
|
||||
self.new_position = None
|
||||
self.change = None
|
||||
self.replace_cmd = None
|
||||
|
||||
def Do(self):
|
||||
sFit = Fit.getInstance()
|
||||
fitID = self.fitID
|
||||
fit = eos.db.getFit(fitID)
|
||||
|
||||
if self.baseItem is None:
|
||||
pyfalog.warning("Unable to build non-mutated module: no base item to build from")
|
||||
return False
|
||||
|
||||
mutaplasmid = getDynamicItem(self.mutaItem.ID)
|
||||
# Try to build simple item even though no mutaplasmid found
|
||||
if mutaplasmid is None:
|
||||
try:
|
||||
module = Module(self.baseItem)
|
||||
except ValueError:
|
||||
pyfalog.warning("Unable to build non-mutated module: typeID {}", self.baseItem.id)
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
module = Module(mutaplasmid.resultingItem, self.baseItem, mutaplasmid)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
for attrID, mutator in module.mutators.items():
|
||||
if attrID in self.attrMap:
|
||||
mutator.value = self.attrMap[attrID]
|
||||
|
||||
|
||||
# this is essentially the same as the FitAddModule command. possibly look into centralizing this functionality somewhere?
|
||||
if module.fits(fit):
|
||||
pyfalog.debug("Adding {} as module for fit {}", module, fit)
|
||||
module.owner = fit
|
||||
numSlots = len(fit.modules)
|
||||
fit.modules.append(module)
|
||||
if module.isValidState(State.ACTIVE):
|
||||
module.state = State.ACTIVE
|
||||
|
||||
# todo: fix these
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
# self.recalc(fit)
|
||||
# Then, check states of all modules and change where needed. This will recalc if needed
|
||||
sFit.checkStates(fit, module)
|
||||
|
||||
# fit.fill()
|
||||
eos.db.commit()
|
||||
|
||||
self.change = numSlots != len(fit.modules)
|
||||
self.new_position = module.modPosition
|
||||
else:
|
||||
return False
|
||||
|
||||
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 is not None:
|
||||
cmd = FitRemoveModuleCommand(self.fitID, [self.new_position])
|
||||
cmd.Do()
|
||||
return True
|
||||
@@ -2,25 +2,28 @@ import wx
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitImportAbyssalModule import FitImportAbyssalCommand
|
||||
from .calc.fitImportMutatedModule import FitImportMutatedCommand
|
||||
from service.fit import Fit
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiImportAbyssalModuleCommand(wx.Command):
|
||||
def __init__(self, fitID, module):
|
||||
wx.Command.__init__(self, True, "Abyssal Module Import: {}".format(module))
|
||||
class GuiImportMutatedModuleCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, baseItem, mutaItem, attrMap):
|
||||
wx.Command.__init__(self, True, "Mutated Module Import: {} {} {}".format(baseItem.id, mutaItem.id, attrMap))
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.module = module
|
||||
self.baseItem = baseItem
|
||||
self.mutaItem = mutaItem
|
||||
self.attrMap = attrMap
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("{} Do()".format(self))
|
||||
|
||||
if self.internal_history.Submit(FitImportAbyssalCommand(self.fitID, self.module)):
|
||||
if self.internal_history.Submit(FitImportMutatedCommand(self.fitID, self.baseItem, self.mutaItem, self.attrMap)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd"))
|
||||
return True
|
||||
@@ -731,15 +731,16 @@ class MainFrame(wx.Frame):
|
||||
clipboard = fromClipboard()
|
||||
activeFit = self.getActiveFit()
|
||||
try:
|
||||
import_type, data = Port().importFitFromBuffer(clipboard, activeFit)
|
||||
if import_type == "Abyssal":
|
||||
importType, importData = Port().importFitFromBuffer(clipboard, activeFit)
|
||||
# If it's mutated item - make sure there's at least base item specified
|
||||
if importType == "MutatedItem":
|
||||
# we've imported an Abyssal module, need to fire off the command to add it to the fit
|
||||
self.command.Submit(cmd.GuiImportAbyssalModuleCommand(activeFit, data[0]))
|
||||
self.command.Submit(cmd.GuiImportMutatedModuleCommand(activeFit, *importData[0]))
|
||||
return # no need to do anything else
|
||||
except:
|
||||
pyfalog.error("Attempt to import failed:\n{0}", clipboard)
|
||||
else:
|
||||
self._openAfterImport(data)
|
||||
self._openAfterImport(importData)
|
||||
|
||||
def exportToClipboard(self, event):
|
||||
CopySelectDict = {CopySelectDialog.copyFormatEft: self.clipboardEft,
|
||||
|
||||
@@ -189,10 +189,10 @@ class Port(object):
|
||||
# TODO: catch the exception?
|
||||
# activeFit is reserved?, bufferStr is unicode? (assume only clipboard string?
|
||||
sFit = svcFit.getInstance()
|
||||
import_type, fits = Port.importAuto(bufferStr, activeFit=activeFit)
|
||||
importType, importData = Port.importAuto(bufferStr, activeFit=activeFit)
|
||||
|
||||
if import_type != 'Abyssal':
|
||||
for fit in fits:
|
||||
if importType != "MutatedItem":
|
||||
for fit in importData:
|
||||
fit.character = sFit.character
|
||||
fit.damagePattern = sFit.pattern
|
||||
fit.targetResists = sFit.targetResists
|
||||
@@ -202,7 +202,7 @@ class Port(object):
|
||||
useCharImplants = sFit.serviceFittingOptions["useCharacterImplantsByDefault"]
|
||||
fit.implantLocation = ImplantLocation.CHARACTER if useCharImplants else ImplantLocation.FIT
|
||||
db.save(fit)
|
||||
return import_type, fits
|
||||
return importType, importData
|
||||
|
||||
@classmethod
|
||||
def importAuto(cls, string, path=None, activeFit=None, iportuser=None):
|
||||
@@ -237,7 +237,7 @@ class Port(object):
|
||||
|
||||
# Assume that we import stand-alone abyssal module if all else fails
|
||||
try:
|
||||
return "Abyssal", (parseMutant(string.split("\n")),)
|
||||
return "MutatedItem", (parseMutant(string.split("\n")),)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user