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 <base/basetypes.hpp>
7#include <math/math.h>
8#include <sstream>
9
10namespace unravel
11{
12
13class material;
14
15// Individual entity component actions
16struct entity_add_component_action_t : crtp_meta_type<entity_add_component_action_t, editing_action_t>
17{
18 entt::handle entity{};
19 entt::meta_type component_type{};
20
21 bool do_was_successful{false};
22
23 entity_add_component_action_t(entt::handle ent, const entt::meta_type& ctype);
24
25 void do_action() override;
26 void undo_action() override;
27 auto is_mergeable(const editing_action_t& previous) const -> bool override;
28 auto is_valid() const -> bool override;
29 void draw_in_inspector(rtti::context& ctx) override;
30};
31
33{
34 entt::handle entity{};
35 entt::meta_type component_type{};
36
37 bool do_was_successful{false};
38 std::stringstream stream{};
39
40 entity_remove_component_action_t(entt::handle ent, const entt::meta_type& ctype);
41
42 void do_action() override;
43 void undo_action() override;
44 auto is_mergeable(const editing_action_t& previous) const -> bool override;
45 auto is_valid() const -> bool override;
46 void draw_in_inspector(rtti::context& ctx) override;
47};
48
49// Individual entity component actions
51{
52 entt::handle entity{};
53 bool old_active{};
54 bool new_active{};
55
56 entity_set_active_action_t(entt::handle ent, bool old_active, bool new_active);
57
58 void do_action() override;
59 void undo_action() override;
60 auto is_mergeable(const editing_action_t& previous) const -> bool override;
61 void merge_with(const editing_action_t& previous) override;
62 auto is_valid() const -> bool override;
63 void draw_in_inspector(rtti::context& ctx) override;
64};
65
67{
68 entt::handle entity{};
69 std::string old_name{};
70 std::string new_name{};
71
72 entity_set_name_action_t(entt::handle ent, const std::string& old_name, const std::string& new_name);
73
74 void do_action() override;
75 void undo_action() override;
76 auto is_mergeable(const editing_action_t& previous) const -> bool override;
77 void merge_with(const editing_action_t& previous) override;
78 auto is_valid() const -> bool override;
79 void draw_in_inspector(rtti::context& ctx) override;
80};
81
83{
84 entt::handle entity{};
85 std::string old_tag{};
86 std::string new_tag{};
87
88 entity_set_tag_action_t(entt::handle ent, const std::string& old_tag, const std::string& new_tag);
89
90 void do_action() override;
91 void undo_action() override;
92 auto is_mergeable(const editing_action_t& previous) const -> bool override;
93 void merge_with(const editing_action_t& previous) override;
94 auto is_valid() const -> bool override;
95 void draw_in_inspector(rtti::context& ctx) override;
96};
97
99{
100 entt::handle entity{};
101 std::vector<asset_handle<material>> old_materials{};
102 std::vector<asset_handle<material>> new_materials{};
103
104 entity_set_materials_action_t(entt::handle ent,
105 const std::vector<asset_handle<material>>& old_materials,
106 const asset_handle<material>& new_material);
107
108 void do_action() override;
109 void undo_action() override;
110 auto is_mergeable(const editing_action_t& previous) const -> bool override;
111 void merge_with(const editing_action_t& previous) override;
112 auto is_valid() const -> bool override;
113 void draw_in_inspector(rtti::context& ctx) override;
114};
115
117{
118 entt::handle entity{};
119 fsize_t old_area{};
120 fsize_t new_area{};
121
122 entity_set_text_bounds_action_t(entt::handle ent, const fsize_t& old_area, const fsize_t& new_area);
123
124 void do_action() override;
125 void undo_action() override;
126 auto is_mergeable(const editing_action_t& previous) const -> bool override;
127 void merge_with(const editing_action_t& previous) override;
128 auto is_valid() const -> bool override;
129 void draw_in_inspector(rtti::context& ctx) override;
130};
131
132// Script component specific actions
134{
135 entt::handle entity{};
136 std::string script_type_name{};
137
138 bool do_was_successful{false};
139
140 entity_add_script_component_action_t(entt::handle ent, const std::string& type_name);
141
142 void do_action() override;
143 void undo_action() override;
144 auto is_mergeable(const editing_action_t& previous) const -> bool override;
145 auto is_valid() const -> bool override;
146 void draw_in_inspector(rtti::context& ctx) override;
147};
148
150{
151 entt::handle entity{};
152 std::string script_type_name{};
153
154 bool do_was_successful{false};
155 // Store the script object data for restoration
156 std::stringstream removed_script_object_data{};
157
158 entity_remove_script_component_action_t(entt::handle ent, const std::string& type_name);
159
160 void do_action() override;
161 void undo_action() override;
162 auto is_mergeable(const editing_action_t& previous) const -> bool override;
163 auto is_valid() const -> bool override;
164 void draw_in_inspector(rtti::context& ctx) override;
165};
166
167} // namespace unravel
Represents a handle to an asset, providing access and management functions.
void draw_in_inspector(rtti::context &ctx) override
auto is_valid() const -> bool override
entity_add_component_action_t(entt::handle ent, const entt::meta_type &ctype)
auto is_mergeable(const editing_action_t &previous) const -> bool override