mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Sync roboport, movement bonus, and game view settings in inventory_sync
The built-in shortcuts are not toggleable in their prototypes and set_shortcut_toggled only affects custom Lua shortcuts, so the state behind them is synced instead: allow_dispatching_robots on the character, inhibit_movement_bonus on the armor grid, and every field of game_view_settings. map_view_settings is write-only and cannot be read. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9bce1e39e
commit
9aeb23e5da
4 files changed
+74
No files matched your search
@@ -2,6 +2,7 @@ local compat = require("modules/clusterio/compat")
|
||||
local clusterio_serialize = require("modules/clusterio/serialize")
|
||||
local character_inventories = require("modules/inventory_sync/define_player_inventories")
|
||||
local character_stat_keys = require("modules/inventory_sync/define_player_stat_keys")
|
||||
local game_view_settings_keys = require("modules/inventory_sync/define_game_view_settings")
|
||||
local serialize = {}
|
||||
|
||||
local v2_logistic_api = compat.version_ge("2.0.0")
|
||||
@@ -52,6 +53,8 @@ end
|
||||
-- character_maximum_following_robot_count_bonus
|
||||
-- character_health_bonus
|
||||
-- character_personal_logistic_requests_enabled
|
||||
-- allow_dispatching_robots
|
||||
-- inhibit_movement_bonus (optional, from the armor equipment grid)
|
||||
-- inventories: table of character inventory name to inventory content
|
||||
function serialize.serialize_character(character)
|
||||
local serialized = { }
|
||||
@@ -64,6 +67,12 @@ function serialize.serialize_character(character)
|
||||
-- Serialize character inventories
|
||||
serialized.inventories = serialize.serialize_inventories(character, character_inventories)
|
||||
|
||||
-- Serialize armor grid state
|
||||
local grid = character.grid
|
||||
if grid then
|
||||
serialized.inhibit_movement_bonus = grid.inhibit_movement_bonus
|
||||
end
|
||||
|
||||
return serialized
|
||||
end
|
||||
|
||||
@@ -75,6 +84,12 @@ function serialize.deserialize_character(character, serialized)
|
||||
|
||||
-- Deserialize character inventories
|
||||
serialize.deserialize_inventories(character, serialized.inventories, character_inventories)
|
||||
|
||||
-- Deserialize armor grid state, the grid exists after the armor inventory is restored
|
||||
local grid = character.grid
|
||||
if grid and serialized.inhibit_movement_bonus ~= nil then
|
||||
grid.inhibit_movement_bonus = serialized.inhibit_movement_bonus
|
||||
end
|
||||
end
|
||||
|
||||
-- Personal logistic slots is a table mapping string indexes to a table with the following fields:
|
||||
@@ -593,6 +608,7 @@ end
|
||||
--- @field cheat_mode boolean
|
||||
--- @field flashlight boolean
|
||||
--- @field shortcuts table<string, boolean>?
|
||||
--- @field game_view_settings table<string, boolean>?
|
||||
--- @field ticks_to_respawn number
|
||||
--- @field character table<string, any>?
|
||||
--- @field inventories table<string, table>?
|
||||
@@ -626,6 +642,28 @@ function serialize.deserialize_shortcuts(player, serialized)
|
||||
end
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @return table<string, boolean>
|
||||
function serialize.serialize_game_view_settings(player)
|
||||
local settings = player.game_view_settings
|
||||
local serialized = {}
|
||||
for _, key in pairs(game_view_settings_keys) do
|
||||
serialized[key] = settings[key]
|
||||
end
|
||||
return serialized
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param serialized table<string, boolean>
|
||||
function serialize.deserialize_game_view_settings(player, serialized)
|
||||
local settings = player.game_view_settings
|
||||
for _, key in pairs(game_view_settings_keys) do
|
||||
if serialized[key] ~= nil then
|
||||
settings[key] = serialized[key]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param failed_deserialization FailedDeserializationPlayerData
|
||||
--- @return SerializedPlayerData
|
||||
@@ -642,6 +680,7 @@ function serialize.serialize_player(player, failed_deserialization)
|
||||
cheat_mode = player.cheat_mode,
|
||||
flashlight = player.is_flashlight_enabled(),
|
||||
shortcuts = serialize.serialize_shortcuts(player),
|
||||
game_view_settings = serialize.serialize_game_view_settings(player),
|
||||
ticks_to_respawn = player.ticks_to_respawn,
|
||||
}
|
||||
|
||||
@@ -819,6 +858,9 @@ function serialize.deserialize_player(player, serialized)
|
||||
if serialized.shortcuts then
|
||||
serialize.deserialize_shortcuts(player, serialized.shortcuts)
|
||||
end
|
||||
if serialized.game_view_settings then
|
||||
serialize.deserialize_game_view_settings(player, serialized.game_view_settings)
|
||||
end
|
||||
|
||||
-- Deserialize character
|
||||
if player.character then
|
||||
|
||||
Reference in new issue
Block a user