You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-02 16:48:55 +00:00
Fix drag and drop @export variable assignment when script has errors
This commit is contained in:
@@ -2263,9 +2263,6 @@ String ScriptTextEditor::_get_dropped_resource_as_exported_member(const Ref<Reso
|
||||
}
|
||||
|
||||
variable_name = variable_name.to_snake_case().validate_unicode_identifier();
|
||||
for (ObjectID obj_id : p_script_instance_obj_ids) {
|
||||
pending_dragged_exports.push_back(DraggedExport{ obj_id, variable_name, p_resource });
|
||||
}
|
||||
|
||||
StringName class_name = p_resource->get_class();
|
||||
Ref<Script> resource_script = p_resource->get_script();
|
||||
@@ -2277,6 +2274,10 @@ String ScriptTextEditor::_get_dropped_resource_as_exported_member(const Ref<Reso
|
||||
}
|
||||
}
|
||||
|
||||
for (ObjectID obj_id : p_script_instance_obj_ids) {
|
||||
pending_dragged_exports.push_back(DraggedExport{ obj_id, variable_name, p_resource, class_name });
|
||||
}
|
||||
|
||||
return vformat("@export var %s: %s", variable_name, class_name);
|
||||
}
|
||||
|
||||
@@ -2468,7 +2469,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
|
||||
|
||||
text_to_drop += vformat("@export var %s: %s\n", variable_name, class_name);
|
||||
for (ObjectID obj_id : obj_ids) {
|
||||
pending_dragged_exports.push_back(DraggedExport{ obj_id, variable_name, node });
|
||||
pending_dragged_exports.push_back(DraggedExport{ obj_id, variable_name, node, class_name });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2576,30 +2577,54 @@ void ScriptTextEditor::_assign_dragged_export_variables() {
|
||||
ERR_FAIL_COND(pending_dragged_exports.is_empty());
|
||||
|
||||
bool export_variable_set = false;
|
||||
for (const DraggedExport &dragged_export : pending_dragged_exports) {
|
||||
|
||||
for (int i = pending_dragged_exports.size() - 1; i >= 0; i--) {
|
||||
const DraggedExport &dragged_export = pending_dragged_exports[i];
|
||||
Object *obj = ObjectDB::get_instance(dragged_export.obj_id);
|
||||
if (!obj) {
|
||||
WARN_PRINT("Object not found, can't assign export variable.");
|
||||
pending_dragged_exports.remove_at(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
ScriptInstance *si = obj->get_script_instance();
|
||||
if (!si) {
|
||||
WARN_PRINT("Script on " + obj->to_string() + " does not exist anymore, can't assign export variable.");
|
||||
pending_dragged_exports.remove_at(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool success = si->set(dragged_export.variable_name, dragged_export.value);
|
||||
if (success) {
|
||||
export_variable_set = true;
|
||||
bool script_has_errors = false;
|
||||
String scr_path = si->get_script()->get_path();
|
||||
|
||||
for (const ScriptLanguage::ScriptError &error : errors) {
|
||||
if (error.path == scr_path) {
|
||||
script_has_errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!script_has_errors) {
|
||||
bool success = false;
|
||||
List<PropertyInfo> properties;
|
||||
si->get_property_list(&properties);
|
||||
for (const PropertyInfo &pi : properties) {
|
||||
if (pi.name == dragged_export.variable_name && pi.hint_string == dragged_export.class_name) {
|
||||
success = si->set(dragged_export.variable_name, dragged_export.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
export_variable_set = true;
|
||||
}
|
||||
pending_dragged_exports.remove_at(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (export_variable_set) {
|
||||
EditorInterface::get_singleton()->mark_scene_as_unsaved();
|
||||
}
|
||||
|
||||
pending_dragged_exports.clear();
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
||||
|
||||
@@ -186,6 +186,7 @@ class ScriptTextEditor : public ScriptEditorBase {
|
||||
ObjectID obj_id;
|
||||
String variable_name;
|
||||
Variant value;
|
||||
String class_name;
|
||||
};
|
||||
|
||||
LocalVector<DraggedExport> pending_dragged_exports;
|
||||
|
||||
Reference in New Issue
Block a user