diff --git a/.gitignore b/.gitignore index 1d6afaa..dd44dfb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,17 @@ DS_Store !.gitkeep ## ignore all files in scripts +scripts/* +!scripts/Libraries +scripts/Libraries/*/*.* +!scripts/Modules +scripts/Modules/*/*.* +!scripts/.gitkeep +Examples/*/*.* +!Examples/ExampleModule.lua +!Examples/Libraries/ExampleLibrary.lua +!Examples/Libraries/ExampleDependency.lua +!Examples/Libraries/ExampleDependencyError.lua ## ignore vscode settings .vscode/* diff --git a/Examples/ExampleModule.lua b/Examples/ExampleModule.lua new file mode 100644 index 0000000..4289a24 --- /dev/null +++ b/Examples/ExampleModule.lua @@ -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) diff --git a/Examples/Libraries/ExampleDependency.lua b/Examples/Libraries/ExampleDependency.lua new file mode 100644 index 0000000..87c1449 --- /dev/null +++ b/Examples/Libraries/ExampleDependency.lua @@ -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 + } +})) diff --git a/Examples/Libraries/ExampleDependencyError.lua b/Examples/Libraries/ExampleDependencyError.lua new file mode 100644 index 0000000..5fc4485 --- /dev/null +++ b/Examples/Libraries/ExampleDependencyError.lua @@ -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 + } +})) diff --git a/Examples/Libraries/ExampleLibrary.lua b/Examples/Libraries/ExampleLibrary.lua new file mode 100644 index 0000000..ddb7afa --- /dev/null +++ b/Examples/Libraries/ExampleLibrary.lua @@ -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 + } +}))