Files
Pal3.Unity/tools/tests/test-format-csharp.py
Jiaqi Liu 4cabbd03a7 Implement native PAL3/PAL3A effects and editing tools (#93)
* Implement original PAL3 effects and editor with formatting checks

* Add native PAL3A effect playback and SPar diagnostics

Enable shared playback for supported PAL3A groups with POL models, model opacity, and explosive geometry. Parse SPar resources for complete dependency diagnostics while retaining whole-group private fallback for pending simulation.

Preserve the last effect position when actors are missing or removed in both games, and keep actor-specific shape changes and private fallback guarded. Expand the editor and viewer to both variants and fix opaque alpha for RGB TGA textures.

Validation: PAL3/PAL3A effect suites 54/54 each; general regressions 278/278 and 295/295. Both-variant formatting and diff checks passed.

* Implement native SPar playback and PAL3A transport effects

Add SPar emitter simulation, native blending and billboard rendering for the
remaining 26 script/scene groups. Restore PAL3A transport geometry and seven
styles in game, the editor and ResourceViewer.

Preserve native live-state initial-frame behavior and mark the runtime UV
table non-serialized. Update the README and add format, playback, geometry
and resource-lifetime regression coverage.

Validation: targeted tests 106/106 for both variants; general regressions
PAL3 293/293 and PAL3A 310/310. Both-variant formatting checks passed.

* Remove prefab effect fallback and simplify effect editing
2026-11-14 22:33:13 +08:00

103 lines
5.5 KiB
Python

#!/usr/bin/env python3
# ------------------------------------------------------------------------
# Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
# See LICENSE file in the project root for license information.
# ------------------------------------------------------------------------
"""Exercise layout fixes, change boundaries and read-only checks with Roslyn."""
import os
from pathlib import Path
import shutil
import runpy
import subprocess
import sys
import tempfile
ROOT = Path(__file__).resolve().parents[2]
def run(command, cwd, success=True):
result = subprocess.run(command, cwd=cwd, capture_output=True, text=True, timeout=180,
env={**os.environ, "TMPDIR": str(cwd)})
if (result.returncode == 0) != success:
raise AssertionError(f"Unexpected exit {result.returncode}: {command}\n{result.stdout}\n{result.stderr}")
return result.stdout + result.stderr
def main():
select = runpy.run_path(str(ROOT / "tools/format-csharp.py"))["select_formatting"]
legacy = b"int A;\r\n\r\nint B;\r\n"
changed = legacy.replace(b"int B", b"int B")
formatted = b"int A;\r\n\r\nint B;\r\n"
assert select(legacy, changed, formatted) == legacy
assert select(legacy, legacy, formatted) == legacy
assert select(None, changed, formatted) == formatted
assert select(legacy.replace(b"\r\n", b"\n"), changed.replace(b"\r\n", b"\n"), formatted) == legacy.replace(b"\r\n", b"\n")
assert select(legacy, legacy[:-2], formatted) == legacy, "Newly removed final newline was missed"
assert select(legacy, legacy.replace(b";\r\n\r\n", b";\r\n"), formatted) == legacy
workspace = ROOT.parent / "workspace"
temporary_root = workspace / "Tooling" / "CodeStyle" if workspace.is_dir() else None
if temporary_root is not None:
temporary_root.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="pal3-format-test-", dir=temporary_root) as directory:
fixture = Path(directory)
(fixture / "tools").mkdir()
for name in (".editorconfig", "global.json", "tools/format-csharp.py"):
shutil.copy2(ROOT / name, fixture / name)
source = fixture / "Assets/Scripts/Effect layout.cs"
source.parent.mkdir(parents=True)
good = ("internal sealed class Layout\n{\n#if PAL3\n"
" public int AOne() => 1;\n\n public int ATwo() => 2;\n"
"#elif PAL3A\n public int BOne() => 1;\n\n public int BTwo() => 2;\n#endif\n}\n")
source.write_bytes(good.replace("\n", "\r\n").encode())
plugin = fixture / "Assets/Plugins/Keep.cs"
plugin.parent.mkdir()
plugin.write_bytes(b"class Plugin{void One(){}void Two(){}}")
plugin_before = plugin.read_bytes()
run(["git", "init", "--quiet"], fixture)
run(["git", "add", "."], fixture)
run(["git", "-c", "user.name=Format fixture", "-c", "user.email=fixture@localhost",
"-c", "commit.gpgsign=false", "commit", "--quiet", "-m", "Fixture baseline"], fixture)
base = run(["git", "rev-parse", "HEAD"], fixture).strip()
command = [sys.executable, "tools/format-csharp.py"]
source.write_bytes(good.replace(";\n\n", ";\n").replace("\n", "\r\n").encode())
before = source.read_bytes()
output = run([*command, "--check"], fixture, success=False)
assert "Formatting required:" in output, output
assert source.read_bytes() == before, "Check mode modified the source"
run(command, fixture)
fixed = source.read_bytes()
assert b"AOne() => 1;\r\n\r\n" in fixed
assert b"BOne() => 1;\r\n\r\n" in fixed
run([*command, "--check", "--all"], fixture)
assert source.read_bytes() == fixed, "Formatting is not stable"
# A violation only in PAL3A must fail the same --base mode as PR CI.
source.write_bytes(fixed.replace(b"BOne() => 1;\r\n\r\n", b"BOne() => 1;\r\n"))
output = run([*command, "--check", "--base", base], fixture, success=False)
assert "Formatting required:" in output, output
run(command, fixture)
# Keep inherited formatting outside the edit, even in the same file.
legacy = fixture / "Assets/Scripts/Legacy.cs"
legacy.write_bytes(b"class Legacy\r\n{\r\n int Untouched;\r\n\r\n int Changed;\r\n}\r\n")
run(["git", "add", "."], fixture)
run(["git", "-c", "user.name=Format fixture", "-c", "user.email=fixture@localhost",
"-c", "commit.gpgsign=false", "commit", "--quiet", "-m", "Legacy baseline"], fixture)
legacy.write_bytes(legacy.read_bytes().replace(b"int Changed", b"int Changed"))
before = legacy.read_bytes()
run([*command, "--check"], fixture, success=False)
assert legacy.read_bytes() == before, "Changed-line check modified the source"
run(command, fixture)
assert b"int Untouched;" in legacy.read_bytes(), "Inherited formatting was changed"
assert b"int Changed;" in legacy.read_bytes(), "Modified line was not formatted"
run([*command, "--check"], fixture)
# Explicit paths still provide an intentional whole-file format/audit.
run([*command, "--check", str(legacy.relative_to(fixture))], fixture, success=False)
assert plugin.read_bytes() == plugin_before, "Third-party source was modified"
print("Passed: both variants fix member gaps, checks are read-only, --base checks PAL3A, inherited formatting and plugins stay untouched, explicit paths audit whole files.")
if __name__ == "__main__":
main()