Example #1
0
Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
	FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
	bool exists = f && f->is_open();

	String tempFile = get_user_data_dir();
	if (!exists)
		return FAILED;

	if (p_path.begins_with("res://")) {
		if (PackedData::get_singleton()->has_path(p_path)) {
			print("Unable to play %S using the native player as it resides in a .pck file\n", p_path.c_str());
			return ERR_INVALID_PARAMETER;
		} else {
			p_path = p_path.replace("res:/", ProjectSettings::get_singleton()->get_resource_path());
		}
	} else if (p_path.begins_with("user://"))
		p_path = p_path.replace("user:/", get_user_data_dir());

	memdelete(f);

	print("Playing video: %S\n", p_path.c_str());
	if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track))
		return OK;
	return FAILED;
}
Example #2
0
void EditorHelp::_class_desc_select(const String& p_select) {



//	print_line("LINK: "+p_select);
	if (p_select.begins_with("#")) {
		//_goto_desc(p_select.substr(1,p_select.length()));
		emit_signal("go_to_help","class_name:"+p_select.substr(1,p_select.length()));
		return;
	} else if (p_select.begins_with("@")) {

		String m = p_select.substr(1,p_select.length());

		if (m.find(".")!=-1) {
			//must go somewhere else

			emit_signal("go_to_help","class_method:"+m.get_slice(".",0)+":"+m.get_slice(".",0));
		} else {

			if (!method_line.has(m))
				return;
			class_desc->scroll_to_line(method_line[m]);
		}

	}


}
Example #3
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 #4
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 #5
0
String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) {

	if (translation_remaps.has(p_path)) {

		Vector<String> &v = *translation_remaps.getptr(p_path);
		String locale = TranslationServer::get_singleton()->get_locale();
		if (r_translation_remapped) {
			*r_translation_remapped = true;
		}
		for (int i = 0; i < v.size(); i++) {

			int split = v[i].find_last(":");
			if (split == -1)
				continue;
			String l = v[i].right(split + 1).strip_edges();
			if (l == String())
				continue;

			if (l.begins_with(locale)) {
				return v[i].left(split);
			}
		}
	}

	return p_path;
}
Example #6
0
void RotatedFileLogger::clear_old_backups() {
	int max_backups = max_files - 1; // -1 for the current file

	String basename = base_path.get_file().get_basename();
	String extension = "." + base_path.get_extension();

	DirAccess *da = DirAccess::open(base_path.get_base_dir());
	if (!da) {
		return;
	}

	da->list_dir_begin();
	String f = da->get_next();
	Set<String> backups;
	while (f != String()) {
		if (!da->current_is_dir() && f.begins_with(basename) && f.ends_with(extension) && f != base_path.get_file()) {
			backups.insert(f);
		}
		f = da->get_next();
	}
	da->list_dir_end();

	if (backups.size() > max_backups) {
		// since backups are appended with timestamp and Set iterates them in sorted order,
		// first backups are the oldest
		int to_delete = backups.size() - max_backups;
		for (Set<String>::Element *E = backups.front(); E && to_delete > 0; E = E->next(), --to_delete) {
			da->remove(E->get());
		}
	}

	memdelete(da);
}
Example #7
0
void EditorDirDialog::_update_dir(TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path) {

	updating = true;

	String path = p_dir->get_path();

	p_item->set_metadata(0, p_dir->get_path());
	p_item->set_icon(0, get_icon("Folder", "EditorIcons"));

	if (!p_item->get_parent()) {
		p_item->set_text(0, "res://");
	} else {

		if (!opened_paths.has(path) && (p_select_path == String() || !p_select_path.begins_with(path))) {
			p_item->set_collapsed(true);
		}

		p_item->set_text(0, p_dir->get_name());
	}

	//this should be handled by EditorFileSystem already
	//bool show_hidden = EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files");
	updating = false;
	for (int i = 0; i < p_dir->get_subdir_count(); i++) {

		TreeItem *ti = tree->create_item(p_item);
		_update_dir(ti, p_dir->get_subdir(i));
	}
}
Example #8
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 #9
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 #10
0
void FileDialog::_update_drives() {


	int dc = dir_access->get_drive_count();
	if (dc==0 || access!=ACCESS_FILESYSTEM) {
		drives->hide();
	} else {
		drives->clear();
		drives->show();

		int current=-1;
		String abspath = dir_access->get_current_dir();

		for(int i=0;i<dir_access->get_drive_count();i++) {
			String d = dir_access->get_drive(i);
			if (abspath.begins_with(d))
				current=i;
			drives->add_item(dir_access->get_drive(i));
		}

		if (current!=-1)
			drives->select(current);

	}
}
void EditorFileDialog::_save_to_recent() {

	String dir = get_current_dir();
	Vector<String> recent = EditorSettings::get_singleton()->get_recent_dirs();

	const int max=20;
	int count=0;
	bool res=dir.begins_with("res://");

	for(int i=0;i<recent.size();i++) {
		bool cres=recent[i].begins_with("res://");
		if (recent[i]==dir || (res==cres && count>max)) {
			recent.remove(i);
			i--;
		} else {
			count++;
		}
	}

	recent.insert(0,dir);

	EditorSettings::get_singleton()->set_recent_dirs(recent);


}
void MeshLibraryEditor::_menu_cbk(int p_option) {

	option=p_option;
	switch(p_option) {

		case MENU_OPTION_ADD_ITEM: {

			theme->create_item(theme->get_last_unused_item_id());
		} break;
		case MENU_OPTION_REMOVE_ITEM: {

			String p = editor->get_property_editor()->get_selected_path();
			if (p.begins_with("/MeshLibrary/item") && p.get_slice_count("/")>=3) {

				to_erase = p.get_slice("/",3).to_int();
				cd->set_text(vformat(TTR("Remove item %d?"),to_erase));
				cd->popup_centered(Size2(300,60));
			}
		} break;
		case MENU_OPTION_IMPORT_FROM_SCENE: {

			file->popup_centered_ratio();
		} break;
		 case MENU_OPTION_UPDATE_FROM_SCENE: {

			 cd->set_text("Update from existing scene?:\n"+String(theme->get_meta("_editor_source_scene")));
			 cd->popup_centered(Size2(500,60));
		 } break;
	}
}
Example #13
0
void FindInFiles::_scan_dir(String path, PoolStringArray &out_folders) {

	DirAccess *dir = DirAccess::open(path);
	if (dir == NULL) {
		print_line("Cannot open directory! " + path);
		return;
	}

	dir->list_dir_begin();

	for (int i = 0; i < 1000; ++i) {
		String file = dir->get_next();

		if (file == "")
			break;

		// Ignore special dirs and hidden dirs (such as .git and .import)
		if (file == "." || file == ".." || file.begins_with("."))
			continue;

		if (dir->current_is_dir())
			out_folders.append(file);

		else {
			String file_ext = file.get_extension();
			if (_extension_filter.has(file_ext)) {
				_files_to_scan.push_back(path.plus_file(file));
			}
		}
	}
}
Example #14
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();
}
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 #16
0
String ProjectSettings::localize_path(const String &p_path) const {

	if (resource_path == "")
		return p_path; //not initialized yet

	if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
			(p_path.is_abs_path() && !p_path.begins_with(resource_path)))
		return p_path.simplify_path();

	DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);

	String path = p_path.replace("\\", "/").simplify_path();

	if (dir->change_dir(path) == OK) {

		String cwd = dir->get_current_dir();
		cwd = cwd.replace("\\", "/");

		memdelete(dir);

		if (!cwd.begins_with(resource_path)) {
			return p_path;
		};

		return cwd.replace_first(resource_path, "res:/");
	} else {

		memdelete(dir);

		int sep = path.find_last("/");
		if (sep == -1) {
			return "res://" + path;
		};

		String parent = path.substr(0, sep);

		String plocal = localize_path(parent);
		if (plocal == "") {
			return "";
		};
		return plocal + path.substr(sep, path.size() - sep);
	};
}
Example #17
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 #18
0
Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) {

	ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
	ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER);
	ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
	ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA);

	String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
	if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) {
		// Don't append the standard ports
		request += "Host: " + conn_host + "\r\n";
	} else {
		request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
	}
	bool add_uagent = true;
	bool add_accept = true;
	bool add_clen = p_body.length() > 0;
	for (int i = 0; i < p_headers.size(); i++) {
		request += p_headers[i] + "\r\n";
		if (add_clen && p_headers[i].findn("Content-Length:") == 0) {
			add_clen = false;
		}
		if (add_uagent && p_headers[i].findn("User-Agent:") == 0) {
			add_uagent = false;
		}
		if (add_accept && p_headers[i].findn("Accept:") == 0) {
			add_accept = false;
		}
	}
	if (add_clen) {
		request += "Content-Length: " + itos(p_body.utf8().length()) + "\r\n";
		// Should it add utf8 encoding?
	}
	if (add_uagent) {
		request += "User-Agent: GodotEngine/" + String(VERSION_FULL_BUILD) + " (" + OS::get_singleton()->get_name() + ")\r\n";
	}
	if (add_accept) {
		request += "Accept: */*\r\n";
	}
	request += "\r\n";
	request += p_body;

	CharString cs = request.utf8();
	Error err = connection->put_data((const uint8_t *)cs.ptr(), cs.length());
	if (err) {
		close();
		status = STATUS_CONNECTION_ERROR;
		return err;
	}

	status = STATUS_REQUESTING;

	return OK;
}
Example #19
0
String ProjectSettings::globalize_path(const String &p_path) const {

	if (p_path.begins_with("res://")) {

		if (resource_path != "") {

			return p_path.replace("res:/", resource_path);
		};
		return p_path.replace("res://", "");
	} else if (p_path.begins_with("user://")) {

		String data_dir = OS::get_singleton()->get_user_data_dir();
		if (data_dir != "") {

			return p_path.replace("user:/", data_dir);
		};
		return p_path.replace("user://", "");
	}

	return p_path;
}
Example #20
0
void SpinBox::_text_entered(const String &p_string) {

	/*
	if (!p_string.is_numeric())
		return;
	*/
	String value = p_string;
	if (prefix != "" && p_string.begins_with(prefix))
		value = p_string.substr(prefix.length(), p_string.length() - prefix.length());
	set_value(value.to_double());
	_value_changed(0);
}
Example #21
0
	bool _get(const StringName &p_name, Variant &r_ret) const {

		String name = p_name;

		if (name.begins_with("bind/")) {
			int which = name.get_slice("/", 1).to_int() - 1;
			ERR_FAIL_INDEX_V(which, params.size(), false);
			r_ret = params[which];
		} else
			return false;

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

		String name = p_name;

		if (name.begins_with("bind/")) {
			int which = name.get_slice("/", 1).to_int() - 1;
			ERR_FAIL_INDEX_V(which, params.size(), false);
			params.write[which] = p_value;
		} else
			return false;

		return true;
	}
Example #23
0
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String& p_path) {

    if (!filesystem || scanning)
    	return NULL;


    String f = GlobalConfig::get_singleton()->localize_path(p_path);

    if (!f.begins_with("res://"))
    	return NULL;


    f=f.substr(6,f.length());
    f=f.replace("\\","/");
    if (f==String())
    	return filesystem;

    if (f.ends_with("/"))
	f=f.substr(0,f.length()-1);

    Vector<String> path = f.split("/");

    if (path.size()==0)
    	return NULL;

    EditorFileSystemDirectory *fs=filesystem;

    for(int i=0;i<path.size();i++) {


	int idx=-1;
	for(int j=0;j<fs->get_subdir_count();j++) {

	    if (fs->get_subdir(j)->get_name()==path[i]) {
		idx=j;
		break;
	    }
	}

	if (idx==-1) {
		return NULL;
	} else {

	    fs=fs->get_subdir(idx);
	}
    }

    return fs;
}
Example #24
0
bool test_27() {

	OS::get_singleton()->print("\n\nTest 27: begins_with\n");
	test_27_data tc[] = {
		{"res://foobar", "res://", true},
		{"res", "res://", false},
		{"abc", "abc", true}
	};
	size_t count = sizeof(tc) / sizeof(tc[0]);
	bool state = true;
	for (size_t i = 0;state && i < count; ++i) {
		String s = tc[i].data;
		state = s.begins_with(tc[i].begin) == tc[i].expected;
		if (state) {
			String sb = tc[i].begin;
			state = s.begins_with(sb) == tc[i].expected;
		}
		if (!state) {
			OS::get_singleton()->print("\n\t Failure on:\n\t\tstring: ", tc[i].data, "\n\t\tbegin: ", tc[i].begin, "\n\t\texpected: ", tc[i].expected ? "true" : "false", "\n");
			break;
		}
	};
	return state;
};
Example #25
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 #26
0
bool Skeleton::_set(const StringName& p_path, const Variant& p_value) {

	String path = p_path;

	if (!path.begins_with("bones/"))
		return false;
		
	int which=path.get_slice("/",1).to_int();
	String what=path.get_slice("/",2);


	if (which==bones.size() && what=="name") {
	
		add_bone(p_value);
		return true;
	}
	
	ERR_FAIL_INDEX_V( which, bones.size(), false );
	
	if (what=="parent")
		set_bone_parent(which, p_value );
	else if (what=="rest")
		set_bone_rest(which, p_value);
	else if (what=="enabled")
		set_bone_enabled(which, p_value);
	else if (what=="pose")
		set_bone_pose(which, p_value);
	else if (what=="bound_childs") {
		Array children=p_value;
		
		bones[which].nodes_bound.clear();
		
		for (int i=0;i<children.size();i++) {
		
			NodePath path=children[i];
			ERR_CONTINUE( path.operator String()=="" );
			Node *node = get_node(path);
			ERR_CONTINUE(!node);
			bind_child_node_to_bone(which,node);
		}
	} else {
		return false;
	}

	return true;
}
Example #27
0
void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) {

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

	if (!f)
		return;

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

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

	int lines = 0;
	String error_text;
	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;
		} else if (err != OK) {
			ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
			memdelete(f);
			return;
		}

		if (assign != String()) {
			if (assign.begins_with("path.")) {
				r_paths->push_back(value);
			} else if (assign == "path") {
				r_paths->push_back(value);
			}
		} else if (next_tag.name != "remap") {
			break;
		}
	}
	memdelete(f);
}
Example #28
0
void EditorAutoloadSettings::_autoload_add() {

	String name = autoload_add_name->get_text();

	String error;
	if (!_autoload_name_is_valid(name, &error)) {
		EditorNode::get_singleton()->show_warning(error);
		return;
	}

	String path = autoload_add_path->get_line_edit()->get_text();
	if (!FileAccess::exists(path)) {
		EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist."));
		return;
	}

	if (!path.begins_with("res://")) {
		EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("Not in resource path."));
		return;
	}

	name = "autoload/" + name;

	UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();

	undo_redo->create_action(TTR("Add AutoLoad"));
	undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);

	if (ProjectSettings::get_singleton()->has(name)) {
		undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
	} else {
		undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
	}

	undo_redo->add_do_method(this, "update_autoload");
	undo_redo->add_undo_method(this, "update_autoload");

	undo_redo->add_do_method(this, "emit_signal", autoload_changed);
	undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

	undo_redo->commit_action();

	autoload_add_path->get_line_edit()->set_text("");
	autoload_add_name->set_text("");
}
Example #29
0
void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {

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

		ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
		if (!ste)
			continue;

		List<int> bpoints;
		ste->get_text_edit()->get_breakpoints(&bpoints);

		Ref<Script> script = ste->get_edited_script();
		String base = script->get_path();
		ERR_CONTINUE( base.begins_with("local://") || base=="" );

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

			p_breakpoints->push_back(base+":"+itos(E->get()+1));
		}
	}

}
Example #30
0
String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) {

	String new_path = p_path;

	if (translation_remaps.has(new_path)) {

		Vector<String> &v = *translation_remaps.getptr(new_path);
		String locale = TranslationServer::get_singleton()->get_locale();
		if (r_translation_remapped) {
			*r_translation_remapped = true;
		}
		for (int i = 0; i < v.size(); i++) {

			int split = v[i].find_last(":");
			if (split == -1)
				continue;
			String l = v[i].right(split + 1).strip_edges();
			if (l == String())
				continue;

			if (l.begins_with(locale)) {
				new_path = v[i].left(split);
				break;
			}
		}
	}

	if (path_remaps.has(new_path)) {
		new_path = path_remaps[new_path];
	}

	if (new_path == p_path) { //did not remap
		//try file remap
		Error err;
		FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err);

		if (f) {

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

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

			int lines = 0;
			String error_text;
			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) {
					break;
				} else if (err != OK) {
					ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text);
					break;
				}

				if (assign == "path") {
					new_path = value;
					break;
				} else if (next_tag.name != "remap") {
					break;
				}
			}

			memdelete(f);
		}
	}

	return new_path;
}