(parse tiled-map)

(parse spec tiled-map)

Parses `tiled-map` (an XML-formatted string) into a hash map. If `spec` is supplied, the parsing will done with that spec rather than the default :tile-soup.map/map spec.

Examples

Parsing a TMX file whose data is encoded in base 64
(parse (str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<map version=\"1.2\" tiledversion=\"1.2.3\" orientation=\"orthogonal\" renderorder=\"right-down\"\n width=\"212\" height=\"20\" tilewidth=\"10\" tileheight=\"2\"\n infinite=\"0\" nextlayerid=\"3\" nextobjectid=\"1\">" "<tileset firstgid=\"1\" name=\"tileSet-hd\" tilewidth=\"16\" tileheight=\"16\"\n tilecount=\"0\" columns=\"16\">" "<image source=\"tileSet.png\" trans=\"fe80fe\" width=\"256\" height=\"256\"/>" "</tileset>" "<layer id=\"1\" name=\"background\" width=\"10\" height=\"2\">" "<data encoding=\"base64\">" "igAAAIsAAACMAAAAjQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJoAAACbAAAAnAAAAJ0AAAA=" "</data>" "</layer>" "</map>"))
Parsing a TMX file whose data is encoded in CSV
(parse (str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<map version=\"1.2\" tiledversion=\"1.2.3\" orientation=\"orthogonal\" renderorder=\"right-down\"\n width=\"212\" height=\"20\" tilewidth=\"10\" tileheight=\"2\"\n infinite=\"0\" nextlayerid=\"3\" nextobjectid=\"1\">" "<tileset firstgid=\"1\" name=\"tileSet-hd\" tilewidth=\"16\" tileheight=\"16\"\n tilecount=\"0\" columns=\"16\">" "<image source=\"tileSet.png\" trans=\"fe80fe\" width=\"256\" height=\"256\"/>" "</tileset>" "<layer id=\"1\" name=\"background\" width=\"10\" height=\"2\">" "<data encoding=\"csv\">" "138,139,140,141,0,0,0,0,0,0,0,0,0,0,0,0,154,155,156,157" "</data>" "</layer>" "</map>"))
Parsing an TMX file whose data is encoded in XML
(parse (str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<map version=\"1.2\" tiledversion=\"1.2.3\" orientation=\"orthogonal\"\n renderorder=\"right-down\" width=\"212\" height=\"20\"\n tilewidth=\"16\" tileheight=\"16\" infinite=\"0\" nextlayerid=\"3\" nextobjectid=\"1\">" "<tileset firstgid=\"1\" name=\"tileSet-hd\" tilewidth=\"16\" tileheight=\"16\"\n tilecount=\"256\" columns=\"16\">" "<image source=\"tileSet.png\" trans=\"fe80fe\" width=\"256\" height=\"256\"/>" "</tileset>" "<layer id=\"1\" name=\"background\" width=\"10\" height=\"2\">" "<data>" "<tile gid=\"138\"/>\n <tile gid=\"139\"/>\n <tile gid=\"140\"/>\n <tile gid=\"141\"/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile/>\n <tile gid=\"154\"/>\n <tile gid=\"155\"/>\n <tile gid=\"156\"/>\n <tile gid=\"157\"/>" "</data>" "</layer>" "</map>"))
Parsing a TSX file
(parse :tile-soup.tileset/tileset (str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<tileset name=\"Desert\" tilewidth=\"32\" tileheight=\"32\" spacing=\"1\" margin=\"1\" tilecount=\"48\" columns=\"8\">" "<image source=\"tmw_desert_spacing.png\" width=\"265\" height=\"199\"/>" "<terraintypes>" "<terrain name=\"Desert\" tile=\"29\"/>" "<terrain name=\"Brick\" tile=\"9\"/>" "<terrain name=\"Cobblestone\" tile=\"33\"/>" "<terrain name=\"Dirt\" tile=\"14\"/>" "</terraintypes>" "<tile id=\"0\" terrain=\"0,0,0,1\"/>" "<tile id=\"1\" terrain=\"0,0,1,1\"/>" "<tile id=\"2\" terrain=\"0,0,1,0\"/>" "<tile id=\"3\" terrain=\"3,3,3,0\"/>" "</tileset>"))

Source

(defn parse "Parses `tiled-map` (an XML-formatted string) into a hash map. If `spec` is supplied,\n the parsing will done with that spec rather than the default :tile-soup.map/map spec." ([tiled-map] (parse :tile-soup.map/map tiled-map)) ([spec tiled-map] (u/parse spec (record->map (parse-xml tiled-map)))))