diff --git a/src/APL/APL.lua b/src/APL/APL.lua index 6f20338..aeae904 100644 --- a/src/APL/APL.lua +++ b/src/APL/APL.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- APL (Attack priority list) class ---@class Bastion.APL @@ -220,4 +222,4 @@ function APL:__tostring() return "Bastion.__APL(" .. self.name .. ")" end -return APL +Bastion.APL = APL diff --git a/src/APLActor/APLActor.lua b/src/APLActor/APLActor.lua index 303e862..8d64572 100644 --- a/src/APLActor/APLActor.lua +++ b/src/APLActor/APLActor.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.APLActor.Table.Base ---@field type "spell" | "item" | "apl" | "sequencer" | "variable" | "action" @@ -131,4 +133,4 @@ function APLActor:__tostring() return string.format("Bastion.__APLActor(%s)", self.name) end -return APLActor +Bastion.APLActor = APLActor diff --git a/src/APLTrait/APLTrait.lua b/src/APLTrait/APLTrait.lua index 7de6529..b1ecace 100644 --- a/src/APLTrait/APLTrait.lua +++ b/src/APLTrait/APLTrait.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create an APL trait for the APL class ---@class Bastion.APLTrait @@ -39,4 +41,4 @@ function APLTrait:__tostring() return "Bastion.__APLTrait" end -return APLTrait +Bastion.APLTrait = APLTrait diff --git a/src/Aura/Aura.lua b/src/Aura/Aura.lua index 1ebc5dd..26039b3 100644 --- a/src/Aura/Aura.lua +++ b/src/Aura/Aura.lua @@ -1,6 +1,7 @@ --- Document with emmy lua: https://emmylua.github.io/ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.Aura.Aura.Data ---@field auraInstanceID? number @@ -399,4 +400,4 @@ function Aura:IsDispelableBySpell(spell) return false end -return Aura +Bastion.Aura = Aura diff --git a/src/AuraTable/AuraTable.lua b/src/AuraTable/AuraTable.lua index 988bf25..80b80c4 100644 --- a/src/AuraTable/AuraTable.lua +++ b/src/AuraTable/AuraTable.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@alias auraInstanceId integer @@ -815,4 +817,4 @@ function AuraTable:HasAnyFoodOrDrinkAura() return false end -return AuraTable +Bastion.AuraTable = AuraTable diff --git a/src/Cache/Cache.lua b/src/Cache/Cache.lua index fa6d328..8f3608a 100644 --- a/src/Cache/Cache.lua +++ b/src/Cache/Cache.lua @@ -1,3 +1,8 @@ +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... + ---@class Bastion.Cache local Cache = {} Cache.__index = Cache @@ -52,4 +57,4 @@ function Cache:IsCached(key) return false end -return Cache +Bastion.Cache = Cache diff --git a/src/Cacheable/Cacheable.lua b/src/Cacheable/Cacheable.lua index f1d2bac..5e450fd 100644 --- a/src/Cacheable/Cacheable.lua +++ b/src/Cacheable/Cacheable.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.Cacheable @@ -84,4 +86,4 @@ function Cacheable:SetCallback(cb, ...) self.args = SafePack(...) end -return Cacheable +Bastion.Cacheable = Cacheable diff --git a/src/Class/Class.lua b/src/Class/Class.lua index 95fcbd9..f7f9cbd 100644 --- a/src/Class/Class.lua +++ b/src/Class/Class.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a new Class class ---@class Bastion.Class @@ -64,4 +66,4 @@ function Class:GetColor() return C_ClassColor.GetClassColor(self.class.name) end -return Class +Bastion.Class = Class diff --git a/src/ClassMagic/ClassMagic.lua b/src/ClassMagic/ClassMagic.lua index 0666b99..146aad7 100644 --- a/src/ClassMagic/ClassMagic.lua +++ b/src/ClassMagic/ClassMagic.lua @@ -1,3 +1,8 @@ +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... + ---@class Bastion.ClassMagic local ClassMagic = {} ClassMagic.__index = ClassMagic @@ -49,4 +54,4 @@ function ClassMagic:Resolve(Class, key) return Class[key] end -return ClassMagic +Bastion.ClassMagic = ClassMagic diff --git a/src/Command/Command.lua b/src/Command/Command.lua index f38c0be..8b31b65 100644 --- a/src/Command/Command.lua +++ b/src/Command/Command.lua @@ -1,3 +1,8 @@ +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... + -- Create a wow command handler class ---@class Bastion.Command ---@field command string @@ -76,4 +81,4 @@ function Command:PrintHelp() end end -return Command +Bastion.Command = Command diff --git a/src/Config/Config.lua b/src/Config/Config.lua index 1f7ad1d..0105553 100644 --- a/src/Config/Config.lua +++ b/src/Config/Config.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.Config ---@field instantiated boolean @@ -79,4 +81,4 @@ function Config:Sync(key) self.config:Sync(key) end -return Config +Bastion.Config = Config diff --git a/src/EventManager/EventManager.lua b/src/EventManager/EventManager.lua index f319bdf..2418fe2 100644 --- a/src/EventManager/EventManager.lua +++ b/src/EventManager/EventManager.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create an EventManager class ---@class Bastion.EventManager @@ -136,4 +138,6 @@ function EventManager:CLEUHandler(timestamp, subevent, ...) end end -return EventManager +Bastion.Globals.EventManager = EventManager:New() + +Bastion.EventManager = EventManager diff --git a/src/Item/Item.lua b/src/Item/Item.lua index 96df453..baad0ed 100644 --- a/src/Item/Item.lua +++ b/src/Item/Item.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.Item.Traits.Use ---@field moving? boolean @@ -242,6 +244,9 @@ end ---@param condition? string | fun(self:Bastion.Item):boolean ---@return boolean function Item:Use(unit, condition) + if not self:Usable() then + return false + end if condition then if type(condition) == "string" and not self:EvaluateCondition(condition) then return false @@ -250,10 +255,6 @@ function Item:Use(unit, condition) end end - if not self:Usable() then - return false - end - -- Call pre Use function if self:GetPreUseFunction() then self:GetPreUseFunction()(self) @@ -582,4 +583,4 @@ function Item:GetSpell() return nil end -return Item +Bastion.Item = Item diff --git a/src/ItemBook/ItemBook.lua b/src/ItemBook/ItemBook.lua index fa1e75a..5c821f3 100644 --- a/src/ItemBook/ItemBook.lua +++ b/src/ItemBook/ItemBook.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@alias itemId integer @@ -35,4 +37,5 @@ function ItemBook:GetItem(id) return self.items[id] end -return ItemBook +Bastion.Globals.ItemBook = ItemBook:New() +Bastion.ItemBook = ItemBook diff --git a/src/Library/Library.lua b/src/Library/Library.lua index eacfc7a..0d6a506 100644 --- a/src/Library/Library.lua +++ b/src/Library/Library.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.Library ---@field name string | nil @@ -117,4 +119,4 @@ function Library:Import(library) return lib:Resolve() end -return Library +Bastion.Library = Library diff --git a/src/List/List.lua b/src/List/List.lua index 289686f..f0455e9 100644 --- a/src/List/List.lua +++ b/src/List/List.lua @@ -1,3 +1,8 @@ +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... + ---@class Bastion.List: { _list: I[] } ---@operator add(any): Bastion.List ---@operator sub(any): Bastion.List @@ -216,4 +221,4 @@ function List:__tostring() return self:toString() end -return List +Bastion.List = List diff --git a/src/Module/Module.lua b/src/Module/Module.lua index 4be4cb6..b081a18 100644 --- a/src/Module/Module.lua +++ b/src/Module/Module.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a module class for a bastion module @@ -37,11 +39,13 @@ end -- Enable the module function Module:Enable() self.enabled = true + return self end -- Disable the module function Module:Disable() self.enabled = false + return self end -- Toggle the module @@ -52,12 +56,14 @@ function Module:Toggle() else self:Enable() end + return self end -- Add a function to the sync list ---@param func function function Module:Sync(func) table.insert(self.synced, func) + return self end -- Remove a function from the sync list @@ -69,6 +75,7 @@ function Module:Unsync(func) break end end + return self end -- Sync @@ -81,6 +88,7 @@ function Module:Tick() end end end + return self end -return Module +Bastion.Module = Module diff --git a/src/MythicPlusUtils/MythicPlusUtils.lua b/src/MythicPlusUtils/MythicPlusUtils.lua index 9ae0466..67b2005 100644 --- a/src/MythicPlusUtils/MythicPlusUtils.lua +++ b/src/MythicPlusUtils/MythicPlusUtils.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.MythicPlusUtils.KickEntry ---@field isKick boolean @@ -1334,4 +1336,4 @@ function MythicPlusUtils:IsAOEBoss(unit) return self.aoeBosses[unit:GetID()] end -return MythicPlusUtils +Bastion.MythicPlusUtils = MythicPlusUtils:New() diff --git a/src/Notification/Notification.lua b/src/Notification/Notification.lua index 905fb07..c67e35a 100644 --- a/src/Notification/Notification.lua +++ b/src/Notification/Notification.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a notification class for the notifications list (takes icon and text) ---@class Bastion.Notification @@ -66,4 +68,4 @@ function Notification:Remove() end) end -return Notification +Bastion.Notification = Notification diff --git a/src/NotificationList/NotificationList.lua b/src/NotificationList/NotificationList.lua index 97b2b88..cb09dcb 100644 --- a/src/NotificationList/NotificationList.lua +++ b/src/NotificationList/NotificationList.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a NotificationList class @@ -88,5 +90,4 @@ function NotificationList:RemoveAllNotifications() end end --- Remove all notifications -return NotificationList +Bastion.NotificationList = NotificationList diff --git a/src/ObjectManager/ObjectManager.lua b/src/ObjectManager/ObjectManager.lua index 88b34cf..b7b3113 100644 --- a/src/ObjectManager/ObjectManager.lua +++ b/src/ObjectManager/ObjectManager.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.ObjectManager ---@field _lists table @@ -126,24 +128,4 @@ function ObjectManager:Refresh() end end -return ObjectManager - --- -- Register a list of objects that are training dummies --- local dummies = Bastion.ObjectManager:RegisterList('dummies', function(object) --- if ObjectType(object) == 5 or ObjectType(object) == 6 then --- local unit = Bastion.UnitManager:GetObject(ObjectGUID(object)) - --- if not unit then --- unit = Bastion.Unit:New(object) --- Bastion.UnitManager:SetObject(unit) --- end - --- if unit:GetID() == 198594 then --- return unit --- end --- end --- end) - --- dummies:each(function(dummy) --- print(dummy:GetName()) --- end) +Bastion.ObjectManager = ObjectManager:New() diff --git a/src/Refreshable/Refreshable.lua b/src/Refreshable/Refreshable.lua index 60f1bea..43dbe34 100644 --- a/src/Refreshable/Refreshable.lua +++ b/src/Refreshable/Refreshable.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Define a Refreshable class ---@class Bastion.Refreshable @@ -73,4 +75,4 @@ function Refreshable:SetCallback(cb) self.callback = cb end -return Refreshable +Bastion.Refreshable = Refreshable diff --git a/src/Sequencer/Sequencer.lua b/src/Sequencer/Sequencer.lua index 6b1495b..7083586 100644 --- a/src/Sequencer/Sequencer.lua +++ b/src/Sequencer/Sequencer.lua @@ -1,3 +1,8 @@ +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... + -- Create a sequencer class that takes a table of actions and executes them in order ---@class Bastion.Sequencer ---@field resetCondition? fun(): boolean @@ -87,4 +92,4 @@ function Sequencer:__tostring() return "Bastion.__Sequencer" end -return Sequencer +Bastion.Sequencer = Sequencer diff --git a/src/Spell/Spell.lua b/src/Spell/Spell.lua index 361ba79..91e74f2 100644 --- a/src/Spell/Spell.lua +++ b/src/Spell/Spell.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... ---@class Bastion.Spell.Traits.Cast ---@field moving boolean @@ -800,4 +802,4 @@ function Spell:UpdateAura(spell, source, target) self.auras[spell:GetID()].lastApplied = GetTime() end -return Spell +Bastion.Spell = Spell diff --git a/src/SpellBook/SpellBook.lua b/src/SpellBook/SpellBook.lua index 695063a..8fad902 100644 --- a/src/SpellBook/SpellBook.lua +++ b/src/SpellBook/SpellBook.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a new SpellBook class ---@class Bastion.SpellBook @@ -99,4 +101,5 @@ function SpellBook:GetIfRegistered(id) return false end -return SpellBook +Bastion.Globals.SpellBook = SpellBook:New() +Bastion.SpellBook = SpellBook diff --git a/src/TimeToDie/TimeToDie.lua b/src/TimeToDie/TimeToDie.lua index e00e786..7439810 100644 --- a/src/TimeToDie/TimeToDie.lua +++ b/src/TimeToDie/TimeToDie.lua @@ -1,7 +1,8 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -local Player = Bastion.UnitManager:Get("player") local Target = Bastion.UnitManager:Get("target") if not Bastion.Globals.UnitInfo then @@ -22,8 +23,6 @@ local TimeToDie = { }, ---@type table Cache = {}, -- A cache of unused { time, value } tables to reduce garbage due to table creation - --@type table - --Units = {}, -- Used to track units, ---@type table, time: number }> Units = {}, ---@type table @@ -56,7 +55,7 @@ function TimeToDie:Refresh() local historyCount = TimeToDie.Settings.HistoryCount local historyTime = TimeToDie.Settings.HistoryTime local ttdCache = TimeToDie.Cache - local iterableUnits = Bastion.ObjectManager.enemies + local iterableUnits = TimeToDie:IterableUnits() local units = TimeToDie.Units local existingUnits = TimeToDie.ExistingUnits @@ -75,7 +74,8 @@ function TimeToDie:Refresh() --local unitTable = units[unitGUID] local unitTable = units[unitGUID] -- Check if we have seen one time this unit, if we don't then initialize it. - if not unitTable or healthPercentage > unitTable.history[1].percentage then + -- Also check to see if the unit's health percentage is higher than the last one we saw. If so, we recreate the table. + if not unitTable or #unitTable.history > 0 and healthPercentage > unitTable.history[1].percentage then unitTable = { history = { { time = currentTime, percentage = healthPercentage } @@ -298,7 +298,7 @@ function TimeToDie.FilteredFightRemains(enemies, operator, value, checkIfValid, return false end - return Bastion.Utils.CompareThis(operator, fightRemains, value) or false + return Bastion.Util:CompareThis(operator, fightRemains, value) or false end -- Returns if the current boss fight length meets the requirements, 11111 if not a boss fight. @@ -309,4 +309,4 @@ function TimeToDie.BossFilteredFightRemains(operator, value, checkIfValid) return TimeToDie.FilteredFightRemains(nil, operator, value, checkIfValid, true) end -return TimeToDie +Bastion.TimeToDie = TimeToDie diff --git a/src/Timer/Timer.lua b/src/Timer/Timer.lua index f2bd5f1..336a670 100644 --- a/src/Timer/Timer.lua +++ b/src/Timer/Timer.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a new Timer class ---@class Bastion.Timer @@ -47,4 +49,4 @@ function Timer:Reset() self.startTime = nil end -return Timer +Bastion.Timer = Timer diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index a3c0042..661321a 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... -- Create a new Unit class ---@class Bastion.Unit @@ -25,7 +27,7 @@ function Unit:UpdateHealth() table.remove(self.health, 1) end table.insert(self.health, { - time = Bastion.Now, + time = GetTime(), percent = self:GetHP(), health = self:GetHealth(), maxHealth = @@ -907,7 +909,7 @@ function Unit:PredictHealth(time) table.remove(self.regression_history, 1) end - table.insert(self.regression_history, { time = Bastion.Now, percent = self:GetHP() }) + table.insert(self.regression_history, { time = GetTime(), percent = self:GetHP() }) for i = 1, #self.regression_history do local entry = self.regression_history[i] @@ -916,7 +918,7 @@ function Unit:PredictHealth(time) end local slope, intercept = self:LinearRegression(x, y) - return slope * (Bastion.Now + time) + intercept + return slope * (GetTime() + time) + intercept end -- Use linear regression to guess the time until a given health percent @@ -930,7 +932,7 @@ function Unit:PredictTime(percent) table.remove(self.regression_history, 1) end - table.insert(self.regression_history, { time = Bastion.Now, percent = self:GetHP() }) + table.insert(self.regression_history, { time = GetTime(), percent = self:GetHP() }) for i = 1, #self.regression_history do local entry = self.regression_history[i] @@ -1580,7 +1582,7 @@ end function Unit:FilteredTimeToDie(operator, value, offset, valueThreshold, minSamples) local TTD = self:TimeToDie2(minSamples) - return TTD > -1 and TTD < valueThreshold and Bastion.Utils.CompareThis(operator, TTD + (offset or 0), value) or false + return TTD > -1 and TTD < valueThreshold and Bastion.Util:CompareThis(operator, TTD + (offset or 0), value) or false end -- Get if the boss unit meets the TimeToDie requirements. @@ -1616,4 +1618,4 @@ function Unit:BossTimeToDieIsNotValid(minSamples) return true end -return Unit +Bastion.Unit = Unit diff --git a/src/UnitManager/UnitManager.lua b/src/UnitManager/UnitManager.lua index 9462923..a30acff 100644 --- a/src/UnitManager/UnitManager.lua +++ b/src/UnitManager/UnitManager.lua @@ -1,5 +1,7 @@ ----@type Tinkr, Bastion -local Tinkr, Bastion = ... +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... local Unit = Bastion.Unit @@ -362,4 +364,4 @@ function UnitManager:FindEnemiesCentroid(radius, range) return centroid end -return UnitManager +Bastion.UnitManager = UnitManager:New() diff --git a/src/Util/Util.lua b/src/Util/Util.lua new file mode 100644 index 0000000..841f181 --- /dev/null +++ b/src/Util/Util.lua @@ -0,0 +1,28 @@ +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... + +---@class Bastion.Util +local Util = {} + + +---@enum (key) CompareThisTable +local compareThisTable = { + [">"] = function(A, B) return A > B end, + ["<"] = function(A, B) return A < B end, + [">="] = function(A, B) return A >= B end, + ["<="] = function(A, B) return A <= B end, + ["=="] = function(A, B) return A == B end, + ["min"] = function(A, B) return A < B end, + ["max"] = function(A, B) return A > B end, +} + +---@generic A +---@param operator CompareThisTable +---@param a A +---@param b A +function Util:CompareThis(operator, a, b) +end + +Bastion.Util = Util diff --git a/src/Vector3/Vector3.lua b/src/Vector3/Vector3.lua index 8c12145..98cf291 100644 --- a/src/Vector3/Vector3.lua +++ b/src/Vector3/Vector3.lua @@ -1,5 +1,9 @@ --- Create a Vector3 class +---@type Tinkr +local Tinkr, +---@class Bastion +Bastion = ... +-- Create a Vector3 class ---@class Bastion.Vector3 ---@field length number ---@field normalized Bastion.Vector3 @@ -363,4 +367,4 @@ function Vector3:NormalizeOrientation(o) return math.fmod(o, 2.0 * math.pi) end -return Vector3 +Bastion.Vector3 = Vector3 diff --git a/src/_bastion.lua b/src/_bastion.lua index ef89444..49b6e24 100644 --- a/src/_bastion.lua +++ b/src/_bastion.lua @@ -4,6 +4,7 @@ local Tinkr = ... ---@class Bastion local Bastion = { DebugMode = false, + Globals = {}, } local TinkrScriptsBase = "scripts" @@ -59,7 +60,7 @@ end --- 0 = Failed, 1 = Success, 2 = Already Loaded ---@param filePath string | { filePath: string, reloadable: boolean } ---@param ... any ----@return 0|1|2, ... +---@return 0|1|2, table function Bastion:Require(filePath, ...) local loadedFile = { originalPath = type(filePath) == "table" and filePath.filePath or tostring(filePath), @@ -70,19 +71,12 @@ function Bastion:Require(filePath, ...) } local filePathModifier = loadedFile.originalPath:sub(1, 1) - - if filePathModifier == "@" then - -- If require starts with an @ then we require from the scripts/bastion/scripts folder - loadedFile.newPath = string.format("%s%s", BastionScriptsBase, loadedFile.originalPath:sub(2)) - loadedFile.loadedPath = loadedFile.newPath - elseif filePathModifier == "~" then - -- If file path starts with a ~ then we require from the scripts/bastion folder - loadedFile.newPath = string.format("%s%s", BastionBase, loadedFile.originalPath:sub(2)) + local base = filePathModifier == "@" and BastionScriptsBase or filePathModifier == "~" and BastionBase + if base then + loadedFile.newPath = string.format("%s%s", base, loadedFile.originalPath:sub(2)) loadedFile.loadedPath = loadedFile.newPath end - loadedFile.loadedPath = loadedFile.newPath - local found = false -- Check if file path has a .lua or .luac extension. If not, try to add one and check if the file exists loadedFile.loadedPath, found = CheckFileExtensions(loadedFile.newPath, { "lua", "luac" }) @@ -152,57 +146,46 @@ local function LoadThird() end end ----@generic V : string ----@param class `V` ----@return V ... -function Bastion.require(class) - ---@cast class string - local newClass = class:gsub("Bastion%.", "") - -- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) - local success, result = Bastion:Require("~/src/" .. newClass .. "/" .. newClass) - if success == 0 then - Log("Bastion.require - Failed to load " .. class .. ": " .. result) - end - return SafeUnpack(result) +local bastionFiles = { + "~/src/ClassMagic/ClassMagic", + "~/src/List/List", + "~/src/Util/Util", + "~/src/Library/Library", + "~/src/Notification/Notification", + "~/src/NotificationList/NotificationList", + "~/src/Vector3/Vector3", + "~/src/Sequencer/Sequencer", + "~/src/Command/Command", + "~/src/Cache/Cache", + "~/src/Cacheable/Cacheable", + "~/src/Refreshable/Refreshable", + "~/src/Unit/Unit", + "~/src/Aura/Aura", + "~/src/APLTrait/APLTrait", + "~/src/APLActor/APLActor", + "~/src/APL/APL", + "~/src/Module/Module", + "~/src/UnitManager/UnitManager", + "~/src/ObjectManager/ObjectManager", + "~/src/EventManager/EventManager", + "~/src/Spell/Spell", + "~/src/SpellBook/SpellBook", + "~/src/Item/Item", + "~/src/ItemBook/ItemBook", + "~/src/AuraTable/AuraTable", + "~/src/Class/Class", + "~/src/Timer/Timer", + "~/src/MythicPlusUtils/MythicPlusUtils", + "~/src/Config/Config", + "~/src/TimeToDie/TimeToDie", +} + +for i = 1, #bastionFiles do + Bastion:Require(bastionFiles[i]) end -Bastion.Globals = {} - -Bastion.ClassMagic = Bastion.require("Bastion.ClassMagic") -Bastion.List = Bastion.require("Bastion.List") -Bastion.Library = Bastion.require("Bastion.Library") -Bastion.Notification = Bastion.require("Bastion.Notification") -Bastion.NotificationList = Bastion.require("Bastion.NotificationList") -Bastion.Vector3 = Bastion.require("Bastion.Vector3") -Bastion.Sequencer = Bastion.require("Bastion.Sequencer") -Bastion.Command = Bastion.require("Bastion.Command") -Bastion.Cache = Bastion.require("Bastion.Cache") -Bastion.Cacheable = Bastion.require("Bastion.Cacheable") -Bastion.Refreshable = Bastion.require("Bastion.Refreshable") -Bastion.Unit = Bastion.require("Bastion.Unit") -Bastion.Aura = Bastion.require("Bastion.Aura") -Bastion.APLTrait = Bastion.require("Bastion.APLTrait") -Bastion.APLActor = Bastion.require("Bastion.APLActor") -Bastion.APL = Bastion.require("Bastion.APL") -Bastion.Module = Bastion.require("Bastion.Module") -Bastion.UnitManager = Bastion.require("Bastion.UnitManager"):New() -Bastion.ObjectManager = Bastion.require("Bastion.ObjectManager"):New() -Bastion.EventManager = Bastion.require("Bastion.EventManager") -Bastion.Globals.EventManager = Bastion.EventManager:New() -Bastion.Spell = Bastion.require("Bastion.Spell") -Bastion.SpellBook = Bastion.require("Bastion.SpellBook") -Bastion.Globals.SpellBook = Bastion.SpellBook:New() -Bastion.Item = Bastion.require("Bastion.Item") -Bastion.ItemBook = Bastion.require("Bastion.ItemBook") -Bastion.Globals.ItemBook = Bastion.ItemBook:New() -Bastion.AuraTable = Bastion.require("Bastion.AuraTable") -Bastion.Class = Bastion.require("Bastion.Class") -Bastion.Timer = Bastion.require("Bastion.Timer") -Bastion.CombatTimer = Bastion.Timer:New("combat") -Bastion.MythicPlusUtils = Bastion.require("Bastion.MythicPlusUtils"):New() -Bastion.Notifications = Bastion.NotificationList:New() -Bastion.Config = Bastion.require("Bastion.Config") -Bastion.TimeToDie = Bastion.require("Bastion.TimeToDie") +Bastion.Globals.CombatTimer = Bastion.Timer:New("combat") +Bastion.Globals.Notifications = Bastion.NotificationList:New() ---@param unitTarget UnitId Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_HEALTH", function(unitTarget) @@ -210,27 +193,6 @@ Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_HEALTH", function(unitTarget end) ----@enum (key) CompareThisTable -local compareThisTable = { - [">"] = function(A, B) return A > B end, - ["<"] = function(A, B) return A < B end, - [">="] = function(A, B) return A >= B end, - ["<="] = function(A, B) return A <= B end, - ["=="] = function(A, B) return A == B end, - ["min"] = function(A, B) return A < B end, - ["max"] = function(A, B) return A > B end, -} - -Bastion.Utils = { - ---@generic A - ---@param operator CompareThisTable - ---@param a A - ---@param b A - CompareThis = function(operator, a, b) - return compareThisTable[operator](a, b) - end -} - ---@type table local LIBRARIES = {} @@ -290,17 +252,6 @@ Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", fun end end - - -- if sourceGUID == pguid then - -- local args = { CombatLogGetCurrentEventInfo() } - - -- for i = 1, #args do - -- Log(tostring(args[i])) - -- end - -- end - --Bastion.UnitManager:SetCombatTime(sourceGUID) - --Bastion.UnitManager:SetCombatTime(destGUID) - local u = Bastion.UnitManager[sourceGUID] local u2 = Bastion.UnitManager[destGUID] @@ -339,10 +290,10 @@ Bastion.Ticker = C_Timer.NewTicker(0.1, function() Bastion.Now = GetTime() Bastion.Tick = GetGameTick() - if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then - Bastion.CombatTimer:Start() - elseif Bastion.CombatTimer:IsRunning() and not UnitAffectingCombat("player") then - Bastion.CombatTimer:Reset() + if not Bastion.Globals.CombatTimer:IsRunning() and UnitAffectingCombat("player") then + Bastion.Globals.CombatTimer:Start() + elseif Bastion.Globals.CombatTimer:IsRunning() and not UnitAffectingCombat("player") then + Bastion.Globals.CombatTimer:Reset() end if Bastion.Enabled then