scene_debugger.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**************************************************************************/
  2. /* scene_debugger.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. #pragma once
  31. #include "core/input/shortcut.h"
  32. #include "core/object/ref_counted.h"
  33. #include "core/string/ustring.h"
  34. #include "core/variant/array.h"
  35. class CanvasItem;
  36. class LiveEditor;
  37. class PopupMenu;
  38. class RuntimeNodeSelect;
  39. class Script;
  40. class SceneTree;
  41. class SceneDebugger {
  42. private:
  43. inline static SceneDebugger *singleton = nullptr;
  44. SceneDebugger();
  45. public:
  46. static void initialize();
  47. static void deinitialize();
  48. ~SceneDebugger();
  49. #ifdef DEBUG_ENABLED
  50. private:
  51. static void _handle_input(const Ref<InputEvent> &p_event, const Ref<Shortcut> &p_shortcut);
  52. static void _handle_embed_input(const Ref<InputEvent> &p_event, const Dictionary &p_settings);
  53. static void _save_node(ObjectID id, const String &p_path);
  54. static void _set_node_owner_recursive(Node *p_node, Node *p_owner);
  55. static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value, const String &p_field = "");
  56. static void _send_object_ids(const Vector<ObjectID> &p_ids, bool p_update_selection);
  57. static void _next_frame();
  58. /// Message handler function for parse_message.
  59. typedef Error (*ParseMessageFunc)(const Array &p_args);
  60. static HashMap<String, ParseMessageFunc> message_handlers;
  61. static void _init_message_handlers();
  62. static Error _msg_setup_scene(const Array &p_args);
  63. static Error _msg_setup_embedded_shortcuts(const Array &p_args);
  64. static Error _msg_request_scene_tree(const Array &p_args);
  65. static Error _msg_save_node(const Array &p_args);
  66. static Error _msg_inspect_objects(const Array &p_args);
  67. #ifndef DISABLE_DEPRECATED
  68. static Error _msg_inspect_object(const Array &p_args);
  69. #endif // DISABLE_DEPRECATED
  70. static Error _msg_clear_selection(const Array &p_args);
  71. static Error _msg_suspend_changed(const Array &p_args);
  72. static Error _msg_next_frame(const Array &p_args);
  73. static Error _msg_speed_changed(const Array &p_args);
  74. static Error _msg_debug_mute_audio(const Array &p_args);
  75. static Error _msg_override_cameras(const Array &p_args);
  76. static Error _msg_set_object_property(const Array &p_args);
  77. static Error _msg_set_object_property_field(const Array &p_args);
  78. static Error _msg_reload_cached_files(const Array &p_args);
  79. static Error _msg_live_set_root(const Array &p_args);
  80. static Error _msg_live_node_path(const Array &p_args);
  81. static Error _msg_live_res_path(const Array &p_args);
  82. static Error _msg_live_node_prop_res(const Array &p_args);
  83. static Error _msg_live_node_prop(const Array &p_args);
  84. static Error _msg_live_res_prop_res(const Array &p_args);
  85. static Error _msg_live_res_prop(const Array &p_args);
  86. static Error _msg_live_node_call(const Array &p_args);
  87. static Error _msg_live_res_call(const Array &p_args);
  88. static Error _msg_live_create_node(const Array &p_args);
  89. static Error _msg_live_instantiate_node(const Array &p_args);
  90. static Error _msg_live_remove_node(const Array &p_args);
  91. static Error _msg_live_remove_and_keep_node(const Array &p_args);
  92. static Error _msg_live_restore_node(const Array &p_args);
  93. static Error _msg_live_duplicate_node(const Array &p_args);
  94. static Error _msg_live_reparent_node(const Array &p_args);
  95. static Error _msg_runtime_node_select_setup(const Array &p_args);
  96. static Error _msg_runtime_node_select_set_type(const Array &p_args);
  97. static Error _msg_runtime_node_select_set_mode(const Array &p_args);
  98. static Error _msg_runtime_node_select_set_visible(const Array &p_args);
  99. static Error _msg_runtime_node_select_set_avoid_locked(const Array &p_args);
  100. static Error _msg_runtime_node_select_set_prefer_group(const Array &p_args);
  101. static Error _msg_rq_screenshot(const Array &p_args);
  102. static Error _msg_runtime_node_select_reset_camera_2d(const Array &p_args);
  103. static Error _msg_transform_camera_2d(const Array &p_args);
  104. #ifndef _3D_DISABLED
  105. static Error _msg_runtime_node_select_reset_camera_3d(const Array &p_args);
  106. static Error _msg_transform_camera_3d(const Array &p_args);
  107. #endif // _3D_DISABLED
  108. public:
  109. static Error parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
  110. static void add_to_cache(const String &p_filename, Node *p_node);
  111. static void remove_from_cache(const String &p_filename, Node *p_node);
  112. static void reload_cached_files(const PackedStringArray &p_files);
  113. #endif
  114. };
  115. #ifdef DEBUG_ENABLED
  116. class LiveEditor {
  117. private:
  118. friend class SceneDebugger;
  119. HashMap<int, NodePath> live_edit_node_path_cache;
  120. HashMap<int, String> live_edit_resource_cache;
  121. NodePath live_edit_root;
  122. String live_edit_scene;
  123. HashMap<String, HashSet<Node *>> live_scene_edit_cache;
  124. HashMap<Node *, HashMap<ObjectID, Node *>> live_edit_remove_list;
  125. void _send_tree();
  126. void _node_path_func(const NodePath &p_path, int p_id);
  127. void _res_path_func(const String &p_path, int p_id);
  128. void _node_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  129. void _node_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  130. void _node_call_func(int p_id, const StringName &p_method, const Variant **p_args, int p_argcount);
  131. void _res_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  132. void _res_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  133. void _res_call_func(int p_id, const StringName &p_method, const Variant **p_args, int p_argcount);
  134. void _root_func(const NodePath &p_scene_path, const String &p_scene_from);
  135. void _create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name);
  136. void _instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name);
  137. void _remove_node_func(const NodePath &p_at);
  138. void _remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id);
  139. void _restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  140. void _duplicate_node_func(const NodePath &p_at, const String &p_new_name);
  141. void _reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  142. LiveEditor() {
  143. singleton = this;
  144. live_edit_root = NodePath("/root");
  145. }
  146. inline static LiveEditor *singleton = nullptr;
  147. public:
  148. static LiveEditor *get_singleton();
  149. };
  150. #endif // DEBUG_ENABLED