Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
db7e5e0
AutoStory: shared core from PLZA's engine
dayfine Nov 17, 2026
200dd1d
AutoStory shared core: code health fixes in the save policy
dayfine Nov 17, 2026
2cefcd3
Logic tests: a Qt/OpenCV/ONNX-free unit test target and CI job
dayfine Nov 18, 2026
5f0cd18
Merge main into autostory/shared-core
dayfine Nov 18, 2026
896d7b6
Merge remote-tracking branch 'origin/autostory/story-range-options-sv…
dayfine Nov 18, 2026
3b8c9aa
AutoStory core: tile-grid arg kinds and declared pose
dayfine Nov 18, 2026
0bef4b4
Revert "AutoStory core: tile-grid arg kinds and declared pose"
dayfine Nov 18, 2026
d3f0a9c
AutoStory core: grid-free, with registered arg kinds and per-game poses
dayfine Nov 18, 2026
9dcb552
AutoStory shared core: leave the Switch system keyboard code to PLZA
dayfine Nov 18, 2026
5ec96a0
AutoStory shared core: move the logic test target to its own branch
dayfine Nov 18, 2026
64861ac
AutoStory shared core: drop the fork-only CommandLineTests pin
dayfine Nov 18, 2026
b525f9a
AutoStory shared core: FakeStoryBackend::inputs() comment matches the…
dayfine Nov 18, 2026
5977a4c
Merge autostory/story-range-options-sv into autostory/shared-core
dayfine Nov 18, 2026
84d9963
Merge origin/autostory/story-range-options-sv into autostory/shared-core
dayfine Nov 18, 2026
bda406f
AutoStory shared core: engine as one free function, one checkpoint re…
dayfine Nov 19, 2026
79833e8
AutoStory shared core: checkpoint, event, outcome and log comments st…
dayfine Nov 19, 2026
b2791c5
AutoStory shared core: Types comments state their contracts
dayfine Nov 19, 2026
30547ce
AutoStory shared core: Data comments state their contracts; split_at_…
dayfine Nov 19, 2026
165c2a7
ScreenEvents, ScreenMachine: comments state their contracts
dayfine Nov 19, 2026
8dce146
ScreenMachineResult: a variant of ScreenMachineTerminal or ScreenMach…
dayfine Nov 19, 2026
edd7e40
Merge autostory/screen-machine into autostory/shared-core
dayfine Nov 19, 2026
a4254cb
Merge autostory/screen-machine into autostory/shared-core
dayfine Nov 19, 2026
36ebaf3
AutoStory core: delete pose, backend kind, battle, registered args, m…
dayfine Nov 19, 2026
42eb0f2
StoryBackend: drop the public_methods allow tag; it is within the lim…
dayfine Nov 19, 2026
25302a5
AutoStory engine core: StoryFailure result, reload-reported start, in…
dayfine Nov 19, 2026
f6b7fe8
Merge remote-tracking branch 'origin/autostory/screen-machine' into t…
dayfine Nov 19, 2026
673607d
AutoStory tests: value-initialize the test-case fields
dayfine Nov 19, 2026
9e9f838
AutoStory plan format: steps name their action; actions parse their a…
dayfine Nov 19, 2026
c1a76fb
AutoStory core: port plza/lean's shared-core edits (step action, RunS…
dayfine Nov 19, 2026
715f833
AutoStory core review: one checkpoint file reader, no story_run_rows,…
dayfine Nov 19, 2026
548b4ea
AutoStory core: the engine's log line formats live in Pokemon_StoryLog
dayfine Nov 19, 2026
245ffc2
Merge origin/autostory/screen-machine into autostory/shared-core
dayfine Nov 19, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* Story Checkpoint JSON
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <set>
#include <utility>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Pokemon_StoryCheckpointJson.h"

namespace PokemonAutomation{
namespace Pokemon{


namespace{


// Throws ParseException naming the first of `keys` missing from `object`.
void require_keys(const JsonObject& object, std::initializer_list<std::string_view> keys){
for (std::string_view key : keys){
object.get_value_throw(std::string(key));
}
}

// A step, parsed by its action among `actions`.
StoryStep read_story_step(const JsonValue& value, StoryActions& actions){

Check warning on line 29 in SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryCheckpointJson.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::read_story_step( const JsonValue & value , StoryActions & actions): function_lines=26 (advisory above 25, limit 50)
const JsonObject& root = value.to_object_throw();
reject_unknown_keys(root, {"id", "why", "action", "args"});
StoryStep result;
result.name = root.get_string_throw("id");
if (result.name.empty()){
throw ParseException("empty step id");
}
if (const JsonValue* field = root.get_value("why")){
result.why = field->to_string_throw();
}
const std::string& action = root.get_string_throw("action");
result.action = action;
const auto parser = actions.find(action);
if (parser == actions.end()){
throw ParseException(std::format("step {}: unknown action \"{}\"", result.name, action));
}
const JsonObject no_args;
const JsonValue* args = root.get_value("args");
try{
result.run = parser->second(args != nullptr ? args->to_object_throw() : no_args);
}catch (const ParseException& error){
throw ParseException(std::format("step {}: {}", result.name, error.message()));
}
return result;
}

// The checkpoint object of a file, each step parsed by its action.
StoryCheckpoint read_checkpoint_object(const JsonValue& value, StoryActions& actions){
const JsonObject& root = value.to_object_throw();
reject_unknown_keys(root, {"id", "title", "start", "events", "metadata"});
StoryCheckpoint result;
result.id = root.get_string_throw("id");
if (result.id.empty()){
throw ParseException("empty checkpoint id");
}
result.title = root.get_string_throw("title");
std::set<std::string> names;
for (const JsonValue& event : root.get_array_throw("events")){
StoryStep step = read_story_step(event, actions);
if (!names.insert(step.name).second){
throw ParseException(std::format("duplicate step id {}", step.name));
}
result.steps.push_back(std::move(step));
}
return result;
}


} // namespace


void reject_unknown_keys(const JsonObject& object, std::initializer_list<std::string_view> keys){
for (const auto& [key, unused] : object){
bool known = false;
for (std::string_view allowed : keys){
known |= key == allowed;
}
if (!known){
throw ParseException(std::format("unknown field \"{}\"", key));
}
}
}

StoryCheckpoint read_story_checkpoint(
const JsonValue& file, std::string_view game, std::string_view source, StoryActions& actions
){
try{
const JsonObject& root = file.to_object_throw();
reject_unknown_keys(root, {"format", "game", "checkpoint", "execution"});
require_keys(root, {"format", "game", "checkpoint", "execution"});
if (root.get_string_throw("format") != "pokesim-authored-checkpoint/1"){
throw ParseException("unsupported format");
}
if (game.empty() || root.get_string_throw("game") != game){
throw ParseException(std::format("not a {} checkpoint", game));
}
root.get_object_throw("execution");
return read_checkpoint_object(root.get_value_throw("checkpoint"), actions);
}catch (const ParseException& error){
throw ParseException(std::format("{}: {}", source, error.message()));
}
}



} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Story Checkpoint JSON
*
* From: https://github.com/PokemonAutomation/
*
* Reads a story checkpoint file into steps ready to run.
*
*/

#ifndef PokemonAutomation_Pokemon_StoryCheckpointJson_H
#define PokemonAutomation_Pokemon_StoryCheckpointJson_H

#include <functional>
#include <initializer_list>
#include <map>
#include <string>
#include <string_view>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/Json/JsonValue.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h"

namespace PokemonAutomation{
namespace Pokemon{


// Parses a step's "args" into its typed args and returns the step's run
// with them bound; throws ParseException on a bad arg.
using StoryActionParser = MoveOnlyFunction<StoryStepRun(const JsonObject& args)>;

// A game's actions by the name a step's "action" gives.
using StoryActions = std::map<std::string, StoryActionParser, std::less<>>;

Check warning on line 31 in SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryCheckpointJson.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: 'StoryActions' is public only for Pokemon_StoryCheckpointJson_Tests.cpp, Pokemon_StoryEngine_Tests.cpp; test through the public function, or keep it in the .cpp's anonymous namespace (ignore if a later PR in the stack calls it) (user review on fork #590)

// Throws ParseException naming the first key of `object` not in `keys`.
// Only an action knows its args, so each parser checks its own with this.
void reject_unknown_keys(const JsonObject& object, std::initializer_list<std::string_view> keys);

Check warning on line 35 in SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryCheckpointJson.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: 'reject_unknown_keys' is public only for Pokemon_StoryCheckpointJson_Tests.cpp; test through the public function, or keep it in the .cpp's anonymous namespace (ignore if a later PR in the stack calls it) (user review on fork #590)

// The checkpoint of a checkpoint file of `game`:
// {"format": "pokesim-authored-checkpoint/1", "game": ...,
// "checkpoint": {"id", "title", "events": [steps]}, "execution": {...}}
// Each step is parsed by its action among `actions`. Throws ParseException
// naming `source` on anything unknown, mistyped or missing. "execution" is
// the game's to read from `file`; the checkpoint's "start" and "metadata"
// are notes for the plan's readers and are not read.
StoryCheckpoint read_story_checkpoint(

Check warning on line 44 in SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryCheckpointJson.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: 'read_story_checkpoint' is public only for Pokemon_StoryCheckpointJson_Tests.cpp; test through the public function, or keep it in the .cpp's anonymous namespace (ignore if a later PR in the stack calls it) (user review on fork #590)
const JsonValue& file, std::string_view game, std::string_view source, StoryActions& actions
);



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Loading