1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-26 03:52:22 +02:00
ComfyFactorio/on_tick_schedule.lua

27 lines
1.1 KiB
Lua
Raw Normal View History

2019-03-03 02:38:29 +01:00
local event = require 'utils.event'
2019-03-06 17:30:59 +01:00
local function trigger_function(schedule)
if not schedule.args then schedule.func() return end
if not schedule.args[2] then schedule.func(schedule.args[1]) return end
if not schedule.args[3] then schedule.func(schedule.args[1], schedule.args[2]) return end
if not schedule.args[4] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3]) return end
2019-03-07 19:54:33 +01:00
if not schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4]) return end
2019-03-06 17:30:59 +01:00
if schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4], schedule.args[5]) return end
end
2019-03-03 02:38:29 +01:00
local function on_tick()
if not global.on_tick_schedule[game.tick] then return end
for _, schedule in pairs(global.on_tick_schedule[game.tick]) do
2019-03-06 17:30:59 +01:00
trigger_function(schedule)
2019-03-03 02:38:29 +01:00
end
global.on_tick_schedule[game.tick] = nil
end
2019-03-11 18:58:30 +01:00
local function on_init(event)
2019-03-03 02:38:29 +01:00
if not global.on_tick_schedule then global.on_tick_schedule = {} end
end
2019-03-11 18:58:30 +01:00
event.on_init(on_init)
2019-03-03 02:38:29 +01:00
event.add(defines.events.on_tick, on_tick)