diff options
author | David Athay <ko2fan@gmail.com> | 2009-02-11 09:30:26 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2009-02-11 09:30:26 +0000 |
commit | 91111ca5d13072ea3b834e23835df9c077329e39 (patch) | |
tree | f0af8dd08b766164835cf9b5412a9aa3267dbad7 /src/resources | |
parent | 8046bb2626b30fecdcea54eb0aa3349cdb7d277b (diff) | |
parent | 63ac001daa7dfc0735dfefd9c2829c8786b4edaf (diff) | |
download | mana-91111ca5d13072ea3b834e23835df9c077329e39.tar.gz mana-91111ca5d13072ea3b834e23835df9c077329e39.tar.bz2 mana-91111ca5d13072ea3b834e23835df9c077329e39.tar.xz mana-91111ca5d13072ea3b834e23835df9c077329e39.zip |
Merge branch 'master' of git@gitorious.org:tmw/eathena
Diffstat (limited to 'src/resources')
42 files changed, 607 insertions, 228 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index 3fd3237e..e2cb11f2 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -20,12 +20,10 @@ */ #include "action.h" - #include "animation.h" #include "../utils/dtor.h" - Action::Action() { } diff --git a/src/resources/action.h b/src/resources/action.h index c557e6da..649d3828 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -44,11 +44,9 @@ class Action */ ~Action(); - void - setAnimation(int direction, Animation *animation); + void setAnimation(int direction, Animation *animation); - Animation* - getAnimation(int direction) const; + Animation* getAnimation(int direction) const; protected: typedef std::map<int, Animation*> Animations; diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index ef034acf..32ed47d1 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -20,7 +20,6 @@ */ #include "ambientoverlay.h" - #include "image.h" #include "../graphics.h" diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index 62e5ac16..54c319de 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -21,8 +21,6 @@ #include "animation.h" -#include <algorithm> - #include "../utils/dtor.h" Animation::Animation(): @@ -30,22 +28,19 @@ Animation::Animation(): { } -void -Animation::addFrame(Image *image, unsigned int delay, int offsetX, int offsetY) +void Animation::addFrame(Image *image, unsigned int delay, int offsetX, int offsetY) { Frame frame = { image, delay, offsetX, offsetY }; mFrames.push_back(frame); mDuration += delay; } -void -Animation::addTerminator() +void Animation::addTerminator() { addFrame(NULL, 0, 0, 0); } -bool -Animation::isTerminator(const Frame &candidate) +bool Animation::isTerminator(const Frame &candidate) { return (candidate.image == NULL); } diff --git a/src/resources/animation.h b/src/resources/animation.h index 29c99209..0c461ebe 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -54,39 +54,33 @@ class Animation /** * Appends a new animation at the end of the sequence. */ - void - addFrame(Image *image, unsigned int delay, int offsetX, int offsetY); + void addFrame(Image *image, unsigned int delay, int offsetX, int offsetY); /** * Appends an animation terminator that states that the animation * should not loop. */ - void - addTerminator(); + void addTerminator(); /** * Returns the frame at the specified index. */ - Frame* - getFrame(int index) { return &(mFrames[index]); } + Frame* getFrame(int index) { return &(mFrames[index]); } /** * Returns the length of this animation in frames. */ - unsigned int - getLength() const { return mFrames.size(); } + unsigned int getLength() const { return mFrames.size(); } /** * Returns the duration of this animation. */ - int - getDuration() const { return mDuration; } + int getDuration() const { return mDuration; } /** * Determines whether the given animation frame is a terminator. */ - static bool - isTerminator(const Frame &phase); + static bool isTerminator(const Frame &phase); protected: std::vector<Frame> mFrames; diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp index 24198f59..719ecab1 100644 --- a/src/resources/buddylist.cpp +++ b/src/resources/buddylist.cpp @@ -21,13 +21,13 @@ #include <algorithm> #include <cstring> -#include <iostream> #include <fstream> +#include <iostream> #include "buddylist.h" -#include "../main.h" #include "../configuration.h" +#include "../main.h" BuddyList::BuddyList() { @@ -55,9 +55,9 @@ void BuddyList::loadFile() char *buddy = new char[LEN_MAX_USERNAME]; inputStream.getline(buddy, LEN_MAX_USERNAME); // Ugly ? - if(strcmp(buddy,"")) mBuddylist.push_back(buddy); + if (strcmp(buddy, "")) mBuddylist.push_back(buddy); delete [] buddy; - } while(!inputStream.eof()); + } while (!inputStream.eof()); // Read buddy and close file inputStream.close(); @@ -111,7 +111,7 @@ bool BuddyList::removeBuddy(const std::string buddy) return false; } -int BuddyList::getNumberOfElements() +int BuddyList::getNumberOfElements() { return mBuddylist.size(); } diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h index 33fcde4d..f0758c25 100644 --- a/src/resources/buddylist.h +++ b/src/resources/buddylist.h @@ -27,7 +27,8 @@ #include <guichan/listmodel.hpp> -class BuddyList : public gcn::ListModel { +class BuddyList : public gcn::ListModel +{ public: /** * Constructor @@ -52,7 +53,7 @@ class BuddyList : public gcn::ListModel { /** * Returns the number of buddy on the list */ - int getNumberOfElements(); + int getNumberOfElements(); /** * Returns the buddy of the number or null diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp new file mode 100644 index 00000000..3a8754ea --- /dev/null +++ b/src/resources/colordb.cpp @@ -0,0 +1,122 @@ +/* + * Color database + * Copyright (C) 2008 Aethyra Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <libxml/tree.h> + +#include "colordb.h" + +#include "../log.h" + +#include "../utils/xml.h" + +#define HAIR_COLOR_FILE "colors.xml" +#define TMW_COLOR_FILE "hair.xml" + +namespace +{ + ColorDB::Colors mColors; + bool mLoaded = false; + std::string mFail = "#ffffff"; +} + +void ColorDB::load() +{ + if (mLoaded) + { + return; + } + + XML::Document *doc = new XML::Document(HAIR_COLOR_FILE); + xmlNodePtr root = doc->rootNode(); + bool TMWHair = false; + + if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + { + logger->log("Trying TMW's color file, %s.", TMW_COLOR_FILE); + + TMWHair = true; + + delete doc; + + doc = new XML::Document(TMW_COLOR_FILE); + root = doc->rootNode(); + if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + { + logger->log("ColorDB: Failed"); + mColors[0] = mFail; + mLoaded = true; + + delete doc; + + return; + } + } + for_each_xml_child_node(node, root) + { + if (xmlStrEqual(node->name, BAD_CAST "color")) + { + int id = XML::getProperty(node, "id", 0); + + if (mColors.find(id) != mColors.end()) + { + logger->log("ColorDB: Redefinition of dye ID %d", id); + } + + TMWHair ? mColors[id] = XML::getProperty(node, "value", "#FFFFFF") : + mColors[id] = XML::getProperty(node, "dye", "#FFFFFF"); + } + } + + delete doc; + + mLoaded = true; +} + +void ColorDB::unload() +{ + logger->log("Unloading color database..."); + + mColors.clear(); + mLoaded = false; +} + +std::string& ColorDB::get(int id) +{ + if (!mLoaded) + load(); + + ColorIterator i = mColors.find(id); + + if (i == mColors.end()) + { + logger->log("ColorDB: Error, unknown dye ID# %d", id); + return mFail; + } + else + { + return i->second; + } +} + +int ColorDB::size() +{ + return mColors.size(); +} diff --git a/src/resources/colordb.h b/src/resources/colordb.h new file mode 100644 index 00000000..c581f653 --- /dev/null +++ b/src/resources/colordb.h @@ -0,0 +1,52 @@ +/* + * Color database + * Copyright (C) 2008 Aethyra Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef COLOR_MANAGER_H +#define COLOR_MANAGER_H + +#include <map> +#include <string> + +/** + * The class that holds the color information. + */ +namespace ColorDB +{ + /** + * Loads the color data from <code>colors.xml</code>. + */ + void load(); + + /** + * Clear the color data + */ + void unload(); + + std::string& get(int id); + + int size(); + + // Color DB + typedef std::map<int, std::string> Colors; + typedef Colors::iterator ColorIterator; +} + +#endif diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 1b34a403..22bd2411 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -19,7 +19,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <algorithm> #include <sstream> #include "dye.h" diff --git a/src/resources/dye.h b/src/resources/dye.h index d32c3f22..3cef334a 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -22,6 +22,7 @@ #ifndef DYE_H #define DYE_H +#include <string> #include <vector> /** @@ -36,7 +37,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(const std::string &); + Palette(const std::string &pallete); /** * Gets a pixel color depending on its intensity. @@ -63,7 +64,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(const std::string &); + Dye(const std::string &dye); /** * Destroys the associated palettes. diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp new file mode 100644 index 00000000..77c3c2fb --- /dev/null +++ b/src/resources/emotedb.cpp @@ -0,0 +1,140 @@ +/* + * Emote database + * Copyright (C) 2008 Aethyra Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "emotedb.h" + +#include "../log.h" + +#include "../utils/xml.h" + +namespace +{ + EmoteInfos mEmoteInfos; + EmoteInfo mUnknown; + bool mLoaded = false; + int mLastEmote = 0; +} + +void EmoteDB::load() +{ + if (mLoaded) + return; + + mLastEmote = 0; + + EmoteSprite *unknownSprite = new EmoteSprite; + unknownSprite->sprite = "error.xml"; + unknownSprite->name = "unknown"; + unknownSprite->variant = 0; + mUnknown.sprites.push_back(unknownSprite); + + logger->log("Initializing emote database..."); + + XML::Document doc("emotes.xml"); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes")) + { + logger->log("Emote Database: Error while loading emotes.xml!"); + return; + } + + //iterate <emote>s + for_each_xml_child_node(emoteNode, rootNode) + { + if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote")) + continue; + + int id = XML::getProperty(emoteNode, "id", -1); + if (id == -1) + { + logger->log("Emote Database: Emote with missing ID in emotes.xml!"); + continue; + } + + EmoteInfo *currentInfo = new EmoteInfo; + + for_each_xml_child_node(spriteNode, emoteNode) + { + if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + { + EmoteSprite *currentSprite = new EmoteSprite; + currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content; + currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + currentInfo->sprites.push_back(currentSprite); + } + else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + { + std::string particlefx = (const char*) spriteNode->xmlChildrenNode->content; + currentInfo->particles.push_back(particlefx); + } + } + mEmoteInfos[id] = currentInfo; + if (id > mLastEmote) mLastEmote = id; + } + + mLoaded = true; +} + +void EmoteDB::unload() +{ + for ( EmoteInfosIterator i = mEmoteInfos.begin(); + i != mEmoteInfos.end(); + i++) + { + while (!i->second->sprites.empty()) + { + delete i->second->sprites.front(); + i->second->sprites.pop_front(); + } + delete i->second; + } + + mEmoteInfos.clear(); + + while (!mUnknown.sprites.empty()) + { + delete mUnknown.sprites.front(); + mUnknown.sprites.pop_front(); + } + + mLoaded = false; +} + +const EmoteInfo& EmoteDB::get(int id) +{ + EmoteInfosIterator i = mEmoteInfos.find(id); + + if (i == mEmoteInfos.end()) + { + logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); + return mUnknown; + } + else + { + return *(i->second); + } +} + +const int& EmoteDB::getLast() +{ + return mLastEmote; +} diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h new file mode 100644 index 00000000..2cf3af62 --- /dev/null +++ b/src/resources/emotedb.h @@ -0,0 +1,60 @@ +/* + * Emote database + * Copyright (C) 2008 Aethyra Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EMOTE_DB_H +#define EMOTE_DB_H + +#include <list> +#include <map> +#include <string> + +struct EmoteSprite +{ + std::string sprite; + std::string name; + int variant; +}; + +struct EmoteInfo +{ + std::list<EmoteSprite*> sprites; + std::list<std::string> particles; +}; + +typedef std::map<int, EmoteInfo*> EmoteInfos; + +/** + * Emote information database. + */ +namespace EmoteDB +{ + void load(); + + void unload(); + + const EmoteInfo& get(int id); + + const int& getLast(); + + typedef EmoteInfos::iterator EmoteInfosIterator; +} + +#endif diff --git a/src/resources/image.cpp b/src/resources/image.cpp index cc986c81..7a7e6ac8 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -21,9 +21,8 @@ #include <SDL_image.h> -#include "image.h" - #include "dye.h" +#include "image.h" #include "../log.h" @@ -168,7 +167,8 @@ Image *Image::load(SDL_Surface *tmpImage) tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, 32, rmask, gmask, bmask, amask); - if (!tmpImage) { + if (!tmpImage) + { logger->log("Error, image convert failed: out of memory"); return NULL; } @@ -179,9 +179,8 @@ Image *Image::load(SDL_Surface *tmpImage) glGenTextures(1, &texture); glBindTexture(mTextureType, texture); - if (SDL_MUSTLOCK(tmpImage)) { + if (SDL_MUSTLOCK(tmpImage)) SDL_LockSurface(tmpImage); - } glTexImage2D( mTextureType, 0, 4, @@ -256,14 +255,13 @@ Image *Image::load(SDL_Surface *tmpImage) SDL_Surface *image; // Convert the surface to the current display format - if (hasAlpha) { + if (hasAlpha) image = SDL_DisplayFormatAlpha(tmpImage); - } - else { + else image = SDL_DisplayFormat(tmpImage); - } - if (!image) { + if (!image) + { logger->log("Error: Image convert failed."); return NULL; } @@ -275,14 +273,16 @@ void Image::unload() { mLoaded = false; - if (mImage) { + if (mImage) + { // Free the image surface. SDL_FreeSurface(mImage); mImage = NULL; } #ifdef USE_OPENGL - if (mGLImage) { + if (mGLImage) + { glDeleteTextures(1, &mGLImage); mGLImage = 0; } @@ -293,10 +293,9 @@ Image *Image::getSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image #ifdef USE_OPENGL - if (mUseOpenGL) { + if (mUseOpenGL) return new SubImage(this, mGLImage, x, y, width, height, mTexWidth, mTexHeight); - } #endif return new SubImage(this, mImage, x, y, width, height); @@ -304,13 +303,13 @@ Image *Image::getSubImage(int x, int y, int width, int height) void Image::setAlpha(float a) { - if (mAlpha == a) { + if (mAlpha == a) return; - } mAlpha = a; - if (mImage) { + if (mImage) + { // Set the alpha value this image is drawn at SDL_SetAlpha(mImage, SDL_SRCALPHA, (int) (255 * mAlpha)); } @@ -322,14 +321,12 @@ float Image::getAlpha() } #ifdef USE_OPENGL -void -Image::setLoadAsOpenGL(bool useOpenGL) +void Image::setLoadAsOpenGL(bool useOpenGL) { Image::mUseOpenGL = useOpenGL; } -int -Image::powerOfTwo(int input) +int Image::powerOfTwo(int input) { int value; if (mTextureType == GL_TEXTURE_2D) @@ -354,7 +351,8 @@ Image::powerOfTwo(int input) SubImage::SubImage(Image *parent, SDL_Surface *image, int x, int y, int width, int height): - Image(image), mParent(parent) + Image(image), + mParent(parent) { mParent->incRef(); @@ -369,7 +367,8 @@ SubImage::SubImage(Image *parent, SDL_Surface *image, SubImage::SubImage(Image *parent, GLuint image, int x, int y, int width, int height, int texWidth, int texHeight): - Image(image, width, height, texWidth, texHeight), mParent(parent) + Image(image, width, height, texWidth, texHeight), + mParent(parent) { mParent->incRef(); @@ -395,3 +394,4 @@ Image *SubImage::getSubImage(int x, int y, int w, int h) { return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); } + diff --git a/src/resources/image.h b/src/resources/image.h index 963fbb24..fe3081ac 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -22,9 +22,10 @@ #ifndef IMAGE_H #define IMAGE_H +#include <SDL.h> + #include "../main.h" -#include <SDL.h> #ifdef USE_OPENGL /* The definition of OpenGL extensions by SDL is giving problems with recent @@ -39,6 +40,8 @@ #include "resource.h" class Dye; +class SDL_Rect; +class SDL_Surface; /** * Defines a class for loading and storing images. @@ -96,7 +99,6 @@ class Image : public Resource virtual int getWidth() const { return mBounds.w; } - /** * Returns the height of the image. */ @@ -114,7 +116,7 @@ class Image : public Resource /** * Sets the alpha value of this image. */ - void setAlpha(float alpha); + virtual void setAlpha(float alpha); /** * Returns the alpha value of this image. @@ -129,7 +131,6 @@ class Image : public Resource static void setLoadAsOpenGL(bool useOpenGL); #endif - protected: /** * Constructor. diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index 5aad7c52..40d62797 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -20,13 +20,12 @@ */ #include <cassert> -#include <string> + #include <guichan/color.hpp> #include <guichan/sdl/sdlpixel.hpp> -#include "imageloader.h" - #include "image.h" +#include "imageloader.h" #include "resourcemanager.h" ProxyImage::ProxyImage(SDL_Surface *s): diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 458b0405..92bb3242 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -19,12 +19,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "image.h" #include "imageset.h" #include "../log.h" -#include "image.h" - #include "../utils/dtor.h" ImageSet::ImageSet(Image *img, int width, int height) @@ -45,8 +44,7 @@ ImageSet::~ImageSet() delete_all(mImages); } -Image* -ImageSet::get(size_type i) const +Image* ImageSet::get(size_type i) const { if (i >= mImages.size()) { diff --git a/src/resources/imageset.h b/src/resources/imageset.h index 00a36754..f59c76bb 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -28,7 +28,6 @@ class Image; - /** * Stores a set of subimages originating from a single image. */ diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index d6bb4659..c350ac07 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -19,11 +19,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "imagewriter.h" - #include <png.h> -#include <string> #include <SDL.h> +#include <string> + +#include "imagewriter.h" #include "../log.h" diff --git a/src/resources/imagewriter.h b/src/resources/imagewriter.h index 8eb6cead..039d3afb 100644 --- a/src/resources/imagewriter.h +++ b/src/resources/imagewriter.h @@ -19,13 +19,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <iosfwd> - struct SDL_Surface; class ImageWriter { public: static bool writePNG(SDL_Surface *surface, - const std::string &filename); + const std::string &filename); }; diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 1678eda8..6fa010d4 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -20,22 +20,22 @@ */ #include <cassert> + #include <libxml/tree.h> #include "itemdb.h" -#include "iteminfo.h" -#include "resourcemanager.h" - #include "../log.h" #include "../utils/dtor.h" #include "../utils/gettext.h" +#include "../utils/trim.h" #include "../utils/xml.h" namespace { ItemDB::ItemInfos mItemInfos; + ItemDB::NamedItemInfos mNamedItemInfos; ItemInfo *mUnknown; bool mLoaded = false; } @@ -52,17 +52,17 @@ void ItemDB::load() logger->log("Initializing item database..."); mUnknown = new ItemInfo(); - mUnknown->setName("Unknown item"); + mUnknown->setName(_("Unknown item")); mUnknown->setImageName(""); mUnknown->setSprite("error.xml", GENDER_MALE); mUnknown->setSprite("error.xml", GENDER_FEMALE); - XML::Document doc("items.xml"); + XML::Document doc(_("items.xml")); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items")) { - logger->error("ItemDB: Error while loading items.xml!"); + logger->error(_("ItemDB: Error while loading items.xml!")); } for_each_xml_child_node(node, rootNode) @@ -82,7 +82,7 @@ void ItemDB::load() logger->log("ItemDB: Redefinition of item ID %d", id); } - int type = XML::getProperty(node, "type", 0); + std::string type = XML::getProperty(node, "type", "other"); int weight = XML::getProperty(node, "weight", 0); int view = XML::getProperty(node, "view", 0); @@ -95,6 +95,7 @@ void ItemDB::load() if (id) { ItemInfo *itemInfo = new ItemInfo; + itemInfo->setId(id); itemInfo->setImageName(image); itemInfo->setName(name.empty() ? _("Unnamed") : name); itemInfo->setDescription(description); @@ -117,6 +118,27 @@ void ItemDB::load() } mItemInfos[id] = itemInfo; + if (!name.empty()) + { + NamedItemInfoIterator itr = mNamedItemInfos.find(name); + if (itr == mNamedItemInfos.end()) + { + std::string temp = name; + trim(temp); + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } + + mNamedItemInfos[temp] = itemInfo; + } + else + { + logger->log("ItemDB: Duplicate name of item found item %d", + id); + } + } } #define CHECK_PARAM(param, error_value) \ @@ -126,7 +148,7 @@ void ItemDB::load() CHECK_PARAM(name, ""); CHECK_PARAM(image, ""); CHECK_PARAM(description, ""); - CHECK_PARAM(effect, ""); + // CHECK_PARAM(effect, ""); // CHECK_PARAM(type, 0); // CHECK_PARAM(weight, 0); // CHECK_PARAM(slot, 0); @@ -166,6 +188,23 @@ const ItemInfo& ItemDB::get(int id) } } +const ItemInfo& ItemDB::get(const std::string &name) +{ + assert(mLoaded && !name.empty()); + + NamedItemInfoIterator i = mNamedItemInfos.find(name); + + if (i == mNamedItemInfos.end()) + { + logger->log("ItemDB: Error, unknown item name %s", name.c_str()); + return *mUnknown; + } + else + { + return *(i->second); + } +} + void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) { std::string gender = XML::getProperty(node, "gender", "unisex"); @@ -175,7 +214,6 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) { itemInfo->setSprite(filename, GENDER_MALE); } - if (gender == "female" || gender == "unisex") { itemInfo->setSprite(filename, GENDER_FEMALE); diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 03fb1eed..08a7acd0 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -22,9 +22,11 @@ #ifndef ITEM_MANAGER_H #define ITEM_MANAGER_H +#include <map> + #include "iteminfo.h" -#include <map> +class ItemInfo; /** * The namespace that holds the item information. @@ -42,10 +44,13 @@ namespace ItemDB void unload(); const ItemInfo& get(int id); + const ItemInfo& get(const std::string &name); // Items database typedef std::map<int, ItemInfo*> ItemInfos; + typedef std::map<std::string, ItemInfo*> NamedItemInfos; typedef ItemInfos::iterator ItemInfoIterator; + typedef NamedItemInfos::iterator NamedItemInfoIterator; } #endif diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index b924c591..2f118284 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -19,12 +19,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "iteminfo.h" - #include "itemdb.h" +#include "iteminfo.h" -const std::string& -ItemInfo::getSprite(Gender gender) const +const std::string& ItemInfo::getSprite(Gender gender) const { if (mView) { @@ -67,15 +65,12 @@ void ItemInfo::setWeaponType(int type) } } -void -ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) +void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) { mSounds[event].push_back("sfx/" + filename); } - -const std::string& -ItemInfo::getSound(EquipmentSoundEvent event) const +const std::string& ItemInfo::getSound(EquipmentSoundEvent event) const { static const std::string empty; std::map< EquipmentSoundEvent, std::vector<std::string> >::const_iterator i; diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index a04213ff..c03dec28 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -47,13 +47,19 @@ class ItemInfo * Constructor. */ ItemInfo(): - mType(0), + mType(""), mWeight(0), mView(0), mAttackType(ACTION_DEFAULT) { } + void setId(int id) + { mId = id; } + + int getId() const + { return mId; } + void setName(const std::string &name) { mName = name; } @@ -75,14 +81,12 @@ class ItemInfo void setEffect(const std::string &effect) { mEffect = effect; } - const std::string& - getEffect() const { return mEffect; } + const std::string& getEffect() const { return mEffect; } - void setType(short type) + void setType(const std::string& type) { mType = type; } - short getType() const - { return mType; } + const std::string& getType() const { return mType; } void setWeight(short weight) { mWeight = weight; } @@ -112,9 +116,10 @@ class ItemInfo std::string mName; std::string mDescription; /**< Short description. */ std::string mEffect; /**< Description of effects. */ - char mType; /**< Item type. */ + std::string mType; /**< Item type. */ short mWeight; /**< Weight in grams. */ int mView; /**< Item ID of how this item looks. */ + int mId; /**< Item ID */ // Equipment related members SpriteAction mAttackType; /**< Attack type, in case of weapon. */ diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 21125c2a..3270c665 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -19,14 +19,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mapreader.h" - #include <cassert> #include <iostream> #include <zlib.h> -#include "resourcemanager.h" +#include "animation.h" #include "image.h" +#include "mapreader.h" +#include "resourcemanager.h" #include "../log.h" #include "../map.h" @@ -205,14 +205,11 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) // Take the filename off the path const std::string pathDir = path.substr(0, path.rfind("/") + 1); - //xmlChar *prop = xmlGetProp(node, BAD_CAST "version"); - //xmlFree(prop); - const int w = XML::getProperty(node, "width", 0); const int h = XML::getProperty(node, "height", 0); - const int tw = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH); - const int th = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT); - Map *map = new Map(w, h, tw, th); + const int tilew = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH); + const int tileh = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT); + Map *map = new Map(w, h, tilew, tileh); for_each_xml_child_node(childNode, node) { @@ -236,8 +233,8 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) // The object group offset is applied to each object individually const int tileOffsetX = XML::getProperty(childNode, "x", 0); const int tileOffsetY = XML::getProperty(childNode, "y", 0); - const int offsetX = tileOffsetX * tw; - const int offsetY = tileOffsetY * th; + const int offsetX = tileOffsetX * tilew; + const int offsetY = tileOffsetY * tileh; for_each_xml_child_node(objectNode, childNode) { @@ -326,8 +323,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) const int offsetY = XML::getProperty(node, "y", 0); const std::string name = XML::getProperty(node, "name", ""); - const bool isFringeLayer = (name == "Fringe"); - const bool isCollisionLayer = (name == "Collision"); + const bool isFringeLayer = (name.substr(0,6) == "Fringe"); + const bool isCollisionLayer = (name.substr(0,9) == "Collision"); MapLayer *layer = 0; @@ -370,7 +367,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) while (*charStart) { if (*charStart != ' ' && *charStart != '\t' && - *charStart != '\n') + *charStart != '\n') { *charIndex = *charStart; charIndex++; @@ -461,15 +458,20 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map) { + int firstGid = XML::getProperty(node, "firstgid", 0); + XML::Document* doc = NULL; Tileset *set = NULL; if (xmlHasProp(node, BAD_CAST "source")) { - logger->log("Warning: External tilesets not supported yet."); - return set; + std::string filename = XML::getProperty(node, "source", ""); + while (filename.substr(0, 3) == "../") + filename.erase(0, 3); // Remove "../" + doc = new XML::Document(filename); + node = doc->rootNode(); + firstGid += XML::getProperty(node, "firstgid", 0); } - const int firstGid = XML::getProperty(node, "firstgid", 0); const int tw = XML::getProperty(node, "tilewidth", map->getTileWidth()); const int th = XML::getProperty(node, "tileheight", map->getTileHeight()); @@ -545,5 +547,7 @@ Tileset *MapReader::readTileset(xmlNodePtr node, } } + delete doc; + return set; } diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index 8cb2749d..0ed553c3 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -22,12 +22,10 @@ #ifndef MAPREADER_H #define MAPREADER_H -#include <iosfwd> - #include <libxml/tree.h> -class Properties; class Map; +class Properties; class Tileset; /** diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 5d452db2..15451c95 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -20,12 +20,12 @@ */ #include "monsterdb.h" - -#include "resourcemanager.h" +#include "monsterinfo.h" #include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" #include "../utils/xml.h" namespace @@ -35,23 +35,22 @@ namespace bool mLoaded = false; } -void -MonsterDB::load() +void MonsterDB::load() { if (mLoaded) return; mUnknown.addSprite("error.xml"); - mUnknown.setName("unnamed"); + mUnknown.setName(_("unnamed")); logger->log("Initializing monster database..."); - XML::Document doc("monsters.xml"); + XML::Document doc(_("monsters.xml")); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters")) { - logger->error("Monster Database: Error while loading monster.xml!"); + logger->error(_("Monster Database: Error while loading monster.xml!")); } //iterate <monster>s @@ -82,7 +81,8 @@ MonsterDB::load() } else { - logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", + logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s -" + "using medium sized one", targetCursor.c_str(), currentInfo->getName().c_str()); currentInfo->setTargetCursorSize(Being::TC_MEDIUM); } @@ -92,7 +92,8 @@ MonsterDB::load() { if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { - currentInfo->addSprite((const char*) spriteNode->xmlChildrenNode->content); + currentInfo->addSprite( + (const char*) spriteNode->xmlChildrenNode->content); } if (xmlStrEqual(spriteNode->name, BAD_CAST "sound")) @@ -119,11 +120,20 @@ MonsterDB::load() } else { - logger->log("MonsterDB: Warning, sound effect %s for unknown event %s of monster %s", - filename, event.c_str(), currentInfo->getName().c_str()); + logger->log("MonsterDB: Warning, sound effect %s for " + "unknown event %s of monster %s", + filename, event.c_str(), + currentInfo->getName().c_str()); } } + if (xmlStrEqual(spriteNode->name, BAD_CAST "attack")) + { + std::string event = XML::getProperty( + spriteNode, "particle-effect", ""); + currentInfo->addAttackParticleEffect(event); + } + if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { currentInfo->addParticleEffect( diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index 8555670b..0a218661 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -24,18 +24,16 @@ #include <map> -#include "monsterinfo.h" +class MonsterInfo; /** * Monster information database. */ namespace MonsterDB { - void - load(); + void load(); - void - unload(); + void unload(); const MonsterInfo& get(int id); diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index d8ff8be3..503990e7 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -36,8 +36,7 @@ MonsterInfo::~MonsterInfo() } -void -MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) +void MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) { if (mSounds.find(event) == mSounds.end()) { @@ -48,8 +47,7 @@ MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) } -std::string -MonsterInfo::getSound(MonsterSoundEvent event) const +std::string MonsterInfo::getSound(MonsterSoundEvent event) const { std::map<MonsterSoundEvent, std::vector<std::string>* >::const_iterator i; diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index b37ac1a9..359791fd 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -22,14 +22,13 @@ #ifndef MONSTERINFO_H #define MONSTERINFO_H +#include <list> #include <map> #include <string> #include <vector> -#include <list> #include "../being.h" - enum MonsterSoundEvent { MONSTER_EVENT_HIT, @@ -57,39 +56,39 @@ class MonsterInfo */ ~MonsterInfo(); - void - setName(std::string name) { mName = name; } + void setName(std::string name) { mName = name; } - void - addSprite(std::string filename) { mSprites.push_back(filename); } + void addSprite(std::string filename) { mSprites.push_back(filename); } - void - setTargetCursorSize(Being::TargetCursorSize targetCursorSize) + void setTargetCursorSize(Being::TargetCursorSize targetCursorSize) { mTargetCursorSize = targetCursorSize; } - void - addSound(MonsterSoundEvent event, std::string filename); + void addSound(MonsterSoundEvent event, std::string filename); + + void addParticleEffect(std::string filename); + + const std::string& getName() const + { return mName; } - void - addParticleEffect(std::string filename); + const std::list<std::string>& getSprites() const + { return mSprites; } - const std::string& - getName() const { return mName; } + Being::TargetCursorSize getTargetCursorSize() const + { return mTargetCursorSize; } - const std::list<std::string>& - getSprites() const { return mSprites; } + std::string getSound(MonsterSoundEvent event) const; - Being::TargetCursorSize - getTargetCursorSize() const { return mTargetCursorSize; } + std::string getAttackParticleEffect() const { return mAttackParticle; } - std::string - getSound(MonsterSoundEvent event) const; + void addAttackParticleEffect(const std::string &particleEffect) + { mAttackParticle = particleEffect; } - const std::list<std::string>& - getParticleEffects() const { return mParticleEffects; } + const std::list<std::string>& getParticleEffects() const + { return mParticleEffects; } private: std::string mName; + std::string mAttackParticle; std::list<std::string> mSprites; Being::TargetCursorSize mTargetCursorSize; std::map<MonsterSoundEvent, std::vector<std::string>* > mSounds; diff --git a/src/resources/music.cpp b/src/resources/music.cpp index 3b81d05b..ed78a541 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -55,8 +55,7 @@ Resource *Music::load(void *buffer, unsigned bufferSize) } } -bool -Music::play(int loops) +bool Music::play(int loops) { /* * Warning: loops should be always set to -1 (infinite) with current @@ -71,8 +70,7 @@ Music::play(int loops) return mChannel != -1; } -void -Music::stop() +void Music::stop() { /* * Warning: very dungerous trick, it could try to stop channels occupied diff --git a/src/resources/music.h b/src/resources/music.h index cff18338..65f1ee88 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -56,14 +56,12 @@ class Music : public Resource * @return <code>true</code> if the playback started properly * <code>false</code> otherwise. */ - virtual bool - play(int loops); + virtual bool play(int loops); /** * Stops the music. */ - virtual void - stop(); + virtual void stop(); protected: /** diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 9faef60d..ee65136a 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -21,11 +21,9 @@ #include "npcdb.h" -#include "resourcemanager.h" - #include "../log.h" -#include "../utils/dtor.h" +#include "../utils/gettext.h" #include "../utils/xml.h" namespace @@ -52,10 +50,10 @@ void NPCDB::load() if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "npcs")) { - logger->error("NPC Database: Error while loading items.xml!"); + logger->error(_("NPC Database: Error while loading npcs.xml!")); } - //iterate <monster>s + //iterate <npc>s for_each_xml_child_node(npcNode, rootNode) { if (!xmlStrEqual(npcNode->name, BAD_CAST "npc")) @@ -91,8 +89,7 @@ void NPCDB::load() mLoaded = true; } -void -NPCDB::unload() +void NPCDB::unload() { for ( NPCInfosIterator i = mNPCInfos.begin(); i != mNPCInfos.end(); @@ -117,8 +114,7 @@ NPCDB::unload() mLoaded = false; } -const NPCInfo& -NPCDB::get(int id) +const NPCInfo& NPCDB::get(int id) { NPCInfosIterator i = mNPCInfos.find(id); diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h index a7f28c50..af6764bf 100644 --- a/src/resources/npcdb.h +++ b/src/resources/npcdb.h @@ -22,8 +22,8 @@ #ifndef NPC_DB_H #define NPC_DB_H -#include <map> #include <list> +#include <map> #include <string> struct NPCsprite @@ -45,11 +45,9 @@ typedef std::map<int, NPCInfo*> NPCInfos; */ namespace NPCDB { - void - load(); + void load(); - void - unload(); + void unload(); const NPCInfo& get(int id); diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 4c173962..d1c3ada4 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -22,21 +22,18 @@ #include <cassert> #include "resource.h" - #include "resourcemanager.h" Resource::~Resource() { } -void -Resource::incRef() +void Resource::incRef() { mRefCount++; } -void -Resource::decRef() +void Resource::decRef() { // Reference may not already have reached zero assert(mRefCount != 0); diff --git a/src/resources/resource.h b/src/resources/resource.h index 0dc50c03..7c5f989e 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -41,8 +41,7 @@ class Resource /** * Increments the internal reference count. */ - void - incRef(); + void incRef(); /** * Decrements the reference count and deletes the object @@ -51,8 +50,7 @@ class Resource * @return <code>true</code> if the object was deleted * <code>false</code> otherwise. */ - void - decRef(); + void decRef(); /** * Return the path identifying this resource. @@ -64,8 +62,7 @@ class Resource /** * Destructor. */ - virtual - ~Resource(); + virtual ~Resource(); private: std::string mIdPath; /**< Path identifying this resource. */ diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index febcf0d0..fa8f4654 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -20,24 +20,22 @@ */ #include <cassert> -#include <sstream> -#include <sys/time.h> - #include <physfs.h> #include <SDL_image.h> +#include <sstream> -#include "resourcemanager.h" +#include <sys/time.h> #include "dye.h" #include "image.h" +#include "imageset.h" #include "music.h" +#include "resourcemanager.h" #include "soundeffect.h" -#include "imageset.h" #include "spritedef.h" #include "../log.h" - ResourceManager *ResourceManager::instance = NULL; ResourceManager::ResourceManager() @@ -155,13 +153,13 @@ bool ResourceManager::addToSearchPath(const std::string &path, bool append) } void ResourceManager::searchAndAddArchives(const std::string &path, - const std::string &ext, - bool append) + const std::string &ext, + bool append) { const char *dirSep = PHYSFS_getDirSeparator(); char **list = PHYSFS_enumerateFiles(path.c_str()); - for (char **i = list; *i != NULL; i++) + for (char **i = list; *i; i++) { size_t len = strlen(*i); @@ -209,7 +207,7 @@ std::string ResourceManager::getPath(const std::string &file) else { // if not found in search path return the default path - path = std::string(TMW_DATADIR) + std::string("data") + "/" + file; + path = std::string(PKG_DATADIR) + std::string("data") + "/" + file; } return path; @@ -420,8 +418,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize) return buffer; } -std::vector<std::string> -ResourceManager::loadTextFile(const std::string &fileName) +std::vector<std::string> ResourceManager::loadTextFile(const std::string &fileName) { int contentsLength; char *fileContents = (char*)loadFile(fileName, contentsLength); diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 6a7a2ed6..c3c68d88 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -27,11 +27,11 @@ #include <string> #include <vector> -class Resource; class Image; +class ImageSet; class Music; +class Resource; class SoundEffect; -class ImageSet; class SpriteDef; struct SDL_Surface; @@ -100,7 +100,7 @@ class ResourceManager /** * 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. */ diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 21488511..3a285730 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -47,8 +47,7 @@ Resource *SoundEffect::load(void *buffer, unsigned bufferSize) } } -bool -SoundEffect::play(int loops, int volume) +bool SoundEffect::play(int loops, int volume) { Mix_VolumeChunk(mChunk, volume); diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 5f511b29..116df930 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -35,8 +35,7 @@ class SoundEffect : public Resource /** * Destructor. */ - virtual - ~SoundEffect(); + virtual ~SoundEffect(); /** * Loads a sample from a buffer in memory. @@ -58,8 +57,7 @@ class SoundEffect : public Resource * @return <code>true</code> if the playback started properly * <code>false</code> otherwise. */ - virtual bool - play(int loops, int volume); + virtual bool play(int loops, int volume); protected: /** diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 64ce8b0a..20c79e73 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -21,14 +21,13 @@ #include <set> -#include "spritedef.h" - #include "action.h" #include "animation.h" #include "dye.h" #include "image.h" #include "imageset.h" #include "resourcemanager.h" +#include "spritedef.h" #include "../log.h" #include "../utils/xml.h" @@ -322,7 +321,7 @@ SpriteDef::~SpriteDef() SpriteAction SpriteDef::makeSpriteAction(const std::string &action) { - if (action == "" || action == "default") { + if (action.empty() || action == "default") { return ACTION_DEFAULT; } if (action == "stand") { @@ -374,7 +373,7 @@ SpriteAction SpriteDef::makeSpriteAction(const std::string &action) SpriteDirection SpriteDef::makeSpriteDirection(const std::string& direction) { - if (direction == "" || direction == "default") { + if (direction.empty() || direction == "default") { return DIRECTION_DEFAULT; } else if (direction == "up") { diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index b86a4c4d..b9d7b85d 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -25,10 +25,10 @@ #include <map> #include <string> -#include "resource.h" - #include <libxml/tree.h> +#include "resource.h" + class Action; class ImageSet; @@ -89,7 +89,6 @@ class SpriteDef : public Resource static SpriteDirection makeSpriteDirection(const std::string &direction); - private: /** * Constructor. @@ -140,7 +139,6 @@ class SpriteDef : public Resource */ void substituteAction(SpriteAction complete, SpriteAction with); - typedef std::map<std::string, ImageSet*> ImageSets; typedef ImageSets::iterator ImageSetIterator; |