WIP: feat(modapi): game.flags and flagChanged take a mod's content flags by their ids (":Seen") #2572
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2572
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-rs-flags-by-id"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The runtime takes a mod's content by its id (
items.grant(":Rupee7")), but its flags only by their game names. A modthat declares a flag with
content.flag({ id: "Seen" })has to write"M1a2b3c4d.Seen"everywhere it uses it: theFNV-1a hash of its own id, worked out by hand.
content.mdlists:idfor flags as not yet.Now
game.flags.get,hasandset, andflagChanged's filter, take a mod's content flags by their ids, as the restof the runtime takes its content:
":id"is the calling mod's own flag,"owner/name:id"another mod's; each is read as the game namecontent.flagmakes (
content::plan::wordand the id). A game name is taken as it is. A mod's tests, which the game runs astests:<id>, name its flags as the mod does.flagChangedtells the flag's game name ine.flag, whichever way the listener named it: the filter is kept as thegame name when the listener subscribes, so it matches the event.
:that names no flag (no id after it, an id that is not a declaration's) isUnknownNameError;has()is false.flag()andsetFlag()take the same names.Read first:
flag_nameandflag_watch_refusedingame/crates/api/src/services/game.rs, thenwatch_refusedingame/crates/script/src/runtime.rsand its caller inscript/src/bind/mod.rs(api_on: the filter the hook handsback is the one kept). The fake game:
_flagNameinlib/fake-game.js,services.js, and the kept filter inlib/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'skokiri-start, a quick build of this head) passes: the mod reads its content flag as":Seen"(0,hastrue,":9Seen"refused withUnknownNameError), sets it (game.flags.set Mf7b05380.Seen 0 -> 1in the log),flagChangedtellsMf7b05380.Seen 0 -> 1, and the test'sgame.flag(":Seen")reads 1 (a mod's tests, run astests:<id>, name its flags as the mod does). Checks:cargo test -p api -p script(api'sflag_nameagainst 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
:idfilter 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.flagits gamename, bad names refused);
cargo run -p schema-gen -- --check; rustfmt. The same twoapiloader tests and fivemod-tools tests fail on
mod-apiitself (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:
mise run rustandmise run test(by hand, or CI)Measurements
Nothing to measure: a name without a
:costs one search for it; a:idname is one FNV-1a over the mod's id per call, andflagChangednames it once, aton().Risks
A game flag's name never holds a
:, so no name that worked before reads anything else now. A filter given as:idtells
e.flagas the game name, which a listener comparinge.flagto the text it gave would not expect: the docs andthe record's doc say so.
Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
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]>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.
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.
Pull request closed