Rename API -> SYSTEM

This commit is contained in:
Van
2026-01-14 15:14:38 +03:00
parent 50dd702e6e
commit 0c5f508152
54 changed files with 57 additions and 54 deletions

View File

@@ -0,0 +1,4 @@
local modInfo = Mod.getInfo('smc__system__helper_lib')
local require = modInfo.require
require('Lib')

View File

@@ -0,0 +1,2 @@
name = smc__system__helper_lib
depends = smc__system__ensure

View File

@@ -0,0 +1,6 @@
Smc = {}
local modInfo = Mod.getInfo('smc__system__helper_lib')
local require = modInfo.require
require('Lib.globalStep')

View File

@@ -0,0 +1,75 @@
---@type {timeDelay:number, callbackFunc:fun(deltaTime:number), timer:number, lastCall:number}[]
local callsWithDelay = {}
---@param timeDelay number
---@param callbackFunc fun(deltaTime:number)
function Smc.registerGlobalStepWithDelay(timeDelay, callbackFunc)
table.insert(callsWithDelay, {
timeDelay = timeDelay,
callbackFunc = callbackFunc,
timer = 0.0,
lastCall = 0.0
})
end
core.register_globalstep(function(deltaTime)
---@type number
local timer
local lastCall
for _, callback in ipairs(callsWithDelay) do
timer = callback.timer
lastCall = callback.lastCall
timer = timer + deltaTime
lastCall = lastCall + deltaTime
if timer >= callback.timeDelay then
callback.callbackFunc(lastCall)
callback.timer = timer - callback.timeDelay
callback.lastCall = 0.0
else
callback.timer = timer
callback.lastCall = lastCall
end
end
end)
---@type {timeDelay:number, callbackFunc:fun(deltaTime:number, player), timer:number, lastCall:number}[]
local callsForEachPlayer = {}
---@param timeDelay number
---@param callbackFunc fun(deltaTime:number, player:Player)
function Smc.registerGlobalStepForEachPlayer(timeDelay, callbackFunc)
table.insert(callsWithDelay, {
timeDelay = timeDelay,
callbackFunc = callbackFunc,
timer = 0.0,
lastCall = 0.0,
})
end
core.register_globalstep(function(deltaTime)
---@type number
local timer
local lastCall
for _, player in ipairs(core.get_connected_players()) do
for _, callback in ipairs(callsForEachPlayer) do
timer = callback.timer
lastCall = callback.lastCall
timer = timer + deltaTime
lastCall = lastCall + deltaTime
if timer >= callback.timeDelay then
callback.callbackFunc(lastCall, player)
callback.timer = timer - callback.timeDelay
callback.lastCall = 0.0
else
callback.timer = timer
callback.lastCall = lastCall
end
end
end
end)