yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_selection_snapshot.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_DUNGEON_SELECTION_SNAPSHOT_H_
2#define YAZE_APP_EDITOR_DUNGEON_DUNGEON_SELECTION_SNAPSHOT_H_
3
4#include <cstddef>
5#include <cstdint>
6#include <optional>
7#include <string>
8#include <vector>
9
11
12namespace yaze::editor {
13
14enum class DungeonSelectionKind : uint8_t {
15 None = 0,
18 Door,
19 Sprite,
20 Item,
22 Mixed,
23};
24
49
50inline void AppendDungeonSelectionSummaryPart(std::vector<std::string>* parts,
51 size_t count,
52 const char* singular,
53 const char* plural = nullptr) {
54 if (count == 0 || parts == nullptr) {
55 return;
56 }
57 parts->push_back(std::to_string(count) + " " +
58 (count == 1 || plural == nullptr ? singular : plural));
59}
60
62 const DungeonObjectInteraction& interaction, const DungeonRoomStore* rooms,
63 int room_id) {
65
66 const auto selected_objects = interaction.GetSelectedObjectIndices();
67 snapshot.object_count = selected_objects.size();
68 if (!selected_objects.empty()) {
69 snapshot.primary_object_index = selected_objects.front();
70
71 if (rooms != nullptr && room_id >= 0 &&
72 room_id < static_cast<int>(rooms->size())) {
73 const auto& objects = (*rooms)[room_id].GetTileObjects();
74 if (selected_objects.front() < objects.size()) {
75 snapshot.selection_layer = objects[selected_objects.front()].layer_;
76 }
77 }
78 }
79
80 auto selected_entities =
82 if (selected_entities.empty() && interaction.HasEntitySelection()) {
83 const SelectedEntity selected = interaction.GetSelectedEntity();
84 if (selected.type != EntityType::None) {
85 selected_entities.push_back(selected);
86 }
87 }
88
89 for (SelectedEntity selected : selected_entities) {
90 if (snapshot.entity.type == EntityType::None &&
91 selected.type != EntityType::None) {
92 snapshot.entity = selected;
93 }
94 switch (selected.type) {
96 ++snapshot.door_count;
97 break;
99 ++snapshot.sprite_count;
100 break;
101 case EntityType::Item:
102 ++snapshot.item_count;
103 break;
105 case EntityType::None:
106 default:
107 break;
108 }
109 }
110
111 const size_t entity_count =
112 snapshot.door_count + snapshot.sprite_count + snapshot.item_count;
113 snapshot.count = snapshot.object_count + entity_count;
114 if (snapshot.count == 0) {
115 return snapshot;
116 }
117 if (snapshot.object_count > 0 && entity_count > 0) {
119 return snapshot;
120 }
121 if (snapshot.object_count > 0) {
122 snapshot.kind = snapshot.object_count == 1
125 return snapshot;
126 }
127 if (entity_count > 1) {
129 return snapshot;
130 }
131
132 switch (snapshot.entity.type) {
133 case EntityType::Door:
135 break;
138 break;
139 case EntityType::Item:
141 break;
143 case EntityType::None:
144 default:
145 break;
146 }
147
148 return snapshot;
149}
150
152 const DungeonSelectionSnapshot& snapshot) {
153 switch (snapshot.kind) {
155 if (snapshot.selection_layer >= 0) {
156 return "1 obj, L" + std::to_string(snapshot.selection_layer + 1);
157 }
158 return "1 obj";
160 return std::to_string(snapshot.count) + " obj";
162 return "Door";
164 return "Sprite";
166 return "Item";
169 std::vector<std::string> parts;
170 AppendDungeonSelectionSummaryPart(&parts, snapshot.object_count, "obj",
171 "obj");
172 AppendDungeonSelectionSummaryPart(&parts, snapshot.door_count, "door",
173 "doors");
174 AppendDungeonSelectionSummaryPart(&parts, snapshot.sprite_count, "sprite",
175 "sprites");
176 AppendDungeonSelectionSummaryPart(&parts, snapshot.item_count, "item",
177 "items");
178 std::string summary = std::to_string(snapshot.count) + " selected";
179 if (!parts.empty()) {
180 summary += ": ";
181 for (size_t i = 0; i < parts.size(); ++i) {
182 if (i > 0) {
183 summary += ", ";
184 }
185 summary += parts[i];
186 }
187 }
188 return summary;
189 }
191 default:
192 return "No selection";
193 }
194}
195
197 switch (kind) {
199 return "object";
201 return "objects";
203 return "door";
205 return "sprite";
207 return "item";
209 return "entities";
211 return "selection";
213 default:
214 return "selection";
215 }
216}
217
218} // namespace yaze::editor
219
220#endif // YAZE_APP_EDITOR_DUNGEON_DUNGEON_SELECTION_SNAPSHOT_H_
Handles object selection, placement, and interaction within the dungeon canvas.
std::vector< size_t > GetSelectedObjectIndices() const
InteractionCoordinator & entity_coordinator()
Get the interaction coordinator for entity handling.
const std::vector< SelectedEntity > & GetSelectedEntities() const
Editors are the view controllers for the application.
DungeonSelectionSnapshot BuildDungeonSelectionSnapshot(const DungeonObjectInteraction &interaction, const DungeonRoomStore *rooms, int room_id)
const char * GetDungeonSelectionKindLabel(DungeonSelectionKind kind)
std::string GetDungeonSelectionSummaryText(const DungeonSelectionSnapshot &snapshot)
void AppendDungeonSelectionSummaryPart(std::vector< std::string > *parts, size_t count, const char *singular, const char *plural=nullptr)
Represents a selected entity in the dungeon editor.