7#include <aegis2d/script/export.hpp>
36 std::span<const EventField> fields = {});
62 const std::array fields{
63 EventField{.
name =
"entity", .value =
static_cast<double>(
event.entity.id())},
64 EventField{.
name =
"killer", .value =
static_cast<double>(
event.killer.id())},
68 emit(lua,
"Explosion", fields);
71 const std::array fields{
72 EventField{.
name =
"player", .value =
static_cast<double>(
event.player.id())},
74 .value =
static_cast<double>(
event.lives_left)},
75 EventField{.
name =
"score", .value =
static_cast<double>(
event.score)},
77 emit(lua,
"LifeLost", fields);
94 std::array<core::SubscriptionId, 2> subscriptions_{};
Lets systems react to events without knowing who sends them.
Definition event_bus.hpp:31
SubscriptionId subscribe(Handler< Event > handler)
Registers a handler for events of type Event.
Definition event_bus.hpp:41
bool unsubscribe(SubscriptionId id)
Removes a handler.
Definition event_bus.hpp:51
Sends the gameplay events of a bus to the scripts of a state, while it lives.
Definition events.hpp:54
EventBridge & operator=(EventBridge &&)=delete
EventBridge & operator=(const EventBridge &)=delete
EventBridge(const EventBridge &)=delete
EventBridge(ScriptState &lua, core::EventBus &bus)
Subscribes to the gameplay events of bus.
Definition events.hpp:59
~EventBridge()
Unsubscribes from the bus.
Definition events.hpp:86
EventBridge(EventBridge &&)=delete
A Lua state for the game's scripts, sandboxed.
Definition state.hpp:52
Gameplay events: explosions and deaths, published on the core event bus.
Typed publish/subscribe event bus with immediate dispatch.
Player deaths: lives, respawn and game over.
std::uint64_t SubscriptionId
Handle returned by EventBus::subscribe(), used to unsubscribe. Never 0.
Definition event_bus.hpp:19
Entity behaviors in Lua, so that new enemies and patterns need no recompilation.
Definition components.hpp:19
AEGIS2D_SCRIPT_EXPORT std::string_view name() noexcept
Name of the module, used to check that it is linked.
AEGIS2D_SCRIPT_EXPORT bool emit(ScriptState &lua, std::string_view name, std::span< const EventField > fields={})
Sends an event to the scripts of a state.
A sandboxed Lua state: scripts run without files, processes nor debug access, and their errors never ...
An entity whose health reached zero blows up: an enemy shot down, or a player that loses a life.
Definition events.hpp:31
A player who lost a life during the tick.
Definition lives.hpp:17
A field of an event sent to scripts.
Definition events.hpp:17
double value
Its value; a whole number (such as an entity's id) reaches Lua as an integer.
Definition events.hpp:21
std::string_view name
Its name in the event's table.
Definition events.hpp:19