flareteam / flare-game

Fantasy action RPG using the FLARE engine
http://flarerpg.org/
Other
1.1k stars 235 forks source link

Creating maps with Tiled for FLARE engine? #830

Open TanisTheRed opened 3 years ago

TanisTheRed commented 3 years ago

I can't find documentation about this process. Specifically if you open the "Arrival.txt" map file that is in the engine in Tiled it shows all the different tilesets that was used to make it. Though there is that custom attribute "tileset=tilesetdefs/tileset_grassland.txt" which has all the tiles used in one giant png with a text file listing each tile's ID, location, etc....

My question is where did that file come from? Looking in Tiled the tile ids are what is in the individual tilesets listed under the [tilesets] section but looking at the final arrival.txt file under [layer] for instance the tile ID's are what is in that final 1 large png. So is there a step or tool that I am missing that converts these and creates that massive 1 png?

dorkster commented 3 years ago

I think Flare's base tilesets were done by hand, because there used to be a limitation of one image per tileset. @clintbellanger might be able to expand on this.

I have since made a tool that will generate the tileset definition file (e.g. tilesetdefs/tileset_grassland.txt) without having to combine the images.

TanisTheRed commented 3 years ago

Ok a few questions just to make sure i'm clear:

1.) You say there used to be a limitation of 1 image per tileset but is that still the case? If not does your tool handle this? 2.) Looking at the script in your tool it talks about "image/tilesets" but is that the tileset created in Tiled or the image used by that tileset? So in essence I would have my map from tiled in folder "maps", and then I should have "maps/images/tilesets" that has the physical images of the tilesets I used?

I'm just trying to make sure I understand the whole process. I looked through the script and I couldn't tell where or how it properly converts the numbers from the individuals tilesets into 1 overall numbering system?

dorkster commented 3 years ago

1.) Yes. Each image is assigned its own [tileset] section in the definition file. The img=... key is the filename of the actual image. 2.) images/tilesets/ is an slightly arbitrary default. It's how we organize our images, but you're free to use your own folder structure. You should have your Tiled TMX files in a location outside of your mod directory along with the tileset images. You would then copy the tileset images to ${YOUR_MOD}/images/tilesets/

It's been a while since I wrote that script, but here's an overview: Tile IDs in Tiled are already uniform across all tilesets in a map. The tilesets are contiguous with a firstgid property telling Tiled where the tileset begins. These lines are where we set the range of tiles for a single tileset image. It simply iterates over all the tilesets in order of appearance in the TMX file.

TanisTheRed commented 3 years ago

Ok I think I finally understand but just 1 more question based on the steps I think I know:

1.) Tiled as you said does modify the ID's to be uniform on the final output even though putting your mouse over the tile just shows the ID of that individual tileset. 2.) Your script reads in the tmx file which would list all the individual tilesets and then creates the master tileset.txt file that listed the location in a master tileset image which flare then reads in for the game engine. 3.) So each flare map in reality is only going to use 1 tileset which can be a group of tilesets used in Tiled to create a map. 4.) Your python script takes that custom attribute "tileset" and then creates that final master.txt file based on that attribute name. Your script does not create that "final master" png image of all the tiles though. That was created by hand in the past, so I would have to create another tool to read in your "master".txt file with all the images location to create 1 master png in the end (or is there a tool that does that already)?

Last things as I have not run python in awhile: 1.) My map is in folder "C:\Map Main\maps" 2.) I put the python script in the same folder 3.) My tileset images are in multiple folders under "C:\Map Main\tiled\" but are linked in the .tmx file properly so they show up. 4.) So I just open a dos window in "C:\Map Main\maps" and run "tilesetdef-generator TestMap1"?

I really appreciate all the help and hope this helps anyone else with these questions as well.

dorkster commented 3 years ago

Your observations in 1-3 are all correct.

Your python script takes that custom attribute "tileset" and then creates that final master.txt file based on that attribute name. Your script does not create that "final master" png image of all the tiles though. That was created by hand in the past, so I would have to create another tool to read in your "master".txt file with all the images location to create 1 master png in the end (or is there a tool that does that already)?

If you wanted to create a single PNG, yes you would need to create a tool to do that.

And as for running the script, what you outlined should do the trick.

TanisTheRed commented 3 years ago

Ok thanks. The script is looking for python 2 and the latest python 3.7 gives a bunch of errors but I'm working on fixing them. Thank you for all the help. =)

dorkster commented 3 years ago

The script is looking for python 2 and the latest python 3.7 gives a bunch of errors but I'm working on fixing them

Ah, sorry about that. The script is pretty old, but I should have ported it to Python 3 by now. ~Putting that on my TODO list.~ Fixed

TanisTheRed commented 3 years ago

Actually I just figured out your script works (the print needs () around it but that is it) as long as the tilesets are embedded into the map. If I add an external tileset, then for some reason it reads the information as "None" as gives errors? I can embedded mine but I was not so that if I modified 1 tileset it would affect the others in my other maps as well. Any ideas on that?

dorkster commented 3 years ago

My script doesn't have support for external tilesets. I'll have to work on that. I've opened an issue if you want to keep tabs on it. I've been busy lately, so it'll be some time before I get to it.

TanisTheRed commented 3 years ago

Thats no problem, just wanted to make sure I was not doing something wrong. Again thank you for your patience and all your help. =)