diff --git a/source/thirdworld/common/config.d b/source/thirdworld/common/config.d index 522059a..a9d78d8 100644 --- a/source/thirdworld/common/config.d +++ b/source/thirdworld/common/config.d @@ -1,41 +1,41 @@ -module thirdworld.common.config; - -import common.log; - -import std.file : readText, exists, isFile, write; -import std.json; -import std.path : absolutePath; - -JSONValue structToJSON(T)(T s) { - JSONValue json; - foreach (member; __traits(allMembers, T)) { - json[member] = JSONValue(__traits(getMember, s, member)); - } - return json; -} - -void createConfigFile(T)(string path) { - path = absolutePath(path); - if (exists(path) && isFile(path)) { - return; - } - - logInfo("No config file found, creating default config file at '%s'", path); - - T config; - auto json = structToJSON(config); - write(path, json.toPrettyString()); -} - -T configFromFile(T)(string path) { - string text = readText(path); - JSONValue json = parseJSON(text); - - T config; - - foreach (member; __traits(allMembers, T)) { - config[member] = json[member]; - } - - return config; +module thirdworld.common.config; + +import thirdworld.common.log; + +import std.file : readText, exists, isFile, write; +import std.json; +import std.path : absolutePath; + +JSONValue structToJSON(T)(T s) { + JSONValue json; + foreach (member; __traits(allMembers, T)) { + json[member] = JSONValue(__traits(getMember, s, member)); + } + return json; +} + +void createConfigFile(T)(string path) { + path = absolutePath(path); + if (exists(path) && isFile(path)) { + return; + } + + logInfo("No config file found, creating default config file at '%s'", path); + + T config; + auto json = structToJSON(config); + write(path, json.toPrettyString()); +} + +T configFromFile(T)(string path) { + string text = readText(path); + JSONValue json = parseJSON(text); + + T config; + + foreach (member; __traits(allMembers, T)) { + config[member] = json[member]; + } + + return config; } \ No newline at end of file