From d55d6c3e5e53412714380b670486eb127119f3d3 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Feb 2019 13:14:31 +0300 Subject: [PATCH] Rework the way options are stored --- gui/copySelectDialog.py | 24 ++++++------------------ service/port/eft.py | 8 ++++---- service/port/multibuy.py | 6 +++--- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 6ead8c44a..49ebb6ac1 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -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 diff --git a/service/port/eft.py b/service/port/eft.py index 9c48dd1d0..4c0d1c6a8 100644 --- a/service/port/eft.py +++ b/service/port/eft.py @@ -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=' ')) diff --git a/service/port/multibuy.py b/service/port/multibuy.py index d31b9f33a..1c6b78836 100644 --- a/service/port/multibuy.py +++ b/service/port/multibuy.py @@ -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)