Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps cannot be imported at runtime? #167

Open
al0fdf opened this issue Jan 5, 2023 · 0 comments
Open

Maps cannot be imported at runtime? #167

al0fdf opened this issue Jan 5, 2023 · 0 comments

Comments

@al0fdf
Copy link

al0fdf commented Jan 5, 2023

Plugin version
2.4 with Godot 3.5 stable. The Plugin was downloaded from github. Level was made using Tiled 1.4.3

Loading maps at runtime when running from the editor works, but maps cannot be imported at runtime from an exported build:

871 total_path ../../tilesets/cave.png
874 total_path tiled/levels/../tileset/../../tilesets/cave.png
876 total_path tilesets/cave.png
Tiled Importer: Image not found: tilesets/cave.png
Error when building Tiled scene: File: Not found error.

With the following bit of code modified in tiled_map_reader.gd:


# Loads an image from a given path
# Returns a Texture
func load_image(rel_path, source_path, options):
	
	print("Load image %s, %s, %s" % [rel_path, source_path, options])
	flags = options.image_flags if "image_flags" in options else Texture.FLAGS_DEFAULT
	var embed = options.embed_internal_images if "embed_internal_images" in options else false

	var ext = rel_path.get_extension().to_lower()
	if ext != "png" and ext != "jpg":
		print_error("Unsupported image format: %s. Use PNG or JPG instead." % [ext])
		return ERR_FILE_UNRECOGNIZED

	var total_path = rel_path
	print("871 total_path %s" % total_path)
	if rel_path.is_rel_path():
		total_path = ProjectSettings.globalize_path(source_path.get_base_dir()).plus_file(rel_path)
		print("874 total_path %s" % total_path)
	total_path = ProjectSettings.localize_path(total_path)
	
	print("876 total_path %s" % total_path)
	
	var dir = Directory.new()
	if not dir.file_exists(total_path):
		print_error("Image not found: %s" % [total_path])
		return ERR_FILE_NOT_FOUND

Part of my level loading code:

var levelPath = "res://tiled/levels/" + levelName + ".tmx"
	
	# create instance from vnen's Tiled importer to import the map
	var tiledMapReader = load("addons/vnen.tiled_importer/tiled_map_reader.gd").new()
	var optionsDict = {
		"add_background":true,
		"collision_layer":8,
		"custom_properties":true,
		"embed_internal_images":false,
		"image_flags":0,
		"post_import_script":null,
		"save_tiled_properties":true,
		"tile_metadata":false,
		"uv_clip":true
	}
	
	# build the level
	var result = tiledMapReader.build(levelPath, optionsDict)
	if typeof(result) == TYPE_INT:
		Logger.print_err(result, "Error when building Tiled scene: ")
		get_tree().quit()
	var scn : Node2D = result
	# procede to run custom code to handle spawning objects and such

It seems tilesets/cave.png cannot be found, even though it is in the project folder.

Tiled files
files.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant