Script to update references to renamed bricks and phrases

merge/2021-11-19
kaetemi 3 years ago
parent d79f103525
commit 5117fd742b
No known key found for this signature in database
GPG Key ID: 9873C4D40BB479BC

@ -0,0 +1,83 @@
import os, re
def loadTsv(filename):
table = []
with open(filename, "r") as f:
for l in f:
table += [ l.strip().split("\t") ]
return table;
sbrickIndex = loadTsv("sbrick_index.tsv")
sbrickRename = {}
sbrickRename2 = {}
for sbrick in sbrickIndex:
name = sbrick[2]
oldNames = filter(None, sbrick[3:])
for n in oldNames:
sbrickRename["\\b" + n + "\\b"] = name
sbrickRename["\\ba" + n + "\\b"] = "a" + name
sbrickRename2["\\b" + n + "\\.sbrick\\b"] = name + ".sbrick"
sbrickRename2["\\ba" + n + "\\.sphrase\\b"] = "a" + name + ".sphrase"
#print(sbrickRename)
def fixFile(file):
print(file)
text = None
with open(file, "r") as f:
text = f.read()
for oldName in sbrickRename:
newName = sbrickRename[oldName]
text = re.sub(oldName, newName, text)
with open(file, "w") as f:
f.write(text)
f.flush()
def fixDir(path):
for p in os.listdir(path):
fp = path + "\\" + p
if os.path.isdir(fp):
fixDir(fp)
elif os.path.isfile(fp):
fixFile(fp)
def fixFile2(file):
print(file)
text = None
with open(file, "r") as f:
text = f.read()
for oldName in sbrickRename2:
newName = sbrickRename2[oldName]
text = re.sub(oldName, newName, text)
with open(file, "w") as f:
f.write(text)
f.flush()
def fixDir2(path):
for p in os.listdir(path):
fp = path + "\\" + p
if os.path.isdir(fp):
fixDir2(fp)
elif os.path.isfile(fp):
fixFile2(fp)
fixFile(r"R:\leveldesign\translation\work\sbrick_words_wk.txt")
fixFile(r"R:\leveldesign\translation\work\sphrase_words_wk.txt")
fixFile(r"R:\leveldesign\translation\translated\sbrick_words_de.txt")
fixFile(r"R:\leveldesign\translation\translated\sbrick_words_en.txt")
fixFile(r"R:\leveldesign\translation\translated\sbrick_words_es.txt")
fixFile(r"R:\leveldesign\translation\translated\sbrick_words_fr.txt")
fixFile(r"R:\leveldesign\translation\translated\sbrick_words_ru.txt")
fixFile(r"R:\leveldesign\translation\translated\sbrick_words_wk.txt")
fixFile(r"R:\leveldesign\translation\translated\sphrase_words_de.txt")
fixFile(r"R:\leveldesign\translation\translated\sphrase_words_en.txt")
fixFile(r"R:\leveldesign\translation\translated\sphrase_words_es.txt")
fixFile(r"R:\leveldesign\translation\translated\sphrase_words_fr.txt")
fixFile(r"R:\leveldesign\translation\translated\sphrase_words_ru.txt")
fixFile(r"R:\leveldesign\translation\translated\sphrase_words_wk.txt")
fixDir2(r"R:\leveldesign\game_elem\createperso")

@ -1,3 +1,4 @@
# Generate sitem, sbrick, and sphrase
- Run extract_palette.py to generate sitem_list.txt and creature_list.txt from the R2 palette - Run extract_palette.py to generate sitem_list.txt and creature_list.txt from the R2 palette
- Run extract_parents.py to generate the parents txt files from the above, and missing sheets - Run extract_parents.py to generate the parents txt files from the above, and missing sheets
- Run scheme_sitem_parser.py to generate sitem_parsed.tsv from sitem_list.txt minus missing_sheets.txt - Run scheme_sitem_parser.py to generate sitem_parsed.tsv from sitem_list.txt minus missing_sheets.txt
@ -6,3 +7,7 @@
- Run sitem_shape_matcher.py to generate match_sitem_shape.tsv from shape_parsed.tsv and sitem_parsed.tsv - Run sitem_shape_matcher.py to generate match_sitem_shape.tsv from shape_parsed.tsv and sitem_parsed.tsv
- Run extract_sbrick.py to generate the sbrick_index.tsv to ensure indices are correctly reused - Run extract_sbrick.py to generate the sbrick_index.tsv to ensure indices are correctly reused
- Run generate_sitem.py to generate sitems from the tsv - Run generate_sitem.py to generate sitems from the tsv
# Fix renamed sbrick
- Run extract_sbrick.py to update sbrick_index.tsv with the current bricks
- Run fix_rename_sbrick.py to rename sbrick and sphrase in leveldesign if their name changed

Loading…
Cancel
Save