WIP: feat(modapi): game.flags and flagChanged take a mod's content flags by their ids (":Seen") #2572

Closed
ChloeNow wants to merge 1032 commits from ChloeNow/Longshot:feat/modapi-rs-flags-by-id into mod-api
Contributor

Summary

The runtime takes a mod's content by its id (items.grant(":Rupee7")), but its flags only by their game names. A mod
that declares a flag with content.flag({ id: "Seen" }) has to write "M1a2b3c4d.Seen" everywhere it uses it: the
FNV-1a hash of its own id, worked out by hand. content.md lists :id for flags as not yet.

Now game.flags.get, has and set, and flagChanged's filter, take a mod's content flags by their ids, as the rest
of the runtime takes its content:

flagChanged.on((e) => log.info(`${e.flag}: ${e.value}`), { flag: ":ChestOpened" });   // e.flag: "M37444242.ChestOpened"
flags.set(":ChestOpened", 1);
flags.get("other/mod:Seen");                                                           // another mod's
  • ":id" is the calling mod's own flag, "owner/name:id" another mod's; each is read as the game name content.flag
    makes (content::plan::word and the id). A game name is taken as it is. A mod's tests, which the game runs as
    tests:<id>, name its flags as the mod does.
  • flagChanged tells the flag's game name in e.flag, whichever way the listener named it: the filter is kept as the
    game name when the listener subscribes, so it matches the event.
  • A name with a : that names no flag (no id after it, an id that is not a declaration's) is UnknownNameError;
    has() is false.
  • The test game's flag() and setFlag() take the same names.

Read first: flag_name and flag_watch_refused in game/crates/api/src/services/game.rs, then watch_refused in
game/crates/script/src/runtime.rs and its caller in script/src/bind/mod.rs (api_on: the filter the hook hands
back is the one kept). The fake game: _flagName in lib/fake-game.js, services.js, and the kept filter in
lib/prelude.js.

This is #2287's change, made again on the Rust mod API; #2287 (the C mod API) can close. Part of #1958's Modding API;
targets mod-api.

Testing

Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. In the game: a mod's own test (dev.py game-tests, the repository's kokiri-start, a quick build of this head) passes: the mod reads its content flag as ":Seen" (0, has true, ":9Seen" refused with UnknownNameError), sets it (game.flags.set Mf7b05380.Seen 0 -> 1 in the log), flagChanged tells Mf7b05380.Seen 0 -> 1, and the test's game.flag(":Seen") reads 1 (a mod's tests, run as tests:<id>, name its flags as the mod does). Checks:
cargo test -p api -p script (api's flag_name against an FNV-1a written out in the test: a game name, the mod's own,
another's, six names refused; script's service hooks keeping a :id filter as its game name); mod-tools'
test/flags-by-id.test.mjs (a mod reads, writes and watches its flag as ":Seen" in the fake game, e.flag its game
name, bad names refused); cargo run -p schema-gen -- --check; rustfmt. The same two api loader tests and five
mod-tools tests fail on mod-api itself (a_content_mods_changed_module_runs_again_and_its_outputs_are_served,
the_note_goes_when_the_list_is_the_game_folders_or_not_there; mod-tools' 59, 69, 73, 86 and 100) and here.

Still to test:

  • Linux, and clippy with warnings as errors: mise run rust and mise run test (by hand, or CI)

Measurements

Nothing to measure: a name without a : costs one search for it; a :id name is one FNV-1a over the mod's id per call, and flagChanged names it once, at on().

Risks

A game flag's name never holds a :, so no name that worked before reads anything else now. A filter given as :id
tells e.flag as the game name, which a listener comparing e.flag to the text it gave would not expect: the docs and
the record's doc say so.

Checklist

Ready for review

  • One topic, on current mod-api; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary The runtime takes a mod's content by its id (`items.grant(":Rupee7")`), but its flags only by their game names. A mod that declares a flag with `content.flag({ id: "Seen" })` has to write `"M1a2b3c4d.Seen"` everywhere it uses it: the FNV-1a hash of its own id, worked out by hand. `content.md` lists `:id` for flags as not yet. Now `game.flags.get`, `has` and `set`, and `flagChanged`'s filter, take a mod's content flags by their ids, as the rest of the runtime takes its content: ```ts flagChanged.on((e) => log.info(`${e.flag}: ${e.value}`), { flag: ":ChestOpened" }); // e.flag: "M37444242.ChestOpened" flags.set(":ChestOpened", 1); flags.get("other/mod:Seen"); // another mod's ``` - `":id"` is the calling mod's own flag, `"owner/name:id"` another mod's; each is read as the game name `content.flag` makes (`content::plan::word` and the id). A game name is taken as it is. A mod's tests, which the game runs as `tests:<id>`, name its flags as the mod does. - `flagChanged` tells the flag's game name in `e.flag`, whichever way the listener named it: the filter is kept as the game name when the listener subscribes, so it matches the event. - A name with a `:` that names no flag (no id after it, an id that is not a declaration's) is `UnknownNameError`; `has()` is false. - The test game's `flag()` and `setFlag()` take the same names. Read first: `flag_name` and `flag_watch_refused` in `game/crates/api/src/services/game.rs`, then `watch_refused` in `game/crates/script/src/runtime.rs` and its caller in `script/src/bind/mod.rs` (`api_on`: the filter the hook hands back is the one kept). The fake game: `_flagName` in `lib/fake-game.js`, `services.js`, and the kept filter in `lib/prelude.js`. This is #2287's change, made again on the Rust mod API; #2287 (the C mod API) can close. Part of #1958's Modding API; targets `mod-api`. ## Testing **Tested:** Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. In the game: a mod's own test (`dev.py game-tests`, the repository's `kokiri-start`, a quick build of this head) passes: the mod reads its content flag as `":Seen"` (0, `has` true, `":9Seen"` refused with `UnknownNameError`), sets it (`game.flags.set Mf7b05380.Seen 0 -> 1` in the log), `flagChanged` tells `Mf7b05380.Seen 0 -> 1`, and the test's `game.flag(":Seen")` reads 1 (a mod's tests, run as `tests:<id>`, name its flags as the mod does). Checks: `cargo test -p api -p script` (api's `flag_name` against an FNV-1a written out in the test: a game name, the mod's own, another's, six names refused; script's service hooks keeping a `:id` filter as its game name); mod-tools' `test/flags-by-id.test.mjs` (a mod reads, writes and watches its flag as `":Seen"` in the fake game, `e.flag` its game name, bad names refused); `cargo run -p schema-gen -- --check`; rustfmt. The same two `api` loader tests and five mod-tools tests fail on `mod-api` itself (`a_content_mods_changed_module_runs_again_and_its_outputs_are_served`, `the_note_goes_when_the_list_is_the_game_folders_or_not_there`; mod-tools' 59, 69, 73, 86 and 100) and here. **Still to test:** - Linux, and clippy with warnings as errors: `mise run rust` and `mise run test` (by hand, or CI) ## Measurements Nothing to measure: a name without a `:` costs one search for it; a `:id` name is one FNV-1a over the mod's id per call, and `flagChanged` names it once, at `on()`. ## Risks A game flag's name never holds a `:`, so no name that worked before reads anything else now. A filter given as `:id` tells `e.flag` as the game name, which a listener comparing `e.flag` to the text it gave would not expect: the docs and the record's doc say so. ## Checklist ### Ready for review - [x] One topic, on current `mod-api`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). <!-- Windows run as Testing says; clippy and Linux: CI --> - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. <!-- Windows built and played; Linux: CI --> - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(modapi): game.flags and flagChanged take a mod's content flags by their ids (":Seen")
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
51b9f4172b
The runtime takes a mod's content by its id (items.grant(":Rupee7")), but its flags only by their game names: a mod
wrote "M1a2b3c4d.Seen", the FNV-1a hash of its own id worked out by hand. content.md listed ":id" for flags as not yet.

game.flags.get, has and set, and flagChanged's filter, now take ":Seen", the calling mod's own flag, and
"owner/name:Seen", another mod's, read as the game name content.flag makes (content::plan::word and the id). A game
name is taken as it is; a name with a ":" that names no flag (no id after it, an id that is not a declaration's) is
UnknownNameError, and has() is false. A mod's tests, which the game runs as "tests:<id>", name its flags as the mod
does.

api::services::game::flag_name names it. flagChanged keeps a ":id" filter as its game name, so the event's flag (its
game name, whichever way the listener named it) matches it: flag_watch_refused, and the script host's watch_refused
hook, may answer with the filter the host keeps in place of the one given (script::bind's api_on). The fake game names
them the same way (lib/fake-game.js _flagName, services.js; its subscribe answers with the filter kept, which
lib/prelude.js matches on), and the test game's flag() and setFlag() take them.

Tests: api's flag_name against an FNV-1a written out in the test (a game name, the mod's own, another's, six names
refused); script's service hooks keeping a ":id" filter as its game name; mod-tools' test/flags-by-id.test.mjs (a mod
reads, writes and watches its flag as ":Seen" in the fake game, e.flag the game name, bad names refused).

This replaces #2287, which made the same change to the C mod API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24, a quick build of this head (longshot-builder, mod-api's builder with main's Windows lock fixes applied locally, not in this PR). A mod's own test through dev.py game-tests from the repository's kokiri-start passes (1 passed, 0 failed): it reads its content flag as ":Seen" (0; ":9Seen" refused with UnknownNameError), sets it (game.flags.set Mf7b05380.Seen 0 -> 1), flagChanged tells changed Mf7b05380.Seen 0 -> 1, and the test's game.flag(":Seen") reads 1.

Tested in game: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24, a quick build of this head (longshot-builder, mod-api's builder with main's Windows lock fixes applied locally, not in this PR). A mod's own test through dev.py game-tests from the repository's kokiri-start passes (1 passed, 0 failed): it reads its content flag as ":Seen" (0; ":9Seen" refused with UnknownNameError), sets it (game.flags.set Mf7b05380.Seen 0 -> 1), flagChanged tells changed Mf7b05380.Seen 0 -> 1, and the test's game.flag(":Seen") reads 1.
Author
Contributor

Moved to #2657: the same flags by id on the current mod-api (rewritten since), on a new branch so the PR is only this change.

Moved to #2657: the same flags by id on the current mod-api (rewritten since), on a new branch so the PR is only this change.
ChloeNow closed this pull request 2026-11-27 09:48:55 +00:00
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2572
No description provided.