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 // View-derived eligibility for tile-object selection. This is intentionally
102 // separate from ObjectSelection's explicit stored-layer filter: hiding BG1
103 // or BG2 must remove that content from canvas hit-testing without changing
104 // which stored object stream the user chose to target.
105 std::function<bool(int, const zelda3::RoomObject&)>
107
108 // Called when an interactive door-pair badge requests navigation to the
109 // adjacent room. The optional door index is in the target room.
110 std::function<void(int target_room_id,
111 std::optional<size_t> target_door_index, int target_tile_x,
112 int target_tile_y)>
114
115 // Last mutation/invalidation domain (best-effort). Set by Notify* helpers so
116 // the editor can route undo capture and expensive rerenders appropriately.
119
123 bool IsValid() const { return canvas != nullptr && rooms != nullptr; }
124
131 return nullptr;
132 }
133 return &(*rooms)[current_room_id];
134 }
135
142 return nullptr;
143 }
144 return &(*rooms)[current_room_id];
145 }
146
151
159 last_mutation_domain = domain;
160 if (on_mutation)
161 on_mutation();
162 }
163
175
183
187 void NotifyEntityChanged() const {
190 }
191};
192
193} // namespace editor
194} // namespace yaze
195
196#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.
std::function< bool(int, const zelda3::RoomObject &) is_object_visible_for_selection)
bool IsObjectVisibleForSelection(const zelda3::RoomObject &object) const
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.