yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
message_id_resolver.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_MESSAGE_MESSAGE_ID_RESOLVER_H_
2#define YAZE_APP_EDITOR_MESSAGE_MESSAGE_ID_RESOLVER_H_
3
4#include <optional>
5
6namespace yaze::editor {
7
9 bool is_expanded = false;
10 int index = -1; // Vanilla: absolute message ID. Expanded: index into expanded list.
11 int display_id = -1; // UI-facing ID (vanilla or expanded_base + index).
12};
13
14// Resolve a UI-facing message ID into either a vanilla or expanded index.
15//
16// Returns std::nullopt if:
17// - display_id is negative
18// - display_id is in the "gap" between vanilla_count and expanded_base_id
19// - display_id is outside the expanded range
20inline std::optional<ResolvedMessageId> ResolveMessageDisplayId(
21 int display_id, int vanilla_count, int expanded_base_id,
22 int expanded_count) {
23 if (display_id < 0) {
24 return std::nullopt;
25 }
26
27 if (vanilla_count > 0 && display_id < vanilla_count) {
28 return ResolvedMessageId{.is_expanded = false,
29 .index = display_id,
30 .display_id = display_id};
31 }
32
33 if (expanded_count > 0 && display_id >= expanded_base_id) {
34 const int idx = display_id - expanded_base_id;
35 if (idx >= 0 && idx < expanded_count) {
36 return ResolvedMessageId{.is_expanded = true,
37 .index = idx,
38 .display_id = display_id};
39 }
40 }
41
42 return std::nullopt;
43}
44
45} // namespace yaze::editor
46
47#endif // YAZE_APP_EDITOR_MESSAGE_MESSAGE_ID_RESOLVER_H_
Editors are the view controllers for the application.
std::optional< ResolvedMessageId > ResolveMessageDisplayId(int display_id, int vanilla_count, int expanded_base_id, int expanded_count)