Fix importing damage profiles which included overwriting existing ones and then performing a delete on one of them. #1416
This commit is contained in:
@@ -18,12 +18,16 @@
|
|||||||
# ===============================================================================
|
# ===============================================================================
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import eos.db
|
||||||
|
|
||||||
|
|
||||||
class DamagePattern(object):
|
class DamagePattern(object):
|
||||||
DAMAGE_TYPES = ("em", "thermal", "kinetic", "explosive")
|
DAMAGE_TYPES = ("em", "thermal", "kinetic", "explosive")
|
||||||
|
|
||||||
def __init__(self, emAmount=25, thermalAmount=25, kineticAmount=25, explosiveAmount=25):
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.update(*args, **kwargs)
|
||||||
|
|
||||||
|
def update(self, emAmount=25, thermalAmount=25, kineticAmount=25, explosiveAmount=25):
|
||||||
self.emAmount = emAmount
|
self.emAmount = emAmount
|
||||||
self.thermalAmount = thermalAmount
|
self.thermalAmount = thermalAmount
|
||||||
self.kineticAmount = kineticAmount
|
self.kineticAmount = kineticAmount
|
||||||
@@ -74,6 +78,14 @@ class DamagePattern(object):
|
|||||||
lines = re.split('[\n\r]+', text)
|
lines = re.split('[\n\r]+', text)
|
||||||
patterns = []
|
patterns = []
|
||||||
numPatterns = 0
|
numPatterns = 0
|
||||||
|
|
||||||
|
# When we import damage profiles, we create new ones and update old ones. To do this, get a list of current
|
||||||
|
# patterns to allow lookup
|
||||||
|
lookup = {}
|
||||||
|
current = eos.db.getDamagePatternList()
|
||||||
|
for pattern in current:
|
||||||
|
lookup[pattern.name] = pattern
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
try:
|
try:
|
||||||
if line.strip()[0] == "#": # comments
|
if line.strip()[0] == "#": # comments
|
||||||
@@ -99,10 +111,18 @@ class DamagePattern(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if len(fields) == 4: # Avoid possible blank lines
|
if len(fields) == 4: # Avoid possible blank lines
|
||||||
pattern = DamagePattern(**fields)
|
if name.strip() in lookup:
|
||||||
pattern.name = name.strip()
|
pattern = lookup[name.strip()]
|
||||||
|
pattern.update(**fields)
|
||||||
|
eos.db.save(pattern)
|
||||||
|
else:
|
||||||
|
pattern = DamagePattern(**fields)
|
||||||
|
pattern.name = name.strip()
|
||||||
|
eos.db.save(pattern)
|
||||||
patterns.append(pattern)
|
patterns.append(pattern)
|
||||||
|
|
||||||
|
eos.db.commit()
|
||||||
|
|
||||||
return patterns, numPatterns
|
return patterns, numPatterns
|
||||||
|
|
||||||
EXPORT_FORMAT = "DamageProfile = %s,%d,%d,%d,%d\n"
|
EXPORT_FORMAT = "DamageProfile = %s,%d,%d,%d,%d\n"
|
||||||
|
|||||||
@@ -72,21 +72,9 @@ class DamagePattern(object):
|
|||||||
eos.db.save(p)
|
eos.db.save(p)
|
||||||
|
|
||||||
def importPatterns(self, text):
|
def importPatterns(self, text):
|
||||||
lookup = {}
|
|
||||||
current = self.getDamagePatternList()
|
|
||||||
for pattern in current:
|
|
||||||
lookup[pattern.name] = pattern
|
|
||||||
|
|
||||||
imports, num = es_DamagePattern.importPatterns(text)
|
imports, num = es_DamagePattern.importPatterns(text)
|
||||||
for pattern in imports:
|
|
||||||
if pattern.name in lookup:
|
|
||||||
match = lookup[pattern.name]
|
|
||||||
match.__dict__.update(pattern.__dict__)
|
|
||||||
else:
|
|
||||||
eos.db.save(pattern)
|
|
||||||
eos.db.commit()
|
|
||||||
|
|
||||||
lenImports = len(imports)
|
lenImports = len(imports)
|
||||||
|
|
||||||
if lenImports == 0:
|
if lenImports == 0:
|
||||||
raise ImportError("No patterns found for import")
|
raise ImportError("No patterns found for import")
|
||||||
if lenImports != num:
|
if lenImports != num:
|
||||||
|
|||||||
Reference in New Issue
Block a user