diff options
author | Jesusaves <cpntb1@ymail.com> | 2022-10-24 12:29:05 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2022-10-24 12:29:05 -0300 |
commit | b5201637f8d6d045a52c8c1a3d548e04adc055b5 (patch) | |
tree | bc80321398fcd187ea1ad24f3ff182a130602a0a | |
parent | 7a8e6b39722d3568358b9a0c3b2a6226bf9e680b (diff) | |
download | tools-b5201637f8d6d045a52c8c1a3d548e04adc055b5.tar.gz tools-b5201637f8d6d045a52c8c1a3d548e04adc055b5.tar.bz2 tools-b5201637f8d6d045a52c8c1a3d548e04adc055b5.tar.xz tools-b5201637f8d6d045a52c8c1a3d548e04adc055b5.zip |
Recursively fix all XMLs
-rwxr-xr-x | merge-client.py | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/merge-client.py b/merge-client.py index 33f2f44..394b93d 100755 --- a/merge-client.py +++ b/merge-client.py @@ -25,11 +25,49 @@ def fix_id(l, offset): l="\"".join(tmp) return l +## This was foked from transverse() +def subxml(WHERE, e, sub): + global MYSELF, paths + pt="NO PATH FOUND" + if os.path.exists("%s/%s" % (WHERE, e)): + pt = "%s/%s" % (WHERE, e) + TARG = "%s/%s/%s" % (MYSELF, sub, e) + elif os.path.exists("%s/graphics/sprites/%s" % (WHERE, e)): + pt = "%s/graphics/sprites/%s" % (WHERE, e) + TARG = "%s/graphics/sprites/%s/%s" % (MYSELF, sub, e) + elif os.path.exists("%s/graphics/%s" % (WHERE, e)): + pt = "%s/graphics/%s" % (WHERE, e) + TARG = "%s/graphics/%s/%s" % (MYSELF, sub, e) + else: + print("\033[1mNO path: %s\033[0m" % e) + + if pt != "NO PATH FOUND": + bf=[] + with open(pt, 'r') as j: + for k in j: + h=k.split("\"") + for g, n in enumerate(h): + if n.split("|")[0].endswith(".png"): + paths.append(n.split("|")[0]) + h[g]="%s/%s" % (sub, n) + ## XML might need to fall in a loop + elif n.split("|")[0].endswith(".xml"): + h[g]="%s/%s" % (sub, n) + subxml(WHERE, n.split("|")[0], sub) + bf.append("\"".join(h)) + + ## Unfortunately, we must save 'bf' here so it is safely done + os.makedirs(os.path.abspath("/".join(TARG.split("/")[:-1])), exist_ok=True) + with open("%s" % (TARG), "w") as j: + for k in bf: + j.write(k) + return + ## This is to find misc files and copy them over with new path ## TODO: sfx makes it confuse (has "quotes" but is enclosed in >arrows<) ## ALSO: Dyed items e.g. "equipment/chest/cottonshirt.png|W" ## ALSO: Sprites may have "quotes" but be enclosed in >arrows< -def hp(l, WHERE, sub): +def transverse(l, WHERE, sub): global paths if "<include" in l: return l @@ -66,37 +104,7 @@ def hp(l, WHERE, sub): tmpi[i]="%s/%s" % (sub, raw) ## We must also open the XML and extract paths from it - - pt="NO PATH FOUND" - if os.path.exists("%s/%s" % (WHERE, e)): - pt = "%s/%s" % (WHERE, e) - TARG = "%s/%s/%s" % (MYSELF, sub, e) - elif os.path.exists("%s/graphics/sprites/%s" % (WHERE, e)): - pt = "%s/graphics/sprites/%s" % (WHERE, e) - TARG = "%s/graphics/sprites/%s/%s" % (MYSELF, sub, e) - elif os.path.exists("%s/graphics/%s" % (WHERE, e)): - pt = "%s/graphics/%s" % (WHERE, e) - TARG = "%s/graphics/%s/%s" % (MYSELF, sub, e) - else: - print("\033[1mNO path: %s\033[0m" % e) - - if pt != "NO PATH FOUND": - bf=[] - with open(pt, 'r') as j: - for k in j: - h=k.split("\"") - for g, n in enumerate(h): - ## TODO: Dye - if n.split("|")[0].endswith(".png"): - paths.append(n.split("|")[0]) - h[g]="%s/%s" % (sub, n) - bf.append("\"".join(h)) - - ## Unfortunately, we must save 'bf' here so it is safely done - os.makedirs(os.path.abspath("/".join(TARG.split("/")[:-1])), exist_ok=True) - with open("%s" % (TARG), "w") as j: - for k in bf: - j.write(k) + subxml(WHERE, e, sub) ## Update the line if ori == 0: @@ -184,12 +192,12 @@ with open("%s/items.xml" % MOUBOO, "r") as f: continue if "</items>" in j: break - j=hp(j, MOUBOO, 'ml') + j=transverse(j, MOUBOO, 'ml') item_db.append(j) continue ## Save the line - l=hp(l, MOUBOO, 'ml') + l=transverse(l, MOUBOO, 'ml') item_db.append(l) while not "</items>" in item_db[-1]: item_db=item_db[:-1] @@ -225,7 +233,7 @@ with open("%s/items.xml" % EVOLVED, "r") as f: if "</items>" in j: break j=fix_id(j, 10000) - j=hp(j, EVOLVED, 'tmw') + j=transverse(j, EVOLVED, 'tmw') item_db.append(j) continue @@ -234,7 +242,7 @@ with open("%s/items.xml" % EVOLVED, "r") as f: if "<items>" in l: saving=True continue - l=hp(l, EVOLVED, 'tmw') + l=transverse(l, EVOLVED, 'tmw') item_db.append(l) while not "</items>" in item_db[-1]: item_db=item_db[:-1] @@ -271,7 +279,7 @@ with open("%s/items.xml" % REVOLT, "r") as f: if "</items>" in j: break j=fix_id(j, 20000) - j=hp(j, REVOLT, 're') + j=transverse(j, REVOLT, 're') item_db.append(j) continue @@ -280,7 +288,7 @@ with open("%s/items.xml" % REVOLT, "r") as f: if "<items>" in l: saving=True continue - l=hp(l, REVOLT, 're') + l=transverse(l, REVOLT, 're') item_db.append(l) while not "</items>" in item_db[-1]: item_db=item_db[:-1] |