summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp7
-rw-r--r--core/bind/core_bind.h2
-rw-r--r--core/dictionary.cpp2
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/ip.cpp2
-rw-r--r--core/io/json.cpp2
-rw-r--r--core/io/stream_peer_tcp.cpp2
-rw-r--r--core/io/xml_parser.cpp4
-rw-r--r--core/math/math_funcs.h6
-rw-r--r--core/method_bind.cpp4
-rw-r--r--core/method_bind.h1
-rw-r--r--core/object.cpp5
-rw-r--r--core/object.h1
-rw-r--r--core/object_type_db.cpp29
-rw-r--r--core/object_type_db.h4
-rw-r--r--core/os/input.cpp25
-rw-r--r--core/os/input.h2
-rw-r--r--core/os/keyboard.cpp105
-rw-r--r--core/os/keyboard.h1
-rw-r--r--core/os/os.cpp5
-rw-r--r--core/os/os.h13
-rw-r--r--core/register_core_types.cpp1
-rw-r--r--core/script_language.h2
-rw-r--r--core/translation.cpp74
-rw-r--r--core/ustring.cpp14
-rw-r--r--core/ustring.h2
-rw-r--r--core/variant.cpp126
-rw-r--r--core/variant.h8
-rw-r--r--core/variant_call.cpp6
-rw-r--r--core/variant_op.cpp36
30 files changed, 443 insertions, 50 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 0dd467986e..0c5d21b4f6 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -12,9 +12,9 @@ Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String& p
return ResourceLoader::load_interactive(p_path,p_type_hint);
}
-RES _ResourceLoader::load(const String &p_path,const String& p_type_hint) {
+RES _ResourceLoader::load(const String &p_path,const String& p_type_hint, bool p_no_cache) {
- RES ret = ResourceLoader::load(p_path,p_type_hint);
+ RES ret = ResourceLoader::load(p_path,p_type_hint, p_no_cache);
return ret;
}
@@ -59,7 +59,7 @@ void _ResourceLoader::_bind_methods() {
ObjectTypeDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
- ObjectTypeDB::bind_method(_MD("load:Resource","path","type_hint"),&_ResourceLoader::load,DEFVAL(""));
+ ObjectTypeDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
ObjectTypeDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
ObjectTypeDB::bind_method(_MD("get_dependencies"),&_ResourceLoader::get_dependencies);
@@ -1121,6 +1121,7 @@ String _File::get_as_text() const {
text+=l+"\n";
l = get_line();
}
+ text+=l;
return text;
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index a76b4aa81f..12a4ae86eb 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -21,7 +21,7 @@ public:
static _ResourceLoader *get_singleton() { return singleton; }
Ref<ResourceInteractiveLoader> load_interactive(const String& p_path,const String& p_type_hint="");
- RES load(const String &p_path,const String& p_type_hint="");
+ RES load(const String &p_path,const String& p_type_hint="", bool p_no_cache = false);
DVector<String> get_recognized_extensions_for_type(const String& p_type);
void set_abort_on_missing_resources(bool p_abort);
StringArray get_dependencies(const String& p_path);
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/http_client.cpp b/core/io/http_client.cpp
index 60a200af12..faead675d4 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -29,6 +29,8 @@
#include "http_client.h"
#include "io/stream_peer_ssl.h"
+VARIANT_ENUM_CAST(HTTPClient::Status);
+
Error HTTPClient::connect_url(const String& p_url) {
return OK;
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index d2a685f6b0..6ef6b31188 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -31,7 +31,7 @@
#include "os/semaphore.h"
#include "hash_map.h"
-
+VARIANT_ENUM_CAST(IP::ResolverStatus);
/************* RESOLVER ******************/
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/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 5d3e4f61ad..1d69f8e5e7 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -30,9 +30,11 @@
#include "print_string.h"
//#define DEBUG_XML
+VARIANT_ENUM_CAST(XMLParser::NodeType);
+
static bool _equalsn(const CharType* str1, const CharType* str2, int len) {
int i;
- for(i=0; str1[i] && str2[i] && i < len; ++i)
+ for(i=0; i < len && str1[i] && str2[i] ; ++i)
if (str1[i] != str2[i])
return false;
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index c98a088912..6d43ed8e64 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -136,7 +136,10 @@ public:
static int b;
-#if defined(_MSC_VER) && _MSC_VER < 1800
+#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone?
+ b = (int)((a>0.0f) ? (a + 0.5f):(a -0.5f));
+
+#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a
__asm fistp b
/*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
@@ -147,6 +150,7 @@ public:
"fistpl %0 \n\t"
: "=m" (b)
: "m" (a));*/
+
#else
b=lrintf(a); //assuming everything but msvc 2012 or earlier has lrint
#endif
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index 739745f70f..6ee4882571 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -87,7 +87,9 @@ Vector<StringName> MethodBind::get_argument_names() const {
void MethodBind::set_default_arguments(const Vector<Variant>& p_defargs) {
- default_arguments=p_defargs; default_argument_count=default_arguments.size();
+ default_arguments=p_defargs;
+ default_argument_count=default_arguments.size();
+
}
#ifdef DEBUG_METHODS_ENABLED
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.cpp b/core/object.cpp
index 42d570042f..82144ab4be 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1694,6 +1694,11 @@ void ObjectDB::debug_objects(DebugFunc p_func) {
}
+void Object::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+
+}
+
int ObjectDB::get_object_count() {
GLOBAL_LOCK_FUNCTION;
diff --git a/core/object.h b/core/object.h
index 7ce07869a6..97ca50cb1a 100644
--- a/core/object.h
+++ b/core/object.h
@@ -583,6 +583,7 @@ public:
virtual void get_translatable_strings(List<String> *p_strings) const;
+ virtual void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
StringName XL_MESSAGE(const StringName& p_message) const; //translate message (internationalization)
StringName tr(const StringName& p_message) const; //translate message (alternative)
diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp
index 62244cbd4f..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);
@@ -805,12 +816,25 @@ void ObjectTypeDB::add_virtual_method(const StringName& p_type,const MethodInfo&
}
-void ObjectTypeDB::get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods ) {
+void ObjectTypeDB::get_virtual_methods(const StringName& p_type, List<MethodInfo> * p_methods , bool p_no_inheritance) {
ERR_FAIL_COND(!types.has(p_type));
#ifdef DEBUG_METHODS_ENABLED
- *p_methods=types[p_type].virtual_methods;
+
+ TypeInfo *type=types.getptr(p_type);
+ TypeInfo *check=type;
+ while(check) {
+
+ for(List<MethodInfo>::Element *E=check->virtual_methods.front();E;E=E->next()) {
+ p_methods->push_back(E->get());
+ }
+
+ if (p_no_inheritance)
+ return;
+ check=check->inherits_ptr;
+ }
+
#endif
}
@@ -901,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 ae0644f9b3..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);
@@ -468,7 +469,7 @@ public:
static MethodBind *get_method(StringName p_type, StringName p_name);
static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method );
- static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods );
+ static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false );
static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant);
static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);
@@ -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..e2a992ecb9 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "keyboard.h"
-
+#include "os/os.h"
struct _KeyCodeText {
int code;
@@ -353,3 +353,106 @@ int find_keycode(const String& p_code) {
return 0;
}
+
+
+
+
+struct _KeyCodeReplace {
+ int from;
+ int to;
+};
+
+static const _KeyCodeReplace _keycode_replace_qwertz[]={
+{KEY_Y,KEY_Z},
+{KEY_Z,KEY_Y},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_azerty[]={
+{KEY_W,KEY_Z},
+{KEY_Z,KEY_W},
+{KEY_A,KEY_Q},
+{KEY_Q,KEY_A},
+{KEY_SEMICOLON,KEY_M},
+{KEY_M,KEY_SEMICOLON},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_qzerty[]={
+{KEY_W,KEY_Z},
+{KEY_Z,KEY_W},
+{KEY_SEMICOLON,KEY_M},
+{KEY_M,KEY_SEMICOLON},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_dvorak[]={
+{KEY_UNDERSCORE,KEY_BRACELEFT},
+{KEY_EQUAL,KEY_BRACERIGHT},
+{KEY_Q,KEY_APOSTROPHE},
+{KEY_W,KEY_COMMA},
+{KEY_E,KEY_PERIOD},
+{KEY_R,KEY_P},
+{KEY_T,KEY_Y},
+{KEY_Y,KEY_F},
+{KEY_U,KEY_G},
+{KEY_I,KEY_C},
+{KEY_O,KEY_R},
+{KEY_P,KEY_L},
+{KEY_BRACELEFT,KEY_SLASH},
+{KEY_BRACERIGHT,KEY_EQUAL},
+{KEY_A,KEY_A},
+{KEY_S,KEY_O},
+{KEY_D,KEY_E},
+{KEY_F,KEY_U},
+{KEY_G,KEY_I},
+{KEY_H,KEY_D},
+{KEY_J,KEY_H},
+{KEY_K,KEY_T},
+{KEY_L,KEY_N},
+{KEY_SEMICOLON,KEY_S},
+{KEY_APOSTROPHE,KEY_UNDERSCORE},
+{KEY_Z,KEY_SEMICOLON},
+{KEY_X,KEY_Q},
+{KEY_C,KEY_J},
+{KEY_V,KEY_K},
+{KEY_B,KEY_X},
+{KEY_N,KEY_B},
+{KEY_M,KEY_M},
+{KEY_COMMA,KEY_W},
+{KEY_PERIOD,KEY_V},
+{KEY_SLASH,KEY_Z},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_neo[]={
+{0,0}
+};
+
+
+int latin_keyboard_keycode_convert(int p_keycode) {
+
+ const _KeyCodeReplace *kcr=NULL;
+ switch(OS::get_singleton()->get_latin_keyboard_variant()) {
+
+ case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break;
+ case OS::LATIN_KEYBOARD_QWERTZ: kcr=_keycode_replace_qwertz; break;
+ case OS::LATIN_KEYBOARD_AZERTY: kcr=_keycode_replace_azerty; break;
+ case OS::LATIN_KEYBOARD_QZERTY: kcr=_keycode_replace_qzerty; break;
+ case OS::LATIN_KEYBOARD_DVORAK: kcr=_keycode_replace_dvorak; break;
+ case OS::LATIN_KEYBOARD_NEO: kcr=_keycode_replace_neo; break;
+ default: return p_keycode;
+ }
+
+ if (!kcr) {
+ return p_keycode;
+ }
+
+ while(kcr->from) {
+ if (kcr->from==p_keycode)
+ return kcr->to;
+ kcr++;
+ }
+
+ 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/register_core_types.cpp b/core/register_core_types.cpp
index 2f16e31de6..4935136eeb 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -110,6 +110,7 @@ void register_core_types() {
ObjectTypeDB::register_type<Reference>();
+ ObjectTypeDB::register_type<WeakRef>();
ObjectTypeDB::register_type<ResourceImportMetadata>();
ObjectTypeDB::register_type<Resource>();
ObjectTypeDB::register_type<FuncRef>();
diff --git a/core/script_language.h b/core/script_language.h
index d62e9849a1..802eff190a 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -144,7 +144,7 @@ public:
virtual bool has_named_classes() const=0;
virtual int find_function(const String& p_function,const String& p_code) const=0;
virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const=0;
- virtual Error complete_keyword(const String& p_code, int p_line, const String& p_base_path, const String& p_keyword, List<String>* r_options) { return ERR_UNAVAILABLE; }
+ virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint) { return ERR_UNAVAILABLE; }
virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const=0;
/* DEBUGGER FUNCTIONS */
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.cpp b/core/variant.cpp
index fdb14c0c0f..2f0eca9e91 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -2631,3 +2631,129 @@ Variant Variant::call(const StringName& p_method,VARIANT_ARG_DECLARE) {
return ret;
}
+
+String Variant::get_construct_string() const {
+
+ switch( type ) {
+
+ case NIL: return "null";
+ case BOOL: return _data._bool ? "true" : "false";
+ case INT: return String::num(_data._int);
+ case REAL: return String::num(_data._real);
+ case STRING: return "\""+*reinterpret_cast<const String*>(_data._mem)+"\"";
+ case VECTOR2: return "Vector2("+operator Vector2()+")";
+ case RECT2: return "Rect2("+operator Rect2()+")";
+ case MATRIX32: return "Matrix32("+operator Matrix32()+")";
+ case VECTOR3: return "Vector3("+operator Vector3()+")";
+ case PLANE: return "Plane("+operator Plane()+")";
+ //case QUAT:
+ case _AABB: return "AABB("+operator AABB()+")";
+ case QUAT: return "Quat("+operator Quat()+")";
+ case MATRIX3: return "Matrix3("+operator Matrix3()+")";
+ case TRANSFORM: return "Transform("+operator Transform()+")";
+ case NODE_PATH: return "@\""+operator NodePath()+"\"";
+ case INPUT_EVENT: return "InputEvent()";
+ case COLOR: return "Color("+String::num( operator Color().r)+","+String::num( operator Color().g)+","+String::num( operator Color().b)+","+String::num( operator Color().a)+")" ;
+ case DICTIONARY: {
+
+ const Dictionary &d =*reinterpret_cast<const Dictionary*>(_data._mem);
+ //const String *K=NULL;
+ String str="{";
+ List<Variant> keys;
+ d.get_key_list(&keys);
+
+ Vector<_VariantStrPair> pairs;
+
+ for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
+
+ _VariantStrPair sp;
+ sp.key=E->get().get_construct_string();
+ sp.value=d[E->get()].get_construct_string();
+ pairs.push_back(sp);
+ }
+
+ pairs.sort();
+
+ for(int i=0;i<pairs.size();i++) {
+ if (i>0)
+ str+=", ";
+ str+="("+pairs[i].key+":"+pairs[i].value+")";
+ }
+ str+="}";
+
+ return str;
+ } break;
+ case VECTOR3_ARRAY: {
+
+ DVector<Vector3> vec = operator DVector<Vector3>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str+=Variant( vec[i] ).get_construct_string();
+ }
+ return str+"]";
+ } break;
+ case STRING_ARRAY: {
+
+ DVector<String> vec = operator DVector<String>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str=str+=Variant( vec[i] ).get_construct_string();
+ }
+ return str+"]";
+ } break;
+ case INT_ARRAY: {
+
+ DVector<int> vec = operator DVector<int>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str=str+itos(vec[i]);
+ }
+ return str+"]";
+ } break;
+ case REAL_ARRAY: {
+
+ DVector<real_t> vec = operator DVector<real_t>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str=str+rtos(vec[i]);
+ }
+ return str+"]";
+ } break;
+ case ARRAY: {
+
+ Array arr = operator Array();
+ String str="[";
+ for (int i=0; i<arr.size(); i++) {
+ if (i)
+ str+=", ";
+ str += arr[i].get_construct_string();
+ };
+ return str+"]";
+
+ } break;
+ case OBJECT: {
+
+ if (_get_obj().obj)
+ return _get_obj().obj->get_type()+".new()";
+ else
+ return "null";
+
+ } break;
+ default: {
+ return "["+get_type_name(type)+"]";
+ }
+ }
+
+}
diff --git a/core/variant.h b/core/variant.h
index 9109f4ad08..47fc3f43ac 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -167,14 +167,18 @@ public:
static String get_type_name(Variant::Type p_type);
static bool can_convert(Type p_type_from,Type p_type_to);
+
+
template<class T>
static Type get_type_for() {
GetSimpleType<T> t;
Variant v(t.type);
- return v.get_type();
+ Type r = v.get_type();
+ return r;
}
+
bool is_ref() const;
_FORCE_INLINE_ bool is_num() const { return type==INT || type==REAL; };
_FORCE_INLINE_ bool is_array() const { return type>=ARRAY; };
@@ -415,6 +419,8 @@ public:
static bool has_numeric_constant(Variant::Type p_type, const StringName& p_value);
static int get_numeric_constant_value(Variant::Type p_type, const StringName& p_value);
+ String get_construct_string() const;
+
void operator=(const Variant& p_variant); // only this is enough for all the other types
Variant(const Variant& p_variant);
_FORCE_INLINE_ Variant() { type=NIL; }
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 93a9e6475f..3f2800494d 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -757,6 +757,11 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
r_ret=Quat(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
}
+ static void Quat_init2(Variant& r_ret,const Variant** p_args) {
+
+ r_ret=Quat(((Vector3)(*p_args[0])),((float)(*p_args[1])));
+ }
+
static void Color_init1(Variant& r_ret,const Variant** p_args) {
r_ret=Color(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
@@ -1509,6 +1514,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
_VariantCall::add_constructor(_VariantCall::Plane_init3,Variant::PLANE,"normal",Variant::VECTOR3,"d",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Quat_init1,Variant::QUAT,"x",Variant::REAL,"y",Variant::REAL,"z",Variant::REAL,"w",Variant::REAL);
+ _VariantCall::add_constructor(_VariantCall::Quat_init2,Variant::QUAT,"axis",Variant::VECTOR3,"angle",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Color_init1,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL,"a",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Color_init2,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL);
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) {