comparison src/xmlmap.d @ 3:a9af6ec19195

working map and tileset loading
author fred@reichbier.de
date Thu, 17 Jul 2008 21:34:53 +0200
parents fc2f936a961c
children
comparison
equal deleted inserted replaced
2:fc2f936a961c 3:a9af6ec19195
6 import tango.text.xml.Document; 6 import tango.text.xml.Document;
7 import tango.text.convert.Integer; 7 import tango.text.convert.Integer;
8 import tango.io.Stdout; // TODO 8 import tango.io.Stdout; // TODO
9 import tools; 9 import tools;
10 import imagecache; 10 import imagecache;
11 import dsfml.system.all;
12 import Text = tango.text.Util;
13
11 14
12 alias XmlPath!(char).NodeSet NodeSet; 15 alias XmlPath!(char).NodeSet NodeSet;
13 alias Document!(char).Node NodeImpl; 16 alias Document!(char).Node NodeImpl;
14 private char[] get_attribute(NodeSet node, char[] name) { 17 private char[] get_attribute(NodeSet node, char[] name) {
15 return node.attribute(name).nodes[0].value; 18 return node.attribute(name).nodes[0].value;
36 int height = Integer.parse(get_attribute(root, "height")); 39 int height = Integer.parse(get_attribute(root, "height"));
37 Stdout.formatln("Width: {}, Height: {}", width, height); 40 Stdout.formatln("Width: {}, Height: {}", width, height);
38 auto tiles_node = root.child.nodes[0]; 41 auto tiles_node = root.child.nodes[0];
39 char[] tileset_file = tiles_node.getAttribute("tileset").value; 42 char[] tileset_file = tiles_node.getAttribute("tileset").value;
40 auto tilemap = new Tilemap(parse_tileset(cache, read_file_contents(tileset_file)), width, height, 32, 32); // TODO: variable tile size 43 auto tilemap = new Tilemap(parse_tileset(cache, read_file_contents(tileset_file)), width, height, 32, 32); // TODO: variable tile size
44 int layer_id=0;
41 foreach(NodeImpl layer_node; tiles_node.query["layer"].nodes) { 45 foreach(NodeImpl layer_node; tiles_node.query["layer"].nodes) {
42 int tile_width = Integer.parse(layer_node.getAttribute("tilewidth").value); 46 int tile_width = Integer.parse(layer_node.getAttribute("tilewidth").value);
43 int tile_height = Integer.parse(layer_node.getAttribute("tileheight").value); 47 int tile_height = Integer.parse(layer_node.getAttribute("tileheight").value);
48 tilemap.layer_tsizes[layer_id] = Vector2i(tile_width, tile_height);
49 char[][] content_ = Text.delimit(Text.trim(layer_node.value), ",");
50 int i=0;
51 for(int x=0; x < width; x++) {
52 for(int y=0; y < height; y++) {
53 tilemap.map[layer_id][x][y] = Integer.parse(content_[i]);
54 i++;
55 }
56 }
57 layer_id++;
44 } 58 }
45 return tilemap; 59 return tilemap;
46 } 60 }