yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
resource_commands.cc
Go to the documentation of this file.
2
3#include "absl/strings/ascii.h"
4#include "absl/strings/match.h"
5#include "absl/strings/str_format.h"
6#include "absl/strings/str_split.h"
8#include "util/macro.h"
9
10namespace yaze {
11namespace cli {
12namespace handlers {
13
15 resources::OutputFormatter& formatter) {
16 auto type = parser.GetString("type").value();
17
18 ResourceContextBuilder builder(rom);
19 ASSIGN_OR_RETURN(auto labels, builder.GetLabels(type));
20
21 formatter.BeginObject(absl::StrFormat("%s Labels", absl::AsciiStrToUpper(type)));
22 for (const auto& [key, value] : labels) {
23 formatter.AddField(key, value);
24 }
25 formatter.EndObject();
26
27 return absl::OkStatus();
28}
29
31 resources::OutputFormatter& formatter) {
32 auto query = parser.GetString("query").value();
33 auto type = parser.GetString("type").value_or("all");
34
35 ResourceContextBuilder builder(rom);
36
37 std::vector<std::string> categories = {"overworld", "dungeon", "entrance",
38 "room", "sprite", "palette", "item"};
39 if (type != "all") {
40 categories = {type};
41 }
42
43 formatter.BeginObject("Resource Search Results");
44 formatter.AddField("query", query);
45 formatter.AddField("search_type", type);
46
47 int total_matches = 0;
48 formatter.BeginArray("matches");
49
50 for (const auto& category : categories) {
51 auto labels_or = builder.GetLabels(category);
52 if (!labels_or.ok()) continue;
53
54 auto labels = labels_or.value();
55 for (const auto& [key, value] : labels) {
56 if (absl::StrContains(absl::AsciiStrToLower(value),
57 absl::AsciiStrToLower(query))) {
58 formatter.AddArrayItem(absl::StrFormat("%s:%s = %s",
59 category, key, value));
60 total_matches++;
61 }
62 }
63 }
64
65 formatter.EndArray();
66 formatter.AddField("total_matches", total_matches);
67 formatter.EndObject();
68
69 return absl::OkStatus();
70}
71
72} // namespace handlers
73} // namespace cli
74} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Builds contextual information from ROM resources for AI prompts.
absl::StatusOr< std::map< std::string, std::string > > GetLabels(const std::string &category)
Get labels for a specific resource category.
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
Utility for parsing common CLI argument patterns.
std::optional< std::string > GetString(const std::string &name) const
Parse a named argument (e.g., –format=json or –format json)
Utility for consistent output formatting across commands.
void BeginArray(const std::string &key)
Begin an array.
void AddArrayItem(const std::string &item)
Add an item to current array.
void BeginObject(const std::string &title="")
Start a JSON object or text section.
void EndObject()
End a JSON object or text section.
void AddField(const std::string &key, const std::string &value)
Add a key-value pair.
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:61
Main namespace for the application.