File: src/core/EventBus.lua
Global: FT_EventBus
Quick-reference. See developer/eventbus.md for usage patterns and implementation notes.
Registers fn as a listener for event. Persists for the game session.
Removes fn from event. The function reference must match exactly.
Calls all listeners for event with ... as arguments. Each listener is wrapped in pcall.
All names are in FT_EventBus.EVENTS:
| Constant | String | Arguments | Emitted by |
|---|---|---|---|
TABLET_OPENED |
"tablet_opened" |
— | FarmTabletUI:openTablet() |
TABLET_CLOSED |
"tablet_closed" |
— | FarmTabletUI:closeTablet() |
APP_SWITCHED |
"app_switched" |
appId: string |
FarmTabletUI:switchApp() |
APP_REGISTERED |
"app_registered" |
appId: string |
AppRegistry:register() |
SETTINGS_CHANGED |
"settings_changed" |
— | (reserved) |
DATA_REFRESHED |
"data_refreshed" |
— | (reserved) |
-- Subscribe at mission load time
FT_EventBus:on(FT_EventBus.EVENTS.TABLET_OPENED, function()
-- refresh your mod's state here
end)
FT_EventBus:on(FT_EventBus.EVENTS.APP_SWITCHED, function(appId)
if appId == "my_app" then
-- user just switched to my app
end
end)