void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture> &p_texture, const Ref<Texture> &p_small_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) {

	preview_mutex->lock();

	String path = p_str;
	uint32_t hash = 0;
	uint64_t modified_time = 0;

	if (p_str.begins_with("ID:")) {
		hash = p_str.get_slicec(':', 2).to_int();
		path = "ID:" + p_str.get_slicec(':', 1);
	} else {
		modified_time = FileAccess::get_modified_time(path);
	}

	Item item;
	item.order = order++;
	item.preview = p_texture;
	item.small_preview = p_small_texture;
	item.last_hash = hash;
	item.modified_time = modified_time;

	cache[path] = item;

	preview_mutex->unlock();

	MessageQueue::get_singleton()->push_call(id, p_func, path, p_texture, p_small_texture, p_ud);
}
Example #2
0
bool ButtonArray::_get(const StringName &p_name, Variant &r_ret) const {

	String n = String(p_name);
	if (n.begins_with("button/")) {

		String what = n.get_slicec('/', 1);
		if (what == "count") {
			r_ret = buttons.size();
		} else if (what == "align") {
			r_ret = get_align();
		} else if (what == "selected") {
			r_ret = get_selected();
		} else if (what == "min_button_size") {
			r_ret = min_button_size;
		} else {
			int idx = what.to_int();
			ERR_FAIL_INDEX_V(idx, buttons.size(), false);
			String f = n.get_slicec('/', 2);
			if (f == "text")
				r_ret = buttons[idx].text;
			else if (f == "tooltip")
				r_ret = buttons[idx].tooltip;
			else if (f == "icon")
				r_ret = buttons[idx].icon;
			else
				return false;
		}

		return true;
	}

	return false;
}
Example #3
0
void EditorResourcePreview::_preview_ready(const String& p_str,const Ref<Texture>& p_texture,ObjectID id,const StringName& p_func,const Variant& p_ud) {

	//print_line("preview is ready");
	preview_mutex->lock();

	String path = p_str;
	uint32_t hash=0;
	uint64_t modified_time=0;

	if (p_str.begins_with("ID:")) {
		hash=p_str.get_slicec(':',2).to_int();
		path="ID:"+p_str.get_slicec(':',1);
	} else {
		modified_time = FileAccess::get_modified_time(path);
	}

	Item item;
	item.order=order++;
	item.preview=p_texture;
	item.last_hash=hash;
	item.modified_time=modified_time;

	cache[path]=item;

	Object *recv = ObjectDB::get_instance(id);
	if (recv) {
		recv->call_deferred(p_func,path,p_texture,p_ud);
	}

	preview_mutex->unlock();
}
Example #4
0
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {

	String name = p_name;
	if (name.begins_with("item/")) {

		int idx = name.get_slicec('/', 1).to_int();
		String what = name.get_slicec('/', 2);
		if (!item_map.has(idx))
			create_item(idx);

		if (what == "name")
			set_item_name(idx, p_value);
		else if (what == "mesh")
			set_item_mesh(idx, p_value);
		else if (what == "shape") {
			Vector<ShapeData> shapes;
			ShapeData sd;
			sd.shape = p_value;
			shapes.push_back(sd);
			set_item_shapes(idx, shapes);
		} else if (what == "shapes") {
			_set_item_shapes(idx, p_value);
		} else if (what == "preview")
			set_item_preview(idx, p_value);
		else if (what == "navmesh")
			set_item_navmesh(idx, p_value);
		else
			return false;

		return true;
	}

	return false;
}
Example #5
0
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const {

	String name = p_name;

	if (name == "theme") {
		r_ret = get_theme();
	} else if (name == "cell_size") {
		r_ret = get_cell_size();
	} else if (name == "cell_octant_size") {
		r_ret = get_octant_size();
	} else if (name == "cell_center_x") {
		r_ret = get_center_x();
	} else if (name == "cell_center_y") {
		r_ret = get_center_y();
	} else if (name == "cell_center_z") {
		r_ret = get_center_z();
	} else if (name == "cell_scale") {
		r_ret = cell_scale;
	} else if (name == "data") {

		Dictionary d;

		PoolVector<int> cells;
		cells.resize(cell_map.size() * 3);
		{
			PoolVector<int>::Write w = cells.write();
			int i = 0;
			for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) {

				encode_uint64(E->key().key, (uint8_t *)&w[i * 3]);
				encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]);
			}
		}

		d["cells"] = cells;

		r_ret = d;
	} else if (name.begins_with("areas/")) {
		int which = name.get_slicec('/', 1).to_int();
		String what = name.get_slicec('/', 2);
		if (what == "bounds")
			r_ret = area_get_bounds(which);
		else if (what == "name")
			r_ret = area_get_name(which);
		else if (what == "disable_distance")
			r_ret = area_get_portal_disable_distance(which);
		else if (what == "exterior_portal")
			r_ret = area_is_exterior_portal(which);
		else
			return false;
	} else
		return false;

	return true;
}
Example #6
0
bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {

	String name = p_name;

	if (name == "playback/speed") { //bw compatibility

		r_ret = speed_scale;
	} else if (name == "playback/active") {

		r_ret = is_active();
	} else if (name == "playback/play") {

		if (is_active() && is_playing())
			r_ret = playback.assigned;
		else
			r_ret = "[stop]";

	} else if (name.begins_with("anims/")) {

		String which = name.get_slicec('/', 1);

		r_ret = get_animation(which).get_ref_ptr();
	} else if (name.begins_with("next/")) {

		String which = name.get_slicec('/', 1);

		r_ret = animation_get_next(which);

	} else if (name == "blend_times") {

		Vector<BlendKey> keys;
		for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) {

			keys.ordered_insert(E->key());
		}

		Array array;
		for (int i = 0; i < keys.size(); i++) {

			array.push_back(keys[i].from);
			array.push_back(keys[i].to);
			array.push_back(blend_times[keys[i]]);
		}

		r_ret = array;
	} else if (name == "autoplay") {
		r_ret = autoplay;

	} else
		return false;

	return true;
}
Example #7
0
bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {

	String name = p_name;

	if (p_name == SceneStringNames::get_singleton()->playback_speed || p_name == SceneStringNames::get_singleton()->speed) { //bw compatibility
		set_speed_scale(p_value);

	} else if (p_name == SceneStringNames::get_singleton()->playback_active) {
		set_active(p_value);
	} else if (name.begins_with("playback/play")) {

		String which = p_value;

		if (which == "[stop]")
			stop();
		else
			play(which);
	} else if (name.begins_with("anims/")) {

		String which = name.get_slicec('/', 1);

		add_animation(which, p_value);
	} else if (name.begins_with("next/")) {

		String which = name.get_slicec('/', 1);
		animation_set_next(which, p_value);

	} else if (p_name == SceneStringNames::get_singleton()->blend_times) {

		Array array = p_value;
		int len = array.size();
		ERR_FAIL_COND_V(len % 3, false);

		for (int i = 0; i < len / 3; i++) {

			StringName from = array[i * 3 + 0];
			StringName to = array[i * 3 + 1];
			float time = array[i * 3 + 2];

			set_blend_time(from, to, time);
		}

	} else if (p_name == SceneStringNames::get_singleton()->autoplay) {
		autoplay = p_value;

	} else
		return false;

	return true;
}
Example #8
0
bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) {

	String n = String(p_name);
	if (n.begins_with("button/")) {

		String what = n.get_slicec('/', 1);
		if (what == "count") {
			int new_size = p_value;
			if (new_size > 0 && buttons.size() == 0) {
				selected = 0;
			}

			if (new_size < buttons.size()) {
				if (selected >= new_size)
					selected = new_size - 1;
			}
			buttons.resize(new_size);
			_change_notify();
			minimum_size_changed();
		} else if (what == "align") {
			set_align(Align(p_value.operator int()));
		} else if (what == "selected") {
			set_selected(p_value);
		} else if (what == "min_button_size") {
			min_button_size = p_value;
		} else {
			int idx = what.to_int();
			ERR_FAIL_INDEX_V(idx, buttons.size(), false);
			String f = n.get_slicec('/', 2);
			if (f == "text") {
				buttons[idx].text = p_value;
				buttons[idx].xl_text = XL_MESSAGE(p_value);
			} else if (f == "tooltip")
				buttons[idx].tooltip = p_value;
			else if (f == "icon")
				buttons[idx].icon = p_value;
			else
				return false;
		}

		update();
		return true;
	}

	return false;
}
Example #9
0
bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {

	String name = p_name;
	int idx = name.get_slicec('/', 1).to_int();
	ERR_FAIL_COND_V(!item_map.has(idx), false);
	String what = name.get_slicec('/', 2);

	if (what == "name")
		r_ret = get_item_name(idx);
	else if (what == "mesh")
		r_ret = get_item_mesh(idx);
	else if (what == "shapes")
		r_ret = _get_item_shapes(idx);
	else if (what == "navmesh")
		r_ret = get_item_navmesh(idx);
	else if (what == "preview")
		r_ret = get_item_preview(idx);
	else
		return false;

	return true;
}
Example #10
0
PropertyInfo MethodBind::get_argument_info(int p_argument) const {

	if (p_argument >= 0) {

		String name = (p_argument < arg_names.size()) ? String(arg_names[p_argument]) : String("arg" + itos(p_argument));
		PropertyInfo pi(get_argument_type(p_argument), name);
		if ((pi.type == Variant::OBJECT) && name.find(":") != -1) {
			pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
			pi.hint_string = name.get_slicec(':', 1);
			pi.name = name.get_slicec(':', 0);
		}
		return pi;

	} else {

		Variant::Type at = get_argument_type(-1);
		if (at == Variant::OBJECT && ret_type)
			return PropertyInfo(at, "ret", PROPERTY_HINT_RESOURCE_TYPE, ret_type);
		else
			return PropertyInfo(at, "ret");
	}

	return PropertyInfo();
}
Example #11
0
bool GridMap::_set(const StringName &p_name, const Variant &p_value) {

	String name = p_name;

	if (name == "theme") {

		set_theme(p_value);
	} else if (name == "cell_size") {
		set_cell_size(p_value);
	} else if (name == "cell_octant_size") {
		set_octant_size(p_value);
	} else if (name == "cell_center_x") {
		set_center_x(p_value);
	} else if (name == "cell_center_y") {
		set_center_y(p_value);
	} else if (name == "cell_center_z") {
		set_center_z(p_value);
	} else if (name == "cell_scale") {
		set_cell_scale(p_value);
		/*	} else if (name=="cells") {
		PoolVector<int> cells = p_value;
		int amount=cells.size();
		PoolVector<int>::Read r = cells.read();
		ERR_FAIL_COND_V(amount&1,false); // not even
		cell_map.clear();
		for(int i=0;i<amount/3;i++) {


			IndexKey ik;
			ik.key=decode_uint64(&r[i*3]);
			Cell cell;
			cell.cell=uint32_t(r[i*+1]);
			cell_map[ik]=cell;

		}
		_recreate_octant_data();*/
	} else if (name == "data") {

		Dictionary d = p_value;

		if (d.has("cells")) {

			PoolVector<int> cells = d["cells"];
			int amount = cells.size();
			PoolVector<int>::Read r = cells.read();
			ERR_FAIL_COND_V(amount % 3, false); // not even
			cell_map.clear();
			for (int i = 0; i < amount / 3; i++) {

				IndexKey ik;
				ik.key = decode_uint64((const uint8_t *)&r[i * 3]);
				Cell cell;
				cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]);
				cell_map[ik] = cell;
			}
		}
		_recreate_octant_data();

	} else if (name.begins_with("areas/")) {
		int which = name.get_slicec('/', 1).to_int();
		String what = name.get_slicec('/', 2);
		if (what == "bounds") {
			ERR_FAIL_COND_V(area_map.has(which), false);
			create_area(which, p_value);
			return true;
		}

		ERR_FAIL_COND_V(!area_map.has(which), false);

		if (what == "name")
			area_set_name(which, p_value);
		else if (what == "disable_distance")
			area_set_portal_disable_distance(which, p_value);
		else if (what == "exterior_portal")
			area_set_portal_disable_color(which, p_value);
		else
			return false;
	} else
		return false;

	return true;
}
Example #12
0
Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const {

	Error err;
	FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);

	if (!f) {
		if (r_valid) {
			*r_valid = false;
		}
		return err;
	}

	VariantParser::StreamFile stream;
	stream.f = f;

	String assign;
	Variant value;
	VariantParser::Tag next_tag;

	if (r_valid) {
		*r_valid = true;
	}

	int lines = 0;
	String error_text;
	bool path_found = false; //first match must have priority
	while (true) {

		assign = Variant();
		next_tag.fields.clear();
		next_tag.name = String();

		err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
		if (err == ERR_FILE_EOF) {
			memdelete(f);
			return OK;
		} else if (err != OK) {
			ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
			memdelete(f);
			return err;
		}

		if (assign != String()) {
			if (!path_found && assign.begins_with("path.") && r_path_and_type.path == String()) {
				String feature = assign.get_slicec('.', 1);
				if (OS::get_singleton()->has_feature(feature)) {
					r_path_and_type.path = value;
					path_found = true; //first match must have priority
				}

			} else if (!path_found && assign == "path") {
				r_path_and_type.path = value;
				path_found = true; //first match must have priority
			} else if (assign == "type") {
				r_path_and_type.type = value;
			} else if (assign == "importer") {
				r_path_and_type.importer = value;
			} else if (assign == "group_file") {
				r_path_and_type.group_file = value;
			} else if (assign == "metadata") {
				r_path_and_type.metadata = value;
			} else if (assign == "valid") {
				if (r_valid) {
					*r_valid = value;
				}
			}

		} else if (next_tag.name != "remap") {
			break;
		}
	}

	memdelete(f);

	if (r_path_and_type.path == String() || r_path_and_type.type == String()) {
		return ERR_FILE_CORRUPT;
	}
	return OK;
}