yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_project_labels.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_DUNGEON_PROJECT_LABELS_H
2#define YAZE_APP_EDITOR_DUNGEON_DUNGEON_PROJECT_LABELS_H
3
4#include <cstddef>
5#include <string>
6
7#include "absl/strings/str_format.h"
8#include "core/project.h"
10
12
13// Keep labels attached to the viewer's project, including while another ROM
14// session owns the global label provider. The legacy provider setter accepts a
15// mutable map; these local lookups only call its const query methods.
17 const project::YazeProject* project) {
19 if (project) {
20 labels.SetProjectLabels(
22 &project->resource_labels));
23 labels.SetHackManifest(&project->hack_manifest);
24 }
25 return labels;
26}
27
28inline std::string GetRoomTagLabel(const project::YazeProject* project,
29 int id) {
30 const auto labels = LabelsForProject(project);
31 std::string label = labels.GetLabel(zelda3::ResourceType::kRoomTag, id);
32 if (project) {
33 const auto tag =
34 project->hack_manifest.GetRoomTag(static_cast<uint8_t>(id));
35 if (tag && !tag->enabled) {
36 label += " (disabled)";
37 }
38 }
39 return label;
40}
41
43 const project::YazeProject* project, int room_id,
44 size_t* dungeon_index = nullptr) {
45 // Real Oracle .yaze projects can ship a project_registry (Docs/Dev/Planning/
46 // dungeons.json) without an accompanying hack_manifest_v1.json — see
47 // ProjectPathsTest::OpenInjectsOracleDungeonRoomLabelsIntoProjectFile. The
48 // registry is the canonical source of room/dungeon names; the hack manifest
49 // is an independent, optional add-on. Don't gate registry lookups on it.
50 if (!project || !project->project_opened() ||
52 return nullptr;
53 }
54
55 const auto& dungeons = project->hack_manifest.project_registry().dungeons;
56 for (size_t i = 0; i < dungeons.size(); ++i) {
57 const auto& dungeon = dungeons[i];
58 for (const auto& room : dungeon.rooms) {
59 if (room.id == room_id) {
60 if (dungeon_index) {
61 *dungeon_index = i;
62 }
63 return &dungeon;
64 }
65 }
66 }
67 return nullptr;
68}
69
71 const project::YazeProject* project, int room_id) {
72 const core::DungeonEntry* dungeon = FindDungeonForRoom(project, room_id);
73 if (!dungeon) {
74 return nullptr;
75 }
76 for (const auto& room : dungeon->rooms) {
77 if (room.id == room_id) {
78 return &room;
79 }
80 }
81 return nullptr;
82}
83
84inline std::string FormatDungeonName(const core::DungeonEntry& dungeon) {
85 if (dungeon.id.empty()) {
86 return dungeon.name;
87 }
88 if (dungeon.name.empty()) {
89 return dungeon.id;
90 }
91 return absl::StrFormat("%s %s", dungeon.id, dungeon.name);
92}
93
94inline std::string GetDungeonNameForRoom(const project::YazeProject* project,
95 int room_id) {
96 const core::DungeonEntry* dungeon = FindDungeonForRoom(project, room_id);
97 return dungeon ? FormatDungeonName(*dungeon) : std::string();
98}
99
100inline std::string GetRoomFloorLabel(const project::YazeProject* project,
101 int room_id) {
102 if (const core::DungeonRoom* room = FindDungeonRoom(project, room_id);
103 room && !room->floor.empty()) {
104 return room->floor;
105 }
106 return std::string();
107}
108
109inline std::string GetRoomLabel(const project::YazeProject* project,
110 int room_id) {
111 if (const core::DungeonRoom* room = FindDungeonRoom(project, room_id);
112 room && !room->name.empty()) {
113 return room->name;
114 }
115 auto& labels = zelda3::GetResourceLabels();
116 return labels.GetLabel(zelda3::ResourceType::kRoom, room_id);
117}
118
119} // namespace yaze::editor::dungeon_project_labels
120
121#endif // YAZE_APP_EDITOR_DUNGEON_DUNGEON_PROJECT_LABELS_H
std::optional< RoomTagEntry > GetRoomTag(uint8_t tag_id) const
Get the full room tag entry for a tag ID.
const ProjectRegistry & project_registry() const
bool HasProjectRegistry() const
Unified interface for accessing resource labels with project overrides.
std::unordered_map< std::string, LabelMap > ProjectLabels
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)
zelda3::ResourceLabelProvider LabelsForProject(const project::YazeProject *project)
std::string GetRoomTagLabel(const project::YazeProject *project, int id)
std::string GetRoomLabel(const project::YazeProject *project, int room_id)
const core::DungeonEntry * FindDungeonForRoom(const project::YazeProject *project, int room_id, size_t *dungeon_index=nullptr)
std::string GetDungeonNameForRoom(const project::YazeProject *project, int room_id)
const core::DungeonRoom * FindDungeonRoom(const project::YazeProject *project, int room_id)
std::string GetRoomFloorLabel(const project::YazeProject *project, int room_id)
std::string FormatDungeonName(const core::DungeonEntry &dungeon)
ResourceLabelProvider & GetResourceLabels()
Get the global ResourceLabelProvider instance.
A complete dungeon entry with rooms and connections.
std::vector< DungeonRoom > rooms
A room within a dungeon, with spatial and metadata info.
std::vector< DungeonEntry > dungeons
Modern project structure with comprehensive settings consolidation.
Definition project.h:287
bool project_opened() const
Definition project.h:505
core::HackManifest hack_manifest
Definition project.h:360
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > resource_labels
Definition project.h:353