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

@@ -1,31 +0,0 @@
local Gui = require("modules/exp_gui")
local PlayerData = require("modules.exp_legacy.expcore.player_data")
-- Used to store the state of the toolbar when a player leaves
local ToolbarState = PlayerData.Settings:combine("ToolbarState")
ToolbarState:set_metadata{
stringify = function()
return "Toolbar is saved on exit"
end,
}
--- Uncompress the data to be more useable
ToolbarState:on_load(function(player_name, value)
-- If there is no value, do nothing
if value == nil then return end
-- Old format, we discard it [ string[], string[], string[], boolean ]
if type(value) ~= "string" then return end
local decompressed = helpers.json_to_table(assert(helpers.decode_string(value), "Failed String Decode"))
local player = assert(game.get_player(player_name))
Gui.toolbar.set_state(player, decompressed --[[@as Gui.ToolbarState]])
return nil -- We don't save the state, use Gui.toolbar.get_state
end)
--- Save the current state of the players toolbar menu
ToolbarState:on_save(function(player_name, _)
local player = assert(game.get_player(player_name))
local value = Gui.toolbar.get_state(player)
return helpers.encode_string(helpers.table_to_json(value))
end)