Parse previous brick family indices to retain compatibility

merge/2021-11-19
kaetemi 4 years ago
parent 68eb9149df
commit 3cf8ca0959
No known key found for this signature in database
GPG Key ID: 9873C4D40BB479BC

@ -0,0 +1,79 @@
import os, re
sbrickPath = "R:\\leveldesign\\game_element\\sbrick"
familyExpr = r"\"FamilyId\"[^\"]+\"[^\"]+\""
indexExpr = r"\"IndexInFamily\"[^\"]+\"[^\"]+\""
sitemExpr = r"\"[^\"]+.sitem\""
fileMap = {}
def listPathExt(path, ext):
for p in os.listdir(path):
fp = path + "\\" + p
if os.path.isdir(fp):
listPathExt(fp, ext)
elif os.path.isfile(fp):
if fp.lower().endswith(ext):
fileMap[p] = fp
listPathExt(sbrickPath, ".sbrick")
sbrickMap = {}
for sbrick in fileMap:
contents = ""
name = sbrick.split(".")[0].lower()
with open(fileMap[sbrick], "r") as f:
contents = f.read()
familyId = re.findall(familyExpr, contents)[0].split('"')[-2]
indexInFamily = re.findall(indexExpr, contents)
if len(indexInFamily) > 0:
indexInFamily = indexInFamily[0].split('"')[-2]
else:
indexInFamily = ""
indexNumeric = len(indexInFamily) > 0 and indexInFamily.isdigit()
if not indexNumeric and len(indexInFamily) > 0 and indexInFamily != "$filename":
print(name + ", IndexInFamily: " + indexInFamily)
if not indexNumeric and name.startswith(familyId.lower()):
indexInFamily = name[len(familyId):]
indexNumeric = len(indexInFamily) > 0 and indexInFamily.isdigit()
if not indexNumeric:
if name[-4:].isdigit():
indexInFamily = name[-4:]
elif name[-3:].isdigit():
indexInFamily = name[-3:]
elif name[-2:].isdigit():
indexInFamily = name[-2:]
indexNumeric = len(indexInFamily) > 0 and indexInFamily.isdigit()
if not indexNumeric:
print(name + ", IndexInFamily: " + indexInFamily)
sitem = re.findall(sitemExpr, contents)
if len(sitem) > 0:
sitem = sitem[0].split('"')[-2].split(".")[0]
else:
sitem = ""
#print(familyId)
#print(indexInFamily)
#print(name)
#print(sitem)
templateName = familyId.lower() + str(int(indexInFamily)).zfill(2)
entryName = familyId + str(int(indexInFamily)).zfill(4) + name
entry = [ familyId, indexInFamily ]
if name != templateName:
entry += [ name ]
if sitem != templateName and sitem != name:
entry += [ sitem ]
sbrickMap[entryName] = entry
w = open("sbrick_index.tsv", "w")
sbrickKeys = sbrickMap.keys()
sbrickKeys.sort()
for k in sbrickKeys:
w.write("\t".join(sbrickMap[k]) + "\n")
w.flush()
w.close()

@ -511,6 +511,8 @@ def generateSitems():
if "armor" in tags and "caster" in tags and not "pants" in tags:
continue # Only include caster pants
if "armor" in tags and "refugee" in tags:
continue # No need to generate these for now
print(path)
with open(path, "w") as f:
@ -546,6 +548,10 @@ def generateSitems():
f.write(" </STRUCT>\n")
f.write("</FORM>\n")
f.flush()
# TODO: Find the best parent sheet
# TODO: Extract the sbrick identifiers
# TODO: Generate the sbrick
generateParents()
generateSitems()

@ -4,3 +4,4 @@
- Run extract_shapes.py to list all shapes into shape_list.txt
- Run scheme_shape_parser.py to generate shape_parsed from shape_list.txt excluding _mission_ shapes
- Run sitem_shape_matcher.py to generate match_sitem_shape.tsv from shape_parsed.tsv and sitem_parsed.tsv
- Run generate_sitem.py to generate sitems from the tsv

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save