Unravel Engine C++ Reference
Loading...
Searching...
No Matches
entity_actions.h
Go to the documentation of this file.
1#pragma once
2
3#include "editing_action.h"
4#include "entt/meta/meta.hpp"
6#include <engine/ecs/scene.h>
7#include <base/basetypes.hpp>
8#include <math/math.h>
9#include <functional>
10#include <sstream>
11#include <uuid/uuid.h>
12#include <vector>
13
14namespace unravel
15{
16
17class material;
18
28struct create_entities_action_t : crtp_meta_type<create_entities_action_t, editing_action_t>
29{
32 std::function<std::vector<entt::handle>()> factory{};
33
35 std::vector<std::string> serialized_roots{};
37 std::vector<entt::uhandle> root_entities{};
39 std::vector<entt::uhandle> parent_entities{};
41 std::vector<std::vector<hpp::uuid>> subtree_uuids{};
42
44 bool captured{false};
45
47 create_entities_action_t(std::function<std::vector<entt::handle>()> factory);
48
50 create_entities_action_t(std::function<entt::handle()> factory);
51
52 void do_action() override;
53 void undo_action() override;
54 auto is_mergeable(const editing_action_t& previous) const -> bool override;
55 auto is_valid() const -> bool override;
56};
57
62{
63 std::vector<std::string> serialized_roots{};
64 std::vector<entt::uhandle> root_entities{};
65 std::vector<entt::uhandle> parent_entities{};
67 std::vector<std::vector<hpp::uuid>> subtree_uuids{};
68
69 explicit delete_entities_action_t(std::vector<entt::handle> entities);
70
71 void do_action() override;
72 void undo_action() override;
73 auto is_mergeable(const editing_action_t& previous) const -> bool override;
74 auto is_valid() const -> bool override;
75};
76
77// Individual entity component actions
79{
81 entt::meta_type component_type{};
82
83 bool do_was_successful{false};
84
85 entity_add_component_action_t(entt::handle ent, const entt::meta_type& ctype);
86
87 void do_action() override;
88 void undo_action() override;
89 auto is_mergeable(const editing_action_t& previous) const -> bool override;
90 auto is_valid() const -> bool override;
91 void draw_in_inspector(rtti::context& ctx) override;
92};
93
95{
97 entt::meta_type component_type{};
98
99 bool do_was_successful{false};
100 std::stringstream stream{};
101
102 entity_remove_component_action_t(entt::handle ent, const entt::meta_type& ctype);
103
104 void do_action() override;
105 void undo_action() override;
106 auto is_mergeable(const editing_action_t& previous) const -> bool override;
107 auto is_valid() const -> bool override;
108 void draw_in_inspector(rtti::context& ctx) override;
109};
110
111// Individual entity component actions
113{
115 bool old_active{};
116 bool new_active{};
117
118 entity_set_active_action_t(entt::handle ent, bool old_active, bool new_active);
119
120 void do_action() override;
121 void undo_action() override;
122 auto is_mergeable(const editing_action_t& previous) const -> bool override;
123 void merge_with(const editing_action_t& previous) override;
124 auto is_valid() const -> bool override;
125 void draw_in_inspector(rtti::context& ctx) override;
126};
127
129{
131 std::string old_name{};
132 std::string new_name{};
133
134 entity_set_name_action_t(entt::handle ent, const std::string& old_name, const std::string& new_name);
135
136 void do_action() override;
137 void undo_action() override;
138 auto is_mergeable(const editing_action_t& previous) const -> bool override;
139 void merge_with(const editing_action_t& previous) override;
140 auto is_valid() const -> bool override;
141 void draw_in_inspector(rtti::context& ctx) override;
142};
143
145{
147 std::string old_tag{};
148 std::string new_tag{};
149
150 entity_set_tag_action_t(entt::handle ent, const std::string& old_tag, const std::string& new_tag);
151
152 void do_action() override;
153 void undo_action() override;
154 auto is_mergeable(const editing_action_t& previous) const -> bool override;
155 void merge_with(const editing_action_t& previous) override;
156 auto is_valid() const -> bool override;
157 void draw_in_inspector(rtti::context& ctx) override;
158};
159
161{
163 std::vector<asset_handle<material>> old_materials{};
164 std::vector<asset_handle<material>> new_materials{};
165
166 entity_set_materials_action_t(entt::handle ent,
167 const std::vector<asset_handle<material>>& old_materials,
168 const asset_handle<material>& new_material);
169
170 void do_action() override;
171 void undo_action() override;
172 auto is_mergeable(const editing_action_t& previous) const -> bool override;
173 void merge_with(const editing_action_t& previous) override;
174 auto is_valid() const -> bool override;
175 void draw_in_inspector(rtti::context& ctx) override;
176};
177
179{
181 fsize_t old_area{};
183
184 entity_set_text_bounds_action_t(entt::handle ent, const fsize_t& old_area, const fsize_t& new_area);
185
186 void do_action() override;
187 void undo_action() override;
188 auto is_mergeable(const editing_action_t& previous) const -> bool override;
189 void merge_with(const editing_action_t& previous) override;
190 auto is_valid() const -> bool override;
191 void draw_in_inspector(rtti::context& ctx) override;
192};
193
195{
197 usize32_t old_size{};
198 usize32_t new_size{};
199
200 entity_set_ui_document_component_bounds_action_t(entt::handle ent, const usize32_t& old_size, const usize32_t& new_size);
201
202 void do_action() override;
203 void undo_action() override;
204 auto is_mergeable(const editing_action_t& previous) const -> bool override;
205 void merge_with(const editing_action_t& previous) override;
206 auto is_valid() const -> bool override;
207 void draw_in_inspector(rtti::context& ctx) override;
208};
209
210// Script component specific actions
212{
214 std::string script_type_name{};
215
216 bool do_was_successful{false};
217
218 entity_add_script_component_action_t(entt::handle ent, const std::string& type_name);
219
220 void do_action() override;
221 void undo_action() override;
222 auto is_mergeable(const editing_action_t& previous) const -> bool override;
223 auto is_valid() const -> bool override;
224 void draw_in_inspector(rtti::context& ctx) override;
225};
226
228{
230 std::string script_type_name{};
231 int script_index{-1}; // Index of the script component to remove
232
233 bool do_was_successful{false};
234 // Store the script object data for restoration
235 std::stringstream removed_script_object_data{};
236
237 entity_remove_script_component_action_t(entt::handle ent, const std::string& type_name, int index = -1);
238
239 void do_action() override;
240 void undo_action() override;
241 auto is_mergeable(const editing_action_t& previous) const -> bool override;
242 auto is_valid() const -> bool override;
243 void draw_in_inspector(rtti::context& ctx) override;
244};
245
246} // namespace unravel
uint16_t index
entt::handle entity
fsize_t new_area
Thread-safe handle to an asset.
Undoable create for entity subtrees: invokes a user-supplied factory on first execution,...
auto is_mergeable(const editing_action_t &previous) const -> bool override
create_entities_action_t(std::function< std::vector< entt::handle >()> factory)
Multi-root constructor. The factory returns the set of newly-created roots.
std::function< std::vector< entt::handle >()> factory
bool captured
True once the initial factory-driven creation has run and the snapshot is populated.
auto is_valid() const -> bool override
std::vector< entt::uhandle > parent_entities
Parent of each root (may hold a nil uuid for root-level entities). Refreshed on every undo.
std::vector< std::string > serialized_roots
Serialized bytes of each root, captured after the first factory execution.
std::vector< entt::uhandle > root_entities
Handles of each created root; the registry pointer persists even after the entity is destroyed.
std::vector< std::vector< hpp::uuid > > subtree_uuids
Preorder UUIDs per root subtree (same ordering as save_to_stream / flatten_hierarchy).
Undoable delete for entity subtrees: snapshots serialized roots at construction, deletes on do,...