From b5201637f8d6d045a52c8c1a3d548e04adc055b5 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Mon, 24 Oct 2022 12:29:05 -0300 Subject: Recursively fix all XMLs --- merge-client.py | 84 +++++++++++++++++++++++++++++++-------------------------- 1 file 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 "" 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 "" in item_db[-1]: item_db=item_db[:-1] @@ -225,7 +233,7 @@ with open("%s/items.xml" % EVOLVED, "r") as f: if "" 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 "" in l: saving=True continue - l=hp(l, EVOLVED, 'tmw') + l=transverse(l, EVOLVED, 'tmw') item_db.append(l) while not "" in item_db[-1]: item_db=item_db[:-1] @@ -271,7 +279,7 @@ with open("%s/items.xml" % REVOLT, "r") as f: if "" 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 "" in l: saving=True continue - l=hp(l, REVOLT, 're') + l=transverse(l, REVOLT, 're') item_db.append(l) while not "" in item_db[-1]: item_db=item_db[:-1] -- cgit v1.2.3-70-g09d2