| 2579 | } |
| 2580 | |
| 2581 | void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload) { |
| 2582 | #ifdef DEBUG_ENABLED |
| 2583 | |
| 2584 | List<Ref<GDScript>> scripts; |
| 2585 | { |
| 2586 | MutexLock lock(mutex); |
| 2587 | |
| 2588 | SelfList<GDScript> *elem = script_list.first(); |
| 2589 | while (elem) { |
| 2590 | // Scripts will reload all subclasses, so only reload root scripts. |
| 2591 | if (elem->self()->is_root_script() && !elem->self()->get_path().is_empty()) { |
| 2592 | scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident |
| 2593 | } |
| 2594 | elem = elem->next(); |
| 2595 | } |
| 2596 | } |
| 2597 | |
| 2598 | //when someone asks you why dynamically typed languages are easier to write.... |
| 2599 | |
| 2600 | HashMap<Ref<GDScript>, HashMap<ObjectID, List<Pair<StringName, Variant>>>> to_reload; |
| 2601 | |
| 2602 | //as scripts are going to be reloaded, must proceed without locking here |
| 2603 | |
| 2604 | scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order |
| 2605 | |
| 2606 | for (Ref<GDScript> &scr : scripts) { |
| 2607 | bool reload = p_scripts.has(scr) || to_reload.has(scr->get_base()); |
| 2608 | |
| 2609 | if (!reload) { |
| 2610 | continue; |
| 2611 | } |
| 2612 | |
| 2613 | to_reload.insert(scr, HashMap<ObjectID, List<Pair<StringName, Variant>>>()); |
| 2614 | |
| 2615 | if (!p_soft_reload) { |
| 2616 | //save state and remove script from instances |
| 2617 | HashMap<ObjectID, List<Pair<StringName, Variant>>> &map = to_reload[scr]; |
| 2618 | |
| 2619 | while (scr->instances.front()) { |
| 2620 | Object *obj = scr->instances.front()->get(); |
| 2621 | //save instance info |
| 2622 | List<Pair<StringName, Variant>> state; |
| 2623 | if (obj->get_script_instance()) { |
| 2624 | obj->get_script_instance()->get_property_state(state); |
| 2625 | map[obj->get_instance_id()] = state; |
| 2626 | obj->set_script(Variant()); |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | //same thing for placeholders |
| 2631 | #ifdef TOOLS_ENABLED |
| 2632 | |
| 2633 | while (scr->placeholders.size()) { |
| 2634 | Object *obj = (*scr->placeholders.begin())->get_owner(); |
| 2635 | |
| 2636 | //save instance info |
| 2637 | if (obj->get_script_instance()) { |
| 2638 | map.insert(obj->get_instance_id(), List<Pair<StringName, Variant>>()); |
no test coverage detected