Clean up TTD and Change Loading.

main
ck 11 months ago
parent 904d20f09c
commit 3f0bc7cb4c
  1. 8
      src/APL/APL.lua
  2. 8
      src/APLActor/APLActor.lua
  3. 8
      src/APLTrait/APLTrait.lua
  4. 9
      src/Aura/Aura.lua
  5. 8
      src/AuraTable/AuraTable.lua
  6. 7
      src/Cache/Cache.lua
  7. 8
      src/Cacheable/Cacheable.lua
  8. 8
      src/Class/Class.lua
  9. 7
      src/ClassMagic/ClassMagic.lua
  10. 7
      src/Command/Command.lua
  11. 8
      src/Config/Config.lua
  12. 10
      src/EventManager/EventManager.lua
  13. 15
      src/Item/Item.lua
  14. 9
      src/ItemBook/ItemBook.lua
  15. 8
      src/Library/Library.lua
  16. 7
      src/List/List.lua
  17. 14
      src/Module/Module.lua
  18. 8
      src/MythicPlusUtils/MythicPlusUtils.lua
  19. 8
      src/Notification/Notification.lua
  20. 9
      src/NotificationList/NotificationList.lua
  21. 28
      src/ObjectManager/ObjectManager.lua
  22. 8
      src/Refreshable/Refreshable.lua
  23. 7
      src/Sequencer/Sequencer.lua
  24. 8
      src/Spell/Spell.lua
  25. 9
      src/SpellBook/SpellBook.lua
  26. 18
      src/TimeToDie/TimeToDie.lua
  27. 8
      src/Timer/Timer.lua
  28. 18
      src/Unit/Unit.lua
  29. 8
      src/UnitManager/UnitManager.lua
  30. 28
      src/Util/Util.lua
  31. 8
      src/Vector3/Vector3.lua
  32. 147
      src/_bastion.lua

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- APL (Attack priority list) class -- APL (Attack priority list) class
---@class Bastion.APL ---@class Bastion.APL
@ -220,4 +222,4 @@ function APL:__tostring()
return "Bastion.__APL(" .. self.name .. ")" return "Bastion.__APL(" .. self.name .. ")"
end end
return APL Bastion.APL = APL

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.APLActor.Table.Base ---@class Bastion.APLActor.Table.Base
---@field type "spell" | "item" | "apl" | "sequencer" | "variable" | "action" ---@field type "spell" | "item" | "apl" | "sequencer" | "variable" | "action"
@ -131,4 +133,4 @@ function APLActor:__tostring()
return string.format("Bastion.__APLActor(%s)", self.name) return string.format("Bastion.__APLActor(%s)", self.name)
end end
return APLActor Bastion.APLActor = APLActor

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create an APL trait for the APL class -- Create an APL trait for the APL class
---@class Bastion.APLTrait ---@class Bastion.APLTrait
@ -39,4 +41,4 @@ function APLTrait:__tostring()
return "Bastion.__APLTrait" return "Bastion.__APLTrait"
end end
return APLTrait Bastion.APLTrait = APLTrait

@ -1,6 +1,7 @@
-- Document with emmy lua: https://emmylua.github.io/ ---@type Tinkr
---@type Tinkr, Bastion local Tinkr,
local Tinkr, Bastion = ... ---@class Bastion
Bastion = ...
---@class Bastion.Aura.Aura.Data ---@class Bastion.Aura.Aura.Data
---@field auraInstanceID? number ---@field auraInstanceID? number
@ -399,4 +400,4 @@ function Aura:IsDispelableBySpell(spell)
return false return false
end end
return Aura Bastion.Aura = Aura

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@alias auraInstanceId integer ---@alias auraInstanceId integer
@ -815,4 +817,4 @@ function AuraTable:HasAnyFoodOrDrinkAura()
return false return false
end end
return AuraTable Bastion.AuraTable = AuraTable

@ -1,3 +1,8 @@
---@type Tinkr
local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.Cache ---@class Bastion.Cache
local Cache = {} local Cache = {}
Cache.__index = Cache Cache.__index = Cache
@ -52,4 +57,4 @@ function Cache:IsCached(key)
return false return false
end end
return Cache Bastion.Cache = Cache

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.Cacheable ---@class Bastion.Cacheable
@ -84,4 +86,4 @@ function Cacheable:SetCallback(cb, ...)
self.args = SafePack(...) self.args = SafePack(...)
end end
return Cacheable Bastion.Cacheable = Cacheable

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a new Class class -- Create a new Class class
---@class Bastion.Class ---@class Bastion.Class
@ -64,4 +66,4 @@ function Class:GetColor()
return C_ClassColor.GetClassColor(self.class.name) return C_ClassColor.GetClassColor(self.class.name)
end end
return Class Bastion.Class = Class

@ -1,3 +1,8 @@
---@type Tinkr
local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.ClassMagic ---@class Bastion.ClassMagic
local ClassMagic = {} local ClassMagic = {}
ClassMagic.__index = ClassMagic ClassMagic.__index = ClassMagic
@ -49,4 +54,4 @@ function ClassMagic:Resolve(Class, key)
return Class[key] return Class[key]
end end
return ClassMagic Bastion.ClassMagic = ClassMagic

@ -1,3 +1,8 @@
---@type Tinkr
local Tinkr,
---@class Bastion
Bastion = ...
-- Create a wow command handler class -- Create a wow command handler class
---@class Bastion.Command ---@class Bastion.Command
---@field command string ---@field command string
@ -76,4 +81,4 @@ function Command:PrintHelp()
end end
end end
return Command Bastion.Command = Command

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.Config ---@class Bastion.Config
---@field instantiated boolean ---@field instantiated boolean
@ -79,4 +81,4 @@ function Config:Sync(key)
self.config:Sync(key) self.config:Sync(key)
end end
return Config Bastion.Config = Config

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create an EventManager class -- Create an EventManager class
---@class Bastion.EventManager ---@class Bastion.EventManager
@ -136,4 +138,6 @@ function EventManager:CLEUHandler(timestamp, subevent, ...)
end end
end end
return EventManager Bastion.Globals.EventManager = EventManager:New()
Bastion.EventManager = EventManager

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.Item.Traits.Use ---@class Bastion.Item.Traits.Use
---@field moving? boolean ---@field moving? boolean
@ -242,6 +244,9 @@ end
---@param condition? string | fun(self:Bastion.Item):boolean ---@param condition? string | fun(self:Bastion.Item):boolean
---@return boolean ---@return boolean
function Item:Use(unit, condition) function Item:Use(unit, condition)
if not self:Usable() then
return false
end
if condition then if condition then
if type(condition) == "string" and not self:EvaluateCondition(condition) then if type(condition) == "string" and not self:EvaluateCondition(condition) then
return false return false
@ -250,10 +255,6 @@ function Item:Use(unit, condition)
end end
end end
if not self:Usable() then
return false
end
-- Call pre Use function -- Call pre Use function
if self:GetPreUseFunction() then if self:GetPreUseFunction() then
self:GetPreUseFunction()(self) self:GetPreUseFunction()(self)
@ -582,4 +583,4 @@ function Item:GetSpell()
return nil return nil
end end
return Item Bastion.Item = Item

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@alias itemId integer ---@alias itemId integer
@ -35,4 +37,5 @@ function ItemBook:GetItem(id)
return self.items[id] return self.items[id]
end end
return ItemBook Bastion.Globals.ItemBook = ItemBook:New()
Bastion.ItemBook = ItemBook

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.Library ---@class Bastion.Library
---@field name string | nil ---@field name string | nil
@ -117,4 +119,4 @@ function Library:Import(library)
return lib:Resolve() return lib:Resolve()
end end
return Library Bastion.Library = Library

@ -1,3 +1,8 @@
---@type Tinkr
local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.List<I>: { _list: I[] } ---@class Bastion.List<I>: { _list: I[] }
---@operator add(any): Bastion.List ---@operator add(any): Bastion.List
---@operator sub(any): Bastion.List ---@operator sub(any): Bastion.List
@ -216,4 +221,4 @@ function List:__tostring()
return self:toString() return self:toString()
end end
return List Bastion.List = List

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a module class for a bastion module -- Create a module class for a bastion module
@ -37,11 +39,13 @@ end
-- Enable the module -- Enable the module
function Module:Enable() function Module:Enable()
self.enabled = true self.enabled = true
return self
end end
-- Disable the module -- Disable the module
function Module:Disable() function Module:Disable()
self.enabled = false self.enabled = false
return self
end end
-- Toggle the module -- Toggle the module
@ -52,12 +56,14 @@ function Module:Toggle()
else else
self:Enable() self:Enable()
end end
return self
end end
-- Add a function to the sync list -- Add a function to the sync list
---@param func function ---@param func function
function Module:Sync(func) function Module:Sync(func)
table.insert(self.synced, func) table.insert(self.synced, func)
return self
end end
-- Remove a function from the sync list -- Remove a function from the sync list
@ -69,6 +75,7 @@ function Module:Unsync(func)
break break
end end
end end
return self
end end
-- Sync -- Sync
@ -81,6 +88,7 @@ function Module:Tick()
end end
end end
end end
return self
end end
return Module Bastion.Module = Module

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.MythicPlusUtils.KickEntry ---@class Bastion.MythicPlusUtils.KickEntry
---@field isKick boolean ---@field isKick boolean
@ -1334,4 +1336,4 @@ function MythicPlusUtils:IsAOEBoss(unit)
return self.aoeBosses[unit:GetID()] return self.aoeBosses[unit:GetID()]
end end
return MythicPlusUtils Bastion.MythicPlusUtils = MythicPlusUtils:New()

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a notification class for the notifications list (takes icon and text) -- Create a notification class for the notifications list (takes icon and text)
---@class Bastion.Notification ---@class Bastion.Notification
@ -66,4 +68,4 @@ function Notification:Remove()
end) end)
end end
return Notification Bastion.Notification = Notification

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a NotificationList class -- Create a NotificationList class
@ -88,5 +90,4 @@ function NotificationList:RemoveAllNotifications()
end end
end end
-- Remove all notifications Bastion.NotificationList = NotificationList
return NotificationList

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.ObjectManager ---@class Bastion.ObjectManager
---@field _lists table<string, { list: Bastion.List, cb: fun(object: TinkrObjectReference): false | Bastion.Unit }> ---@field _lists table<string, { list: Bastion.List, cb: fun(object: TinkrObjectReference): false | Bastion.Unit }>
@ -126,24 +128,4 @@ function ObjectManager:Refresh()
end end
end end
return ObjectManager Bastion.ObjectManager = ObjectManager:New()
-- -- 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)

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Define a Refreshable class -- Define a Refreshable class
---@class Bastion.Refreshable ---@class Bastion.Refreshable
@ -73,4 +75,4 @@ function Refreshable:SetCallback(cb)
self.callback = cb self.callback = cb
end end
return Refreshable Bastion.Refreshable = Refreshable

@ -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 -- Create a sequencer class that takes a table of actions and executes them in order
---@class Bastion.Sequencer ---@class Bastion.Sequencer
---@field resetCondition? fun(): boolean ---@field resetCondition? fun(): boolean
@ -87,4 +92,4 @@ function Sequencer:__tostring()
return "Bastion.__Sequencer" return "Bastion.__Sequencer"
end end
return Sequencer Bastion.Sequencer = Sequencer

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
---@class Bastion.Spell.Traits.Cast ---@class Bastion.Spell.Traits.Cast
---@field moving boolean ---@field moving boolean
@ -800,4 +802,4 @@ function Spell:UpdateAura(spell, source, target)
self.auras[spell:GetID()].lastApplied = GetTime() self.auras[spell:GetID()].lastApplied = GetTime()
end end
return Spell Bastion.Spell = Spell

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a new SpellBook class -- Create a new SpellBook class
---@class Bastion.SpellBook ---@class Bastion.SpellBook
@ -99,4 +101,5 @@ function SpellBook:GetIfRegistered(id)
return false return false
end end
return SpellBook Bastion.Globals.SpellBook = SpellBook:New()
Bastion.SpellBook = SpellBook

@ -1,7 +1,8 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
local Player = Bastion.UnitManager:Get("player")
local Target = Bastion.UnitManager:Get("target") local Target = Bastion.UnitManager:Get("target")
if not Bastion.Globals.UnitInfo then if not Bastion.Globals.UnitInfo then
@ -22,8 +23,6 @@ local TimeToDie = {
}, },
---@type table<number, { time: number, percentage: number }> ---@type table<number, { time: number, percentage: number }>
Cache = {}, -- A cache of unused { time, value } tables to reduce garbage due to table creation Cache = {}, -- A cache of unused { time, value } tables to reduce garbage due to table creation
--@type table<string, {[1]: {[1]: {[1]: number, [2]: number}, [2]: number}, [2]: number }>
--Units = {}, -- Used to track units,
---@type table<string, { history: table<number, { time: number, percentage: number }>, time: number }> ---@type table<string, { history: table<number, { time: number, percentage: number }>, time: number }>
Units = {}, Units = {},
---@type table<string, boolean> ---@type table<string, boolean>
@ -56,7 +55,7 @@ function TimeToDie:Refresh()
local historyCount = TimeToDie.Settings.HistoryCount local historyCount = TimeToDie.Settings.HistoryCount
local historyTime = TimeToDie.Settings.HistoryTime local historyTime = TimeToDie.Settings.HistoryTime
local ttdCache = TimeToDie.Cache local ttdCache = TimeToDie.Cache
local iterableUnits = Bastion.ObjectManager.enemies local iterableUnits = TimeToDie:IterableUnits()
local units = TimeToDie.Units local units = TimeToDie.Units
local existingUnits = TimeToDie.ExistingUnits local existingUnits = TimeToDie.ExistingUnits
@ -75,7 +74,8 @@ function TimeToDie:Refresh()
--local unitTable = units[unitGUID] --local unitTable = units[unitGUID]
local unitTable = units[unitGUID] local unitTable = units[unitGUID]
-- Check if we have seen one time this unit, if we don't then initialize it. -- 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 = { unitTable = {
history = { history = {
{ time = currentTime, percentage = healthPercentage } { time = currentTime, percentage = healthPercentage }
@ -298,7 +298,7 @@ function TimeToDie.FilteredFightRemains(enemies, operator, value, checkIfValid,
return false return false
end end
return Bastion.Utils.CompareThis(operator, fightRemains, value) or false return Bastion.Util:CompareThis(operator, fightRemains, value) or false
end end
-- Returns if the current boss fight length meets the requirements, 11111 if not a boss fight. -- 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) return TimeToDie.FilteredFightRemains(nil, operator, value, checkIfValid, true)
end end
return TimeToDie Bastion.TimeToDie = TimeToDie

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a new Timer class -- Create a new Timer class
---@class Bastion.Timer ---@class Bastion.Timer
@ -47,4 +49,4 @@ function Timer:Reset()
self.startTime = nil self.startTime = nil
end end
return Timer Bastion.Timer = Timer

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
-- Create a new Unit class -- Create a new Unit class
---@class Bastion.Unit ---@class Bastion.Unit
@ -25,7 +27,7 @@ function Unit:UpdateHealth()
table.remove(self.health, 1) table.remove(self.health, 1)
end end
table.insert(self.health, { table.insert(self.health, {
time = Bastion.Now, time = GetTime(),
percent = self:GetHP(), percent = self:GetHP(),
health = self:GetHealth(), health = self:GetHealth(),
maxHealth = maxHealth =
@ -907,7 +909,7 @@ function Unit:PredictHealth(time)
table.remove(self.regression_history, 1) table.remove(self.regression_history, 1)
end 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 for i = 1, #self.regression_history do
local entry = self.regression_history[i] local entry = self.regression_history[i]
@ -916,7 +918,7 @@ function Unit:PredictHealth(time)
end end
local slope, intercept = self:LinearRegression(x, y) local slope, intercept = self:LinearRegression(x, y)
return slope * (Bastion.Now + time) + intercept return slope * (GetTime() + time) + intercept
end end
-- Use linear regression to guess the time until a given health percent -- 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) table.remove(self.regression_history, 1)
end 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 for i = 1, #self.regression_history do
local entry = self.regression_history[i] local entry = self.regression_history[i]
@ -1580,7 +1582,7 @@ end
function Unit:FilteredTimeToDie(operator, value, offset, valueThreshold, minSamples) function Unit:FilteredTimeToDie(operator, value, offset, valueThreshold, minSamples)
local TTD = self:TimeToDie2(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 end
-- Get if the boss unit meets the TimeToDie requirements. -- Get if the boss unit meets the TimeToDie requirements.
@ -1616,4 +1618,4 @@ function Unit:BossTimeToDieIsNotValid(minSamples)
return true return true
end end
return Unit Bastion.Unit = Unit

@ -1,5 +1,7 @@
---@type Tinkr, Bastion ---@type Tinkr
local Tinkr, Bastion = ... local Tinkr,
---@class Bastion
Bastion = ...
local Unit = Bastion.Unit local Unit = Bastion.Unit
@ -362,4 +364,4 @@ function UnitManager:FindEnemiesCentroid(radius, range)
return centroid return centroid
end end
return UnitManager Bastion.UnitManager = UnitManager:New()

@ -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

@ -1,5 +1,9 @@
-- Create a Vector3 class ---@type Tinkr
local Tinkr,
---@class Bastion
Bastion = ...
-- Create a Vector3 class
---@class Bastion.Vector3 ---@class Bastion.Vector3
---@field length number ---@field length number
---@field normalized Bastion.Vector3 ---@field normalized Bastion.Vector3
@ -363,4 +367,4 @@ function Vector3:NormalizeOrientation(o)
return math.fmod(o, 2.0 * math.pi) return math.fmod(o, 2.0 * math.pi)
end end
return Vector3 Bastion.Vector3 = Vector3

@ -4,6 +4,7 @@ local Tinkr = ...
---@class Bastion ---@class Bastion
local Bastion = { local Bastion = {
DebugMode = false, DebugMode = false,
Globals = {},
} }
local TinkrScriptsBase = "scripts" local TinkrScriptsBase = "scripts"
@ -59,7 +60,7 @@ end
--- 0 = Failed, 1 = Success, 2 = Already Loaded --- 0 = Failed, 1 = Success, 2 = Already Loaded
---@param filePath string | { filePath: string, reloadable: boolean } ---@param filePath string | { filePath: string, reloadable: boolean }
---@param ... any ---@param ... any
---@return 0|1|2, ... ---@return 0|1|2, table
function Bastion:Require(filePath, ...) function Bastion:Require(filePath, ...)
local loadedFile = { local loadedFile = {
originalPath = type(filePath) == "table" and filePath.filePath or tostring(filePath), 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) local filePathModifier = loadedFile.originalPath:sub(1, 1)
local base = filePathModifier == "@" and BastionScriptsBase or filePathModifier == "~" and BastionBase
if filePathModifier == "@" then if base then
-- If require starts with an @ then we require from the scripts/bastion/scripts folder loadedFile.newPath = string.format("%s%s", base, loadedFile.originalPath:sub(2))
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))
loadedFile.loadedPath = loadedFile.newPath loadedFile.loadedPath = loadedFile.newPath
end end
loadedFile.loadedPath = loadedFile.newPath
local found = false 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 -- 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" }) loadedFile.loadedPath, found = CheckFileExtensions(loadedFile.newPath, { "lua", "luac" })
@ -152,57 +146,46 @@ local function LoadThird()
end end
end end
---@generic V : string local bastionFiles = {
---@param class `V` "~/src/ClassMagic/ClassMagic",
---@return V ... "~/src/List/List",
function Bastion.require(class) "~/src/Util/Util",
---@cast class string "~/src/Library/Library",
local newClass = class:gsub("Bastion%.", "") "~/src/Notification/Notification",
-- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) "~/src/NotificationList/NotificationList",
local success, result = Bastion:Require("~/src/" .. newClass .. "/" .. newClass) "~/src/Vector3/Vector3",
if success == 0 then "~/src/Sequencer/Sequencer",
Log("Bastion.require - Failed to load " .. class .. ": " .. result) "~/src/Command/Command",
end "~/src/Cache/Cache",
return SafeUnpack(result) "~/src/Cacheable/Cacheable",
end "~/src/Refreshable/Refreshable",
"~/src/Unit/Unit",
Bastion.Globals = {} "~/src/Aura/Aura",
"~/src/APLTrait/APLTrait",
Bastion.ClassMagic = Bastion.require("Bastion.ClassMagic") "~/src/APLActor/APLActor",
Bastion.List = Bastion.require("Bastion.List") "~/src/APL/APL",
Bastion.Library = Bastion.require("Bastion.Library") "~/src/Module/Module",
Bastion.Notification = Bastion.require("Bastion.Notification") "~/src/UnitManager/UnitManager",
Bastion.NotificationList = Bastion.require("Bastion.NotificationList") "~/src/ObjectManager/ObjectManager",
Bastion.Vector3 = Bastion.require("Bastion.Vector3") "~/src/EventManager/EventManager",
Bastion.Sequencer = Bastion.require("Bastion.Sequencer") "~/src/Spell/Spell",
Bastion.Command = Bastion.require("Bastion.Command") "~/src/SpellBook/SpellBook",
Bastion.Cache = Bastion.require("Bastion.Cache") "~/src/Item/Item",
Bastion.Cacheable = Bastion.require("Bastion.Cacheable") "~/src/ItemBook/ItemBook",
Bastion.Refreshable = Bastion.require("Bastion.Refreshable") "~/src/AuraTable/AuraTable",
Bastion.Unit = Bastion.require("Bastion.Unit") "~/src/Class/Class",
Bastion.Aura = Bastion.require("Bastion.Aura") "~/src/Timer/Timer",
Bastion.APLTrait = Bastion.require("Bastion.APLTrait") "~/src/MythicPlusUtils/MythicPlusUtils",
Bastion.APLActor = Bastion.require("Bastion.APLActor") "~/src/Config/Config",
Bastion.APL = Bastion.require("Bastion.APL") "~/src/TimeToDie/TimeToDie",
Bastion.Module = Bastion.require("Bastion.Module") }
Bastion.UnitManager = Bastion.require("Bastion.UnitManager"):New()
Bastion.ObjectManager = Bastion.require("Bastion.ObjectManager"):New() for i = 1, #bastionFiles do
Bastion.EventManager = Bastion.require("Bastion.EventManager") Bastion:Require(bastionFiles[i])
Bastion.Globals.EventManager = Bastion.EventManager:New() end
Bastion.Spell = Bastion.require("Bastion.Spell")
Bastion.SpellBook = Bastion.require("Bastion.SpellBook") Bastion.Globals.CombatTimer = Bastion.Timer:New("combat")
Bastion.Globals.SpellBook = Bastion.SpellBook:New() Bastion.Globals.Notifications = Bastion.NotificationList: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")
---@param unitTarget UnitId ---@param unitTarget UnitId
Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_HEALTH", function(unitTarget) Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_HEALTH", function(unitTarget)
@ -210,27 +193,6 @@ Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_HEALTH", function(unitTarget
end) 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<string, Bastion.Library> ---@type table<string, Bastion.Library>
local LIBRARIES = {} local LIBRARIES = {}
@ -290,17 +252,6 @@ Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", fun
end end
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 u = Bastion.UnitManager[sourceGUID]
local u2 = Bastion.UnitManager[destGUID] local u2 = Bastion.UnitManager[destGUID]
@ -339,10 +290,10 @@ Bastion.Ticker = C_Timer.NewTicker(0.1, function()
Bastion.Now = GetTime() Bastion.Now = GetTime()
Bastion.Tick = GetGameTick() Bastion.Tick = GetGameTick()
if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then if not Bastion.Globals.CombatTimer:IsRunning() and UnitAffectingCombat("player") then
Bastion.CombatTimer:Start() Bastion.Globals.CombatTimer:Start()
elseif Bastion.CombatTimer:IsRunning() and not UnitAffectingCombat("player") then elseif Bastion.Globals.CombatTimer:IsRunning() and not UnitAffectingCombat("player") then
Bastion.CombatTimer:Reset() Bastion.Globals.CombatTimer:Reset()
end end
if Bastion.Enabled then if Bastion.Enabled then

Loading…
Cancel
Save