yaze
0.3.2
Link to the Past ROM Editor
Loading...
Searching...
No Matches
resource_commands.cc
Go to the documentation of this file.
1
#include "
cli/handlers/tools/resource_commands.h
"
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"
7
#include "
cli/service/resources/resource_context_builder.h
"
8
#include "
util/macro.h
"
9
10
namespace
yaze
{
11
namespace
cli {
12
namespace
handlers {
13
14
absl::Status
ResourceListCommandHandler::Execute
(
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
32
absl::Status
ResourceSearchCommandHandler::Execute
(
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
yaze::Rom
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
yaze::cli::ResourceContextBuilder
Builds contextual information from ROM resources for AI prompts.
Definition
resource_context_builder.h:26
yaze::cli::ResourceContextBuilder::GetLabels
absl::StatusOr< std::map< std::string, std::string > > GetLabels(const std::string &category)
Get labels for a specific resource category.
Definition
resource_context_builder.cc:202
yaze::cli::handlers::ResourceListCommandHandler::Execute
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
Definition
resource_commands.cc:14
yaze::cli::handlers::ResourceSearchCommandHandler::Execute
absl::Status Execute(Rom *rom, const resources::ArgumentParser &parser, resources::OutputFormatter &formatter) override
Execute the command business logic.
Definition
resource_commands.cc:32
yaze::cli::resources::ArgumentParser
Utility for parsing common CLI argument patterns.
Definition
command_context.h:78
yaze::cli::resources::ArgumentParser::GetString
std::optional< std::string > GetString(const std::string &name) const
Parse a named argument (e.g., –format=json or –format json)
Definition
command_context.cc:149
yaze::cli::resources::OutputFormatter
Utility for consistent output formatting across commands.
Definition
command_context.h:122
yaze::cli::resources::OutputFormatter::BeginArray
void BeginArray(const std::string &key)
Begin an array.
Definition
command_context.cc:350
yaze::cli::resources::OutputFormatter::AddArrayItem
void AddArrayItem(const std::string &item)
Add an item to current array.
Definition
command_context.cc:378
yaze::cli::resources::OutputFormatter::BeginObject
void BeginObject(const std::string &title="")
Start a JSON object or text section.
Definition
command_context.cc:261
yaze::cli::resources::OutputFormatter::EndObject
void EndObject()
End a JSON object or text section.
Definition
command_context.cc:271
yaze::cli::resources::OutputFormatter::EndArray
void EndArray()
End an array.
Definition
command_context.cc:367
yaze::cli::resources::OutputFormatter::AddField
void AddField(const std::string &key, const std::string &value)
Add a key-value pair.
Definition
command_context.cc:280
macro.h
ASSIGN_OR_RETURN
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition
macro.h:62
yaze::zelda3::category
category
Definition
object_templates.cc:18
yaze
Definition
application.cc:18
resource_commands.h
resource_context_builder.h
src
cli
handlers
tools
resource_commands.cc
Generated by
1.10.0