PDA

View Full Version : Tiled and xml



code_glitch
02-09-2010, 02:48 PM
I was looking around for my engine and thought that I should probably update my rustique map functions and procedures. So I finally moved away from my very basic format and editor in favour of the very popular TileD. (Name might be wrong). However, I did encouter a hitch in that tiled saves in XML format. I plan to use xml and the csv format for the maps but havent found any good tutorials on how to read xml.

If any of you have a basic program you would be willing to share or have some docs that would be helpful to someone who has just begun xml I would really appreciate it.

Thanks,
code_glitch.

AthenaOfDelphi
02-09-2010, 02:56 PM
Hi code_glitch,

Which compiler are you using?

code_glitch
02-09-2010, 03:20 PM
using fpc 2.2.4 since I have had some problems with the new one (2.4.0) if i remember.

chronozphere
02-09-2010, 04:42 PM
I know that Jeremy Darling has a lot of experience with XML. Check out his site:

http://www.eonclash.com/

I needed an XML library that will work in both Delphi and FPC. I remembar that his TXMLParser worked out of the box in Delphi. It was quite easy to compile it with FPC. Just use {$mode delphi} and remove one assembly method. :)

code_glitch
02-09-2010, 05:19 PM
One thing though, I dont know how to compile (which file and where to get missing units) since the only xml parser I saw on the site you mentioned is in the Delphi section. Any suggestions? Or could anyone submit a compiled .ppu for this unit?

dazappa
02-09-2010, 07:32 PM
In freepascal, look for TXMLDocument, and the xmlread unit. There's a good tutorial here: http://wiki.freepascal.org/XML_Tutorial . You need the dom unit as well, I'm not sure what all others.

It's fairly painless. I've implemented tiled maps in a slightly less efficient way -- straight up file io. I export them as CSV, and based on the number of layers I have I simply skip lines to get to the CSV of each layer. It's certainly not flexible, but if your map format is going to be the same (number of layers, size, etc), it gets rid of whatever XML size overhead there may be, although I really doubt this is worth it.

code_glitch
02-09-2010, 08:16 PM
I had a look at that tutorial, but what would I use in this instance:

<name length="6" type="text">glitch</name>
to get the length parameter and for the data? And what would I do to get the data between the tags if it were around 3,000 characters long? As far as I know you can only have 255 characters in a string... :(

Thats the main problem I have with that tutorial, and why I was asking if anyone knew of any other xml parsers. Also, does anyone have a good example with this for TileD? I cant believe I am the only one using TileD with a pascal program...

dazappa
03-09-2010, 12:33 AM
For strings, see: http://wiki.freepascal.org/String
Either explicitly define the type as being an ansistring, or set that switch.

For parsing XML, it's all up to how the XML file is structured... assuming you have only that line in your entire XML file, I believe you'd have something like "YourNode.Attributes.Item[0].NodeValue".

I haven't played with XML in a while so I'm not quite sure. But basically have a look at the section "Printing the names of nodes". If you're still struggling with how it all works, simply compile that example yourself and look at the example.

You're not the only one who uses Tiled. As I said, I use it myself, but I just choose not read the file as XML.

code_glitch
03-09-2010, 12:40 AM
I just choose not read the file as XML.


lol. Thats a bit basic... I was moving to XML to get away from my limited support for my basic and patchy file system based on primitive meta tags and data arrays written as csv lists of integers... Will try and get around with this. Thanks for all your help.

chronozphere
03-09-2010, 01:19 AM
Lazarus has a very handy feature that allows you to import and convert an existing delphi project. So you can just import that delphi project from eonclash and see what happens. :)

Delphi also likes to include a lot of units in the uses clause, which are not even needed. If you encounter any missing units, just remove them from the clause. If it's really incomplete, please let me know the details.

If you are interested, I can dig up my converted source-code. However, I think there are other options for you to explore so it's all up to you. ;)

code_glitch
04-09-2010, 10:36 AM
If you are interested, I can dig up my converted source-code. However, I think there are other options for you to explore so it's all up to you. ;)


The way things are going, that would be a great help if that's not too much of an inconvenience for you. I know how much of a mess my old code collection is. :D

XML is a bit tougher than I had originally thought, and it seems that lazarus is far better kitted out to deal with it than good 'ol fpc. ;)

chronozphere
04-09-2010, 11:15 AM
I couldn't access my "dump" FTP account so I uploaded it here:

http://www.megafileupload.com/en/file/265374/eonclash-xml-for-fpc-zip.html

Hope everything works for you. :)

code_glitch
04-09-2010, 01:47 PM
Thanks, this is a great help. Much appreciated. :)