Unravel Engine C++ Reference
Loading...
Searching...
No Matches
property_actions.cpp
Go to the documentation of this file.
1
#include "
property_actions.h
"
2
3
namespace
unravel
4
{
5
6
7
// Property Action Implementation
8
property_action_t::property_action_t
(
meta_any_proxy
inst,
const
entt::meta_any& old_val,
const
entt::meta_any& new_val,
const
entt::meta_custom& custom,
const
std::function<
void
()>& on_success)
9
: instance(inst), old_value(old_val), new_value(new_val), custom(custom), on_success(on_success)
10
{
11
12
if
(!inst.
impl
->name.empty())
13
{
14
name = inst.impl->name;
15
}
16
else
17
{
18
name =
"Property Edit"
;
19
}
20
}
21
22
void
property_action_t::do_action
()
23
{
24
if
(
instance
.
impl
->setter(
instance
,
new_value
, execution_count))
25
{
26
if
(
on_success
)
27
{
28
on_success
();
29
}
30
}
31
// After first execution, switch to resolver-based access.
32
// The original references will go out of scope after this frame.
33
if
(execution_count <= 1)
34
{
35
detach
();
36
}
37
}
38
39
void
property_action_t::undo_action
()
40
{
41
if
(
instance
.
impl
->setter(
instance
,
old_value
, execution_count))
42
{
43
if
(
on_success
)
44
{
45
on_success
();
46
}
47
}
48
}
49
50
void
property_action_t::detach
()
51
{
52
instance
.
detach
();
53
}
54
55
auto
property_action_t::is_mergeable
(
const
editing_action_t
& previous)
const
->
bool
56
{
57
const
auto
& prev =
static_cast<
const
property_action_t
&
>
(previous);
58
entt::meta_any inst;
59
instance.
impl
->getter(inst);
60
entt::meta_any prev_inst;
61
prev.instance.impl->getter(prev_inst);
62
return
inst == prev_inst;
63
}
64
65
void
property_action_t::merge_with
(
const
editing_action_t
& previous)
66
{
67
const
auto
& prev =
static_cast<
const
property_action_t
&
>
(previous);
68
old_value
.assign(prev.old_value);
69
}
70
71
auto
property_action_t::is_valid
() const ->
bool
72
{
73
entt::meta_any inst;
74
instance
.
impl
->getter(inst);
75
76
return
!!inst;
77
}
78
79
void
property_action_t::draw_in_inspector
(
rtti::context
& ctx)
80
{
81
draw_in_inspector_impl(ctx,
old_value
,
new_value
,
custom
);
82
}
83
84
}
// namespace unravel
unravel
Definition
crash.cpp:21
property_actions.h
rtti::context
Definition
context.hpp:14
unravel::editing_action_t
Definition
editing_action.h:12
unravel::meta_any_proxy
Safe deferred property access proxy for arbitrary object properties.
Definition
inspector.h:216
unravel::meta_any_proxy::detach
void detach()
Definition
inspector.h:279
unravel::meta_any_proxy::impl
std::shared_ptr< meta_any_proxy_impl > impl
Definition
inspector.h:274
unravel::property_action_t
Definition
property_actions.h:15
unravel::property_action_t::custom
entt::meta_custom custom
Definition
property_actions.h:19
unravel::property_action_t::is_mergeable
auto is_mergeable(const editing_action_t &previous) const -> bool override
Definition
property_actions.cpp:55
unravel::property_action_t::new_value
entt::meta_any new_value
Definition
property_actions.h:18
unravel::property_action_t::draw_in_inspector
void draw_in_inspector(rtti::context &ctx) override
Definition
property_actions.cpp:79
unravel::property_action_t::property_action_t
property_action_t(meta_any_proxy inst, const entt::meta_any &old_val, const entt::meta_any &new_val, const entt::meta_custom &custom={}, const std::function< void()> &on_success={})
Definition
property_actions.cpp:8
unravel::property_action_t::old_value
entt::meta_any old_value
Definition
property_actions.h:17
unravel::property_action_t::merge_with
void merge_with(const editing_action_t &previous) override
Definition
property_actions.cpp:65
unravel::property_action_t::undo_action
void undo_action() override
Definition
property_actions.cpp:39
unravel::property_action_t::detach
void detach() override
Definition
property_actions.cpp:50
unravel::property_action_t::on_success
std::function< void()> on_success
Definition
property_actions.h:20
unravel::property_action_t::is_valid
auto is_valid() const -> bool override
Definition
property_actions.cpp:71
unravel::property_action_t::instance
meta_any_proxy instance
Definition
property_actions.h:16
unravel::property_action_t::do_action
void do_action() override
Definition
property_actions.cpp:22
editor
editor
editing
actions
property_actions.cpp
Generated by
1.12.0