V - Importing/Converting for Custom
Right now, there is no way to have Custom read external files. What we're going to do then, is to get the output from Tiled, convert it into a script, run that script in Custom, and then use the generated map. We'll use our tiny little 16×10 map as an example.
Once you have the map you want, go to File→Export As. There, you can select where you want to export the file. You
can export everything as a CSV, but if you have multiple layers (which I do) it can be easier to export the map as a .json file rather than having to deal with multiple .csv files. Once you've exported the map, open it up and if you set tile layer format to XML as mentioned earlier, you should have something that looks like this:
Code: Select all
{ "height":10,
"layers":[
{
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"height":10,
"name":"ground",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":16,
"x":0,
"y":0
},
...
...
...
That's only a small snippet, as the rest of the file goes on and on and on. What you're looking for is the line that starts with "data". That right there is your map. This one has a bunch of 1s, but in more complex maps (i.e. not the lame one I'm using as an example right now) you'll have a bunch of different numbers. Each of those numbers corresponds to a certain tile. Here, "1" is tile position "0" in Custom. You'll have one of these blocks for each layer that you created.
One thing to keep in mind though, is that the number count goes up by 160 for each layer (16 tiles wide × 10 tiles high). This means that while in Custom, layer 1's tile 0 will be the tile at the top left, and layer 2's tile 0 will also be the tile at the top left, in this output file layer 1's top left tile will be tile 1, and layer 2's top left tile will be 161, and so on and so forth.
Now that you have these numbers, it's up to you how to parse them. The method I've done is to copy/paste those lines into a spreadsheet which will then create a string of values for me with each number formatted to be exactly 4 characters long (e.g. 0000, 0001, 0002, etc...). Once I have that string of values, it's a simple matter to script something to turn that string of values into tiles. In an .hsi file, I store each of those into separate "layer strings" (Strings 90 to 100 for me) which I can then refer to later on in other scripts. The generator script I came up with is below:
Code: Select all
#This file is a VERY crude generator. Used in conjunction with the spreadsheet built for this, it allows me to
# translate data from Tiled to the OHRRPGCE.
plotscript, autogen, begin
variable(
minX
minY
maxX
maxY
curX #Current X value
curY #Current Y value
curT #Current Tile value
curL #Current Layer value
curP #Current Pass bitset
ctr #Counter for where to cut
)
minX := 0
minY := 0
maxX := map width -- 1
maxY := map height -- 1
ctr := 0
data set
for(curL, 0, 7) do(
switch(curL) do(
case(0) do(81 $= 90) #Layer 0
case(1) do(81 $= 91) #Layer 1
case(2) do(81 $= 92) #Layer 2
case(3) do(81 $= 93) #Layer 3
case(4) do(81 $= 94) #Layer 4
case(5) do(81 $= 95) #Layer 5
case(6) do(81 $= 96) #Layer 6
case(7) do(81 $= 97) #Layer 7
)
for(curY, minY, maxY) do(
for(curX, minX, maxX) do(
80 $= 81
trim string (80, ctr + 1, 4)
curT := number from string (80)
write map block(curX, curY, curT, curL)
ctr += 5
)
)
ctr := 0
)
...
...
...
save map state #Very important, saves the map so I can retrieve it later
This script is run when the map first loads, so if done right it will populate your map with the one made in Tiled. The way that script works is to grab each "layer string" and then chop each one up to figure out what tile and what layer to
write map block to. As shown in the script comment, the above script is very crude, and for larger maps, relatively slow. That doesn't matter though, as we're only going to be running this script once. Granted, you can always write a more efficient script, but I'm lazy and this works well enough for my purposes.
Right, so by now you've compiled your script, imported it into Custom, added your plotscript to your map's autorun special plotscript. Now for the fun part, getting that scripted map into Custom. To do so, first check and remember the number of the map you're working on. Once you've done that, go ahead and save & quit Custom. Now, if you haven't already, unlump your .rpg file. Inside your unlumped .rpg file (.rpgdir) are a whole bunch of files. For now, you don't need to worry about them.
Go ahead and fire up Game and load up your .rpgdir. Once the game starts, and assuming that you've properly attached your plotscript and are on the appropriate map, you should be good to go. When Game runs, it will create a working directory for the game files. Exactly where this file is will vary between the different operating systems. For more information, check
this page. Chances are, you'll have a whole bunch of files there as well as directories. The easiest way to find the one you want is to arrange everything by modification date. The newest directory is the one you want, so go ahead and open it up.
Inside are a whole bunch of files. The file you're looking for is named "map#_t.tmp", where ## is the number of the map you were working on (you remembered which one it was, right?). This file contains the tilemap that was created with the above script. Go ahead and copy/paste this somewhere, preferably the directory where your .rpgdir is located (but
not inside the .rpgdir, or at least not yet.).
Once you've done that, you can exit Game. Now back to your game directory. Backup your .rpgdir file just in case (which should go without saying, as you should
always have a backup of your game). Rename the "map#_t.tmp" file into "ohrrpgce.t##". So if the file you copied was "map1_t.tmp", you'll rename it to "ohrrpgce.t01". Next, copy/paste the renamed file into your .rpgdir, overwriting your existing file and you're done! When you next open up Custom, if you did everything correctly you should be able to see the map you created in Tiled and edit it to your heart's content.
VI - Final Thoughts
And that's that! It should save some time when making maps (or at least it does for me) as well as streamlining a few things. This tutorial only covers tiles, but once you've got this basic technique down, it's a simple matter to expand it to include wallmaps, zonemaps, doors, and everything else that you could want. This method works well for me, but the extra steps might not make it something that appeals to everyone. You'll have to do a bit of testing to see if this is right for you.
Additionally, if anyone wants a copy of the spreadsheet I use to convert stuff as well as the complete script I use, don't hesitate to ask me if you're interested in using them. Anywho, that's all from me for now, cheers!
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl