yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
resource_labels.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_RESOURCE_LABELS_H
2#define YAZE_ZELDA3_RESOURCE_LABELS_H
3
4#include <cstdint>
5#include <functional>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "core/hack_manifest.h"
12
13namespace yaze {
14namespace zelda3 {
15
20enum class ResourceType {
21 kSprite,
22 kRoom,
24 kItem,
27 kMusic,
32};
33
37std::string ResourceTypeToString(ResourceType type);
38
42ResourceType StringToResourceType(const std::string& type_str);
43
44// Project label section for explicit user room renames. Opening an Oracle
45// project re-injects registry defaults into "room", so renames live here and
46// take precedence over registry and "room" labels.
47inline constexpr char kRoomOverrideLabelType[] = "room_override";
48
57 // Project name when set, else default_name.
58 std::string name;
59 // Hyrule Magic name (sprites, when preferred), else vanilla.
60 std::string default_name;
61 bool from_project = false;
62
63 // "Collectible (vanilla: ZoraKing)" when renamed, else just the name.
64 std::string Display() const;
65};
66
81 public:
82 using LabelMap = std::unordered_map<std::string, std::string>;
83 using ProjectLabels = std::unordered_map<std::string, LabelMap>;
84
86
91
95 void SetHackManifest(const core::HackManifest* manifest) {
96 hack_manifest_ = manifest;
97 }
99
111 std::string GetLabel(ResourceType type, int id) const;
112
116 std::string GetDefaultLabel(ResourceType type, int id) const;
117
121 ResolvedLabel ResolveLabel(ResourceType type, int id) const;
122
126 std::string GetLabel(const std::string& type_str, int id) const;
127
131 void SetProjectLabel(ResourceType type, int id, const std::string& label);
132
136 void ClearProjectLabel(ResourceType type, int id);
137
141 bool HasProjectLabel(ResourceType type, int id) const;
142
146 std::string GetVanillaLabel(ResourceType type, int id) const;
147
151 std::string GetHMagicLabel(ResourceType type, int id) const;
152
153 // =========================================================================
154 // Hyrule Magic Naming Toggle
155 // =========================================================================
156
160 void SetPreferHMagicNames(bool prefer) { prefer_hmagic_ = prefer; }
161
165 bool PreferHMagicNames() const { return prefer_hmagic_; }
166
167 // =========================================================================
168 // ZScream DefaultNames.txt Import/Export
169 // =========================================================================
170
182 absl::Status ImportFromZScreamFormat(const std::string& content);
183
188 std::string ExportToZScreamFormat() const;
189
198 absl::Status ImportOracleSpriteRegistry(const std::string& csv_content);
199
200 // =========================================================================
201 // Utility Methods
202 // =========================================================================
203
207 int GetResourceCount(ResourceType type) const;
208
213
218
223
227 struct State {
230 bool prefer_hmagic = true;
231 };
235 void RestoreState(const State& state) {
239 }
240
241 private:
242 // Project-specific label overrides (owned by YazeProject)
244
245 // Hack manifest reference (owned by YazeProject)
247
248 // Whether to prefer Hyrule Magic sprite names
249 bool prefer_hmagic_ = true;
250
251 // Parse a single line in ZScream format
252 bool ParseZScreamLine(const std::string& line, const std::string& section,
253 int& line_index);
254};
255
256// ============================================================================
257// Global Provider Instance
258// ============================================================================
259
267
271inline std::string GetSpriteLabel(int id) {
273}
274
281
285inline std::string GetRoomLabel(int id) {
287}
288
292inline std::string GetItemLabel(int id) {
294}
295
296// Chest/item-receipt IDs use the separate "item_receipt" project-label namespace.
297// Generic "item" labels have a different ID domain and are never used here.
298// A vanilla fallback does not establish the meaning of a patched receipt handler.
299// Explicit context (including nullptr) never consults the global provider.
300std::string GetItemReceiptLabel(
301 uint8_t id, const ResourceLabelProvider::ProjectLabels* project_labels);
302const char* GetItemReceiptLabelSource(
303 uint8_t id, const ResourceLabelProvider::ProjectLabels* project_labels);
304// Compatibility helpers for callers that use the active global project.
305std::string GetItemReceiptLabel(uint8_t id);
306const char* GetItemReceiptLabelSource(uint8_t id);
307
311inline std::string GetEntranceLabel(int id) {
313}
314
318inline std::string GetOverlordLabel(int id) {
320}
321
325inline std::string GetOverworldMapLabel(int id) {
327}
328
332inline std::string GetMusicLabel(int id) {
334}
335
339inline std::string GetRoomTagLabel(int id) {
341}
342
343} // namespace zelda3
344} // namespace yaze
345
346#endif // YAZE_ZELDA3_RESOURCE_LABELS_H
Loads and queries the hack manifest JSON for yaze-ASM integration.
Unified interface for accessing resource labels with project overrides.
std::string ExportToZScreamFormat() const
Export project labels to ZScream DefaultNames.txt format.
void SetProjectLabel(ResourceType type, int id, const std::string &label)
Set a project-specific label override.
bool HasProjectLabel(ResourceType type, int id) const
Check if a project-specific label exists.
const ProjectLabels * GetAllProjectLabels() const
Get all project labels (read-only)
void ClearAllProjectLabels()
Clear all project labels.
int GetResourceCount(ResourceType type) const
Get the count of resources for a given type.
std::unordered_map< std::string, std::string > LabelMap
const core::HackManifest * hack_manifest_
bool PreferHMagicNames() const
Get whether Hyrule Magic names are preferred.
std::string GetDefaultLabel(ResourceType type, int id) const
Get the label without project overrides (steps 4-5 above)
const core::HackManifest * hack_manifest() const
ResolvedLabel ResolveLabel(ResourceType type, int id) const
Get the label and the default name it replaces.
std::string GetLabel(ResourceType type, int id) const
Get a label for a resource by type and ID.
void RestoreState(const State &state)
bool ParseZScreamLine(const std::string &line, const std::string &section, int &line_index)
void SetPreferHMagicNames(bool prefer)
Set whether to prefer Hyrule Magic sprite names.
std::unordered_map< std::string, LabelMap > ProjectLabels
absl::Status ImportFromZScreamFormat(const std::string &content)
Import labels from ZScream DefaultNames.txt format.
std::string GetVanillaLabel(ResourceType type, int id) const
Get the vanilla (default) label for a resource.
const LabelMap * GetProjectLabelsForType(ResourceType type) const
Get all project labels for a given type.
std::string GetHMagicLabel(ResourceType type, int id) const
Get the Hyrule Magic label for a resource (sprites only)
void SetHackManifest(const core::HackManifest *manifest)
Set the hack manifest reference for ASM-defined labels.
void SetProjectLabels(ProjectLabels *labels)
Set the project labels reference (typically from YazeProject)
void ClearProjectLabel(ResourceType type, int id)
Clear a project-specific label (revert to default)
absl::Status ImportOracleSpriteRegistry(const std::string &csv_content)
Import sprite labels from Oracle of Secrets registry.csv format.
ResourceType
Enumeration of all supported resource types for labeling.
const char * GetItemReceiptLabelSource(uint8_t id, const ResourceLabelProvider::ProjectLabels *project_labels)
std::string GetRoomTagLabel(int id)
Convenience function to get a room tag label.
std::string GetSpriteLabel(int id)
Convenience function to get a sprite label.
ResolvedLabel ResolveSpriteLabel(int id)
Convenience function to resolve a sprite label with its default name.
std::string GetEntranceLabel(int id)
Convenience function to get an entrance label.
std::string GetRoomLabel(int id)
Convenience function to get a room label.
std::string GetItemReceiptLabel(uint8_t id, const ResourceLabelProvider::ProjectLabels *project_labels)
std::string GetOverlordLabel(int id)
Convenience function to get an overlord label.
std::string GetItemLabel(int id)
Convenience function to get an item label.
std::string GetOverworldMapLabel(int id)
Convenience function to get an overworld map label.
std::string ResourceTypeToString(ResourceType type)
Convert ResourceType enum to string key for storage.
ResourceType StringToResourceType(const std::string &type_str)
Convert string key to ResourceType enum.
std::string GetMusicLabel(int id)
Convenience function to get a music track label.
ResourceLabelProvider & GetResourceLabels()
Get the global ResourceLabelProvider instance.
A label plus the name it replaces.
Provider wiring, saved and restored around a scoped project.