Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space age update #75

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions src/compat/factorio_2.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local compat = {}

function compat.set_parameters(combinator, parameters)
combinator.parameters = parameters
end

function compat.version_ge(major, minor)
return major < 2 or major == 2 and minor == 0
end

return compat
36 changes: 27 additions & 9 deletions src/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require("config")
local mod_gui = require("mod-gui")

local clusterio_api = require("__clusterio_lib__/api")
local lib_compat = require("__clusterio_lib__/compat")

local compat = require("compat")

Expand Down Expand Up @@ -58,7 +59,7 @@ function OnBuiltEntity(event)
})
end
-- kill entity, try to give it back to the player though
if compat.version_ge(1, 0) then
if lib_compat.version_ge("1.0.0") then
local inventory = game.create_inventory(1)
entity.mine {
inventory = inventory,
Expand All @@ -82,7 +83,7 @@ function OnBuiltEntity(event)
end
else
-- it wasn't placed by a player, we can't tell em whats wrong
if compat.version_ge(1, 0) then
if lib_compat.version_ge("1.0.0") then
entity.mine()
else
entity.destroy()
Expand Down Expand Up @@ -229,12 +230,20 @@ end
--[[Thing resetting events]]--
------------------------------
script.on_init(function()
-- 2.0 compatibility
if lib_compat.version_ge("2.0.0") then
global = storage
end
clusterio_api.init()
RegisterClusterioEvents()
Reset()
end)

script.on_load(function()
-- 2.0 compatibility
if lib_compat.version_ge("2.0.0") then
global = storage
end
clusterio_api.init()
RegisterClusterioEvents()
end)
Expand Down Expand Up @@ -623,7 +632,12 @@ function GetOutputChestRequest(requests, entityData)
--If there isn't enough items in the chest
local missingAmount = requestItem.count - itemsInChest
--But don't request more than the chest can hold
local stackSize = game.item_prototypes[requestItem.name].stack_size
local stackSize
if lib_compat.version_ge("2.0.0") then
stackSize = prototypes.item[requestItem.name].stack_size
else
stackSize = game.item_prototypes[requestItem.name].stack_size
end
missingAmount = math.min(missingAmount, slotsLeft * stackSize)
if missingAmount > 0 then
slotsLeft = slotsLeft - math.ceil(missingAmount / stackSize)
Expand Down Expand Up @@ -841,7 +855,7 @@ function ExportOutputList()
end

function Import(data)
local items = game.json_to_table(data)
local items = lib_compat.json_to_table(data)
for _, item in ipairs(items) do
GiveItemsToStorage(item[1], item[2])
end
Expand All @@ -851,7 +865,7 @@ function UpdateInvData(data, full)
if full then
global.invdata = {}
end
local items = game.json_to_table(data)
local items = lib_compat.json_to_table(data)
for _, item in ipairs(items) do
global.invdata[item[1]] = item[2]
end
Expand Down Expand Up @@ -911,9 +925,9 @@ function UpdateInvCombinators()
table.insert(invframe,{count=instance_id,index=#invframe+1,signal={name="signal-localid",type="virtual"}})
end

local items = game.item_prototypes
local fluids = game.fluid_prototypes
local virtuals = game.virtual_signal_prototypes
local items = lib_compat.version_ge("2.0.0") and prototypes.item or game.item_prototypes
local fluids = lib_compat.version_ge("2.0.0") and prototypes.fluid or game.fluid_prototypes
local virtuals = lib_compat.version_ge("2.0.0") and prototypes.virtual_signal or game.virtual_signal_prototypes
if global.invdata then
for name, count in pairs(global.invdata) do
-- Combinator signals are limited to a max value of 2^31-1
Expand Down Expand Up @@ -1227,7 +1241,11 @@ script.on_event(defines.events.on_player_cursor_stack_changed, function(event)
end
else
if global.zoneDraw[event.player_index] then
rendering.destroy(global.zoneDraw[event.player_index])
if lib_compat.version_ge("2.0.0") then
global.zoneDraw[event.player_index].destroy()
else
rendering.destroy(global.zoneDraw[event.player_index])
end
global.zoneDraw[event.player_index] = nil
end
end
Expand Down
7 changes: 3 additions & 4 deletions src/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ inv.minable.result = INV_COMBINATOR_NAME
inv.item_slot_count = 2000
for _, sprite in pairs(inv.sprites) do
sprite.layers[1].tint = tint
sprite.layers[1].hr_version.tint = tint
end
data:extend{
inv,
Expand All @@ -111,10 +110,10 @@ data:extend{
enabled = true, -- TODO do this on a tech somewhere
ingredients =
{
{"constant-combinator", 1},
{"electronic-circuit", 50}
{type = "item", name = "constant-combinator", amount = 1},
{type = "item", name = "electronic-circuit", amount = 50}
},
result = INV_COMBINATOR_NAME,
results = {{type = "item", name = INV_COMBINATOR_NAME, amount = 1}},
requester_paste_multiplier = 1
},
}
Expand Down
11 changes: 8 additions & 3 deletions src/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
"name": "subspace_storage",
"variants": [
{
"version": "1.99.18",
"version": "2.17.0",
"factorio_version": "0.17",
"additional_files": { "compat.lua": ["compat", "factorio_0.17.lua"] }
},
{
"version": "1.99.19",
"version": "2.10.0",
"factorio_version": "1.0",
"additional_files": { "compat.lua": ["compat", "factorio_1.0.lua"] }
},
{
"version": "1.99.20",
"version": "2.11.0",
"factorio_version": "1.1",
"additional_files": { "compat.lua": ["compat", "factorio_1.1.lua"] }
},
{
"version": "2.20.0",
"factorio_version": "2.0",
"additional_files": { "compat.lua": ["compat", "factorio_2.0.lua"] }
}
],
"title": "Subspace Storage (Alpha)",
Expand Down
Loading