Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::script::EventBridge Class Reference

Sends the gameplay events of a bus to the scripts of a state, while it lives. More...

#include <aegis2d/script/events.hpp>

Public Member Functions

 EventBridge (ScriptState &lua, core::EventBus &bus)
 Subscribes to the gameplay events of bus.
 
 EventBridge (const EventBridge &)=delete
 
EventBridge & operator= (const EventBridge &)=delete
 
 EventBridge (EventBridge &&)=delete
 
EventBridge & operator= (EventBridge &&)=delete
 
 ~EventBridge ()
 Unsubscribes from the bus.
 

Detailed Description

Sends the gameplay events of a bus to the scripts of a state, while it lives.

Each ecs::Explosion reaches the scripts as an "Explosion" event (entity, killer, x, y), each ecs::LifeLost as a "LifeLost" one (player, lives_left, score). Destroy it before the state or the bus. Defined in the header: the bus finds its handlers by typeid, which differs between the engine's libraries and the game with libc++.

script::bind_components(lua, registry);
const script::EventBridge bridge{lua, events};
lua.run(R"(
events.on("Explosion", function(event)
ecs.create({Transform = {x = event.x, y = event.y}, Velocity = {y = -60}})
end)
)");
Sends the gameplay events of a bus to the scripts of a state, while it lives.
Definition events.hpp:54
A Lua state for the game's scripts, sandboxed.
Definition state.hpp:52
bool run(std::string_view code, std::string_view chunk="script")
Runs Lua code.
void bind_components(ScriptState &lua, ecs::Registry &registry)
Gives the scripts of a state the common components of a registry.
Definition components.hpp:278

Constructor & Destructor Documentation

◆ EventBridge() [1/3]

aegis2d::script::EventBridge::EventBridge ( ScriptState &  lua,
core::EventBus &  bus 
)
inline

Subscribes to the gameplay events of bus.

Parameters
luaState whose scripts get them, kept by reference.
busBus the gameplay publishes on, kept by reference.

◆ EventBridge() [2/3]

aegis2d::script::EventBridge::EventBridge ( const EventBridge &  )
delete

◆ EventBridge() [3/3]

aegis2d::script::EventBridge::EventBridge ( EventBridge &&  )
delete

◆ ~EventBridge()

aegis2d::script::EventBridge::~EventBridge ( )
inline

Unsubscribes from the bus.

Member Function Documentation

◆ operator=() [1/2]

EventBridge & aegis2d::script::EventBridge::operator= ( const EventBridge &  )
delete

◆ operator=() [2/2]

EventBridge & aegis2d::script::EventBridge::operator= ( EventBridge &&  )
delete

The documentation for this class was generated from the following file: