From ef435d3ddbeda713d5851b3f35d7879d15b10ca8 Mon Sep 17 00:00:00 2001 From: Paul Merrill Date: Thu, 9 Jun 2011 02:58:24 -0700 Subject: [PATCH] impl'd processObjectGroup --- src/area.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/area.h | 2 + 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/src/area.cpp b/src/area.cpp index 230b67e..902fbe7 100644 --- a/src/area.cpp +++ b/src/area.cpp @@ -215,6 +215,7 @@ Area::TileType Area::defaultTileType(const Gosu::Bitmap source, coord_t tiledim, bool Area::processTileType(xmlNode* node, Tileset& ts) { + /* @@ -382,8 +383,131 @@ bool Area::processLayerData(xmlNode* node) return true; } -bool Area::processObjectGroup(xmlNode*) +bool Area::processObjectGroup(xmlNode* node) +{ + +/* + + + + + + + + + + + + + +*/ + + xmlChar* width = xmlGetProp(node, BAD_CAST("width")); + xmlChar* height = xmlGetProp(node, BAD_CAST("height")); + unsigned x = atol((const char*)width); + unsigned y = atol((const char*)height); + + unsigned zpos = -1; + + if (dim.x != x || dim.y != y) { + // XXX we need to know the Area we're loading... + Log::err("unknown area", "objectgroup x,y size != map x,y size"); + return false; + } + + xmlNode* child = node->xmlChildrenNode; + for (; child != NULL; child = child->next) { + if (!xmlStrncmp(child->name, BAD_CAST("properties"), 11)) { + if (!processObjectGroupProperties(child, &zpos)) + return false; + } + else if (!xmlStrncmp(child->name, BAD_CAST("object"), 7)) { + if (zpos == (unsigned)-1 || !processObject(child, zpos)) + return false; + } + } + + return true; +} + +bool Area::processObjectGroupProperties(xmlNode* node, unsigned* zpos) +{ + +/* + + + +*/ + + xmlNode* child = node->xmlChildrenNode; + for (; child != NULL; child = child->next) { + xmlChar* name = xmlGetProp(child, BAD_CAST("name")); + xmlChar* value = xmlGetProp(child, BAD_CAST("value")); + if (!xmlStrncmp(name, BAD_CAST("layer"), 6)) { + int layer = atol((const char*)value); + if (0 < layer || layer >= (int)dim.z) { + // XXX we need to know the Area we're loading... + Log::err("unknown area", + "objectgroup must correspond with layer" + ); + return false; + } + *zpos = layer; + } + } + return true; +} + +bool Area::processObject(xmlNode* node, unsigned zpos) { + +/* + + + + + + + + +*/ + + xmlChar* type = xmlGetProp(node, BAD_CAST("type")); + if (xmlStrncmp(type, BAD_CAST("Tile"), 5)) { + Log::err("unknown area", "object type must be Tile"); + return false; + } + + xmlChar* xStr = xmlGetProp(node, BAD_CAST("x")); + xmlChar* yStr = xmlGetProp(node, BAD_CAST("y")); + // XXX we ignore the object gid... is that okay? + + // wouldn't have to access tilesets if we had tiledim ourselves + unsigned x = atol((const char*)xStr) / tilesets[0].tiledim.x; + unsigned y = atol((const char*)yStr) / tilesets[0].tiledim.y; + y = y - 1; // bug in tiled? y is 1 too high + + // We know which Tile is being talked about now... yay + Tile* t = map[zpos][y][x]; + + xmlNode* child = node->xmlChildrenNode; // + child = node->xmlChildrenNode; // + for (; child != NULL; child = child->next) { + xmlChar* name = xmlGetProp(child, BAD_CAST("name")); + xmlChar* value = xmlGetProp(child, BAD_CAST("value")); + if (!xmlStrncmp(child->name, BAD_CAST("flags"), 6)) { + // TODO flags + } + else if (!xmlStrncmp(name, BAD_CAST("onEnter"), 8)) { + // TODO events + } + else if (!xmlStrncmp(name, BAD_CAST("onLeave"), 8)) { + // TODO events + } + else if (!xmlStrncmp(name, BAD_CAST("door"), 5)) { + // TODO doors + } + } return true; } diff --git a/src/area.h b/src/area.h index 3f34f13..dcd2378 100644 --- a/src/area.h +++ b/src/area.h @@ -129,6 +129,8 @@ private: bool processLayerProperties(xmlNode* node); bool processLayerData(xmlNode* node); bool processObjectGroup(xmlNode* node); + bool processObjectGroupProperties(xmlNode* node, unsigned* zpos); + bool processObject(xmlNode* node, unsigned zpos); Resourcer* rc; -- 2.11.4.GIT