diff --git a/src/Cache/Cache.lua b/src/Cache/Cache.lua index 2e4d6fb..f9468d5 100644 --- a/src/Cache/Cache.lua +++ b/src/Cache/Cache.lua @@ -19,7 +19,7 @@ function Cache:Set(key, value, duration) self.cache[key] = { value = value, duration = duration, - time = GetTime() + time = GetTime(), } end diff --git a/src/Cacheable/Cacheable.lua b/src/Cacheable/Cacheable.lua index 4d8078d..eae502b 100644 --- a/src/Cacheable/Cacheable.lua +++ b/src/Cacheable/Cacheable.lua @@ -1,11 +1,10 @@ ----@types Tinkr, Bastion +---@type Tinkr, Bastion local Tinkr, Bastion = ... -- Define a Cacheable class +---@class Cacheable: { value: V, cache: Cache, callback?: fun(): V } + ---@class Cacheable ----@field cache? Cache ----@field callback? fun():any ----@field value any local Cacheable = { cache = nil, callback = nil, @@ -40,10 +39,9 @@ function Cacheable:__tostring() end -- Create ----@generic V: Cacheable, V ----@param value V +---@generic V : Cacheable, V +---@param value `V` ---@param cb fun(): V ----@return V function Cacheable:New(value, cb) local self = setmetatable({}, Cacheable) diff --git a/src/Spell/Spell.lua b/src/Spell/Spell.lua index 1c4e773..d49bc4e 100644 --- a/src/Spell/Spell.lua +++ b/src/Spell/Spell.lua @@ -127,11 +127,8 @@ function Spell:GetFullRechargeTime() return 0 end - if charges == 0 then - return start + duration - GetTime() - end - - return chargeStart + chargeDuration - GetTime() + local totalChargeTime = ((maxCharges - charges) * chargeDuration) - ((chargeStart + chargeDuration) - GetTime()) + return totalChargeTime end -- Return the castable function diff --git a/src/UnitManager/UnitManager.lua b/src/UnitManager/UnitManager.lua index a4b6d4b..63703d7 100644 --- a/src/UnitManager/UnitManager.lua +++ b/src/UnitManager/UnitManager.lua @@ -5,7 +5,7 @@ local ObjectManager = Tinkr.Util.ObjectManager local Unit = Bastion.Unit ----@class CacheableUnit : Cacheable, Unit +---@class CacheableUnit : Cacheable -- Create a new UnitManager class ---@class UnitManager : { [UnitId]: Unit } @@ -122,16 +122,14 @@ end -- Create a custom unit and cache it for .5 seconds ---@param token string ---@param cb fun(): Unit ----@return CacheableUnit +---@return Cacheable function UnitManager:CreateCustomUnit(token, cb) local unit = cb() - ---@type CacheableUnit local cachedUnit = Bastion.Cacheable:New(unit, cb) if unit == nil then error("UnitManager:CreateCustomUnit - Invalid unit: " .. token) end - if self.customUnits[token] == nil then self.customUnits[token] = { unit = cachedUnit, @@ -140,7 +138,6 @@ function UnitManager:CreateCustomUnit(token, cb) end self.cache:Set(token, cachedUnit, 0.5) - return cachedUnit end diff --git a/src/_bastion.lua b/src/_bastion.lua index aee1228..cb65b68 100644 --- a/src/_bastion.lua +++ b/src/_bastion.lua @@ -82,7 +82,9 @@ local function LoadThird() end end ----@return any ... +---@generic V +---@param class `V` +---@return V ... function Bastion.require(class) -- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) return Bastion:Require("~/src/" .. class .. "/" .. class) @@ -90,62 +92,37 @@ end Bastion.Globals = {} ----@type ClassMagic Bastion.ClassMagic = Bastion.require("ClassMagic") ----@type List Bastion.List = Bastion.require("List") ----@type Library Bastion.Library = Bastion.require("Library") ---@type NotificationsList, Notification Bastion.NotificationsList, Bastion.Notification = Bastion.require("NotificationsList") ----@type Vector3 Bastion.Vector3 = Bastion.require("Vector3") ----@type Sequencer Bastion.Sequencer = Bastion.require("Sequencer") ----@type Command Bastion.Command = Bastion.require("Command") ----@type Cache Bastion.Cache = Bastion.require("Cache") ----@type Cacheable Bastion.Cacheable = Bastion.require("Cacheable") ----@type Refreshable Bastion.Refreshable = Bastion.require("Refreshable") ----@type Unit Bastion.Unit = Bastion.require("Unit") ----@type Aura Bastion.Aura = Bastion.require("Aura") ---@type APL, APLActor, APLTrait Bastion.APL, Bastion.APLActor, Bastion.APLTrait = Bastion.require("APL") ----@type Module Bastion.Module = Bastion.require("Module") ----@type UnitManager Bastion.UnitManager = Bastion.require("UnitManager"):New() ----@type ObjectManager Bastion.ObjectManager = Bastion.require("ObjectManager"):New() ----@type EventManager Bastion.EventManager = Bastion.require("EventManager") Bastion.Globals.EventManager = Bastion.EventManager:New() ----@type Spell Bastion.Spell = Bastion.require("Spell") ----@type SpellBook Bastion.SpellBook = Bastion.require("SpellBook") Bastion.Globals.SpellBook = Bastion.SpellBook:New() ----@type Item Bastion.Item = Bastion.require("Item") ----@type ItemBook Bastion.ItemBook = Bastion.require("ItemBook") Bastion.Globals.ItemBook = Bastion.ItemBook:New() ----@type AuraTable Bastion.AuraTable = Bastion.require("AuraTable") ----@type Class Bastion.Class = Bastion.require("Class") ----@type Timer Bastion.Timer = Bastion.require("Timer") ----@type Timer Bastion.CombatTimer = Bastion.Timer:New("combat") ----@type MythicPlusUtils Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New() ----@type NotificationsList Bastion.Notifications = Bastion.NotificationsList:New() local LIBRARIES = {} @@ -317,11 +294,7 @@ Command:Register("dumpspells", "Dump spells to a file", function() if spellID then spellName = spellName:gsub("[%W%s]", "") - WriteFile( - "bastion-" .. UnitClass("player") .. "-" .. rand .. ".lua", - "local " .. spellName .. " = Bastion.Globals.SpellBook:GetSpell(" .. spellID .. ")\n", - true - ) + WriteFile("bastion-" .. UnitClass("player") .. "-" .. rand .. ".lua", "local " .. spellName .. " = Bastion.Globals.SpellBook:GetSpell(" .. spellID .. ")\n", true) end i = i + 1 end