Merge pull request #1626 from WatchMeCalculate/Issue-#1519
Issue #1519, on fitting restriction toggle, accurately keep valid modules
This commit is contained in:
@@ -1016,6 +1016,16 @@ class Fit(object):
|
||||
def getNumSlots(self, type):
|
||||
return self.ship.getModifiedItemAttr(self.slots[type]) or 0
|
||||
|
||||
def getHardpointsFree(self, type):
|
||||
if type == Hardpoint.NONE:
|
||||
return 1
|
||||
elif type == Hardpoint.TURRET:
|
||||
return self.ship.getModifiedItemAttr('turretSlotsLeft') - self.getHardpointsUsed(Hardpoint.TURRET)
|
||||
elif type == Hardpoint.MISSILE:
|
||||
return self.ship.getModifiedItemAttr('launcherSlotsLeft') - self.getHardpointsUsed(Hardpoint.MISSILE)
|
||||
else:
|
||||
raise ValueError("%d is not a valid value for Hardpoint Enum", type)
|
||||
|
||||
@property
|
||||
def calibrationUsed(self):
|
||||
return self.getItemAttrOnlineSum(self.modules, 'upgradeCost')
|
||||
|
||||
@@ -472,7 +472,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
if max is not None:
|
||||
current = 0 # if self.owner != fit else -1 # Disabled, see #1278
|
||||
for mod in fit.modules:
|
||||
if mod.item and mod.item.groupID == self.item.groupID:
|
||||
if (mod.item and mod.item.groupID == self.item.groupID and
|
||||
self.modPosition != mod.modPosition):
|
||||
current += 1
|
||||
|
||||
if current >= max:
|
||||
@@ -480,12 +481,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
|
||||
# Check this only if we're told to do so
|
||||
if hardpointLimit:
|
||||
if self.hardpoint == Hardpoint.TURRET:
|
||||
if fit.ship.getModifiedItemAttr('turretSlotsLeft') - fit.getHardpointsUsed(Hardpoint.TURRET) < 1:
|
||||
return False
|
||||
elif self.hardpoint == Hardpoint.MISSILE:
|
||||
if fit.ship.getModifiedItemAttr('launcherSlotsLeft') - fit.getHardpointsUsed(Hardpoint.MISSILE) < 1:
|
||||
return False
|
||||
if fit.getHardpointsFree(self.hardpoint) < 1:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -686,7 +686,22 @@ class FittingView(d.Display):
|
||||
|
||||
# only consider changing color if we're dealing with a Module
|
||||
if type(mod) is Module:
|
||||
if slotMap[mod.slot] or getattr(mod, 'restrictionOverridden', None): # Color too many modules as red
|
||||
hasRestrictionOverriden = getattr(mod, 'restrictionOverridden', None)
|
||||
# If module had broken fitting restrictions but now doesn't,
|
||||
# ensure it is now valid, and remove restrictionOverridden
|
||||
# variable. More in #1519
|
||||
if not fit.ignoreRestrictions and hasRestrictionOverriden:
|
||||
clean = False
|
||||
if mod.fits(fit, False):
|
||||
if not mod.hardpoint:
|
||||
clean = True
|
||||
elif fit.getHardpointsFree(mod.hardpoint) >= 0:
|
||||
clean = True
|
||||
if clean:
|
||||
del mod.restrictionOverridden
|
||||
hasRestrictionOverriden = not hasRestrictionOverriden
|
||||
|
||||
if slotMap[mod.slot] or hasRestrictionOverriden: # Color too many modules as red
|
||||
self.SetItemBackgroundColour(i, wx.Colour(204, 51, 51))
|
||||
elif sFit.serviceFittingOptions["colorFitBySlot"]: # Color by slot it enabled
|
||||
self.SetItemBackgroundColour(i, self.slotColour(mod.slot))
|
||||
|
||||
@@ -973,7 +973,7 @@ class Fit(object):
|
||||
# remove invalid modules when switching back to enabled fitting restrictions
|
||||
if not fit.ignoreRestrictions:
|
||||
for m in fit.modules:
|
||||
if not m.isEmpty and not m.fits(fit):
|
||||
if not m.isEmpty and not m.fits(fit, False):
|
||||
self.removeModule(fit.ID, m.modPosition)
|
||||
|
||||
eos.db.commit()
|
||||
|
||||
Reference in New Issue
Block a user