Skip to content

Resolve template tileset source relative to the template file - #187

Merged
fallahn merged 1 commit into
fallahn:masterfrom
vtxe02023274:fix-template-tileset-path
Nov 18, 2026
Merged

fallahn merged 1 commit into
fallahn:masterfrom
vtxe02023274:fix-template-tileset-path

Conversation

@vtxe02023274

Copy link
Copy Markdown
Contributor

Object templates in a subfolder could not load their tileset.

Tiled writes <tileset source> inside a .tx file relative to the template file, but parseTemplate resolved it against the map directory.

data/maps/m.tmx               <object template="templates/enemy.tx"/>
data/maps/templates/enemy.tx  <tileset firstgid="1" source="../../tilesets/enemies.tsx"/>
data/tilesets/enemies.tsx

Loading data/maps/m.tmx before this change:

ERROR: Failed to read file tilesets/enemies.tsx

The template path was also built as getWorkingDirectory() + "/" + path, so loading m.tmx from its own folder (empty working dir) tried /templates/enemy.tx:

ERROR: Failed opening template file templates/enemy.tx

Both now go through resolveFilePath, and the template tileset gets the template's directory as its working dir. Templates next to the map resolve exactly as before.

Tested with MinGW g++ on Windows: the case above loads from data/maps/m.tmx, from inside data/maps, and with an absolute C:\... path. ParseTest output is identical before and after (all resolveFilePath checks OK).

Tiled writes the tileset source inside a .tx file relative to the
template, but it was resolved against the map directory, so a template
in a subfolder failed to load its tileset. The template path itself was
built with map dir + "/", which became "/templates/x.tx" when the map
was loaded from the current directory. Use resolveFilePath for both.
@fallahn
fallahn merged commit 98f27a6 into fallahn:master Nov 18, 2026
9 checks passed
@fallahn

fallahn commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants