From aad9b09935fe35f9e0d21d5d5546e3dfea664525 Mon Sep 17 00:00:00 2001 From: camille lechauve Date: Sun, 3 Sep 2023 20:04:49 +0200 Subject: [PATCH] add config --- lua/autorun/server/sv_config.lua | 23 +++++++++++++++++++++++ lua/autorun/server/sv_utils.lua | 11 +++++++++++ lua/autorun/sh_config.lua | 6 ++++++ 3 files changed, 40 insertions(+) create mode 100644 lua/autorun/server/sv_config.lua create mode 100644 lua/autorun/server/sv_utils.lua create mode 100644 lua/autorun/sh_config.lua diff --git a/lua/autorun/server/sv_config.lua b/lua/autorun/server/sv_config.lua new file mode 100644 index 0000000..d0ad6b1 --- /dev/null +++ b/lua/autorun/server/sv_config.lua @@ -0,0 +1,23 @@ +utils = include("sv_utils.lua") +config = include("../sh_config.lua") + +local dirs = utils.split(config.config_path, "/") +table.remove(dirs) +local tmp = ""; +for i, dir in ipairs(dirs) do + tmp = tmp .. dir + if not file.Exists(tmp, "DATA") + then + print(tmp) + file.CreateDir(tmp) + end + tmp = tmp .. "/" +end + +if not file.Exists(config.config_path, "DATA") +then + print(config.config_path) + local default_config = {} + default_config.diseases = {} + file.Write(config.config_path, util.TableToJSON(default_config, true)) +end diff --git a/lua/autorun/server/sv_utils.lua b/lua/autorun/server/sv_utils.lua new file mode 100644 index 0000000..df362cb --- /dev/null +++ b/lua/autorun/server/sv_utils.lua @@ -0,0 +1,11 @@ +utils = {} + +function utils.split (str, sep) + local new_table = {} + for v in string.gmatch(str, "([^"..sep.."]+)") do + table.insert(new_table, v) + end + return new_table +end + +return utils \ No newline at end of file diff --git a/lua/autorun/sh_config.lua b/lua/autorun/sh_config.lua new file mode 100644 index 0000000..4e3a4f1 --- /dev/null +++ b/lua/autorun/sh_config.lua @@ -0,0 +1,6 @@ +config = {} + +-- the config file path location +config.config_path = "disease/config.json" + +return config \ No newline at end of file