From 5fe757aaf1ebcdb1d98753c0deb551e0249172b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20K=C5=82ysz?= Date: Mon, 23 Nov 2026 14:48:47 +0000 Subject: [PATCH] feat(map): adding a shared map turns on the editor-runtime mod it needs A shared map whose objects move or stand for their look, or that has cutscenes, needs the editor-runtime mod, which only the editor's Play turned on. Adding such a map as a planet now installs the mod in the game's mods folder and turns it on in the player's list; their other mods stay as they were. --- openrac/tools/openrac_editor.py | 51 ++++++++++++++++++++++------ openrac/tools/shared_map.py | 19 +++++++++++ openrac/tools/test_openrac_editor.py | 14 ++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/openrac/tools/openrac_editor.py b/openrac/tools/openrac_editor.py index b0c935b7..64cb69e7 100644 --- a/openrac/tools/openrac_editor.py +++ b/openrac/tools/openrac_editor.py @@ -485,24 +485,55 @@ def play_plugins(data: Path, runtime: Path = RUNTIME) -> Path | None: (DATA/plugins, where the launcher keeps the player's), and a list beside the player's plugins.json, which it leaves as it is, with that mod on. None when this editor carries no built mod (a checkout, not a download).""" - if not (runtime / "openrac-mod.json").is_file(): + if not install_runtime(data, runtime): return None folder = data / "plugins" - installed = folder / RUNTIME_ID + play = folder / PLAY_LIST + write_mod_list(play, with_runtime(read_mod_list(folder / "plugins.json"))) + return play + + +def install_runtime(data: Path, runtime: Path = RUNTIME) -> bool: + """The editor's mod brought up to date in DATA/plugins; False when this editor carries no built + mod (a checkout, not a download).""" + if not (runtime / "openrac-mod.json").is_file(): + return False + installed = data / "plugins" / RUNTIME_ID if not same_tree(runtime, installed): if installed.exists(): shutil.rmtree(installed) shutil.copytree(runtime, installed) - mods: list = [] + return True + + +def read_mod_list(path: Path) -> list: try: - listed = json.loads((folder / "plugins.json").read_text(encoding="utf-8")) - mods = [m for m in listed.get("mods", []) if isinstance(m, dict)] + listed = json.loads(path.read_text(encoding="utf-8")) + return [m for m in listed.get("mods", []) if isinstance(m, dict)] except (OSError, ValueError, AttributeError): - pass - mods = [m for m in mods if m.get("id") != RUNTIME_ID] + [{"id": RUNTIME_ID, "enabled": True}] - play = folder / PLAY_LIST - play.write_text(json.dumps({"format": 1, "mods": mods}, indent=2) + "\n", encoding="utf-8", newline="\n") - return play + return [] + + +def with_runtime(mods: list) -> list: + return [m for m in mods if m.get("id") != RUNTIME_ID] + [{"id": RUNTIME_ID, "enabled": True}] + + +def write_mod_list(path: Path, mods: list) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps({"format": 1, "mods": mods}, indent=2) + "\n", encoding="utf-8", newline="\n") + + +def turn_on_runtime(data: Path, runtime: Path = RUNTIME) -> bool: + """For a planet that needs it (a shared map's): the editor's mod installed in DATA/plugins and + on in the player's own list (plugins.json), their other mods as they were. False when this + editor carries no built mod.""" + if not install_runtime(data, runtime): + return False + listed = data / "plugins" / "plugins.json" + mods = read_mod_list(listed) + if {"id": RUNTIME_ID, "enabled": True} not in mods: + write_mod_list(listed, with_runtime(mods)) + return True def same_tree(a: Path, b: Path) -> bool: diff --git a/openrac/tools/shared_map.py b/openrac/tools/shared_map.py index 3ae83983..4c75f591 100644 --- a/openrac/tools/shared_map.py +++ b/openrac/tools/shared_map.py @@ -724,6 +724,19 @@ def import_map(path: Path, projects: Path, disc_path: Path | None = None) -> dic # COMMAND LINE # ============================================================================= +def needs_runtime(project: Path, level: int) -> bool: + """Whether PROJECT's level has what only the editor-runtime mod plays: simple moves (objects + of other levels brought for their look among them) or cutscenes.""" + import behaviours + level_dir = project / "levels" / f"level_{level:02}" + scene = level_dir / f"level_{level:02}.tscn" + try: + moves = behaviours.given(scene.read_text(encoding="utf-8")) + except OSError: + moves = [] + return bool(moves) or (level_dir / "cutscenes").is_dir() + + def main(argv=None) -> int: parser = argparse.ArgumentParser(prog="openrac_editor.py map", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -782,6 +795,12 @@ def main(argv=None) -> int: raise FormatError(str(exc), code=planet.code_of(exc)) from exc print(f"Added it to your mods as the planet {added['name']}: turn on Mods, board the ship " "and pick it in the ship's menu.") + if needs_runtime(done["project"], done["level"]): + import openrac_editor + if openrac_editor.turn_on_runtime(args.planet.resolve().parent): + print("Turned on the editor-runtime mod: this map's moving objects and cutscenes need it.") + else: + print(" check: this map needs the editor-runtime mod: turn it on in Mods.") print(f"openrac-output: {done['project']}") return 0 except (MapError, planet.PlanetError, FormatError, OSError, struct.error, zipfile.BadZipFile) as exc: diff --git a/openrac/tools/test_openrac_editor.py b/openrac/tools/test_openrac_editor.py index 61344d78..dbe521dd 100644 --- a/openrac/tools/test_openrac_editor.py +++ b/openrac/tools/test_openrac_editor.py @@ -286,6 +286,20 @@ def test_play_turns_the_editors_mod_on_and_keeps_the_players(self): oe.play_plugins(data, runtime) self.assertEqual((data / "plugins" / "editor-runtime" / "lib" / "editor_runtime.so").read_bytes(), b"v2") + def test_a_map_that_needs_it_turns_the_editors_mod_on_in_the_players_list(self): + with tempfile.TemporaryDirectory() as tmp: + runtime = Path(tmp) / "editor" / "mods" / "editor-runtime" + runtime.mkdir(parents=True) + (runtime / "openrac-mod.json").write_text('{"id": "editor-runtime"}') + data = Path(tmp) / "data" + self.assertFalse(oe.turn_on_runtime(data, Path(tmp) / "nothing")) + (data / "plugins").mkdir(parents=True) + (data / "plugins" / "plugins.json").write_text('{"format": 1, "mods": [{"id": "lock-strafe", "enabled": true}]}') + self.assertTrue(oe.turn_on_runtime(data, runtime)) + self.assertEqual(json.loads((data / "plugins" / "plugins.json").read_text())["mods"], + [{"id": "lock-strafe", "enabled": True}, {"id": "editor-runtime", "enabled": True}]) + self.assertTrue((data / "plugins" / "editor-runtime" / "openrac-mod.json").is_file()) + def test_on_a_mac_the_game_draws_with_vulkan_like_the_launcher(self): with mock.patch.object(oe.sys, "platform", "darwin"), mock.patch.dict(oe.os.environ, {}, clear=True): self.assertEqual(oe.game_environment()["OPENRAC_GL_API"], "vulkan")