9#include "absl/strings/str_format.h"
10#include "absl/strings/str_split.h"
11#include "absl/strings/strip.h"
41 return "overworld_map";
57 if (type_str ==
"sprite")
59 if (type_str ==
"room")
61 if (type_str ==
"entrance")
63 if (type_str ==
"item")
65 if (type_str ==
"overlord")
67 if (type_str ==
"overworld_map")
69 if (type_str ==
"music")
71 if (type_str ==
"graphics")
73 if (type_str ==
"room_effect")
75 if (type_str ==
"room_tag")
77 if (type_str ==
"tile_type")
103 auto label_it = type_it->second.find(std::to_string(
id));
104 if (label_it != type_it->second.end() && !label_it->second.empty()) {
105 return label_it->second;
113 if (!hmagic.empty()) {
129 const std::string& label) {
134 (*project_labels_)[type_str][std::to_string(
id)] = label;
144 type_it->second.erase(std::to_string(
id));
157 return type_it->second.find(std::to_string(
id)) != type_it->second.end();
165 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
168 return absl::StrFormat(
"Sprite %02X",
id);
172 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
175 return absl::StrFormat(
"Room %03X",
id);
179 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
182 return absl::StrFormat(
"Entrance %02X",
id);
186 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
189 return absl::StrFormat(
"Item %02X",
id);
193 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
196 return absl::StrFormat(
"Overlord %02X",
id);
200 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
203 return absl::StrFormat(
"Map %02X",
id);
207 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
210 return absl::StrFormat(
"Music %02X",
id);
214 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
217 return absl::StrFormat(
"GFX %02X",
id);
221 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
224 return absl::StrFormat(
"Effect %02X",
id);
228 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
231 return absl::StrFormat(
"Tag %02X",
id);
235 if (
id >= 0 &&
static_cast<size_t>(
id) < names.size()) {
238 return absl::StrFormat(
"Tile %02X",
id);
241 return absl::StrFormat(
"Unknown %02X",
id);
310 const std::string& content) {
312 return absl::FailedPreconditionError(
313 "Project labels not initialized. Open a project first.");
316 std::istringstream stream(content);
318 std::string current_section;
322 while (std::getline(stream, line)) {
326 std::string trimmed = std::string(absl::StripAsciiWhitespace(line));
329 if (trimmed.empty() || trimmed.substr(0, 2) ==
"//") {
334 if (trimmed.front() ==
'[' && trimmed.back() ==
']') {
335 current_section = trimmed.substr(1, trimmed.length() - 2);
341 if (!current_section.empty()) {
346 return absl::OkStatus();
350 const std::string& section,
357 std::string resource_type;
358 bool has_hex_prefix =
false;
360 if (section ==
"Sprites Names") {
361 resource_type =
"sprite";
362 has_hex_prefix =
true;
363 }
else if (section ==
"Rooms Names") {
364 resource_type =
"room";
365 has_hex_prefix =
false;
366 }
else if (section ==
"Chests Items") {
367 resource_type =
"item";
368 has_hex_prefix =
true;
369 }
else if (section ==
"Tags Names") {
370 resource_type =
"room_tag";
371 has_hex_prefix =
false;
380 if (has_hex_prefix) {
382 size_t space_pos = line.find(
' ');
383 if (space_pos == std::string::npos || space_pos < 2) {
388 std::string hex_str = line.substr(0, space_pos);
389 label = line.substr(space_pos + 1);
393 int id = std::stoi(hex_str,
nullptr, 16);
394 id_str = std::to_string(
id);
400 id_str = std::to_string(line_index);
406 label = std::string(absl::StripAsciiWhitespace(label));
409 if (!label.empty()) {
410 (*project_labels_)[resource_type][id_str] = label;
417 std::ostringstream output;
419 output <<
"//Do not use brackets [] in naming\n";
422 output <<
"[Sprites Names]\n";
423 for (
int i = 0; i < 256; ++i) {
425 output << absl::StrFormat(
"%02X %s\n", i, label);
429 output <<
"\n[Rooms Names]\n";
430 for (
int i = 0; i < 297; ++i) {
432 output << label <<
"\n";
436 output <<
"\n[Chests Items]\n";
438 for (
int i = 0; i < item_count; ++i) {
440 output << absl::StrFormat(
"%02X %s\n", i, label);
444 output <<
"\n[Tags Names]\n";
446 for (
int i = 0; i < tag_count; ++i) {
448 output << label <<
"\n";
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
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)
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)
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.
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()