2023-08-19 04:25:27 +02:00
|
|
|
require("core.game")
|
2022-04-04 01:58:10 +02:00
|
|
|
|
2022-04-05 06:36:11 +02:00
|
|
|
GameConfig = {}
|
2022-04-04 01:58:10 +02:00
|
|
|
|
2023-08-19 04:25:27 +02:00
|
|
|
---Find patterns in file
|
|
|
|
---@param path string # relative path to game file
|
|
|
|
---@param pattern string # search pattern
|
|
|
|
---@return table? matches # {{group1, group2, ...}, ...}
|
|
|
|
---@return string? errmsg
|
|
|
|
local function match_all(path, pattern)
|
|
|
|
local matches = {}
|
|
|
|
local text, err = game.file.open(path, "r")
|
|
|
|
if not text then
|
|
|
|
return nil, err
|
|
|
|
end
|
|
|
|
for line in text:lines() do
|
|
|
|
if line:match(pattern) then
|
|
|
|
table.insert(matches, {line:match(pattern)})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return matches
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameConfig.refresh()
|
|
|
|
local config, err = match_all("Main.cfg", "(%w*)%s*=%s*\"?([^\"%s]*)\"?")
|
|
|
|
if not config then
|
|
|
|
game.Log("Unable to refresh GameConfig, " .. err, game.LOGGER_ERROR)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, match in ipairs(config) do
|
2022-04-05 06:36:11 +02:00
|
|
|
GameConfig[match[1]] = match[2]
|
2022-04-04 01:58:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-19 04:25:27 +02:00
|
|
|
GameConfig.refresh()
|