yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_wall_profile.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_DUNGEON_WALL_PROFILE_H_
2#define YAZE_ZELDA3_DUNGEON_DUNGEON_WALL_PROFILE_H_
3
4#include <cstddef>
5#include <cstdint>
6#include <memory>
7#include <optional>
8#include <string>
9#include <vector>
10
11#include "absl/status/statusor.h"
12#include "absl/strings/string_view.h"
14
15namespace yaze::zelda3 {
16
17inline constexpr size_t kWallProfileMaxSourceBytes = 1024 * 1024;
18inline constexpr size_t kWallProfileMaxProfiles = 128;
19inline constexpr size_t kWallProfileMaxPatterns = 128;
20inline constexpr size_t kWallProfileMaxWordsPerProfile = 4096;
21inline constexpr size_t kWallProfileMaxBindings = 4096;
22
24 std::string name;
25 uint32_t pc_offset;
26 std::vector<uint16_t> words;
27};
28
30 std::string id;
31 std::vector<DungeonWallPattern> patterns;
32};
33
35 uint16_t room;
36 std::string profile;
37 std::optional<uint8_t> world;
38 std::optional<uint16_t> entrance;
39};
40
41// Missing optional context never satisfies an entrance/world constraint.
43 int room = -1;
44 std::optional<int> world;
45 std::optional<int> entrance;
46};
47
48// A validated immutable source snapshot. This model owns no global state and
49// performs no publication, ROM mutation, editor history or rendering.
51 public:
52 const std::vector<DungeonWallProfile>& profiles() const { return profiles_; }
53 const std::vector<DungeonWallProfileBinding>& bindings() const {
54 return bindings_;
55 }
56 const std::string& source_text() const { return source_text_; }
57 const std::string& source_path() const { return source_path_; }
58
59 private:
60 friend absl::StatusOr<std::shared_ptr<const DungeonWallProfileCollection>>
61 ParseDungeonWallProfiles(absl::string_view source);
62 friend absl::StatusOr<std::shared_ptr<const DungeonWallProfileCollection>>
63 LoadDungeonWallProfiles(const std::string& path);
64
65 DungeonWallProfileCollection(std::vector<DungeonWallProfile> profiles,
66 std::vector<DungeonWallProfileBinding> bindings,
67 std::string source_text,
68 std::string source_path);
69
70 std::vector<DungeonWallProfile> profiles_;
71 std::vector<DungeonWallProfileBinding> bindings_;
72 std::string source_text_;
73 std::string source_path_;
74};
75
76// The merged words are read-only. A selected profile has no legacy publication
77// provenance: its words must never be published into the legacy ASM source.
79 public:
80 const std::optional<std::string>& profile_id() const { return profile_id_; }
81 const DungeonTilePatterns& patterns() const { return patterns_; }
82
83 private:
84 friend absl::StatusOr<ResolvedWallProfile> ResolveWallProfile(
85 const DungeonWallProfileCollection& collection,
86 const WallProfileContext& context, const DungeonTilePatterns& legacy);
87
88 ResolvedWallProfile(std::optional<std::string> profile_id,
90
91 std::optional<std::string> profile_id_;
93};
94
95// Strict JSON v1. Unknown/duplicate keys, signed/float/bool numeric fields,
96// invalid identifiers, overlapping profile spans and resource excesses reject
97// the whole source. All addresses are aligned headerless bank-00 pattern PCs.
98absl::StatusOr<std::shared_ptr<const DungeonWallProfileCollection>>
99ParseDungeonWallProfiles(absl::string_view source);
100absl::StatusOr<std::shared_ptr<const DungeonWallProfileCollection>>
101LoadDungeonWallProfiles(const std::string& path);
102
103// Chooses the matching binding with the most optional constraints. Equal-best
104// matches are an error, even if they name the same profile. Equal-rank
105// intersecting bindings are rejected while parsing. No match preserves the
106// legacy snapshot exactly.
107absl::StatusOr<ResolvedWallProfile> ResolveWallProfile(
108 const DungeonWallProfileCollection& collection,
109 const WallProfileContext& context, const DungeonTilePatterns& legacy);
110
111} // namespace yaze::zelda3
112
113#endif // YAZE_ZELDA3_DUNGEON_DUNGEON_WALL_PROFILE_H_
const std::vector< DungeonWallProfile > & profiles() const
std::vector< DungeonWallProfileBinding > bindings_
const std::vector< DungeonWallProfileBinding > & bindings() const
friend absl::StatusOr< std::shared_ptr< const DungeonWallProfileCollection > > LoadDungeonWallProfiles(const std::string &path)
friend absl::StatusOr< std::shared_ptr< const DungeonWallProfileCollection > > ParseDungeonWallProfiles(absl::string_view source)
DungeonWallProfileCollection(std::vector< DungeonWallProfile > profiles, std::vector< DungeonWallProfileBinding > bindings, std::string source_text, std::string source_path)
std::vector< DungeonWallProfile > profiles_
const std::optional< std::string > & profile_id() const
friend absl::StatusOr< ResolvedWallProfile > ResolveWallProfile(const DungeonWallProfileCollection &collection, const WallProfileContext &context, const DungeonTilePatterns &legacy)
ResolvedWallProfile(std::optional< std::string > profile_id, DungeonTilePatterns patterns)
std::optional< std::string > profile_id_
const DungeonTilePatterns & patterns() const
Zelda 3 specific classes and functions.
constexpr size_t kWallProfileMaxBindings
absl::StatusOr< std::shared_ptr< const DungeonWallProfileCollection > > ParseDungeonWallProfiles(absl::string_view source)
constexpr size_t kWallProfileMaxPatterns
absl::StatusOr< std::shared_ptr< const DungeonWallProfileCollection > > LoadDungeonWallProfiles(const std::string &path)
constexpr size_t kWallProfileMaxWordsPerProfile
absl::StatusOr< ResolvedWallProfile > ResolveWallProfile(const DungeonWallProfileCollection &collection, const WallProfileContext &context, const DungeonTilePatterns &legacy)
constexpr size_t kWallProfileMaxProfiles
constexpr size_t kWallProfileMaxSourceBytes
std::vector< DungeonWallPattern > patterns