summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/object.cpp73
-rw-r--r--core/script_language.cpp94
-rw-r--r--core/script_language.h12
3 files changed, 161 insertions, 18 deletions
diff --git a/core/object.cpp b/core/object.cpp
index a0c64feb09..ba8b710a84 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -450,16 +450,41 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
*r_valid = true;
return;
#endif
- } else {
- //something inside the object... :|
- bool success = _setv(p_name, p_value);
- if (success) {
+ }
+
+ //something inside the object... :|
+ bool success = _setv(p_name, p_value);
+ if (success) {
+ if (r_valid)
+ *r_valid = true;
+ return;
+ }
+
+ {
+ bool valid;
+ setvar(p_name, p_value, &valid);
+ if (valid) {
+ if (r_valid)
+ *r_valid = true;
+ return;
+ }
+ }
+
+#ifdef TOOLS_ENABLED
+ if (script_instance) {
+ bool valid;
+ script_instance->property_set_fallback(p_name, p_value, &valid);
+ if (valid) {
if (r_valid)
*r_valid = true;
return;
}
- setvar(p_name, p_value, r_valid);
}
+#endif
+
+ if (r_valid)
+ *r_valid = false;
+ return;
}
Variant Object::get(const StringName &p_name, bool *r_valid) const {
@@ -513,8 +538,33 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
*r_valid = true;
return ret;
}
+
//if nothing else, use getvar
- return getvar(p_name, r_valid);
+ {
+ bool valid;
+ ret = getvar(p_name, &valid);
+ if (valid) {
+ if (r_valid)
+ *r_valid = true;
+ return ret;
+ }
+ }
+
+#ifdef TOOLS_ENABLED
+ if (script_instance) {
+ bool valid;
+ ret = script_instance->property_get_fallback(p_name, &valid);
+ if (valid) {
+ if (r_valid)
+ *r_valid = true;
+ return ret;
+ }
+ }
+#endif
+
+ if (r_valid)
+ *r_valid = false;
+ return Variant();
}
}
@@ -979,9 +1029,14 @@ void Object::set_script(const RefPtr &p_script) {
script = p_script;
Ref<Script> s(script);
- if (!s.is_null() && s->can_instance()) {
- OBJ_DEBUG_LOCK
- script_instance = s->instance_create(this);
+ if (!s.is_null()) {
+ if (s->can_instance()) {
+ OBJ_DEBUG_LOCK
+ script_instance = s->instance_create(this);
+ } else if (Engine::get_singleton()->is_editor_hint()) {
+ OBJ_DEBUG_LOCK
+ script_instance = s->placeholder_instance_create(this);
+ }
}
_change_notify("script");
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 37ba3cfc62..e146fb773c 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -255,6 +255,17 @@ void ScriptInstance::call_multilevel_reversed(const StringName &p_method, const
call(p_method, p_args, p_argcount, ce); // script may not support multilevel calls
}
+void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
+ if (r_valid)
+ *r_valid = false;
+}
+
+Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
+ if (r_valid)
+ *r_valid = false;
+ return Variant();
+}
+
void ScriptInstance::call_multilevel(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
@@ -364,6 +375,9 @@ ScriptDebugger::ScriptDebugger() {
bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) {
+ if (build_failed)
+ return false;
+
if (values.has(p_name)) {
Variant defval;
if (script->get_property_default_value(p_name, defval)) {
@@ -392,22 +406,31 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co
return true;
}
- Variant defval;
- if (script->get_property_default_value(p_name, defval)) {
- r_ret = defval;
- return true;
+ if (!build_failed) {
+ 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;
+ if (build_failed) {
+ for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
+ p_properties->push_back(E->get());
+ }
+ } else {
+ 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());
}
- p_properties->push_back(E->get());
}
}
@@ -426,12 +449,18 @@ Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_n
void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
+ if (build_failed)
+ return;
+
if (script.is_valid()) {
script->get_script_method_list(p_list);
}
}
bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
+ if (build_failed)
+ return false;
+
if (script.is_valid()) {
return script->has_method(p_method);
}
@@ -440,6 +469,8 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values) {
+ build_failed = false;
+
Set<StringName> new_values;
for (const List<PropertyInfo>::Element *E = p_properties.front(); E; E = E->next()) {
@@ -483,6 +514,51 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
//change notify
}
+void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) {
+
+ if (build_failed) {
+ Map<StringName, Variant>::Element *E = values.find(p_name);
+
+ if (E) {
+ E->value() = p_value;
+ } else {
+ values.insert(p_name, p_value);
+ }
+
+ bool found = false;
+ for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
+ if (E->get().name == p_name) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ properties.push_back(PropertyInfo(p_value.get_type(), p_name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE));
+ }
+ }
+
+ if (r_valid)
+ *r_valid = false; // Cannot change the value in either case
+}
+
+Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) {
+
+ if (build_failed) {
+ const Map<StringName, Variant>::Element *E = values.find(p_name);
+
+ if (E) {
+ if (r_valid)
+ *r_valid = true;
+ return E->value();
+ }
+ }
+
+ if (r_valid)
+ *r_valid = false;
+
+ return Variant();
+}
+
PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner) :
owner(p_owner),
language(p_language),
diff --git a/core/script_language.h b/core/script_language.h
index 71d550d404..a5987e2a78 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -115,6 +115,7 @@ public:
virtual StringName get_instance_base_type() const = 0; // this may not work in all scripts, will return empty if so
virtual ScriptInstance *instance_create(Object *p_this) = 0;
+ virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) { return NULL; }
virtual bool instance_has(const Object *p_this) const = 0;
virtual bool has_source_code() const = 0;
@@ -176,6 +177,9 @@ public:
virtual bool is_placeholder() const { return false; }
+ virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
+ virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
+
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const = 0;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const = 0;
@@ -326,6 +330,8 @@ class PlaceHolderScriptInstance : public ScriptInstance {
ScriptLanguage *language;
Ref<Script> script;
+ bool build_failed;
+
public:
virtual bool set(const StringName &p_name, const Variant &p_value);
virtual bool get(const StringName &p_name, Variant &r_ret) const;
@@ -351,8 +357,14 @@ public:
void update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values); //likely changed in editor
+ void set_build_failed(bool p_build_failed) { build_failed = p_build_failed; }
+ bool get_build_failed() const { return build_failed; }
+
virtual bool is_placeholder() const { return true; }
+ virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
+ virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
+
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const { return MultiplayerAPI::RPC_MODE_DISABLED; }
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const { return MultiplayerAPI::RPC_MODE_DISABLED; }