summaryrefslogtreecommitdiff
path: root/ItemConfiguration.cpp
diff options
context:
space:
mode:
authorJapa Illo2012-03-26 13:16:58 +0200
committerJapa Illo2012-03-26 13:16:58 +0200
commitdf37cc7e59b3cf5fadfa680a68793b91810a30ff (patch)
treec1f9e2b3d4e2d1cf6d2fe7b9a15e801d441cbae9 /ItemConfiguration.cpp
parent3f7c63d777bf3722c07fdea721652da22fd2bbc2 (diff)
downloadstonesense-df37cc7e59b3cf5fadfa680a68793b91810a30ff.tar.gz
stonesense-df37cc7e59b3cf5fadfa680a68793b91810a30ff.tar.bz2
stonesense-df37cc7e59b3cf5fadfa680a68793b91810a30ff.tar.xz
Added configurable sprite support for items on the floor.
Signed-off-by: Japa Illo <japa.mala.illo@gmail.com>
Diffstat (limited to 'ItemConfiguration.cpp')
-rw-r--r--ItemConfiguration.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/ItemConfiguration.cpp b/ItemConfiguration.cpp
new file mode 100644
index 0000000..49553c0
--- /dev/null
+++ b/ItemConfiguration.cpp
@@ -0,0 +1,119 @@
+#include "common.h"
+#include "ItemConfiguration.h"
+#include "tinyxml.h"
+#include "GUI.h"
+#include "ContentLoader.h"
+
+ItemConfiguration::ItemConfiguration()
+{
+ configured=0;
+}
+
+
+
+ItemConfiguration::~ItemConfiguration()
+{
+ subItems.clear();
+}
+
+
+bool addSingleItemConfig( TiXmlElement* elemRoot)
+{
+ const char* strGameID = elemRoot->Attribute("game_type");
+ const char* strGameSub = elemRoot->Attribute("game_subtype");
+
+ if (strGameID == NULL || strGameID[0] == 0)
+ {
+ contentError("<item> node must game_type attribute",elemRoot);
+ return false;
+ }
+ item_type::item_type main_type = (item_type::item_type) INVALID_INDEX;
+ int subtype = INVALID_INDEX;
+ string game_type_s;
+ FOR_ENUM_ITEMS(item_type,i)
+ {
+ game_type_s = strGameID;
+ if (game_type_s == ENUM_KEY_STR(item_type,i))
+ {
+ main_type = i;
+ break;
+ }
+ }
+ if(main_type == (item_type::item_type) INVALID_INDEX)
+ {
+ contentError("<item> unknown game_type value",elemRoot);
+ return false;
+ }
+
+ if(strGameSub && strGameSub[0] != 0)
+ {
+ // get subtype string, if available
+ string sub;
+ if(strGameSub)
+ sub = strGameSub;
+
+ //process subtypes
+ ItemTypeInfo itemdef;
+ if(!itemdef.find(sub))
+ {
+ contentError("<item> unknown game_subtype value",elemRoot);
+ return false;
+ }
+ else subtype = itemdef.subtype;
+ }
+
+ int basefile = -1;
+
+ const char* filename = elemRoot->Attribute("file");
+ if (filename != NULL && filename[0] != 0)
+ {
+ basefile = loadConfigImgFile((char*)filename, elemRoot);
+ if(basefile == -1) return false;
+ }
+
+
+ c_sprite sprite;
+
+ sprite.set_by_xml(elemRoot, basefile);
+
+ if(contentLoader->itemConfigs[main_type] == NULL)
+ contentLoader->itemConfigs[main_type] = new ItemConfiguration;
+ //check for an existing item there.
+ if(subtype == INVALID_INDEX)
+ {
+ if(!contentLoader->itemConfigs[main_type]->configured)
+ {
+ contentLoader->itemConfigs[main_type]->configured = true;
+ contentLoader->itemConfigs[main_type]->default_sprite = sprite;
+ }
+ }
+ else
+ {
+ if(contentLoader->itemConfigs[main_type]->subItems.size() <= subtype)
+ contentLoader->itemConfigs[main_type]->subItems.resize(subtype+1, NULL);
+ if(!contentLoader->itemConfigs[main_type]->subItems[subtype]->configured)
+ {
+ contentLoader->itemConfigs[main_type]->subItems[subtype]->configured = true;
+ contentLoader->itemConfigs[main_type]->subItems[subtype]->sprite = sprite;
+ }
+ }
+ return true;
+}
+
+
+void flushItemConfig(vector<ItemConfiguration *> &config)
+{
+ uint32_t currentsize = (uint32_t)config.size();
+ for (uint32_t i=0;i<currentsize;i++)
+ {
+ if (config[i] != NULL)
+ {
+ delete(config[i]);
+ }
+ }
+
+ config.clear();
+ if (currentsize < ENUM_LAST_ITEM(item_type))
+ currentsize = ENUM_LAST_ITEM(item_type);
+ config.resize(currentsize,NULL);
+} \ No newline at end of file