2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_debugger_inspector.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
#include "editor_debugger_inspector.h"
|
|
|
|
|
2020-03-08 12:21:08 +01:00
|
|
|
#include "core/debugger/debugger_marshalls.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
#include "core/io/marshalls.h"
|
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "scene/debugger/scene_debugger.h"
|
|
|
|
|
|
|
|
bool EditorDebuggerRemoteObject::_set(const StringName &p_name, const Variant &p_value) {
|
2022-07-29 20:29:43 +02:00
|
|
|
if (!prop_values.has(p_name) || String(p_name).begins_with("Constants/")) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
prop_values[p_name] = p_value;
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("value_edited"), remote_object_id, p_name, p_value);
|
2020-02-07 02:52:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorDebuggerRemoteObject::_get(const StringName &p_name, Variant &r_ret) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!prop_values.has(p_name)) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
r_ret = prop_values[p_name];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerRemoteObject::_get_property_list(List<PropertyInfo> *p_list) const {
|
2021-12-01 21:21:58 +01:00
|
|
|
p_list->clear(); // Sorry, no want category.
|
|
|
|
for (const PropertyInfo &prop : prop_list) {
|
|
|
|
if (prop.name == "script") {
|
|
|
|
// Skip the script property, it's always added by the non-virtual method.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_list->push_back(prop);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorDebuggerRemoteObject::get_title() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (remote_object_id.is_valid()) {
|
2022-06-08 11:42:51 +02:00
|
|
|
return vformat(TTR("Remote %s:"), String(type_name)) + " " + itos(remote_object_id);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2020-02-07 02:52:05 +01:00
|
|
|
return "<null>";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Variant EditorDebuggerRemoteObject::get_variant(const StringName &p_name) {
|
|
|
|
Variant var;
|
|
|
|
_get(p_name, var);
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerRemoteObject::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("get_title"), &EditorDebuggerRemoteObject::get_title);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_variant"), &EditorDebuggerRemoteObject::get_variant);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &EditorDebuggerRemoteObject::clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_remote_object_id"), &EditorDebuggerRemoteObject::get_remote_object_id);
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("value_edited", PropertyInfo(Variant::INT, "object_id"), PropertyInfo(Variant::STRING, "property"), PropertyInfo("value")));
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorDebuggerInspector::EditorDebuggerInspector() {
|
|
|
|
variables = memnew(EditorDebuggerRemoteObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorDebuggerInspector::~EditorDebuggerInspector() {
|
2020-03-05 12:24:49 +01:00
|
|
|
clear_cache();
|
2020-02-07 02:52:05 +01:00
|
|
|
memdelete(variables);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("object_selected", PropertyInfo(Variant::INT, "id")));
|
|
|
|
ADD_SIGNAL(MethodInfo("object_edited", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property"), PropertyInfo("value")));
|
|
|
|
ADD_SIGNAL(MethodInfo("object_property_updated", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2022-02-16 00:52:32 +01:00
|
|
|
case NOTIFICATION_POSTINITIALIZE: {
|
2020-02-21 18:28:45 +01:00
|
|
|
connect("object_id_selected", callable_mp(this, &EditorDebuggerInspector::_object_selected));
|
2022-02-16 00:52:32 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2020-02-07 02:52:05 +01:00
|
|
|
edit(variables);
|
2022-02-16 00:52:32 +01:00
|
|
|
} break;
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::_object_edited(ObjectID p_id, const String &p_prop, const Variant &p_value) {
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("object_edited"), p_id, p_prop, p_value);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::_object_selected(ObjectID p_object) {
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("object_selected"), p_object);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) {
|
2022-07-25 14:29:33 +02:00
|
|
|
EditorDebuggerRemoteObject *debug_obj = nullptr;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
SceneDebuggerObject obj;
|
|
|
|
obj.deserialize(p_arr);
|
|
|
|
ERR_FAIL_COND_V(obj.id.is_null(), ObjectID());
|
|
|
|
|
|
|
|
if (remote_objects.has(obj.id)) {
|
2022-07-25 14:29:33 +02:00
|
|
|
debug_obj = remote_objects[obj.id];
|
2020-02-07 02:52:05 +01:00
|
|
|
} else {
|
2022-07-25 14:29:33 +02:00
|
|
|
debug_obj = memnew(EditorDebuggerRemoteObject);
|
|
|
|
debug_obj->remote_object_id = obj.id;
|
|
|
|
debug_obj->type_name = obj.class_name;
|
|
|
|
remote_objects[obj.id] = debug_obj;
|
|
|
|
debug_obj->connect("value_edited", callable_mp(this, &EditorDebuggerInspector::_object_edited));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
2022-07-25 14:29:33 +02:00
|
|
|
int old_prop_size = debug_obj->prop_list.size();
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2022-07-25 14:29:33 +02:00
|
|
|
debug_obj->prop_list.clear();
|
2020-02-07 02:52:05 +01:00
|
|
|
int new_props_added = 0;
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<String> changed;
|
2020-02-07 02:52:05 +01:00
|
|
|
for (int i = 0; i < obj.properties.size(); i++) {
|
|
|
|
PropertyInfo &pinfo = obj.properties[i].first;
|
|
|
|
Variant &var = obj.properties[i].second;
|
|
|
|
|
|
|
|
if (pinfo.type == Variant::OBJECT) {
|
|
|
|
if (var.get_type() == Variant::STRING) {
|
|
|
|
String path = var;
|
2022-02-03 17:03:38 +01:00
|
|
|
if (path.contains("::")) {
|
2020-02-07 02:52:05 +01:00
|
|
|
// built-in resource
|
|
|
|
String base_path = path.get_slice("::", 0);
|
2022-05-03 01:43:50 +02:00
|
|
|
Ref<Resource> dependency = ResourceLoader::load(base_path);
|
2020-05-22 21:50:16 +02:00
|
|
|
if (dependency.is_valid()) {
|
|
|
|
remote_dependencies.insert(dependency);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var = ResourceLoader::load(path);
|
|
|
|
|
|
|
|
if (pinfo.hint_string == "Script") {
|
2022-07-25 14:29:33 +02:00
|
|
|
if (debug_obj->get_script() != var) {
|
|
|
|
debug_obj->set_script(Ref<RefCounted>());
|
2022-09-29 11:53:28 +02:00
|
|
|
Ref<Script> scr(var);
|
|
|
|
if (!scr.is_null()) {
|
|
|
|
ScriptInstance *scr_instance = scr->placeholder_instance_create(debug_obj);
|
|
|
|
if (scr_instance) {
|
|
|
|
debug_obj->set_script_and_instance(var, scr_instance);
|
2022-07-25 14:29:33 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//always add the property, since props may have been added or removed
|
2022-07-25 14:29:33 +02:00
|
|
|
debug_obj->prop_list.push_back(pinfo);
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2022-07-25 14:29:33 +02:00
|
|
|
if (!debug_obj->prop_values.has(pinfo.name)) {
|
2020-02-07 02:52:05 +01:00
|
|
|
new_props_added++;
|
2022-07-25 14:29:33 +02:00
|
|
|
debug_obj->prop_values[pinfo.name] = var;
|
2020-02-07 02:52:05 +01:00
|
|
|
} else {
|
2022-07-25 14:29:33 +02:00
|
|
|
if (bool(Variant::evaluate(Variant::OP_NOT_EQUAL, debug_obj->prop_values[pinfo.name], var))) {
|
|
|
|
debug_obj->prop_values[pinfo.name] = var;
|
2020-02-07 02:52:05 +01:00
|
|
|
changed.insert(pinfo.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 14:29:33 +02:00
|
|
|
if (old_prop_size == debug_obj->prop_list.size() && new_props_added == 0) {
|
2020-02-07 02:52:05 +01:00
|
|
|
//only some may have changed, if so, then update those, if exist
|
2022-05-19 01:43:40 +02:00
|
|
|
for (const String &E : changed) {
|
2022-07-25 14:29:33 +02:00
|
|
|
emit_signal(SNAME("object_property_updated"), debug_obj->remote_object_id, E);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//full update, because props were added or removed
|
2022-07-25 14:29:33 +02:00
|
|
|
debug_obj->update();
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
return obj.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::clear_cache() {
|
2021-08-09 22:13:42 +02:00
|
|
|
for (const KeyValue<ObjectID, EditorDebuggerRemoteObject *> &E : remote_objects) {
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorNode *editor = EditorNode::get_singleton();
|
2022-03-30 20:12:26 +02:00
|
|
|
if (editor->get_editor_selection_history()->get_current() == E.value->get_instance_id()) {
|
2020-04-02 01:20:12 +02:00
|
|
|
editor->push_item(nullptr);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
2021-08-09 22:13:42 +02:00
|
|
|
memdelete(E.value);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
remote_objects.clear();
|
2020-05-22 21:50:16 +02:00
|
|
|
remote_dependencies.clear();
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *EditorDebuggerInspector::get_object(ObjectID p_id) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (remote_objects.has(p_id)) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return remote_objects[p_id];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::add_stack_variable(const Array &p_array) {
|
2020-03-08 12:21:08 +01:00
|
|
|
DebuggerMarshalls::ScriptStackVariable var;
|
2020-02-07 02:52:05 +01:00
|
|
|
var.deserialize(p_array);
|
|
|
|
String n = var.name;
|
|
|
|
Variant v = var.value;
|
|
|
|
|
|
|
|
PropertyHint h = PROPERTY_HINT_NONE;
|
2022-11-14 18:21:06 +01:00
|
|
|
String hs;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
if (v.get_type() == Variant::OBJECT) {
|
|
|
|
v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
|
|
|
|
h = PROPERTY_HINT_OBJECT_ID;
|
|
|
|
hs = "Object";
|
|
|
|
}
|
|
|
|
String type;
|
|
|
|
switch (var.type) {
|
|
|
|
case 0:
|
|
|
|
type = "Locals/";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
type = "Members/";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
type = "Globals/";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "Unknown/";
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo pinfo;
|
|
|
|
pinfo.name = type + n;
|
|
|
|
pinfo.type = v.get_type();
|
|
|
|
pinfo.hint = h;
|
|
|
|
pinfo.hint_string = hs;
|
|
|
|
|
|
|
|
variables->prop_list.push_back(pinfo);
|
|
|
|
variables->prop_values[type + n] = v;
|
|
|
|
variables->update();
|
|
|
|
edit(variables);
|
2022-01-12 12:53:32 +01:00
|
|
|
|
|
|
|
// To prevent constantly resizing when using filtering.
|
|
|
|
int size_x = get_size().x;
|
|
|
|
if (size_x > get_custom_minimum_size().x) {
|
|
|
|
set_custom_minimum_size(Size2(size_x, 0));
|
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerInspector::clear_stack_variables() {
|
|
|
|
variables->clear();
|
|
|
|
variables->update();
|
2022-01-12 12:53:32 +01:00
|
|
|
set_custom_minimum_size(Size2(0, 0));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorDebuggerInspector::get_stack_variable(const String &p_var) {
|
2022-05-13 15:04:37 +02:00
|
|
|
for (KeyValue<StringName, Variant> &E : variables->prop_values) {
|
|
|
|
String v = E.key.operator String();
|
2021-09-15 18:04:44 +02:00
|
|
|
if (v.get_slice("/", 1) == p_var) {
|
|
|
|
return variables->get_variant(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return String();
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|