yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
story_event_graph.h
Go to the documentation of this file.
1#ifndef YAZE_CORE_STORY_EVENT_GRAPH_H
2#define YAZE_CORE_STORY_EVENT_GRAPH_H
3
4#include <cstdint>
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9#include "absl/status/status.h"
11
12namespace yaze::core {
13
17struct StoryFlag {
18 std::string name;
19 std::string value; // e.g., "2" for GameState=2
20 std::string reg; // e.g., "OOSPROG" for bit-based flags
21 int bit = -1; // Bit index if applicable (-1 = not a bitfield)
22 std::string operation; // "increment", "set", etc.
23};
24
29 std::string name;
30 std::string entrance_id; // e.g., "0/1", "2"
31 std::string overworld_id; // e.g., "0x33"
32 std::string special_world_id; // e.g., "0x80"
33 std::string room_id; // e.g., "0x202"
34};
35
48 std::string reg; // e.g., "GAMESTATE", "CRYSTALS", "OOSPROG"
49 std::string op;
50 int value = 0;
51 int bit = -1;
52 uint32_t mask = 0;
53};
54
58struct StoryEdge {
59 std::string from;
60 std::string to;
61 std::string type; // "dependency"
62};
63
67enum class StoryNodeStatus : uint8_t {
68 kLocked, // Prerequisites not met (gray)
69 kAvailable, // Prerequisites met, not yet done (yellow)
70 kCompleted, // Event has occurred (green)
71 kBlocked, // Has a blocker annotation (red)
72};
73
85 std::string id; // "EV-001"
86 std::string name; // "Intro begins"
87
88 std::vector<StoryFlag> flags;
89 std::vector<StoryLocation> locations;
90 std::vector<std::string> scripts;
91 std::vector<std::string> text_ids; // hex: "0x1F"
92
93 // Optional completion predicates. If empty, the graph falls back to
94 // heuristics based on game_state/crystals (legacy behavior).
95 std::vector<StoryPredicate> completed_when;
96
97 std::vector<std::string> dependencies; // Inbound edge source IDs
98 std::vector<std::string> unlocks; // Outbound edge target IDs
99
100 std::string evidence;
101 std::string last_verified;
102 std::string notes;
103
104 // Layout position (computed by AutoLayout)
105 float pos_x = 0.0f;
106 float pos_y = 0.0f;
107
108 // Runtime state
110};
111
130 public:
131 StoryEventGraph() = default;
132
136 absl::Status LoadFromJson(const std::string& path);
137
141 absl::Status LoadFromString(const std::string& json_content);
142
146 [[nodiscard]] bool loaded() const { return !nodes_.empty(); }
147
155 void AutoLayout();
156
163 void UpdateStatus(uint8_t crystal_bitfield, uint8_t game_state);
164
168 void UpdateStatus(const OracleProgressionState& state);
169
173 [[nodiscard]] std::vector<std::string> GetCompletedNodes(
174 uint8_t crystal_bitfield, uint8_t game_state) const;
175
179 [[nodiscard]] std::vector<std::string> GetCompletedNodes(
180 const OracleProgressionState& state) const;
181
182 // ─── Accessors ─────────────────────────────────────────────────
183
184 [[nodiscard]] const std::vector<StoryEventNode>& nodes() const {
185 return nodes_;
186 }
187
188 [[nodiscard]] const std::vector<StoryEdge>& edges() const { return edges_; }
189
190 [[nodiscard]] const StoryEventNode* GetNode(const std::string& id) const;
191
192 private:
193 std::vector<StoryEventNode> nodes_;
194 std::vector<StoryEdge> edges_;
195 std::unordered_map<std::string, size_t> node_index_; // id -> nodes_ index
196};
197
198} // namespace yaze::core
199
200#endif // YAZE_CORE_STORY_EVENT_GRAPH_H
The complete Oracle narrative progression graph.
const std::vector< StoryEventNode > & nodes() const
void AutoLayout()
Compute layout positions using topological sort + layered positioning.
std::vector< StoryEventNode > nodes_
std::vector< StoryEdge > edges_
const StoryEventNode * GetNode(const std::string &id) const
void UpdateStatus(uint8_t crystal_bitfield, uint8_t game_state)
Update node completion status based on SRAM state.
std::vector< std::string > GetCompletedNodes(uint8_t crystal_bitfield, uint8_t game_state) const
Get IDs of events that are completed based on SRAM state.
bool loaded() const
Check if the graph has been loaded.
const std::vector< StoryEdge > & edges() const
absl::Status LoadFromJson(const std::string &path)
Load the graph from a JSON file.
std::unordered_map< std::string, size_t > node_index_
absl::Status LoadFromString(const std::string &json_content)
Load the graph from a JSON string.
StoryNodeStatus
Completion status of a story event node for rendering.
Oracle of Secrets game progression state parsed from SRAM.
A directed edge in the story event graph.
A node in the Oracle story event graph.
std::vector< StoryLocation > locations
std::vector< std::string > unlocks
std::vector< std::string > dependencies
std::vector< std::string > scripts
std::vector< std::string > text_ids
std::vector< StoryFlag > flags
std::vector< StoryPredicate > completed_when
A flag set or cleared by a story event.
A location associated with a story event.
A predicate for determining event completion from SRAM state.