From 0eb8109ac25f2da886b5f8d6f836651d093c0233 Mon Sep 17 00:00:00 2001 From: Linventif Date: Thu, 17 Apr 2025 17:32:44 +0000 Subject: [PATCH] refact: manual priority of folder / file --- lua/autorun/gmod_integration.lua | 57 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua index f004d73..b10e9b0 100644 --- a/lua/autorun/gmod_integration.lua +++ b/lua/autorun/gmod_integration.lua @@ -3,7 +3,7 @@ gmInte = gmInte || {} gmInte.version = "0.5.0" gmInte.config = {} gmInte.materials = {} -local function loadServerConfig() +local function loadConfig() RunConsoleCommand("sv_hibernate_think", "1") if !file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA") then file.CreateDir("gm_integration") @@ -12,7 +12,6 @@ local function loadServerConfig() if gmInte.config.id && gmInte.config.id != "" then return end local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) if !oldConfig.version || (oldConfig.version < gmInte.version) then - print(" | Merging Config | gmod_integration/sv_config.lua") table.Merge(gmInte.config, oldConfig) gmInte.config.version = gmInte.version file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) @@ -22,32 +21,36 @@ local function loadServerConfig() end end -local function loadAllFiles(folder) - local files, folders = file.Find(folder .. "/*", "LUA") - for k, fileName in SortedPairs(files) do - local path = folder .. "/" .. fileName - print(" | Loading File | " .. path) - if string.StartWith(fileName, "cl_") then - if SERVER then - AddCSLuaFile(path) - else - include(path) - end - elseif string.StartWith(fileName, "sv_") then - if SERVER then include(path) end - elseif string.StartWith(fileName, "sh_") then - if SERVER then AddCSLuaFile(path) end +local loadedFiles = {} +local function loadFile(folder, fileName) + local path = folder .. "/" .. fileName + if loadedFiles[path] then return end + loadedFiles[path] = true + print(" | Loading File | " .. path) + if string.StartWith(fileName, "cl_") then + if SERVER then + AddCSLuaFile(path) + else include(path) end - - if fileName == "sv_config.lua" then - loadServerConfig() - continue - end + elseif string.StartWith(fileName, "sv_") then + if SERVER then include(path) end + elseif string.StartWith(fileName, "sh_") then + if SERVER then AddCSLuaFile(path) end + include(path) end - for k, v in SortedPairs(folders, true) do - loadAllFiles(folder .. "/" .. v, name) + if fileName == "sv_config.lua" then loadConfig() end +end + +local function loadFolder(folder) + local files, folders = file.Find(folder .. "/*", "LUA") + for k, fileName in SortedPairs(files) do + loadFile(folder, fileName) + end + + for k, subFolder in SortedPairs(folders) do + loadFolder(folder .. "/" .. subFolder) end end @@ -65,5 +68,9 @@ print(" - https://gmod-integration.com/discord - ") print(" - - ") print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ") print(" ") -loadAllFiles("gmod_integration") +loadFile("gmod_integration", "sv_config.lua") +loadFolder("gmod_integration/languages") +loadFolder("gmod_integration/core") +loadFolder("gmod_integration/modules") +loadFolder("gmod_integration") print(" ") \ No newline at end of file