mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
11.27k stars 1.76k forks source link

registerWorldFormat for worlds with embedded tilemaps #4049

Open swoolcock opened 2 months ago

swoolcock commented 2 months ago

I'm attempting to write a map import/export handler for a platform game that has rooms of arbitrary size that can be moved around. In Tiled this translates to a world with multiple tilemaps. Reading the Tiled documentation it doesn't look like worlds can have the tilemaps embedded.

The problem is that this game stores this data in one file per "world", and I can't see a way to write a registerWorldFormat that would then generate the world and all of its tilemaps in a single data structure (and be able to save that entire structure back to a single file).

It would be great if tilemaps could be embedded in the world data, and if you could then register a file handler instead of being restricted to .world JSON files.

Although I could just load the entire world into one great big tilemap, it loses the ability to define room sizes.

eishiya commented 2 months ago

I don't think it's necessary to refactor the way Worlds work in order to allow you to import/export files like this. Rather than a custom world format, you can write a pair of actions for importing/exporting a world in your desired format. The import would create multiple maps (potentially writing them to files if desired), while the export would take the current world's maps and write them to a file as you need. This could be done as a custom map format as well, in which case you'll probably want to prompt the user which map(s) from the "world" you want to read/write (using the existing data for unmodified maps). It might be a little unintuitive though, compared to actions that clearly deal with the entire "world".

swoolcock commented 2 months ago

Yeah if possible I'd prefer to work using only the game's file format. Preferably the Tiled world/map formats would be completely invisible to the mapper.

bjorn commented 2 months ago

Although I could just load the entire world into one great big tilemap, it loses the ability to define room sizes.

Are there multiple layers per room? If not you could derive the room size from the each layer's contents. Alternatively, you could place rectangle objects to mark the rooms.

I do think the suggested feature's would be nice to have, though I think it's quite an uncommon need.

swoolcock commented 2 months ago

Are there multiple layers per room?

Yes, there's two tile layers and two decal layers.

If not you could derive the room size from the each layer's contents

Unfortunately the game has the ability to store entities outside of the room boundaries, so it's possible for an entity to have coordinates in one room but actually belong to a neighbour room; it wouldn't get loaded until the player enters the room it belongs to.

It's probably going to be too difficult I think.