forked from Bastion/Bastion
Compare commits
54 Commits
4n0n-patch
...
main
@ -0,0 +1,24 @@ |
|||||||
|
local Tinkr, Bastion = ... |
||||||
|
local ExampleModule = Bastion.Module:New('ExampleModule') |
||||||
|
local Player = Bastion.UnitManager:Get('player') |
||||||
|
|
||||||
|
-- Create a local spellbook |
||||||
|
local SpellBook = Bastion.SpellBook:New() |
||||||
|
|
||||||
|
local FlashHeal = SpellBook:GetSpell(2061) |
||||||
|
|
||||||
|
-- Get a global spell (this can collide with other modules, so be careful) |
||||||
|
-- This is useful for caching common spells that you might not actually cast, and to avoid needless spell creation inline |
||||||
|
local FlashHeal = Bastion.Globals.SpellBook:GetSpell(2061) |
||||||
|
|
||||||
|
local AdvancedMath = Bastion:Import('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,21 @@ |
|||||||
|
local Tinkr, Bastion = ... |
||||||
|
|
||||||
|
local Player = Bastion.UnitManager:Get('player') |
||||||
|
|
||||||
|
Bastion:RegisterLibrary(Bastion.Library:New({ |
||||||
|
name = 'Dependable', |
||||||
|
exports = { |
||||||
|
default = function() |
||||||
|
local Dependable = {} |
||||||
|
|
||||||
|
Dependable.__index = Dependable |
||||||
|
|
||||||
|
function Dependable:Test(a) |
||||||
|
print(a) |
||||||
|
end |
||||||
|
|
||||||
|
return Dependable |
||||||
|
end, |
||||||
|
Test = 5 |
||||||
|
} |
||||||
|
})) |
@ -0,0 +1,15 @@ |
|||||||
|
local Tinkr, Bastion = ... |
||||||
|
|
||||||
|
Bastion:RegisterLibrary(Bastion.Library:New({ |
||||||
|
name = 'Circular', |
||||||
|
exports = { |
||||||
|
default = function(self) |
||||||
|
-- Return default first, and then the remaining exports |
||||||
|
local Math, OtherExports = self:Import('AdvancedMath') |
||||||
|
|
||||||
|
print(Math:Add(1, 2)) |
||||||
|
|
||||||
|
return 'Circular' |
||||||
|
end |
||||||
|
} |
||||||
|
})) |
@ -0,0 +1,25 @@ |
|||||||
|
local Tinkr, Bastion = ... |
||||||
|
|
||||||
|
Bastion:RegisterLibrary(Bastion.Library:New({ |
||||||
|
name = 'AdvancedMath', |
||||||
|
exports = { |
||||||
|
default = function(self) -- Function exports are called when the library is loaded |
||||||
|
-- Return default first, and then the remaining exports |
||||||
|
local Dependable, OtherExports = self:Import('Dependable') |
||||||
|
|
||||||
|
local CircularDependency = self:Import('Circular') -- Causes a circular dependency error |
||||||
|
|
||||||
|
Dependable:Test(OtherExports.Test) |
||||||
|
|
||||||
|
local AdvancedMath = {} |
||||||
|
|
||||||
|
AdvancedMath.__index = AdvancedMath |
||||||
|
|
||||||
|
function AdvancedMath:Add(a, b) |
||||||
|
return a + b |
||||||
|
end |
||||||
|
|
||||||
|
return AdvancedMath |
||||||
|
end |
||||||
|
} |
||||||
|
})) |
@ -0,0 +1,115 @@ |
|||||||
|
local Tinkr, Bastion = ... |
||||||
|
|
||||||
|
---@class Library |
||||||
|
---@field name string |
||||||
|
---@field dependencies table |
||||||
|
---@field exports table |
||||||
|
---@field resolved table |
||||||
|
local Library = { |
||||||
|
name = nil, |
||||||
|
dependencies = {}, |
||||||
|
exports = { |
||||||
|
default = function() |
||||||
|
return nil |
||||||
|
end |
||||||
|
}, |
||||||
|
resolved = nil |
||||||
|
} |
||||||
|
|
||||||
|
Library.__index = Library |
||||||
|
|
||||||
|
---@param name string |
||||||
|
---@param library table |
||||||
|
---@return Library |
||||||
|
function Library:New(library) |
||||||
|
local self = { |
||||||
|
name = library.name or nil, |
||||||
|
dependencies = {}, |
||||||
|
exports = library.exports or { |
||||||
|
default = function() |
||||||
|
return nil |
||||||
|
end |
||||||
|
}, |
||||||
|
resolved = nil |
||||||
|
} |
||||||
|
|
||||||
|
self = setmetatable(self, Library) |
||||||
|
|
||||||
|
return self |
||||||
|
end |
||||||
|
|
||||||
|
function Library:ResolveExport(export) |
||||||
|
if type(export) == 'function' then |
||||||
|
return export(self) |
||||||
|
end |
||||||
|
|
||||||
|
return export |
||||||
|
end |
||||||
|
|
||||||
|
function Library:Resolve() |
||||||
|
if not self.exports then |
||||||
|
error("Library " .. self.name .. " has no exports") |
||||||
|
end |
||||||
|
|
||||||
|
if self.resolved then |
||||||
|
if self.exports.default then |
||||||
|
return self.resolved[1], self.resolved[2] |
||||||
|
end |
||||||
|
|
||||||
|
return unpack(self.resolved) |
||||||
|
end |
||||||
|
|
||||||
|
if self.exports.default then |
||||||
|
-- return default first if it exists |
||||||
|
local default = self.exports.default |
||||||
|
local remaining = {} |
||||||
|
for k, v in pairs(self.exports) do |
||||||
|
if k ~= 'default' then |
||||||
|
remaining[k] = self:ResolveExport(v) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
self.resolved = {self:ResolveExport(default), remaining} |
||||||
|
|
||||||
|
return self.resolved[1], self.resolved[2] |
||||||
|
end |
||||||
|
|
||||||
|
self.resolved = {} |
||||||
|
|
||||||
|
for k, v in pairs(self.exports) do |
||||||
|
self.resolved[k] = self:ResolveExport(v) |
||||||
|
end |
||||||
|
|
||||||
|
return unpack(self.resolved) |
||||||
|
end |
||||||
|
|
||||||
|
function Library:DependsOn(other) |
||||||
|
for _, dependency in pairs(self.dependencies) do |
||||||
|
if dependency == other then |
||||||
|
return true |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
return false |
||||||
|
end |
||||||
|
|
||||||
|
---@param library string |
||||||
|
function Library:Import(library) |
||||||
|
local lib = Bastion:GetLibrary(library) |
||||||
|
|
||||||
|
if not lib then |
||||||
|
error("Library " .. library .. " does not exist") |
||||||
|
end |
||||||
|
|
||||||
|
if not table.contains(self.dependencies, library) then |
||||||
|
table.insert(self.dependencies, library) |
||||||
|
end |
||||||
|
|
||||||
|
if lib:DependsOn(self.name) then |
||||||
|
error("Circular dependency detected between " .. self.name .. " and " .. library) |
||||||
|
end |
||||||
|
|
||||||
|
return lib:Resolve() |
||||||
|
end |
||||||
|
|
||||||
|
return Library |
@ -1,274 +1,412 @@ |
|||||||
local Tinkr = ... |
local Tinkr = ... |
||||||
|
|
||||||
|
local Evaulator = Tinkr.Evaluator |
||||||
|
|
||||||
---@class Bastion |
---@class Bastion |
||||||
local Bastion = { |
local Bastion = {DebugMode = false} |
||||||
DebugMode = false |
|
||||||
} |
|
||||||
Bastion.__index = Bastion |
Bastion.__index = Bastion |
||||||
|
|
||||||
function Bastion.require(class) |
function Bastion:Require(file) |
||||||
return Tinkr:require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) |
-- If require starts with an @ then we require from the scripts/bastion/scripts folder |
||||||
|
if file:sub(1, 1) == '@' then |
||||||
|
file = file:sub(2) |
||||||
|
-- print('1') |
||||||
|
return require('scripts/bastion/scripts/' .. file, Bastion) |
||||||
|
elseif file:sub(1, 1) == "~" then |
||||||
|
file = file:sub(2) |
||||||
|
-- print("2") |
||||||
|
return require('scripts/bastion/' .. file, Bastion) |
||||||
|
else |
||||||
|
-- print("Normal req") |
||||||
|
return require(file, Bastion) |
||||||
|
end |
||||||
end |
end |
||||||
|
|
||||||
---@type ClassMagic |
local function Load(dir) |
||||||
Bastion.ClassMagic = Bastion.require("ClassMagic") |
local dir = dir |
||||||
---@type List |
|
||||||
Bastion.List = Bastion.require("List") |
|
||||||
---@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"):New() |
|
||||||
---@type Spell |
|
||||||
Bastion.Spell = Bastion.require("Spell") |
|
||||||
---@type SpellBook |
|
||||||
Bastion.SpellBook = Bastion.require("SpellBook"):New() |
|
||||||
---@type Item |
|
||||||
Bastion.Item = Bastion.require("Item") |
|
||||||
---@type ItemBook |
|
||||||
Bastion.ItemBook = Bastion.require("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() |
|
||||||
Bastion.modules = {} |
|
||||||
Bastion.Enabled = false |
|
||||||
|
|
||||||
Bastion.EventManager:RegisterWoWEvent('UNIT_AURA', function(unit, auras) |
|
||||||
local u = Bastion.UnitManager[unit] |
|
||||||
|
|
||||||
if u then |
|
||||||
u:GetAuras():OnUpdate(auras) |
|
||||||
end |
|
||||||
end) |
|
||||||
|
|
||||||
Bastion.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", function(...) |
if dir:sub(1, 1) == '@' then |
||||||
local unit, castGUID, spellID = ... |
dir = dir:sub(2) |
||||||
|
dir = 'scripts/bastion/scripts/' .. dir |
||||||
|
end |
||||||
|
|
||||||
local spell = Bastion.SpellBook:GetIfRegistered(spellID) |
if dir:sub(1, 1) == '~' then |
||||||
|
dir = dir:sub(2) |
||||||
|
dir = 'scripts/bastion/' .. dir |
||||||
|
end |
||||||
|
|
||||||
if unit == "player" and spell then |
local files = ListFiles(dir) |
||||||
spell.lastCastAt = GetTime() |
|
||||||
|
|
||||||
if spell:GetPostCastFunction() then |
for i = 1, #files do |
||||||
spell:GetPostCastFunction()(spell) |
local file = files[i] |
||||||
|
if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then |
||||||
|
Bastion:Require(dir .. file:sub(1, -5)) |
||||||
end |
end |
||||||
end |
end |
||||||
end) |
end |
||||||
|
|
||||||
local pguid = UnitGUID("player") |
function Bastion.require(class) |
||||||
local missed = {} |
-- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) |
||||||
Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function() |
return Bastion:Require("~/src/" .. class .. "/" .. class) |
||||||
local args = { CombatLogGetCurrentEventInfo() } |
end |
||||||
|
|
||||||
|
-- fenv for all required files |
||||||
|
function Bastion.Bootstrap() |
||||||
|
|
||||||
|
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 = {} |
||||||
|
local MODULES = {} |
||||||
|
|
||||||
|
Bastion.Enabled = false |
||||||
|
|
||||||
|
Bastion.Globals.EventManager:RegisterWoWEvent('UNIT_AURA', |
||||||
|
function(unit, auras) |
||||||
|
local u = Bastion.UnitManager[unit] |
||||||
|
|
||||||
|
if u then u:GetAuras():OnUpdate(auras) end |
||||||
|
end) |
||||||
|
|
||||||
|
Bastion.Globals.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", |
||||||
|
function(...) |
||||||
|
local unit, castGUID, spellID = ... |
||||||
|
|
||||||
|
local spell = Bastion.Globals.SpellBook:GetIfRegistered(spellID) |
||||||
|
|
||||||
|
if unit == "player" and spell then |
||||||
|
spell.lastCastAt = GetTime() |
||||||
|
|
||||||
|
if spell:GetPostCastFunction() then |
||||||
|
spell:GetPostCastFunction()(spell) |
||||||
|
end |
||||||
|
end |
||||||
|
end) |
||||||
|
|
||||||
local subEvent = args[2] |
local pguid = UnitGUID("player") |
||||||
local sourceGUID = args[4] |
local missed = {} |
||||||
local destGUID = args[8] |
|
||||||
local spellID = args[12] |
|
||||||
|
|
||||||
-- if sourceGUID == pguid then |
Bastion.Globals.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", |
||||||
-- local args = { CombatLogGetCurrentEventInfo() } |
function() |
||||||
|
local args = {CombatLogGetCurrentEventInfo()} |
||||||
|
|
||||||
-- for i = 1, #args do |
local subEvent = args[2] |
||||||
-- Log(tostring(args[i])) |
local sourceGUID = args[4] |
||||||
-- end |
local destGUID = args[8] |
||||||
-- end |
local spellID = args[12] |
||||||
|
|
||||||
local u = Bastion.UnitManager[sourceGUID] |
-- if sourceGUID == pguid then |
||||||
local u2 = Bastion.UnitManager[destGUID] |
-- local args = { CombatLogGetCurrentEventInfo() } |
||||||
|
|
||||||
local t = GetTime() |
-- for i = 1, #args do |
||||||
|
-- Log(tostring(args[i])) |
||||||
|
-- end |
||||||
|
-- end |
||||||
|
|
||||||
if u then |
local u = Bastion.UnitManager[sourceGUID] |
||||||
u:SetLastCombatTime(t) |
local u2 = Bastion.UnitManager[destGUID] |
||||||
end |
|
||||||
|
local t = GetTime() |
||||||
|
|
||||||
if u2 then |
if u then u:SetLastCombatTime(t) end |
||||||
u2:SetLastCombatTime(t) |
|
||||||
|
|
||||||
if subEvent == "SPELL_MISSED" and sourceGUID == pguid and spellID == 408 then |
if u2 then |
||||||
local missType = args[15] |
u2:SetLastCombatTime(t) |
||||||
|
|
||||||
if missType == "IMMUNE" then |
if subEvent == "SPELL_MISSED" and sourceGUID == pguid and spellID == |
||||||
local castingSpell = u:GetCastingOrChannelingSpell() |
408 then |
||||||
|
local missType = args[15] |
||||||
|
|
||||||
if castingSpell then |
if missType == "IMMUNE" then |
||||||
if not missed[castingSpell:GetID()] then |
local castingSpell = u:GetCastingOrChannelingSpell() |
||||||
missed[castingSpell:GetID()] = true |
|
||||||
|
if castingSpell then |
||||||
|
if not missed[castingSpell:GetID()] then |
||||||
|
missed[castingSpell:GetID()] = true |
||||||
|
end |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end) |
||||||
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() |
||||||
elseif Bastion.CombatTimer:IsRunning() and not UnitAffectingCombat("player") then |
elseif Bastion.CombatTimer:IsRunning() and |
||||||
Bastion.CombatTimer:Reset() |
not UnitAffectingCombat("player") then |
||||||
end |
Bastion.CombatTimer:Reset() |
||||||
|
|
||||||
if Bastion.Enabled then |
|
||||||
Bastion.ObjectManager:Refresh() |
|
||||||
for i = 1, #Bastion.modules do |
|
||||||
Bastion.modules[i]:Tick() |
|
||||||
end |
end |
||||||
end |
|
||||||
end) |
|
||||||
|
|
||||||
function Bastion:Register(module) |
|
||||||
table.insert(Bastion.modules, module) |
|
||||||
Bastion:Print("Registered", module) |
|
||||||
end |
|
||||||
|
|
||||||
-- Find a module by name |
if Bastion.Enabled then |
||||||
function Bastion:FindModule(name) |
Bastion.ObjectManager:Refresh() |
||||||
for i = 1, #Bastion.modules do |
for i = 1, #MODULES do MODULES[i]:Tick() end |
||||||
if Bastion.modules[i].name == name then |
|
||||||
return Bastion.modules[i] |
|
||||||
end |
end |
||||||
|
end) |
||||||
|
|
||||||
|
function Bastion:Register(module) |
||||||
|
table.insert(MODULES, module) |
||||||
|
Bastion:Print("Registered", module) |
||||||
end |
end |
||||||
|
|
||||||
return nil |
-- Find a module by name |
||||||
end |
function Bastion:FindModule(name) |
||||||
|
for i = 1, #MODULES do |
||||||
|
if MODULES[i].name == name then return MODULES[i] end |
||||||
|
end |
||||||
|
|
||||||
function Bastion:Print(...) |
return nil |
||||||
local args = { ... } |
|
||||||
local str = "|cFFDF362D[Bastion]|r |cFFFFFFFF" |
|
||||||
for i = 1, #args do |
|
||||||
str = str .. tostring(args[i]) .. " " |
|
||||||
end |
end |
||||||
print(str) |
|
||||||
end |
|
||||||
|
|
||||||
function Bastion:Debug(...) |
function Bastion:Print(...) |
||||||
if not Bastion.DebugMode then |
local args = {...} |
||||||
return |
local str = "|cFFDF362D[Bastion]|r |cFFFFFFFF" |
||||||
|
for i = 1, #args do str = str .. tostring(args[i]) .. " " end |
||||||
|
print(str) |
||||||
end |
end |
||||||
local args = { ... } |
|
||||||
local str = "|cFFDF6520[Bastion]|r |cFFFFFFFF" |
function Bastion:Debug(...) |
||||||
for i = 1, #args do |
if not Bastion.DebugMode then return end |
||||||
str = str .. tostring(args[i]) .. " " |
local args = {...} |
||||||
|
local str = "|cFFDF6520[Bastion]|r |cFFFFFFFF" |
||||||
|
for i = 1, #args do str = str .. tostring(args[i]) .. " " end |
||||||
|
print(str) |
||||||
end |
end |
||||||
print(str) |
|
||||||
end |
|
||||||
|
|
||||||
local Command = Bastion.Command:New('bastion') |
local Command = Bastion.Command:New('bastion') |
||||||
|
|
||||||
Command:Register('toggle', 'Toggle bastion on/off', function() |
Command:Register('toggle', 'Toggle bastion on/off', function() |
||||||
Bastion.Enabled = not Bastion.Enabled |
Bastion.Enabled = not Bastion.Enabled |
||||||
if Bastion.Enabled then |
if Bastion.Enabled then |
||||||
Bastion:Print("Enabled") |
Bastion:Print("Enabled") |
||||||
else |
else |
||||||
Bastion:Print("Disabled") |
Bastion:Print("Disabled") |
||||||
end |
end |
||||||
end) |
end) |
||||||
|
|
||||||
Command:Register('debug', 'Toggle debug mode on/off', function() |
Command:Register('debug', 'Toggle debug mode on/off', function() |
||||||
Bastion.DebugMode = not Bastion.DebugMode |
Bastion.DebugMode = not Bastion.DebugMode |
||||||
if Bastion.DebugMode then |
if Bastion.DebugMode then |
||||||
Bastion:Print("Debug mode enabled") |
Bastion:Print("Debug mode enabled") |
||||||
else |
else |
||||||
Bastion:Print("Debug mode disabled") |
Bastion:Print("Debug mode disabled") |
||||||
end |
|
||||||
end) |
|
||||||
Command:Register('dumpspells', 'Dump spells to a file', function() |
|
||||||
local i = 1 |
|
||||||
local rand = math.random(100000, 999999) |
|
||||||
while true do |
|
||||||
local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL) |
|
||||||
if not spellName then |
|
||||||
do break end |
|
||||||
end |
end |
||||||
|
end) |
||||||
|
|
||||||
|
Command:Register('dumpspells', 'Dump spells to a file', function() |
||||||
|
local i = 1 |
||||||
|
local rand = math.random(100000, 999999) |
||||||
|
local BOOKTYPE_SPELL = BOOKTYPE_SPELL or (Enum.SpellBookSpellBank.Player and Enum.SpellBookSpellBank.Player or 'spell') |
||||||
|
while true do |
||||||
|
local spellName, spellSubName |
||||||
|
|
||||||
|
if C_SpellBook.GetSpellBookItemName then |
||||||
|
spellName, spellSubName = C_SpellBook.GetSpellBookItemName(i, BOOKTYPE_SPELL) |
||||||
|
else |
||||||
|
spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_SPELL) |
||||||
|
end |
||||||
|
|
||||||
|
if not spellName then do break end end |
||||||
|
|
||||||
|
-- use spellName and spellSubName here |
||||||
|
local spellID |
||||||
|
|
||||||
-- use spellName and spellSubName here |
if C_Spell.GetSpellInfo then |
||||||
local spellID = select(7, GetSpellInfo(spellName)) |
local info = C_Spell.GetSpellInfo(spellName) |
||||||
|
spellID = info.spellID |
||||||
|
else |
||||||
|
spellID = select(7, GetSpellInfo(spellName)) |
||||||
|
end |
||||||
|
|
||||||
if spellID then |
if spellID then |
||||||
spellName = spellName:gsub("[%W%s]", "") |
spellName = spellName:gsub("[%W%s]", "") |
||||||
WriteFile('bastion-' .. UnitClass('player') .. '-' .. rand .. '.lua', |
WriteFile('bastion-' .. UnitClass('player') .. '-' .. rand .. |
||||||
"local " .. spellName .. " = Bastion.SpellBook:GetSpell(" .. spellID .. ")", true) |
'.lua', |
||||||
|
"local " .. spellName .. |
||||||
|
" = Bastion.Globals.SpellBook:GetSpell(" .. |
||||||
|
spellID .. ")\n", true) |
||||||
|
end |
||||||
|
i = i + 1 |
||||||
end |
end |
||||||
i = i + 1 |
end) |
||||||
end |
|
||||||
end) |
Command:Register('module', 'Toggle a module on/off', function(args) |
||||||
|
local module = Bastion:FindModule(args[2]) |
||||||
Command:Register('module', 'Toggle a module on/off', function(args) |
if module then |
||||||
local module = Bastion:FindModule(args[2]) |
module:Toggle() |
||||||
if module then |
if module.enabled then |
||||||
module:Toggle() |
Bastion:Print("Enabled", module.name) |
||||||
if module.enabled then |
else |
||||||
Bastion:Print("Enabled", module.name) |
Bastion:Print("Disabled", module.name) |
||||||
|
end |
||||||
else |
else |
||||||
Bastion:Print("Disabled", module.name) |
Bastion:Print("Module not found") |
||||||
end |
end |
||||||
else |
end) |
||||||
Bastion:Print("Module not found") |
|
||||||
end |
Command:Register('mplus', 'Toggle m+ module on/off', function(args) |
||||||
end) |
local cmd = args[2] |
||||||
|
if cmd == 'debuffs' then |
||||||
Command:Register('mplus', 'Toggle m+ module on/off', function(args) |
Bastion.MythicPlusUtils:ToggleDebuffLogging() |
||||||
local cmd = args[2] |
Bastion:Print("Debuff logging", Bastion.MythicPlusUtils |
||||||
if cmd == 'debuffs' then |
.debuffLogging and "enabled" or "disabled") |
||||||
Bastion.MythicPlusUtils:ToggleDebuffLogging() |
return |
||||||
Bastion:Print("Debuff logging", Bastion.MythicPlusUtils.debuffLogging and "enabled" or "disabled") |
end |
||||||
return |
|
||||||
|
if cmd == 'casts' then |
||||||
|
Bastion.MythicPlusUtils:ToggleCastLogging() |
||||||
|
Bastion:Print("Cast logging", |
||||||
|
Bastion.MythicPlusUtils.castLogging and "enabled" or |
||||||
|
"disabled") |
||||||
|
return |
||||||
|
end |
||||||
|
|
||||||
|
Bastion:Print("[MythicPlusUtils] Unknown command") |
||||||
|
Bastion:Print("Available commands:") |
||||||
|
Bastion:Print("debuffs") |
||||||
|
Bastion:Print("casts") |
||||||
|
end) |
||||||
|
|
||||||
|
Command:Register('missed', 'Dump the list of immune kidney shot spells', |
||||||
|
function() |
||||||
|
for k, v in pairs(missed) do Bastion:Print(k) end |
||||||
|
end) |
||||||
|
|
||||||
|
---@param library Library |
||||||
|
function Bastion:RegisterLibrary(library) |
||||||
|
LIBRARIES[library.name] = library |
||||||
end |
end |
||||||
|
|
||||||
if cmd == 'casts' then |
function Bastion:CheckLibraryDependencies() |
||||||
Bastion.MythicPlusUtils:ToggleCastLogging() |
for k, v in pairs(LIBRARIES) do |
||||||
Bastion:Print("Cast logging", Bastion.MythicPlusUtils.castLogging and "enabled" or "disabled") |
if v.dependencies then |
||||||
return |
for i = 1, #v.dependencies do |
||||||
|
local dep = v.dependencies[i] |
||||||
|
if LIBRARIES[dep] then |
||||||
|
if LIBRARIES[dep].dependencies then |
||||||
|
for j = 1, #LIBRARIES[dep].dependencies do |
||||||
|
if LIBRARIES[dep].dependencies[j] == v.name then |
||||||
|
Bastion:Print( |
||||||
|
"Circular dependency detected between " .. |
||||||
|
v.name .. " and " .. dep) |
||||||
|
return false |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
else |
||||||
|
Bastion:Print("Library " .. v.name .. " depends on " .. |
||||||
|
dep .. " but it's not registered") |
||||||
|
return false |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
return true |
||||||
end |
end |
||||||
|
|
||||||
Bastion:Print("[MythicPlusUtils] Unknown command") |
function Bastion:Import(library) |
||||||
Bastion:Print("Available commands:") |
local lib = self:GetLibrary(library) |
||||||
Bastion:Print("debuffs") |
|
||||||
Bastion:Print("casts") |
if not lib then error("Library " .. library .. " not found") end |
||||||
end) |
|
||||||
|
|
||||||
Command:Register('missed', 'Dump the list of immune kidney shot spells', function() |
return lib:Resolve() |
||||||
for k, v in pairs(missed) do |
|
||||||
Bastion:Print(k) |
|
||||||
end |
end |
||||||
end) |
|
||||||
|
|
||||||
local files = ListFiles("scripts/bastion/scripts") |
function Bastion:GetLibrary(name) |
||||||
|
if not LIBRARIES[name] then |
||||||
|
error("Library " .. name .. " not found") |
||||||
|
end |
||||||
|
|
||||||
for i = 1, #files do |
local library = LIBRARIES[name] |
||||||
local file = files[i] |
|
||||||
if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then |
-- if library.dependencies then |
||||||
Tinkr:require("scripts/bastion/scripts/" .. file:sub(1, -5), Bastion) |
-- for i = 1, #library.dependencies do |
||||||
|
-- local dep = library.dependencies[i] |
||||||
|
-- if LIBRARIES[dep] then |
||||||
|
-- if LIBRARIES[dep].dependencies then |
||||||
|
-- for j = 1, #LIBRARIES[dep].dependencies do |
||||||
|
-- if LIBRARIES[dep].dependencies[j] == library.name then |
||||||
|
-- Bastion:Print("Circular dependency detected between " .. library.name .. " and " .. dep) |
||||||
|
-- return false |
||||||
|
-- end |
||||||
|
-- end |
||||||
|
-- end |
||||||
|
-- else |
||||||
|
-- Bastion:Print("Library " .. v.name .. " depends on " .. dep .. " but it's not registered") |
||||||
|
-- return false |
||||||
|
-- end |
||||||
|
-- end |
||||||
|
-- end |
||||||
|
|
||||||
|
return library |
||||||
end |
end |
||||||
|
|
||||||
|
-- if not Bastion:CheckLibraryDependencies() then |
||||||
|
-- return |
||||||
|
-- end |
||||||
|
|
||||||
|
Load("@Libraries/") |
||||||
|
Load("@Modules/") |
||||||
|
Load("@") |
||||||
end |
end |
||||||
|
|
||||||
|
Bastion.Bootstrap() |
||||||
|
Loading…
Reference in new issue