summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-05-02 14:43:40 -0600
committerJared Adams <jaxad0127@gmail.com>2010-05-06 22:21:57 -0600
commit9baedc27191c82bbf1fedee2a7e738bc5b267c0e (patch)
treef0986c6839d1e79b402d5d4ec36e4994741955ea /src/resources
parent844e9a7a72faca6a212e788a3adc45e17f41dca6 (diff)
downloadMana-9baedc27191c82bbf1fedee2a7e738bc5b267c0e.tar.gz
Mana-9baedc27191c82bbf1fedee2a7e738bc5b267c0e.tar.bz2
Mana-9baedc27191c82bbf1fedee2a7e738bc5b267c0e.tar.xz
Mana-9baedc27191c82bbf1fedee2a7e738bc5b267c0e.zip
Add support for floor item sprites
This commit adds a sprite hierarchy (Sprite->ImageSprite,AnimatedSprite,CompundSprite; CompoundSprite,Actor->ActorSprite;ActorSprite->Being,FloorItem) to collect common functionailty into new base classes which will make other Mantis tickets easier to do. Also allows monsters to use particle effects. Reviewed-by: Bertram
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/itemdb.cpp32
-rw-r--r--src/resources/iteminfo.h10
-rw-r--r--src/resources/monsterdb.cpp23
-rw-r--r--src/resources/monsterinfo.cpp5
-rw-r--r--src/resources/monsterinfo.h22
-rw-r--r--src/resources/npcdb.cpp18
-rw-r--r--src/resources/npcdb.h20
-rw-r--r--src/resources/resourcemanager.cpp2
-rw-r--r--src/resources/spritedef.h16
9 files changed, 95 insertions, 53 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 4638f00e..57df6143 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -46,6 +46,7 @@ namespace
// Forward declarations
static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node);
static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node);
+static void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node);
static char const *const fields[][2] =
{
@@ -114,7 +115,7 @@ void ItemDB::load()
mUnknown = new ItemInfo;
mUnknown->setName(_("Unknown item"));
- mUnknown->setImageName("");
+ mUnknown->setDisplay(SpriteDisplay());
mUnknown->setSprite("error.xml", GENDER_MALE);
mUnknown->setSprite("error.xml", GENDER_FEMALE);
@@ -154,9 +155,11 @@ void ItemDB::load()
int attackRange = XML::getProperty(node, "attack-range", 0);
std::string missileParticle = XML::getProperty(node, "missile-particle", "");
+ SpriteDisplay display;
+ display.image = image;
+
ItemInfo *itemInfo = new ItemInfo;
itemInfo->setId(id);
- itemInfo->setImageName(image);
itemInfo->setName(name.empty() ? _("unnamed") : name);
itemInfo->setDescription(description);
itemInfo->setType(itemTypeFromString(typeStr));
@@ -202,8 +205,14 @@ void ItemDB::load()
{
loadSoundRef(itemInfo, itemChild);
}
+ else if (xmlStrEqual(itemChild->name, BAD_CAST "floor"))
+ {
+ loadFloorSprite(&display, itemChild);
+ }
}
+ itemInfo->setDisplay(display);
+
mItemInfos[id] = itemInfo;
if (!name.empty())
{
@@ -334,3 +343,22 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node)
event.c_str());
}
}
+
+void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode)
+{
+ for_each_xml_child_node(spriteNode, floorNode)
+ {
+ if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
+ {
+ SpriteReference *currentSprite = new SpriteReference;
+ currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content;
+ currentSprite->variant = XML::getProperty(spriteNode, "variant", 0);
+ display->sprites.push_back(currentSprite);
+ }
+ else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
+ {
+ std::string particlefx = (const char*)spriteNode->xmlChildrenNode->content;
+ display->particles.push_back(particlefx);
+ }
+ }
+}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index a7c0ddca..f42ac8e6 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -143,11 +143,11 @@ class ItemInfo
std::string getParticleEffect() const { return mParticle; }
- void setImageName(const std::string &imageName)
- { mImageName = imageName; }
+ void setDisplay(SpriteDisplay display)
+ { mDisplay = display; }
- const std::string &getImageName() const
- { return mImageName; }
+ const SpriteDisplay &getDisplay() const
+ { return mDisplay; }
void setDescription(const std::string &description)
{ mDescription = description; }
@@ -201,7 +201,7 @@ class ItemInfo
const std::string &getSound(EquipmentSoundEvent event) const;
protected:
- std::string mImageName; /**< The filename of the icon image. */
+ SpriteDisplay mDisplay; /**< Display info (like icon) */
std::string mName;
std::string mDescription; /**< Short description. */
std::string mEffect; /**< Description of effects. */
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index e9afa7ef..658321f1 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -45,7 +45,16 @@ void MonsterDB::load()
if (mLoaded)
return;
- mUnknown.addSprite("error.xml");
+ {
+ SpriteReference *unknownSprite = new SpriteReference;
+ unknownSprite->sprite = "error.xml";
+ unknownSprite->variant = 0;
+
+ SpriteDisplay display;
+ display.sprites.push_front(unknownSprite);
+
+ mUnknown.setDisplay(display);
+ }
logger->log("Initializing monster database...");
@@ -94,13 +103,17 @@ void MonsterDB::load()
currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
}
+ SpriteDisplay display;
+
//iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, monsterNode)
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
- currentInfo->addSprite(
- (const char*) spriteNode->xmlChildrenNode->content);
+ SpriteReference *currentSprite = new SpriteReference;
+ currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content;
+ currentSprite->variant = XML::getProperty(spriteNode, "variant", 0);
+ display.sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "sound"))
{
@@ -145,10 +158,12 @@ void MonsterDB::load()
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- currentInfo->addParticleEffect(
+ display.particles.push_back(
(const char*) spriteNode->xmlChildrenNode->content);
}
}
+ currentInfo->setDisplay(display);
+
mMonsterInfos[XML::getProperty(monsterNode, "id", 0) + offset] = currentInfo;
}
diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp
index 9104c721..41ce5b6b 100644
--- a/src/resources/monsterinfo.cpp
+++ b/src/resources/monsterinfo.cpp
@@ -91,8 +91,3 @@ void MonsterInfo::addMonsterAttack(int id,
a->action = action;
mMonsterAttacks[id] = a;
}
-
-void MonsterInfo::addParticleEffect(const std::string &filename)
-{
- mParticleEffects.push_back(filename);
-}
diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h
index f074254a..7741f762 100644
--- a/src/resources/monsterinfo.h
+++ b/src/resources/monsterinfo.h
@@ -24,6 +24,8 @@
#include "being.h"
+#include "resources/spritedef.h"
+
#include <list>
#include <map>
#include <string>
@@ -59,23 +61,21 @@ class MonsterInfo
void setName(const std::string &name) { mName = name; }
- void addSprite(const std::string &filename)
- { mSprites.push_back(filename); }
+ void setDisplay(SpriteDisplay display)
+ { mDisplay = display; }
+
+ const SpriteDisplay &getDisplay() const
+ { return mDisplay; }
void setTargetCursorSize(Being::TargetCursorSize targetCursorSize)
{ mTargetCursorSize = targetCursorSize; }
void addSound(MonsterSoundEvent event, const std::string &filename);
- void addParticleEffect(const std::string &filename);
-
const std::string &getName() const
{ return mName; }
- const std::list<std::string>& getSprites() const
- { return mSprites; }
-
- Being::TargetCursorSize getTargetCursorSize() const
+ ActorSprite::TargetCursorSize getTargetCursorSize() const
{ return mTargetCursorSize; }
const std::string &getSound(MonsterSoundEvent event) const;
@@ -91,16 +91,12 @@ class MonsterInfo
SpriteAction getAttackAction(int attackType) const;
- const std::list<std::string>& getParticleEffects() const
- { return mParticleEffects; }
-
private:
+ SpriteDisplay mDisplay;
std::string mName;
- std::list<std::string> mSprites;
Being::TargetCursorSize mTargetCursorSize;
std::map<MonsterSoundEvent, std::vector<std::string>* > mSounds;
std::map<int, MonsterAttack*> mMonsterAttacks;
- std::list<std::string> mParticleEffects;
};
#endif // MONSTERINFO_H
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index 4bc5a6e4..e2628257 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -28,7 +28,7 @@
namespace
{
NPCInfos mNPCInfos;
- NPCInfo mUnknown;
+ SpriteDisplay mUnknown;
bool mLoaded = false;
}
@@ -37,10 +37,12 @@ void NPCDB::load()
if (mLoaded)
return;
- NPCsprite *unknownSprite = new NPCsprite;
- unknownSprite->sprite = "error.xml";
- unknownSprite->variant = 0;
- mUnknown.sprites.push_back(unknownSprite);
+ {
+ SpriteReference *unknownSprite = new SpriteReference;
+ unknownSprite->sprite = "error.xml";
+ unknownSprite->variant = 0;
+ mUnknown.sprites.push_back(unknownSprite);
+ }
logger->log("Initializing NPC database...");
@@ -65,13 +67,13 @@ void NPCDB::load()
continue;
}
- NPCInfo *currentInfo = new NPCInfo;
+ SpriteDisplay *currentInfo = new SpriteDisplay;
for_each_xml_child_node(spriteNode, npcNode)
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
- NPCsprite *currentSprite = new NPCsprite;
+ SpriteReference *currentSprite = new SpriteReference;
currentSprite->sprite = (const char*)spriteNode->xmlChildrenNode->content;
currentSprite->variant = XML::getProperty(spriteNode, "variant", 0);
currentInfo->sprites.push_back(currentSprite);
@@ -113,7 +115,7 @@ void NPCDB::unload()
mLoaded = false;
}
-const NPCInfo& NPCDB::get(int id)
+const SpriteDisplay& NPCDB::get(int id)
{
NPCInfosIterator i = mNPCInfos.find(id);
diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h
index 9da873e4..84ae4e24 100644
--- a/src/resources/npcdb.h
+++ b/src/resources/npcdb.h
@@ -22,23 +22,11 @@
#ifndef NPC_DB_H
#define NPC_DB_H
-#include <list>
-#include <map>
-#include <string>
-
-struct NPCsprite
-{
- std::string sprite;
- int variant;
-};
+#include "resources/spritedef.h"
-struct NPCInfo
-{
- std::list<NPCsprite*> sprites;
- std::list<std::string> particles;
-};
+#include <map>
-typedef std::map<int, NPCInfo*> NPCInfos;
+typedef std::map<int, SpriteDisplay*> NPCInfos;
/**
* NPC information database.
@@ -49,7 +37,7 @@ namespace NPCDB
void unload();
- const NPCInfo& get(int id);
+ const SpriteDisplay& get(int id);
typedef NPCInfos::iterator NPCInfosIterator;
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 24f346f7..3d23edcd 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -164,6 +164,8 @@ void ResourceManager::searchAndAddArchives(const std::string &path,
const char *dirSep = PHYSFS_getDirSeparator();
char **list = PHYSFS_enumerateFiles(path.c_str());
+ printf("Path: %s -> %s\n", path.c_str(), PHYSFS_getRealDir(path.c_str()));
+
for (char **i = list; *i; i++)
{
size_t len = strlen(*i);
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 5bb6078e..d5db542c 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -26,12 +26,28 @@
#include <libxml/tree.h>
+#include <list>
#include <map>
#include <string>
class Action;
class ImageSet;
+struct SpriteReference
+{
+ std::string sprite;
+ int variant;
+};
+
+struct SpriteDisplay
+{
+ std::string image;
+ std::list<SpriteReference*> sprites;
+ std::list<std::string> particles;
+};
+
+typedef std::list<SpriteReference*>::const_iterator SpriteRefs;
+
enum SpriteAction
{
ACTION_DEFAULT = 0,