10#include "absl/strings/str_format.h"
11#include "absl/strings/str_split.h"
12#include "absl/strings/strip.h"
42 return "overworld_map";
58 if (type_str ==
"sprite")
60 if (type_str ==
"room")
62 if (type_str ==
"entrance")
64 if (type_str ==
"item")
66 if (type_str ==
"overlord")
68 if (type_str ==
"overworld_map")
70 if (type_str ==
"music")
72 if (type_str ==
"graphics")
74 if (type_str ==
"room_effect")
76 if (type_str ==
"room_tag")
78 if (type_str ==
"tile_type")
88 auto lookup = [&](
const std::string& key) -> std::string {
89 auto it = labels.find(key);
90 if (it != labels.end() && !it->second.empty()) {
97 if (std::string decimal = lookup(std::to_string(
id)); !decimal.empty()) {
102 const std::string hex_upper = absl::StrFormat(
"%X",
id);
103 const std::string hex_lower = absl::StrFormat(
"%x",
id);
104 const std::array<std::string, 8> keys = {
105 absl::StrFormat(
"0x%s", hex_lower), absl::StrFormat(
"0x%s", hex_upper),
106 absl::StrFormat(
"0X%s", hex_upper), absl::StrFormat(
"$%s", hex_upper),
107 absl::StrFormat(
"0x%02X",
id), absl::StrFormat(
"0x%03X",
id),
108 absl::StrFormat(
"0x%04X",
id), absl::StrFormat(
"$%02X",
id),
111 for (
const auto& key : keys) {
112 if (std::string label = lookup(key); !label.empty()) {
122 if (project_labels) {
123 const auto it = project_labels->find(
"item_receipt");
124 if (it != project_labels->end()) {
142 for (
const auto& room : dungeon.rooms) {
143 if (room.id ==
id && !room.name.empty()) {
174 if (std::string registry_label =
176 !registry_label.empty()) {
177 return registry_label;
187 if (std::string project_label = LookupProjectLabel(type_it->second,
id);
188 !project_label.empty()) {
189 return project_label;
198 if (!manifest_label.empty()) {
199 return manifest_label;
208 if (!hmagic.empty()) {
224 const std::string& label) {
229 (*project_labels_)[type_str][std::to_string(
id)] = label;
239 type_it->second.erase(std::to_string(
id));
252 return !LookupProjectLabel(type_it->second,
id).empty();
260 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
263 return absl::StrFormat(
"Sprite %02X",
id);
267 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
270 return absl::StrFormat(
"Room %03X",
id);
274 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
277 return absl::StrFormat(
"Entrance %02X",
id);
281 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
284 return absl::StrFormat(
"Item %02X",
id);
288 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
291 return absl::StrFormat(
"Overlord %02X",
id);
295 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
298 return absl::StrFormat(
"Map %02X",
id);
302 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
305 return absl::StrFormat(
"Music %02X",
id);
309 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
312 return absl::StrFormat(
"GFX %02X",
id);
316 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
319 return absl::StrFormat(
"Effect %02X",
id);
323 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
326 return absl::StrFormat(
"Tag %02X",
id);
330 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
333 return absl::StrFormat(
"Tile %02X",
id);
336 return absl::StrFormat(
"Unknown %02X",
id);
405 const std::string& content) {
407 return absl::FailedPreconditionError(
408 "Project labels not initialized. Open a project first.");
411 std::istringstream stream(content);
413 std::string current_section;
417 while (std::getline(stream, line)) {
421 std::string trimmed = std::string(absl::StripAsciiWhitespace(line));
424 if (trimmed.empty() || trimmed.substr(0, 2) ==
"//") {
429 if (trimmed.front() ==
'[' && trimmed.back() ==
']') {
430 current_section = trimmed.substr(1, trimmed.length() - 2);
436 if (!current_section.empty()) {
441 return absl::OkStatus();
445 const std::string& section,
452 std::string resource_type;
453 bool has_hex_prefix =
false;
455 if (section ==
"Sprites Names") {
456 resource_type =
"sprite";
457 has_hex_prefix =
true;
458 }
else if (section ==
"Rooms Names") {
459 resource_type =
"room";
460 has_hex_prefix =
false;
461 }
else if (section ==
"Chests Items") {
462 resource_type =
"item_receipt";
463 has_hex_prefix =
true;
464 }
else if (section ==
"Tags Names") {
465 resource_type =
"room_tag";
466 has_hex_prefix =
false;
475 if (has_hex_prefix) {
477 size_t space_pos = line.find(
' ');
478 if (space_pos == std::string::npos || space_pos < 2) {
483 std::string hex_str = line.substr(0, space_pos);
484 label = line.substr(space_pos + 1);
488 int id = std::stoi(hex_str,
nullptr, 16);
489 id_str = std::to_string(
id);
495 id_str = std::to_string(line_index);
501 label = std::string(absl::StripAsciiWhitespace(label));
504 if (!label.empty()) {
505 (*project_labels_)[resource_type][id_str] = label;
512 std::ostringstream output;
514 output <<
"//Do not use brackets [] in naming\n";
517 output <<
"[Sprites Names]\n";
518 for (
int i = 0; i < 256; ++i) {
520 output << absl::StrFormat(
"%02X %s\n", i, label);
524 output <<
"\n[Rooms Names]\n";
525 for (
int i = 0; i < 297; ++i) {
527 output << label <<
"\n";
531 output <<
"\n[Chests Items]\n";
532 for (
int i = 0; i <= 0xFF; ++i) {
533 const auto id =
static_cast<uint8_t
>(i);
538 output << absl::StrFormat(
"%02X %s\n", i,
543 output <<
"\n[Tags Names]\n";
545 for (
int i = 0; i < tag_count; ++i) {
547 output << label <<
"\n";
558 const std::string& csv_content) {
565 std::istringstream stream(csv_content);
568 int imported_count = 0;
570 while (std::getline(stream, line)) {
574 std::string trimmed = std::string(absl::StripAsciiWhitespace(line));
577 if (trimmed.empty() || line_number == 1) {
582 std::vector<std::string> fields = absl::StrSplit(trimmed,
',');
583 if (fields.size() < 2) {
587 std::string
name = std::string(absl::StripAsciiWhitespace(fields[0]));
588 std::string id_str = std::string(absl::StripAsciiWhitespace(fields[1]));
592 if (id_str.empty()) {
597 if (id_str[0] ==
'$') {
598 id_str = id_str.substr(1);
601 if (id_str.size() >= 2 && id_str[0] ==
'0' &&
602 (id_str[1] ==
'x' || id_str[1] ==
'X')) {
603 id_str = id_str.substr(2);
607 sprite_id = std::stoi(id_str,
nullptr, 16);
612 if (sprite_id < 0 || sprite_id > 255) {
617 (*project_labels_)[
"sprite"][std::to_string(sprite_id)] =
name;
621 if (imported_count == 0) {
622 return absl::InvalidArgumentError(
623 "No valid sprite entries found in registry CSV");
626 return absl::OkStatus();
631 if (
const auto label = LookupProjectReceiptLabel(
id, project_labels);
636 if (
id < names.size())
638 return absl::StrFormat(
"Unknown item %02X",
id);
643 if (!LookupProjectReceiptLabel(
id, project_labels).empty())
Loads and queries the hack manifest JSON for yaze-ASM integration.
const ProjectRegistry & project_registry() const
bool HasProjectRegistry() const
std::string GetRoomTagLabel(uint8_t tag_id) const
Get the human-readable label for a room tag ID.
bool loaded() const
Check if the manifest has been loaded.
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.
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_
ProjectLabels * project_labels_
std::string GetLabel(ResourceType type, int id) const
Get a label for a resource by type and ID.
bool ParseZScreamLine(const std::string &line, const std::string §ion, int &line_index)
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 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.
std::string LookupProjectRegistryRoomLabel(const core::HackManifest *manifest, int id)
std::string LookupProjectReceiptLabel(uint8_t id, const ResourceLabelProvider::ProjectLabels *project_labels)
std::string LookupProjectLabel(const ResourceLabelProvider::LabelMap &labels, int id)
Zelda 3 specific classes and functions.
ResourceType
Enumeration of all supported resource types for labeling.
const char * GetItemReceiptLabelSource(uint8_t id, const ResourceLabelProvider::ProjectLabels *project_labels)
const size_t kSpriteNameCount
const char *const kSpriteNames[]
std::string GetItemReceiptLabel(uint8_t id, const ResourceLabelProvider::ProjectLabels *project_labels)
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.
ResourceLabelProvider & GetResourceLabels()
Get the global ResourceLabelProvider instance.
std::vector< DungeonEntry > dungeons
static const std::vector< std::string > & GetRoomNames()
static const std::vector< std::string > & GetItemNames()
static const std::vector< std::string > & GetEntranceNames()
static const std::vector< std::string > & GetGraphicsSheetNames()
static const std::vector< std::string > & GetMusicTrackNames()
static const std::vector< std::string > & GetItemReceiptNames()
static const std::vector< std::string > & GetTileTypeNames()
static const std::vector< std::string > & GetOverlordNames()
static const std::vector< std::string > & GetSpriteNames()
static const std::vector< std::string > & GetOverworldMapNames()
static const std::vector< std::string > & GetRoomEffectNames()
static const std::vector< std::string > & GetRoomTagNames()