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()) {
131 for (
const auto& room : dungeon.rooms) {
132 if (room.id ==
id && !room.name.empty()) {
163 if (std::string registry_label =
165 !registry_label.empty()) {
166 return registry_label;
176 if (std::string project_label = LookupProjectLabel(type_it->second,
id);
177 !project_label.empty()) {
178 return project_label;
187 if (!manifest_label.empty()) {
188 return manifest_label;
197 if (!hmagic.empty()) {
213 const std::string& label) {
218 (*project_labels_)[type_str][std::to_string(
id)] = label;
228 type_it->second.erase(std::to_string(
id));
241 return !LookupProjectLabel(type_it->second,
id).empty();
249 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
252 return absl::StrFormat(
"Sprite %02X",
id);
256 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
259 return absl::StrFormat(
"Room %03X",
id);
263 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
266 return absl::StrFormat(
"Entrance %02X",
id);
270 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
273 return absl::StrFormat(
"Item %02X",
id);
277 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
280 return absl::StrFormat(
"Overlord %02X",
id);
284 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
287 return absl::StrFormat(
"Map %02X",
id);
291 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
294 return absl::StrFormat(
"Music %02X",
id);
298 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
301 return absl::StrFormat(
"GFX %02X",
id);
305 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
308 return absl::StrFormat(
"Effect %02X",
id);
312 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
315 return absl::StrFormat(
"Tag %02X",
id);
319 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
322 return absl::StrFormat(
"Tile %02X",
id);
325 return absl::StrFormat(
"Unknown %02X",
id);
394 const std::string& content) {
396 return absl::FailedPreconditionError(
397 "Project labels not initialized. Open a project first.");
400 std::istringstream stream(content);
402 std::string current_section;
406 while (std::getline(stream, line)) {
410 std::string trimmed = std::string(absl::StripAsciiWhitespace(line));
413 if (trimmed.empty() || trimmed.substr(0, 2) ==
"//") {
418 if (trimmed.front() ==
'[' && trimmed.back() ==
']') {
419 current_section = trimmed.substr(1, trimmed.length() - 2);
425 if (!current_section.empty()) {
430 return absl::OkStatus();
434 const std::string& section,
441 std::string resource_type;
442 bool has_hex_prefix =
false;
444 if (section ==
"Sprites Names") {
445 resource_type =
"sprite";
446 has_hex_prefix =
true;
447 }
else if (section ==
"Rooms Names") {
448 resource_type =
"room";
449 has_hex_prefix =
false;
450 }
else if (section ==
"Chests Items") {
451 resource_type =
"item";
452 has_hex_prefix =
true;
453 }
else if (section ==
"Tags Names") {
454 resource_type =
"room_tag";
455 has_hex_prefix =
false;
464 if (has_hex_prefix) {
466 size_t space_pos = line.find(
' ');
467 if (space_pos == std::string::npos || space_pos < 2) {
472 std::string hex_str = line.substr(0, space_pos);
473 label = line.substr(space_pos + 1);
477 int id = std::stoi(hex_str,
nullptr, 16);
478 id_str = std::to_string(
id);
484 id_str = std::to_string(line_index);
490 label = std::string(absl::StripAsciiWhitespace(label));
493 if (!label.empty()) {
494 (*project_labels_)[resource_type][id_str] = label;
501 std::ostringstream output;
503 output <<
"//Do not use brackets [] in naming\n";
506 output <<
"[Sprites Names]\n";
507 for (
int i = 0; i < 256; ++i) {
509 output << absl::StrFormat(
"%02X %s\n", i, label);
513 output <<
"\n[Rooms Names]\n";
514 for (
int i = 0; i < 297; ++i) {
516 output << label <<
"\n";
520 output <<
"\n[Chests Items]\n";
522 for (
int i = 0; i < item_count; ++i) {
524 output << absl::StrFormat(
"%02X %s\n", i, label);
528 output <<
"\n[Tags Names]\n";
530 for (
int i = 0; i < tag_count; ++i) {
532 output << label <<
"\n";
543 const std::string& csv_content) {
550 std::istringstream stream(csv_content);
553 int imported_count = 0;
555 while (std::getline(stream, line)) {
559 std::string trimmed = std::string(absl::StripAsciiWhitespace(line));
562 if (trimmed.empty() || line_number == 1) {
567 std::vector<std::string> fields = absl::StrSplit(trimmed,
',');
568 if (fields.size() < 2) {
572 std::string
name = std::string(absl::StripAsciiWhitespace(fields[0]));
573 std::string id_str = std::string(absl::StripAsciiWhitespace(fields[1]));
577 if (id_str.empty()) {
582 if (id_str[0] ==
'$') {
583 id_str = id_str.substr(1);
586 if (id_str.size() >= 2 && id_str[0] ==
'0' &&
587 (id_str[1] ==
'x' || id_str[1] ==
'X')) {
588 id_str = id_str.substr(2);
592 sprite_id = std::stoi(id_str,
nullptr, 16);
597 if (sprite_id < 0 || sprite_id > 255) {
602 (*project_labels_)[
"sprite"][std::to_string(sprite_id)] =
name;
606 if (imported_count == 0) {
607 return absl::InvalidArgumentError(
608 "No valid sprite entries found in registry CSV");
611 return absl::OkStatus();
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 LookupProjectLabel(const ResourceLabelProvider::LabelMap &labels, int id)
Zelda 3 specific classes and functions.
ResourceType
Enumeration of all supported resource types for labeling.
const size_t kSpriteNameCount
const char *const kSpriteNames[]
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 > & 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()