"""Change world.rotate without losing every map's position. python tools/retilt.py 35 `place` coordinates live in the ROTATED frame, so changing the tilt would otherwise move every map. This converts each `place` back through the old rotation and forward through the new one, then writes both the new angle and the converted coordinates to maps.json. Geography is preserved; only the tilt changes. Re-run `tools/place_preview.py` afterwards to check, then `tools/build.py --tiles-only` to retile. """ from __future__ import annotations import json import sys from common import CONFIG, load_config, rotate_point, unrotate_point def main() -> None: if len(sys.argv) != 2: raise SystemExit(__doc__) new_deg = float(sys.argv[1]) cfg = load_config() old_deg = cfg.rotate bw, bh = cfg.base_size() if abs(new_deg - old_deg) < 1e-9: print(f"rotate is already {old_deg}; nothing to do") return raw = json.loads(CONFIG.read_text(encoding="utf-8")) print(f"rotate {old_deg} -> {new_deg} (base {bw}x{bh})\n") print(f"{'map':<18} {'old cx,cy':>14} {'new cx,cy':>14}") for m in raw["maps"]: p = m.get("place") if not p: continue sx, sy = unrotate_point(p["cx"], p["cy"], bw, bh, old_deg) nx, ny = rotate_point(sx, sy, bw, bh, new_deg) print(f"{m['id']:<18} {p['cx']:>6.0f},{p['cy']:>6.0f} {nx:>6.0f},{ny:>6.0f}") p["cx"], p["cy"] = round(nx), round(ny) raw["world"]["rotate"] = new_deg CONFIG.write_text(json.dumps(raw, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") print(f"\nwrote {CONFIG.name}; now run place_preview.py and build.py --tiles-only") if __name__ == "__main__": main()