Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 21 additions & 1 deletion .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,32 @@ jobs:
cd Arduino-Source/SerialPrograms
mkdir bin
cd bin
cmake .. -DQT_MAJOR:STRING=6 ${{env.CMAKE_ADDITIONAL_FLAGS}}
cmake .. -DQT_MAJOR:STRING=6 -DPA_FRLG_STORY_EXPORT=ON ${{env.CMAKE_ADDITIONAL_FLAGS}}
# By default Ninja reads each compile's .d dependency file into its own database, then deletes it.
# To keep them for the downstream clang-query cache (see .github/scripts/clang-query-cached.py), add
# -d keepdepfile
cmake --build . --config RelWithDebInfo --parallel ${{env.BUILD_PARALLEL}} -- -d keepdepfile

- name: Export evaluated FRLG Parcel checkpoint (Ubuntu)
if: startsWith(inputs.os, 'ubuntu') && inputs.run-tests
run: |
cd Arduino-Source/SerialPrograms/bin
./StoryCheckpointExport 00.05 > frlg-parcel.native.json
python3 - <<'PYTHON'
import json
from pathlib import Path
data = json.loads(Path('frlg-parcel.native.json').read_text())
assert data['game'] == 'frlg' and data['checkpoint']['id'] == '00.05'
assert len(data['checkpoint']['events']) == 3
PYTHON

- name: Upload evaluated FRLG checkpoint
if: startsWith(inputs.os, 'ubuntu') && inputs.run-tests
uses: actions/upload-artifact@v7
with:
name: frlg-checkpoint-${{inputs.os}}-${{inputs.compiler}}
path: Arduino-Source/SerialPrograms/bin/frlg-parcel.native.json

- name: Prepare upload build
if: inputs.upload-build
shell: bash
Expand Down
1 change: 1 addition & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ if(COMMAND_LINE_EXE)
include(Source/CommandLine/CommandLineExecutable.cmake)
endif()

include(../devtools/story-export/FRLG.cmake)
if(PA_PYTHON_BINDINGS)
# Python bindings (GUI-free) from subdirectory
include(Source/PythonBindings/PythonBindings.cmake)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "PokemonFRLG_Navigation.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h"
#include "Tests/TestUtils.h"

#include "PokemonFRLG_Tests.h"
Expand Down Expand Up @@ -317,6 +318,7 @@ void add_tests(UnitTestDatabase& database){
add_tests_OverworldRecovery(database);
add_tests_PlayerFacingReader(database);
add_tests_AutoStory(database);
add_tests_AutoStoryExport(database);
add_tests_AutoStorySimulation(database);
add_tests_AutoStoryItems(database);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* FRLG Authored Checkpoint Export
* From: https://github.com/PokemonAutomation/
*/
#include <limits>
#include <utility>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h"
#include "PokemonFRLG_AutoStoryExport.h"
namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{
namespace{
const char* menu_name(StartMenu menu){
switch (menu){
case StartMenu::BEFORE_POKEMON: return "before_pokemon";
case StartMenu::BEFORE_POKEDEX: return "before_pokedex";
case StartMenu::FULL: return "full";
}
throw ParseException("Unsupported FRLG START menu.");
}
JsonArray strings(const std::vector<std::string>& values){
JsonArray result;
for (const std::string& value : values){
result.push_back(value);
}
return result;
}
int64_t count(size_t value){
if (value > (size_t)std::numeric_limits<int64_t>::max()){
throw ParseException("FRLG checkpoint count exceeds JSON integer range.");
}
return (int64_t)value;
}
JsonObject stats_json(const Stats& stats){
JsonObject result;
result["hp"] = stats.hp;
result["attack"] = stats.attack;
result["defense"] = stats.defense;
result["sp_attack"] = stats.sp_attack;
result["sp_defense"] = stats.sp_defense;
result["speed"] = stats.speed;
return result;
}
JsonObject member_json(const PartyMember& member){
JsonObject result;
result["species"] = member.species;
JsonArray moves;
for (const KnownMove& move : member.moves){
JsonObject entry;
entry["move"] = move.move;
entry["pp"] = move.pp;
moves.push_back(std::move(entry));
}
result["moves"] = std::move(moves);
result["moves_through_level"] = member.moves_through_level;
result["moves_read"] = member.moves_read;
result["level"] = member.level;
result["stats"] = member.stats ? JsonValue(stats_json(*member.stats)) : JsonValue();
return result;
}
JsonObject supplies_json(const Supplies& supplies){
JsonObject result;
result["potions"] = supplies.potions;
result["antidotes"] = supplies.antidotes;
result["parlyz_heals"] = supplies.parlyz_heals;
result["pocket"] = strings(supplies.pocket);
result["status"] = status_name(supplies.status);
result["hurt"] = supplies.hurt;
result["hp_red"] = supplies.hp_red;
result["hp_fill"] = supplies.hp_fill;
result["lead"] = member_json(supplies.lead);
JsonArray protected_slots;
for (size_t slot : supplies.protected_slots){
protected_slots.push_back(count(slot));
}
result["protected_slots"] = std::move(protected_slots);
result["foes"] = strings(supplies.foes);
result["trainer"] = supplies.trainer;
result["risk"] = battle_risk_name(supplies.risk);
result["foe_out"] = supplies.foe_out ? JsonValue(count(*supplies.foe_out)) : JsonValue();
result["wild_foes"] = strings(supplies.wild_foes);
return result;
}
} // namespace
JsonValue story_checkpoint_export(const StoryCheckpoint& checkpoint){
JsonObject result;
result["format"] = "pokesim-native-checkpoint-export/1";
result["game"] = "frlg";
result["status"] = "native-table-export";
result["checkpoint"] = Pokemon::story_checkpoint_json(checkpoint);
JsonObject native;
native["menu"] = menu_name(checkpoint.menu);
native["supplies"] = supplies_json(checkpoint.supplies);
result["native_fields"] = std::move(native);
result["state_basis"] = "native-table-bookkeeping";
result["unbound"] = strings({"runtime_configuration", "map_pins", "executor_bindings", "entry_evidence", "effective_save_retry_policy"});
return result;
}
} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* FRLG Authored Checkpoint Export
* From: https://github.com/PokemonAutomation/
*/
#ifndef PokemonAutomation_PokemonFRLG_AutoStoryExport_H
#define PokemonAutomation_PokemonFRLG_AutoStoryExport_H
#include "Common/Cpp/Json/JsonValue.h"
#include "PokemonFRLG_AutoStoryEvents.h"
namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{
// Capture evaluated shared fields and every FRLG checkpoint extension.
// Native supplies are bookkeeping, not observed state or entry requirements.
// Runtime options, map pins, effective policies and execution remain unbound.
JsonValue story_checkpoint_export(const StoryCheckpoint& checkpoint);
} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* FRLG Checkpoint Export Tests
* From: https://github.com/PokemonAutomation/
*/
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h"
#include "PokemonFRLG_AutoStoryExport.h"
#include "PokemonFRLG_AutoStoryTable.h"
#include "PokemonFRLG_AutoStoryExport_Tests.h"
namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{
namespace{
struct ExportInput{
std::string_view id;
bool custom = false;
};
struct ExportExpectation{
std::vector<std::string> events;
std::string_view menu;
std::string_view native_json = {};
};
struct ExportCase{
ExportInput input;
ExportExpectation expectation;
};
const ExportCase CASES[] = {
{.input = {.id = "00.05"}, .expectation = {.events = {"below_mart_door", "mart_door", "parcel_from_clerk"}, .menu = "before_pokedex"}},
{.input = {.id = "00.05", .custom = true}, .expectation = {
.events = {"below_mart_door", "mart_door", "parcel_from_clerk"}, .menu = "full",
.native_json = R"({"menu":"full","supplies":{"potions":2,"antidotes":3,"parlyz_heals":4,"pocket":["antidote",""],"status":"PSN","hurt":true,"hp_red":true,"hp_fill":0.25,"lead":{"species":"wartortle","moves":[{"move":"bite","pp":0}],"moves_through_level":18,"moves_read":true,"level":19,"stats":{"hp":50,"attack":20,"defense":30,"sp_attack":40,"sp_defense":35,"speed":25}},"protected_slots":[0,2],"foes":["staryu"],"trainer":"misty","risk":"high","foe_out":0,"wild_foes":["pidgey"]}})"
}},
};
void customize(StoryCheckpoint& row){
row.menu = StartMenu::FULL;
Supplies& state = row.supplies;
state.potions = 2;
state.antidotes = 3;
state.parlyz_heals = 4;
state.pocket = {"antidote", ""};
state.status = StatusCondition::POISON;
state.hurt = true;
state.hp_red = true;
state.hp_fill = 0.25;
state.lead = PartyMember{.species = "wartortle", .moves = {{"bite", 0}},
.moves_through_level = 18, .moves_read = true, .level = 19,
.stats = Stats{.hp = 50, .attack = 20, .defense = 30, .sp_attack = 40, .sp_defense = 35, .speed = 25}};
state.protected_slots = {0, 2};
state.foes = {"staryu"};
state.trainer = "misty";
state.risk = BattleRisk::HIGH;
state.foe_out = 0;
state.wild_foes = {"pidgey"};
}
std::string check_export(StoryCheckpoint row, const ExportCase& test){
if (test.input.custom){
customize(row);
}
const JsonValue encoded = story_checkpoint_export(row);
const JsonObject& root = encoded.to_object_throw();
const JsonObject& native = root.get_object_throw("native_fields");
if (native.get_string_throw("menu") != test.expectation.menu){
return "Expected menu " + std::string(test.expectation.menu) + ", read " + native.get_string_throw("menu");
}
if (!test.expectation.native_json.empty() && !(JsonValue(native.clone()) == parse_json(std::string(test.expectation.native_json)))){
return "Expected native fields " + std::string(test.expectation.native_json) + ", read " + native.dump();
}
const auto decoded = Pokemon::read_story_checkpoint(root.get_value_throw("checkpoint"), "export test");
if (!(Pokemon::story_checkpoint_json(decoded) == Pokemon::story_checkpoint_json(row))){
return "Expected every authored common field to survive export/import.";
}
std::vector<std::string> names;
for (const auto& step : decoded.steps){
names.push_back(step.name);
}
return names == test.expectation.events ? "" : "Expected Parcel's three authored events in order.";
}
class ExportTest : public UnitTest{
public:
explicit ExportTest(ExportCase test)
: UnitTest("PokemonFRLG::CheckpointExport - " + std::string(test.input.id) + (test.input.custom ? " custom" : " authored")), m_test(test){}
virtual UnitTestResult run(Logger&, CancellableScope&) const override{
for (const auto& row : story_checkpoints()){
if (row.id == m_test.input.id){
const std::string error = check_export(row, m_test);
return error.empty() ? UnitTestResult(true) : UnitTestResult(error);
}
}
return UnitTestResult("Expected checkpoint " + std::string(m_test.input.id) + ", read no matching row.");
}
private:
ExportCase m_test;
};
} // namespace
void add_tests_AutoStoryExport(UnitTestDatabase& database){
for (const ExportCase& test : CASES){
database.add<ExportTest>(test);
}
}
} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* FRLG Checkpoint Export Tests
* From: https://github.com/PokemonAutomation/
*/
#ifndef PokemonAutomation_PokemonFRLG_AutoStoryExport_Tests_H
#define PokemonAutomation_PokemonFRLG_AutoStoryExport_Tests_H
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{
// Register evaluated-table and non-default native-extension preservation tests.
void add_tests_AutoStoryExport(UnitTestDatabase& database);
} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
4 changes: 4 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,10 @@ file(GLOB LIBRARY_SOURCES
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty_Tests.cpp
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.cpp
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySummary.h
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.h
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h
Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp
Expand Down
17 changes: 17 additions & 0 deletions devtools/story-export/FRLG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Evaluates the real game table without constructing a console executor.
# Full application libraries are build dependencies; this is not PA_CORE_ONLY.
option(PA_FRLG_STORY_EXPORT "Build the offline evaluated FRLG checkpoint exporter" OFF)
if(PA_FRLG_STORY_EXPORT)
execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY "${REPO_ROOT_DIR}"
OUTPUT_VARIABLE STORY_EXPORT_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
execute_process(COMMAND git diff --quiet HEAD WORKING_DIRECTORY "${REPO_ROOT_DIR}"
RESULT_VARIABLE STORY_EXPORT_DIRTY)
if(NOT STORY_EXPORT_DIRTY EQUAL 0)
message(FATAL_ERROR "Commit tracked changes before configuring a provenance-bearing story export.")
endif()
add_executable(StoryCheckpointExport
../devtools/story-export/frlg_main.cpp)
target_link_libraries(StoryCheckpointExport PRIVATE SerialProgramsLib)
apply_common_target_properties(StoryCheckpointExport)
target_compile_definitions(StoryCheckpointExport PRIVATE PA_STORY_EXPORT_REVISION="${STORY_EXPORT_REVISION}")
endif()
38 changes: 38 additions & 0 deletions devtools/story-export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Evaluated native story checkpoint capture

This first adapter exports FRLG stage 1's actual `story_checkpoints()` rows.
It does not parse C++ text, construct a story executor, load a save, open a
profile or send controller inputs. It is a full-library build target, not the
Qt-free core target; linking Qt libraries does not create an application/window.

From a clean committed checkout with the usual native build dependencies:

```sh
cmake -S SerialPrograms -B build -DPA_FRLG_STORY_EXPORT=ON
cmake --build build --target StoryCheckpointExport -j4
build/StoryCheckpointExport 00.05 > frlg-parcel.native.json
```

On multi-configuration generators add `--config RelWithDebInfo`, then run
`build/RelWithDebInfo/StoryCheckpointExport.exe`. The current full-library CI
builds the target on every platform and captures Parcel as a Linux artifact.
Reconfigure after switching source revisions: `source_revision` names the clean
revision used at configure time. Canonical captures should come from clean CI.

The `pokesim-native-checkpoint-export/1` capture contains the shared checkpoint
codec plus all fields of this source revision's FRLG checkpoint extension:
menu and supplies (including party moves/PP, optional stats, slot zero, and
foe bookkeeping). Defaults remain native bookkeeping, not measured state or
requirements. No inference of full HP, actual inventory or battle probability
is permitted from this capture alone.

Runtime configuration, map pins, executor bindings, entry evidence and effective
save/retry policy are explicitly unbound. This is not the proposed executable
story-plan envelope, and must not be passed directly to a console executor.
Other native revisions with more checkpoint fields need an updated adapter.
BDSP `01.03`, policy binding and native/Python execution parity remain next.

Stdout is machine JSON; import/format it through PokemonSimulation's native
export CLI and compact contract formatter before checking in review data.
Tests next to the adapter check the real Parcel row and every native extension
field using synthetic non-default state. They do not validate console timings.
Loading
Loading