Add Bastion Libraries

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

4
.gitignore vendored

@ -7,7 +7,11 @@ DS_Store
## ignore all files in scripts
scripts/*
!scripts/Libraries
scripts/Libraries/*
!scripts/.gitkeep
!scripts/ExampleModule.lua
!scripts/Libraries/ExampleLibrary.lua
## ignore vscode settings
.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
function Bastion.require(class)
return Tinkr:require("scripts/bastion/src/" .. class .. "/" .. class, Bastion)
return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion)
end
---@type ClassMagic
@ -61,7 +61,8 @@ Bastion.CombatTimer = Bastion.Timer:New('combat')
Bastion.MythicPlusUtils = Bastion.require("MythicPlusUtils"):New()
---@type NotificationsList
Bastion.Notifications = Bastion.NotificationsList:New()
Bastion.modules = {}
local LIBRARIES = {}
local MODULES = {}
Bastion.Enabled = false
Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras)
@ -131,6 +132,16 @@ Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
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()
if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then
Bastion.CombatTimer:Start()
@ -140,22 +151,22 @@ Bastion.Ticker = C_Timer.NewTicker(0.1, function()
if Bastion.Enabled then
Bastion.ObjectManager:Refresh()
for i = 1, #Bastion.modules do
Bastion.modules[i]:Tick()
for i = 1, #MODULES do
MODULES[i]:Tick()
end
end
end)
function Bastion:Register(module)
table.insert(Bastion.modules, module)
table.insert(MODULES, module)
Bastion:Print("Registered", module)
end
-- Find a module by name
function Bastion:FindModule(name)
for i = 1, #Bastion.modules do
if Bastion.modules[i].name == name then
return Bastion.modules[i]
for i = 1, #MODULES do
if MODULES[i].name == name then
return MODULES[i]
end
end
@ -207,7 +218,9 @@ Command:Register('dumpspells', 'Dump spells to a file', function()
while true do
local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL)
if not spellName then
do break end
do
break
end
end
-- use spellName and spellSubName here
@ -261,14 +274,17 @@ Command:Register('missed', 'Dump the list of immune kidney shot spells', functio
end
end)
local files = ListFiles("scripts/bastion/scripts")
local function Load(dir)
local files = ListFiles(dir)
for i = 1, #files do
local file = files[i]
if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then
Tinkr:require("scripts/bastion/scripts/" .. file:sub(1, -5), Bastion)
require(dir .. file:sub(1, -5), Bastion)
end
end
end
Load("scripts/bastion/scripts/Libraries/")
Load("scripts/bastion/scripts/Modules/")
Load("scripts/bastion/scripts/")

Loading…
Cancel
Save