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 "absl/status/status.h"
5#include "absl/status/statusor.h"
6#include "imgui/imgui.h"
12
13namespace yaze {
14namespace editor {
15
44absl::StatusOr<zelda3::OverworldEntrance*> InsertEntrance(
45 zelda3::Overworld* overworld, ImVec2 mouse_pos, int current_map,
46 bool is_hole = false);
47
62absl::StatusOr<zelda3::OverworldExit*> InsertExit(zelda3::Overworld* overworld,
63 ImVec2 mouse_pos,
64 int current_map);
65
81absl::StatusOr<zelda3::Sprite*> InsertSprite(zelda3::Overworld* overworld,
82 ImVec2 mouse_pos, int current_map,
83 int game_state,
84 uint8_t sprite_id = 0);
85
100absl::StatusOr<zelda3::OverworldItem*> InsertItem(zelda3::Overworld* overworld,
101 ImVec2 mouse_pos,
102 int current_map,
103 uint8_t item_id = 0);
104
115absl::Status RemoveItem(zelda3::Overworld* overworld,
116 const zelda3::OverworldItem* item_ptr);
117
128absl::Status RemoveItemByIdentity(zelda3::Overworld* overworld,
129 const zelda3::OverworldItem& item_identity);
130
138zelda3::OverworldItem* FindItemByIdentity(
139 zelda3::Overworld* overworld, const zelda3::OverworldItem& item_identity);
140
150absl::StatusOr<zelda3::OverworldItem*> DuplicateItemByIdentity(
151 zelda3::Overworld* overworld, const zelda3::OverworldItem& item_identity,
152 int offset_x = 16, int offset_y = 0);
153
162absl::Status NudgeItem(zelda3::OverworldItem* item, int delta_x, int delta_y);
163
176zelda3::OverworldItem* FindNearestItemForSelection(
177 zelda3::Overworld* overworld, const zelda3::OverworldItem& anchor_identity);
178
185inline uint8_t GetParentMapId(const zelda3::OverworldMap* map,
186 int current_map) {
187 uint8_t parent = map->parent();
188 return (parent == 0xFF) ? static_cast<uint8_t>(current_map) : parent;
189}
190
194inline ImVec2 SnapToEntityGrid(ImVec2 pos) {
195 return ImVec2(static_cast<float>(static_cast<int>(pos.x / 16) * 16),
196 static_cast<float>(static_cast<int>(pos.y / 16) * 16));
197}
198
202inline ImVec2 ClampToOverworldBounds(ImVec2 pos) {
203 return ImVec2(std::clamp(pos.x, 0.0f, 4080.0f), // 4096 - 16
204 std::clamp(pos.y, 0.0f, 4080.0f));
205}
206
207} // namespace editor
208} // namespace yaze
209
210#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::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.