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 Rom* rom, const resources::ArgumentParser& parser,
16 resources::OutputFormatter& formatter) {
17 auto type = parser.GetString("type").value();
18
19 ResourceContextBuilder builder(rom);
20 ASSIGN_OR_RETURN(auto labels, builder.GetLabels(type));
21
22 formatter.BeginObject(
23 absl::StrFormat("%s Labels", absl::AsciiStrToUpper(type)));
24 for (const auto& [key, value] : labels) {
25 formatter.AddField(key, value);
26 }
27 formatter.EndObject();
28
29 return absl::OkStatus();
30}
31
33 Rom* rom, const resources::ArgumentParser& parser,
34 resources::OutputFormatter& formatter) {
35 auto query = parser.GetString("query").value();
36 auto type = parser.GetString("type").value_or("all");
37
38 ResourceContextBuilder builder(rom);
39
40 std::vector<std::string> categories = {
41 "overworld", "dungeon", "entrance", "room", "sprite", "palette", "item"};
42 if (type != "all") {
43 categories = {type};
44 }
45
46 formatter.BeginObject("Resource Search Results");
47 formatter.AddField("query", query);
48 formatter.AddField("search_type", type);
49
50 int total_matches = 0;
51 formatter.BeginArray("matches");
52
53 for (const auto& category : categories) {
54 auto labels_or = builder.GetLabels(category);
55 if (!labels_or.ok())
56 continue;
57
58 auto labels = labels_or.value();
59 for (const auto& [key, value] : labels) {
60 if (absl::StrContains(absl::AsciiStrToLower(value),
61 absl::AsciiStrToLower(query))) {
62 formatter.AddArrayItem(
63 absl::StrFormat("%s:%s = %s", category, key, value));
64 total_matches++;
65 }
66 }
67 }
68
69 formatter.EndArray();
70 formatter.AddField("total_matches", total_matches);
71 formatter.EndObject();
72
73 return absl::OkStatus();
74}
75
76} // namespace handlers
77} // namespace cli
78} // namespace yaze
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
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:62