keep default exported script values unless overriden, closes #8127

(cherry picked from commit 475e8b28b2)
This commit is contained in:
Juan Linietsky 2017-08-06 09:32:52 -03:00 committed by Rémi Verschelde
parent 17b04adcc3
commit c1b6301050
4 changed files with 39 additions and 0 deletions

View File

@ -91,6 +91,8 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_STORE_IF_NULL = 16384,
PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768,
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,
PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK,

View File

@ -277,8 +277,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;
}
@ -288,12 +303,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());
}
}
@ -333,6 +358,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()) {

View File

@ -474,6 +474,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
bool isdefault = ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one());
if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) {
isdefault = true; //is script default value
}
// if (nd.instance<0 && ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one())) {
// continue;
// }

View File

@ -188,6 +188,7 @@ void ImageTexture::create(int p_width, int p_height, Image::Format p_format, uin
}
void ImageTexture::create_from_image(const Image &p_image, uint32_t p_flags) {
ERR_FAIL_COND(p_image.empty());
flags = p_flags;
w = p_image.get_width();
h = p_image.get_height();