Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings, int &line, String &r_err_str) { Token token; get_token(p_stream,token,line,r_err_str); if (token.type!=TK_PARENTHESIS_OPEN) { r_err_str="Expected '(' in old-style engine.cfg construct"; return ERR_PARSE_ERROR; } String accum; while(true) { CharType c=p_stream->get_char(); if (p_stream->is_eof()) { r_err_str="Unexpected EOF while parsing old-style engine.cfg construct"; return ERR_PARSE_ERROR; } if (c==',') { strings.push_back(accum.strip_edges()); accum=String(); } else if (c==')') { strings.push_back(accum.strip_edges()); return OK; } else if (c=='\n') { line++; } } return OK; }
void TranslationServer::setup() { String test = GLOBAL_DEF("locale/test",""); test=test.strip_edges(); if (test!="") set_locale( test ); else set_locale( OS::get_singleton()->get_locale() ); fallback = GLOBAL_DEF("locale/fallback","en"); #ifdef TOOLS_ENABLED { String options=""; int idx=0; while(locale_list[idx]) { if (idx>0) options+=", "; options+=locale_list[idx]; idx++; } Globals::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options)); } #endif //load translations }
void GroupsEditor::_add_group(const String& p_group) { if (!node) return; String name = group_name->get_text(); if (name.strip_edges()=="") return; if (node->is_in_group(name)) return; undo_redo->create_action(TTR("Add to Group")); undo_redo->add_do_method(node,"add_to_group",name,true); undo_redo->add_do_method(this,"update_tree"); undo_redo->add_undo_method(node,"remove_from_group",name); undo_redo->add_undo_method(this,"update_tree"); undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(),"update_tree"); //to force redraw of scene tree undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(),"update_tree"); //to force redraw of scene tree undo_redo->commit_action(); group_name->clear(); }
String OS_X11::get_system_dir(SystemDir p_dir) const { String xdgparam; switch(p_dir) { case SYSTEM_DIR_DESKTOP: { xdgparam="DESKTOP"; } break; case SYSTEM_DIR_DCIM: { xdgparam="PICTURES"; } break; case SYSTEM_DIR_DOCUMENTS: { xdgparam="DOCUMENTS"; } break; case SYSTEM_DIR_DOWNLOADS: { xdgparam="DOWNLOAD"; } break; case SYSTEM_DIR_MOVIES: { xdgparam="VIDEOS"; } break; case SYSTEM_DIR_MUSIC: { xdgparam="MUSIC"; } break; case SYSTEM_DIR_PICTURES: { xdgparam="PICTURES"; } break; case SYSTEM_DIR_RINGTONES: { xdgparam="MUSIC"; } break; } String pipe; List<String> arg; arg.push_back(xdgparam); Error err = const_cast<OS_X11*>(this)->execute("/usr/bin/xdg-user-dir",arg,true,NULL,&pipe); if (err!=OK) return "."; return pipe.strip_edges(); }
void ScriptEditor::edit(const Ref<Script>& p_script) { if (p_script.is_null()) return; // see if already has it if (p_script->get_path().is_resource_file() && bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor"))) { String path = EditorSettings::get_singleton()->get("external_editor/exec_path"); String flags = EditorSettings::get_singleton()->get("external_editor/exec_flags"); List<String> args; flags=flags.strip_edges(); if (flags!=String()) { Vector<String> flagss = flags.split(" ",false); for(int i=0;i<flagss.size();i++) args.push_back(flagss[i]); } args.push_back(Globals::get_singleton()->globalize_path(p_script->get_path())); Error err = OS::get_singleton()->execute(path,args,false); if (err==OK) return; WARN_PRINT("Couldn't open external text editor, using internal"); } for(int i=0;i<tab_container->get_child_count();i++) { ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>(); if (!ste) continue; if (ste->get_edited_script()==p_script) { if (tab_container->get_current_tab()!=i) tab_container->set_current_tab(i); ste->get_text_edit()->grab_focus(); return; } } // doesn't have it, make a new one ScriptTextEditor *ste = memnew( ScriptTextEditor ); ste->set_edited_script(p_script); ste->get_text_edit()->set_tooltip_request_func(this,"_get_debug_tooltip",ste); tab_container->add_child(ste); tab_container->set_current_tab(tab_container->get_tab_count()-1); _update_window_menu(); _save_files_state(); }
void GroupDialog::_add_group(String p_name) { String name = p_name.strip_edges(); if (name == "" || groups->search_item_text(name)) { return; } TreeItem *new_group = groups->create_item(groups_root); new_group->set_text(0, name); new_group->add_button(0, get_icon("Remove", "EditorIcons"), 0); new_group->set_editable(0, true); }
Error EditorSceneImporterFBXConv::_parse_fbx(State& state,const String& p_path) { state.base_path=p_path.get_base_dir(); if (p_path.to_lower().ends_with("g3dj")) { return _parse_json(state,p_path.basename()+".g3dj"); } String tool = EDITOR_DEF("fbxconv/path",""); ERR_FAIL_COND_V( !FileAccess::exists(tool),ERR_UNCONFIGURED); String wine = EDITOR_DEF("fbxconv/use_wine",""); List<String> args; String path=p_path; if (wine!="") { List<String> wpargs; wpargs.push_back("-w"); wpargs.push_back(p_path); String pipe; //winepath to convert to windows path int wpres; Error wperr = OS::get_singleton()->execute(wine+"path",wpargs,true,NULL,&pipe,&wpres); ERR_FAIL_COND_V(wperr!=OK,ERR_CANT_CREATE); ERR_FAIL_COND_V(wpres!=0,ERR_CANT_CREATE); path=pipe.strip_edges(); args.push_back(tool); tool=wine; } args.push_back("-o"); args.push_back(TTR("G3DJ")); args.push_back(path); int res; Error err = OS::get_singleton()->execute(tool,args,true,NULL,NULL,&res); ERR_FAIL_COND_V(err!=OK,ERR_CANT_CREATE); ERR_FAIL_COND_V(res!=0,ERR_CANT_CREATE); return _parse_json(state,p_path.basename()+".g3dj"); }
RES ResourceFormatLoaderShader::load(const String &p_path, const String& p_original_path, Error *r_error) { if (r_error) *r_error=ERR_FILE_CANT_OPEN; String fragment_code; String vertex_code; String light_code; int mode=-1; Error err; FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); ERR_EXPLAIN("Unable to open shader file: "+p_path); ERR_FAIL_COND_V(err,RES()); String base_path = p_path.get_base_dir(); if (r_error) *r_error=ERR_FILE_CORRUPT; Ref<Shader> shader;//( memnew( Shader ) ); int line=0; while(!f->eof_reached()) { String l = f->get_line(); line++; if (mode<=0) { l = l.strip_edges(); int comment = l.find(";"); if (comment!=-1) l=l.substr(0,comment); } if (mode<1) vertex_code+="\n"; if (mode<2) fragment_code+="\n"; if (mode < 1 && l=="") continue; if (l.begins_with("[")) { l=l.strip_edges(); if (l=="[params]") { if (mode>=0) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [params] section."); ERR_FAIL_V(RES()); } mode=0; } else if (l=="[vertex]") { if (mode>=1) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [vertex] section."); ERR_FAIL_V(RES()); } mode=1; } else if (l=="[fragment]") { if (mode>=2) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [fragment] section."); ERR_FAIL_V(RES()); } mode=1; } else { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Unknown section type: '"+l+"'."); ERR_FAIL_V(RES()); } continue; } if (mode==0) { int eqpos = l.find("="); if (eqpos==-1) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Expected '='."); ERR_FAIL_V(RES()); } String right=l.substr(eqpos+1,l.length()).strip_edges(); if (right=="") { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Expected value after '='."); ERR_FAIL_V(RES()); } Variant value; if (right=="true") { value = true; } else if (right=="false") { value = false; } else if (right.is_valid_float()) { //is number value = right.to_double(); } else if (right.is_valid_html_color()) { //is html color value = Color::html(right); } else { //attempt to parse a constructor int popenpos = right.find("("); if (popenpos==-1) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor syntax: "+right); ERR_FAIL_V(RES()); } int pclosepos = right.find_last(")"); if (pclosepos==-1) { ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor parameter syntax: "+right); ERR_FAIL_V(RES()); } String type = right.substr(0,popenpos); String param = right.substr(popenpos+1,pclosepos-popenpos-1).strip_edges(); if (type=="tex") { if (param=="") { value=RID(); } else { String path; if (param.is_abs_path()) path=param; else path=base_path+"/"+param; Ref<Texture> texture = ResourceLoader::load(path); if (!texture.is_valid()) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Couldn't find icon at path: "+path); ERR_FAIL_V(RES()); } value=texture; } } else if (type=="vec3") { if (param=="") { value=Vector3(); } else { Vector<String> params = param.split(","); if (params.size()!=3) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid param count for vec3(): '"+right+"'."); ERR_FAIL_V(RES()); } Vector3 v; for(int i=0;i<3;i++) v[i]=params[i].to_double(); value=v; } } else if (type=="xform") { if (param=="") { value=Transform(); } else { Vector<String> params = param.split(","); if (params.size()!=12) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid param count for xform(): '"+right+"'."); ERR_FAIL_V(RES()); } Transform t; for(int i=0;i<9;i++) t.basis[i%3][i/3]=params[i].to_double(); for(int i=0;i<3;i++) t.origin[i]=params[i-9].to_double(); value=t; } } else { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor type: '"+type+"'."); ERR_FAIL_V(RES()); } } String left= l.substr(0,eqpos); // shader->set_param(left,value); } else if (mode==1) { vertex_code+=l; } else if (mode==2) { fragment_code+=l; } } shader->set_code(vertex_code,fragment_code,light_code); f->close(); memdelete(f); if (r_error) *r_error=OK; return shader; }
static void _compress_image(Image::CompressMode p_mode, Image *p_image) { String ttpath = EditorSettings::get_singleton()->get("filesystem/import/pvrtc_texture_tool"); if (ttpath.strip_edges() == "" || !FileAccess::exists(ttpath)) { switch (p_mode) { case Image::COMPRESS_PVRTC2: if (_base_image_compress_pvrtc2_func) _base_image_compress_pvrtc2_func(p_image); else if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); break; case Image::COMPRESS_PVRTC4: if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); break; default: ERR_FAIL(); } return; } String tmppath = EditorSettings::get_singleton()->get_cache_dir(); List<String> args; String src_img = tmppath.plus_file("_tmp_src_img.png"); String dst_img = tmppath.plus_file("_tmp_dst_img.pvr"); args.push_back("-i"); args.push_back(src_img); args.push_back("-o"); args.push_back(dst_img); args.push_back("-f"); switch (p_mode) { case Image::COMPRESS_PVRTC2: args.push_back("PVRTC2"); break; case Image::COMPRESS_PVRTC4: args.push_back("PVRTC4"); break; case Image::COMPRESS_ETC: args.push_back("ETC"); break; default: ERR_FAIL(); } if (EditorSettings::get_singleton()->get("filesystem/import/pvrtc_fast_conversion").operator bool()) { args.push_back("-pvrtcfast"); } if (p_image->has_mipmaps()) args.push_back("-m"); Ref<ImageTexture> t = memnew(ImageTexture); t->create_from_image(Ref<Image>(p_image), 0); ResourceSaver::save(src_img, t); Error err = OS::get_singleton()->execute(ttpath, args, true); ERR_EXPLAIN(TTR("Could not execute PVRTC tool:") + " " + ttpath); ERR_FAIL_COND(err != OK); t = ResourceLoader::load(dst_img, "Texture"); ERR_EXPLAIN(TTR("Can't load back converted image using PVRTC tool:") + " " + dst_img); ERR_FAIL_COND(t.is_null()); p_image->copy_internals_from(t->get_data()); }
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) { String l = f->get_line(); enum Status { STATUS_NONE, STATUS_READING_ID, STATUS_READING_STRING, }; Status status=STATUS_NONE; String msg_id; String msg_str; String config; int msg_line=0; if (r_error) *r_error=ERR_FILE_CORRUPT; Ref<Translation> translation = Ref<Translation>( memnew( Translation )); int line = 1; while(true) { String l = f->get_line(); if (f->eof_reached()) { if ( status == STATUS_READING_STRING) { if (msg_id!="") translation->add_message(msg_id,msg_str); else if (config=="") config=msg_str; break; } else if ( status==STATUS_NONE) break; memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+" Unexpected EOF while reading 'msgid' at file: "); ERR_FAIL_V(RES()); } l=l.strip_edges(); if (l.begins_with("msgid")) { if (status==STATUS_READING_ID) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+" Unexpected 'msgid', was expecting 'msgstr' while parsing: "); ERR_FAIL_V(RES()); } if (msg_id!="") translation->add_message(msg_id,msg_str); else if (config=="") config=msg_str; l=l.substr(5,l.length()).strip_edges(); status=STATUS_READING_ID; msg_id=""; msg_str=""; msg_line=line; } if (l.begins_with("msgstr")) { if (status!=STATUS_READING_ID) { memdelete(f); ERR_EXPLAIN(p_path+":"+itos(line)+" Unexpected 'msgstr', was expecting 'msgid' while parsing: "); ERR_FAIL_V(RES()); } l=l.substr(6,l.length()).strip_edges(); status=STATUS_READING_STRING; msg_line=line; } if (l=="" || l.begins_with("#")) { line++; continue; //nothing to read or comment } if (!l.begins_with("\"") || status==STATUS_NONE) { //not a string? failure! ERR_EXPLAIN(p_path+":"+itos(line)+" Invalid line '"+l+"' while parsing: "); ERR_FAIL_V(RES()); } l=l.substr(1,l.length()); //find final quote int end_pos=-1; for(int i=0; i<l.length(); i++) { if (l[i]=='"' && (i==0 || l[i-1]!='\\')) { end_pos=i; break; } } if (end_pos==-1) { ERR_EXPLAIN(p_path+":"+itos(line)+" Expected '\"' at end of message while parsing file: "); ERR_FAIL_V(RES()); } l=l.substr(0,end_pos); l=l.c_unescape(); if (status==STATUS_READING_ID) msg_id+=l; else msg_str+=l; line++; } f->close(); memdelete(f); if (config=="") { ERR_EXPLAIN("No config found in file: "+p_path); ERR_FAIL_V(RES()); } Vector<String> configs = config.split("\n"); for(int i=0; i<configs.size(); i++) { String c = configs[i].strip_edges(); int p = c.find(":"); if (p==-1) continue; String prop = c.substr(0,p).strip_edges(); String value = c.substr(p+1,c.length()).strip_edges(); if (prop=="X-Language") { translation->set_locale(value); } } if (r_error) *r_error=OK; return translation; }
static void _initialize_java_modules() { if (!GlobalConfig::get_singleton()->has("android/modules")) { print_line("ANDROID MODULES: Nothing to load, aborting"); return; } String modules = GlobalConfig::get_singleton()->get("android/modules"); modules = modules.strip_edges(); if (modules == String()) { return; } Vector<String> mods = modules.split(",", false); print_line("ANDROID MODULES : " + modules); __android_log_print(ANDROID_LOG_INFO, "godot", "mod count: %i", mods.size()); if (mods.size()) { JNIEnv *env = ThreadAndroid::get_env(); jclass activityClass = env->FindClass("org/godotengine/godot/Godot"); jmethodID getClassLoader = env->GetMethodID(activityClass, "getClassLoader", "()Ljava/lang/ClassLoader;"); jobject cls = env->CallObjectMethod(_godot_instance, getClassLoader); //cls=env->NewGlobalRef(cls); jclass classLoader = env->FindClass("java/lang/ClassLoader"); //classLoader=(jclass)env->NewGlobalRef(classLoader); jmethodID findClass = env->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); for (int i = 0; i < mods.size(); i++) { String m = mods[i]; //jclass singletonClass = env->FindClass(m.utf8().get_data()); print_line("LOADING MODULE: " + m); jstring strClassName = env->NewStringUTF(m.utf8().get_data()); jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName); if (!singletonClass) { ERR_EXPLAIN("Couldn't find singleton for class: " + m); ERR_CONTINUE(!singletonClass); } //singletonClass=(jclass)env->NewGlobalRef(singletonClass); __android_log_print(ANDROID_LOG_INFO, "godot", "****^*^*?^*^*class data %x", singletonClass); jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;"); if (!initialize) { ERR_EXPLAIN("Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m); ERR_CONTINUE(!initialize); } jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, _godot_instance); __android_log_print(ANDROID_LOG_INFO, "godot", "****^*^*?^*^*class instance %x", obj); jobject gob = env->NewGlobalRef(obj); } } }
String FindInFilesDialog::get_folder() const { String text = _folder_line_edit->get_text(); return text.strip_edges(); }
String FindInFilesDialog::get_search_text() const { String text = _search_text_line_edit->get_text(); return text.strip_edges(); }
void ScriptCreateDialog::_path_changed(const String &p_path) { is_path_valid = false; is_new_script_created = true; String p = p_path.strip_edges(); if (p == "") { _msg_path_valid(false, TTR("Path is empty")); _update_dialog(); return; } if (p.get_file().get_basename() == "") { _msg_path_valid(false, TTR("Filename is empty")); _update_dialog(); return; } p = ProjectSettings::get_singleton()->localize_path(p); if (!p.begins_with("res://")) { _msg_path_valid(false, TTR("Path is not local")); _update_dialog(); return; } DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (d->change_dir(p.get_base_dir()) != OK) { _msg_path_valid(false, TTR("Invalid base path")); memdelete(d); _update_dialog(); return; } memdelete(d); /* Does file already exist */ DirAccess *f = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (f->dir_exists(p)) { is_new_script_created = false; is_path_valid = false; _msg_path_valid(false, TTR("Directory of the same name exists")); } else if (f->file_exists(p)) { is_new_script_created = false; is_path_valid = true; _msg_path_valid(true, TTR("File exists, will be reused")); } memdelete(f); _update_dialog(); /* Check file extension */ String extension = p.get_extension(); List<String> extensions; // get all possible extensions for script for (int l = 0; l < language_menu->get_item_count(); l++) { ScriptServer::get_language(l)->get_recognized_extensions(&extensions); } bool found = false; bool match = false; int index = 0; for (List<String>::Element *E = extensions.front(); E; E = E->next()) { if (E->get().nocasecmp_to(extension) == 0) { //FIXME (?) - changing language this way doesn't update controls, needs rework //language_menu->select(index); // change Language option by extension found = true; if (E->get() == ScriptServer::get_language(language_menu->get_selected())->get_extension()) { match = true; } break; } index++; } if (!found) { _msg_path_valid(false, TTR("Invalid extension")); _update_dialog(); return; } if (!match) { _msg_path_valid(false, TTR("Wrong extension chosen")); _update_dialog(); return; } String path_error = ScriptServer::get_language(language_menu->get_selected())->validate_path(p); if (path_error != "") { _msg_path_valid(false, path_error); _update_dialog(); return; } /* All checks passed */ is_path_valid = true; _update_dialog(); }