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
9#include "absl/status/status.h"
14#include "rom/rom.h"
15#include "zelda3/dungeon/room.h"
16
17namespace yaze {
18namespace editor {
19
20class ObjectSelection;
21struct DungeonSelectionEditPlan;
22
26enum class EntityType {
27 None,
28 Object, // Room tile objects
29 Door, // Door entities
30 Sprite, // Enemy/NPC sprites
31 Item // Pot items
32};
33
41enum class MutationDomain : uint8_t {
42 kUnknown = 0,
44 kDoors,
46 kItems,
49};
50
55 EntityType type = EntityType::None;
56 size_t index = 0; // Index into the respective container
57
58 bool operator==(const SelectedEntity& other) const {
59 return type == other.type && index == other.index;
60 }
61};
62
80 // Core dependencies (required)
81 gui::Canvas* canvas = nullptr;
82 Rom* rom = nullptr;
86
87 // Palette for rendering previews
89
90 // Unified callbacks
91 // A complete, validated selection edit is published by the editor as one
92 // undo action. Continuous edits share a gesture until the finish callback.
93 std::function<absl::Status(const DungeonSelectionEditPlan&, bool continuous)>
95 std::function<void()> on_selection_edit_finished;
96 std::function<void(const absl::Status&)> on_selection_edit_error;
97
98 // Called before any state modification (for undo snapshots)
99 std::function<void()> on_mutation;
100
101 // Called after rendering changes require cache refresh
102 std::function<void()> on_invalidate_cache;
103
104 // Called when selection state changes
105 std::function<void()> on_selection_changed;
106
107 // Called when entity (door/sprite/item) changes
108 std::function<void()> on_entity_changed;
109
110 // View-derived eligibility for tile-object selection. This is intentionally
111 // separate from ObjectSelection's explicit stored-layer filter: hiding BG1
112 // or BG2 must remove that content from canvas hit-testing without changing
113 // which stored object stream the user chose to target.
114 std::function<bool(int, const zelda3::RoomObject&)>
116
117 // Called when an interactive door-pair badge requests navigation to the
118 // adjacent room. The optional door index is in the target room.
119 std::function<void(int target_room_id,
120 std::optional<size_t> target_door_index, int target_tile_x,
121 int target_tile_y)>
123
124 // Last mutation/invalidation domain (best-effort). Set by Notify* helpers so
125 // the editor can route undo capture and expensive rerenders appropriately.
128
132 bool IsValid() const { return canvas != nullptr && rooms != nullptr; }
133
140 return nullptr;
141 }
142 return &(*rooms)[current_room_id];
143 }
144
151 return nullptr;
152 }
153 return &(*rooms)[current_room_id];
154 }
155
160
168 last_mutation_domain = domain;
169 if (on_mutation)
170 on_mutation();
171 }
172
184
192
196 void NotifyEntityChanged() const {
199 }
200};
201
202} // namespace editor
203} // namespace yaze
204
205#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:49
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
std::function< void(const absl::Status &) on_selection_edit_error)
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.
std::function< void()> on_selection_edit_finished
zelda3::Room * GetCurrentRoom() const
Get pointer to current room.
std::function< absl::Status(const DungeonSelectionEditPlan &, bool continuous) on_selection_edit)
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.