From f6cedc9eae7e9380f667b5163a815314ab7a3113 Mon Sep 17 00:00:00 2001 From: Paul Merrill Date: Thu, 9 Jun 2011 01:11:42 -0700 Subject: [PATCH] impl'd Area::processTileType --- src/area.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- src/area.h | 18 +++++++++--------- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/area.cpp b/src/area.cpp index 1f5f405..f33a565 100644 --- a/src/area.cpp +++ b/src/area.cpp @@ -11,6 +11,7 @@ #include "area.h" #include "common.h" #include "entity.h" +#include "log.h" #include "resourcer.h" #include "sprite.h" @@ -173,12 +174,16 @@ bool Area::processTileset(xmlNode* node) if (!xmlStrncmp(child->name, BAD_CAST("tile"), 5)) { xmlChar* idstr = xmlGetProp(child, BAD_CAST("id")); unsigned id = atol((const char*)idstr); + + // Undeclared TileTypes have default properties. while (ts.defaults.size() != id) { TileType tt = defaultTileType(ts.source, ts.tiledim, ts.defaults.size()); ts.defaults.push_back(tt); } - if (!processTileType(child)) + + // Handle explicit TileType + if (!processTileType(child, ts)) return false; } else if (!xmlStrncmp(child->name, BAD_CAST("image"), 6)) { @@ -204,7 +209,7 @@ Area::TileType Area::defaultTileType(const Gosu::Bitmap source, coord_t tiledim, return tt; } -bool Area::processTileType(xmlNode* node) +bool Area::processTileType(xmlNode* node, Tileset& ts) { /* @@ -222,7 +227,46 @@ bool Area::processTileType(xmlNode* node) */ - + + // Initialize a default TileType, we'll build on that. + TileType tt = defaultTileType(ts.source, + ts.tiledim, ts.defaults.size()); + + xmlChar* idstr = xmlGetProp(node, BAD_CAST("tilewidth")); + unsigned id = atol((const char*)idstr); + if (id != ts.defaults.size()) { + // XXX we need to know the Area we're loading... + Log::err("unknown area", std::string("expected TileType id ") + + itostr(ts.defaults.size()) + ", but got " + itostr(id)); + return false; + } + + 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("animated"), 9)) { + tt.animated = parseBool((const char*)value); + } + else if (!xmlStrncmp(name, BAD_CAST("size"), 5)) { + // TODO animation + } + else if (!xmlStrncmp(name, BAD_CAST("speed"), 6)) { + tt.ani_speed = atol((const char*)value); + } + } + + ts.defaults.push_back(tt); return true; } diff --git a/src/area.h b/src/area.h index 994b193..2496f91 100644 --- a/src/area.h +++ b/src/area.h @@ -100,15 +100,6 @@ public: Tile* getTile(coord_t c); private: - bool processDescriptor(); - bool processMapProperties(xmlNode* node); - TileType defaultTileType(const Gosu::Bitmap source, coord_t tiledim, - int id); - bool processTileset(xmlNode* node); - bool processTileType(xmlNode* node); - bool processLayer(xmlNode* node); - bool processObjectGroup(xmlNode* node); - //! Tileset /*! Stores info for a tileset, and global settings for tiles. @@ -128,6 +119,15 @@ private: std::string filename; }; + bool processDescriptor(); + bool processMapProperties(xmlNode* node); + TileType defaultTileType(const Gosu::Bitmap source, coord_t tiledim, + int id); + bool processTileset(xmlNode* node); + bool processTileType(xmlNode* node, Tileset& ts); + bool processLayer(xmlNode* node); + bool processObjectGroup(xmlNode* node); + Resourcer* rc; Entity* player; -- 2.11.4.GIT