yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
interaction_context.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_INTERACTION_INTERACTION_CONTEXT_H_
2#define YAZE_APP_EDITOR_DUNGEON_INTERACTION_INTERACTION_CONTEXT_H_
3
4#include <array>
5#include <cstdint>
6#include <functional>
7#include <optional>
8
13#include "rom/rom.h"
14#include "zelda3/dungeon/room.h"
15
16namespace yaze {
17namespace editor {
18
19class ObjectSelection;
20
24enum class EntityType {
25 None,
26 Object, // Room tile objects
27 Door, // Door entities
28 Sprite, // Enemy/NPC sprites
29 Item // Pot items
30};
31
39enum class MutationDomain : uint8_t {
40 kUnknown = 0,
42 kDoors,
44 kItems,
47};
48
54 size_t index = 0; // Index into the respective container
55
56 bool operator==(const SelectedEntity& other) const {
57 return type == other.type && index == other.index;
58 }
59};
60
78 // Core dependencies (required)
79 gui::Canvas* canvas = nullptr;
80 Rom* rom = nullptr;
84
85 // Palette for rendering previews
87
88 // Unified callbacks
89 // Called before any state modification (for undo snapshots)
90 std::function<void()> on_mutation;
91
92 // Called after rendering changes require cache refresh
93 std::function<void()> on_invalidate_cache;
94
95 // Called when selection state changes
96 std::function<void()> on_selection_changed;
97
98 // Called when entity (door/sprite/item) changes
99 std::function<void()> on_entity_changed;
100
101 // Called when an interactive door-pair badge requests navigation to the
102 // adjacent room. The optional door index is in the target room.
103 std::function<void(int target_room_id,
104 std::optional<size_t> target_door_index, int target_tile_x,
105 int target_tile_y)>
107
108 // Last mutation/invalidation domain (best-effort). Set by Notify* helpers so
109 // the editor can route undo capture and expensive rerenders appropriately.
112
116 bool IsValid() const { return canvas != nullptr && rooms != nullptr; }
117
124 return nullptr;
125 }
126 return &(*rooms)[current_room_id];
127 }
128
135 return nullptr;
136 }
137 return &(*rooms)[current_room_id];
138 }
139
147 last_mutation_domain = domain;
148 if (on_mutation)
149 on_mutation();
150 }
151
163
171
175 void NotifyEntityChanged() const {
178 }
179};
180
181} // namespace editor
182} // namespace yaze
183
184#endif // YAZE_APP_EDITOR_DUNGEON_INTERACTION_INTERACTION_CONTEXT_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Manages object selection state and operations for the dungeon editor.
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
bool IsValidRoomId(int room_id)
Validate room ID is within valid range.
MutationDomain
Domain/type of mutation for undo + invalidation routing.
EntityType
Type of entity that can be selected in the dungeon editor.
Shared context for all interaction handlers.
std::function< void(int target_room_id, std::optional< size_t > target_door_index, int target_tile_x, int target_tile_y)> on_door_pair_navigation
std::function< void()> on_invalidate_cache
const zelda3::Room * GetCurrentRoomConst() const
Get const pointer to current room.
void NotifyEntityChanged() const
Notify that entity has changed.
void NotifyInvalidateCache(MutationDomain domain=MutationDomain::kUnknown) const
Notify that cache invalidation is needed.
bool IsValid() const
Check if context has required dependencies.
void NotifySelectionChanged() const
Notify that selection has changed.
void NotifyMutation(MutationDomain domain=MutationDomain::kUnknown) const
Notify that a mutation is about to happen.
zelda3::Room * GetCurrentRoom() const
Get pointer to current room.
std::function< void()> on_entity_changed
std::function< void()> on_selection_changed
Represents a selected entity in the dungeon editor.
bool operator==(const SelectedEntity &other) const
Represents a group of palettes.