Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion openrac/tools/map_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

def export_map(packed: Path, project: Path, out: Path, name: str, level: int,
spawn: list[float] | None = None, heading: float | None = None, skip_movies: bool = True,
skip_cutscenes: bool = True, destination: bool = False, map_id: str | None = None) -> dict:
skip_cutscenes: bool = True, destination: bool = False, map_id: str | None = None,
author: str = "", description: str = "") -> dict:
"""Only copies inputs; never changes the editor project, packed files or an existing export."""
packed, project, out = Path(packed), Path(project), Path(out)
if out.exists():
Expand All @@ -32,6 +33,11 @@ def export_map(packed: Path, project: Path, out: Path, name: str, level: int,
"game": "rac1", "version": note["version"], "name": name,
"map": {"level": level, "spawn": spawn, "heading": heading, "skip_movies": skip_movies,
"skip_cutscenes": skip_cutscenes}}
# What the launcher's Mods list shows under the name.
if author.strip():
manifest["author"] = author.strip()[:80]
if description.strip():
manifest["description"] = description.strip()[:300]
prefix = f"level_{level:02}"
# The level's project, the folder of every level's project (--split), or the level folder itself.
level_dir = next((p for p in (project / "levels" / prefix, project / prefix / "levels" / prefix,
Expand Down
20 changes: 19 additions & 1 deletion openrac/tools/planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from __future__ import annotations

import openrac_root # noqa: F401,I001 (OpenRAC's extractor on the import path)
import json
import re
import secrets
import tempfile
Expand Down Expand Up @@ -165,6 +166,21 @@ def level_of(project: Path) -> int:
return found[0]


def map_note(project: Path) -> tuple[str, str]:
"""The author and the line about the map a shared map's import keeps (.openrac/map.json),
else the author the project's settings name."""
note = {}
try:
note = json.loads((project / ".openrac" / "map.json").read_text(encoding="utf-8"))
except (OSError, ValueError):
pass
if not isinstance(note, dict):
note = {}
author = note.get("author") if isinstance(note.get("author"), str) else ""
about = note.get("about") if isinstance(note.get("about"), str) else ""
return author or settings(project).get("map/author", "").strip(), about


def add_planet(disc, survey: dict, project: Path, into: Path) -> dict:
"""Packs PROJECT's level, exports it as a new planet and installs it in the launcher's packs
folder INTO: what was done, for the report."""
Expand All @@ -184,7 +200,9 @@ def add_planet(disc, survey: dict, project: Path, into: Path) -> dict:
if refused:
raise PlanetError("Some edits could not be packed:\n" + "\n".join(f" {line}" for line in refused), INCOMPLETE)
out = Path(temp) / "planet"
manifest = export_map(packed, project, out, name, level, destination=True, map_id=ident)
author, about = map_note(project)
manifest = export_map(packed, project, out, name, level, destination=True, map_id=ident,
author=author, description=about)
installed, _, _ = overrides.add(out, into)
return {"name": name, "id": ident, "installed": installed, "level": level, "report": report,
"spawn": manifest["map"]["spawn"]}
5 changes: 4 additions & 1 deletion openrac/tools/shared_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ def by_id(text: str) -> str:
def find(key: str):
return next((b for b in blocks if key_of(b) == key), None)

# A copy names the section it was made from as the level has it, which may be one the map
# removes (a model kept only for its copies).
pristine_by = {key_of(b): b for b in blocks if key_of(b) is not None}
for key in changes.get("removed", []):
gone = find(key)
if gone is None:
Expand All @@ -370,7 +373,7 @@ def find(key: str):
continue
block = carry.Block(by_id(entry["head"]))
if "base" in entry:
base = find(entry["base"])
base = find(entry["base"]) or pristine_by.get(entry["base"])
if base is None:
problems.append(f"{entry['key'][5:]}: copies {entry['base'][5:]}, which this level lacks")
continue
Expand Down
13 changes: 13 additions & 0 deletions openrac/tools/test_shared_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ def test_removed_node_and_a_change_for_a_missing_node(self):
self.assertEqual(len(problems), 1)


def test_a_copy_of_a_removed_node(self):
# The model is removed and only its moved copy stays: the copy still comes back.
head, rest = SCENE.split('[node name="Bolt_0011"')
text = head + '[node name="Bolt_0011_2"' + rest.replace("139, 229, 31", "160, 227, 40")
changes = shared_map.scene_changes(SCENE, text)
self.assertEqual(changes["removed"], ["node:Game/Mobys/Bolt_0011"])
problems = []
made = shared_map.apply_scene_changes(SCENE, changes, problems)
self.assertEqual(problems, [])
self.assertNotIn('name="Bolt_0011"', made)
self.assertIn("[9, 9, 9", made.split('name="Bolt_0011_2"')[1])


def project(root: Path, level: int, files: dict) -> Path:
folder = root / f"level_{level:02}"
for rel, data in files.items():
Expand Down
Loading