Respect spaces between the modules during import

This commit is contained in:
DarkPhoenix
2018-08-25 17:42:19 +03:00
parent 44aed364b7
commit 93f1a18b37
2 changed files with 33 additions and 14 deletions

View File

@@ -113,6 +113,7 @@ class HandledList(list):
class HandledModuleList(HandledList): class HandledModuleList(HandledList):
def append(self, mod): def append(self, mod):
emptyPosition = float("Inf") emptyPosition = float("Inf")
for i in range(len(self)): for i in range(len(self)):
@@ -130,6 +131,9 @@ class HandledModuleList(HandledList):
self.remove(mod) self.remove(mod)
return return
self.appendIgnoreEmpty(mod)
def appendIgnoreEmpty(self, mod):
mod.position = len(self) mod.position = len(self)
HandledList.append(self, mod) HandledList.append(self, mod)
if mod.isInvalid: if mod.isInvalid:

View File

@@ -205,7 +205,7 @@ class AbstractFit:
self.cargo = {} # Format: {item: Cargo} self.cargo = {} # Format: {item: Cargo}
@property @property
def modContMap(self): def __slotContainerMap(self):
return { return {
Slot.HIGH: self.modulesHigh, Slot.HIGH: self.modulesHigh,
Slot.MED: self.modulesMed, Slot.MED: self.modulesMed,
@@ -214,6 +214,17 @@ class AbstractFit:
Slot.SUBSYSTEM: self.subsystems, Slot.SUBSYSTEM: self.subsystems,
Slot.SERVICE: self.services} Slot.SERVICE: self.services}
def getContainerBySlot(self, slotType):
return self.__slotContainerMap.get(slotType)
def getSlotByContainer(self, container):
slotType = None
for k, v in self.__slotContainerMap.items():
if v is container:
slotType = k
break
return slotType
def addModules(self, itemSpecs): def addModules(self, itemSpecs):
modules = [] modules = []
slotTypes = set() slotTypes = set()
@@ -228,25 +239,24 @@ class AbstractFit:
modules.append(m) modules.append(m)
slotTypes.add(m.slot) slotTypes.add(m.slot)
clearTail(modules) clearTail(modules)
modContMap = self.modContMap
# If all the modules have same slot type, put them to appropriate # If all the modules have same slot type, put them to appropriate
# container with stubs # container with stubs
if len(slotTypes) == 1: if len(slotTypes) == 1:
slotType = tuple(slotTypes)[0] slotType = tuple(slotTypes)[0]
modContMap[slotType].extend(modules) self.getContainerBySlot(slotType).extend(modules)
# Otherwise, put just modules # Otherwise, put just modules
else: else:
for m in modules: for m in modules:
if m is None: if m is None:
continue continue
modContMap[m.slot].append(m) self.getContainerBySlot(m.slot).append(m)
def addModule(self, itemSpec): def addModule(self, itemSpec):
if itemSpec is None: if itemSpec is None:
return return
m = self.__makeModule(itemSpec) m = self.__makeModule(itemSpec)
if m is not None: if m is not None:
self.modContMap[m.slot].append(m) self.getContainerBySlot(m.slot).append(m)
def __makeModule(self, itemSpec): def __makeModule(self, itemSpec):
try: try:
@@ -492,12 +502,15 @@ class EftPort:
aFit.addCargo(itemSpec) aFit.addCargo(itemSpec)
# Subsystems first because they modify slot amount # Subsystems first because they modify slot amount
for subsystem in aFit.subsystems: for m in aFit.subsystems:
if subsystem is None: if m is None:
continue dummy = Module.buildEmpty(aFit.getSlotByContainer(aFit.subsystems))
if subsystem.fits(fit): dummy.owner = fit
subsystem.owner = fit fit.modules.appendIgnoreEmpty(dummy)
fit.modules.append(subsystem) elif m.fits(fit):
m.owner = fit
pyfalog.error('kurwa {}'.format(type(fit.modules)))
fit.modules.appendIgnoreEmpty(m)
svcFit.getInstance().recalc(fit) svcFit.getInstance().recalc(fit)
# Other stuff # Other stuff
@@ -510,12 +523,14 @@ class EftPort:
): ):
for m in modRack: for m in modRack:
if m is None: if m is None:
continue dummy = Module.buildEmpty(aFit.getSlotByContainer(modRack))
if m.fits(fit): dummy.owner = fit
fit.modules.appendIgnoreEmpty(dummy)
elif m.fits(fit):
m.owner = fit m.owner = fit
if not m.isValidState(m.state): if not m.isValidState(m.state):
pyfalog.warning('EftPort.importEft: module {} cannot have state {}', m, m.state) pyfalog.warning('EftPort.importEft: module {} cannot have state {}', m, m.state)
fit.modules.append(m) fit.modules.appendIgnoreEmpty(m)
for implant in aFit.implants: for implant in aFit.implants:
fit.implants.append(implant) fit.implants.append(implant)
for booster in aFit.boosters: for booster in aFit.boosters: