Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
1176498
FRLG AutoStory 00.28: sim tests for wild battles every few steps in R…
dayfine Nov 9, 2026
4febace
FRLG walker: after a stop, find the player the way that walks the few…
dayfine Nov 9, 2026
1484c5e
FRLG AutoStory: watch a warp's fade from the start of the hold onto it
dayfine Nov 9, 2026
ec9cf9f
FRLG walker: walk on after a wild battle when the next holds find the…
dayfine Nov 9, 2026
291f72d
FRLG AutoStory: run from wild battles on steps into a trainer's line;…
dayfine Nov 9, 2026
9229561
Merge remote-tracking branch 'origin/frlg/stage8-rocktunnel' into frl…
dayfine Nov 9, 2026
62aa1d4
FRLG sim: wild battles at the game's own odds; 00.28 Monte Carlo numbers
dayfine Nov 9, 2026
d5910eb
FRLG AutoStory: reach Martha's line up column 16, no one-tile step
dayfine Nov 9, 2026
d9dae01
FRLG walker: check each turn tap by the facing on screen, tap again i…
dayfine Nov 9, 2026
680662b
StoryInterrupts: a battle's opening before a battle step is the step's
dayfine Nov 9, 2026
d40ae84
FRLG walker: turn tap tests in the walk tests; no extra public sim me…
dayfine Nov 9, 2026
0b8e597
Merge nav/story-steps into frlg/stage1-core
dayfine Nov 9, 2026
3670827
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 9, 2026
7f66d16
Merge frlg/stage2-rng into frlg/stage3-mtmoon
dayfine Nov 9, 2026
9eb43c0
Merge frlg/stage3-mtmoon into frlg/stage4-cerulean
dayfine Nov 9, 2026
24a17a1
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 9, 2026
592d740
Merge frlg/stage5-bill into frlg/stage6-vermilion
dayfine Nov 9, 2026
f2d20c7
Merge frlg/stage6-vermilion into frlg/stage7-celadon
dayfine Nov 9, 2026
8cabfdf
Merge frlg/stage7-celadon into frlg/checkpoint-replay
dayfine Nov 9, 2026
0e0b2db
Merge frlg/checkpoint-replay into frlg/stage8-rocktunnel
dayfine Nov 9, 2026
75c8c85
FRLG AutoStory: test that every resource it loads is in Resources
dayfine Nov 9, 2026
2134dbb
FRLG: movement mechanics table; sim taps as measured on the console
dayfine Nov 9, 2026
2bd5874
FRLG: space step taps past the lockout
dayfine Nov 9, 2026
91b9ff7
FRLG: code health for the movement table and tap tests
dayfine Nov 9, 2026
853a6b5
FRLG AutoStory sim: sweep scene end poses, wild battles and late fade…
dayfine Nov 9, 2026
f6080f0
FRLG 00.28: honest stops in the dark cave; Martha via the corner (11,…
dayfine Nov 9, 2026
e951ea8
Merge remote-tracking branch 'origin/frlg/stage8-rocktunnel' into fix…
dayfine Nov 9, 2026
79bfa97
FRLG 00.28: dark-cave stop rule shared in the reanchor code; code health
dayfine Nov 9, 2026
46c99dc
StoryInterrupts tests: a battle's opening before a walk step (red)
dayfine Nov 9, 2026
0be68ac
StoryInterrupts: wait for a battle's opening before any step
dayfine Nov 9, 2026
8679be4
Merge nav/story-steps into frlg/stage1-core (wait for a battle's open…
dayfine Nov 9, 2026
1360bea
Merge frlg/stage1-core into frlg/stage2-rng (wait for a battle's open…
dayfine Nov 9, 2026
16ac7c0
Merge frlg/stage2-rng into frlg/stage3-mtmoon (wait for a battle's op…
dayfine Nov 9, 2026
68b7586
Merge frlg/stage3-mtmoon into frlg/stage4-cerulean (wait for a battle…
dayfine Nov 9, 2026
8f6fdc5
Merge frlg/stage4-cerulean into frlg/stage5-bill (wait for a battle's…
dayfine Nov 9, 2026
b6421e4
Merge frlg/stage5-bill into frlg/stage6-vermilion (wait for a battle'…
dayfine Nov 9, 2026
195ed57
Merge frlg/stage6-vermilion into frlg/stage7-celadon (wait for a batt…
dayfine Nov 9, 2026
740398a
Merge frlg/stage7-celadon into frlg/checkpoint-replay (wait for a bat…
dayfine Nov 9, 2026
30dc576
Merge frlg/checkpoint-replay into frlg/stage8-rocktunnel (wait for a …
dayfine Nov 9, 2026
500e624
Scene judges tests: a closing fade is no quiet (red)
dayfine Nov 9, 2026
7c6e9bd
Scene judges: a fade ends no quiet; log the screen before every step
dayfine Nov 9, 2026
1325e52
Merge nav/story-steps into frlg/stage1-core (scene ends after its fad…
dayfine Nov 9, 2026
8c007f5
FRLG AutoStory: log the screen before every step
dayfine Nov 9, 2026
d8b2eab
Merge frlg/stage1-core into frlg/stage2-rng (scene ends after its fad…
dayfine Nov 9, 2026
51bf32e
Merge frlg/stage2-rng into frlg/stage3-mtmoon (scene ends after its f…
dayfine Nov 9, 2026
b6814a4
Merge frlg/stage3-mtmoon into frlg/stage4-cerulean (scene ends after …
dayfine Nov 9, 2026
93c1b56
Merge frlg/stage4-cerulean into frlg/stage5-bill (scene ends after it…
dayfine Nov 9, 2026
edc2002
Merge frlg/stage5-bill into frlg/stage6-vermilion (scene ends after i…
dayfine Nov 9, 2026
b83cc4c
Merge frlg/stage6-vermilion into frlg/stage7-celadon (scene ends afte…
dayfine Nov 9, 2026
806a540
Merge frlg/stage7-celadon into frlg/checkpoint-replay (scene ends aft…
dayfine Nov 9, 2026
5edbf42
Merge frlg/checkpoint-replay into frlg/stage8-rocktunnel (scene ends …
dayfine Nov 9, 2026
2b8b70e
FRLG: red tests for a battle won in a dark cave
dayfine Nov 9, 2026
710e5de
FRLG: a dark cave's overworld ends the battle loop's evolution wait
dayfine Nov 9, 2026
db14a25
FRLG: keep the battle loop and the sim walker within the file limit
dayfine Nov 9, 2026
9b00e53
Story interrupts: red tests for a step that starts on the Switch HOME…
dayfine Nov 9, 2026
fd603ca
Story interrupts: the HOME menu is not an overworld; a step on it fai…
dayfine Nov 9, 2026
bee7206
Merge nav/story-steps into frlg/stage1-core: a step on the Switch HOM…
dayfine Nov 9, 2026
5e00efa
FRLG AutoStory: look for the Switch HOME menu before each step
dayfine Nov 9, 2026
350d783
Merge frlg/stage1-core into frlg/stage2-rng: a step on the Switch HOM…
dayfine Nov 9, 2026
35dc611
Merge frlg/stage2-rng into frlg/stage3-mtmoon: a step on the Switch H…
dayfine Nov 9, 2026
bfc2a30
Merge frlg/stage3-mtmoon into frlg/stage4-cerulean: a step on the Swi…
dayfine Nov 9, 2026
5c8b08f
Merge frlg/stage4-cerulean into frlg/stage5-bill: a step on the Switc…
dayfine Nov 9, 2026
8885f95
Merge frlg/stage5-bill into frlg/stage6-vermilion: a step on the Swit…
dayfine Nov 9, 2026
a4e3de3
Merge frlg/stage6-vermilion into frlg/stage7-celadon: a step on the S…
dayfine Nov 9, 2026
583905b
Merge frlg/stage7-celadon into frlg/checkpoint-replay: a step on the …
dayfine Nov 9, 2026
a22824f
Merge frlg/checkpoint-replay into frlg/stage8-rocktunnel: a step on t…
dayfine Nov 9, 2026
413f1cb
FRLG AutoStory: wait out a battle's exit before the next tap in a tra…
dayfine Nov 9, 2026
10f0583
AutoStory: story types and engine, split out of #122
dayfine Nov 10, 2026
e9f0efe
AutoStory: screen state and interrupt tracking, split out of #122
dayfine Nov 10, 2026
14010d1
Merge nav/screen-state into nav/story-steps (#122 split into three la…
dayfine Nov 10, 2026
0a1ab58
FRLG maps: adopt PokemonSimulation e52be04; spin, hole and button glyphs
dayfine Nov 10, 2026
6aa5a9b
FRLG replay: refresh the Parcel fixture for PokemonSimulation bdca47c
dayfine Nov 10, 2026
5b974f0
AutoStory: story data types in Types/, executor as a data-free interf…
dayfine Nov 10, 2026
d39d8ce
Merge nav/story-engine into nav/screen-state (#312 review: Types/, da…
dayfine Nov 10, 2026
1db4a28
Merge nav/screen-state into nav/story-steps (#312 review: Types/, dat…
dayfine Nov 10, 2026
6b908f4
AutoStory: TableExecutor without per-kind virtuals
dayfine Nov 10, 2026
1b74c82
AutoStory: structured step args next to a plain variant name
dayfine Nov 10, 2026
c224081
Merge nav/screen-state into nav/story-steps (structured step args)
dayfine Nov 10, 2026
942e468
Merge nav/story-engine into nav/screen-state (structured step args)
dayfine Nov 10, 2026
2984456
AutoStory: actions declare their args; lint checks steps against them
dayfine Nov 10, 2026
dd9529b
AutoStory: shared story range options and story log lines
dayfine Nov 10, 2026
babbf85
Merge remote-tracking branch 'origin/nav/story-engine' into nav/story…
dayfine Nov 10, 2026
28df3b2
Merge nav/story-engine into nav/screen-state (story range options and…
dayfine Nov 10, 2026
fd6de90
Merge nav/screen-state into nav/story-steps (story range options and …
dayfine Nov 10, 2026
48c10b7
StoryRangeOptions: let a program unlock the end while running
dayfine Nov 10, 2026
936b808
Merge nav/story-engine into nav/screen-state (range end lock mode)
dayfine Nov 10, 2026
c656501
Merge nav/screen-state into nav/story-steps (range end lock mode)
dayfine Nov 10, 2026
c766e87
AutoStory tests: register the story engine suites through one call
dayfine Nov 10, 2026
7b73ef0
Merge nav/story-engine into nav/screen-state (one story test registra…
dayfine Nov 10, 2026
46c65d7
Merge nav/screen-state into nav/story-steps (one story test registrat…
dayfine Nov 10, 2026
f5b35c5
Merge nav/story-steps into frlg/stage1-core
dayfine Nov 10, 2026
e3f232c
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 10, 2026
d481656
Merge frlg/stage2-rng into frlg/stage3-mtmoon
dayfine Nov 10, 2026
10dee67
Merge frlg/stage3-mtmoon into frlg/stage4-cerulean
dayfine Nov 10, 2026
bb75eb0
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 10, 2026
ab46733
Merge frlg/stage5-bill into frlg/stage6-vermilion
dayfine Nov 10, 2026
93d602b
Merge frlg/stage6-vermilion into frlg/stage7-celadon
dayfine Nov 10, 2026
9e5ca48
Merge frlg/checkpoint-replay into frlg/stage8-rocktunnel
dayfine Nov 10, 2026
2611b1b
Merge frlg/stage7-celadon into frlg/checkpoint-replay
dayfine Nov 10, 2026
c326739
FRLG AutoStory: build against the core's executor interface
dayfine Nov 10, 2026
42e98c5
Pokemon navigation: write a route plan on one log line
dayfine Nov 10, 2026
d3e856e
Merge nav/shared (one-line route plan) into nav/story-engine
dayfine Nov 10, 2026
bd2a594
Merge nav/story-engine (one-line route plan) into nav/screen-state
dayfine Nov 10, 2026
c53f345
Merge nav/shared (one-line route plan) into nav/story-steps
dayfine Nov 10, 2026
b3b4cdc
Merge nav/story-steps (one-line route plan) into frlg/stage1-core
dayfine Nov 10, 2026
495c170
FRLG AutoStory: expect the route plan on one log line
dayfine Nov 10, 2026
2b68a52
Pokemon AutoStory: tile_pose() and facing_of() next to TilePose
dayfine Nov 10, 2026
093d1ab
Merge branch 'review312/nav-shared' into nav/story-engine
dayfine Nov 10, 2026
a940ce0
AutoStory: move the JSON codecs to Data/, StorySteps to StoryStepExec…
dayfine Nov 10, 2026
e8833b3
AutoStory: review fixes to the story engine's API (#312)
dayfine Nov 10, 2026
4652d59
Merge remote-tracking branch 'origin/nav/story-engine' into review312…
dayfine Nov 10, 2026
a91cd6a
Merge remote-tracking branch 'origin/nav/screen-state' into review312…
dayfine Nov 10, 2026
a03bfe6
AutoStory: StoryActions lint lists every args error
dayfine Nov 10, 2026
31ddeae
AutoStory: steps carry an action and typed args (#312 review)
dayfine Nov 10, 2026
8dad6da
AutoStory: test steps get their built-in action's fallbacks, as loadi…
dayfine Nov 10, 2026
2871e3e
AutoStory: shared StoryLog and StoryRangeOptions (prep for #114, #312…
dayfine Nov 10, 2026
e79f719
Merge autostory/story-range-options; take #312's StoryEvents and Stor…
dayfine Nov 10, 2026
8fd27c7
Merge nav/shared (#114) into nav/story-engine: StoryLog, StoryRangeOp…
dayfine Nov 10, 2026
c51e57f
AutoStory: built-in actions in Pokemon_BuiltinStoryActions, clear of …
dayfine Nov 10, 2026
51f72b1
Merge nav/story-engine (#312) into nav/story-steps
dayfine Nov 10, 2026
d9d2e64
AutoStory: the action table and its tests read StoryStep::action and …
dayfine Nov 10, 2026
8cc0d89
AutoStory: lookup test names actions, not variants
dayfine Nov 10, 2026
76d2645
Pokemon navigation: split over-limit headers, drop char* for code health
dayfine Nov 10, 2026
20c4961
Merge branch 'nav/shared' into nav/story-engine
dayfine Nov 10, 2026
1f44949
Merge branch 'nav/story-engine' into nav/story-steps
dayfine Nov 10, 2026
7d04d13
AutoStory: split over-limit headers, drop char* for code health
dayfine Nov 10, 2026
e4636eb
Merge origin/nav/story-steps into frlg/stage1-core
dayfine Nov 10, 2026
801dd92
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 10, 2026
62c65b0
Merge origin/frlg/stage2-rng into frlg/stage3-mtmoon
dayfine Nov 10, 2026
567f9b3
Merge origin/frlg/stage3-mtmoon into frlg/stage4-cerulean
dayfine Nov 10, 2026
bec6662
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 10, 2026
fddde42
Merge origin/frlg/stage5-bill into frlg/stage6-vermilion
dayfine Nov 10, 2026
ac8a50e
Merge origin/frlg/stage6-vermilion into frlg/stage7-celadon
dayfine Nov 10, 2026
ec4ff09
Merge origin/frlg/stage7-celadon into frlg/checkpoint-replay
dayfine Nov 10, 2026
51cb266
FRLG AutoStory: checkpoints 00.01-00.10 as authored JSON, on #312's a…
dayfine Nov 10, 2026
3f0b338
FRLG AutoStory: delete the C++ story rows, parity proven
dayfine Nov 10, 2026
636f021
Merge frlg/stage1-json (#330) into frlg/stage2-json: stage 2's rows a…
dayfine Nov 10, 2026
9d54f1b
FRLG AutoStory: delete stage 2's C++ story rows, parity proven
dayfine Nov 10, 2026
b9ac130
Merge pull request #331 from dayfine/frlg/stage2-json
dayfine Nov 10, 2026
34fecef
Merge frlg/stage2-rng (#331) into frlg/stage3-json: stage 3's rows as…
dayfine Nov 10, 2026
68b113f
FRLG AutoStory: delete stage 3's C++ story rows, parity proven
dayfine Nov 10, 2026
7f7a9cf
Merge pull request #333 from dayfine/frlg/stage3-json
dayfine Nov 10, 2026
703f5e8
Merge frlg/stage3-mtmoon (#333) into frlg/stage4-json: stage 4's rows…
dayfine Nov 10, 2026
25ce096
FRLG AutoStory: delete stage 4's C++ story rows, parity proven
dayfine Nov 10, 2026
48f46db
Merge pull request #334 from dayfine/frlg/stage4-json
dayfine Nov 10, 2026
b28ee6e
Merge frlg/stage4-cerulean (#334) into frlg/stage5-json: stage 5's ro…
dayfine Nov 10, 2026
0d47b00
FRLG AutoStory: delete stage 5's C++ story rows, parity proven
dayfine Nov 10, 2026
c4b55d7
Merge pull request #336 from dayfine/frlg/stage5-json
dayfine Nov 10, 2026
201cda0
Merge frlg/stage5-bill (#336) into frlg/stage6-json: stage 6's rows a…
dayfine Nov 10, 2026
e3ab8e1
FRLG AutoStory: delete stage 6's C++ story rows, parity proven
dayfine Nov 10, 2026
7dadd34
Merge pull request #337 from dayfine/frlg/stage6-json
dayfine Nov 10, 2026
93703c5
Merge frlg/stage6-vermilion (#337) into frlg/stage7-json: stage 7's r…
dayfine Nov 10, 2026
9d78b82
FRLG AutoStory: delete stage 7's C++ story rows, parity proven
dayfine Nov 10, 2026
f6bdfd4
Merge pull request #338 from dayfine/frlg/stage7-json
dayfine Nov 10, 2026
b1d89b1
Merge frlg/stage7-celadon (#338) into frlg/checkpoint-replay-json: re…
dayfine Nov 10, 2026
4ca5721
Merge pull request #339 from dayfine/frlg/checkpoint-replay-json
dayfine Nov 10, 2026
67def56
Merge frlg/checkpoint-replay (#339) into frlg/stage8-json: stage 8's …
dayfine Nov 10, 2026
405f12e
FRLG AutoStory: delete stage 8's C++ story rows, parity proven
dayfine Nov 10, 2026
bf5f498
Merge pull request #340 from dayfine/frlg/stage8-json
dayfine Nov 10, 2026
aac8cac
Merge frlg/stage8-rocktunnel into frlg/autostory-failure-capture
dayfine Nov 10, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
uses: actions/checkout@v7
with:
repository: dayfine/PokemonSimulation
ref: 9cb12c52f5f055299e32c2a7cf43e7103c101e3e
ref: bdca47c5045797be1d2a1f0931ad6a8f15ab3225
path: StoryReplaySource

- name: Verify replay preview bytes and independently regenerate its route input
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pa_embed_text_files(SerialProgramsLib "${FRLG_MAP_RESOURCES}"
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData
VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData
VideoGames/PokemonFRLG/Programs/AutoStory/Data/JsonParser.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_checkpoint_json)
VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_checkpoint_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/ReplayData
VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay.h PokemonAutomation::NintendoSwitch::PokemonFRLG story_replay_fixture_json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ void StepTrace::screen(const std::string& name){
}
m_count++;
const double seconds = std::chrono::duration<double>(current_time() - m_start).count();
char prefix[16];
std::snprintf(prefix, sizeof(prefix), "%03zu-", m_count);
std::string path = m_folder + prefix + name + ".png";
std::string path = m_folder + std::format("{:03}-", m_count) + name + ".png";
VideoSnapshot screen = m_stream.video().snapshot();
if (screen){
screen.frame->save(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Common/Qt/QtThreadPool_Tests.h"
#include "Kernels/Kernels_Tests.h"
#include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h"
#include "Pokemon/AutoStory/Pokemon_StoryRun_Tests.h"
#include "CommonFramework/AudioPipeline/AudioInfo_Tests.h"
#include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h"
#include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h"
Expand Down Expand Up @@ -80,16 +81,16 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){
Pokemon::add_tests_MapData(ret);
Pokemon::add_tests_RuntimeMap(ret);
Pokemon::add_tests_RouteLog(ret);
Pokemon::add_tests_StoryEvents(ret);
Pokemon::add_tests_StorySegments(ret);
Pokemon::add_tests_StoryLog(ret);
Pokemon::add_tests_StoryRangeOptions(ret);
Pokemon::add_tests_ScreenEvents(ret);
Pokemon::add_tests_Interrupts(ret);
Pokemon::add_tests_Transitions(ret);
Pokemon::add_tests_StoryActions(ret);
Pokemon::add_tests_StoryInterrupts(ret);
Pokemon::add_tests_StoryEvents(ret);
Pokemon::add_tests_StorySegments(ret);
Pokemon::add_tests_StorySteps(ret);
Pokemon::add_tests_StoryStepJson(ret);
Pokemon::add_tests_AuthoredCheckpointJson(ret);
Pokemon::add_tests_AutoStory(ret);
NintendoSwitch::add_tests_CheckOnlineDetector(ret);
NintendoSwitch::add_tests_FailedToConnectDetector(ret);
NintendoSwitch::add_tests_UpdatePopupDetector(ret);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* Shared Authored Checkpoint JSON
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
Expand All @@ -12,7 +14,7 @@ namespace PokemonAutomation{
namespace Pokemon{


void require_story_json_fields(
void validate_json_fields(
const JsonObject& object, std::initializer_list<std::string_view> fields, std::string_view source
){
if (object.size() != fields.size()){
Expand All @@ -23,20 +25,20 @@ void require_story_json_fields(
}
}

AuthoredCheckpoint read_authored_checkpoint(
const JsonValue& value, std::string_view expected_game, std::string_view source
StoryCheckpoint read_authored_checkpoint(
const JsonValue& value, std::string_view game, std::string_view source,
const ExecutionReader& read_execution, std::span<const StoryActionSpec> actions
){
const JsonObject& root = value.to_object_throw(std::string(source));
require_story_json_fields(root, {"format", "game", "checkpoint", "execution"}, source);
if (expected_game.empty() || root.get_string_throw("format") != "pokesim-authored-checkpoint/1"
|| root.get_string_throw("game") != expected_game
validate_json_fields(root, {"format", "game", "checkpoint", "execution"}, source);
if (game.empty() || root.get_string_throw("format") != "pokesim-authored-checkpoint/1"
|| root.get_string_throw("game") != game
){
throw ParseException(std::format("{}: unsupported authored checkpoint format/game.", source));
}
return {
.checkpoint = read_story_checkpoint(root.get_value_throw("checkpoint"), source),
.execution = root.get_object_throw("execution", std::string(source)).clone(),
};
StoryCheckpoint checkpoint = read_story_checkpoint(root.get_value_throw("checkpoint"), source, actions);
read_execution(root.get_object_throw("execution", std::string(source)), source);
return checkpoint;
}

JsonValue authored_checkpoint_json(const StoryCheckpoint& checkpoint, std::string_view game, JsonObject execution){
Expand All @@ -51,17 +53,19 @@ JsonValue authored_checkpoint_json(const StoryCheckpoint& checkpoint, std::strin
return result;
}

AuthoredCheckpoint load_authored_checkpoint(
std::span<const std::pair<std::string, std::string>> files, std::string_view file, std::string_view expected_game
StoryCheckpoint load_authored_checkpoint(
std::span<const EmbeddedJsonFile> files, std::string_view file, std::string_view game,
const ExecutionReader& read_execution, std::span<const StoryActionSpec> actions
){
for (const auto& [name, text] : files){
if (name == file){
return read_authored_checkpoint(parse_json(text), expected_game, file);
return read_authored_checkpoint(parse_json(text), game, file, read_execution, actions);
}
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Authored checkpoint is not embedded: " + std::string(file));
}



} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Shared Authored Checkpoint JSON
*
* From: https://github.com/PokemonAutomation/
*
* Reading and writing an authored checkpoint file: the shared
* StoryCheckpoint (Pokemon_StoryStepJson.h) in an envelope that names the
* game, plus the game's own execution object, which the game parses into
* its own type through a reader it passes in. Only parsing and encoding:
* nothing here binds or runs a step, and nothing read keeps JSON.
*
*/

#ifndef PokemonAutomation_AuthoredCheckpointJson_H
#define PokemonAutomation_AuthoredCheckpointJson_H

#include <functional>
#include <initializer_list>
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include "Common/Cpp/Json/JsonObject.h"
#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h"

namespace PokemonAutomation{
namespace Pokemon{


// The game's reader of an envelope's execution object: it parses the
// object into the game's own type and throws ParseException when it is
// malformed.
using ExecutionReader = std::function<void(const JsonObject& execution, std::string_view source)>;

// Require exactly these fields, including fields whose value is null/zero/false.
// Missing/unknown fields throw ParseException with the document source.
void validate_json_fields(
const JsonObject& object, std::initializer_list<std::string_view> fields, std::string_view source
);

// The checkpoint of `game`'s strict authored envelope, its steps read
// against `actions` (read_story_checkpoint()); its execution object goes
// to `read_execution`.
StoryCheckpoint read_authored_checkpoint(
const JsonValue& value, std::string_view game, std::string_view source,
const ExecutionReader& read_execution,
std::span<const StoryActionSpec> actions = builtin_story_actions()
);

// Encode the authored envelope; execution is supplied by the game adapter.
// This does not encode game bookkeeping or the legacy native-export envelope.
JsonValue authored_checkpoint_json(const StoryCheckpoint& checkpoint, std::string_view game, JsonObject execution);

// A JSON file built into the program: its name without ".json", and its
// text.
using EmbeddedJsonFile = std::pair<std::string, std::string>;

// Find embedded file `file` among `files` and parse it as
// read_authored_checkpoint() does. Missing resources throw
// InternalProgramError; malformed documents throw ParseException.
StoryCheckpoint load_authored_checkpoint(
std::span<const EmbeddedJsonFile> files, std::string_view file, std::string_view game,
const ExecutionReader& read_execution,
std::span<const StoryActionSpec> actions = builtin_story_actions()
);



} // namespace Pokemon
} // namespace PokemonAutomation

#endif
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
/* Shared Authored Checkpoint JSON Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include "Common/Cpp/Exceptions.h"
#include "Pokemon_AuthoredCheckpointJson.h"
#include "Pokemon_StoryStepJson.h"
#ifndef PA_STORY_DATA_STANDALONE
#include "Pokemon_AutoStory_Tests.h"
#include "Pokemon/AutoStory/Pokemon_AutoStory_Tests.h"
#endif

namespace PokemonAutomation{
namespace Pokemon{


namespace{


// Documents intentionally contain no game headers or native bookkeeping.
const std::string FRLG = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{"id":"00.05","title":"Parcel","events":[{"id":"first","kind":"route"},{"id":"second","kind":"scene"}]},"execution":{"menu":"before_pokedex"}})";
const std::string FRLG = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{"id":"00.05","title":"Parcel","events":[{"id":"first","kind":"talk"},{"id":"second","kind":"scene"}]},"execution":{"menu":"before_pokedex"}})";
const std::string BDSP = R"({"format":"pokesim-authored-checkpoint/1","game":"bdsp","checkpoint":{"id":"01.03","title":"Mine","events":[{"id":"roark","kind":"talk"}]},"execution":{"on_failure":"reload_and_retry","saves_in":"Oreburgh City"}})";

enum class Failure{ NONE, PARSE, MISSING_RESOURCE };
// How a case fails, if it does.
enum class Failure{
NONE,
PARSE,
MISSING_RESOURCE,
};

struct AuthoredInput{
std::string name;
Expand Down Expand Up @@ -60,7 +72,24 @@ const AuthoredCase CASES[] = {
.checkpoint = "x", .execution = R"({"zero":0,"false":false,"null":null})", .events = {}}},
};

std::string check_loaded(const AuthoredCheckpoint& actual, const AuthoredCase& test){

// What a test reads: the checkpoint, and the execution object its reader
// kept.
struct Loaded{
StoryCheckpoint checkpoint;
JsonObject execution;
};

// A reader that keeps the execution object in `kept`.
ExecutionReader keep_execution(JsonObject& kept){
return [&kept](const JsonObject& execution, std::string_view){
kept = execution.clone();
};
}

// "" when `actual` is what `test` expects and survives a write and a
// read, else what was expected and what was read.
std::string check_loaded(const Loaded& actual, const AuthoredCase& test){
if (test.expectation.failure != Failure::NONE){
return "Expected rejection, read accepted authored checkpoint.";
}
Expand All @@ -78,19 +107,22 @@ std::string check_loaded(const AuthoredCheckpoint& actual, const AuthoredCase& t
return "Expected authored event IDs in their original order.";
}
const JsonValue encoded = authored_checkpoint_json(actual.checkpoint, test.input.game, actual.execution.clone());
const AuthoredCheckpoint reread = read_authored_checkpoint(encoded, test.input.game, test.input.name);
Loaded reread;
reread.checkpoint = read_authored_checkpoint(encoded, test.input.game, test.input.name, keep_execution(reread.execution));
if (!(story_checkpoint_json(actual.checkpoint) == story_checkpoint_json(reread.checkpoint)) || actual.execution != reread.execution){
return "Expected checkpoint and execution to survive the shared writer/reader round trip.";
}
return "";
}

// "" when `test` reads or fails as expected.
std::string check_case(const AuthoredCase& test){
try{
const std::vector<std::pair<std::string, std::string>> files = {{"plan", test.input.json}};
const AuthoredCheckpoint actual = test.input.resource
? load_authored_checkpoint(files, test.input.file, test.input.game)
: read_authored_checkpoint(parse_json(test.input.json), test.input.game, test.input.name);
Loaded actual;
actual.checkpoint = test.input.resource
? load_authored_checkpoint(files, test.input.file, test.input.game, keep_execution(actual.execution))
: read_authored_checkpoint(parse_json(test.input.json), test.input.game, test.input.name, keep_execution(actual.execution));
return check_loaded(actual, test);
}catch (const ParseException& error){
return test.expectation.failure == Failure::PARSE ? "" : "Unexpected parse failure: " + error.message();
Expand All @@ -99,34 +131,49 @@ std::string check_case(const AuthoredCase& test){
}
}


#ifndef PA_STORY_DATA_STANDALONE

class AuthoredJsonTest : public UnitTest{
public:
explicit AuthoredJsonTest(AuthoredCase test)
: UnitTest("Pokemon::AuthoredCheckpointJson - " + test.input.name), m_case(std::move(test)){}
: UnitTest("Pokemon::AuthoredCheckpointJson - " + test.input.name)
, m_case(std::move(test))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const std::string error = check_case(m_case);
return error.empty() ? UnitTestResult(true) : UnitTestResult(error);
}

private:
AuthoredCase m_case;
};

#endif


} // namespace


#ifndef PA_STORY_DATA_STANDALONE

void add_tests_AuthoredCheckpointJson(UnitTestDatabase& database){
for (const AuthoredCase& test : CASES){
database.add<AuthoredJsonTest>(test);
}
}

#endif



} // namespace Pokemon
} // namespace PokemonAutomation


#ifdef PA_STORY_DATA_STANDALONE

int main(){
int failed = 0;
for (const auto& test : PokemonAutomation::Pokemon::CASES){
Expand All @@ -136,4 +183,5 @@ int main(){
}
return failed != 0;
}

#endif
Loading
Loading