mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-22 07:33:12 +09:00
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:
1 parent
ebe7504c00
commit
54941b85aa
15 files changed
+228
-45
No files matched your search
@@ -25,14 +25,18 @@ export default async function (context: ControllerPluginContext) {
|
||||
).bootstrap()
|
||||
);
|
||||
|
||||
type PlayerSettings = Pick<messages.PlayerRecord, "joinMessage" | "locale">;
|
||||
type PlayerSettings = Pick<messages.PlayerRecord, "joinMessage" | "locale" | "toolbar">;
|
||||
|
||||
/** Change some settings of a player, empty values are removed and so is a record left empty */
|
||||
function updatePlayer(name: string, changes: PlayerSettings) {
|
||||
const old = playerStore.get(name);
|
||||
const settings: PlayerSettings = { joinMessage: old?.joinMessage, locale: old?.locale, ...changes };
|
||||
const record = new messages.PlayerRecord(name, settings.joinMessage || undefined, settings.locale || undefined);
|
||||
if (record.joinMessage || record.locale) {
|
||||
const settings: PlayerSettings = {
|
||||
joinMessage: old?.joinMessage, locale: old?.locale, toolbar: old?.toolbar, ...changes,
|
||||
};
|
||||
const record = new messages.PlayerRecord(
|
||||
name, settings.joinMessage || undefined, settings.locale || undefined, settings.toolbar || undefined,
|
||||
);
|
||||
if (record.joinMessage || record.locale || record.toolbar) {
|
||||
playerStore.set(record);
|
||||
} else if (old) {
|
||||
playerStore.delete(old);
|
||||
@@ -234,6 +238,10 @@ export default async function (context: ControllerPluginContext) {
|
||||
updatePlayer(event.playerName, { locale: event.locale });
|
||||
});
|
||||
|
||||
controller.handle(messages.PlayerToolbarEvent, async (event: messages.PlayerToolbarEvent) => {
|
||||
updatePlayer(event.playerName, { toolbar: event.toolbar });
|
||||
});
|
||||
|
||||
controller.hooks.save.attach(plugin.name, async () => {
|
||||
await playerStore.save();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user