Sync the toolbar of players through the controller

The toolbar order, favourites, and open panels were saved into
exp_legacy's PlayerData, which was never synced, and the file doing so
was no longer loaded. When a player leaves, the lua side now sends
Gui.toolbar.get_state as json compressed with helpers.encode_string,
and the controller stores the string on the player record.

When the player joins again the instance plugin sends the stored string
over rcon to exp_scenario.player_settings.receive_toolbar, which
decodes it and calls Gui.toolbar.set_state. exp_gui builds the toolbar
in on_player_joined_game, so it exists by the time the rcon arrives.
A string which does not decode, or a state naming buttons which no
longer exist, is logged and ignored rather than raising in the game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 22:10:31 +00:00
1 parent ebe7504c00
commit 54941b85aa
15 files changed
+228 -45

No files matched your search

+12 -1
View File
@@ -9,6 +9,8 @@ export type IpcJoinMessageSet = { player_name: string, message?: string };
export type IpcJoinMessageGet = { player_name: string };
/** Sent by the lua side when a player joins or changes language, see module/control/player_settings.lua */
export type IpcLocale = { player_name: string, locale: string };
/** Sent by the lua side when a player leaves */
export type IpcToolbar = { player_name: string, toolbar: string };
/** Json as a lua expression for a table, inside a long bracket the json does not contain */
export function luaJson(value: unknown) {
@@ -69,6 +71,11 @@ export default async function (context: InstancePluginContext) {
if (record.joinMessage && featureEnabled.get("greetings") !== false) {
await luaWithPlayer(name, { message: record.joinMessage }, "game.print(d.message, { color = p.color })");
}
if (record.toolbar) {
await luaWithPlayer(
name, { toolbar: record.toolbar }, "exp_scenario.player_settings.receive_toolbar(d.name, d.toolbar)",
);
}
}
instance.handle(messages.FeatureUpdatedEvent, async event => {
@@ -95,10 +102,14 @@ export default async function (context: InstancePluginContext) {
instance.sendTo("controller", new messages.PlayerLocaleEvent(event.player_name, event.locale));
});
instance.server.handle("exp_scenario:toolbar", async (event: IpcToolbar) => {
instance.sendTo("controller", new messages.PlayerToolbarEvent(event.player_name, event.toolbar));
});
instance.hooks.playerEvent.attach(plugin.name, async event => {
if (event.type === "join") {
await onPlayerJoin(event.name).catch(err => logger.error(
`Error showing the join message of ${event.name}:\n${err.stack ?? err.message}`,
`Error sending the settings of ${event.name}:\n${err.stack ?? err.message}`,
));
}
});