1 | /**************************************************************************/ |
2 | /* scene_replication_config.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef SCENE_REPLICATION_CONFIG_H |
32 | #define SCENE_REPLICATION_CONFIG_H |
33 | |
34 | #include "core/io/resource.h" |
35 | #include "core/variant/typed_array.h" |
36 | |
37 | class SceneReplicationConfig : public Resource { |
38 | GDCLASS(SceneReplicationConfig, Resource); |
39 | OBJ_SAVE_TYPE(SceneReplicationConfig); |
40 | RES_BASE_EXTENSION("repl" ); |
41 | |
42 | public: |
43 | enum ReplicationMode { |
44 | REPLICATION_MODE_NEVER, |
45 | REPLICATION_MODE_ALWAYS, |
46 | REPLICATION_MODE_ON_CHANGE, |
47 | }; |
48 | |
49 | private: |
50 | struct ReplicationProperty { |
51 | NodePath name; |
52 | bool spawn = true; |
53 | ReplicationMode mode = REPLICATION_MODE_ALWAYS; |
54 | |
55 | bool operator==(const ReplicationProperty &p_to) { |
56 | return name == p_to.name; |
57 | } |
58 | |
59 | ReplicationProperty() {} |
60 | |
61 | ReplicationProperty(const NodePath &p_name) { |
62 | name = p_name; |
63 | } |
64 | }; |
65 | |
66 | List<ReplicationProperty> properties; |
67 | List<NodePath> spawn_props; |
68 | List<NodePath> sync_props; |
69 | List<NodePath> watch_props; |
70 | bool dirty = false; |
71 | |
72 | void _update(); |
73 | |
74 | protected: |
75 | static void _bind_methods(); |
76 | |
77 | bool _set(const StringName &p_name, const Variant &p_value); |
78 | bool _get(const StringName &p_name, Variant &r_ret) const; |
79 | void _get_property_list(List<PropertyInfo> *p_list) const; |
80 | |
81 | public: |
82 | TypedArray<NodePath> get_properties() const; |
83 | |
84 | void add_property(const NodePath &p_path, int p_index = -1); |
85 | void remove_property(const NodePath &p_path); |
86 | bool has_property(const NodePath &p_path) const; |
87 | |
88 | int property_get_index(const NodePath &p_path) const; |
89 | bool property_get_spawn(const NodePath &p_path); |
90 | void property_set_spawn(const NodePath &p_path, bool p_enabled); |
91 | |
92 | bool property_get_sync(const NodePath &p_path); |
93 | void property_set_sync(const NodePath &p_path, bool p_enabled); |
94 | |
95 | bool property_get_watch(const NodePath &p_path); |
96 | void property_set_watch(const NodePath &p_path, bool p_enabled); |
97 | |
98 | ReplicationMode property_get_replication_mode(const NodePath &p_path); |
99 | void property_set_replication_mode(const NodePath &p_path, ReplicationMode p_mode); |
100 | |
101 | const List<NodePath> &get_spawn_properties(); |
102 | const List<NodePath> &get_sync_properties(); |
103 | const List<NodePath> &get_watch_properties(); |
104 | |
105 | SceneReplicationConfig() {} |
106 | }; |
107 | |
108 | VARIANT_ENUM_CAST(SceneReplicationConfig::ReplicationMode); |
109 | |
110 | #endif // SCENE_REPLICATION_CONFIG_H |
111 | |