mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Fix sync when joining a new server
This commit is contained in:
1 file changed
+28
-3
@@ -377,10 +377,35 @@ function serialize.deserialize_crafting_notifications(player, serialized)
|
|||||||
local recipe_names = helpers.json_to_table(assert(helpers.decode_string(serialized)))
|
local recipe_names = helpers.json_to_table(assert(helpers.decode_string(serialized)))
|
||||||
assert(type(recipe_names) == "table", "wrong type decoded from json_to_table")
|
assert(type(recipe_names) == "table", "wrong type decoded from json_to_table")
|
||||||
local clear_notification = player.clear_recipe_notification
|
local clear_notification = player.clear_recipe_notification
|
||||||
local valid_recipes = compat.prototypes.recipe
|
local add_notification = player.add_recipe_notification
|
||||||
|
local notifications = {}
|
||||||
|
|
||||||
|
-- Assume all recipes need a notification
|
||||||
|
for _, recipe in pairs(player.force.recipes) do
|
||||||
|
if recipe.enabled and not recipe.hidden then
|
||||||
|
notifications[recipe.name] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remove recipes the player has cleared
|
||||||
for _, recipe_name in pairs(recipe_names) do
|
for _, recipe_name in pairs(recipe_names) do
|
||||||
if valid_recipes[recipe_name] then
|
if notifications[recipe_name] then
|
||||||
clear_notification(recipe_name)
|
notifications[recipe_name] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clear ones which are ones which are not required
|
||||||
|
for _, recipe in pairs(player.get_recipe_notifications()) do
|
||||||
|
if notifications[recipe.name] == false then
|
||||||
|
clear_notification(recipe.name)
|
||||||
|
end
|
||||||
|
notifications[recipe.name] = nil -- Prevents double add below
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add any which the player did not have
|
||||||
|
for recipe_name, should_add in pairs(notifications) do
|
||||||
|
if should_add then
|
||||||
|
add_notification(recipe_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user