News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Cwiiis

New CPC/Plus-focused tile-map editor

Started by Cwiiis, 13:19, 12 March 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Cwiiis

I've reached what I'd now call an alpha stage of a tile-map editor I've been working on for the last couple of weeks. The idea is that you'd use it in conjunction with an image editor - making the first draft of your level in something like Grafx2 or the GIMP and then importing it into this editor to tweak/edit/annotate. The editor has its own map format so you can save/load everything it can edit (which is handy to save annotations), it can import png images (which need to conform to CPC limitations and are validated) and it can export both png images and CPC-compatible binary data. It's written in Python and depends only on pytk (which is bundled with Python on most platforms) and pypng (which may or may not be, but is installable using pip). I wrote this quickly rather than neatly, so the code isn't amazing and there's plenty of scope to shrink/optimise. That isn't really the goal right now, though.

Why did I write this when something like tiled exists? tiled is very cool and I recommend checking it out, but I found it both massively overkill and under-featured for the very specific case of making tilemap-based games on the Amstrad Plus machines. I had a particular workflow in mind (start with image editor, use map editor to tweak/annotate/export) and this tool does exactly what I wanted it to do. It may not be suitable for your game, but I've tried to make it reasonably flexible at what it does and I'm open to suggestions :)

A particularly neat feature that I quite like is the 'Apply to similar' - if you have a feature in your map that reoccurs, you can select it, hit that button and the tags from the current selection will be applied to every reoccurrence of that set of tiles. This is super handy when you want to mark all ground tiles as solid, for example. The entity and metadata management sides of the app are pretty under-developed as none of my current projects are that far down the line, but they do work. Ideas/patches welcome!

You can download it/file bugs on Github: https://github.com/Cwiiis/maped/tree/main

OneVision


GUNHED

Please put this to non-CPC software, else we think this is software for the CPC / Plus, but get disappointed to see, that it only runs on PC. That would be kind.
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

Cwiiis

Quote from: GUNHED on 16:19, 12 March 24Please put this to non-CPC software, else we think this is software for the CPC / Plus, but get disappointed to see, that it only runs on PC. That would be kind.

There isn't a non-CPC software forum as far as I can see and this forum doesn't say CPC applications... This is why I put 'CPC/Plus-focused' in the title. I've also seen non-CPC apps posted here before, but if there's a more suitable place for it on this forum, I apologise! Let me know and I'll ask gryzor to move it there.

GUNHED

Seems things have changed. The 'other retro' is still there, but I can't find the other board.
Could be a good idea to have a board for 'PC software for CPC' or something like that. Because if one searches specific for PC stuff, then it's hard to find actually. 
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

HAL6128

Hi @Cwiiis,

just tried your tool with one of my maps (created in Grafx2). It has the size 240x336 because for scrolling. 16 colors mode 0.
Using Window11 with python 3.x installed.

I got this failure(?) message in the terminal during importing the png-file.

Any idea?
HAL6128

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python312\Lib\tkinter\__init__.py", line 1967, in __call__
    return self.func(*args)
          ^^^^^^^^^^^^^^^^
  File "D:\Downloads\maped-main\maped.py", line 1486, in <lambda>
    menu.add_command(label='Import...', underline=0, accelerator='Ctrl+I', command=lambda : import_file(root))
                                                                                            ^^^^^^^^^^^^^^^^^
  File "D:\Downloads\maped-main\maped.py", line 1221, in import_file
    ctx.palette = ['#%02x%02x%02x' % c for c in palette]
                  ~~~~~~~~~~~~~~~~^~~
TypeError: not all arguments converted during string formatting
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Cwiiis

Quote from: HAL6128 on 15:12, 14 March 24Hi @Cwiiis,

just tried your tool with one of my maps (created in Grafx2). It has the size 240x336 because for scrolling. 16 colors mode 0.
Using Window11 with python 3.x installed.

I got this failure(?) message in the terminal during importing the png-file.

Any idea?
HAL6128

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python312\Lib\tkinter\__init__.py", line 1967, in __call__
    return self.func(*args)
          ^^^^^^^^^^^^^^^^
  File "D:\Downloads\maped-main\maped.py", line 1486, in <lambda>
    menu.add_command(label='Import...', underline=0, accelerator='Ctrl+I', command=lambda : import_file(root))
                                                                                            ^^^^^^^^^^^^^^^^^
  File "D:\Downloads\maped-main\maped.py", line 1221, in import_file
    ctx.palette = ['#%02x%02x%02x' % c for c in palette]
                  ~~~~~~~~~~~~~~~~^~~
TypeError: not all arguments converted during string formatting

Having a quick look at the code, I'm guessing this PNG has an alpha channel(?) If you could attach a copy (or send me one privately if it's sensitive), I can debug and fix the issue - alternatively, if you can confirm there's an alpha channel and removing it fixes it, I'll push a fix.

Gryzor

There, I just changed the board title, better? 😁

HAL6128

Yeah @Cwiiis, you were right. It was the alpha channel which were set in Grafx2 (background colour). I unset it, saved the image again and now I can load into your tool.
Thanks for the hint.

Now I can "dig" into your tool further... :)
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

HAL6128

It automatically recognises similar tiles (count them also) if the settings are right (height x width).
Very nice!!

Do you have a description what I can also do?

I mean, your workflow is exactly what I also need. Lean and built for CPCs.
In the past I created a map in Grafx2, then converted it with AugustoRuiz tool Img2CPC into tiles and then - please don't laugh - analysed it with Excel-VBA on similarities, colors and so on and created with Excel data code statement for a C code environment.

I've seen that your tool can export the image directly into a binary code which could be loaded into RAM.
Don't know what all these setting can do...

Seems promising!! Keep on going.
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Cwiiis

Quote from: HAL6128 on 18:36, 14 March 24It automatically recognises similar tiles (count them also) if the settings are right (height x width).
Very nice!!

Do you have a description what I can also do?

I mean, your workflow is exactly what I also need. Lean and built for CPCs.
In the past I created a map in Grafx2, then converted it with AugustoRuiz tool Img2CPC into tiles and then - please don't laugh - analysed it with Excel-VBA on similarities, colors and so on and created with Excel data code statement for a C code environment.

I've seen that your tool can export the image directly into a binary code which could be loaded into RAM.
Don't know what all these setting can do...

Seems promising!! Keep on going.

I guess I ought to write some documentation :P

Though I want it to be useful for stock CPC too, at the moment it's very much aimed at the Plus - the binary formats are as follows:

Map: Just the 8-bit tile indices in either row or column order - (so column-major would be x1y1...x1yn, ..., xny1...xnyn and row-major x1y1...xny1, ..., x1yn...xnyn)
Tags*: Same as above with the 8-bit cell tag instead of the tile index
Tiles: CPC pixel format data in scanline order (so tile 0 scanline 1-scanline n, tile 1 scanline 1-scanline n, etc.)
Entities: n * [16-bit X, 16-bit Y, entity-size bytes] (stored in the same order they appear in the app - I need to add sorting like the metadata has)
Data: n * [8-bit ID, 8-bit data] (I need to add an option to optionally not export ID)
Palette: 12-bit palette in Plus colour format (so these values can be directly used with the ASIC)

* Whoops, accidentally left this out, will commit an update soon

In terms of what you can do, you can:

- Import images as maps
- Import tiles from an image (the palette will then be ignored, this is intended for when you're adding new tiles to an existing tile-set)
- Resize maps (either shrink or expand)
- Select tiles (drag in the map area)
- Change tiles (click tiles in the tile grid to assign to the current selection)
- Assign 8-bit tags to tiles (changing the tag value assigns that value to all tiles in the current selection)
- Duplicate cell tag assignments to similar areas
- Cut/copy/paste tiles (also copies tags)
- Reassign the 'zero' tile (right-click a tile in the tile grid)
- Add/edit map metadata (you can use this however you like)
- Add/edit entity data (data specific to a point on the map - the 'add' button will pre-fill the dialog with the centre of the current selection, you can also double-click on the map)
- Change entity data size
- Add/edit annotations to data and cells in the map (which is saved when saving as a .map file).

The map format is just a JSON serialisation of the map context object zipped up - so if you want to inspect that/do your own data transformations, you can rename the .map files as .zip and you'll find it in there. I intend to add undo/redo and CPC palette support at some point.

My intended use case is sketch a level in something like Grafx2, then refine it in this editor, annotate with whatever data the particular game needs and export. I may add more export customisability/options in future (perhaps ZX0 compression?) but the general idea is that this is a lightweight tool to be used in conjunction with other tools. That tends to be how I work, I prefer multiple special-purpose, lightweight tools to one monolithic tool that does everything (and I'd recommend tiled to people that prefer the latter :))

Just so I know, what does Grafx2 do with the alpha channel? Can it just be safely ignored or should pixels with alpha be counted as another palette entry?

Powered by SMFPacks Menu Editor Mod