Map Format Import & Conversion
There's literally hundreds of 2d mapping tools on the net, finding one isn't difficult, but importing/converting the data formats can be. So this little thread will document my various little explorations from time to time.
Isometric Map Test
This is just a quick import mock up of the Isometric map from 'Tiled' map editor, this scene is one of the stock examples that comes with it. The editor seems to default XML with compressed tile data hunk, can't be bothered with that. But there is a CSV form, which just spits the tile data out as,
<data encoding="csv">
24,24,23,24,23,24,23,23,24,24,23,7,2,2,1,4,2,2,3,4,4,1,3,4,1,
24,23,23,23,23,23,24,23,24,24,18,4,1,3,1,3,3,4,4,1,3,1,4,3,4,
23,23,23,23,23,24,24,24,23,11,7,2,1,3,1,3,4,4,3,2,2,3,4,2,1,
23,24,24,23,23,24,24,24,11,7,2,4,4,3,3,1,4,2,1,4,4,4,1,1,1,
23,23,23,24,23,23,24,23,18,4,4,2,2,3,3,3,4,3,4,4,3,2,4,3,4,
24,23,23,24,11,12,24,24,18,4,4,3,2,1,2,2,1,1,1,2,1,4,2,1,1,
24,24,23,23,10,9,23,11,7,1,4,1,1,1,2,3,2,3,3,3,4,2,4,4,4,
24,23,23,24,24,23,11,7,3,1,3,1,1,3,4,4,1,1,4,2,2,3,4,4,2,
19,19,19,19,19,19,7,3,1,3,3,2,3,1,1,3,1,3,3,2,4,3,3,3,1,
1,2,4,2,2,3,3,2,1,5,6,4,1,2,3,1,2,4,3,4,4,1,1,1,1,
3,3,1,1,2,4,3,4,4,8,7,4,3,2,1,5,6,4,1,2,2,4,4,4,4,
2,4,4,4,4,2,3,3,4,4,2,3,3,5,17,21,7,1,4,1,3,2,4,3,1,
3,1,2,2,3,2,4,4,3,1,2,2,4,20,23,18,2,1,1,3,3,1,4,3,4,
4,2,3,3,1,2,4,3,1,1,3,1,1,20,23,18,3,1,2,4,3,4,1,3,2,
4,1,2,1,3,3,1,4,4,1,4,1,3,20,23,18,1,3,3,3,3,2,1,4,2,
3,4,3,2,3,4,3,4,4,3,1,5,17,9,23,18,1,2,2,4,4,4,1,2,3,
2,2,1,4,4,3,3,3,2,4,4,8,19,19,19,7,3,2,4,4,3,3,4,3,4,
1,4,1,3,2,1,4,4,1,3,4,3,4,4,3,2,2,2,3,3,3,1,1,2,3,
2,1,3,3,3,3,2,2,3,2,1,3,3,1,3,4,3,3,2,3,1,1,3,4,2,
4,2,4,1,2,1,2,3,4,4,3,4,3,2,3,3,1,2,3,1,1,1,4,4,1,
3,2,2,4,4,3,2,1,4,2,2,1,4,2,3,4,1,2,3,2,2,2,4,3,1,
1,3,1,2,3,3,3,4,2,1,3,2,1,1,1,3,3,1,3,4,3,1,2,3,4,
1,2,3,4,1,3,4,4,4,1,4,4,3,2,3,4,1,2,4,2,1,2,2,4,1,
4,2,3,2,1,4,2,2,1,2,2,2,4,3,3,2,3,3,2,3,2,4,1,3,1,
1,1,1,4,1,3,3,2,1,4,2,1,3,1,3,3,4,3,4,2,1,2,3,1,1
</data>
So really all you'd do is load the map file to a string, find the DATA tags and pull out the text, remove the chr$(13) and Chr(10) characters and split it to an integer array. Couldn't be simpler.
Example of pulling the tile indexes from the data section of the xml.
[pbcode]
// Make the data section of string just like it was when loaded
cr$=chr$(13)+chr$(10)
s$ ="<data encoding='csv'>"+cr$
s$+="24,24,23,24,23,24,23,23,24,24,23,7,2,2,1,4,2,2,3,4,4,1,3,4,1,"+cr$
s$+="24,23,23,23,23,23,24,23,24,24,18,4,1,3,1,3,3,4,4,1,3,1,4,3,4,"+cr$
s$+="23,23,23,23,23,24,24,24,23,11,7,2,1,3,1,3,4,4,3,2,2,3,4,2,1,"+cr$
s$+="23,24,24,23,23,24,24,24,11,7,2,4,4,3,3,1,4,2,1,4,4,4,1,1,1,"+cr$
s$+="23,23,23,24,23,23,24,23,18,4,4,2,2,3,3,3,4,3,4,4,3,2,4,3,4,"+cr$
s$+="24,23,23,24,11,12,24,24,18,4,4,3,2,1,2,2,1,1,1,2,1,4,2,1,1,"+cr$
s$+="24,24,23,23,10,9,23,11,7,1,4,1,1,1,2,3,2,3,3,3,4,2,4,4,4,"+cr$
s$+="24,23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,1,3,3,2,1,4,2,1,3,1,3,3,4,3,4,2,1,2,3,1,1"+cr$
s$+="</data>"+cr$
DIm Map(0,0)
Map()=Decode_Map(s$,25,25)
For Ylp=0 to GetArrayELements(Map(),2)-1
For Xlp=0 to GetArrayELements(Map())-1
text xlp*20,ylp*20,Map(xlp,ylp)
next
next
sync
waitkey
Function Decode_Map(s$,width,Height)
Dim MapData(Width,Height)
startpos=instring(s$,"<data ")
if STartpos
TagEnd=Instring(s$,">",Startpos)
if Tagend
Endpos=instring(s$,"</data>")
if EndPos
StartPos=TagEnd+1
Dim Values(0)
t$=mid$(s$,StartPos,EndPos-StartPos)
t$=replace$(t$,chr$(13)+chr$(10),"")
count=SplitToArray(t$,",",Values())
if count
For ylp=0 to Height-1
For xlp=0 to Width-1
MapData(xlp,ylp)=Values(Index)
Index++
next
next
endif
endif
endif
endif
EndFunction MapData()
[/pbcode]