diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/dictionary.cpp | 2 | ||||
-rw-r--r-- | core/io/json.cpp | 2 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 2 | ||||
-rw-r--r-- | core/method_bind.h | 1 | ||||
-rw-r--r-- | core/object_type_db.cpp | 12 | ||||
-rw-r--r-- | core/object_type_db.h | 2 | ||||
-rw-r--r-- | core/os/input.cpp | 25 | ||||
-rw-r--r-- | core/os/input.h | 2 | ||||
-rw-r--r-- | core/os/keyboard.cpp | 5 | ||||
-rw-r--r-- | core/os/keyboard.h | 1 | ||||
-rw-r--r-- | core/os/os.cpp | 5 | ||||
-rw-r--r-- | core/os/os.h | 13 | ||||
-rw-r--r-- | core/translation.cpp | 74 | ||||
-rw-r--r-- | core/ustring.cpp | 14 | ||||
-rw-r--r-- | core/ustring.h | 2 | ||||
-rw-r--r-- | core/variant_op.cpp | 36 |
16 files changed, 162 insertions, 36 deletions
diff --git a/core/dictionary.cpp b/core/dictionary.cpp index 16ee397382..2d503bae50 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -186,10 +186,12 @@ Error Dictionary::parse_json(const String& p_json) { String errstr; int errline=0; + if (p_json != ""){ Error err = JSON::parse(p_json,*this,errstr,errline); if (err!=OK) { ERR_EXPLAIN("Error parsing JSON: "+errstr+" at line: "+itos(errline)); ERR_FAIL_COND_V(err!=OK,err); + } } return OK; diff --git a/core/io/json.cpp b/core/io/json.cpp index a83d7e4d6e..88a23eb4cd 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -250,7 +250,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_toke if (p_str[idx]=='-' || (p_str[idx]>='0' && p_str[idx]<='9')) { //a number const CharType *rptr; - double number = String::to_double(&p_str[idx],-1,&rptr); + double number = String::to_double(&p_str[idx],&rptr); idx+=(rptr - &p_str[idx]); r_token.type=TK_NUMBER; r_token.value=number; diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 0e75e22767..f83c174084 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -32,7 +32,7 @@ StreamPeerTCP* (*StreamPeerTCP::_create)()=NULL; void StreamPeerTCP::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect","host","ip"),&StreamPeerTCP::connect); + ObjectTypeDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::connect); ObjectTypeDB::bind_method(_MD("is_connected"),&StreamPeerTCP::is_connected); ObjectTypeDB::bind_method(_MD("get_status"),&StreamPeerTCP::get_status); ObjectTypeDB::bind_method(_MD("get_connected_host"),&StreamPeerTCP::get_connected_host); diff --git a/core/method_bind.h b/core/method_bind.h index 3f08c70af8..6ea9340ad5 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -178,6 +178,7 @@ public: #ifdef DEBUG_METHODS_ENABLED _FORCE_INLINE_ void set_return_type(const StringName& p_type) { ret_type=p_type; } + _FORCE_INLINE_ StringName get_return_type() const { return ret_type; } _FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const { diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp index efd92542ce..f7917b7418 100644 --- a/core/object_type_db.cpp +++ b/core/object_type_db.cpp @@ -191,6 +191,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co HashMap<StringName,ObjectTypeDB::TypeInfo,StringNameHasher> ObjectTypeDB::types; HashMap<StringName,StringName,StringNameHasher> ObjectTypeDB::resource_base_extensions; +HashMap<StringName,StringName,StringNameHasher> ObjectTypeDB::compat_types; ObjectTypeDB::TypeInfo::TypeInfo() { @@ -263,12 +264,22 @@ bool ObjectTypeDB::type_exists(const String &p_type) { return types.has(p_type); } +void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringName& p_fallback) { + + compat_types[p_type]=p_fallback; +} + Object *ObjectTypeDB::instance(const String &p_type) { TypeInfo *ti; { OBJTYPE_LOCK; ti=types.getptr(p_type); + if (!ti || ti->disabled || !ti->creation_func) { + if (compat_types.has(p_type)) { + ti=types.getptr(compat_types[p_type]); + } + } ERR_FAIL_COND_V(!ti,NULL); ERR_FAIL_COND_V(ti->disabled,NULL); ERR_FAIL_COND_V(!ti->creation_func,NULL); @@ -914,6 +925,7 @@ void ObjectTypeDB::cleanup() { } types.clear(); resource_base_extensions.clear(); + compat_types.clear(); } // diff --git a/core/object_type_db.h b/core/object_type_db.h index f2ff194e28..617a0a7c20 100644 --- a/core/object_type_db.h +++ b/core/object_type_db.h @@ -151,6 +151,7 @@ class ObjectTypeDB { static Mutex *lock; static HashMap<StringName,TypeInfo,StringNameHasher> types; static HashMap<StringName,StringName,StringNameHasher> resource_base_extensions; + static HashMap<StringName,StringName,StringNameHasher> compat_types; #ifdef DEBUG_METHODS_ENABLED static MethodBind* bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount); @@ -482,6 +483,7 @@ public: static void get_resource_base_extensions(List<String> *p_extensions); static void get_extensions_for_type(const StringName& p_type,List<String> *p_extensions); + static void add_compatibility_type(const StringName& p_type,const StringName& p_fallback); static void init(); static void cleanup(); }; diff --git a/core/os/input.cpp b/core/os/input.cpp index 4151c1b5a8..a827e75896 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -29,6 +29,7 @@ #include "input.h" #include "input_map.h" #include "os/os.h" +#include "globals.h" Input *Input::singleton=NULL; Input *Input::get_singleton() { @@ -69,6 +70,30 @@ void Input::_bind_methods() { ADD_SIGNAL( MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")) ); } +void Input::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const { +#ifdef TOOLS_ENABLED + + String pf=p_function; + if (p_idx==0 && (pf=="is_action_pressed" || pf=="action_press" || pf=="action_release")) { + + List<PropertyInfo> pinfo; + Globals::get_singleton()->get_property_list(&pinfo); + + for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + const PropertyInfo &pi=E->get(); + + if (!pi.name.begins_with("input/")) + continue; + + String name = pi.name.substr(pi.name.find("/")+1,pi.name.length()); + r_options->push_back("\""+name+"\""); + + } + } +#endif + +} + Input::Input() { singleton=this; diff --git a/core/os/input.h b/core/os/input.h index 1cb0f35d96..387a43a35a 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -76,6 +76,8 @@ public: virtual void action_press(const StringName& p_action)=0; virtual void action_release(const StringName& p_action)=0; + void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + Input(); }; diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index a4201c34ea..c9979d1921 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -353,3 +353,8 @@ int find_keycode(const String& p_code) { return 0; } + +int latin_keyboard_keycode_convert(int p_keycode){ + + return p_keycode; +} diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 18b56b5830..b4ec5da26f 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -328,5 +328,6 @@ enum KeyModifierMask { String keycode_get_string(uint32_t p_code); bool keycode_has_unicode(uint32_t p_unicode); int find_keycode(const String& p_code); +int latin_keyboard_keycode_convert(int p_keycode); #endif diff --git a/core/os/os.cpp b/core/os/os.cpp index 081f7c1c5e..5e0e5eed77 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -485,6 +485,11 @@ void OS::set_time_scale(float p_scale) { _time_scale=p_scale; } +OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const { + + return LATIN_KEYBOARD_QWERTY; +} + float OS::get_time_scale() const { return _time_scale; diff --git a/core/os/os.h b/core/os/os.h index 805d6ac57d..d4deff2f5e 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -34,6 +34,7 @@ #include "vector.h" #include "os/main_loop.h" #include <stdarg.h> + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -348,6 +349,18 @@ public: virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback); + enum LatinKeyboardVariant { + LATIN_KEYBOARD_QWERTY, + LATIN_KEYBOARD_QWERTZ, + LATIN_KEYBOARD_AZERTY, + LATIN_KEYBOARD_QZERTY, + LATIN_KEYBOARD_DVORAK, + LATIN_KEYBOARD_NEO, + }; + + + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + void set_time_scale(float p_scale); float get_time_scale() const; diff --git a/core/translation.cpp b/core/translation.cpp index 81f2c36075..6ad34651b2 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -550,7 +550,7 @@ StringName TranslationServer::translate(const StringName& p_message) const { continue; // locale not match //near match - bool match = (l!=lptr); + bool match = (l!=locale); if (near_match && !match) continue; //only near-match once @@ -570,6 +570,42 @@ StringName TranslationServer::translate(const StringName& p_message) const { } + if (!res) { + //try again with fallback + if (fallback.length()>=2) { + + const CharType *fptr=&fallback[0]; + bool near_match=false; + for (const Set< Ref<Translation> >::Element *E=translations.front();E;E=E->next()) { + + const Ref<Translation>& t = E->get(); + String l = t->get_locale(); + if (fptr[0]!=l[0] || fptr[1]!=l[1]) + continue; // locale not match + + //near match + bool match = (l!=fallback); + + if (near_match && !match) + continue; //only near-match once + + StringName r=t->get_message(p_message); + + if (!r) + continue; + + res=r; + + if (match) + break; + else + near_match=true; + + } + } + } + + if (!res) return p_message; @@ -604,9 +640,27 @@ bool TranslationServer::_load_translations(const String& p_from) { void TranslationServer::setup() { - - set_locale( GLOBAL_DEF("locale/default",OS::get_singleton()->get_locale()) ); - fallback = GLOBAL_DEF("locale/fallback",""); + 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 } @@ -629,6 +683,7 @@ void TranslationServer::load_translations() { String locale = get_locale(); bool found = _load_translations("locale/translations"); //all + if (_load_translations("locale/translations_"+locale.substr(0,2))) found=true; if ( locale.substr(0,2) != locale ) { @@ -637,17 +692,6 @@ void TranslationServer::load_translations() { } - if (!found && fallback!="") { //none found anywhere, use fallback - - _load_translations("locale/translations_"+fallback.substr(0,2)); - if ( fallback.substr(0,2) != fallback ) { - _load_translations("locale/translations_"+fallback); - } - - this->locale=fallback; - - } - } TranslationServer::TranslationServer() { diff --git a/core/ustring.cpp b/core/ustring.cpp index d75c21d16e..581cc29440 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -626,7 +626,7 @@ Vector<float> String::split_floats(const String &p_splitter,bool p_allow_empty) if (end<0) end=len; if (p_allow_empty || (end>from)) - ret.push_back(String::to_double(&c_str()[from],end-from)); + ret.push_back(String::to_double(&c_str()[from])); if (end==len) break; @@ -654,8 +654,9 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters,bool p_a spl_len=p_splitters[idx].length(); } - if (p_allow_empty || (end>from)) - ret.push_back(String::to_double(&c_str()[from],end-from)); + if (p_allow_empty || (end>from)) { + ret.push_back(String::to_double(&c_str()[from])); + } if (end==len) break; @@ -1959,8 +1960,10 @@ float String::to_float() const { return to_double(); } -double String::to_double(const CharType* p_str, int p_len, const CharType **r_end) { +double String::to_double(const CharType* p_str, const CharType **r_end) { + return built_in_strtod<CharType>(p_str,(CharType**)r_end); +#if 0 #if 0 //ndef NO_USE_STDLIB return wcstod(p_str,p_len<0?NULL:p_str+p_len); @@ -2053,6 +2056,7 @@ double String::to_double(const CharType* p_str, int p_len, const CharType **r_en return sign*(integer+decimal)*Math::pow(10,exp_sign*exp); #endif +#endif } int64_t String::to_int(const CharType* p_str,int p_len) { @@ -3437,7 +3441,7 @@ String String::percent_encode() const { uint8_t c = cs[i]; if ( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || c=='-' || c=='_' || c=='~' || c=='.') { - char p[2]={c,0}; + char p[2]={(char)c,0}; encoded+=p; } else { char p[4]={'%',0,0,0}; diff --git a/core/ustring.h b/core/ustring.h index 8fe3a95463..e1d6761742 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -142,7 +142,7 @@ public: int64_t to_int64() const; static int to_int(const char* p_str); static double to_double(const char* p_str); - static double to_double(const CharType* p_str, int p_len=-1, const CharType **r_end=NULL); + static double to_double(const CharType* p_str, const CharType **r_end=NULL); static int64_t to_int(const CharType* p_str,int p_len=-1); String capitalize() const; diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 9c489c5ef2..ec43b1275c 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -922,21 +922,31 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) case REAL: { return; } break; case STRING: { - if (p_value.type!=Variant::STRING) + + if (p_index.type!=Variant::INT && p_index.type!=Variant::REAL) return; - if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) { - //string index - int idx=p_index; - String *str=reinterpret_cast<String*>(_data._mem); - if (idx >=0 && idx<str->length()) { - String chr = p_value; - *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length()); - valid=true; - return; - } + int idx=p_index; + String *str=reinterpret_cast<String*>(_data._mem); + if (idx <0 || idx>=str->length()) + return; + + String chr; + if (p_value.type==Variant::INT || p_value.type==Variant::REAL) { + + chr = String::chr(p_value); + } else if (p_value.type==Variant::STRING) { + + chr = p_value; + } else { + return; } + *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length()); + valid=true; + return; + + } break; case VECTOR2: { @@ -951,7 +961,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) Vector2 *v=reinterpret_cast<Vector2*>(_data._mem); valid=true; - v[idx]=p_value; + (*v)[idx]=p_value; return; } } else if (p_index.get_type()==Variant::STRING) { @@ -1045,7 +1055,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) Vector3 *v=reinterpret_cast<Vector3*>(_data._mem); valid=true; - v[idx]=p_value; + (*v)[idx]=p_value; return; } } else if (p_index.get_type()==Variant::STRING) { |