Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Tiled and xml

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Tiled and xml

    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.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,246
    Blog Entries
    2

    Re: Tiled and xml

    Hi code_glitch,

    Which compiler are you using?
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Tiled and xml

    using fpc 2.2.4 since I have had some problems with the new one (2.4.0) if i remember.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4

    Re: Tiled and xml

    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.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #5
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Tiled and xml

    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?
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  6. #6

    Re: Tiled and xml

    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.

  7. #7
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Tiled and xml

    I had a look at that tutorial, but what would I use in this instance:
    Code:
    <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...
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  8. #8

    Re: Tiled and xml

    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.

  9. #9
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Re: Tiled and xml

    Quote Originally Posted by dazappa
    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.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  10. #10

    Re: Tiled and xml

    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.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •