Commit fb5787da authored by Colomban Wendling's avatar Colomban Wendling

Tile set XML: make "first" an attribute of the root node and fix loading

parent 2f45962a
<!ELEMENT tileset (name?,author?,first,tile+)>
<!ELEMENT tileset (name?,author?,tile+)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT first EMPTY>
<!ELEMENT tile EMPTY>
<!ATTLIST first id CDATA #REQUIRED>
<!ATTLIST tileset first CDATA #REQUIRED>
<!ATTLIST tile id ID #REQUIRED>
<!ATTLIST tile count CDATA #REQUIRED>
<?xml version="1.0" encoding="utf8"?>
<!DOCTYPE tileset SYSTEM "tileset.dtd">
<tileset>
<tileset first="t1">
<name>Example set</name>
<first id="t1"/>
<tile id="t1" count="1" />
<tile id="t2" count="1" />
<tile id="t3" count="10" />
......
<?xml version="1.0" encoding="utf8"?>
<!DOCTYPE tileset SYSTEM "tileset.dtd">
<tileset>
<tileset first="t17">
<name>Original Tileset</name>
<first id="t17"/>
<tile id="t1" count="9" />
<tile id="t2" count="3" />
<tile id="t3" count="2" />
......
......@@ -210,7 +210,7 @@ namespace OVCC
tile = tiles.get_tile (id);
if (tile == null) {
throw new TileSetError.MISSING_TILE ("Tile ID %u not found in the tiles definitions", id);
throw new TileSetError.MISSING_TILE ("Tile ID #%u not found in the tiles definitions", id);
} else {
this.add (tile, count);
}
......@@ -218,43 +218,31 @@ namespace OVCC
return true;
}
private bool xml_read_first (Xml.Node *node,
private bool xml_read_tiles (Xml.Node *node,
TilesDef tiles)
throws Error
{
TileID id = 0;
for (var attr = node->properties; attr != null; attr = attr->next) {
if (Xml.ElementType.ATTRIBUTE_NODE == attr->type) {
switch (attr->name) {
case "id":
id = TileID.from_string (attr->children->content.strip ());
case "first":
var id = TileID.from_string (attr->children->content.strip ());
var tile = tiles.get_tile (id);
if (tile == null) {
throw new TileSetError.MISSING_TILE ("First tile (ID #%u) not found in the tiles definitions", id);
} else {
this.first = tile;
}
break;
}
}
}
var tile = tiles.get_tile (id);
if (tile == null) {
throw new TileSetError.MISSING_TILE ("Tile ID %u not found in the tiles definitions", id);
} else {
this.first = tile;
}
return true;
}
private bool xml_read_tiles (Xml.Node *node,
TilesDef tiles)
throws Error
{
for (var child = node->children; child != null; child = child->next) {
if (Xml.ElementType.ELEMENT_NODE == child->type) {
switch (child->name) {
case "tile": xml_read_tile (child, tiles); break;
case "name": this.name = child->name; break;
case "first": xml_read_first (child, tiles); break;
case "name": this.name = child->children->content.strip (); break;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment