Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
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
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 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 @@ -54,7 +55,7 @@



UnitTestDatabase make_UNIT_TESTS_ALL(){

Check warning on line 58 in SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::ComputerPrograms::make_UNIT_TESTS_ALL(): function_lines=50 (advisory above 25, limit 50)
UnitTestDatabase ret;

add_tests_QtEventThreadPool(ret, GlobalThreadPools::computation_normal());
Expand All @@ -80,6 +81,10 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,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 @@ -25,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 @@ -53,12 +53,13 @@ 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));
Expand Down
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
Expand Up @@ -12,7 +12,7 @@
#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{
Expand All @@ -23,7 +23,7 @@ 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"}})";

// How a case fails, if it does.
Expand Down Expand Up @@ -73,9 +73,23 @@ const AuthoredCase CASES[] = {
};


// 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 AuthoredCheckpoint& actual, const AuthoredCase& test){
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 @@ -93,7 +107,8 @@ 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.";
}
Expand All @@ -104,9 +119,10 @@ std::string check_loaded(const AuthoredCheckpoint& actual, const AuthoredCase& t
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 Down
Loading
Loading