From 75ac8bb491e45c2f472d3651297f7fa66c22e287 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Sat, 5 Sep 2026 22:13:12 +0000 Subject: [PATCH] Sync personal roboport and movement bonus toggles in inventory_sync The toggle state of the personal roboport and equipment movement bonus shortcuts lives on the player and was not part of the serialized player data, so it reset when switching instances. Closes #898 Co-Authored-By: Claude Fable 5.1 --- plugins/inventory_sync/messages.ts | 1 + plugins/inventory_sync/module/serialize.lua | 35 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/plugins/inventory_sync/messages.ts b/plugins/inventory_sync/messages.ts index 53178b56..27fabf55 100644 --- a/plugins/inventory_sync/messages.ts +++ b/plugins/inventory_sync/messages.ts @@ -12,6 +12,7 @@ export type IpcPlayerData = { force: string, cheat_mode: boolean, flashlight: boolean, + shortcuts?: Record, ticks_to_respawn?: number, character?: any, inventories?: any, diff --git a/plugins/inventory_sync/module/serialize.lua b/plugins/inventory_sync/module/serialize.lua index 9c0aa509..85c09c27 100644 --- a/plugins/inventory_sync/module/serialize.lua +++ b/plugins/inventory_sync/module/serialize.lua @@ -592,6 +592,7 @@ end --- @field force string --- @field cheat_mode boolean --- @field flashlight boolean +--- @field shortcuts table? --- @field ticks_to_respawn number --- @field character table? --- @field inventories table? @@ -601,6 +602,36 @@ end --- @field crafting_queue table? --- @field recipe_notifications string? +--- Toggle shortcuts whose state is stored on the player and not covered by any other synced data +local synced_shortcuts = { + "toggle-personal-roboport", + "toggle-equipment-movement-bonus", +} + +--- @param player LuaPlayer +--- @return table +function serialize.serialize_shortcuts(player) + local shortcut_prototypes = compat.prototypes.shortcut + local shortcuts = {} + for _, name in ipairs(synced_shortcuts) do + if shortcut_prototypes[name] then + shortcuts[name] = player.is_shortcut_toggled(name) + end + end + return shortcuts +end + +--- @param player LuaPlayer +--- @param serialized table +function serialize.deserialize_shortcuts(player, serialized) + local shortcut_prototypes = compat.prototypes.shortcut + for name, toggled in pairs(serialized) do + if shortcut_prototypes[name] then + player.set_shortcut_toggled(name, toggled) + end + end +end + --- @param player LuaPlayer --- @param failed_deserialization FailedDeserializationPlayerData --- @return SerializedPlayerData @@ -616,6 +647,7 @@ function serialize.serialize_player(player, failed_deserialization) force = player.force.name, cheat_mode = player.cheat_mode, flashlight = player.is_flashlight_enabled(), + shortcuts = serialize.serialize_shortcuts(player), ticks_to_respawn = player.ticks_to_respawn, } @@ -790,6 +822,9 @@ function serialize.deserialize_player(player, serialized) else player.disable_flashlight() end + if serialized.shortcuts then + serialize.deserialize_shortcuts(player, serialized.shortcuts) + end -- Deserialize character if player.character then