mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-27 07:57:13 +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
@@ -136,6 +136,8 @@ export class PlayerRecord {
|
||||
public joinMessage?: string,
|
||||
/** The language of their game, such as "en" or "pt-BR" */
|
||||
public locale?: string,
|
||||
/** Toolbar state from Gui.toolbar.get_state, json compressed with helpers.encode_string */
|
||||
public toolbar?: string,
|
||||
public updatedAtMs: number = 0,
|
||||
public isDeleted: boolean = false,
|
||||
) {}
|
||||
@@ -144,6 +146,7 @@ export class PlayerRecord {
|
||||
id: Type.String(),
|
||||
join_message: Type.Optional(Type.String()),
|
||||
locale: Type.Optional(Type.String()),
|
||||
toolbar: Type.Optional(Type.String()),
|
||||
updated_at_ms: Type.Optional(Type.Number()),
|
||||
is_deleted: Type.Optional(Type.Boolean()),
|
||||
});
|
||||
@@ -156,6 +159,9 @@ export class PlayerRecord {
|
||||
if (this.locale) {
|
||||
json.locale = this.locale;
|
||||
}
|
||||
if (this.toolbar) {
|
||||
json.toolbar = this.toolbar;
|
||||
}
|
||||
if (this.updatedAtMs) {
|
||||
json.updated_at_ms = this.updatedAtMs;
|
||||
}
|
||||
@@ -170,6 +176,7 @@ export class PlayerRecord {
|
||||
json.id,
|
||||
json.join_message,
|
||||
json.locale,
|
||||
json.toolbar,
|
||||
json.updated_at_ms ?? 0,
|
||||
json.is_deleted ?? false,
|
||||
);
|
||||
@@ -276,3 +283,30 @@ export class PlayerLocaleEvent {
|
||||
return new this(json.player_name, json.locale);
|
||||
}
|
||||
}
|
||||
|
||||
/** The toolbar of a player, sent when they leave. */
|
||||
export class PlayerToolbarEvent {
|
||||
declare ["constructor"]: typeof PlayerToolbarEvent;
|
||||
static plugin = "exp_scenario" as const;
|
||||
static type = "event" as const;
|
||||
static src = "instance" as const;
|
||||
static dst = "controller" as const;
|
||||
|
||||
constructor(
|
||||
public playerName: string,
|
||||
public toolbar: string,
|
||||
) {}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
player_name: Type.String(),
|
||||
toolbar: Type.String(),
|
||||
});
|
||||
|
||||
toJSON() {
|
||||
return { player_name: this.playerName, toolbar: this.toolbar };
|
||||
}
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.player_name, json.toolbar);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user