summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/class_db.cpp22
-rw-r--r--core/class_db.h1
-rw-r--r--core/global_constants.cpp2
-rw-r--r--core/input_map.cpp4
-rw-r--r--core/object.cpp21
-rw-r--r--core/object.h5
-rw-r--r--core/os/keyboard.cpp4
-rw-r--r--core/os/keyboard.h4
-rw-r--r--core/project_settings.cpp4
-rw-r--r--core/resource.cpp1
-rw-r--r--core/script_language.cpp33
-rw-r--r--core/variant.h2
12 files changed, 84 insertions, 19 deletions
diff --git a/core/class_db.cpp b/core/class_db.cpp
index 6b8c290a99..24d71f86b0 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -937,6 +937,28 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
return false;
}
+int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
+
+ ClassInfo *type = classes.getptr(p_class);
+ ClassInfo *check = type;
+ while (check) {
+ const PropertySetGet *psg = check->property_setget.getptr(p_property);
+ if (psg) {
+
+ if (r_is_valid)
+ *r_is_valid = true;
+
+ return psg->index;
+ }
+
+ check = check->inherits_ptr;
+ }
+ if (r_is_valid)
+ *r_is_valid = false;
+
+ return -1;
+}
+
Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
ClassInfo *type = classes.getptr(p_class);
diff --git a/core/class_db.h b/core/class_db.h
index 4f00a16e91..02eac0dbbc 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -480,6 +480,7 @@ public:
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = NULL);
static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
+ static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = NULL);
static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = NULL);
static StringName get_property_setter(StringName p_class, const StringName p_property);
static StringName get_property_getter(StringName p_class, const StringName p_property);
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 18071d7748..9e745ecb98 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -67,8 +67,8 @@ static _GlobalConstant _global_constants[] = {
BIND_GLOBAL_CONSTANT(KEY_TAB),
BIND_GLOBAL_CONSTANT(KEY_BACKTAB),
BIND_GLOBAL_CONSTANT(KEY_BACKSPACE),
- BIND_GLOBAL_CONSTANT(KEY_RETURN),
BIND_GLOBAL_CONSTANT(KEY_ENTER),
+ BIND_GLOBAL_CONSTANT(KEY_KP_ENTER),
BIND_GLOBAL_CONSTANT(KEY_INSERT),
BIND_GLOBAL_CONSTANT(KEY_DELETE),
BIND_GLOBAL_CONSTANT(KEY_PAUSE),
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 24d0624e98..85e627f352 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -219,11 +219,11 @@ void InputMap::load_default() {
add_action("ui_accept");
key.instance();
- key->set_scancode(KEY_RETURN);
+ key->set_scancode(KEY_ENTER);
action_add_event("ui_accept", key);
key.instance();
- key->set_scancode(KEY_ENTER);
+ key->set_scancode(KEY_KP_ENTER);
action_add_event("ui_accept", key);
key.instance();
diff --git a/core/object.cpp b/core/object.cpp
index 316c624268..5824084151 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1182,10 +1182,10 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Variant::Ca
return Variant();
}
-void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
+Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
if (_block_signals)
- return; //no emit, signals blocked
+ return ERR_CANT_AQUIRE_RESOURCE; //no emit, signals blocked
Signal *s = signal_map.getptr(p_name);
if (!s) {
@@ -1194,11 +1194,11 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
//check in script
if (!signal_is_valid && !script.is_null() && !Ref<Script>(script)->has_script_signal(p_name)) {
ERR_EXPLAIN("Can't emit non-existing signal " + String("\"") + p_name + "\".");
- ERR_FAIL();
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
#endif
//not connected? just return
- return;
+ return ERR_UNAVAILABLE;
}
List<_ObjectSignalDisconnectData> disconnect_data;
@@ -1214,6 +1214,8 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
Vector<const Variant *> bind_mem;
+ Error err = OK;
+
for (int i = 0; i < ssize; i++) {
const Connection &c = slot_map.getv(i).conn;
@@ -1249,12 +1251,14 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
} else {
Variant::CallError ce;
target->call(c.method, args, argc, ce);
+
if (ce.error != Variant::CallError::CALL_OK) {
if (ce.error == Variant::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
} else {
ERR_PRINTS("Error calling method from signal '" + String(p_name) + "': " + Variant::get_call_error_text(target, c.method, args, argc, ce));
+ err = ERR_METHOD_NOT_FOUND;
}
}
}
@@ -1274,21 +1278,24 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
disconnect(dd.signal, dd.target, dd.method);
disconnect_data.pop_front();
}
+
+ return err;
}
-void Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
+Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
+
if (argptr[i]->get_type() == Variant::NIL)
break;
argc++;
}
- emit_signal(p_name, argptr, argc);
+ return emit_signal(p_name, argptr, argc);
}
void Object::_add_user_signal(const String &p_name, const Array &p_args) {
@@ -2008,7 +2015,7 @@ void ObjectDB::cleanup() {
String node_name;
if (instances[*K]->is_class("Node"))
node_name = " - Node Name: " + String(instances[*K]->call("get_name"));
- if (instances[*K]->is_class("Resoucre"))
+ if (instances[*K]->is_class("Resource"))
node_name = " - Resource Name: " + String(instances[*K]->call("get_name")) + " Path: " + String(instances[*K]->call("get_path"));
print_line("Leaked Instance: " + String(instances[*K]->get_class()) + ":" + itos(*K) + node_name);
}
diff --git a/core/object.h b/core/object.h
index 148a73fbc4..fd3bb624ec 100644
--- a/core/object.h
+++ b/core/object.h
@@ -105,6 +105,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_STORE_IF_NULL = 16384,
PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768,
PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536,
+ PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 17,
PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED,
@@ -654,8 +655,8 @@ public:
void set_script_and_instance(const RefPtr &p_script, ScriptInstance *p_instance); //some script languages can't control instance creation, so this function eases the process
void add_user_signal(const MethodInfo &p_signal);
- void emit_signal(const StringName &p_name, VARIANT_ARG_LIST);
- void emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount);
+ Error emit_signal(const StringName &p_name, VARIANT_ARG_LIST);
+ Error emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount);
void get_signal_list(List<MethodInfo> *p_signals) const;
void get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const;
void get_all_signal_connections(List<Connection> *p_connections) const;
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index e154b1934d..9b3e376ea6 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -42,8 +42,8 @@ static const _KeyCodeText _keycodes[] = {
{KEY_TAB ,"Tab"},
{KEY_BACKTAB ,"BackTab"},
{KEY_BACKSPACE ,"BackSpace"},
- {KEY_RETURN ,"Return"},
{KEY_ENTER ,"Enter"},
+ {KEY_KP_ENTER ,"Kp Enter"},
{KEY_INSERT ,"Insert"},
{KEY_DELETE ,"Delete"},
{KEY_PAUSE ,"Pause"},
@@ -294,8 +294,8 @@ bool keycode_has_unicode(uint32_t p_keycode) {
case KEY_TAB:
case KEY_BACKTAB:
case KEY_BACKSPACE:
- case KEY_RETURN:
case KEY_ENTER:
+ case KEY_KP_ENTER:
case KEY_INSERT:
case KEY_DELETE:
case KEY_PAUSE:
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index c6985c887d..1ed93e3540 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -57,8 +57,8 @@ enum KeyList {
KEY_TAB = SPKEY | 0x02,
KEY_BACKTAB = SPKEY | 0x03,
KEY_BACKSPACE = SPKEY | 0x04,
- KEY_RETURN = SPKEY | 0x05,
- KEY_ENTER = SPKEY | 0x06,
+ KEY_ENTER = SPKEY | 0x05,
+ KEY_KP_ENTER = SPKEY | 0x06,
KEY_INSERT = SPKEY | 0x07,
KEY_DELETE = SPKEY | 0x08,
KEY_PAUSE = SPKEY | 0x09,
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index b31f78ec20..f6e0d2e991 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -925,10 +925,10 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("application/config/use_shared_user_dir", true);
key.instance();
- key->set_scancode(KEY_RETURN);
+ key->set_scancode(KEY_ENTER);
va.push_back(key);
key.instance();
- key->set_scancode(KEY_ENTER);
+ key->set_scancode(KEY_KP_ENTER);
va.push_back(key);
key.instance();
key->set_scancode(KEY_SPACE);
diff --git a/core/resource.cpp b/core/resource.cpp
index 5625784396..86069bf2e9 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -32,6 +32,7 @@
#include "core_string_names.h"
#include "io/resource_loader.h"
#include "os/file_access.h"
+#include "scene/main/node.h" //only so casting works
#include "script_language.h"
#include <stdio.h>
diff --git a/core/script_language.cpp b/core/script_language.cpp
index aeb1573840..bb99e0abae 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -280,8 +280,23 @@ ScriptDebugger::ScriptDebugger() {
bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) {
if (values.has(p_name)) {
+ Variant defval;
+ if (script->get_property_default_value(p_name, defval)) {
+ if (defval == p_value) {
+ values.erase(p_name);
+ return true;
+ }
+ }
values[p_name] = p_value;
return true;
+ } else {
+ Variant defval;
+ if (script->get_property_default_value(p_name, defval)) {
+ if (defval != p_value) {
+ values[p_name] = p_value;
+ }
+ return true;
+ }
}
return false;
}
@@ -291,12 +306,22 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co
r_ret = values[p_name];
return true;
}
+
+ Variant defval;
+ if (script->get_property_default_value(p_name, defval)) {
+ r_ret = defval;
+ return true;
+ }
return false;
}
void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
+ PropertyInfo pinfo = E->get();
+ if (!values.has(pinfo.name)) {
+ pinfo.usage |= PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE;
+ }
p_properties->push_back(E->get());
}
}
@@ -336,6 +361,14 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
if (!new_values.has(E->key()))
to_remove.push_back(E->key());
+
+ Variant defval;
+ if (script->get_property_default_value(E->key(), defval)) {
+ //remove because it's the same as the default value
+ if (defval == E->get()) {
+ to_remove.push_back(E->key());
+ }
+ }
}
while (to_remove.size()) {
diff --git a/core/variant.h b/core/variant.h
index 583a0d09a0..95782d9619 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -42,8 +42,8 @@
#include "io/ip_address.h"
#include "math_2d.h"
#include "matrix3.h"
-#include "os/power.h"
#include "node_path.h"
+#include "os/power.h"
#include "plane.h"
#include "quat.h"
#include "rect3.h"