mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Fix edge cases with physical location and controller
This commit is contained in:
3 files changed
+43
-6
No files matched your search
@@ -16,6 +16,8 @@ local get_script_data = require("modules/inventory_sync/get_script_data")
|
|||||||
local progress_dialog = require("modules/inventory_sync/gui/progress_dialog")
|
local progress_dialog = require("modules/inventory_sync/gui/progress_dialog")
|
||||||
local dialog_failed_download = require("modules/inventory_sync/gui/dialog_failed_download")
|
local dialog_failed_download = require("modules/inventory_sync/gui/dialog_failed_download")
|
||||||
|
|
||||||
|
local v2_remote_controller = compat.version_ge("2.0.0")
|
||||||
|
|
||||||
-- Returns true if the player is currently in a cutscene
|
-- Returns true if the player is currently in a cutscene
|
||||||
local function is_in_cutscene(player)
|
local function is_in_cutscene(player)
|
||||||
return player.controller_type == defines.controllers.cutscene
|
return player.controller_type == defines.controllers.cutscene
|
||||||
@@ -114,6 +116,11 @@ function inventory_sync.deserialize_player(player, finished_record)
|
|||||||
-- Restore player position and driving state
|
-- Restore player position and driving state
|
||||||
restore_position(player, finished_record)
|
restore_position(player, finished_record)
|
||||||
|
|
||||||
|
-- Return to remote if needed (restore position may exit remote view)
|
||||||
|
if serialized_player.remote then
|
||||||
|
player.set_controller{ type = defines.controllers.remote }
|
||||||
|
end
|
||||||
|
|
||||||
-- Transfer items from stashed inventory
|
-- Transfer items from stashed inventory
|
||||||
if stashed_corpse then
|
if stashed_corpse then
|
||||||
local stash = stashed_corpse.get_inventory(defines.inventory.character_corpse)
|
local stash = stashed_corpse.get_inventory(defines.inventory.character_corpse)
|
||||||
@@ -440,8 +447,13 @@ function inventory_sync.initiate_inventory_download(player, player_record, gener
|
|||||||
-- player data is downloading
|
-- player data is downloading
|
||||||
if player_record.sync then
|
if player_record.sync then
|
||||||
-- Store original position to teleport back to
|
-- Store original position to teleport back to
|
||||||
record.surface = player.surface
|
if v2_remote_controller then
|
||||||
record.position = player.position
|
record.surface = player.physical_surface
|
||||||
|
record.position = player.physical_position
|
||||||
|
else
|
||||||
|
record.surface = player.surface
|
||||||
|
record.position = player.position
|
||||||
|
end
|
||||||
if player.driving then
|
if player.driving then
|
||||||
record.vehicle = player.vehicle
|
record.vehicle = player.vehicle
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
local compat = require("modules/clusterio/compat")
|
||||||
|
|
||||||
local can_enter_vehicle = {
|
local can_enter_vehicle = {
|
||||||
[defines.controllers.character] = true,
|
[defines.controllers.character] = true,
|
||||||
[defines.controllers.god] = true,
|
[defines.controllers.god] = true,
|
||||||
[defines.controllers.editor] = true,
|
[defines.controllers.editor] = true,
|
||||||
|
[defines.controllers.remote] = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local v2_surface_platform = compat.version_ge("2.0.0")
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param record table
|
--- @param record table
|
||||||
return function(player, record)
|
return function(player, record)
|
||||||
@@ -20,6 +25,8 @@ return function(player, record)
|
|||||||
player.teleport(safe_position, player.surface)
|
player.teleport(safe_position, player.surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif v2_surface_platform and record.surface and record.surface.platform and can_enter_vehicle[player.controller_type] then
|
||||||
|
player.enter_space_platform(record.surface.platform)
|
||||||
elseif record.surface and record.position then
|
elseif record.surface and record.position then
|
||||||
player.teleport(record.position, record.surface)
|
player.teleport(record.position, record.surface)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ local serialize = {}
|
|||||||
|
|
||||||
local v2_logistic_api = compat.version_ge("2.0.0")
|
local v2_logistic_api = compat.version_ge("2.0.0")
|
||||||
local v2_storage_api = compat.version_ge("2.0.0")
|
local v2_storage_api = compat.version_ge("2.0.0")
|
||||||
|
local v2_remote_controller = compat.version_ge("2.0.0")
|
||||||
local recipe_notifications_api = compat.version_ge("2.0.67")
|
local recipe_notifications_api = compat.version_ge("2.0.67")
|
||||||
|
|
||||||
function serialize.serialize_inventories(source, inventories)
|
function serialize.serialize_inventories(source, inventories)
|
||||||
@@ -428,6 +429,7 @@ end
|
|||||||
--- @field generation number
|
--- @field generation number
|
||||||
--- @field name string
|
--- @field name string
|
||||||
--- @field controller string
|
--- @field controller string
|
||||||
|
--- @field remote boolean
|
||||||
--- @field color Color
|
--- @field color Color
|
||||||
--- @field chat_color Color
|
--- @field chat_color Color
|
||||||
--- @field tag string
|
--- @field tag string
|
||||||
@@ -450,6 +452,7 @@ function serialize.serialize_player(player, failed_deserialization)
|
|||||||
local serialized = {
|
local serialized = {
|
||||||
generation = 0, -- Gets replaced later
|
generation = 0, -- Gets replaced later
|
||||||
controller = controller_to_name[player.controller_type],
|
controller = controller_to_name[player.controller_type],
|
||||||
|
remote = false,
|
||||||
name = player.name,
|
name = player.name,
|
||||||
color = player.color,
|
color = player.color,
|
||||||
chat_color = player.chat_color,
|
chat_color = player.chat_color,
|
||||||
@@ -460,6 +463,11 @@ function serialize.serialize_player(player, failed_deserialization)
|
|||||||
ticks_to_respawn = player.ticks_to_respawn,
|
ticks_to_respawn = player.ticks_to_respawn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v2_remote_controller then
|
||||||
|
serialized.remote = player.controller_type == defines.controllers.remote
|
||||||
|
serialized.controller = controller_to_name[player.physical_controller_type]
|
||||||
|
end
|
||||||
|
|
||||||
-- For the waiting to respawn state the inventory logistic requests and filters are hidden on the player
|
-- For the waiting to respawn state the inventory logistic requests and filters are hidden on the player
|
||||||
if player.controller_type == defines.controllers.ghost and player.ticks_to_respawn then
|
if player.controller_type == defines.controllers.ghost and player.ticks_to_respawn then
|
||||||
player.ticks_to_respawn = nil -- Respawn now
|
player.ticks_to_respawn = nil -- Respawn now
|
||||||
@@ -482,7 +490,9 @@ function serialize.serialize_player(player, failed_deserialization)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Serialize non-character inventories
|
-- Serialize non-character inventories
|
||||||
if player.controller_type == defines.controllers.god then
|
if player.controller_type == defines.controllers.god
|
||||||
|
or v2_remote_controller and player.physical_controller_type == defines.controllers.god
|
||||||
|
then
|
||||||
serialized.inventories = serialize.serialize_inventories(player, { main = defines.inventory.god_main })
|
serialized.inventories = serialize.serialize_inventories(player, { main = defines.inventory.god_main })
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -541,8 +551,8 @@ function serialize.deserialize_player(player, serialized)
|
|||||||
|
|
||||||
local target_controller = defines.controllers[serialized.controller]
|
local target_controller = defines.controllers[serialized.controller]
|
||||||
if player.controller_type ~= target_controller or serialized.controller == "ghost" then
|
if player.controller_type ~= target_controller or serialized.controller == "ghost" then
|
||||||
if serialized.controller == "character" or serialized.controller == "remote" then
|
if serialized.controller == "character" then
|
||||||
-- Character and Remote both require a character, but must not destroy an existing one
|
-- Create a character but do not destroy an existing one
|
||||||
ensure_character(player)
|
ensure_character(player)
|
||||||
if player.controller_type ~= target_controller then
|
if player.controller_type ~= target_controller then
|
||||||
player.set_controller{ type = target_controller }
|
player.set_controller{ type = target_controller }
|
||||||
@@ -570,7 +580,7 @@ function serialize.deserialize_player(player, serialized)
|
|||||||
character.destroy()
|
character.destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
elseif serialized.controller ~= "remote" then
|
||||||
-- All other controllers should not have a character
|
-- All other controllers should not have a character
|
||||||
local character = player.character
|
local character = player.character
|
||||||
if character and character.valid then
|
if character and character.valid then
|
||||||
@@ -579,6 +589,9 @@ function serialize.deserialize_player(player, serialized)
|
|||||||
if player.controller_type ~= target_controller then
|
if player.controller_type ~= target_controller then
|
||||||
player.set_controller{ type = target_controller }
|
player.set_controller{ type = target_controller }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
error("Remote should not be 'serialized.controller'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -624,6 +637,11 @@ function serialize.deserialize_player(player, serialized)
|
|||||||
serialize.deserialize_crafting_notifications(player, serialized.recipe_notifications)
|
serialize.deserialize_crafting_notifications(player, serialized.recipe_notifications)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Return to remote view after physical controller has been synced
|
||||||
|
if serialized.remote then
|
||||||
|
player.set_controller{ type = defines.controllers.remote }
|
||||||
|
end
|
||||||
|
|
||||||
return next(failed_deserialization) and failed_deserialization or nil
|
return next(failed_deserialization) and failed_deserialization or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user