main
jeffi 10 months ago
parent cfd67584e7
commit 4ff7657bd8
  1. 2
      src/Bastion/Bastion.lua
  2. 31
      src/Module/Module.lua

@ -20,7 +20,6 @@ local Bastion = {
BastionScripts = "scripts/bastion/scripts", BastionScripts = "scripts/bastion/scripts",
ThirdParty = "scripts/BastionScripts", ThirdParty = "scripts/BastionScripts",
}, },
Tick = 0,
} }
function Bastion:__index(key) function Bastion:__index(key)
@ -282,7 +281,6 @@ function Bastion:Load()
end) end)
self.Ticker = C_Timer.NewTicker(0.1, function() self.Ticker = C_Timer.NewTicker(0.1, function()
Bastion.Tick = GetGameTick()
self.Globals.CombatTimer:Check() self.Globals.CombatTimer:Check()
if Bastion.Enabled then if Bastion.Enabled then

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

Loading…
Cancel
Save