mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 23:24:52 +09:00
Send only the local state on download init
The current state sent with the download request no longer includes the failed names from the previous deserialization. Stored names unknown on this instance always end up in the add list, so the deserializer recomputes the failed list from that on every download and needs no previous state. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
68ce13ead4
commit
b1e79cf86d
2 files changed
+9
-28
No files matched your search
@@ -551,33 +551,27 @@ end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param serialized string Encoded delta against the state sent with the download request
|
||||
--- @param previous_failed string[]? Recipe names that did not exist at the last deserialization
|
||||
--- @return string[]? failed Recipe names that do not exist
|
||||
function serialize.deserialize_crafting_notifications(player, serialized, previous_failed)
|
||||
function serialize.deserialize_crafting_notifications(player, serialized)
|
||||
--- @type CraftingNotificationDelta
|
||||
local delta = helpers.json_to_table(assert(helpers.decode_string(serialized)))
|
||||
assert(type(delta) == "table", "wrong type decoded from json_to_table")
|
||||
|
||||
local failed = {}
|
||||
for _, recipe_name in pairs(previous_failed or {}) do
|
||||
failed[recipe_name] = true
|
||||
end
|
||||
|
||||
-- Recipes which can have a notification on this server
|
||||
local enabled = {}
|
||||
for _, recipe in pairs(player.force.recipes) do
|
||||
if recipe.enabled and not recipe.hidden then
|
||||
enabled[recipe.name] = true
|
||||
failed[recipe.name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Clear notifications the player has cleared elsewhere, this means "add seen notification"
|
||||
local failed = {}
|
||||
for _, recipe_name in pairs(delta.add or {}) do
|
||||
if enabled[recipe_name] then
|
||||
player.clear_recipe_notification(recipe_name)
|
||||
else
|
||||
failed[recipe_name] = true -- Recipe does not exist on this server
|
||||
failed[#failed + 1] = recipe_name -- Recipe does not exist on this server
|
||||
end
|
||||
end
|
||||
|
||||
@@ -585,16 +579,10 @@ function serialize.deserialize_crafting_notifications(player, serialized, previo
|
||||
for _, recipe_name in pairs(delta.remove or {}) do
|
||||
if enabled[recipe_name] then
|
||||
player.add_recipe_notification(recipe_name)
|
||||
else
|
||||
failed[recipe_name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local failed_names = {}
|
||||
for recipe_name in pairs(failed) do
|
||||
failed_names[#failed_names + 1] = recipe_name
|
||||
end
|
||||
return next(failed_names) and failed_names or nil
|
||||
return next(failed) and failed or nil
|
||||
end
|
||||
|
||||
local controller_to_name = {}
|
||||
@@ -800,9 +788,8 @@ end
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param serialized SerializedPlayerData
|
||||
--- @param previous_failed FailedDeserializationPlayerData?
|
||||
--- @return FailedDeserializationPlayerData?
|
||||
function serialize.deserialize_player(player, serialized, previous_failed)
|
||||
function serialize.deserialize_player(player, serialized)
|
||||
local failed_deserialization = {}
|
||||
|
||||
local target_controller = defines.controllers[serialized.controller]
|
||||
@@ -889,9 +876,8 @@ function serialize.deserialize_player(player, serialized, previous_failed)
|
||||
|
||||
-- Deserialize recipe notifications
|
||||
if recipe_notifications_api and serialized.recipe_notifications then
|
||||
failed_deserialization.recipe_notifications = serialize.deserialize_crafting_notifications(
|
||||
player, serialized.recipe_notifications, previous_failed and previous_failed.recipe_notifications
|
||||
)
|
||||
failed_deserialization.recipe_notifications =
|
||||
serialize.deserialize_crafting_notifications(player, serialized.recipe_notifications)
|
||||
end
|
||||
|
||||
return next(failed_deserialization) and failed_deserialization or nil
|
||||
|
||||
Reference in new issue
Block a user