asobi_game_modes (asobi v0.75.1)

View Source

Game-mode configuration, and the registry that maps a mode kind to the module that provides it.

A mode declaring module => {lua, "game/match.lua"} needs a scripting runtime to run it. That runtime lives outside this library (asobi_lua), so the provider module is registered here at boot rather than named in core - core depends on no bridge module.

Summary

Functions

Every game-wide chat channel name declared by any configured game mode.

Register Module as the provider for a game-mode kind.

Resolve a mode to the module that runs it, plus the extra game config it needs.

Drop a registration. Mainly for tests; releases register once and keep it.

Build a world server config map from a mode's game_modes config.

Types

game_mode_kind()

-type game_mode_kind() :: lua_world | lua_match | lua_match_shared.

Functions

global_chat_channels()

-spec global_chat_channels() -> [binary()].

Every game-wide chat channel name declared by any configured game mode.

#299: global:<Name> is the one channel scheme that outlives a single world, so the set of legal names cannot come from the joining client. It is the union of the chat => #{global => [...]} declarations across game_modes, which is what asobi_chat_acl authorises against.

mode_config(Mode)

-spec mode_config(binary()) -> map().

register_game_mode(Kind, Module)

-spec register_game_mode(game_mode_kind(), module()) -> ok.

Register Module as the provider for a game-mode kind.

Call this once, at application start - a persistent_term write is not a hot-path operation. asobi_lua registers its bridge modules this way; a release built without a scripting runtime simply leaves the table empty, and every {lua, _} mode then fails with {error, lua_runtime_unavailable} rather than calling a module that is not in the release.

resolve_game_module(Mode)

-spec resolve_game_module(binary()) ->
                             {ok, module(), map()} | {error, not_found | lua_runtime_unavailable}.

Resolve a mode to the module that runs it, plus the extra game config it needs.

{error, not_found} means the mode declares no usable module. {error, lua_runtime_unavailable} means it declares a Lua script but no runtime registered a provider for that kind - a release built without asobi_lua. That case used to be an unenforced convention that failed later and obscurely; it is now a named error at the point of resolution.

unregister_game_mode(Kind)

-spec unregister_game_mode(game_mode_kind()) -> ok.

Drop a registration. Mainly for tests; releases register once and keep it.

world_config(Mode)

-spec world_config(binary()) -> {ok, map()} | {error, not_found | lua_runtime_unavailable}.

Build a world server config map from a mode's game_modes config.