scene_replication_config.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #ifndef SCENE_REPLICATION_CONFIG_H
  31. #define SCENE_REPLICATION_CONFIG_H
  32. #include "core/io/resource.h"
  33. #include "core/variant/typed_array.h"
  34. class SceneReplicationConfig : public Resource {
  35. GDCLASS(SceneReplicationConfig, Resource);
  36. OBJ_SAVE_TYPE(SceneReplicationConfig);
  37. RES_BASE_EXTENSION("repl");
  38. public:
  39. enum ReplicationMode {
  40. REPLICATION_MODE_NEVER,
  41. REPLICATION_MODE_ALWAYS,
  42. REPLICATION_MODE_ON_CHANGE,
  43. };
  44. private:
  45. struct ReplicationProperty {
  46. NodePath name;
  47. bool spawn = true;
  48. ReplicationMode mode = REPLICATION_MODE_ALWAYS;
  49. bool operator==(const ReplicationProperty &p_to) {
  50. return name == p_to.name;
  51. }
  52. ReplicationProperty() {}
  53. ReplicationProperty(const NodePath &p_name) {
  54. name = p_name;
  55. }
  56. };
  57. List<ReplicationProperty> properties;
  58. List<NodePath> spawn_props;
  59. List<NodePath> sync_props;
  60. List<NodePath> watch_props;
  61. bool dirty = false;
  62. void _update();
  63. protected:
  64. static void _bind_methods();
  65. bool _set(const StringName &p_name, const Variant &p_value);
  66. bool _get(const StringName &p_name, Variant &r_ret) const;
  67. void _get_property_list(List<PropertyInfo> *p_list) const;
  68. public:
  69. virtual void reset_state() override; // Required since we use variable amount of properties.
  70. TypedArray<NodePath> get_properties() const;
  71. void add_property(const NodePath &p_path, int p_index = -1);
  72. void remove_property(const NodePath &p_path);
  73. bool has_property(const NodePath &p_path) const;
  74. int property_get_index(const NodePath &p_path) const;
  75. bool property_get_spawn(const NodePath &p_path);
  76. void property_set_spawn(const NodePath &p_path, bool p_enabled);
  77. bool property_get_sync(const NodePath &p_path);
  78. void property_set_sync(const NodePath &p_path, bool p_enabled);
  79. bool property_get_watch(const NodePath &p_path);
  80. void property_set_watch(const NodePath &p_path, bool p_enabled);
  81. ReplicationMode property_get_replication_mode(const NodePath &p_path);
  82. void property_set_replication_mode(const NodePath &p_path, ReplicationMode p_mode);
  83. const List<NodePath> &get_spawn_properties();
  84. const List<NodePath> &get_sync_properties();
  85. const List<NodePath> &get_watch_properties();
  86. SceneReplicationConfig() {}
  87. };
  88. VARIANT_ENUM_CAST(SceneReplicationConfig::ReplicationMode);
  89. #endif // SCENE_REPLICATION_CONFIG_H