From 4041ecddc4229e806a6f47d18f355ad3941bbe6c Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 15 May 2016 22:23:23 -0400 Subject: [PATCH] Create Citadel class that inherits from Ship. Add Service slots --- eos/saveddata/citadel.py | 42 +++++++++++++++++++++++++++++++++ eos/saveddata/fit.py | 11 ++++++--- eos/saveddata/module.py | 5 +++- eos/saveddata/ship.py | 8 ++++--- eos/types.py | 2 ++ gui/builtinViews/fittingView.py | 2 +- 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 eos/saveddata/citadel.py diff --git a/eos/saveddata/citadel.py b/eos/saveddata/citadel.py new file mode 100644 index 000000000..f4d5fed47 --- /dev/null +++ b/eos/saveddata/citadel.py @@ -0,0 +1,42 @@ +#=============================================================================== +# Copyright (C) 2010 Diego Duclos +# +# This file is part of eos. +# +# eos is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# eos is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with eos. If not, see . +#=============================================================================== + +from eos.modifiedAttributeDict import ModifiedAttributeDict, ItemAttrShortcut +from eos.effectHandlerHelpers import HandledItem +from eos.saveddata.mode import Mode +import eos.db +from eos.types import Ship +import logging + +logger = logging.getLogger(__name__) + +class Citadel(Ship): + + def validate(self, item): + if item.category.name != "Structure": + raise ValueError('Passed item "%s" (category: (%s)) is not under Structure category'%(item.name, item.category.name)) + + def __deepcopy__(self, memo): + copy = Citadel(self.item) + return copy + + def __repr__(self): + return "Citadel(ID={}, name={}) at {}".format( + self.item.ID, self.item.name, hex(id(self)) + ) diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 2db3f6aab..c95f2e150 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -24,7 +24,7 @@ from itertools import chain from eos import capSim from copy import deepcopy from math import sqrt, log, asinh -from eos.types import Drone, Cargo, Ship, Character, State, Slot, Module, Implant, Booster, Skill +from eos.types import Drone, Cargo, Ship, Character, State, Slot, Module, Implant, Booster, Skill, Citadel from eos.saveddata.module import State, Hardpoint from eos.saveddata.mode import Mode import eos.db @@ -92,7 +92,11 @@ class Fit(object): return try: - self.__ship = Ship(item, self) + try: + self.__ship = Ship(item, self) + except ValueError: + self.__ship = Citadel(item, self) + print self.__ship # @todo extra attributes is now useless, however it set to be # the same as ship attributes for ease (so we don't have to # change all instances in source). Remove this at some point @@ -564,7 +568,7 @@ class Fit(object): if self.ship is None: return - for slotType in (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM): + for slotType in (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM, Slot.SERVICE): amount = self.getSlotsFree(slotType, True) if amount > 0: for _ in xrange(int(amount)): @@ -639,6 +643,7 @@ class Fit(object): Slot.HIGH: "hiSlots", Slot.RIG: "rigSlots", Slot.SUBSYSTEM: "maxSubSystems", + Slot.SERVICE: "serviceSlots", Slot.F_LIGHT: "fighterLightSlots", Slot.F_SUPPORT: "fighterSupportSlots", Slot.F_HEAVY: "fighterHeavySlots"} diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index e0587c044..f9cf1714f 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -46,6 +46,8 @@ class Slot(Enum): # system effects. They are projected "modules" and pyfa assumes all modules # have a slot. In this case, make one up. SYSTEM = 7 + # used for citadel services + SERVICE = 8 # fighter 'slots'. Just easier to put them here... F_LIGHT = 10 F_SUPPORT = 11 @@ -534,7 +536,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): "loPower" : Slot.LOW, "medPower" : Slot.MED, "hiPower" : Slot.HIGH, - "subSystem" : Slot.SUBSYSTEM} + "subSystem" : Slot.SUBSYSTEM, + "serviceSlot": Slot.SERVICE} if item is None: return None for effectName, slot in effectSlotMap.iteritems(): diff --git a/eos/saveddata/ship.py b/eos/saveddata/ship.py index cf6ee072b..1a1644849 100644 --- a/eos/saveddata/ship.py +++ b/eos/saveddata/ship.py @@ -42,9 +42,7 @@ class Ship(ItemAttrShortcut, HandledItem): } def __init__(self, item, parent=None): - - if item.category.name not in ("Ship", "Structure"): - raise ValueError('Passed item "%s" (category: (%s)) is not under Ship category'%(item.name, item.category.name)) + self.validate(item) self.__item = item self.__modeItems = self.__getModeItems() @@ -58,6 +56,10 @@ class Ship(ItemAttrShortcut, HandledItem): self.parent = parent self.commandBonus = 0 + def validate(self, item): + if item.category.name != "Ship": + raise ValueError('Passed item "%s" (category: (%s)) is not under Ship category'%(item.name, item.category.name)) + @property def item(self): return self.__item diff --git a/eos/types.py b/eos/types.py index fc25741b2..31bbcd47a 100644 --- a/eos/types.py +++ b/eos/types.py @@ -35,9 +35,11 @@ from eos.saveddata.implantSet import ImplantSet from eos.saveddata.booster import SideEffect from eos.saveddata.booster import Booster from eos.saveddata.ship import Ship +from eos.saveddata.citadel import Citadel from eos.saveddata.fit import Fit, ImplantLocation from eos.saveddata.mode import Mode from eos.saveddata.fleet import Fleet, Wing, Squad from eos.saveddata.miscData import MiscData from eos.saveddata.override import Override + import eos.db diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index d16c0f251..206914ac0 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -395,7 +395,7 @@ class FittingView(d.Display): sFit = service.Fit.getInstance() fit = sFit.getFit(self.activeFitID) - slotOrder = [Slot.SUBSYSTEM, Slot.HIGH, Slot.MED, Slot.LOW, Slot.RIG] + slotOrder = [Slot.SUBSYSTEM, Slot.HIGH, Slot.MED, Slot.LOW, Slot.RIG, Slot.SERVICE] if fit is not None: self.mods = fit.modules[:]