144 {
return std::any_cast<const T &>(
mValue); }
151 {
return mValue.type() ==
typeid(T) && Event::value<T>() ==
value; }
163 int getInt(
const std::string &key)
const;
169 int getInt(
const std::string &key,
int defaultValue)
const
170 {
try {
return getInt(key); }
catch (
BadEvent) {
return defaultValue; }}
182 const std::string &
getString(
const std::string &key)
const;
189 const std::string &defaultValue)
const
203 double getFloat(
const std::string &key)
const;
209 double getFloat(
const std::string &key,
float defaultValue)
const
222 bool getBool(
const std::string &key)
const;
228 bool getBool(
const std::string &key,
bool defaultValue)
const
229 {
try {
return getBool(key); }
catch (
BadEvent) {
return defaultValue; }}
248 {
try {
return getItem(key); }
catch (
BadEvent) {
return defaultValue; }}
311 using ListenMap = std::map<Channel, std::set<EventListener *>>;
315 std::map<std::string, VariableData *>
mData;
322 event.setString(
"message", message);
virtual void event(Event::Channel channel, const Event &event)=0
ActorSprite * getActor(const std::string &key) const
Returns the given variable if it is set and an actor.
Event(Type type)
Makes an event with the given name.
void setValue(const T &value)
Sets the value of the event.
void setBool(const std::string &key, bool value)
Sets the given variable to the given boolean, if it isn't already set.
static void trigger(Channel channel, Type type)
Sends an empty event with the given name to all classes listening to the given channel.
const T & value() const
Returns the value of the event.
int getInt(const std::string &key, int defaultValue) const
Returns the given variable if it is set and an integer, returning the given default otherwise.
static void unbind(EventListener *listener, Channel channel)
Unbinds the given listener from the given channel.
void setString(const std::string &key, const std::string &value)
Sets the given variable to the given string, if it isn't already set.
double getFloat(const std::string &key) const
Returns the given variable if it is set and a floating-point.
Item * getItem(const std::string &key, Item *defaultValue) const
Returns the given variable if it is set and an Item, returning the given default otherwise.
void trigger(Channel channel) const
Sends this event to all classes listening to the given channel.
bool hasValue(const T &value) const
Returns whether the event has the given the value.
const std::string & getString(const std::string &key) const
Returns the given variable if it is set and a string.
Item * getItem(const std::string &key) const
Returns the given variable if it is set and an Item.
static ListenMap mBindings
void setFloat(const std::string &key, double value)
Sets the given variable to the given floating-point, if it isn't already set.
void setActor(const std::string &key, ActorSprite *value)
Sets the given variable to the given actor, if it isn't already set.
std::string getString(const std::string &key, const std::string &defaultValue) const
Returns the given variable if it is set and a string, returning the given default otherwise.
std::map< std::string, VariableData * > mData
ActorSprite * getActor(const std::string &key, ActorSprite *defaultValue) const
Returns the given variable if it is set and an actor, returning the given default otherwise.
bool getBool(const std::string &key, bool defaultValue) const
Returns the given variable if it is set and a boolean, returning the given default otherwise.
static void remove(EventListener *listener)
Unbinds the given listener from all channels.
void setInt(const std::string &key, int value)
Sets the given variable to the given integer, if it isn't already set.
double getFloat(const std::string &key, float defaultValue) const
Returns the given variable if it is set and a floating-point, returning the given default otherwise.
static void bind(EventListener *listener, Channel channel)
Binds the given listener to the given channel.
Event(Type type, const T &value)
Makes an event with the given name and value.
std::map< Channel, std::set< EventListener * > > ListenMap
Type getType() const
Returns the name of the event.
int getInt(const std::string &key) const
Returns the given variable if it is set and an integer.
void setItem(const std::string &key, Item *value)
Sets the given variable to the given Item, if it isn't already set.
bool getBool(const std::string &key) const
Returns the given variable if it is set and a boolean.
Represents one or more instances of a certain item type.
void serverNotice(const std::string &message)