00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SPRITEDEF_H
00023 #define SPRITEDEF_H
00024
00025 #include "resources/resource.h"
00026
00027 #include <map>
00028 #include <string>
00029
00030 #include <libxml/tree.h>
00031
00032 class Action;
00033 class ImageSet;
00034
00035 enum SpriteAction
00036 {
00037 ACTION_DEFAULT = 0,
00038 ACTION_STAND,
00039 ACTION_WALK,
00040 ACTION_RUN,
00041 ACTION_ATTACK,
00042 ACTION_ATTACK_SWING,
00043 ACTION_ATTACK_STAB,
00044 ACTION_ATTACK_BOW,
00045 ACTION_ATTACK_THROW,
00046 ACTION_SPECIAL_0,
00047 ACTION_SPECIAL_1,
00048 ACTION_SPECIAL_2,
00049 ACTION_SPECIAL_3,
00050 ACTION_SPECIAL_4,
00051 ACTION_SPECIAL_5,
00052 ACTION_SPECIAL_6,
00053 ACTION_SPECIAL_7,
00054 ACTION_SPECIAL_8,
00055 ACTION_SPECIAL_9,
00056 ACTION_CAST_MAGIC,
00057 ACTION_USE_ITEM,
00058 ACTION_SIT,
00059 ACTION_SLEEP,
00060 ACTION_HURT,
00061 ACTION_DEAD,
00062 ACTION_INVALID
00063 };
00064
00065 enum SpriteDirection
00066 {
00067 DIRECTION_DEFAULT = 0,
00068 DIRECTION_UP,
00069 DIRECTION_DOWN,
00070 DIRECTION_LEFT,
00071 DIRECTION_RIGHT,
00072 DIRECTION_INVALID
00073 };
00074
00078 class SpriteDef : public Resource
00079 {
00080 public:
00084 static SpriteDef *load(const std::string &file, int variant);
00085
00089 Action *getAction(SpriteAction action) const;
00090
00094 static SpriteAction makeSpriteAction(const std::string &action);
00095
00099 static SpriteDirection
00100 makeSpriteDirection(const std::string &direction);
00101
00102 private:
00106 SpriteDef() {}
00107
00111 ~SpriteDef();
00112
00116 void loadSprite(xmlNodePtr spriteNode, int variant,
00117 const std::string &palettes = "");
00118
00122 void loadImageSet(xmlNodePtr node, const std::string &palettes);
00123
00127 void loadAction(xmlNodePtr node, int variant_offset);
00128
00132 void loadAnimation(xmlNodePtr animationNode,
00133 Action *action, ImageSet *imageSet,
00134 int variant_offset);
00135
00139 void includeSprite(xmlNodePtr includeNode);
00140
00144 void substituteActions();
00145
00150 void substituteAction(SpriteAction complete, SpriteAction with);
00151
00152 typedef std::map<std::string, ImageSet*> ImageSets;
00153 typedef ImageSets::iterator ImageSetIterator;
00154
00155 typedef std::map<SpriteAction, Action*> Actions;
00156
00157 ImageSets mImageSets;
00158 Actions mActions;
00159 };
00160
00161 #endif // SPRITEDEF_H