From 19f0bbc811d197c71751f61e7cf3e075f13d1ac9 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 4 May 2014 19:15:25 -0400 Subject: [PATCH] Add cargo support to XML, DNA, EFT import/export --- eos/saveddata/fit.py | 75 +++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 54960b4bb..92f00b985 100755 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -175,11 +175,9 @@ class Fit(object): d.amount = int(amount) f.drones.append(d) elif item.category.name == "Charge": - for i in xrange(int(amount)): - for mod in f.modules: - if (mod.isValidCharge(item) and mod.charge == None): - mod.charge = item - break; + c = Cargo(item) + c.amount = int(amount) + f.cargo.append(c) else: for i in xrange(int(amount)): try: @@ -217,9 +215,10 @@ class Fit(object): # maintain map of drones and their quantities droneMap = {} + cargoMap = {} for i in range(1, len(lines)): ammoName = None - droneAmount = None + extraAmount = None line = lines[i].strip() if not line: @@ -240,7 +239,7 @@ class Fit(object): modName = modAmmo[0].strip() elif len(modExtra) == 2: # line with drone/cargo and qty - droneAmount = modExtra[1].strip() + extraAmount = modExtra[1].strip() modName = modExtra[0].strip() else: # line with just module @@ -249,17 +248,20 @@ class Fit(object): try: # get item information. If we are on a Drone/Cargo line, throw out cargo item = db.getItem(modName, eager="group.category") - if len(modExtra) == 2 and item.category.name != "Drone": - continue except: # if no data can be found (old names) continue if item.category.name == "Drone": - droneAmount = int(droneAmount) if droneAmount is not None else 1 + extraAmount = int(extraAmount) if extraAmount is not None else 1 if not modName in droneMap: droneMap[modName] = 0 - droneMap[modName] += droneAmount + droneMap[modName] += extraAmount + if len(modExtra) == 2 and item.category.name != "Drone": + extraAmount = int(extraAmount) if extraAmount is not None else 1 + if not modName in cargoMap: + cargoMap[modName] = 0 + cargoMap[modName] += extraAmount elif item.category.name == "Implant": fit.implants.append(Implant(item)) else: @@ -287,6 +289,11 @@ class Fit(object): d.amount = droneMap[droneName] fit.drones.append(d) + for cargoName in cargoMap: + c = Cargo(db.getItem(cargoName)) + c.amount = cargoMap[cargoName] + fit.cargo.append(c) + return fit @classmethod @@ -328,10 +335,12 @@ class Fit(object): f.name = fitLines[0][1:-1] # Assign ship to fitting f.ship = Ship(db.getItem(shipname)) + for i in range(1, len(fitLines)): line = fitLines[i] # Parse line into some data we will need misc = re.match("(Drones|Implant|Booster)_(Active|Inactive)=(.+)",line) + cargo = re.match("Cargohold=(.+)",line) if misc: entityType = misc.group(1) entityState = misc.group(2) @@ -388,6 +397,19 @@ class Fit(object): b.active = False f.boosters.append(b) # If we don't have any prefixes, then it's a module + elif cargo: + cargoData = re.match("(.+),([0-9]+)", cargo.group(1)) + cargoName = cargoData.group(1) if cargoData else cargo.group(1) + cargoAmount = int(cargoData.group(2)) if cargoData else 1 + # Bail if we can't get item + try: + item = db.getItem(cargoName) + except: + continue + # Add Cargo to the fitting + c = Cargo(item) + c.amount = cargoAmount + f.cargo.append(c) else: withCharge = re.match("(.+),(.+)", line) modName = withCharge.group(1) if withCharge else line @@ -397,6 +419,7 @@ class Fit(object): modItem = db.getItem(modName) except: continue + # Create module and activate it if it's activable m = Module(modItem) if m.isValidState(State.ACTIVE): @@ -448,7 +471,10 @@ class Fit(object): d = Drone(item) d.amount = int(hardware.getAttribute("qty")) f.drones.append(d) - elif item.category.name == "Charge": + elif hardware.getAttribute("slot").lower() == "cargo": + # although the eve client only support charges in cargo, third-party programs + # may support items or "refits" in cargo. Support these by blindly adding all + # cargo, not just charges c = Cargo(item) c.amount = int(hardware.getAttribute("qty")) f.cargo.append(c) @@ -495,6 +521,9 @@ class Fit(object): export += "\n\n" for drone in self.drones: export += "%s x%s\n" % (drone.item.name, drone.amount) + if len(self.cargo) > 0: + for cargo in self.cargo: + export += "%s x%s\n" % (cargo.item.name, cargo.amount) if export[-1] == "\n": export = export[:-1] @@ -535,6 +564,17 @@ class Fit(object): for drone in self.drones: dna += ":{0};{1}".format(drone.itemID, drone.amount) + for cargo in self.cargo: + # DNA format is a simple/dumb format. As CCP uses the slot information of the item itself + # without designating slots in the DNA standard, we need to make sure we only include + # charges in the DNA export. If modules were included, the EVE Client will interpret these + # as being "Fitted" to whatever slot they are for, and it causes an corruption error in the + # client when trying to save the fit + if cargo.item.category.name == "Charge": + if not cargo.item.ID in charges: + charges[cargo.item.ID] = 0 + charges[cargo.item.ID] += cargo.amount + for charge in charges: dna += ":{0};{1}".format(charge, charges[charge]) @@ -586,6 +626,11 @@ class Fit(object): hardware.setAttribute("type", drone.item.name) fitting.appendChild(hardware) + for cargo in fit.cargo: + if not cargo.item.name in charges: + charges[cargo.item.name] = 0 + charges[cargo.item.name] += cargo.amount + for name, qty in charges.items(): hardware = doc.createElement("hardware") hardware.setAttribute("qty", "%d" % qty) @@ -593,12 +638,6 @@ class Fit(object): hardware.setAttribute("type", name) fitting.appendChild(hardware) - for cargo in fit.cargo: - hardware = doc.createElement("hardware") - hardware.setAttribute("qty", "%d" % cargo.amount) - hardware.setAttribute("slot", "cargo") - hardware.setAttribute("type", cargo.item.name) - fitting.appendChild(hardware) return doc.toprettyxml() @reconstructor