mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Create equipment grid when deserializing it
Create equipment grid for items that support it and doesn't currently have a grid. Fixes deserialization of spidertron equipment grids.
This commit is contained in:
1 parent
b0067eccc6
commit
0ae4fa0d2e
1 file changed
+35
-2
@@ -2,18 +2,44 @@
|
|||||||
-- Based on code from playerManager and trainTeleports
|
-- Based on code from playerManager and trainTeleports
|
||||||
local serialize = {}
|
local serialize = {}
|
||||||
|
|
||||||
|
local function version_to_table(version)
|
||||||
|
local t = {}
|
||||||
|
for p in string.gmatch(version, "%d+") do
|
||||||
|
t[#t + 1] = tonumber(p)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
-- 0.17 compatibility
|
-- 0.17 compatibility
|
||||||
local supports_bar, get_bar, has_bar
|
local supports_bar, get_bar, has_bar, version
|
||||||
if (pcall(function() local mods = script.active_mods end)) then
|
if (pcall(function() local mods = script.active_mods end)) then
|
||||||
supports_bar = "supports_bar"
|
supports_bar = "supports_bar"
|
||||||
get_bar = "get_bar"
|
get_bar = "get_bar"
|
||||||
set_bar = "set_bar"
|
set_bar = "set_bar"
|
||||||
|
version = version_to_table(script.active_mods.base)
|
||||||
else
|
else
|
||||||
supports_bar = "hasbar"
|
supports_bar = "hasbar"
|
||||||
get_bar = "getbar"
|
get_bar = "getbar"
|
||||||
set_bar = "setbar"
|
set_bar = "setbar"
|
||||||
|
version = version_to_table("0.17.69")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns true if the game version is greater than or equal to the given version
|
||||||
|
local function version_ge(comp)
|
||||||
|
comp = version_to_table(comp)
|
||||||
|
for i=1, 3 do
|
||||||
|
if comp[i] > version[i] then
|
||||||
|
return false
|
||||||
|
elseif comp[i] < version[i] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local has_create_grid = version_ge("1.1.7")
|
||||||
|
|
||||||
|
|
||||||
-- Equipment Grids are serialized into an array of equipment entries
|
-- Equipment Grids are serialized into an array of equipment entries
|
||||||
-- where ench entry is a table with the following fields:
|
-- where ench entry is a table with the following fields:
|
||||||
-- n: name
|
-- n: name
|
||||||
@@ -173,7 +199,14 @@ function serialize.deserialize_item_stack(slot, entry)
|
|||||||
slot.allow_manual_label_change = label.a
|
slot.allow_manual_label_change = label.a
|
||||||
end
|
end
|
||||||
if entry.g then
|
if entry.g then
|
||||||
serialize.deserialize_equipment_grid(slot.grid, entry.g)
|
if slot.grid then
|
||||||
|
serialize.deserialize_equipment_grid(slot.grid, entry.g)
|
||||||
|
elseif slot.type == "item-with-entity-data" and has_create_grid then
|
||||||
|
slot.create_grid()
|
||||||
|
serialize.deserialize_equipment_grid(slot.grid, entry.g)
|
||||||
|
else
|
||||||
|
print("Error: Attempt to deserialize equipment grid on an unsupported entity")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if entry.i then
|
if entry.i then
|
||||||
local sub_inventory = slot.get_inventory(defines.inventory.item_main)
|
local sub_inventory = slot.get_inventory(defines.inventory.item_main)
|
||||||
|
|||||||
Reference in new issue
Block a user