Rework the way options are stored

This commit is contained in:
DarkPhoenix
2019-02-12 13:14:31 +03:00
parent eeef2104c2
commit d55d6c3e5e
3 changed files with 13 additions and 25 deletions

View File

@@ -43,24 +43,20 @@ class CopySelectDialog(wx.Dialog):
self.copyFormats = OrderedDict((
("EFT", (CopySelectDialog.copyFormatEft, EFT_OPTIONS)),
("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, MULTIBUY_OPTIONS)),
("ESI", (CopySelectDialog.copyFormatEsi, None)),
("EFS", (CopySelectDialog.copyFormatEfs, None)),
# ("XML", (CopySelectDialog.copyFormatXml, None)),
# ("DNA", (CopySelectDialog.copyFormatDna, None)),
("ESI", (CopySelectDialog.copyFormatEsi, None)),
("MultiBuy", (CopySelectDialog.copyFormatMultiBuy, MULTIBUY_OPTIONS)),
("EFS", (CopySelectDialog.copyFormatEfs, None)),
))
defaultFormatOptions = {}
for formatId, formatOptions in self.copyFormats.values():
if formatOptions is None:
continue
defaultFormatOptions[formatId] = self._GetFormatOptions(
{option[0]: option[3] for option in formatOptions})
defaultFormatOptions[formatId] = {opt[0]: opt[3] for opt in formatOptions}
self.settings = SettingsProvider.getInstance().getSettings("pyfaExport", {"format": 0, "options": defaultFormatOptions})
# Overwrite older options format which was plain int storing EFT options
if not isinstance(self.settings["options"], dict):
self.settings["options"] = {CopySelectDialog.copyFormatEft: self.settings["options"]}
self.options = {}
@@ -85,7 +81,7 @@ class CopySelectDialog(wx.Dialog):
for optId, optName, optDesc, optDefault in formatOptions:
checkbox = wx.CheckBox(self, -1, optName)
self.options[formatId][optId] = checkbox
if self.settings['options'].get(formatId, 0) & optId:
if self.settings['options'].get(formatId, {}).get(optId, defaultFormatOptions.get(formatId, {}).get(optId)):
checkbox.SetValue(True)
bsizer.Add(checkbox, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 3)
mainSizer.Add(bsizer, 1, wx.EXPAND | wx.LEFT, 20)
@@ -117,13 +113,5 @@ class CopySelectDialog(wx.Dialog):
def GetOptions(self):
options = {}
for formatId in self.options:
options[formatId] = self._GetFormatOptions(
{optId: ch.IsChecked() for optId, ch in self.options[formatId].items()})
options[formatId] = {optId: ch.IsChecked() for optId, ch in self.options[formatId].items()}
return options
def _GetFormatOptions(self, optMap):
optVal = 0
for optId, optState in optMap.items():
if optState:
optVal = optVal ^ optId
return optVal

View File

@@ -86,14 +86,14 @@ def exportEft(fit, options):
modName = module.baseItem.name
else:
modName = module.item.name
if module.isMutated and options & Options.MUTATIONS.value:
if module.isMutated and options[Options.MUTATIONS.value]:
mutants[mutantReference] = module
mutationSuffix = ' [{}]'.format(mutantReference)
mutantReference += 1
else:
mutationSuffix = ''
modOfflineSuffix = ' {}'.format(OFFLINE_SUFFIX) if module.state == State.OFFLINE else ''
if module.charge and options & Options.LOADED_CHARGES.value:
if module.charge and options[Options.LOADED_CHARGES.value]:
rackLines.append('{}, {}{}{}'.format(
modName, module.charge.name, modOfflineSuffix, mutationSuffix))
else:
@@ -122,7 +122,7 @@ def exportEft(fit, options):
sections.append('\n\n'.join(minionSection))
# Section 3: implants, boosters
if options & Options.IMPLANTS.value:
if options[Options.IMPLANTS.value]:
charSection = []
implantLines = []
for implant in fit.implants:
@@ -149,7 +149,7 @@ def exportEft(fit, options):
# Section 5: mutated modules' details
mutationLines = []
if mutants and options & Options.MUTATIONS.value:
if mutants and options[Options.MUTATIONS.value]:
for mutantReference in sorted(mutants):
mutant = mutants[mutantReference]
mutationLines.append(renderMutant(mutant, firstPrefix='[{}] '.format(mutantReference), prefix=' '))

View File

@@ -48,7 +48,7 @@ def exportMultiBuy(fit, options):
if module.isMutated:
continue
addItem(module.item)
if module.charge and options & Options.LOADED_CHARGES.value:
if module.charge and options[Options.LOADED_CHARGES.value]:
addItem(module.charge, module.numCharges)
for drone in fit.drones:
@@ -57,11 +57,11 @@ def exportMultiBuy(fit, options):
for fighter in fit.fighters:
addItem(fighter.item, fighter.amountActive)
if options & Options.CARGO.value:
if options[Options.CARGO.value]:
for cargo in fit.cargo:
addItem(cargo.item, cargo.amount)
if options & Options.IMPLANTS.value:
if options[Options.IMPLANTS.value]:
for implant in fit.implants:
addItem(implant.item)