Skip to content

Commit

Permalink
Merge pull request #2561 from m-sasha/abyssal-xml
Browse files Browse the repository at this point in the history
Add mutation info to XML export/import.
  • Loading branch information
DarkFenX authored Feb 20, 2024
2 parents 612591b + 6ed34be commit e2dbfb5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
22 changes: 15 additions & 7 deletions service/port/muta.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@

def renderMutant(mutant, firstPrefix='', prefix=''):
exportLines = []
exportLines.append('{}{}'.format(firstPrefix, mutant.baseItem.name))
exportLines.append('{}{}'.format(prefix, mutant.mutaplasmid.item.name))
exportLines.append('{}{}'.format(prefix, renderMutantAttrs(mutant)))
return '\n'.join(exportLines)


def renderMutantAttrs(mutant):
mutatedAttrs = {}
for attrID, mutator in mutant.mutators.items():
attrName = getAttributeInfo(attrID).name
mutatedAttrs[attrName] = mutator.value
exportLines.append('{}{}'.format(firstPrefix, mutant.baseItem.name))
exportLines.append('{}{}'.format(prefix, mutant.mutaplasmid.item.name))
customAttrsLine = ', '.join(
return ', '.join(
'{} {}'.format(a, floatUnerr(mutatedAttrs[a]))
for a in sorted(mutatedAttrs))
exportLines.append('{}{}'.format(prefix, customAttrsLine))
return '\n'.join(exportLines)


def parseMutant(lines):
Expand All @@ -64,8 +67,13 @@ def parseMutant(lines):
mutationsLine = lines[2]
except IndexError:
return baseItem, mutaplasmidItem, {}
mutations = parseMutantAttrs(mutationsLine)
return baseItem, mutaplasmidItem, mutations


def parseMutantAttrs(line):
mutations = {}
pairs = [p.strip() for p in mutationsLine.split(',')]
pairs = [p.strip() for p in line.split(',')]
for pair in pairs:
try:
attrName, value = pair.split(' ')
Expand All @@ -79,7 +87,7 @@ def parseMutant(lines):
if attrInfo is None:
continue
mutations[attrInfo.ID] = value
return baseItem, mutaplasmidItem, mutations
return mutations


def parseDynamicItemString(text):
Expand Down
58 changes: 52 additions & 6 deletions service/port/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from logbook import Logger

from eos.const import FittingModuleState, FittingSlot
from eos.db import getDynamicItem
from eos.saveddata.cargo import Cargo
from eos.saveddata.citadel import Citadel
from eos.saveddata.drone import Drone
Expand All @@ -34,7 +35,8 @@
from gui.fitCommands.helpers import activeStateLimit
from service.fit import Fit as svcFit
from service.market import Market
from service.port.shared import IPortUser, processing_notify
from service.port.muta import renderMutantAttrs, parseMutantAttrs
from service.port.shared import IPortUser, processing_notify, fetchItem
from utils.strfunctions import replace_ltgt, sequential_rep


Expand Down Expand Up @@ -115,7 +117,7 @@ def _resolve_ship(fitting, sMkt, b_localized):

def _resolve_module(hardware, sMkt, b_localized):
# type: (xml.dom.minidom.Element, service.market.Market, bool) -> eos.saveddata.module.Module
moduleName = hardware.getAttribute("type")
moduleName = hardware.getAttribute("base_type") or hardware.getAttribute("type")
emergency = None
if b_localized:
try:
Expand All @@ -142,7 +144,14 @@ def _resolve_module(hardware, sMkt, b_localized):
must_retry = True
if not must_retry:
break
return item

mutaplasmidName = hardware.getAttribute("mutaplasmid")
mutaplasmidItem = fetchItem(mutaplasmidName) if mutaplasmidName else None

mutatedAttrsText = hardware.getAttribute("mutated_attrs")
mutatedAttrs = parseMutantAttrs(mutatedAttrsText) if mutatedAttrsText else None

return item, mutaplasmidItem, mutatedAttrs


def importXml(text, iportuser):
Expand Down Expand Up @@ -185,12 +194,25 @@ def importXml(text, iportuser):
moduleList = []
for hardware in hardwares:
try:
item = _resolve_module(hardware, sMkt, b_localized)
item, mutaItem, mutaAttrs = _resolve_module(hardware, sMkt, b_localized)
if not item or not item.published:
continue

if item.category.name == "Drone":
d = Drone(item)
d = None
if mutaItem:
mutaplasmid = getDynamicItem(mutaItem.ID)
if mutaplasmid:
try:
d = Drone(mutaplasmid.resultingItem, item, mutaplasmid)
except ValueError:
pass
else:
for attrID, mutator in d.mutators.items():
if attrID in mutaAttrs:
mutator.value = mutaAttrs[attrID]
if d is None:
d = Drone(item)
d.amount = int(hardware.getAttribute("qty"))
fitobj.drones.append(d)
elif item.category.name == "Fighter":
Expand All @@ -205,8 +227,21 @@ def importXml(text, iportuser):
c.amount = int(hardware.getAttribute("qty"))
fitobj.cargo.append(c)
else:
m = None
try:
m = Module(item)
if mutaItem:
mutaplasmid = getDynamicItem(mutaItem.ID)
if mutaplasmid:
try:
m = Module(mutaplasmid.resultingItem, item, mutaplasmid)
except ValueError:
pass
else:
for attrID, mutator in m.mutators.items():
if attrID in mutaAttrs:
mutator.value = mutaAttrs[attrID]
if m is None:
m = Module(item)
# When item can't be added to any slot (unknown item or just charge), ignore it
except ValueError:
pyfalog.warning("item can't be added to any slot (unknown item or just charge), ignore it")
Expand Down Expand Up @@ -254,6 +289,11 @@ def exportXml(fits, iportuser, callback):
fittings.setAttribute("count", "%s" % fit_count)
doc.appendChild(fittings)

def addMutantAttributes(node, mutant):
node.setAttribute("base_type", mutant.baseItem.name)
node.setAttribute("mutaplasmid", mutant.mutaplasmid.item.name)
node.setAttribute("mutated_attrs", renderMutantAttrs(mutant))

for i, fit in enumerate(fits):
try:
fitting = doc.createElement("fitting")
Expand Down Expand Up @@ -303,6 +343,9 @@ def exportXml(fits, iportuser, callback):
slotName = FittingSlot(slot).name.lower()
slotName = slotName if slotName != "high" else "hi"
hardware.setAttribute("slot", "%s slot %d" % (slotName, slotId))
if module.isMutated:
addMutantAttributes(hardware, module)

fitting.appendChild(hardware)

if module.charge:
Expand All @@ -316,6 +359,9 @@ def exportXml(fits, iportuser, callback):
hardware.setAttribute("qty", "%d" % drone.amount)
hardware.setAttribute("slot", "drone bay")
hardware.setAttribute("type", drone.item.name)
if drone.isMutated:
addMutantAttributes(hardware, drone)

fitting.appendChild(hardware)

for fighter in fit.fighters:
Expand Down

0 comments on commit e2dbfb5

Please sign in to comment.