diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 0e68a14..454ad44 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -59,7 +59,7 @@ dofile(wea_c.modpath.."/utils/player.lua") -- Player info functions - +wea_c.setting_handler = dofile(wea_c.modpath.."/utils/setting_handler.lua") -- AFTER parser wea_c.pos = dofile(modpath.."/core/pos.lua") -- AFTER EventEmitter wea_c.register_command = dofile(modpath.."/core/register_command.lua") diff --git a/worldeditadditions_core/utils/setting_handler.lua b/worldeditadditions_core/utils/setting_handler.lua new file mode 100644 index 0000000..5265c97 --- /dev/null +++ b/worldeditadditions_core/utils/setting_handler.lua @@ -0,0 +1,43 @@ +--- A wrapper to simultaniously handle global and world settings. + +-- Initialize settings container +local wea_c = worldeditadditions_core +wea_c.settings = {} + +-- Initialize wea world folder if not already existing +local path = minetest.get_worldpath() .. "/worldeditadditions" +minetest.mkdir(path) + +-- @class +local setting_handler = {} + +--- Reads world settings into WEA core settings object +setting_handler.read = function() + local file, err = io.open(path .. "/settings.conf", "rb") + if err then return false end + -- Split by newline + -- local settings = wea_c.split(file:read(),"[\n\r]+") + file:close() +end + +--- Write setting to world settings +setting_handler.write = function(setting, state) + local writer, err = io.open(path .. "/settings.conf", "ab") + if not writer then + return false + elseif setting == "" and not state then + writer:write("") + else + writer:write("worldeditadditions_" .. setting .. " = " .. state .. "\n") + end + writer:flush() + writer:close() + return true +end + +-- Test for world settings and generate file if none +if not setting_handler.read() then + setting_handler.write("") +end + +return setting_handler \ No newline at end of file