evo/tools/waves_n42.py

126 lines
3.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Волна N+42: vfbuild75 — 42 EF в up.java (render, renderBlood, renderSoul ×2).
Запуск: python3 tools/waves_n42.py"""
import os, re, sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
p = os.path.join(ROOT, "src/main/java/defpackage/up.java")
L = open(p, encoding="utf-8", errors="replace").read().splitlines()
ok = True
def edit(ln, *names):
global ok
i = ln - 1
new = L[i]
for name in names:
new = re.sub(rf"\b{name}\b", name + "f", new)
if new != L[i]:
L[i] = new
else:
ok = False
print(f"MISS {ln}: none of {names} in {L[i].strip()[:90]!r}")
def insert_before(ln, anchor_prev, anchor_next, decls):
global ok
ip = ln - 1
prev_ok = anchor_prev in L[ip - 1]
next_ok = anchor_next in L[ip]
done = decls[0] in "\n".join(L[max(0, ip - 12) : ip + 10])
if prev_ok and next_ok and not done:
line = L[ip]
indent = line[: len(line) - len(line.lstrip())]
L[ip:ip] = [indent + d for d in decls]
elif done:
pass
else:
ok = False
print(
f"INSERT-MISS {ln}: prev={L[ip - 1].strip()[:70]!r} next={L[ip].strip()[:70]!r}"
)
# --- edits (descending) ---
# Region D: renderSoul, 2nd lambda (drawBox)
edit(2958, "var14")
edit(2957, "var13")
for ln in (2956, 2955, 2954, 2953, 2952, 2951, 2950, 2949):
edit(ln, "var20")
# Region C: renderSoul, 1st lambda (emitBoltSegment)
edit(2881, "var15")
edit(2877, "var11")
edit(2875, "var6")
edit(2874, "var6")
edit(2873, "var6")
# Region B: renderBlood lambda
for ln, name in (
(2682, "var16"),
(2681, "var15"),
(2680, "var14"),
(2679, "var13"),
(2678, "var12"),
(2677, "var11"),
):
edit(ln, name)
# Region A: render lambda (drawBox ×2)
edit(2180, "var15")
edit(2179, "var10")
for ln in (2178, 2177, 2176, 2175, 2174):
edit(ln, "var16")
edit(2173, "var19")
edit(2172, "var18")
edit(2171, "var17")
edit(2166, "var17", "var18", "var19", "var16", "var10", "var15")
# --- inserts (descending) ---
insert_before(
2943,
"var2.translate(var20.centerXPx() * 0.0625F, var20.centerYPx() * 0.0625F, 0.0F);",
"var3.submitCustomGeometry(",
[
"final float var13f = var13;",
"final float var14f = var14;",
"final um var20f = var20;",
],
)
insert_before(
2843,
"var15 = var9;",
"var3.submitCustomGeometry(",
[
"final float var6f = var6;",
"final float var11f = var11;",
"final float var15f = var15;",
],
)
insert_before(
2617,
"case 1921332157:",
"var3.submitCustomGeometry(",
[
"final float var11f = var11;",
"final float var12f = var12;",
"final float var13f = var13;",
"final float var14f = var14;",
"final float var15f = var15;",
"final float var16f = var16;",
],
)
insert_before(
2162,
"var19 = var16.depthPx() * 0.0625F * 0.5F;",
"var3.submitCustomGeometry(",
[
"final int var10f = var10;",
"final int var15f = var15;",
"final um var16f = var16;",
"final float var17f = var17;",
"final float var18f = var18;",
"final float var19f = var19;",
],
)
open(p, "w", encoding="utf-8").write("\n".join(L) + "\n")
print("OK" if ok else "PROBLEMS")
sys.exit(0 if ok else 1)