summaryrefslogtreecommitdiff
path: root/src/event.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-08-15 21:28:10 -0600
committerJared Adams <jaxad0127@gmail.com>2010-08-16 13:19:09 -0600
commitd8d9232a67a03548b827bdb0515fe7a620a488f8 (patch)
treed6e0644f99e0ff89f9b320c0b479ba5a4e398125 /src/event.cpp
parenta6c2b90c2dabac18ad8052d948bc540406b3a613 (diff)
downloadmana-d8d9232a67a03548b827bdb0515fe7a620a488f8.tar.gz
mana-d8d9232a67a03548b827bdb0515fe7a620a488f8.tar.bz2
mana-d8d9232a67a03548b827bdb0515fe7a620a488f8.tar.xz
mana-d8d9232a67a03548b827bdb0515fe7a620a488f8.zip
Move more to the event system
Most of Net::InventoryHandler is now done through events. The ActorSpriteManager was also replaced by events. A few odds and ends were taken care of too. Reviewed-by: Bertram
Diffstat (limited to 'src/event.cpp')
-rw-r--r--src/event.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/event.cpp b/src/event.cpp
index 38213cd2..3ca4c5e2 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -38,6 +38,8 @@ Event::~Event()
}
}
+// Integers
+
void Event::setInt(const std::string &key, int value) throw (BadEvent)
{
if (mData.find(key) != mData.end())
@@ -65,6 +67,8 @@ bool Event::hasInt(const std::string &key) const
|| it->second->getType() != VariableData::DATA_INT);
}
+// Strings
+
void Event::setString(const std::string &key, const std::string &value) throw (BadEvent)
{
if (mData.find(key) != mData.end())
@@ -93,6 +97,8 @@ bool Event::hasString(const std::string &key) const
|| it->second->getType() != VariableData::DATA_STRING);
}
+// Floats
+
void Event::setFloat(const std::string &key, double value) throw (BadEvent)
{
if (mData.find(key) != mData.end())
@@ -120,6 +126,8 @@ bool Event::hasFloat(const std::string &key) const
|| it->second->getType() != VariableData::DATA_FLOAT);
}
+// Booleans
+
void Event::setBool(const std::string &key, bool value) throw (BadEvent)
{
if (mData.find(key) != mData.end())
@@ -147,6 +155,66 @@ bool Event::hasBool(const std::string &key) const
|| it->second->getType() != VariableData::DATA_BOOL);
}
+// Items
+
+void Event::setItem(const std::string &key, Item *value) throw (BadEvent)
+{
+ if (mData.find(key) != mData.end())
+ throw KEY_ALREADY_EXISTS;
+
+ mData[key] = new ItemData(value);
+}
+
+Item *Event::getItem(const std::string &key) const throw (BadEvent)
+{
+ VariableMap::const_iterator it = mData.find(key);
+ if (it == mData.end())
+ throw BAD_KEY;
+
+ if (it->second->getType() != VariableData::DATA_ITEM)
+ throw BAD_VALUE;
+
+ return static_cast<ItemData *>(it->second)->getData();
+}
+
+bool Event::hasItem(const std::string &key) const
+{
+ VariableMap::const_iterator it = mData.find(key);
+ return !(it == mData.end()
+ || it->second->getType() != VariableData::DATA_ITEM);
+}
+
+// Actors
+
+void Event::setActor(const std::string &key, ActorSprite *value) throw (BadEvent)
+{
+ if (mData.find(key) != mData.end())
+ throw KEY_ALREADY_EXISTS;
+
+ mData[key] = new ActorData(value);
+}
+
+ActorSprite *Event::getActor(const std::string &key) const throw (BadEvent)
+{
+ VariableMap::const_iterator it = mData.find(key);
+ if (it == mData.end())
+ throw BAD_KEY;
+
+ if (it->second->getType() != VariableData::DATA_ACTOR)
+ throw BAD_VALUE;
+
+ return static_cast<ActorData *>(it->second)->getData();
+}
+
+bool Event::hasActor(const std::string &key) const
+{
+ VariableMap::const_iterator it = mData.find(key);
+ return !(it == mData.end()
+ || it->second->getType() != VariableData::DATA_ACTOR);
+}
+
+// Triggers
+
void Event::trigger(const std::string &channel, const Event &event)
{
ListenMap::iterator it = mBindings.find(channel);