# HG changeset patch
# User fred@reichbier.de
# Date 1216321603 -7200
# Node ID fc2f936a961cdae2983b1fc0c9242dccdafff12d
# Parent f193d0c14685eaeff7a47660d3293aef20af2a9f
basic loading, to be fixed
diff -r f193d0c14685 -r fc2f936a961c bin/map-example.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/map-example.xml Thu Jul 17 21:06:43 2008 +0200
@@ -0,0 +1,7 @@
+
diff -r f193d0c14685 -r fc2f936a961c bin/tileset-example.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/tileset-example.xml Thu Jul 17 21:06:43 2008 +0200
@@ -0,0 +1,3 @@
+
+
+
diff -r f193d0c14685 -r fc2f936a961c src/test.d
--- a/src/test.d Thu Jul 17 20:19:24 2008 +0200
+++ b/src/test.d Thu Jul 17 21:06:43 2008 +0200
@@ -14,8 +14,9 @@
import tools;
int main(char[][] args) {
-// Tilemap map = parse_map(read_file_contents("map-example.xml"));
Cache cache = new Cache("gfx");
+ Tilemap map = parse_map(cache, read_file_contents("map-example.xml"));
+/*
Tileset tileset = new Tileset(cache);
Tilemap map = new Tilemap(tileset, 5, 5, 32, 32);
tileset.add_tile(0, "grass.png");
@@ -31,6 +32,6 @@
TileConsumer consumer = new TileConsumer(render, map);
render.add_consumer(consumer);
- render.mainloop();
+ render.mainloop();*/
return 0;
}
diff -r f193d0c14685 -r fc2f936a961c src/tileset.d
--- a/src/tileset.d Thu Jul 17 20:19:24 2008 +0200
+++ b/src/tileset.d Thu Jul 17 21:06:43 2008 +0200
@@ -6,9 +6,11 @@
import imagecache;
+alias Image[int] TileList;
+
class Tileset {
private Cache cache;
- public Image[int] tiles;
+ public TileList tiles;
this(Cache cache) {
this.cache = cache;
diff -r f193d0c14685 -r fc2f936a961c src/tools.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tools.d Thu Jul 17 21:06:43 2008 +0200
@@ -0,0 +1,10 @@
+module tools;
+
+import tango.io.File;
+
+char[] read_file_contents(char[] filename) {
+ auto file = new File (filename);
+ auto content = cast(char[]) file.read();
+
+ return content;
+}
diff -r f193d0c14685 -r fc2f936a961c src/xmlmap.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/xmlmap.d Thu Jul 17 21:06:43 2008 +0200
@@ -0,0 +1,46 @@
+module xmlmap;
+
+import tileset;
+import tilemap;
+
+import tango.text.xml.Document;
+import tango.text.convert.Integer;
+import tango.io.Stdout; // TODO
+import tools;
+import imagecache;
+
+alias XmlPath!(char).NodeSet NodeSet;
+alias Document!(char).Node NodeImpl;
+private char[] get_attribute(NodeSet node, char[] name) {
+ return node.attribute(name).nodes[0].value;
+}
+
+Tileset parse_tileset(Cache cache, char[] content) {
+ auto tileset = new Tileset(cache);
+
+ auto doc = new Document!(char);
+ doc.parse(content);
+ auto root = doc.query["tileset"];
+ auto nodes = root.child.nodes;
+ foreach(NodeImpl tiles_node; nodes) {
+ tileset.add_tile(Integer.parse(tiles_node.getAttribute("id").value), tiles_node.getAttribute("filename").value);
+ }
+ return tileset;
+}
+
+Tilemap parse_map(Cache cache, char[] content) {
+ auto doc = new Document!(char);
+ doc.parse(content);
+ auto root = doc.query["map"];
+ int width = Integer.parse(get_attribute(root, "width"));
+ int height = Integer.parse(get_attribute(root, "height"));
+ Stdout.formatln("Width: {}, Height: {}", width, height);
+ auto tiles_node = root.child.nodes[0];
+ char[] tileset_file = tiles_node.getAttribute("tileset").value;
+ auto tilemap = new Tilemap(parse_tileset(cache, read_file_contents(tileset_file)), width, height, 32, 32); // TODO: variable tile size
+ foreach(NodeImpl layer_node; tiles_node.query["layer"].nodes) {
+ int tile_width = Integer.parse(layer_node.getAttribute("tilewidth").value);
+ int tile_height = Integer.parse(layer_node.getAttribute("tileheight").value);
+ }
+ return tilemap;
+}