String ProjectSettings::localize_path(const String &p_path) const { if (resource_path == "") return p_path; //not initialized yet if (p_path.begins_with("res://") || p_path.begins_with("user://") || (p_path.is_abs_path() && !p_path.begins_with(resource_path))) return p_path.simplify_path(); DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String path = p_path.replace("\\", "/").simplify_path(); if (dir->change_dir(path) == OK) { String cwd = dir->get_current_dir(); cwd = cwd.replace("\\", "/"); memdelete(dir); if (!cwd.begins_with(resource_path)) { return p_path; }; return cwd.replace_first(resource_path, "res:/"); } else { memdelete(dir); int sep = path.find_last("/"); if (sep == -1) { return "res://" + path; }; String parent = path.substr(0, sep); String plocal = localize_path(parent); if (plocal == "") { return ""; }; return plocal + path.substr(sep, path.size() - sep); }; }
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "theme") { r_ret = get_theme(); } else if (name == "cell_size") { r_ret = get_cell_size(); } else if (name == "cell_octant_size") { r_ret = get_octant_size(); } else if (name == "cell_center_x") { r_ret = get_center_x(); } else if (name == "cell_center_y") { r_ret = get_center_y(); } else if (name == "cell_center_z") { r_ret = get_center_z(); } else if (name == "cell_scale") { r_ret = cell_scale; } else if (name == "data") { Dictionary d; PoolVector<int> cells; cells.resize(cell_map.size() * 3); { PoolVector<int>::Write w = cells.write(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } } d["cells"] = cells; r_ret = d; } else if (name.begins_with("areas/")) { int which = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "bounds") r_ret = area_get_bounds(which); else if (what == "name") r_ret = area_get_name(which); else if (what == "disable_distance") r_ret = area_get_portal_disable_distance(which); else if (what == "exterior_portal") r_ret = area_is_exterior_portal(which); else return false; } else return false; return true; }
String DirAccess::fix_path(String p_path) const { switch(_access_type) { case ACCESS_RESOURCES: { if (GlobalConfig::get_singleton()) { if (p_path.begins_with("res://")) { String resource_path = GlobalConfig::get_singleton()->get_resource_path(); if (resource_path != "") { return p_path.replace_first("res:/",resource_path); }; return p_path.replace_first("res://", ""); } } } break; case ACCESS_USERDATA: { if (p_path.begins_with("user://")) { String data_dir=OS::get_singleton()->get_data_dir(); if (data_dir != "") { return p_path.replace_first("user:/",data_dir); }; return p_path.replace_first("user://", ""); } } break; case ACCESS_FILESYSTEM: { return p_path; } break; } return p_path; }
int DirAccess::get_current_drive() { String path = get_current_dir().to_lower(); for(int i=0;i<get_drive_count();i++) { String d = get_drive(i).to_lower(); if (path.begins_with(d)) return i; } return 0; }
Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) { ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA); String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n"; if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) { // Don't append the standard ports request += "Host: " + conn_host + "\r\n"; } else { request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n"; } bool add_uagent = true; bool add_accept = true; bool add_clen = p_body.length() > 0; for (int i = 0; i < p_headers.size(); i++) { request += p_headers[i] + "\r\n"; if (add_clen && p_headers[i].findn("Content-Length:") == 0) { add_clen = false; } if (add_uagent && p_headers[i].findn("User-Agent:") == 0) { add_uagent = false; } if (add_accept && p_headers[i].findn("Accept:") == 0) { add_accept = false; } } if (add_clen) { request += "Content-Length: " + itos(p_body.utf8().length()) + "\r\n"; // Should it add utf8 encoding? } if (add_uagent) { request += "User-Agent: GodotEngine/" + String(VERSION_FULL_BUILD) + " (" + OS::get_singleton()->get_name() + ")\r\n"; } if (add_accept) { request += "Accept: */*\r\n"; } request += "\r\n"; request += p_body; CharString cs = request.utf8(); Error err = connection->put_data((const uint8_t *)cs.ptr(), cs.length()); if (err) { close(); status = STATUS_CONNECTION_ERROR; return err; } status = STATUS_REQUESTING; return OK; }
String DirAccess::fix_path(String p_path) const { switch (_access_type) { case ACCESS_RESOURCES: { if (ProjectSettings::get_singleton()) { if (p_path.begins_with("res://")) { String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { return p_path.replace_first("res:/", resource_path); }; return p_path.replace_first("res://", ""); } } } break; case ACCESS_USERDATA: { if (p_path.begins_with("user://")) { String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { return p_path.replace_first("user:/", data_dir); }; return p_path.replace_first("user://", ""); } } break; case ACCESS_FILESYSTEM: { return p_path; } break; case ACCESS_MAX: break; // Can't happen, but silences warning } return p_path; }
bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "playback/play") { // bw compatibility r_ret = get_current_animation(); } else if (name.begins_with("anims/")) { String which = name.get_slicec('/', 1); r_ret = get_animation(which).get_ref_ptr(); } else if (name.begins_with("next/")) { String which = name.get_slicec('/', 1); r_ret = animation_get_next(which); } else if (name == "blend_times") { Vector<BlendKey> keys; for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) { keys.ordered_insert(E->key()); } Array array; for (int i = 0; i < keys.size(); i++) { array.push_back(keys[i].from); array.push_back(keys[i].to); array.push_back(blend_times[keys[i]]); } r_ret = array; } else return false; return true; }
void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) { Object *obj = ObjectDB::get_instance(p_id); if (!obj) return; String prop_name = p_property; if (p_property.begins_with("Members/")) prop_name = p_property.substr(8, p_property.length()); obj->set(prop_name, p_value); }
String ProjectSettings::globalize_path(const String &p_path) const { if (p_path.begins_with("res://")) { if (resource_path != "") { return p_path.replace("res:/", resource_path); }; return p_path.replace("res://", ""); } else if (p_path.begins_with("user://")) { String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { return p_path.replace("user:/", data_dir); }; return p_path.replace("user://", ""); } return p_path; }
bool GDNativeLibrary::_get(const StringName &p_name, Variant &r_property) const { String name = p_name; if (name.begins_with("entry/")) { String key = name.substr(6, name.length() - 6); r_property = config_file->get_value("entry", key); return true; } if (name.begins_with("dependency/")) { String key = name.substr(11, name.length() - 11); r_property = config_file->get_value("dependencies", key); return true; } return false; }
void SpinBox::_text_entered(const String &p_string) { /* if (!p_string.is_numeric()) return; */ String value = p_string; if (prefix != "" && p_string.begins_with(prefix)) value = p_string.substr(prefix.length(), p_string.length() - prefix.length()); set_value(value.to_double()); _value_changed(0); }
bool _get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name.begins_with("bind/")) { int which = name.get_slice("/", 1).to_int() - 1; ERR_FAIL_INDEX_V(which, params.size(), false); r_ret = params[which]; } else return false; return true; }
bool _set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("bind/")) { int which = name.get_slice("/", 1).to_int() - 1; ERR_FAIL_INDEX_V(which, params.size(), false); params.write[which] = p_value; } else return false; return true; }
String Globals::globalize_path(const String& p_path) const { if (p_path.begins_with("res://")) { if (resource_path != "") { return p_path.replace("res:/",resource_path); }; return p_path.replace("res://", ""); }; return p_path; }
Error DirAccessJAndroid::change_dir(String p_dir){ JNIEnv *env = ThreadAndroid::get_env(); p_dir=p_dir.simplify_path(); if (p_dir=="" || p_dir=="." || (p_dir==".." && current_dir=="")) return OK; String new_dir; if (p_dir!="res://" && p_dir.length()>1 && p_dir.ends_with("/")) p_dir=p_dir.substr(0,p_dir.length()-1); if (p_dir.begins_with("/")) new_dir=p_dir.substr(1,p_dir.length()); else if (p_dir.begins_with("res://")) new_dir=p_dir.substr(6,p_dir.length()); else if (current_dir=="") new_dir=p_dir; else new_dir=current_dir.plus_file(p_dir); //print_line("new dir is: "+new_dir); //test if newdir exists new_dir=new_dir.simplify_path(); jstring js = env->NewStringUTF(new_dir.utf8().get_data()); int res = env->CallIntMethod(io,_dir_open,js); env->DeleteLocalRef(js); if (res<=0) return ERR_INVALID_PARAMETER; env->CallObjectMethod(io,_dir_close,res); current_dir=new_dir; return OK; }
bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("playback/play")) { // bw compatibility set_current_animation(p_value); } else if (name.begins_with("anims/")) { String which = name.get_slicec('/', 1); add_animation(which, p_value); } else if (name.begins_with("next/")) { String which = name.get_slicec('/', 1); animation_set_next(which, p_value); } else if (p_name == SceneStringNames::get_singleton()->blend_times) { Array array = p_value; int len = array.size(); ERR_FAIL_COND_V(len % 3, false); for (int i = 0; i < len / 3; i++) { StringName from = array[i * 3 + 0]; StringName to = array[i * 3 + 1]; float time = array[i * 3 + 2]; set_blend_time(from, to, time); } } else return false; return true; }
void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) { Object *obj = ObjectDB::get_instance(p_id); if (!obj) return; String prop_name = p_property; if (p_property.begins_with("Members/")) { Vector<String> ss = p_property.split("/"); prop_name = ss[ss.size() - 1]; } obj->set(prop_name, p_value); }
EditorFileSystemDirectory *EditorFileSystem::get_path(const String& p_path) { if (!filesystem || scanning) return NULL; String f = Globals::get_singleton()->localize_path(p_path); if (!f.begins_with("res://")) return NULL; f=f.substr(6,f.length()); f=f.replace("\\","/"); if (f==String()) return filesystem; if (f.ends_with("/")) f=f.substr(0,f.length()-1); Vector<String> path = f.split("/"); if (path.size()==0) return NULL; EditorFileSystemDirectory *fs=filesystem; for(int i=0;i<path.size();i++) { int idx=-1; for(int j=0;j<fs->get_subdir_count();j++) { if (fs->get_subdir(j)->get_name()==path[i]) { idx=j; break; } } if (idx==-1) { return NULL; } else { fs=fs->get_subdir(idx); } } return fs; }
bool test_27() { OS::get_singleton()->print("\n\nTest 27: begins_with\n"); test_27_data tc[] = { {"res://foobar", "res://", true}, {"res", "res://", false}, {"abc", "abc", true} }; size_t count = sizeof(tc) / sizeof(tc[0]); bool state = true; for (size_t i = 0;state && i < count; ++i) { String s = tc[i].data; state = s.begins_with(tc[i].begin) == tc[i].expected; if (state) { String sb = tc[i].begin; state = s.begins_with(sb) == tc[i].expected; } if (!state) { OS::get_singleton()->print("\n\t Failure on:\n\t\tstring: ", tc[i].data, "\n\t\tbegin: ", tc[i].begin, "\n\t\texpected: ", tc[i].expected ? "true" : "false", "\n"); break; } }; return state; };
bool Skeleton::_set(const StringName& p_path, const Variant& p_value) { String path = p_path; if (!path.begins_with("bones/")) return false; int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); if (which==bones.size() && what=="name") { add_bone(p_value); return true; } ERR_FAIL_INDEX_V( which, bones.size(), false ); if (what=="parent") set_bone_parent(which, p_value ); else if (what=="rest") set_bone_rest(which, p_value); else if (what=="enabled") set_bone_enabled(which, p_value); else if (what=="pose") set_bone_pose(which, p_value); else if (what=="bound_childs") { Array children=p_value; if (is_inside_tree()) { bones[which].nodes_bound.clear(); for (int i=0;i<children.size();i++) { NodePath path=children[i]; ERR_CONTINUE( path.operator String()=="" ); Node *node = get_node(path); ERR_CONTINUE(!node); bind_child_node_to_bone(which,node); } } } else { return false; } return true; }
String DirAccessWindows::get_current_dir() { String base = _get_root_path(); if (base != "") { String bd = current_dir.replace("\\", "/").replace_first(base, ""); if (bd.begins_with("/")) return _get_root_string() + bd.substr(1, bd.length()); else return _get_root_string() + bd; } else { } return current_dir; }
bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) { if (p_name==SceneStringNames::get_singleton()->shader_shader) { set_shader(p_value); return true; } else { String n = p_name; if (n.begins_with("param/")) { VisualServer::get_singleton()->material_set_param(material,String(n.ptr()+6),p_value); return true; } } return false; }
bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) { String n = String(p_name); if (n.begins_with("button/")) { String what = n.get_slicec('/', 1); if (what == "count") { int new_size = p_value; if (new_size > 0 && buttons.size() == 0) { selected = 0; } if (new_size < buttons.size()) { if (selected >= new_size) selected = new_size - 1; } buttons.resize(new_size); _change_notify(); minimum_size_changed(); } else if (what == "align") { set_align(Align(p_value.operator int())); } else if (what == "selected") { set_selected(p_value); } else if (what == "min_button_size") { min_button_size = p_value; } else { int idx = what.to_int(); ERR_FAIL_INDEX_V(idx, buttons.size(), false); String f = n.get_slicec('/', 2); if (f == "text") { buttons[idx].text = p_value; buttons[idx].xl_text = XL_MESSAGE(p_value); } else if (f == "tooltip") buttons[idx].tooltip = p_value; else if (f == "icon") buttons[idx].icon = p_value; else return false; } update(); return true; } return false; }
void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) { Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); if (!f) return; VariantParser::StreamFile stream; stream.f = f; String assign; Variant value; VariantParser::Tag next_tag; int lines = 0; String error_text; while (true) { assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); if (err == ERR_FILE_EOF) { memdelete(f); return; } else if (err != OK) { ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text); memdelete(f); return; } if (assign != String()) { if (assign.begins_with("path.")) { r_paths->push_back(value); } else if (assign == "path") { r_paths->push_back(value); } } else if (next_tag.name != "remap") { break; } } memdelete(f); }
void EditorAutoloadSettings::_autoload_add() { String name = autoload_add_name->get_text(); String error; if (!_autoload_name_is_valid(name, &error)) { EditorNode::get_singleton()->show_warning(error); return; } String path = autoload_add_path->get_line_edit()->get_text(); if (!FileAccess::exists(path)) { EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist.")); return; } if (!path.begins_with("res://")) { EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n"+ TTR("Not in resource path.")); return; } name = "autoload/" + name; UndoRedo* undo_redo = EditorNode::get_singleton()->get_undo_redo(); undo_redo->create_action(TTR("Add AutoLoad")); undo_redo->add_do_property(GlobalConfig::get_singleton(), name, "*" + path); if (GlobalConfig::get_singleton()->has(name)) { undo_redo->add_undo_property(GlobalConfig::get_singleton(), name, GlobalConfig::get_singleton()->get(name)); } else { undo_redo->add_undo_property(GlobalConfig::get_singleton(), name, Variant()); } undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); undo_redo->add_do_method(this, "emit_signal", autoload_changed); undo_redo->add_undo_method(this, "emit_signal", autoload_changed); undo_redo->commit_action(); autoload_add_path->get_line_edit()->set_text(""); autoload_add_name->set_text(""); }
void EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_path) { String name = p_name; String error; if (!_autoload_name_is_valid(name, &error)) { EditorNode::get_singleton()->show_warning(error); return; } String path = p_path; if (!FileAccess::exists(path)) { EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist.")); return; } if (!path.begins_with("res://")) { EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("Not in resource path.")); return; } name = "autoload/" + name; UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); undo_redo->create_action(TTR("Add AutoLoad")); // Singleton autoloads are represented with a leading "*" in their path. undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path); if (ProjectSettings::get_singleton()->has_setting(name)) { undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name)); } else { undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant()); } undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); undo_redo->add_do_method(this, "emit_signal", autoload_changed); undo_redo->add_undo_method(this, "emit_signal", autoload_changed); undo_redo->commit_action(); }
bool CollisionObject2D::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name.begins_with("shapes/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "shape") r_ret = get_shape(idx); else if (what == "transform") r_ret = get_shape_transform(idx); else if (what == "trigger") r_ret = is_shape_set_as_trigger(idx); } else return false; return true; }
bool ShaderMaterial::_get(const StringName& p_name,Variant &r_ret) const { if (p_name==SceneStringNames::get_singleton()->shader_shader) { r_ret=get_shader(); return true; } else { String n = p_name; if (n.begins_with("param/")) { r_ret=VisualServer::get_singleton()->material_get_param(material,String(n.ptr()+6)); return true; } } return false; }
bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { String path = p_path; if (!path.begins_with("bones/")) return false; int which = path.get_slicec('/', 1).to_int(); String what = path.get_slicec('/', 2); ERR_FAIL_INDEX_V(which, bones.size(), false); if (what == "name") r_ret = get_bone_name(which); else if (what == "parent") r_ret = get_bone_parent(which); else if (what == "rest") r_ret = get_bone_rest(which); else if (what == "enabled") r_ret = is_bone_enabled(which); else if (what == "pose") r_ret = get_bone_pose(which); else if (what == "bound_children") { Array children; for (const List<uint32_t>::Element *E = bones[which].nodes_bound.front(); E; E = E->next()) { Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); Node *node = Object::cast_to<Node>(obj); ERR_CONTINUE(!node); NodePath path = get_path_to(node); children.push_back(path); } r_ret = children; } else return false; return true; }
bool CollisionObject2D::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("shapes/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "shape") { if (idx >= shapes.size()) add_shape(RefPtr(p_value)); else set_shape(idx, RefPtr(p_value)); } else if (what == "transform") set_shape_transform(idx, p_value); else if (what == "trigger") set_shape_as_trigger(idx, p_value); } else return false; return true; }