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