void MainLoop::init() { if (init_script.is_valid()) set_script(init_script.get_ref_ptr()); if (get_script_instance()) get_script_instance()->call("_initialize"); }
String EditorPlugin::get_name() const { if (get_script_instance() && get_script_instance()->has_method("get_name")) { return get_script_instance()->call("get_name"); } return String(); }
void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) { StringArray arr = get_script_instance()->call("get_breakpoints"); for(int i=0;i<arr.size();i++) p_breakpoints->push_back(arr[i]); } }
bool EditorPlugin::has_main_screen() const { if (get_script_instance() && get_script_instance()->has_method("has_main_screen")) { return get_script_instance()->call("has_main_screen"); } return false; }
void MainLoop::finish() { if (get_script_instance()) { get_script_instance()->call("_finalize"); set_script(RefPtr()); //clear script } }
void Node::_propagate_enter_tree() { // this needs to happen to all childs before any enter_tree if (data.parent) { data.tree=data.parent->data.tree; data.depth=data.parent->data.depth+1; } else { data.depth=1; } data.viewport = cast_to<Viewport>(); if (!data.viewport) data.viewport = data.parent->data.viewport; data.inside_tree=true; const StringName *K=NULL; while ((K=data.grouped.next(K))) { data.tree->add_to_group(*K,this); } notification(NOTIFICATION_ENTER_TREE); if (get_script_instance()) { Variant::CallError err; get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree,NULL,0); } emit_signal(SceneStringNames::get_singleton()->enter_tree); data.blocked++; //block while adding children for (int i=0;i<data.children.size();i++) { if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree data.children[i]->_propagate_enter_tree(); } data.blocked--; #ifdef DEBUG_ENABLED if (ScriptDebugger::get_singleton() && data.filename!=String()) { //used for live edit data.tree->live_scene_edit_cache[data.filename].insert(this); } #endif // enter groups }
bool Reference::unreference() { bool die = refcount.unref(); if (get_script_instance()) { die = die && get_script_instance()->refcount_decremented(); } return die; }
void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { if (get_script_instance()) { Array parameters = get_script_instance()->call("get_parameter_list"); for (int i = 0; i < parameters.size(); i++) { Dictionary d = parameters[i]; ERR_CONTINUE(d.empty()); r_list->push_back(PropertyInfo::from_dict(d)); } } }
Rect2 Node2D::get_item_rect() const { if (get_script_instance()) { Variant::CallError err; Rect2 r = get_script_instance()->call("_get_item_rect",NULL,0,err); if (err.error==Variant::CallError::CALL_OK) return r; } return Rect2(Point2(-32,-32),Size2(64,64)); }
void EditorImportPlugin::import_dialog(const String& p_from) { if (get_script_instance() && get_script_instance()->has_method("import_dialog")) { get_script_instance()->call("import_dialog",p_from); return; } ERR_FAIL(); }
Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 p_size) const { if (get_script_instance() && get_script_instance()->has_method("generate_from_path")) { return get_script_instance()->call("generate_from_path", p_path, p_size); } RES res = ResourceLoader::load(p_path); if (!res.is_valid()) return res; return generate(res, p_size); }
void AnimController::remove_status_with(const String& p_key, const String& p_name) { if (current_anims.has(p_key) && current_anims[p_key] == p_name) { remove_anim(p_key, p_name); if (remove_counts.has(p_key)) { remove_counts.erase(p_key); } current_anims.erase(p_key); _changed = true; if (get_script_instance()) { get_script_instance()->call(StringName("_remove_status"), p_key, p_name); } } }
void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const { if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { PoolStringArray exts = get_script_instance()->call("get_recognized_extensions"); { PoolStringArray::Read r = exts.read(); for (int i = 0; i < exts.size(); ++i) { p_extensions->push_back(r[i]); } } } }
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) { PoolStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types); { PoolStringArray::Read r = deps.read(); for (int i = 0; i < deps.size(); ++i) { p_dependencies->push_back(r[i]); } } } }
void AnimController::remove_status(String p_key) { if (current_anims.has(p_key)) { String name = current_anims[p_key]; remove_anim(p_key, name); if (remove_counts.has(p_key)) { remove_counts.erase(p_key); } current_anims.erase(p_key); _changed = true; if (get_script_instance()) { get_script_instance()->call(StringName("_remove_status"), p_key, name); } } }
void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { if (get_script_instance()) { Dictionary cn = get_script_instance()->call("get_child_nodes"); List<Variant> keys; cn.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { ChildNode child; child.name = E->get(); child.node = cn[E->get()]; r_child_nodes->push_back(child); } } }
Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) { Dictionary deps_dict; for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) { deps_dict[E->key()] = E->value(); } int64_t res = get_script_instance()->call("rename_dependencies", deps_dict); return (Error)res; } return OK; }
void AnimController::remove_all() { HashMap<String, String> cp = current_anims; if (current_anims.size() != 0) { current_anims.clear(); _changed = true; } bool has_instance = get_script_instance() != NULL; const String *k = NULL; while ((k = cp.next(k))) { const String &name = cp[*k]; remove_anim(*k, name); if (has_instance) get_script_instance()->call(StringName("_remove_status"), *k, cp[*k]); } }
void Node::_propagate_enter_scene() { // this needs to happen to all childs before any ENTER_SCENE if (data.parent) { data.scene=data.parent->data.scene; data.depth=data.parent->data.depth+1; } else { data.depth=1; } data.viewport = cast_to<Viewport>(); if (!data.viewport) data.viewport = data.parent->data.viewport; data.inside_scene=true; const StringName *K=NULL; while ((K=data.grouped.next(K))) { data.scene->add_to_group(*K,this); } notification(NOTIFICATION_ENTER_SCENE); if (get_script_instance()) { Variant::CallError err; get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_scene,NULL,0); } emit_signal(SceneStringNames::get_singleton()->enter_scene); data.blocked++; //block while adding children for (int i=0;i<data.children.size();i++) { if (!data.children[i]->is_inside_scene()) // could have been added in ENTER_SCENE data.children[i]->_propagate_enter_scene(); } data.blocked--; // enter groups }
void AnimController::set_status(String p_key, String p_name, float p_time) { if (!current_anims.has(p_key) || current_anims[p_key] != p_name) { if (current_anims.has(p_key)) { remove_anim(p_key, current_anims[p_key]); } current_anims[p_key] = p_name; add_anim(p_key, p_name); if (p_time > 0) { remove_counts[p_key] = p_time; } _changed = true; if (get_script_instance()) { get_script_instance()->call(StringName("_add_status"), p_key, p_name); } } }
void EditorScript::_run() { Ref<Script> s = get_script(); ERR_FAIL_COND(!s.is_valid()); if (!get_script_instance()) { EditorNode::add_io_error(TTR("Couldn't instance script:") + "\n " + s->get_path() + "\n" + TTR("Did you forget the 'tool' keyword?")); return; } Variant::CallError ce; ce.error = Variant::CallError::CALL_OK; get_script_instance()->call("_run", NULL, 0, ce); if (ce.error != Variant::CallError::CALL_OK) { EditorNode::add_io_error(TTR("Couldn't run script:") + "\n " + s->get_path() + "\n" + TTR("Did you forget the '_run' method?")); } }
Variant::Type Object::get_static_property_type(const StringName &p_property, bool *r_valid) const { bool valid; Variant::Type t = ClassDB::get_property_type(get_class_name(), p_property, &valid); if (valid) { if (r_valid) *r_valid = true; return t; } if (get_script_instance()) { return get_script_instance()->get_property_type(p_property, r_valid); } if (r_valid) *r_valid = false; return Variant::NIL; }
Vector<uint8_t> EditorExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) { if (get_script_instance()) { Variant d = get_script_instance()->call("custom_export",p_path,p_platform); if (d.get_type()==Variant::NIL) return Vector<uint8_t>(); ERR_FAIL_COND_V(d.get_type()!=Variant::DICTIONARY,Vector<uint8_t>()); Dictionary dict=d; ERR_FAIL_COND_V(!dict.has("name"),Vector<uint8_t>()); ERR_FAIL_COND_V(!dict.has("data"),Vector<uint8_t>()); p_path=dict["name"]; return dict["data"]; } return Vector<uint8_t>(); }
bool Reference::reference() { bool success = refcount.ref(); if (success && refcount.get() <= 2 /* higher is not relevant */) { if (get_script_instance()) { get_script_instance()->refcount_incremented(); } if (instance_binding_count > 0) { for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { if (_script_instance_bindings[i]) { ScriptServer::get_language(i)->refcount_incremented_instance_binding(this); } } } } return success; }
void BehaviorNode::send_notify(const Variant& from, const StringName &key, const Variant& value) { _on_notify(from, key, value); if (get_script_instance()) { Variant v_key(key); const Variant* ptr[3]={&from, &v_key, &value}; get_script_instance()->call_multilevel(StringName("_on_notify"),ptr,3); } int count = get_child_count(); for (int i = 0; i < count; ++i) { Node *node = get_child(i); if (node) { BehaviorNode *bn = node->cast_to<BehaviorNode>(); if (bn) { bn->send_notify(from, key, value); } } } }
void HitStatus::step(Object *character, Dictionary env) { if (!started) { started = true; _start(character, env); if (get_script_instance()) { Variant v1 = Variant(character); Variant var_env = Variant(env); const Variant* ptr[2]={&v1,&var_env}; get_script_instance()->call_multilevel(StringName("_start"),ptr,2); } } _step(character, env); if (get_script_instance()) { Variant v1 = Variant(character); Variant var_env = Variant(env); const Variant* ptr[2]={&v1,&var_env}; get_script_instance()->call_multilevel(StringName("_step"),ptr,2); } }
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { if (get_script_instance() && get_script_instance()->has_method("load")) { Variant res = get_script_instance()->call("load", p_path, p_original_path); if (res.get_type() == Variant::INT) { if (r_error) *r_error = (Error)res.operator int64_t(); } else { if (r_error) *r_error = OK; return res; } } //or this must be implemented Ref<ResourceInteractiveLoader> ril = load_interactive(p_path, p_original_path, r_error); if (!ril.is_valid()) return RES(); ril->set_local_path(p_original_path); while (true) { Error err = ril->poll(); if (err == ERR_FILE_EOF) { if (r_error) *r_error = OK; return ril->get_resource(); } if (r_error) *r_error = err; ERR_FAIL_COND_V(err != OK, RES()); } return RES(); }
void Node::_propagate_exit_tree() { //block while removing children data.blocked++; for (int i=data.children.size()-1;i>=0;i--) { data.children[i]->_propagate_exit_tree(); } data.blocked--; if (get_script_instance()) { Variant::CallError err; get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree,NULL,0); } emit_signal(SceneStringNames::get_singleton()->exit_tree); notification(NOTIFICATION_EXIT_TREE,true); if (data.tree) data.tree->node_removed(this); // exit groups const StringName *K=NULL; while ((K=data.grouped.next(K))) { data.tree->remove_from_group(*K,this); } data.viewport = NULL; if (data.tree) data.tree->tree_changed(); data.inside_tree=false; data.tree=NULL; data.depth=-1; }
bool Reference::unreference() { bool die = refcount.unref(); if (refcount.get() <= 1 /* higher is not relevant */) { if (get_script_instance()) { bool script_ret = get_script_instance()->refcount_decremented(); die = die && script_ret; } if (instance_binding_count > 0) { for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { if (_script_instance_bindings[i]) { bool script_ret = ScriptServer::get_language(i)->refcount_decremented_instance_binding(this); die = die && script_ret; } } } } return die; }
void AttackNode::_during_behavior(const Variant &target, Dictionary &env) { bool is_hit = false; if (attack_area) { Character *from = ((Object*)target)->cast_to<Character>(); if (from) { bool hit = attack_area->attack(from); if (hit) { is_hit = true; if (get_script_instance()) { Variant var_env = Variant(env); const Variant* ptr[2]={&target,&var_env}; get_script_instance()->call_multilevel(StringName("_on_attack"),ptr,2); } } } } Action::_during_behavior(target, env); if (is_hit) { set_hit(is_hit); } }