fix config loading with directorys (#52)

This commit is contained in:
Pierce Lally 2023-11-09 22:10:21 -05:00 committed by GitHub
parent fad5576e8f
commit 33b31a0742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 13 deletions

View File

@ -4,12 +4,14 @@ local function requestNetworkedConfig()
end
local function loadConfigsClient()
CFCHTTP.LoadConfig( {
CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.sharedConfigsDir ),
CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.clientConfigsDir ),
CFCHTTP.LuaTableSources( CFCHTTP.networkedConfig ),
CFCHTTP.FileSource( CFCHTTP.filenames.defaultJsonConfig ),
} )
---@type (fun(): WhitelistConfig)[]
local configSources = {}
table.Add(configSources, CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.sharedConfigsDir ))
table.Add(configSources, CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.clientConfigsDir ))
table.insert(configSources, CFCHTTP.LuaTableSources( CFCHTTP.networkedConfig ) )
table.insert(configSources, CFCHTTP.FileSource( CFCHTTP.filenames.defaultJsonConfig ))
CFCHTTP.LoadConfig( configSources )
end
net.Receive( "CFCHTTP_ConfigUpdate", function()

View File

@ -21,11 +21,11 @@ CFCHTTP.Net.receiveWithMiddleware( "CFCHTTP_RequestConfig", function( _, ply )
end, CFCHTTP.Net.rateLimit( "CFCHTTP_RequestConfig", 2, 10 ) )
local function loadConfigsServer()
CFCHTTP.LoadConfig( {
CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.sharedConfigsDir ),
CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.serverConfigsDir ),
CFCHTTP.FileSource( CFCHTTP.filenames.defaultJsonConfig ),
} )
local configSources = {}
table.Add(configSources, CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.sharedConfigsDir ))
table.Add(configSources, CFCHTTP.LuaDirectorySources( CFCHTTP.filenames.serverConfigsDir ))
table.insert(configSources, CFCHTTP.FileSource( CFCHTTP.filenames.defaultJsonConfig ))
CFCHTTP.LoadConfig( configSources )
local data = file.Read( CFCHTTP.filenames.serverClientJsonConfig, "DATA" )
CFCHTTP.networkedClientConfig = data and util.JSONToTable( data )

View File

@ -35,8 +35,9 @@ function CFCHTTP.LuaFileSource( filename )
end
---@param dir string
---@return fun(): WhitelistConfig ...
---@return fun(): WhitelistConfig[]
function CFCHTTP.LuaDirectorySources( dir )
---@type (fun(): WhitelistConfig)[]
local funcs = {}
local files = file.Find( dir .. "*.lua", "LUA" )
@ -44,7 +45,7 @@ function CFCHTTP.LuaDirectorySources( dir )
table.insert( funcs, CFCHTTP.LuaFileSource( dir .. fil ) )
end
return unpack( funcs )
return funcs
end
---@param tbl WhitelistConfig