Add 2.0 support to core lua

This commit is contained in:
Cooldude2606 committed 2024-11-23 14:26:10 +00:00
1 parent 201a201f05
commit ad836d3776
6 files changed
+46 -54

No files matched your search

+15 -11
View File
@@ -1,9 +1,10 @@
local api = require('modules/clusterio/api')
local compat = require("modules/clusterio/compat")
local function check_patch()
if global.clusterio_patch_number ~= clusterio_patch_number then
global.clusterio_patch_number = clusterio_patch_number
local script_data = compat.script_data()
if script_data.clusterio_patch_number ~= clusterio_patch_number then
script_data.clusterio_patch_number = clusterio_patch_number
script.raise_event(api.events.on_server_startup, {})
end
end
@@ -14,8 +15,9 @@ impl.events = {}
impl.events[defines.events.on_tick] = check_patch
impl.events[api.events.on_server_startup] = function()
if not global.clusterio then
global.clusterio = {
local script_data = compat.script_data()
if not script_data.clusterio then
script_data.clusterio = {
instance_id = nil,
instance_name = nil,
}
@@ -49,9 +51,10 @@ end
-- Internal API
clusterio_private = {}
function clusterio_private.update_instance(new_id, new_name)
local script_data = compat.script_data()
check_patch()
global.clusterio.instance_id = new_id
global.clusterio.instance_name = new_name
script_data.clusterio.instance_id = new_id
script_data.clusterio.instance_name = new_name
script.raise_event(api.events.on_instance_updated, {
instance_id = new_id,
instance_name = new_name,
@@ -71,16 +74,17 @@ remote.add_interface('clusterio_api', {
end,
get_instance_id = function()
return global.clusterio.instance_id
return compat.script_data().clusterio.instance_id
end,
get_instance_name = function()
return global.clusterio.instance_name
return compat.script_data().clusterio.instance_name
end,
get_file_no = function()
global.clusterio_file_no = (global.clusterio_file_no or 0) + 1
return global.clusterio_file_no
local script_data = compat.script_data()
script_data.clusterio_file_no = (script_data.clusterio_file_no or 0) + 1
return script_data.clusterio_file_no
end,
})