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
46absl::StatusOr<zelda3::OverworldEntrance*> InsertEntrance(
47 zelda3::Overworld* overworld, ImVec2 mouse_pos, int current_map,
48 bool is_hole = false);
49
64absl::StatusOr<zelda3::OverworldExit*> InsertExit(zelda3::Overworld* overworld,
65 ImVec2 mouse_pos,
66 int current_map);
67
83absl::StatusOr<zelda3::Sprite*> InsertSprite(zelda3::Overworld* overworld,
84 ImVec2 mouse_pos, int current_map,
85 int game_state,
86 uint8_t sprite_id = 0);
87
102absl::StatusOr<zelda3::OverworldItem*> InsertItem(zelda3::Overworld* overworld,
103 ImVec2 mouse_pos,
104 int current_map,
105 uint8_t item_id = 0);
106
107// Construct insertion values from the authored map domain without mutating it.
108// current_map identifies the physical 512-pixel screen under world_position;
109// the resulting entity belongs to that screen's parent and uses parent-relative
110// game coordinates. InsertItem/InsertSprite additionally require a loaded model.
111absl::StatusOr<zelda3::OverworldItem> BuildOverworldItemForInsertion(
112 const std::vector<zelda3::OverworldMap>& maps, ImVec2 world_position,
113 int current_map, uint8_t item_id);
114absl::StatusOr<zelda3::Sprite> BuildOverworldSpriteForInsertion(
115 const std::vector<zelda3::OverworldMap>& maps, ImVec2 world_position,
116 int current_map, uint8_t sprite_id);
117
128absl::Status RemoveItem(zelda3::Overworld* overworld,
129 const zelda3::OverworldItem* item_ptr);
130
141absl::Status RemoveItemByIdentity(zelda3::Overworld* overworld,
142 const zelda3::OverworldItem& item_identity);
143
151zelda3::OverworldItem* FindItemByIdentity(
152 zelda3::Overworld* overworld, const zelda3::OverworldItem& item_identity);
153
163absl::StatusOr<zelda3::OverworldItem*> DuplicateItemByIdentity(
164 zelda3::Overworld* overworld, const zelda3::OverworldItem& item_identity,
165 int offset_x = 16, int offset_y = 0);
166
175absl::Status NudgeItem(zelda3::OverworldItem* item, int delta_x, int delta_y);
176
189zelda3::OverworldItem* FindNearestItemForSelection(
190 zelda3::Overworld* overworld, const zelda3::OverworldItem& anchor_identity);
191
198inline uint8_t GetParentMapId(const zelda3::OverworldMap* map,
199 int current_map) {
200 uint8_t parent = map->parent();
201 return (parent == 0xFF) ? static_cast<uint8_t>(current_map) : parent;
202}
203
207inline ImVec2 SnapToEntityGrid(ImVec2 pos) {
208 return ImVec2(static_cast<float>(static_cast<int>(pos.x / 16) * 16),
209 static_cast<float>(static_cast<int>(pos.y / 16) * 16));
210}
211
215inline ImVec2 ClampToOverworldBounds(ImVec2 pos) {
216 return ImVec2(std::clamp(pos.x, 0.0f, 4080.0f), // 4096 - 16
217 std::clamp(pos.y, 0.0f, 4080.0f));
218}
219
220} // namespace editor
221} // namespace yaze
222
223#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::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.
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)