feat(modapi): game.flags and flagChanged take a mod's content flags by their ids #2657
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2657
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-flags-by-id-v2"
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.
game.flagsand theflagChangedfilter, a name with a:that names no flag (no id after it, an id that is not a declaration's) isUnknownNameError;has()is false. The test game'sflag()returnsundefinedfor such a name.flag()andsetFlag()take the same names (it runs the same services).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 test game:
flag_nameingame/crates/modtool/src/testing_game/hooks.rs.This is #2572 moved onto the current
mod-api(rewritten since), on a new branch so the pull request is only thischange; #2572 can close. It was #2287's change to the C mod API first. 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 quick build of current
mod-apiwith this change and the flow patches' (#2656),dev.py game-tests, the repository'skokiri-start. Amod's own test 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 itsflags as the mod does). Checks:
cargo test -p api -p script -p modtool(api'sflag_nameagainst an FNV-1a writtenout 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; modtool's testing_game: a mod that reads, writes and watches its flag as
":Seen",e.flagits game name, a bad name returning
undefinedfrom the test'sflag(), the test'sflag(":Seen"));cargo check --workspace --all-targets;cargo run -p schema-gen -- --check; rustfmt. Two tests fail onmod-apiitself and here, on Windows:api'sa_content_mods_changed_module_runs_again_and_its_outputs_are_servedandmodtool'seden_and_ryujinx_mods_are_found_with_their_switches.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. The generated docs'schema hash (
docs/modding/*.md) conflicts with any other schema change: whichever of this and #2656 merges secondneeds
cargo run -p schema-genagain. 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 test game (modtool's testing_game) runs the same services, and its flag() and setFlag() take the same names. 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; modtool's testing_game test of a mod that reads, writes and watches its flag as ":Seen" (e.flag the game name, a bad name refused, the test's flag(":Seen")). 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, RTX 4060 Laptop, a quick build of current mod-api with this and the flow patches: a mod's own test passes in play (dev.py game-tests, kokiri-start): it reads its flag as ":Seen", sets it (game.flags.set Mf7b05380.Seen 0 -> 1), flagChanged tells it, and the test's game.flag(":Seen") reads 1.
Possibly related, for context:
@review
Recommendation: Request changes. The fake test game throws for an invalid content flag ID, while the in-game test runner returns undefined for the same call. The new test therefore encourages behavior that cannot pass in both runners.
Mods can name content flags by ID for reads, writes and change subscriptions, avoiding hand-computed game names. The translation is small, but the test-game mismatch makes tests less portable between the fake and real game.
Blocking (1): must change before merging.
@​fixor@​rebasetry first). (for the author)Should fix (1): not blocking, but worth doing before merging.
game/crates/modtool/src/testing_game/hooks.rs:445: The fake runner throws for an invalid content flag ID, but the in-game runner's game.flag first calls flags.has, which returns false for that ID, and consequently returns undefined. (more on the line) Do: Make fake game.flag return the same missing-value result as the in-game runner for invalid IDs, and update the test to exercise the same behavior in both runners.@fixcan do L1.Checks: Still running:
Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request).More: does it help, other systems, switches, what was read
Does it help: Yes for the demonstrated own-flag flow: the author reports a Windows in-game test that read, wrote and watched :Seen. Cross-mod names and invalid-name behavior have not been demonstrated in that run.
Other systems: The change affects script subscriptions, game flag reads and writes, and both test runners. It does not change rendering or GPU-specific code. Windows was exercised in game; Linux and the remaining checks are still listed as untested.
Switches: None.
Reviewed:
ce89a911deagainst3391f978eb: Read AGENTS.md, CONTRIBUTING.md, the pull request template, applicable standards, the diff and commit message, and the changed flag service and test-game paths with their callers. Skimmed the remaining portions of the large changed Rust files and generated documentation; docs/review-checklist.md and the sibling Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The author reports a Windows in-game run and crate checks; Linux and clippy remain outstanding, and three CI checks are still running.
Overlaps and merge order: #2572 is described as superseded by this pull request. The author notes a generated schema documentation conflict with #2656; regenerate after whichever merges second.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -436,3 +444,2 @@"flag" => {let name = str_of(a, "flag(name): the name")?;Ok(match g.world.flag(name) {let name = flag_name(g, str_of(a, "flag(name): the name")?, "flag")?;L1 (should fix): The fake runner throws for an invalid content flag ID, but the in-game runner's game.flag first calls flags.has, which returns false for that ID, and consequently returns undefined.
When: A test calling game.flag(":9Seen") passes the new assert.throws in the fake runner but fails when run in the game, where the call returns undefined.
Do: Make fake game.flag return the same missing-value result as the in-game runner for invalid IDs, and update the test to exercise the same behavior in both runners.
@fix
ce89a911ded12d86ca5bRecommendation: Approve. The fake test game now returns the missing-value result for invalid flag IDs, without disabling flag ID support. The supplied base diff contains extensive changes beyond the described feature and was not fully reviewed, so the pull request is not ready for a merge judgment. Nothing blocking is left. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
d12d86ca5b. I rebased it ontomod-api(3f47557067).Conflicts resolved
Changed
Nothing was built or run: the checks run again on the new head.
Mods can address content flags by ID, and the fake test game now treats invalid IDs as missing values. The reported Windows game run demonstrates the main flow.
Checks: they run again on this head; a failure shows on the pull request.
Also noticed (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes for the described feature: the author reports reading, setting and watching a mod flag by ID in a Windows game run. This is not a performance change.
Other systems: The fix changes the fake test game's flag read; its JavaScript wrapper converts the null result to undefined. Linux behavior and the full base diff were not verified.
Switches: None in the described flag change; switches in the much larger supplied base diff were not reviewed.
Reviewed:
d12d86ca5bagainst3f47557067: Read the fix diff, repository rules and pull request template; inspected the flag resolver, fake-game hook, test and JavaScript wrapper. The much larger diff against the supplied base and its other changed files were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run. The author reports a Windows in-game run and checks; CI has not run on this head.
Overlaps and merge order: #2572 is described as superseded; #2656 overlaps generated schema documentation and may require regeneration after merging.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: feat(modapi): game.flags and flagChanged take a mod's content flags by their idsto feat(modapi): game.flags and flagChanged take a mod's content flags by their ids