mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
refactor: load file & moving 1 conf val
This commit is contained in:
parent
40f7bb8079
commit
00880889bf
|
@ -1,65 +1,67 @@
|
||||||
if game.SinglePlayer() then return end
|
if (game.SinglePlayer()) then return print("Gmod Integration is not supported in Singleplayer!") end
|
||||||
|
|
||||||
//
|
//
|
||||||
// Variables
|
// Variables
|
||||||
//
|
//
|
||||||
|
|
||||||
gmInte = gmInte || {}
|
gmInte = gmInte || {}
|
||||||
|
|
||||||
gmInte.version = "0.3.0"
|
gmInte.version = "0.3.0"
|
||||||
gmInte.config = gmInte.config || {
|
gmInte.config = {}
|
||||||
["redownloadMaterials"] = false,
|
|
||||||
}
|
|
||||||
gmInte.materials = {}
|
gmInte.materials = {}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Functions
|
// Functions
|
||||||
//
|
//
|
||||||
|
|
||||||
local function loadConfig()
|
local function loadServerConfig()
|
||||||
if (SERVER) then
|
RunConsoleCommand("sv_hibernate_think", "1")
|
||||||
RunConsoleCommand("sv_hibernate_think", "1")
|
|
||||||
if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then
|
if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then
|
||||||
file.CreateDir("gm_integration")
|
file.CreateDir("gm_integration")
|
||||||
|
file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
|
||||||
|
else
|
||||||
|
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))
|
file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
|
||||||
else
|
else
|
||||||
if (gmInte.config.id && gmInte.config.id != "") then return end
|
gmInte.config = oldConfig
|
||||||
|
|
||||||
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))
|
|
||||||
else
|
|
||||||
gmInte.config = oldConfig
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadAllFiles(folder)
|
local function loadAllFiles(folder)
|
||||||
local files, folders = file.Find(folder .. "/*", "LUA")
|
local files, folders = file.Find(folder .. "/*", "LUA")
|
||||||
for k, v in SortedPairs(files) do
|
|
||||||
local path = folder .. "/" .. v
|
for k, fileName in SortedPairs(files) do
|
||||||
|
local path = folder .. "/" .. fileName
|
||||||
print(" | Loading File | " .. path)
|
print(" | Loading File | " .. path)
|
||||||
if string.StartWith(v, "cl_") then
|
|
||||||
|
if (string.StartWith(fileName, "cl_")) then
|
||||||
if SERVER then
|
if SERVER then
|
||||||
AddCSLuaFile(path)
|
AddCSLuaFile(path)
|
||||||
else
|
else
|
||||||
include(path)
|
include(path)
|
||||||
end
|
end
|
||||||
elseif string.StartWith(v, "sv_") then
|
elseif (string.StartWith(fileName, "sv_")) then
|
||||||
if SERVER then
|
if SERVER then
|
||||||
include(path)
|
include(path)
|
||||||
end
|
end
|
||||||
elseif string.StartWith(v, "sh_") then
|
elseif (string.StartWith(fileName, "sh_")) then
|
||||||
if SERVER then
|
if SERVER then
|
||||||
AddCSLuaFile(path)
|
AddCSLuaFile(path)
|
||||||
end
|
end
|
||||||
include(path)
|
include(path)
|
||||||
end
|
end
|
||||||
if (path == "gmod_integration/sv_config.lua") then loadConfig() continue end
|
|
||||||
|
if (fileName == "sv_config.lua") then loadServerConfig() continue end
|
||||||
end
|
end
|
||||||
|
|
||||||
for k, v in SortedPairs(folders, true) do
|
for k, v in SortedPairs(folders, true) do
|
||||||
loadAllFiles(folder .. "/" .. v, name)
|
loadAllFiles(folder .. "/" .. v, name)
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,6 +70,12 @@ gmInte.config.filterOnBan = true // If true, the addon will filter the players a
|
||||||
// Will disable the features of the addon
|
// Will disable the features of the addon
|
||||||
gmInte.config.sendLog = false // Disable the logs
|
gmInte.config.sendLog = false // Disable the logs
|
||||||
|
|
||||||
|
//
|
||||||
|
// Materials
|
||||||
|
//
|
||||||
|
|
||||||
|
gmInte.config.redownloadMaterials = false // If true, the addon will redownload the materials of the addon (useful if you have a problem with the materials)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Debug & Development
|
// Debug & Development
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user