yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
gfx_sheet_inventory.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_GFX_SHEET_INVENTORY_H
2#define YAZE_ZELDA3_GFX_SHEET_INVENTORY_H
3
4#include <array>
5#include <cstdint>
6#include <map>
7#include <optional>
8#include <set>
9#include <string>
10#include <vector>
11
12#include "absl/status/statusor.h"
13#include "nlohmann/json_fwd.hpp"
14#include "rom/rom.h"
16
17namespace yaze::zelda3 {
18
19struct GameData;
20class Overworld;
21
34constexpr uint16_t kSpriteSheetBase = 0x73;
35constexpr uint16_t kSpriteSheetValueCount = 0x67;
36constexpr uint16_t kDungeonSpritesetBase = 0x40;
37constexpr int kNumOverworldAreas = 0xA0;
38constexpr int kNumDungeonRooms = 0x128;
39
41 int world = 0; // 0 light, 1 dark, 2 special
42 uint8_t parent = 0;
43 uint8_t area_graphics = 0;
44 std::array<uint8_t, 16> static_graphics{};
45 // Sprite graphics set per game state (beginning, first part, second part).
46 std::array<uint8_t, 3> sprite_graphics{};
47};
48
50 uint8_t blockset = 0;
51 uint8_t spriteset = 0; // header value; spriteset index = value + 0x40
52};
53
55 std::vector<int> main_blocksets;
56 std::vector<int> room_blocksets;
57 std::vector<int> ow_areas_static;
58 // Set for sprite sheets only (gfx 0x73-0xD9).
59 std::vector<int> spritesets;
60 std::vector<int> ow_areas_sprite;
61 std::vector<int> rooms_sprite;
62
63 bool Any() const {
64 return !main_blocksets.empty() || !room_blocksets.empty() ||
65 !ow_areas_static.empty() || !spritesets.empty() ||
66 !ow_areas_sprite.empty() || !rooms_sprite.empty();
67 }
68};
69
71 uint16_t gfx = 0;
72 uint32_t pc = 0;
74 // Set for gfx 0x73-0xD9: the value a spriteset stores for this sheet.
75 std::optional<uint8_t> sprite_value;
76 // 3bpp sheets only (2bpp sheets are engine-loaded fonts and UI).
77 std::optional<size_t> stored_bytes;
78 bool has_block_stats = false;
79 int empty_8x8 = 0;
80 std::vector<int> empty_16x16_blocks;
81 bool all_empty = false;
82 std::string sha1; // first 12 hex digits of the 0x600-byte sheet
83 std::string error;
84 bool reserved = false;
85 bool flagged = false; // looks free, needs the owner's approval
86 std::vector<uint16_t> reserved_blocks;
87 bool engine_loaded = false;
88 std::vector<uint16_t> shares_pointer_with;
89 std::vector<uint16_t> same_content_as;
91 bool unreferenced = false;
92 std::vector<std::string> labels;
93
96 std::vector<int> FreeBlocks() const;
97};
98
100 std::set<uint16_t> reserved_sheets;
101 std::set<uint16_t> flagged_sheets;
102 std::map<uint16_t, std::vector<uint16_t>> reserved_blocks;
103 // Names per spriteset value, for example from Oracle's Spritesets sheet.
104 std::map<uint8_t, std::set<std::string>> sprite_value_labels;
105};
106
108 std::vector<GfxSheetInventoryEntry> sheets; // kGfxSheetCount entries
109 std::vector<std::array<uint8_t, 4>> spritesets;
110 std::vector<std::array<uint8_t, 8>> main_blocksets;
111 std::vector<std::array<uint8_t, 4>> room_blocksets;
112 std::map<int, OverworldAreaGfxInfo> overworld_areas;
113 std::map<int, RoomGfxInfo> rooms;
114};
115
118absl::StatusOr<GfxSheetInventory> BuildGfxSheetInventory(
119 const Rom& rom, const std::map<int, OverworldAreaGfxInfo>& areas,
120 const std::map<int, RoomGfxInfo>& rooms,
121 const GfxSheetInventoryOptions& options = {});
122
126std::map<int, OverworldAreaGfxInfo> CollectOverworldAreaGfx(
127 Rom& rom, GameData* game_data = nullptr);
128
132std::map<int, RoomGfxInfo> CollectRoomGfx(const Rom& rom);
133
136 // Spritesets: overworld areas per game state (0 beginning, 1 first part,
137 // 2 second part).
138 std::array<std::vector<int>, 3> ow_areas_by_state;
139 // Roomsets: overworld areas whose area graphics (room blockset) match.
140 std::vector<int> ow_areas;
141 // Spritesets: rooms whose header value + 0x40 matches.
142 // Roomsets: rooms whose header blockset matches.
143 std::vector<int> rooms;
144};
145
147 int spriteset, const std::map<int, OverworldAreaGfxInfo>& areas,
148 const std::map<int, RoomGfxInfo>& rooms);
149
151 const std::map<int, OverworldAreaGfxInfo>& areas,
152 const std::map<int, RoomGfxInfo>& rooms);
153
158 std::vector<int> rooms;
159 std::vector<int> ow_areas;
160 std::vector<int> overridden_ow_areas;
161 std::vector<int> independent_ow_areas;
165};
166
169absl::StatusOr<RoomsetUsageReport> DescribeRoomsetUsage(
170 Rom& rom, GameData& game_data, int roomset,
171 const std::map<int, RoomGfxInfo>& rooms,
172 const Overworld* live_overworld = nullptr);
173
179 std::vector<int> explicit_preview_rooms;
180 std::vector<int> direct_default_rooms;
181 std::vector<int> inferred_default_rooms;
182 std::vector<int> fallback_rooms;
183 std::vector<int> overridden_rooms;
184 std::vector<int> ow_areas;
185 std::vector<int> overridden_ow_areas;
186 std::vector<int> independent_ow_areas;
190 // Overworld slot 7's main/area sheet supplies its bottom half only; the top
191 // half is animated. Dungeon room slot 7 uses the full sheet.
193};
194
195absl::StatusOr<MainGroupUsageReport> DescribeMainGroupUsage(
196 Rom& rom, GameData& game_data, int group, int slot,
197 const std::map<int, RoomGfxInfo>& rooms,
198 const std::map<int, uint8_t>& explicit_room_main = {},
199 const Overworld* live_overworld = nullptr);
200
205nlohmann::json GfxSheetInventoryToJson(const GfxSheetInventory& inventory);
206
208
211std::map<uint8_t, std::set<std::string>> ParseSpritesetLabelCsv(
212 const std::string& csv_text);
213
214} // namespace yaze::zelda3
215
216#endif // YAZE_ZELDA3_GFX_SHEET_INVENTORY_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:49
Locates graphics sheets in the ROM and writes edited sheets back.
Zelda 3 specific classes and functions.
constexpr int kNumDungeonRooms
absl::StatusOr< RoomsetUsageReport > DescribeRoomsetUsage(Rom &rom, GameData &game_data, int roomset, const std::map< int, RoomGfxInfo > &rooms, const Overworld *live_overworld)
GfxGroupUsage FindSpritesetUsage(int spriteset, const std::map< int, OverworldAreaGfxInfo > &areas, const std::map< int, RoomGfxInfo > &rooms)
absl::StatusOr< MainGroupUsageReport > DescribeMainGroupUsage(Rom &rom, GameData &game_data, int group, int slot, const std::map< int, RoomGfxInfo > &rooms, const std::map< int, uint8_t > &explicit_room_main, const Overworld *live_overworld)
std::map< int, OverworldAreaGfxInfo > CollectOverworldAreaGfx(Rom &rom, GameData *game_data)
const char * GfxSheetInventoryKindName(GfxSheetStorageKind kind)
absl::StatusOr< GfxSheetInventory > BuildGfxSheetInventory(const Rom &rom, const std::map< int, OverworldAreaGfxInfo > &areas, const std::map< int, RoomGfxInfo > &rooms, const GfxSheetInventoryOptions &options)
constexpr uint16_t kDungeonSpritesetBase
constexpr uint16_t kSpriteSheetValueCount
std::map< int, RoomGfxInfo > CollectRoomGfx(const Rom &rom)
constexpr uint16_t kSpriteSheetBase
GfxGroupUsage FindRoomsetUsage(int roomset, const std::map< int, OverworldAreaGfxInfo > &areas, const std::map< int, RoomGfxInfo > &rooms)
std::map< uint8_t, std::set< std::string > > ParseSpritesetLabelCsv(const std::string &csv_text)
constexpr int kNumOverworldAreas
nlohmann::json GfxSheetInventoryToJson(const GfxSheetInventory &inventory)
Where one spriteset or roomset is used.
std::array< std::vector< int >, 3 > ow_areas_by_state
std::vector< uint16_t > shares_pointer_with
std::map< uint8_t, std::set< std::string > > sprite_value_labels
std::map< uint16_t, std::vector< uint16_t > > reserved_blocks
std::vector< GfxSheetInventoryEntry > sheets
std::vector< std::array< uint8_t, 8 > > main_blocksets
std::vector< std::array< uint8_t, 4 > > spritesets
std::vector< std::array< uint8_t, 4 > > room_blocksets
std::map< int, OverworldAreaGfxInfo > overworld_areas
std::map< int, RoomGfxInfo > rooms
std::array< uint8_t, 16 > static_graphics
std::array< uint8_t, 3 > sprite_graphics