From d8d9232a67a03548b827bdb0515fe7a620a488f8 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 15 Aug 2010 21:28:10 -0600 Subject: 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 --- src/event.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'src/event.h') diff --git a/src/event.h b/src/event.h index 68560dae..c7382fc1 100644 --- a/src/event.h +++ b/src/event.h @@ -21,9 +21,12 @@ #ifndef EVENT_H #define EVENT_H -#include #include #include +#include + +class ActorSprite; +class Item; namespace Mana { @@ -65,6 +68,8 @@ public: const std::string &getName() const { return mEventName; } +// Integers + /** * Sets the given variable to the given integer, if it isn't already set. */ @@ -87,6 +92,8 @@ public: */ bool hasInt(const std::string &key) const; +// Strings + /** * Sets the given variable to the given string, if it isn't already set. */ @@ -110,6 +117,8 @@ public: */ bool hasString(const std::string &key) const; +// Floats + /** * Sets the given variable to the given floating-point, if it isn't already * set. @@ -133,6 +142,8 @@ public: */ bool hasFloat(const std::string &key) const; +// Booleans + /** * Sets the given variable to the given boolean, if it isn't already set. */ @@ -155,6 +166,57 @@ public: */ bool hasBool(const std::string &key) const; +// Items + + /** + * Sets the given variable to the given Item, if it isn't already set. + */ + void setItem(const std::string &key, Item *value) throw (BadEvent); + + /** + * Returns the given variable if it is set and an Item. + */ + Item *getItem(const std::string &key) const throw (BadEvent); + + /** + * Returns the given variable if it is set and an Item, returning the + * given default otherwise. + */ + inline Item *getItem(const std::string &key, Item *defaultValue) const + { try { return getItem(key); } catch (BadEvent) { return defaultValue; }} + + /** + * Returns true if the given variable exists and is an Item. + */ + bool hasItem(const std::string &key) const; + +// ActorSprites + + /** + * Sets the given variable to the given actor, if it isn't already set. + */ + void setActor(const std::string &key, ActorSprite *value) throw (BadEvent); + + /** + * Returns the given variable if it is set and an actor. + */ + ActorSprite *getActor(const std::string &key) const throw (BadEvent); + + /** + * Returns the given variable if it is set and an actor, returning the + * given default otherwise. + */ + inline ActorSprite *getActor(const std::string &key, + ActorSprite *defaultValue) const + { try { return getActor(key); } catch (BadEvent) { return defaultValue; }} + + /** + * Returns true if the given variable exists and is an actor. + */ + bool hasActor(const std::string &key) const; + +// Triggers + /** * Sends this event to all classes listening to the given channel. */ -- cgit v1.2.3-60-g2f50