Monday, September 16, 2019

Custom git diff tool for Tiled

As I'm currently developing Tiny Little Slug and I use tiled for the levels I had the frequent issue that I wanted to compare .tmx files over the history of the game. As .tmx files are rather difficult to parse with the human brain I thought it must be possible to get an automated image export from tiled. And I was lucky. Here is my approach:

Create a text file with this content. I name it tileddiff.

#!/bin/bash

tmxrasterizer "$1" /tmp/local.png || exit 1
tmxrasterizer "$2" /tmp/remote.png || exit 1
compare /tmp/local.png /tmp/remote.png /tmp/view.png
eog /tmp/view.png


Save it at a preferred place and make it executable.
Edit your ~/.gitconfig and add these lines at the end:

[difftool "tiled"]
    cmd = /home/derp/bin/tileddiff "$LOCAL" "$REMOTE"

Then use this call to let's say compare the current state to the last one.

git difftool -t tiled HEAD~1

You should see a nice visualization where all changed tiles are highlighted in red.

Possible Problems:
Please keep in mind that this only compares .tmx files. If you have external dependencies like .png or .tsx files this approach will probably not work.
Differences between .tsx files are easy to observe though.
And comparing .png files is a different story. But the approach presented here will work for .png files as well ;-)

No comments:

Post a Comment