Restore booster state even when it was replaced by another booster

This commit is contained in:
DarkPhoenix
2019-04-10 18:18:26 +03:00
parent 7fc98037a6
commit fda2c43a1d
8 changed files with 64 additions and 34 deletions

View File

@@ -23,7 +23,7 @@ import datetime
from eos.db import saveddata_meta
from eos.db.saveddata.implant import charImplants_table
from eos.effectHandlerHelpers import HandledImplantBoosterList, HandledSsoCharacterList
from eos.effectHandlerHelpers import HandledImplantList, HandledSsoCharacterList
from eos.saveddata.implant import Implant
from eos.saveddata.user import User
from eos.saveddata.character import Character, Skill
@@ -75,7 +75,7 @@ mapper(Character, characters_table,
cascade="all,delete-orphan"),
"_Character__implants" : relation(
Implant,
collection_class=HandledImplantBoosterList,
collection_class=HandledImplantList,
cascade='all,delete-orphan',
backref='character',
single_parent=True,

View File

@@ -31,7 +31,7 @@ from eos.db.saveddata.drone import drones_table
from eos.db.saveddata.fighter import fighters_table
from eos.db.saveddata.implant import fitImplants_table
from eos.db.saveddata.module import modules_table
from eos.effectHandlerHelpers import HandledDroneCargoList, HandledImplantBoosterList, HandledModuleList, HandledProjectedDroneList, HandledProjectedModList
from eos.effectHandlerHelpers import HandledDroneCargoList, HandledImplantList, HandledBoosterList, HandledModuleList, HandledProjectedDroneList, HandledProjectedModList
from eos.saveddata.booster import Booster
from eos.saveddata.cargo import Cargo
from eos.saveddata.character import Character
@@ -183,7 +183,7 @@ mapper(es_Fit, fits_table,
"shipID": fits_table.c.shipID,
"_Fit__boosters": relation(
Booster,
collection_class=HandledImplantBoosterList,
collection_class=HandledBoosterList,
cascade='all, delete, delete-orphan',
backref='owner',
single_parent=True),
@@ -219,7 +219,7 @@ mapper(es_Fit, fits_table,
primaryjoin=and_(fighters_table.c.fitID == fits_table.c.ID, fighters_table.c.projected == True)), # noqa
"_Fit__implants": relation(
Implant,
collection_class=HandledImplantBoosterList,
collection_class=HandledImplantList,
cascade='all, delete, delete-orphan',
backref='owner',
single_parent=True,

View File

@@ -23,7 +23,7 @@ import datetime
from eos.db import saveddata_meta
from eos.db.saveddata.implant import implantsSetMap_table
from eos.effectHandlerHelpers import HandledImplantBoosterList
from eos.effectHandlerHelpers import HandledImplantList
from eos.saveddata.implant import Implant
from eos.saveddata.implantSet import ImplantSet
@@ -38,7 +38,7 @@ mapper(ImplantSet, implant_set_table,
properties={
"_ImplantSet__implants": relation(
Implant,
collection_class=HandledImplantBoosterList,
collection_class=HandledImplantList,
cascade='all, delete, delete-orphan',
backref='set',
single_parent=True,

View File

@@ -211,7 +211,8 @@ class HandledDroneCargoList(HandledList):
self.remove(thing)
class HandledImplantBoosterList(HandledList):
class HandledImplantList(HandledList):
def append(self, thing):
if thing.isInvalid:
HandledList.append(self, thing)
@@ -234,6 +235,32 @@ class HandledImplantBoosterList(HandledList):
return None
class HandledBoosterList(HandledList):
def append(self, thing):
if thing.isInvalid:
HandledList.append(self, thing)
self.remove(thing)
return
self.makeRoom(thing)
HandledList.append(self, thing)
def makeRoom(self, thing):
# if needed, remove booster that was occupying slot
oldObj = next((m for m in self if m.slot == thing.slot), None)
if oldObj:
pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name,
thing.item.name)
itemID = oldObj.itemID
state = oldObj.active
sideEffects = {se.effectID: se.active for se in oldObj.sideEffects}
oldObj.itemID = 0 # hack to remove from DB. See GH issue #324
self.remove(oldObj)
return itemID, state, sideEffects
return None, None, None
class HandledSsoCharacterList(list):
def append(self, character):
old = next((x for x in self if x.client == character.client), None)

View File

@@ -27,7 +27,7 @@ from sqlalchemy.orm import validates, reconstructor
import eos
import eos.db
import eos.config
from eos.effectHandlerHelpers import HandledItem, HandledImplantBoosterList
from eos.effectHandlerHelpers import HandledItem, HandledImplantList
pyfalog = Logger(__name__)
@@ -51,7 +51,7 @@ class Character(object):
for item in self.getSkillList():
self.addSkill(Skill(self, item.ID, self.defaultLevel))
self.__implants = HandledImplantBoosterList()
self.__implants = HandledImplantList()
@reconstructor
def init(self):

View File

@@ -27,7 +27,7 @@ from sqlalchemy.orm import validates, reconstructor
import eos.db
from eos import capSim
from eos.effectHandlerHelpers import HandledModuleList, HandledDroneCargoList, HandledImplantBoosterList, HandledProjectedDroneList, HandledProjectedModList
from eos.effectHandlerHelpers import HandledModuleList, HandledDroneCargoList, HandledImplantList, HandledBoosterList, HandledProjectedDroneList, HandledProjectedModList
from eos.const import ImplantLocation, CalcType, FittingSlot
from eos.saveddata.ship import Ship
from eos.saveddata.drone import Drone
@@ -57,8 +57,8 @@ class Fit(object):
self.__drones = HandledDroneCargoList()
self.__fighters = HandledDroneCargoList()
self.__cargo = HandledDroneCargoList()
self.__implants = HandledImplantBoosterList()
self.__boosters = HandledImplantBoosterList()
self.__implants = HandledImplantList()
self.__boosters = HandledBoosterList()
# self.__projectedFits = {}
self.__projectedModules = HandledProjectedModList()
self.__projectedDrones = HandledProjectedDroneList()

View File

@@ -19,13 +19,13 @@
from copy import deepcopy
from eos.effectHandlerHelpers import HandledImplantBoosterList
from eos.effectHandlerHelpers import HandledImplantList
class ImplantSet(object):
def __init__(self, name=None):
self.name = name
self.__implants = HandledImplantBoosterList()
self.__implants = HandledImplantList()
@property
def implants(self):

View File

@@ -9,49 +9,52 @@ class FitAddBoosterCommand(wx.Command):
""""
from sFit.addBooster
"""
def __init__(self, fitID, itemID, state=None, sideEffects=None):
def __init__(self, fitID, itemID, state, sideEffects):
wx.Command.__init__(self, True)
self.fitID = fitID
self.itemID = itemID
self.state = state
self.sideEffects = sideEffects
self.new_index = None
self.old_item = None
self.newItemID = itemID
self.newState = state
self.newSideEffects = sideEffects
self.newIndex = None
self.oldItemID = None
self.oldState = None
self.oldSideEffects = None
def Do(self):
pyfalog.debug("Adding booster ({0}) to fit ID: {1}", self.itemID, self.fitID)
pyfalog.debug("Adding booster ({0}) to fit ID: {1}", self.newItemID, self.fitID)
fit = eos.db.getFit(self.fitID)
item = eos.db.getItem(self.itemID, eager="attributes")
item = eos.db.getItem(self.newItemID, eager="attributes")
if next((x for x in fit.boosters if x.itemID == self.itemID), None):
if next((x for x in fit.boosters if x.itemID == self.newItemID), None):
return False # already have item in list of boosters
try:
booster = Booster(item)
except ValueError:
pyfalog.warning("Invalid item: {0}", self.itemID)
pyfalog.warning("Invalid item: {0}", self.newItemID)
return False
if self.state is not None:
booster.active = self.state
if self.sideEffects is not None:
if self.newState is not None:
booster.active = self.newState
if self.newSideEffects is not None:
for sideEffect in booster.sideEffects:
sideEffect.active = self.sideEffects.get(sideEffect.effectID, False)
sideEffect.active = self.newSideEffects.get(sideEffect.effectID, False)
self.old_item = fit.boosters.makeRoom(booster)
self.oldItemID, self.oldState, self.oldSideEffects = fit.boosters.makeRoom(booster)
fit.boosters.append(booster)
self.new_index = fit.boosters.index(booster)
self.newIndex = fit.boosters.index(booster)
return True
def Undo(self):
if self.old_item:
if self.oldItemID:
# If we had an item in the slot previously, add it back.
cmd = FitAddBoosterCommand(self.fitID, self.old_item)
cmd = FitAddBoosterCommand(self.fitID, self.oldItemID, self.oldState, self.oldSideEffects)
cmd.Do()
return True
from .fitRemoveBooster import FitRemoveBoosterCommand # Avoid circular import
cmd = FitRemoveBoosterCommand(self.fitID, self.new_index)
cmd = FitRemoveBoosterCommand(self.fitID, self.newIndex)
cmd.Do()
return True