osr-editor 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. osr_editor-0.1.0/LICENSE +21 -0
  2. osr_editor-0.1.0/PKG-INFO +137 -0
  3. osr_editor-0.1.0/README.md +108 -0
  4. osr_editor-0.1.0/pyproject.toml +134 -0
  5. osr_editor-0.1.0/src/osreditor/__init__.py +6 -0
  6. osr_editor-0.1.0/src/osreditor/addresses.py +123 -0
  7. osr_editor-0.1.0/src/osreditor/aids.py +932 -0
  8. osr_editor-0.1.0/src/osreditor/app.py +1756 -0
  9. osr_editor-0.1.0/src/osreditor/catalogs.py +208 -0
  10. osr_editor-0.1.0/src/osreditor/config.py +134 -0
  11. osr_editor-0.1.0/src/osreditor/conversions.py +864 -0
  12. osr_editor-0.1.0/src/osreditor/diagnostics.py +285 -0
  13. osr_editor-0.1.0/src/osreditor/documents.py +1797 -0
  14. osr_editor-0.1.0/src/osreditor/errors.py +397 -0
  15. osr_editor-0.1.0/src/osreditor/forge.py +510 -0
  16. osr_editor-0.1.0/src/osreditor/importers/__init__.py +197 -0
  17. osr_editor-0.1.0/src/osreditor/importers/project.py +146 -0
  18. osr_editor-0.1.0/src/osreditor/importers/watabou.py +603 -0
  19. osr_editor-0.1.0/src/osreditor/lint.py +295 -0
  20. osr_editor-0.1.0/src/osreditor/ops.py +740 -0
  21. osr_editor-0.1.0/src/osreditor/overrides.py +957 -0
  22. osr_editor-0.1.0/src/osreditor/projects.py +321 -0
  23. osr_editor-0.1.0/src/osreditor/providers.py +209 -0
  24. osr_editor-0.1.0/src/osreditor/publish.py +138 -0
  25. osr_editor-0.1.0/src/osreditor/py.typed +0 -0
  26. osr_editor-0.1.0/src/osreditor/sidecar.py +309 -0
  27. osr_editor-0.1.0/src/osreditor/static/assets/index-BzGvXxpQ.css +2 -0
  28. osr_editor-0.1.0/src/osreditor/static/assets/index-pa5z1OMB.js +55 -0
  29. osr_editor-0.1.0/src/osreditor/static/index.html +13 -0
  30. osr_editor-0.1.0/src/osreditor/store.py +270 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marsh Macy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: osr-editor
3
+ Version: 0.1.0
4
+ Summary: Local GUI editor for creating and modifying osrlib adventure modules.
5
+ Keywords: bx,osr,ttrpg,adventure-module,dungeon,editor,osrlib,old-school-essentials
6
+ Author: Marsh Macy
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Topic :: Games/Entertainment :: Role-Playing
15
+ Classifier: Typing :: Typed
16
+ Requires-Dist: osrlib>=1.3,<2
17
+ Requires-Dist: osr-forge>=0.1,<0.2
18
+ Requires-Dist: pydantic>=2
19
+ Requires-Dist: pyyaml>=6
20
+ Requires-Dist: fastapi>=0.139
21
+ Requires-Dist: uvicorn>=0.51
22
+ Requires-Dist: platformdirs>=4
23
+ Requires-Python: >=3.14
24
+ Project-URL: Changelog, https://github.com/mmacy/osr-editor/blob/main/CHANGELOG.md
25
+ Project-URL: Documentation, https://mmacy.github.io/osr-editor/
26
+ Project-URL: Issues, https://github.com/mmacy/osr-editor/issues
27
+ Project-URL: Repository, https://github.com/mmacy/osr-editor
28
+ Description-Content-Type: text/markdown
29
+
30
+ # osr-editor
31
+
32
+ A local GUI application for creating and modifying adventure modules playable by [osrlib](https://github.com/mmacy/osrlib-python)-powered games. osr-editor authors the same stamped `adventure.json` documents that [osr-forge](https://github.com/mmacy/osr-forge) produces and [osr-web](https://github.com/mmacy/osr-web) plays: a FastAPI backend that holds the working document as real osrlib model objects, serving a React frontend to the browser.
33
+
34
+ **[Documentation](https://mmacy.github.io/osr-editor/)** · **[PyPI](https://pypi.org/project/osr-editor/)** · **[Changelog](https://github.com/mmacy/osr-editor/blob/main/CHANGELOG.md)**
35
+
36
+ ## Install
37
+
38
+ ```console
39
+ uv tool install osr-editor
40
+ ```
41
+
42
+ Or `pipx install osr-editor`, or `pip install osr-editor`. Python ≥ 3.14; no node toolchain — the published wheel ships the built frontend.
43
+
44
+ ## Quickstart
45
+
46
+ ```console
47
+ osr-editor
48
+ ```
49
+
50
+ The editor serves on `http://127.0.0.1:8630` and opens your browser to the home screen. Pass a project directory to open it straight away — `osr-editor ~/adventures/mill.osr`. The [quickstart](https://mmacy.github.io/osr-editor/getting-started/quickstart/) takes you from launch to a first exported adventure.
51
+
52
+ ## What it does
53
+
54
+ - **[Projects](https://mmacy.github.io/osr-editor/guides/projects/)** — always-saved, canonically serialized, git-friendly project directories; every commit is one undo step, and the document on disk is always the artifact the game engine loads.
55
+ - **[The map editor](https://mmacy.github.io/osr-editor/guides/map-editor/)** — the full geometry tool set on graph paper: rooms, corridors, walls and doors in every state, areas, entrances, transitions, multi-level and multi-dungeon management, and live structural lint with click-to-navigate findings.
56
+ - **[Stocking and keyed content](https://mmacy.github.io/osr-editor/guides/stocking-and-keyed-content/)** — the map-first stocking flow over encounters, treasure, traps, features, and wandering tables, through type-ahead pickers that never author a dangling reference.
57
+ - **[The monster editor](https://mmacy.github.io/osr-editor/guides/monster-editor/)** — full stat-block authoring over the adventure's bundled templates: create from scratch or clone any catalog monster, with renames cascading through every reference.
58
+ - **[Forge-backed review](https://mmacy.github.io/osr-editor/guides/forge-backed-review/)** — open an osr-forge workdir and correct it graphically: the report as a work list beside the source pages, every edit a reasoned `overrides.yaml` entry on forge's own pure assemble loop.
59
+ - **[Converting a PDF](https://mmacy.github.io/osr-editor/guides/converting-a-pdf/)** — the front door to forge's pipeline: price the run first, convert with live progress and cooperative cancel, land in the review queue. No credential is ever written to disk.
60
+ - **[Authoring aids](https://mmacy.github.io/osr-editor/guides/authoring-aids/)** — SRD stocking with seeded, reproducible re-rolls; treasure and encounter previews; and the prose assistant, present only when a provider is configured.
61
+ - **[Import, export, and publish](https://mmacy.github.io/osr-editor/guides/import-export-publish/)** — geometry in from another project or a Watabou One Page Dungeon export (or any installed [importer plugin](https://mmacy.github.io/osr-editor/reference/writing-a-geometry-importer/)); the stamped document out to any path; publish into an osr-web checkout as a live symlink or a snapshot.
62
+
63
+ ## Development
64
+
65
+ Working on the editor itself takes both toolchains: Python ≥ 3.14 with [uv](https://docs.astral.sh/uv/), and Node.js (LTS, see `frontend/.nvmrc`). Build the frontend once, then run the editor from the checkout:
66
+
67
+ ```console
68
+ cd frontend && npm ci && npm run build && cd ..
69
+ uv sync
70
+ uv run osr-editor
71
+ ```
72
+
73
+ The dev loop runs the two halves side by side:
74
+
75
+ ```console
76
+ # terminal one — the backend
77
+ uv run osr-editor --no-browser
78
+
79
+ # terminal two — the frontend with hot reload
80
+ cd frontend && npm run dev
81
+ ```
82
+
83
+ Vite serves the frontend on its own port and proxies `/api` to the backend on 8630.
84
+
85
+ ### The full local gauntlet
86
+
87
+ Everything CI runs, runnable locally:
88
+
89
+ ```console
90
+ # backend
91
+ uv sync --locked
92
+ uv run ruff format --check
93
+ uv run ruff check
94
+ uv run pyright
95
+ uv run pytest
96
+
97
+ # docs
98
+ uv run mkdocs build --strict
99
+
100
+ # frontend (from frontend/)
101
+ npm ci
102
+ npx prettier --check .
103
+ npx eslint .
104
+ npx tsc -b --force
105
+ npx vitest run
106
+ npm run build
107
+
108
+ # generated types (from the repo root; fails CI on drift)
109
+ uv run scripts/generate_types.py
110
+
111
+ # end to end (from frontend/, after npm run build)
112
+ npx tsc -p ../tests/e2e
113
+ npx playwright test
114
+ ```
115
+
116
+ ### Type generation
117
+
118
+ TypeScript types in `frontend/src/types/generated/` are generated from the pydantic models by `uv run scripts/generate_types.py`. Never hand-edit them; CI regenerates and fails on drift.
119
+
120
+ ### Working against unreleased sibling checkouts
121
+
122
+ Dependencies resolve from PyPI. When a phase needs unreleased osrlib or osr-forge surface, flip the dependency to an editable path source in `pyproject.toml` for the duration:
123
+
124
+ ```toml
125
+ [tool.uv.sources]
126
+ osrlib = { path = "../osrlib-python", editable = true }
127
+ ```
128
+
129
+ Revert before merging — CI resolves `uv sync --locked` from PyPI.
130
+
131
+ ### Releasing
132
+
133
+ Releases are tag-driven; the runbook lives in [`AGENTS.md`](https://github.com/mmacy/osr-editor/blob/main/AGENTS.md).
134
+
135
+ ## License
136
+
137
+ MIT. osr-editor ships no game content — osrlib carries the OGL data. Modules you author or convert are yours and stay in your project directories.
@@ -0,0 +1,108 @@
1
+ # osr-editor
2
+
3
+ A local GUI application for creating and modifying adventure modules playable by [osrlib](https://github.com/mmacy/osrlib-python)-powered games. osr-editor authors the same stamped `adventure.json` documents that [osr-forge](https://github.com/mmacy/osr-forge) produces and [osr-web](https://github.com/mmacy/osr-web) plays: a FastAPI backend that holds the working document as real osrlib model objects, serving a React frontend to the browser.
4
+
5
+ **[Documentation](https://mmacy.github.io/osr-editor/)** · **[PyPI](https://pypi.org/project/osr-editor/)** · **[Changelog](https://github.com/mmacy/osr-editor/blob/main/CHANGELOG.md)**
6
+
7
+ ## Install
8
+
9
+ ```console
10
+ uv tool install osr-editor
11
+ ```
12
+
13
+ Or `pipx install osr-editor`, or `pip install osr-editor`. Python ≥ 3.14; no node toolchain — the published wheel ships the built frontend.
14
+
15
+ ## Quickstart
16
+
17
+ ```console
18
+ osr-editor
19
+ ```
20
+
21
+ The editor serves on `http://127.0.0.1:8630` and opens your browser to the home screen. Pass a project directory to open it straight away — `osr-editor ~/adventures/mill.osr`. The [quickstart](https://mmacy.github.io/osr-editor/getting-started/quickstart/) takes you from launch to a first exported adventure.
22
+
23
+ ## What it does
24
+
25
+ - **[Projects](https://mmacy.github.io/osr-editor/guides/projects/)** — always-saved, canonically serialized, git-friendly project directories; every commit is one undo step, and the document on disk is always the artifact the game engine loads.
26
+ - **[The map editor](https://mmacy.github.io/osr-editor/guides/map-editor/)** — the full geometry tool set on graph paper: rooms, corridors, walls and doors in every state, areas, entrances, transitions, multi-level and multi-dungeon management, and live structural lint with click-to-navigate findings.
27
+ - **[Stocking and keyed content](https://mmacy.github.io/osr-editor/guides/stocking-and-keyed-content/)** — the map-first stocking flow over encounters, treasure, traps, features, and wandering tables, through type-ahead pickers that never author a dangling reference.
28
+ - **[The monster editor](https://mmacy.github.io/osr-editor/guides/monster-editor/)** — full stat-block authoring over the adventure's bundled templates: create from scratch or clone any catalog monster, with renames cascading through every reference.
29
+ - **[Forge-backed review](https://mmacy.github.io/osr-editor/guides/forge-backed-review/)** — open an osr-forge workdir and correct it graphically: the report as a work list beside the source pages, every edit a reasoned `overrides.yaml` entry on forge's own pure assemble loop.
30
+ - **[Converting a PDF](https://mmacy.github.io/osr-editor/guides/converting-a-pdf/)** — the front door to forge's pipeline: price the run first, convert with live progress and cooperative cancel, land in the review queue. No credential is ever written to disk.
31
+ - **[Authoring aids](https://mmacy.github.io/osr-editor/guides/authoring-aids/)** — SRD stocking with seeded, reproducible re-rolls; treasure and encounter previews; and the prose assistant, present only when a provider is configured.
32
+ - **[Import, export, and publish](https://mmacy.github.io/osr-editor/guides/import-export-publish/)** — geometry in from another project or a Watabou One Page Dungeon export (or any installed [importer plugin](https://mmacy.github.io/osr-editor/reference/writing-a-geometry-importer/)); the stamped document out to any path; publish into an osr-web checkout as a live symlink or a snapshot.
33
+
34
+ ## Development
35
+
36
+ Working on the editor itself takes both toolchains: Python ≥ 3.14 with [uv](https://docs.astral.sh/uv/), and Node.js (LTS, see `frontend/.nvmrc`). Build the frontend once, then run the editor from the checkout:
37
+
38
+ ```console
39
+ cd frontend && npm ci && npm run build && cd ..
40
+ uv sync
41
+ uv run osr-editor
42
+ ```
43
+
44
+ The dev loop runs the two halves side by side:
45
+
46
+ ```console
47
+ # terminal one — the backend
48
+ uv run osr-editor --no-browser
49
+
50
+ # terminal two — the frontend with hot reload
51
+ cd frontend && npm run dev
52
+ ```
53
+
54
+ Vite serves the frontend on its own port and proxies `/api` to the backend on 8630.
55
+
56
+ ### The full local gauntlet
57
+
58
+ Everything CI runs, runnable locally:
59
+
60
+ ```console
61
+ # backend
62
+ uv sync --locked
63
+ uv run ruff format --check
64
+ uv run ruff check
65
+ uv run pyright
66
+ uv run pytest
67
+
68
+ # docs
69
+ uv run mkdocs build --strict
70
+
71
+ # frontend (from frontend/)
72
+ npm ci
73
+ npx prettier --check .
74
+ npx eslint .
75
+ npx tsc -b --force
76
+ npx vitest run
77
+ npm run build
78
+
79
+ # generated types (from the repo root; fails CI on drift)
80
+ uv run scripts/generate_types.py
81
+
82
+ # end to end (from frontend/, after npm run build)
83
+ npx tsc -p ../tests/e2e
84
+ npx playwright test
85
+ ```
86
+
87
+ ### Type generation
88
+
89
+ TypeScript types in `frontend/src/types/generated/` are generated from the pydantic models by `uv run scripts/generate_types.py`. Never hand-edit them; CI regenerates and fails on drift.
90
+
91
+ ### Working against unreleased sibling checkouts
92
+
93
+ Dependencies resolve from PyPI. When a phase needs unreleased osrlib or osr-forge surface, flip the dependency to an editable path source in `pyproject.toml` for the duration:
94
+
95
+ ```toml
96
+ [tool.uv.sources]
97
+ osrlib = { path = "../osrlib-python", editable = true }
98
+ ```
99
+
100
+ Revert before merging — CI resolves `uv sync --locked` from PyPI.
101
+
102
+ ### Releasing
103
+
104
+ Releases are tag-driven; the runbook lives in [`AGENTS.md`](https://github.com/mmacy/osr-editor/blob/main/AGENTS.md).
105
+
106
+ ## License
107
+
108
+ MIT. osr-editor ships no game content — osrlib carries the OGL data. Modules you author or convert are yours and stay in your project directories.
@@ -0,0 +1,134 @@
1
+ [project]
2
+ name = "osr-editor"
3
+ version = "0.1.0"
4
+ description = "Local GUI editor for creating and modifying osrlib adventure modules."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Marsh Macy" }]
9
+ requires-python = ">=3.14"
10
+ keywords = [
11
+ "bx",
12
+ "osr",
13
+ "ttrpg",
14
+ "adventure-module",
15
+ "dungeon",
16
+ "editor",
17
+ "osrlib",
18
+ "old-school-essentials",
19
+ ]
20
+ # Python :: 3.14 only — the version CI tests (the family rule); no License ::
21
+ # classifier beside the SPDX expression, per PEP 639.
22
+ classifiers = [
23
+ "Development Status :: 4 - Beta",
24
+ "Intended Audience :: Developers",
25
+ "Operating System :: OS Independent",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Games/Entertainment :: Role-Playing",
29
+ "Typing :: Typed",
30
+ ]
31
+ dependencies = [
32
+ "osrlib>=1.3,<2",
33
+ "osr-forge>=0.1,<0.2",
34
+ "pydantic>=2",
35
+ "pyyaml>=6",
36
+ "fastapi>=0.139",
37
+ "uvicorn>=0.51",
38
+ "platformdirs>=4",
39
+ ]
40
+
41
+ [project.scripts]
42
+ osr-editor = "osreditor.app:main"
43
+
44
+ # The geometry importer seam: each entry is a zero-arg callable returning a
45
+ # GeometryImporter instance. The built-in converters register through the same
46
+ # public group any third-party converter uses — dogfooding the seam keeps the
47
+ # protocol honest. A format ships bundled when it is broadly useful,
48
+ # permissively licensed, and parseable with no new dependency; everything else
49
+ # is a separate installable package, and the group stays public either way.
50
+ [project.entry-points."osreditor.importers"]
51
+ project = "osreditor.importers.project:ProjectImporter"
52
+ watabou-opd = "osreditor.importers.watabou:OPDImporter"
53
+
54
+ [project.urls]
55
+ Repository = "https://github.com/mmacy/osr-editor"
56
+ Documentation = "https://mmacy.github.io/osr-editor/"
57
+ Issues = "https://github.com/mmacy/osr-editor/issues"
58
+ Changelog = "https://github.com/mmacy/osr-editor/blob/main/CHANGELOG.md"
59
+
60
+ [dependency-groups]
61
+ dev = [
62
+ "pytest>=8",
63
+ "ruff>=0.11",
64
+ "pyright>=1.1",
65
+ "httpx2>=2.7.0",
66
+ "types-pyyaml>=6",
67
+ { include-group = "docs" },
68
+ ]
69
+ # The documentation site's toolchain; included by dev so `uv sync` stays one
70
+ # command. No mkdocs-gen-files or mkdocs-literate-nav: the editor's reference
71
+ # surface is one seam, not a generated per-module tree, so the nav is
72
+ # hand-written — which also sidesteps the properdocs hazard osrlib pins
73
+ # against (both plugins' next releases depend on an unvetted mkdocs fork).
74
+ docs = [
75
+ "mkdocs>=1.6.1",
76
+ "mkdocs-material>=9.7.6",
77
+ "mkdocstrings[python]>=1.0.4",
78
+ ]
79
+
80
+ [build-system]
81
+ requires = ["uv_build>=0.8.22,<0.9.0"]
82
+ build-backend = "uv_build"
83
+
84
+ # uv_build packages the tree, not the git index: with the frontend built, the
85
+ # gitignored src/osreditor/static/ ships in both artifacts by design — and so
86
+ # would any junk sitting in the tree. These excludes fix the leak at the
87
+ # source; uv_build silently ignores unknown keys here (a typo'd exclude builds
88
+ # clean and excludes nothing), so the dist audit's forbidden-member sweep
89
+ # (scripts/release/check_dist.py) is the guard that would ever notice.
90
+ [tool.uv.build-backend]
91
+ module-name = "osreditor"
92
+ source-exclude = ["**/.DS_Store", "**/Thumbs.db", "**/.AppleDouble", "**/__pycache__"]
93
+ wheel-exclude = ["**/.DS_Store", "**/Thumbs.db", "**/.AppleDouble", "**/__pycache__"]
94
+
95
+ [tool.ruff]
96
+ line-length = 120
97
+ src = ["src", "tests", "scripts"]
98
+
99
+ [tool.ruff.lint]
100
+ select = ["E", "F", "W", "I", "D", "UP", "B", "SIM", "RUF"]
101
+ ignore = [
102
+ "D105", # missing docstring in magic method — __str__ and friends are self-evident
103
+ ]
104
+ # Intentional module notation, not confusable typos: the multiplication sign
105
+ # ("5 × acolyte", matching the frontend) and the en dash osrlib's save-band
106
+ # labels print ("1–3").
107
+ allowed-confusables = ["×", "–"]
108
+
109
+ [tool.ruff.lint.pydocstyle]
110
+ convention = "google"
111
+
112
+ [tool.ruff.lint.per-file-ignores]
113
+ "tests/**" = ["D"]
114
+ "scripts/**" = ["D"]
115
+
116
+ [tool.ruff.lint.isort]
117
+ known-first-party = ["osreditor"]
118
+
119
+ [tool.pyright]
120
+ pythonVersion = "3.14"
121
+ include = ["src", "tests", "scripts"]
122
+ typeCheckingMode = "standard"
123
+ strict = ["src"]
124
+
125
+ # Tests import sibling helper modules bare (osrlib's pattern: `from test_documents
126
+ # import ...` in generator scripts); pytest and direct script runs both put tests/
127
+ # on sys.path, so pyright mirrors that here.
128
+ [[tool.pyright.executionEnvironments]]
129
+ root = "tests"
130
+ extraPaths = ["tests"]
131
+
132
+ [tool.pytest.ini_options]
133
+ testpaths = ["tests"]
134
+ addopts = "-q"
@@ -0,0 +1,6 @@
1
+ """osr-editor: a local GUI application for authoring osrlib adventure modules.
2
+
3
+ The package is the FastAPI backend of the editor: it holds the working document
4
+ as real osrlib model objects, applies typed edit operations, and serves the
5
+ built React frontend. See `docs/spec.md` for the architecture and contracts.
6
+ """
@@ -0,0 +1,123 @@
1
+ """The diagnostics address grammar, built: `/`-joined `kind:value` segments.
2
+
3
+ The grammar was pinned by the validation tier (see
4
+ [`osreditor.diagnostics`][osreditor.diagnostics]): values are percent-encoded
5
+ (RFC 3986, everything reserved) so arbitrary osrlib ids can never make the
6
+ grammar ambiguous. Phase 2 adds two geometry segments, appended after the level
7
+ segment: `cell:<x>,<y>` and `edge:<x>,<y>:<north|west>`. Their values are
8
+ numeric grammar, unambiguous without encoding; the general segment parse rule
9
+ stays "kind is up to the first `:`, value is the remainder". The `edge:`
10
+ segment ships with the grammar (the inspector and hover refs use edge
11
+ addressing) even though no phase 2 finding emits it — `edge_invalid`
12
+ deliberately addresses the level. Phase 4 adds the top-level `monster:<id>`
13
+ segment for bundled monster templates, finer than the bare `monsters` scope
14
+ phase 1 pinned.
15
+
16
+ Three producers build addresses — the validation parser, the structural lint,
17
+ and the `ResizeLevel` offender list — so the builders live here, in one place.
18
+ """
19
+
20
+ from urllib.parse import quote
21
+
22
+ from osrlib.crawl.dungeon import Position
23
+
24
+ __all__ = [
25
+ "area_address",
26
+ "cell_address",
27
+ "dungeon_address",
28
+ "edge_address",
29
+ "encode_value",
30
+ "level_address",
31
+ "monster_address",
32
+ ]
33
+
34
+
35
+ def encode_value(value: str) -> str:
36
+ """Percent-encode an id for the address grammar (RFC 3986, everything reserved).
37
+
38
+ Args:
39
+ value: The raw id.
40
+
41
+ Returns:
42
+ The encoded segment value.
43
+ """
44
+ return quote(value, safe="")
45
+
46
+
47
+ def monster_address(template_id: str) -> str:
48
+ """Build a bundled-monster-template address — a top-level segment kind, phase 4's.
49
+
50
+ Args:
51
+ template_id: The bundled template id.
52
+
53
+ Returns:
54
+ `monster:<id>`.
55
+ """
56
+ return f"monster:{encode_value(template_id)}"
57
+
58
+
59
+ def dungeon_address(dungeon_id: str) -> str:
60
+ """Build a dungeon-scope address.
61
+
62
+ Args:
63
+ dungeon_id: The dungeon id.
64
+
65
+ Returns:
66
+ `dungeon:<id>`.
67
+ """
68
+ return f"dungeon:{encode_value(dungeon_id)}"
69
+
70
+
71
+ def level_address(dungeon_id: str, level_number: int) -> str:
72
+ """Build a level-scope address.
73
+
74
+ Args:
75
+ dungeon_id: The dungeon id.
76
+ level_number: The 1-based level number.
77
+
78
+ Returns:
79
+ `dungeon:<id>/level:<n>`.
80
+ """
81
+ return f"{dungeon_address(dungeon_id)}/level:{level_number}"
82
+
83
+
84
+ def area_address(dungeon_id: str, level_number: int, area_id: str) -> str:
85
+ """Build an area-scope address.
86
+
87
+ Args:
88
+ dungeon_id: The dungeon id.
89
+ level_number: The 1-based level number.
90
+ area_id: The area id.
91
+
92
+ Returns:
93
+ `dungeon:<id>/level:<n>/area:<id>`.
94
+ """
95
+ return f"{level_address(dungeon_id, level_number)}/area:{encode_value(area_id)}"
96
+
97
+
98
+ def cell_address(dungeon_id: str, level_number: int, cell: Position) -> str:
99
+ """Build a cell-scope address.
100
+
101
+ Args:
102
+ dungeon_id: The dungeon id.
103
+ level_number: The 1-based level number.
104
+ cell: The cell.
105
+
106
+ Returns:
107
+ `dungeon:<id>/level:<n>/cell:<x>,<y>`.
108
+ """
109
+ return f"{level_address(dungeon_id, level_number)}/cell:{cell[0]},{cell[1]}"
110
+
111
+
112
+ def edge_address(dungeon_id: str, level_number: int, edge_key: str) -> str:
113
+ """Build an edge-scope address from a canonical edge key.
114
+
115
+ Args:
116
+ dungeon_id: The dungeon id.
117
+ level_number: The 1-based level number.
118
+ edge_key: The canonical edge key (`x,y:north|west`).
119
+
120
+ Returns:
121
+ `dungeon:<id>/level:<n>/edge:<x>,<y>:<side>`.
122
+ """
123
+ return f"{level_address(dungeon_id, level_number)}/edge:{edge_key}"