tilegen.py tileset and tilemap generator

By pizzapower

Master (172)

pizzapower さんの画像

11-02-2022, 16:49

I just wanted to share a script I created that may help more people create their own game assets. Tilegen.py is a simple tileset and tilemap generator from static images. It also eliminates repeated tiles by MD5 signature comparison of the contents of the tiles. It requires ImageMagick and Python, but extra care was taken to make it OS agnostic so it should work under windows and mac too (I don't use windows myself, but I accept pull requests ;) ). In simple terms it turns this:

Into this:

Also, the generated tileset is formatted in a specified resolution (256x192 in this example for easy integration into your MSX game). Image is from Maniac Mansion.

ログイン/登録して投稿

By MsxKun

Paragon (1134)

MsxKun さんの画像

11-02-2022, 17:32

Hi!

This is a feature that TileStudio had integrated and I always missed to have in Tiled when I tried Tiled. So it's very welcome even if it's a standalone script.
Probably I can add it to the Gimp plugins too, so you can open(or edit) the image with Gimp, and export the Tileset/Tilemap.

Thx! Big smile

By MsxKun

Paragon (1134)

MsxKun さんの画像

11-02-2022, 17:44

Btw...
I'm trying. It seems it wont work on python versions under 3.8, due to walrus operator :=

By MsxKun

Paragon (1134)

MsxKun さんの画像

11-02-2022, 18:01

Ok, fixed the walrus problem by re-writing the 3 lines using it in the old style Wink
Then it complained about then check_calls... maybe for the same reason, too news python? So I commented the try lines, as I know ImageMagick is already on my system. And tho it still complains (ImageMagick says something about gray imanges(?) ) it works Smile
Next time I'll change it to also support a more standard .bin pure binary data export, Cool Thanks for the toy! I'm pretty much sure I'll use it many times. That was almost the last step to don't depend on TileStudio (wich I like, but makes me use wine :-P )

By pizzapower

Master (172)

pizzapower さんの画像

11-02-2022, 20:41

Hey MsxKun, thanks for the feedback! You can send me these and the next changes by PR. I will have a look and integrate them directly or maybe create a branch just for older versions of Python and put an explanation on how to access the other version in the docs. Glad to know it will be useful! Big smile

About the pure binary data export, I feel it is beyond the scope of this tool. I like small tools that can be combined together to do complex things. But maybe the GIMP plug-in idea is better suited for this kind of integration. If that's what you meant, then it is a great idea actually. I already have a GIMP plug-in written in Python, so maybe I will use it as a base.

About the weird ImageMagick warning, it seems like it tries to optimize away some metadata based on the colours it finds in a single image (there are lots of blank tiles in the sample). I will try some options to make it go away.

By MsxKun

Paragon (1134)

MsxKun さんの画像

12-02-2022, 10:25

Not sure what PR is. Private message or so? Not sure if there is any.
So easier... I changed

#if not (tile_dim := re.search('(\d+)x(\d+)', sys.argv[2])):  #<- this
tile_dim = re.search('(\d+)x(\d+)', sys.argv[2])   #<- to this
if not (tile_dim):
#if not (tileset_dim := re.search('(\d+)x(\d+)', sys.argv[4])):  #< this
tileset_dim = re.search('(\d+)x(\d+)', sys.argv[4]) #<- to this
if not (tileset_dim):
#tile_num = match.group(0) if (match := re.search("[0-9]+", filename)) else None  #< this
match = re.search("[0-9]+", filename)  #<- to this
tile_num = match.group(0) if (match) else None

This way Python 3.7 likes it. I should update someday, but in the time, and for my own use, it works.
also commented all this, for same reasons

    """ 
    try:
        check_call(['convert', '-help'], stdout=DEVNULL, stderr=STDOUT)
    except FileNotFoundError:
        sys.exit('Install ImageMagick or put magick in your path')

    try:
        check_call(['identify', '-help'], stdout=DEVNULL, stderr=STDOUT)
    except FileNotFoundError:
        sys.exit('Install ImageMagick or put identify in your path')

    try:
        check_call(['convert', '-help'], stdout=DEVNULL, stderr=STDOUT)
    except FileNotFoundError:
        sys.exit('Install ImageMagick or put convert in your path')
    """

By ren

Paragon (1947)

ren さんの画像

12-02-2022, 10:30

By PingPong

Enlighted (4156)

PingPong さんの画像

12-02-2022, 12:47

hi, did you take into account the infamous color clash in screen 2/4 modes?
did you try to map the original color into the msx1 fixed palette or to reduce the number of colors to 15 and reconfigure the palette if used on msx2?

By MsxKun

Paragon (1134)

MsxKun さんの画像

12-02-2022, 16:29

oh, if it's that, i don't have user in github. Too modern for me.

By MsxKun

Paragon (1134)

MsxKun さんの画像

12-02-2022, 16:54

PingPong wrote:

hi, did you take into account the infamous color clash in screen 2/4 modes?
did you try to map the original color into the msx1 fixed palette or to reduce the number of colors to 15 and reconfigure the palette if used on msx2?

The tool won't convert. Its not the purpose. It only creates the minimal tilset from a bigger image and the map to recreate it. Its up to you to convert the tileset one way or another. I do it with Gimp, usually.