yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
entity_operations.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_OVERWORLD_ENTITY_OPERATIONS_H
2#define YAZE_APP_EDITOR_OVERWORLD_ENTITY_OPERATIONS_H
3
4#include <vector>
5
6#include "absl/status/status.h"
7#include "absl/status/statusor.h"
8#include "imgui/imgui.h"
14
15namespace yaze {
16namespace editor {
17
18// Build an existing table row's complete serialized value before mutating it.
19// The row is explicit: entrance IDs and return rooms are not unique identities.
20// Maps must already be present in the owning model; this does not admit or
21// allocate a project terrain map, entrance slot, or return row.
22absl::StatusOr<zelda3::OverworldEntrance> BuildOverworldEntranceEdit(
23 const zelda3::Overworld& overworld,
24 const std::vector<zelda3::OverworldEntrance>& records, size_t row,
25 const zelda3::OverworldEntrance& draft, bool legacy_hole_table = false);
26absl::StatusOr<zelda3::OverworldExit> BuildOverworldExitEdit(
27 const zelda3::Overworld& overworld,
28 const std::vector<zelda3::OverworldExit>& records, size_t row,
29 const zelda3::OverworldExit& draft);
30
59absl::StatusOr<zelda3::OverworldEntrance*> InsertEntrance(
60 zelda3::Overworld* overworld, ImVec2 mouse_pos, int current_map,
61 bool is_hole = false);
62
77absl::StatusOr<zelda3::OverworldExit*> InsertExit(zelda3::Overworld* overworld,
78 ImVec2 mouse_pos,
79 int current_map);
80
96absl::StatusOr<zelda3::Sprite*> InsertSprite(zelda3::Overworld* overworld,
97 ImVec2 mouse_pos, int current_map,
98 int game_state,
99 uint8_t sprite_id = 0);
100
115absl::StatusOr<zelda3::OverworldItem*> InsertItem(zelda3::Overworld* overworld,
116 ImVec2 mouse_pos,
117 int current_map,
118 uint8_t item_id = 0);
119
120// Construct insertion values from the authored map domain without mutating it.
121// current_map identifies the physical 512-pixel screen under world_position;
122// the resulting entity belongs to that screen's parent and uses parent-relative
123// game coordinates. InsertItem/InsertSprite additionally require a loaded model.
124absl::StatusOr<zelda3::OverworldItem> BuildOverworldItemForInsertion(
125 const std::vector<zelda3::OverworldMap>& maps, ImVec2 world_position,
126 int current_map, uint8_t item_id);
127absl::StatusOr<zelda3::Sprite> BuildOverworldSpriteForInsertion(
128 const std::vector<zelda3::OverworldMap>& maps, ImVec2 world_position,
129 int current_map, uint8_t sprite_id);
130
141absl::Status RemoveItem(zelda3::Overworld* overworld,
142 const zelda3::OverworldItem* item_ptr);
143
154absl::Status RemoveItemByIdentity(zelda3::Overworld* overworld,
155 const zelda3::OverworldItem& item_identity);
156
164zelda3::OverworldItem* FindItemByIdentity(
165 zelda3::Overworld* overworld, const zelda3::OverworldItem& item_identity);
166
176absl::StatusOr<zelda3::OverworldItem*> DuplicateItemByIdentity(
177 zelda3::Overworld* overworld, const zelda3::OverworldItem& item_identity,
178 int offset_x = 16, int offset_y = 0);
179
188absl::Status NudgeItem(zelda3::OverworldItem* item, int delta_x, int delta_y);
189
202zelda3::OverworldItem* FindNearestItemForSelection(
203 zelda3::Overworld* overworld, const zelda3::OverworldItem& anchor_identity);
204
211inline uint8_t GetParentMapId(const zelda3::OverworldMap* map,
212 int current_map) {
213 if (!map) {
214 return static_cast<uint8_t>(current_map);
215 }
216 uint8_t parent = map->parent();
217 return (parent == 0xFF) ? static_cast<uint8_t>(current_map) : parent;
218}
219
223inline ImVec2 SnapToEntityGrid(ImVec2 pos) {
224 return ImVec2(static_cast<float>(static_cast<int>(pos.x / 16) * 16),
225 static_cast<float>(static_cast<int>(pos.y / 16) * 16));
226}
227
231inline ImVec2 ClampToOverworldBounds(ImVec2 pos) {
232 return ImVec2(std::clamp(pos.x, 0.0f, 4080.0f), // 4096 - 16
233 std::clamp(pos.y, 0.0f, 4080.0f));
234}
235
236} // namespace editor
237} // namespace yaze
238
239#endif // YAZE_APP_EDITOR_OVERWORLD_ENTITY_OPERATIONS_H
Represents a single Overworld map screen.
absl::StatusOr< zelda3::OverworldItem * > InsertItem(zelda3::Overworld *overworld, ImVec2 mouse_pos, int current_map, uint8_t item_id)
Insert a new item at the specified position.
absl::StatusOr< zelda3::OverworldExit > BuildOverworldExitEdit(const zelda3::Overworld &overworld, const std::vector< zelda3::OverworldExit > &records, size_t row, const zelda3::OverworldExit &draft)
absl::Status RemoveItemByIdentity(zelda3::Overworld *overworld, const zelda3::OverworldItem &item_identity)
Remove an item by value identity instead of pointer identity.
absl::StatusOr< zelda3::OverworldEntrance * > InsertEntrance(zelda3::Overworld *overworld, ImVec2 mouse_pos, int current_map, bool is_hole)
Flat helper functions for entity insertion/manipulation.
absl::Status NudgeItem(zelda3::OverworldItem *item, int delta_x, int delta_y)
Move an item by pixel deltas with overworld bounds clamping.
zelda3::OverworldItem * FindNearestItemForSelection(zelda3::Overworld *overworld, const zelda3::OverworldItem &anchor_identity)
Find the best next item to keep selection continuity after deletion.
absl::Status RemoveItem(zelda3::Overworld *overworld, const zelda3::OverworldItem *item_ptr)
Remove an item from the overworld item list by pointer identity.
zelda3::OverworldItem * FindItemByIdentity(zelda3::Overworld *overworld, const zelda3::OverworldItem &item_identity)
Find a live item by value identity.
absl::StatusOr< zelda3::OverworldItem > BuildOverworldItemForInsertion(const std::vector< zelda3::OverworldMap > &maps, ImVec2 world_position, int current_map, uint8_t item_id)
absl::StatusOr< zelda3::OverworldExit * > InsertExit(zelda3::Overworld *overworld, ImVec2 mouse_pos, int current_map)
Insert a new exit at the specified position.
absl::StatusOr< zelda3::OverworldEntrance > BuildOverworldEntranceEdit(const zelda3::Overworld &overworld, const std::vector< zelda3::OverworldEntrance > &records, size_t row, const zelda3::OverworldEntrance &draft, bool legacy_hole_table)
ImVec2 SnapToEntityGrid(ImVec2 pos)
Snap position to 16x16 grid (standard entity positioning)
absl::StatusOr< zelda3::OverworldItem * > DuplicateItemByIdentity(zelda3::Overworld *overworld, const zelda3::OverworldItem &item_identity, int offset_x, int offset_y)
Duplicate an existing item by identity with a positional offset.
absl::StatusOr< zelda3::Sprite * > InsertSprite(zelda3::Overworld *overworld, ImVec2 mouse_pos, int current_map, int game_state, uint8_t sprite_id)
Insert a new sprite at the specified position.
ImVec2 ClampToOverworldBounds(ImVec2 pos)
Clamp position to valid overworld bounds.
uint8_t GetParentMapId(const zelda3::OverworldMap *map, int current_map)
Helper to get parent map ID for multi-area maps.
absl::StatusOr< zelda3::Sprite > BuildOverworldSpriteForInsertion(const std::vector< zelda3::OverworldMap > &maps, ImVec2 world_position, int current_map, uint8_t sprite_id)