From e4d4270b602834c4629281238af2a2918b65172c Mon Sep 17 00:00:00 2001 From: 4n0n <4n0n@tinkr.site> Date: Sat, 19 Aug 2023 15:31:29 -0500 Subject: [PATCH] add bastion requires --- src/_bastion.lua | 60 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/_bastion.lua b/src/_bastion.lua index 6399489..161bce3 100644 --- a/src/_bastion.lua +++ b/src/_bastion.lua @@ -6,8 +6,48 @@ local Bastion = { } Bastion.__index = Bastion +function Bastion:Require(file) + -- 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 + +local function Load(dir) + local dir = dir + + if dir:sub(1, 1) == '@' then + dir = dir:sub(2) + dir = 'scripts/bastion/scripts/' .. dir + end + + if dir:sub(1, 1) == '~' then + dir = dir:sub(2) + dir = 'scripts/bastion/' .. dir + end + + local files = ListFiles(dir) + + for i = 1, #files do + local file = files[i] + if file:sub(-4) == ".lua" or file:sub(-5) == '.luac' then + return Bastion:Require(dir .. file:sub(1, -5)) + end + end +end + function Bastion.require(class) - return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) + -- return require("scripts/bastion/src/" .. class .. "/" .. class, Bastion) + return Bastion:Require("~/src/" .. class .. "/" .. class) end Bastion.Globals = {} @@ -279,17 +319,6 @@ Command:Register('missed', 'Dump the list of immune kidney shot spells', functio end end) -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 - require(dir .. file:sub(1, -5), Bastion) - end - end -end - ---@param library Library function Bastion:RegisterLibrary(library) LIBRARIES[library.name] = library @@ -359,11 +388,10 @@ function Bastion:GetLibrary(name) return library end -Load("scripts/bastion/scripts/Libraries/") - -- if not Bastion:CheckLibraryDependencies() then -- return -- end -Load("scripts/bastion/scripts/Modules/") -Load("scripts/bastion/scripts/") +Load("@Libraries/") +Load("@Modules/") +Load("@")