diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/dye.cpp | 6 | ||||
-rw-r--r-- | src/resources/dye.h | 6 | ||||
-rw-r--r-- | src/resources/imageloader.cpp | 2 | ||||
-rw-r--r-- | src/resources/imageloader.h | 3 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 13 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 6 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 90 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 12 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 9 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 28 | ||||
-rw-r--r-- | src/resources/spritedef.h | 23 |
12 files changed, 119 insertions, 81 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 3be105d8..d180d725 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -26,7 +26,7 @@ #include "../log.h" -Palette::Palette(std::string const &description) +Palette::Palette(const std::string &description) { int size = description.length(); if (size == 0) return; @@ -109,7 +109,7 @@ void Palette::getColor(int intensity, int color[3]) const color[2] = ((255 - t) * b1 + t * b2) / 255; } -Dye::Dye(std::string const &description) +Dye::Dye(const std::string &description) { for (int i = 0; i < 7; ++i) mPalettes[i] = 0; @@ -175,7 +175,7 @@ void Dye::update(int color[3]) const mPalettes[i - 1]->getColor(cmax, color); } -void Dye::instantiate(std::string &target, std::string const &palettes) +void Dye::instantiate(std::string &target, const std::string &palettes) { std::string::size_type next_pos = target.find('|'); if (next_pos == std::string::npos || palettes.empty()) return; diff --git a/src/resources/dye.h b/src/resources/dye.h index 528a1d91..f0bd7aab 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -36,7 +36,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(std::string const &); + Palette(const std::string &); /** * Gets a pixel color depending on its intensity. @@ -63,7 +63,7 @@ class Dye * The parts of string are separated by semi-colons. Each part starts * by an uppercase letter, followed by a colon and then a palette name. */ - Dye(std::string const &); + Dye(const std::string &); /** * Destroys the associated palettes. @@ -79,7 +79,7 @@ class Dye * Fills the blank in a dye placeholder with some palette names. */ static void instantiate(std::string &target, - std::string const &palettes); + const std::string &palettes); private: diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index 29458ba3..835ba100 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -88,7 +88,7 @@ void ProxyImage::convertToDisplayFormat() mSDLImage = NULL; } -gcn::Image *ImageLoader::load(std::string const &filename, bool convert) +gcn::Image *ImageLoader::load(const std::string &filename, bool convert) { ResourceManager *resman = ResourceManager::getInstance(); ProxyImage *i = new ProxyImage(resman->loadSDLSurface(filename)); diff --git a/src/resources/imageloader.h b/src/resources/imageloader.h index 7979fd2f..821a0254 100644 --- a/src/resources/imageloader.h +++ b/src/resources/imageloader.h @@ -61,7 +61,8 @@ class ProxyImage : public gcn::Image class ImageLoader : public gcn::ImageLoader { public: - gcn::Image *load(std::string const &filename, bool convertToDisplayFormat); + gcn::Image *load(const std::string &filename, + bool convertToDisplayFormat); }; #endif diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index c05d4604..4b3024a7 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -30,6 +30,7 @@ #include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" #include "../utils/xml.h" namespace @@ -53,8 +54,8 @@ void ItemDB::load() mUnknown = new ItemInfo(); mUnknown->setName("Unknown item"); mUnknown->setImageName(""); - mUnknown->setSprite("error.xml", 0); - mUnknown->setSprite("error.xml", 1); + mUnknown->setSprite("error.xml", GENDER_MALE); + mUnknown->setSprite("error.xml", GENDER_FEMALE); XML::Document doc("items.xml"); xmlNodePtr rootNode = doc.rootNode(); @@ -93,9 +94,9 @@ void ItemDB::load() if (id) { - ItemInfo *itemInfo = new ItemInfo(); + ItemInfo *itemInfo = new ItemInfo; itemInfo->setImageName(image); - itemInfo->setName((name == "") ? "Unnamed" : name); + itemInfo->setName(name.empty() ? _("Unnamed") : name); itemInfo->setDescription(description); itemInfo->setEffect(effect); itemInfo->setType(type); @@ -172,12 +173,12 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) if (gender == "male" || gender == "unisex") { - itemInfo->setSprite(filename, 0); + itemInfo->setSprite(filename, GENDER_MALE); } if (gender == "female" || gender == "unisex") { - itemInfo->setSprite(filename, 1); + itemInfo->setSprite(filename, GENDER_FEMALE); } } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index fb2c8ffe..201b8ca9 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -24,7 +24,7 @@ #include "itemdb.h" const std::string& -ItemInfo::getSprite(int gender) const +ItemInfo::getSprite(Gender gender) const { if (mView) { diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 4678bc08..b7729d2c 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -28,6 +28,8 @@ #include "spritedef.h" +#include "../being.h" + enum EquipmentSoundEvent { EQUIP_EVENT_STRIKE, @@ -91,10 +93,10 @@ class ItemInfo void setView(int view) { mView = view; } - void setSprite(const std::string &animationFile, int gender) + void setSprite(const std::string &animationFile, Gender gender) { mAnimationFiles[gender] = animationFile; } - const std::string& getSprite(int gender) const; + const std::string& getSprite(Gender gender) const; void setWeaponType(int); diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 835e52b3..4e116889 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -304,7 +304,8 @@ void MapReader::readProperties(xmlNodePtr node, Properties *props) static void setTile(Map *map, MapLayer *layer, int x, int y, int gid) { const Tileset * const set = map->getTilesetWithGid(gid); - if (layer) { + if (layer) + { // Set regular tile on a layer Image * const img = set ? set->get(gid - set->getFirstGid()) : 0; layer->setTile(x, y, img); @@ -407,6 +408,12 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) setTile(map, layer, x, y, gid); + TileAnimation* ani = map->getAnimationForGid(gid); + if (ani) + { + ani->addAffectedTile(layer, x + y * w); + } + x++; if (x == w) { x = 0; y++; @@ -452,10 +459,12 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map) { + Tileset *set = NULL; + if (xmlHasProp(node, BAD_CAST "source")) { logger->log("Warning: External tilesets not supported yet."); - return NULL; + return set; } const int firstGid = XML::getProperty(node, "firstgid", 0); @@ -464,34 +473,69 @@ Tileset *MapReader::readTileset(xmlNodePtr node, for_each_xml_child_node(childNode, node) { - if (!xmlStrEqual(childNode->name, BAD_CAST "image")) - continue; + if (xmlStrEqual(childNode->name, BAD_CAST "image")) + { + const std::string source = XML::getProperty(childNode, "source", ""); - const std::string source = XML::getProperty(childNode, "source", ""); + if (!source.empty()) + { + std::string sourceStr = source; + sourceStr.erase(0, 3); // Remove "../" + + ResourceManager *resman = ResourceManager::getInstance(); + Image* tilebmp = resman->getImage(sourceStr); - if (!source.empty()) + if (tilebmp) + { + set = new Tileset(tilebmp, tw, th, firstGid); + tilebmp->decRef(); + } + else { + logger->log("Warning: Failed to load tileset (%s)", + source.c_str()); + } + } + } + else if (xmlStrEqual(childNode->name, BAD_CAST "tile")) { - std::string sourceStr = source; - sourceStr.erase(0, 3); // Remove "../" + for_each_xml_child_node(tileNode, childNode) + { + if (!xmlStrEqual(tileNode->name, BAD_CAST "properties")) continue; - ResourceManager *resman = ResourceManager::getInstance(); - Image* tilebmp = resman->getImage(sourceStr); + int tileGID = firstGid + XML::getProperty(childNode, "id", 0); - if (tilebmp) - { - Tileset *set = new Tileset(tilebmp, tw, th, firstGid); - tilebmp->decRef(); - return set; - } - else { - logger->log("Warning: Failed to load tileset (%s)", - source.c_str()); + // read tile properties to a map for simpler handling + std::map<std::string, int> tileProperties; + for_each_xml_child_node(propertyNode, tileNode) + { + if (!xmlStrEqual(propertyNode->name, BAD_CAST "property")) continue; + std::string name = XML::getProperty(propertyNode, "name", ""); + int value = XML::getProperty(propertyNode, "value", 0); + tileProperties[name] = value; + logger->log("Tile Prop of %d \"%s\" = \"%d\"", tileGID, name.c_str(), value); + } + + // create animation + if (!set) continue; + + Animation *ani = new Animation(); + for (int i = 0; ;i++) + { + std::map<std::string, int>::iterator iFrame, iDelay; + iFrame = tileProperties.find("animation-frame" + toString(i)); + iDelay = tileProperties.find("animation-delay" + toString(i)); + if (iFrame != tileProperties.end() && iDelay != tileProperties.end()) + { + ani->addFrame(set->get(iFrame->second), iDelay->second, 0, 0); + } else { + break; + } + } + map->addAnimation(tileGID, new TileAnimation(ani)); + logger->log("Animation length: %d", ani->getLength()); } } - - // Only one image element expected - break; } - return NULL; + return set; } diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a1965d57..3d42d92e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -215,7 +215,7 @@ std::string ResourceManager::getPath(const std::string &file) return path; } -Resource *ResourceManager::get(std::string const &idPath, generator fun, +Resource *ResourceManager::get(const std::string &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. @@ -267,7 +267,7 @@ struct ResourceLoader } }; -Resource *ResourceManager::load(std::string const &path, loader fun) +Resource *ResourceManager::load(const std::string &path, loader fun) { ResourceLoader l = { this, path, fun }; return get(path, ResourceLoader::load, &l); @@ -309,7 +309,7 @@ struct DyedImageLoader } }; -Image *ResourceManager::getImage(std::string const &idPath) +Image *ResourceManager::getImage(const std::string &idPath) { DyedImageLoader l = { this, idPath }; return static_cast<Image*>(get(idPath, DyedImageLoader::load, &l)); @@ -351,8 +351,7 @@ struct SpriteDefLoader } }; -SpriteDef *ResourceManager::getSprite - (std::string const &path, int variant) +SpriteDef *ResourceManager::getSprite(const std::string &path, int variant) { SpriteDefLoader l = { path, variant }; std::stringstream ss; @@ -381,7 +380,8 @@ void ResourceManager::release(Resource *res) ResourceManager *ResourceManager::getInstance() { // Create a new instance if necessary. - if (instance == NULL) instance = new ResourceManager(); + if (!instance) + instance = new ResourceManager(); return instance; } diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index c1007f4a..e70dfb9d 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -98,7 +98,8 @@ class ResourceManager bool isDirectory(const std::string &path); /** - * Returns the real path to a file + * Returns the real path to a file. Note that this method will always + * return a path, it does not check whether the file exists. * * @param file The file to get the real path to. * @return The real path. @@ -114,7 +115,7 @@ class ResourceManager * @return A valid resource or <code>NULL</code> if the resource could * not be generated. */ - Resource *get(std::string const &idPath, generator fun, void *data); + Resource *get(const std::string &idPath, generator fun, void *data); /** * Loads a resource from a file and adds it to the resource map. @@ -124,7 +125,7 @@ class ResourceManager * @return A valid resource or <code>NULL</code> if the resource could * not be loaded. */ - Resource *load(std::string const &path, loader fun); + Resource *load(const std::string &path, loader fun); /** * Convenience wrapper around ResourceManager::get for loading @@ -154,7 +155,7 @@ class ResourceManager * Creates a sprite definition based on a given path and the supplied * variant. */ - SpriteDef *getSprite(std::string const &path, int variant = 0); + SpriteDef *getSprite(const std::string &path, int variant = 0); /** * Releases a resource, placing it in the set of orphaned resources. diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 3eb1d92b..28db0452 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -46,7 +46,7 @@ Action *SpriteDef::getAction(SpriteAction action) const return i->second; } -SpriteDef *SpriteDef::load(std::string const &animationFile, int variant) +SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) { std::string::size_type pos = animationFile.find('|'); std::string palettes; @@ -121,7 +121,7 @@ void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, } } -void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes) +void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes) { const std::string name = XML::getProperty(node, "name", ""); @@ -146,8 +146,7 @@ void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes) mImageSets[name] = imageSet; } -void -SpriteDef::loadAction(xmlNodePtr node, int variant_offset) +void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); @@ -187,10 +186,9 @@ SpriteDef::loadAction(xmlNodePtr node, int variant_offset) } } -void -SpriteDef::loadAnimation(xmlNodePtr animationNode, - Action *action, ImageSet *imageSet, - int variant_offset) +void SpriteDef::loadAnimation(xmlNodePtr animationNode, + Action *action, ImageSet *imageSet, + int variant_offset) { const std::string directionName = XML::getProperty(animationNode, "direction", ""); @@ -267,8 +265,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, } // for frameNode } -void -SpriteDef::includeSprite(xmlNodePtr includeNode) +void SpriteDef::includeSprite(xmlNodePtr includeNode) { // TODO: Perform circular dependency check, since it's easy to crash the // client this way. @@ -289,8 +286,7 @@ SpriteDef::includeSprite(xmlNodePtr includeNode) loadSprite(rootNode, 0); } -void -SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) +void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) { if (mActions.find(complete) == mActions.end()) { @@ -324,8 +320,7 @@ SpriteDef::~SpriteDef() } } -SpriteAction -SpriteDef::makeSpriteAction(const std::string& action) +SpriteAction SpriteDef::makeSpriteAction(const std::string &action) { if (action == "" || action == "default") { return ACTION_DEFAULT; @@ -377,8 +372,7 @@ SpriteDef::makeSpriteAction(const std::string& action) } } -SpriteDirection -SpriteDef::makeSpriteDirection(const std::string& direction) +SpriteDirection SpriteDef::makeSpriteDirection(const std::string& direction) { if (direction == "" || direction == "default") { return DIRECTION_DEFAULT; @@ -397,5 +391,5 @@ SpriteDef::makeSpriteDirection(const std::string& direction) } else { return DIRECTION_INVALID; - }; + } } diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 88f9b7b7..49a4ca51 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -71,7 +71,7 @@ class SpriteDef : public Resource /** * Loads a sprite definition file. */ - static SpriteDef *load(std::string const &file, int variant); + static SpriteDef *load(const std::string &file, int variant); /** * Returns the specified action. @@ -81,8 +81,7 @@ class SpriteDef : public Resource /** * Converts a string into a SpriteAction enum. */ - static SpriteAction - makeSpriteAction(const std::string &action); + static SpriteAction makeSpriteAction(const std::string &action); /** * Converts a string into a SpriteDirection enum. @@ -111,27 +110,24 @@ class SpriteDef : public Resource /** * Loads an imageset element. */ - void loadImageSet(xmlNodePtr node, std::string const &palettes); + void loadImageSet(xmlNodePtr node, const std::string &palettes); /** * Loads an action element. */ - void - loadAction(xmlNodePtr node, int variant_offset); + void loadAction(xmlNodePtr node, int variant_offset); /** * Loads an animation element. */ - void - loadAnimation(xmlNodePtr animationNode, - Action *action, ImageSet *imageSet, - int variant_offset); + void loadAnimation(xmlNodePtr animationNode, + Action *action, ImageSet *imageSet, + int variant_offset); /** * Include another sprite into this one. */ - void - includeSprite(xmlNodePtr includeNode); + void includeSprite(xmlNodePtr includeNode); /** * Complete missing actions by copying existing ones. @@ -142,8 +138,7 @@ class SpriteDef : public Resource * When there are no animations defined for the action "complete", its * animations become a copy of those of the action "with". */ - void - substituteAction(SpriteAction complete, SpriteAction with); + void substituteAction(SpriteAction complete, SpriteAction with); typedef std::map<std::string, ImageSet*> ImageSets; |