Add Bastion Libraries

main
4n0n 1 year ago
parent e3d52b41c4
commit 5f0affd907
  1. 4
      .gitignore
  2. 17
      scripts/ExampleModule.lua
  3. 14
      scripts/Libraries/ExampleLibrary.lua
  4. 50
      src/_bastion.lua

4
.gitignore vendored

@ -7,7 +7,11 @@ DS_Store
## ignore all files in scripts ## ignore all files in scripts
scripts/* scripts/*
!scripts/Libraries
scripts/Libraries/*
!scripts/.gitkeep !scripts/.gitkeep
!scripts/ExampleModule.lua
!scripts/Libraries/ExampleLibrary.lua
## ignore vscode settings ## ignore vscode settings
.vscode/* .vscode/*

@ -0,0 +1,17 @@
local Tinkr, Bastion = ...
local ExampleModule = Bastion.Module:New('ExampleModule')
local Player = Bastion.UnitManager:Get('player')
local FlashHeal = Bastion.SpellBook:GetSpell(2061)
local AdvancedMath = Bastion:GetLibrary('AdvancedMath')
print(AdvancedMath:Add(1, 2))
ExampleModule:Sync(function()
if Player:GetHP() <= 50 then
FlashHeal:Cast(Player)
end
end)
Bastion:Register(ExampleModule)

@ -0,0 +1,14 @@
local Tinkr, Bastion = ...
local ExampleModule = Bastion.Module:New('ExampleModule')
local Player = Bastion.UnitManager:Get('player')
local AdvancedMath = {}
AdvancedMath.__index = AdvancedMath
function AdvancedMath:Add(a, b)
return a + b
end
Bastion:RegisterLibrary('AdvancedMath', AdvancedMath)

@ -7,7 +7,7 @@ local Bastion = {
Bastion.__index = Bastion Bastion.__index = Bastion
function Bastion.require(class) function Bastion.require(class)
return Tinkr:require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion)
end end
---@type ClassMagic ---@type ClassMagic
@ -61,7 +61,8 @@ Bastion.CombatTimer = Bastion.Timer:New('combat')
Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New() Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New()
---@type NotificationsList ---@type NotificationsList
Bastion.Notifications = Bastion.NotificationsList:New() Bastion.Notifications = Bastion.NotificationsList:New()
Bastion.modules = {} local LIBRARIES = {}
local MODULES = {}
Bastion.Enabled = false Bastion.Enabled = false
Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras) Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras)
@ -89,7 +90,7 @@ end)
local pguid = UnitGUID("player") local pguid = UnitGUID("player")
local missed = {} local missed = {}
Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function() Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
local args = { CombatLogGetCurrentEventInfo() } local args = {CombatLogGetCurrentEventInfo()}
local subEvent = args[2] local subEvent = args[2]
local sourceGUID = args[4] local sourceGUID = args[4]
@ -131,6 +132,16 @@ Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
end end
end end
end) end)
function Bastion:RegisterLibrary(name, payload)
LIBRARIES[name] = payload
-- Bastion:Print("Registered Library", name)
end
function Bastion:GetLibrary(name)
return LIBRARIES[name]
end
Bastion.Ticker = C_Timer.NewTicker(0.1, function() Bastion.Ticker = C_Timer.NewTicker(0.1, function()
if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then
Bastion.CombatTimer:Start() Bastion.CombatTimer:Start()
@ -140,29 +151,29 @@ Bastion.Ticker = C_Timer.NewTicker(0.1, function()
if Bastion.Enabled then if Bastion.Enabled then
Bastion.ObjectManager:Refresh() Bastion.ObjectManager:Refresh()
for i = 1, #Bastion.modules do for i = 1, #MODULES do
Bastion.modules[i]:Tick() MODULES[i]:Tick()
end end
end end
end) end)
function Bastion:Register(module) function Bastion:Register(module)
table.insert(Bastion.modules, module) table.insert(MODULES, module)
Bastion:Print("Registered", module) Bastion:Print("Registered", module)
end end
-- Find a module by name -- Find a module by name
function Bastion:FindModule(name) function Bastion:FindModule(name)
for i = 1, #Bastion.modules do for i = 1, #MODULES do
if Bastion.modules[i].name == name then if MODULES[i].name == name then
return Bastion.modules[i] return MODULES[i]
end end
end end
return nil return nil
end end
function Bastion:Print(...) function Bastion:Print(...)
local args = { ... } local args = {...}
local str = "|cFFDF362D[Bastion]|r |cFFFFFFFF" local str = "|cFFDF362D[Bastion]|r |cFFFFFFFF"
for i = 1, #args do for i = 1, #args do
str = str .. tostring(args[i]) .. " " str = str .. tostring(args[i]) .. " "
@ -174,7 +185,7 @@ function Bastion:Debug(...)
if not Bastion.DebugMode then if not Bastion.DebugMode then
return return
end end
local args = { ... } local args = {...}
local str = "|cFFDF6520[Bastion]|r |cFFFFFFFF" local str = "|cFFDF6520[Bastion]|r |cFFFFFFFF"
for i = 1, #args do for i = 1, #args do
str = str .. tostring(args[i]) .. " " str = str .. tostring(args[i]) .. " "
@ -207,7 +218,9 @@ Command:Register('dumpspells', 'Dump spells to a file', function()
while true do while true do
local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL) local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
if not spellName then if not spellName then
do break end do
break
end
end end
-- use spellName and spellSubName here -- use spellName and spellSubName here
@ -261,14 +274,17 @@ Command:Register('missed', 'Dump the list of immune kidney shot spells', functio
end end
end) end)
local files = ListFiles("scripts/bastion/scripts") local function Load(dir)
local files = ListFiles(dir)
for i = 1, #files do for i = 1, #files do
local file = files[i] local file = files[i]
if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then
require(dir .. file:sub(1, -5), Bastion)
Tinkr:require("scripts/bastion/scripts/" .. file:sub(1, -5), Bastion) end
end end
end end
Load("scripts/bastion/scripts/Libraries/")
Load("scripts/bastion/scripts/Modules/")
Load("scripts/bastion/scripts/")

Loading…
Cancel
Save