|
|
|
@ -11,6 +11,7 @@ Bastion = ... |
|
|
|
|
---@field synced function[] |
|
|
|
|
---@field interval? number |
|
|
|
|
---@field nextTick number |
|
|
|
|
---@field persist boolean |
|
|
|
|
local Module = {} |
|
|
|
|
Module.__index = Module |
|
|
|
|
|
|
|
|
@ -23,17 +24,18 @@ end |
|
|
|
|
-- Constructor |
|
|
|
|
---@param name string |
|
|
|
|
---@param interval? number |
|
|
|
|
---@param persist? boolean |
|
|
|
|
---@return Bastion.Module |
|
|
|
|
function Module:New(name, interval) |
|
|
|
|
local module = {} |
|
|
|
|
setmetatable(module, Module) |
|
|
|
|
function Module:New(name, interval, persist) |
|
|
|
|
local self = setmetatable({}, Module) |
|
|
|
|
|
|
|
|
|
module.name = name |
|
|
|
|
module.enabled = false |
|
|
|
|
module.synced = {} |
|
|
|
|
module.interval = interval |
|
|
|
|
module.nextTick = 0 |
|
|
|
|
return module |
|
|
|
|
self.name = name |
|
|
|
|
self.enabled = false |
|
|
|
|
self.synced = {} |
|
|
|
|
self.interval = interval or 0.01 |
|
|
|
|
self.nextTick = GetTime() + self.interval |
|
|
|
|
self.persist = persist or false |
|
|
|
|
return self |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Enable the module |
|
|
|
@ -48,6 +50,11 @@ function Module:Disable() |
|
|
|
|
return self |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
function Module:NextTick() |
|
|
|
|
self.nextTick = GetTime() + self.interval |
|
|
|
|
return self |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Toggle the module |
|
|
|
|
---@return nil |
|
|
|
|
function Module:Toggle() |
|
|
|
@ -81,8 +88,8 @@ end |
|
|
|
|
-- Sync |
|
|
|
|
function Module:Tick() |
|
|
|
|
if self.enabled then |
|
|
|
|
if Bastion.Tick >= self.nextTick then |
|
|
|
|
self.nextTick = Bastion.Tick + (self.interval or 1) |
|
|
|
|
if GetTime() >= self.nextTick then |
|
|
|
|
self:NextTick() |
|
|
|
|
for i = 1, #self.synced do |
|
|
|
|
self.synced[i]() |
|
|
|
|
end |
|
|
|
|