mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #24877 from neikeq/issue-24280
Fix properties being lost when reloading placeholder GDScript instance
This commit is contained in:
commit
658296856c
6 changed files with 51 additions and 40 deletions
|
@ -475,20 +475,15 @@ bool GDScript::_update_exports() {
|
|||
_signals[c->_signals[i].name] = c->_signals[i].arguments;
|
||||
}
|
||||
} else {
|
||||
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
|
||||
E->get()->set_build_failed(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!valid) {
|
||||
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
|
||||
E->get()->set_build_failed(true);
|
||||
}
|
||||
placeholder_fallback_enabled = true;
|
||||
return false;
|
||||
}
|
||||
} else if (!valid || placeholder_fallback_enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
placeholder_fallback_enabled = false;
|
||||
|
||||
if (base_cache.is_valid()) {
|
||||
if (base_cache->_update_exports()) {
|
||||
changed = true;
|
||||
|
@ -503,7 +498,6 @@ bool GDScript::_update_exports() {
|
|||
_update_exports_values(values, propnames);
|
||||
|
||||
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
|
||||
E->get()->set_build_failed(false);
|
||||
E->get()->update(propnames, values);
|
||||
}
|
||||
}
|
||||
|
@ -907,6 +901,7 @@ GDScript::GDScript() :
|
|||
tool = false;
|
||||
#ifdef TOOLS_ENABLED
|
||||
source_changed_cache = false;
|
||||
placeholder_fallback_enabled = false;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
@ -1675,6 +1670,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
|
|||
//restore state if saved
|
||||
for (Map<ObjectID, List<Pair<StringName, Variant> > >::Element *F = E->get().front(); F; F = F->next()) {
|
||||
|
||||
List<Pair<StringName, Variant> > &saved_state = F->get();
|
||||
|
||||
Object *obj = ObjectDB::get_instance(F->key());
|
||||
if (!obj)
|
||||
continue;
|
||||
|
@ -1684,16 +1681,26 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
|
|||
obj->set_script(RefPtr());
|
||||
}
|
||||
obj->set_script(scr.get_ref_ptr());
|
||||
if (!obj->get_script_instance()) {
|
||||
|
||||
ScriptInstance *script_instance = obj->get_script_instance();
|
||||
|
||||
if (!script_instance) {
|
||||
//failed, save reload state for next time if not saved
|
||||
if (!scr->pending_reload_state.has(obj->get_instance_id())) {
|
||||
scr->pending_reload_state[obj->get_instance_id()] = F->get();
|
||||
scr->pending_reload_state[obj->get_instance_id()] = saved_state;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (List<Pair<StringName, Variant> >::Element *G = F->get().front(); G; G = G->next()) {
|
||||
obj->get_script_instance()->set(G->get().first, G->get().second);
|
||||
if (script_instance->is_placeholder() && scr->is_placeholder_fallback_enabled()) {
|
||||
PlaceHolderScriptInstance *placeholder = static_cast<PlaceHolderScriptInstance *>(script_instance);
|
||||
for (List<Pair<StringName, Variant> >::Element *G = saved_state.front(); G; G = G->next()) {
|
||||
placeholder->property_set_fallback(G->get().first, G->get().second);
|
||||
}
|
||||
} else {
|
||||
for (List<Pair<StringName, Variant> >::Element *G = saved_state.front(); G; G = G->next()) {
|
||||
script_instance->set(G->get().first, G->get().second);
|
||||
}
|
||||
}
|
||||
|
||||
scr->pending_reload_state.erase(obj->get_instance_id()); //as it reloaded, remove pending state
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue