You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Fixed reloading of tool scripts within editor, they should work much better now, closes #3194
This commit is contained in:
@@ -1643,13 +1643,16 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
for(Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get()->pending_reload_state.front();F;F=F->next()) {
|
||||||
|
map[F->key()]=F->get(); //pending to reload, use this one instead
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Map< Ref<GDScript>, Map<ObjectID,List<Pair<StringName,Variant> > > >::Element *E=to_reload.front();E;E=E->next()) {
|
for(Map< Ref<GDScript>, Map<ObjectID,List<Pair<StringName,Variant> > > >::Element *E=to_reload.front();E;E=E->next()) {
|
||||||
|
|
||||||
Ref<GDScript> scr = E->key();
|
Ref<GDScript> scr = E->key();
|
||||||
scr->reload(true);
|
scr->reload(p_soft_reload);
|
||||||
|
|
||||||
//restore state if saved
|
//restore state if saved
|
||||||
for (Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get().front();F;F=F->next()) {
|
for (Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get().front();F;F=F->next()) {
|
||||||
@@ -1658,13 +1661,24 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof
|
|||||||
if (!obj)
|
if (!obj)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!p_soft_reload) {
|
||||||
|
//clear it just in case (may be a pending reload state)
|
||||||
|
obj->set_script(RefPtr());
|
||||||
|
}
|
||||||
obj->set_script(scr.get_ref_ptr());
|
obj->set_script(scr.get_ref_ptr());
|
||||||
if (!obj->get_script_instance())
|
if (!obj->get_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();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (List<Pair<StringName,Variant> >::Element *G=F->get().front();G;G=G->next()) {
|
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);
|
obj->get_script_instance()->set(G->get().first,G->get().second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scr->pending_reload_state.erase(obj->get_instance_ID()); //as it reloaded, remove pending state
|
||||||
}
|
}
|
||||||
|
|
||||||
//if instance states were saved, set them!
|
//if instance states were saved, set them!
|
||||||
|
|||||||
@@ -120,7 +120,11 @@ friend class GDScriptLanguage;
|
|||||||
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
|
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
|
||||||
|
Map<ObjectID,List<Pair<StringName,Variant> > > pending_reload_state;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
bool _update_exports();
|
bool _update_exports();
|
||||||
|
|
||||||
@@ -265,6 +269,8 @@ class GDScriptLanguage : public ScriptLanguage {
|
|||||||
|
|
||||||
Mutex *lock;
|
Mutex *lock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
friend class GDScript;
|
friend class GDScript;
|
||||||
|
|
||||||
SelfList<GDScript>::List script_list;
|
SelfList<GDScript>::List script_list;
|
||||||
|
|||||||
Reference in New Issue
Block a user