From 4ff7657bd873ae4cb8d568d6543bb8a04873676a Mon Sep 17 00:00:00 2001 From: jeffi Date: Wed, 13 Mar 2024 04:57:44 -0500 Subject: [PATCH] Upgrades --- src/Bastion/Bastion.lua | 2 -- src/Module/Module.lua | 31 +++++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Bastion/Bastion.lua b/src/Bastion/Bastion.lua index 34f48c0..1be75e5 100644 --- a/src/Bastion/Bastion.lua +++ b/src/Bastion/Bastion.lua @@ -20,7 +20,6 @@ local Bastion = { BastionScripts = "scripts/bastion/scripts", ThirdParty = "scripts/BastionScripts", }, - Tick = 0, } function Bastion:__index(key) @@ -282,7 +281,6 @@ function Bastion:Load() end) self.Ticker = C_Timer.NewTicker(0.1, function() - Bastion.Tick = GetGameTick() self.Globals.CombatTimer:Check() if Bastion.Enabled then diff --git a/src/Module/Module.lua b/src/Module/Module.lua index c11b1a2..fd27129 100644 --- a/src/Module/Module.lua +++ b/src/Module/Module.lua @@ -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) - - module.name = name - module.enabled = false - module.synced = {} - module.interval = interval - module.nextTick = 0 - return module +function Module:New(name, interval, persist) + local self = setmetatable({}, 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