Esempio n. 1
0
Ref<Resource> Resource::duplicate(bool p_subresources) {

	List<PropertyInfo> plist;
	get_property_list(&plist);

	Resource *r = (Resource *)ObjectTypeDB::instance(get_type());
	ERR_FAIL_COND_V(!r, Ref<Resource>());

	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

		if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
			continue;
		Variant p = get(E->get().name);
		if (p.get_type() == Variant::OBJECT && p_subresources) {

			RES sr = p;
			if (sr.is_valid())
				p = sr->duplicate(true);
		}

		r->set(E->get().name, p);
	}

	return Ref<Resource>(r);
}
Esempio n. 2
0
void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {

	print_line("configure for local: " + get_class());
	List<PropertyInfo> plist;
	get_property_list(&plist);

	local_scene = p_for_scene;

	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

		if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
			continue;
		Variant p = get(E->get().name);
		if (p.get_type() == Variant::OBJECT) {

			RES sr = p;
			if (sr.is_valid()) {

				if (sr->is_local_to_scene()) {
					if (!remap_cache.has(sr)) {
						sr->configure_for_local_scene(p_for_scene, remap_cache);
						remap_cache[sr] = sr;
					}
				}
			}
		}
	}
}
Status SiGetPropertyList(const char *type_name,
		const char ***property_types,
		const char ***property_names,
		int *property_count)
{
	return get_property_list(type_name, property_types, property_names, property_count);
}
Esempio n. 4
0
void Object::clear_internal_resource_paths() {

	List<PropertyInfo> pinfo;

	get_property_list(&pinfo);

	for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {

		_clear_internal_resource_paths(get(E->get().name));
	}
}
Esempio n. 5
0
void ScriptInstance::get_property_state(List<Pair<StringName, Variant> > &state) {

	List<PropertyInfo> pinfo;
	get_property_list(&pinfo);
	for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {

		if (E->get().usage&PROPERTY_USAGE_STORAGE) {
			Pair<StringName,Variant> p;
			p.first=E->get().name;
			if (get(p.first,p.second))
				state.push_back(p);
		}
	}
}
Esempio n. 6
0
Node *Node::duplicate() const {


	Node *node=NULL;

	Object *obj = ObjectTypeDB::instance(get_type());
	ERR_FAIL_COND_V(!obj,NULL);
	node = obj->cast_to<Node>();
	if (!node)
		memdelete(obj);
	ERR_FAIL_COND_V(!node,NULL);



	if (get_filename()!="") { //an instance
		node->set_filename(get_filename());
	}

	List<PropertyInfo> plist;

	get_property_list(&plist);

	for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {

		if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
			continue;
		String name = E->get().name;
		node->set( name, get(name) );

	}

	node->set_name(get_name());

	for(int i=0;i<get_child_count();i++) {

		if (get_child(i)->data.parent_owned)
			continue;
		Node *dup = get_child(i)->duplicate();
		if (!dup) {

			memdelete(node);
			return NULL;
		}

		node->add_child(dup);
	}

	return node;
}
Esempio n. 7
0
void Object::get_translatable_strings(List<String> *p_strings) const {

	List<PropertyInfo> plist;
	get_property_list(&plist);

	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

		if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED))
			continue;

		String text = get(E->get().name);

		if (text == "")
			continue;

		p_strings->push_back(text);
	}
}
Esempio n. 8
0
uint32_t Resource::hash_edited_version() const {

	uint32_t hash = hash_djb2_one_32(get_edited_version());

	List<PropertyInfo> plist;
	get_property_list(&plist);

	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

		if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) {
			RES res = get(E->get().name);
			if (res.is_valid()) {
				hash = hash_djb2_one_32(res->hash_edited_version(), hash);
			}
		}
	}

	return hash;
}
Esempio n. 9
0
void Node::generate_instance_state() {

	List<PropertyInfo> properties;
	get_property_list(&properties);

	data.instance_state.clear();

	for( List<PropertyInfo>::Element *E=properties.front();E;E=E->next() ) {

		PropertyInfo &pi=E->get();
		if ((pi.usage&PROPERTY_USAGE_NO_INSTANCE_STATE) || !(pi.usage&PROPERTY_USAGE_EDITOR) || !(pi.usage&PROPERTY_USAGE_STORAGE))
			continue;

		data.instance_state[pi.name]=get(pi.name);
	}

	List<GroupInfo> groups;
	get_groups(&groups);
	for(List<GroupInfo>::Element *E=groups.front();E;E=E->next()) {

		if (!E->get().persistent)
			continue;
		data.instance_groups.push_back(E->get().name);
	}

	List<MethodInfo> signal_list;

	get_signal_list(&signal_list);

	for(List<MethodInfo>::Element *E=signal_list.front();E;E=E->next()) {

		StringName name = E->get().name;
		List<Connection> connections;
		get_signal_connection_list(name,&connections);

		for(List<Connection>::Element *F=connections.front();F;F=F->next()) {

			if (F->get().flags&CONNECT_PERSIST)
				data.instance_connections.push_back(F->get());
		}

	}
}
Esempio n. 10
0
Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const {


	ERR_FAIL_COND_V(get_filename()!="",NULL);

	Node *node=NULL;

	Object *obj = ObjectTypeDB::instance(get_type());
	if (!obj) {
		print_line("could not duplicate: "+String(get_type()));
	}
	ERR_FAIL_COND_V(!obj,NULL);
	node = obj->cast_to<Node>();
	if (!node)
		memdelete(obj);
	ERR_FAIL_COND_V(!node,NULL);

	node->set_name(get_name());

	List<PropertyInfo> plist;

	get_property_list(&plist);

	for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {

		if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
			continue;
		String name = E->get().name;
		node->set( name, get(name) );

	}


	for(int i=0;i<get_child_count();i++) {

		get_child(i)->_duplicate_and_reown(node,p_reown_map);
	}

	_duplicate_signals(this,node);
	return node;

}
Esempio n. 11
0
Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {

	List<PropertyInfo> plist;
	get_property_list(&plist);

	Resource *r = (Resource *)ClassDB::instance(get_class());
	ERR_FAIL_COND_V(!r, Ref<Resource>());

	r->local_scene = p_for_scene;

	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

		if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
			continue;
		Variant p = get(E->get().name);
		if (p.get_type() == Variant::OBJECT) {

			RES sr = p;
			if (sr.is_valid()) {

				if (sr->is_local_to_scene()) {
					if (remap_cache.has(sr)) {
						p = remap_cache[sr];
					} else {

						RES dupe = sr->duplicate_for_local_scene(p_for_scene, remap_cache);
						p = dupe;
						remap_cache[sr] = dupe;
					}
				}
			}
		}

		r->set(E->get().name, p);
	}

	return Ref<Resource>(r);
}
Esempio n. 12
0
void Node::replace_by(Node* p_node,bool p_keep_data) {

	ERR_FAIL_NULL(p_node);
	ERR_FAIL_COND(p_node->data.parent);

	List<Node*> owned = data.owned;
	List<Node*> owned_by_owner;
	Node *owner = (data.owner==this)?p_node:data.owner;

	List<_NodeReplaceByPair> replace_data;

	if (p_keep_data) {

		List<PropertyInfo> plist;
		get_property_list(&plist);

		for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next() ) {

			_NodeReplaceByPair rd;
			if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
				continue;
			rd.name=E->get().name;
			rd.value=get(rd.name);
		}
	}

	if (data.owner) {
		for(int i=0;i<get_child_count();i++)
			find_owned_by(data.owner,get_child(i),&owned_by_owner);
	}

	Node *parent = data.parent;
	int pos_in_parent = data.pos;

	if (data.parent) {

		parent->remove_child(this);
		parent->add_child(p_node);
		parent->move_child(p_node,pos_in_parent);
	}

	while(get_child_count()) {

		Node * child = get_child(0);
		remove_child(child);
		p_node->add_child(child);
	}

	p_node->set_owner(owner);
	for(int i=0;i<owned.size();i++)
		owned[i]->set_owner(p_node);

	for(int i=0;i<owned_by_owner.size();i++)
		owned_by_owner[i]->set_owner(owner);

	p_node->set_filename(get_filename());

	for (List<_NodeReplaceByPair>::Element *E=replace_data.front();E;E=E->next()) {

		p_node->set(E->get().name,E->get().value);
	}

}
Esempio n. 13
0
void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const {

	if (get_owner()!=get_parent()->get_owner())
		return;

	Node *node=NULL;

	if (get_filename()!="") {

		Ref<PackedScene> res = ResourceLoader::load(get_filename());
		ERR_FAIL_COND(res.is_null());
		node=res->instance();
		ERR_FAIL_COND(!node);
	} else {

		Object *obj = ObjectTypeDB::instance(get_type());
		if (!obj) {
			print_line("could not duplicate: "+String(get_type()));
		}
		ERR_FAIL_COND(!obj);
		node = obj->cast_to<Node>();
		if (!node)
			memdelete(obj);
	}


	List<PropertyInfo> plist;

	get_property_list(&plist);

	for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {

		if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
			continue;
		String name = E->get().name;
		node->set( name, get(name) );

	}

	node->set_name(get_name());
	p_new_parent->add_child(node);

	Node *owner=get_owner();

	if (p_reown_map.has(owner))
		owner=p_reown_map[owner];


	if (owner) {
		NodePath p = get_path_to(owner);
		if (owner!=this) {
			Node *new_owner = node->get_node(p);
			if (new_owner) {
				node->set_owner(new_owner);
			}
		}
	}

	for(int i=0;i<get_child_count();i++) {

		get_child(i)->_duplicate_and_reown(node,p_reown_map);
	}

}
Esempio n. 14
0
Node *Node::duplicate(bool p_use_instancing) const {


	Node *node=NULL;

	bool instanced=false;

	if (p_use_instancing && get_filename()!=String()) {

		Ref<PackedScene> res = ResourceLoader::load(get_filename());
		ERR_FAIL_COND_V(res.is_null(),NULL);
		node=res->instance();
		ERR_FAIL_COND_V(!node,NULL);

		instanced=true;

	} else {

		Object *obj = ObjectTypeDB::instance(get_type());
		ERR_FAIL_COND_V(!obj,NULL);
		node = obj->cast_to<Node>();
		if (!node)
			memdelete(obj);
		ERR_FAIL_COND_V(!node,NULL);
	}


	if (get_filename()!="") { //an instance
		node->set_filename(get_filename());
	}

	List<PropertyInfo> plist;

	get_property_list(&plist);

	for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {

		if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
			continue;
		String name = E->get().name;
		node->set( name, get(name) );

	}

	node->set_name(get_name());

	for(int i=0;i<get_child_count();i++) {

		if (get_child(i)->data.parent_owned)
			continue;
		if (instanced && get_child(i)->data.owner==this)
			continue; //part of instance

		Node *dup = get_child(i)->duplicate(p_use_instancing);
		if (!dup) {

			memdelete(node);
			return NULL;
		}

		node->add_child(dup);
	}

	return node;
}
Esempio n. 15
0
Array Object::_get_property_list_bind() const {

	List<PropertyInfo> lpi;
	get_property_list(&lpi);
	return convert_property_list(&lpi);
}