2017-02-09 07:08:29 +01:00
|
|
|
-- microexpansion/init.lua
|
2017-07-25 19:47:25 +02:00
|
|
|
microexpansion = {}
|
|
|
|
microexpansion.data = {}
|
|
|
|
microexpansion.modpath = minetest.get_modpath("microexpansion") -- Get modpath
|
|
|
|
microexpansion.worldpath = minetest.get_worldpath() -- Get worldpath
|
|
|
|
|
|
|
|
local modpath = microexpansion.modpath -- Modpath pointer
|
|
|
|
local worldpath = microexpansion.worldpath -- Worldpath pointer
|
2017-02-09 07:08:29 +01:00
|
|
|
|
2017-02-23 02:25:43 +01:00
|
|
|
-- Formspec GUI related stuff
|
|
|
|
microexpansion.gui_bg = "bgcolor[#080808BB;true]background[5,5;1,1;gui_formbg.png;true]"
|
|
|
|
microexpansion.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
|
|
|
|
|
2017-02-09 07:08:29 +01:00
|
|
|
-- logger
|
|
|
|
function microexpansion.log(content, log_type)
|
2017-07-25 19:47:25 +02:00
|
|
|
assert(content, "microexpansion.log: missing content")
|
|
|
|
if not content then return false end
|
|
|
|
if log_type == nil then log_type = "action" end
|
|
|
|
minetest.log(log_type, "[MicroExpansion] "..content)
|
2017-02-09 07:08:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Load API
|
|
|
|
dofile(modpath.."/api.lua")
|
2017-02-09 07:29:04 +01:00
|
|
|
|
2017-07-25 19:47:25 +02:00
|
|
|
-----------------
|
|
|
|
---- ME DATA ----
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
-- [function] Load
|
|
|
|
function microexpansion.load()
|
|
|
|
local res = io.open(worldpath.."/microexpansion.txt", "r")
|
|
|
|
if res then
|
|
|
|
res = minetest.deserialize(res:read("*all"))
|
|
|
|
if type(res) == "table" then
|
|
|
|
microexpansion.networks = res.networks or {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Load
|
|
|
|
microexpansion.load()
|
|
|
|
|
|
|
|
-- [function] Save
|
|
|
|
function microexpansion.save()
|
|
|
|
local data = {
|
|
|
|
networks = microexpansion.networks,
|
|
|
|
}
|
|
|
|
|
|
|
|
io.open(worldpath.."/microexpansion.txt", "w"):write(minetest.serialize(data))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- [register on] Server Shutdown
|
|
|
|
minetest.register_on_shutdown(microexpansion.save)
|
|
|
|
|
2017-02-15 04:35:06 +01:00
|
|
|
-------------------
|
|
|
|
----- MODULES -----
|
|
|
|
-------------------
|
2017-02-09 16:37:14 +01:00
|
|
|
|
2017-02-15 04:35:06 +01:00
|
|
|
local loaded_modules = {}
|
|
|
|
|
|
|
|
local settings = Settings(modpath.."/modules.conf"):to_table()
|
|
|
|
|
|
|
|
-- [function] Get module path
|
|
|
|
function microexpansion.get_module_path(name)
|
2017-07-25 19:47:25 +02:00
|
|
|
local module_path = modpath.."/modules/"..name
|
2017-02-15 04:35:06 +01:00
|
|
|
|
2017-07-25 19:47:25 +02:00
|
|
|
if io.open(module_path.."/init.lua") then
|
|
|
|
return module_path
|
|
|
|
end
|
2017-02-15 04:35:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- [function] Load module (overrides modules.conf)
|
|
|
|
function microexpansion.load_module(name)
|
2017-07-25 19:47:25 +02:00
|
|
|
if loaded_modules[name] ~= false then
|
|
|
|
local module_init = microexpansion.get_module_path(name).."/init.lua"
|
|
|
|
|
|
|
|
if module_init then
|
|
|
|
dofile(module_init)
|
|
|
|
loaded_modules[name] = true
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
microexpansion.log("Invalid module \""..name.."\". The module either does not exist "..
|
|
|
|
"or is missing an init.lua file.", "error")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
2017-02-15 04:35:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- [function] Require module (does not override modules.conf)
|
|
|
|
function microexpansion.require_module(name)
|
2017-07-25 19:47:25 +02:00
|
|
|
if settings[name] and settings[name] ~= false then
|
|
|
|
return microexpansion.load_module(name)
|
|
|
|
end
|
2017-02-15 04:35:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
for name,enabled in pairs(settings) do
|
2017-07-25 19:47:25 +02:00
|
|
|
if enabled ~= false then
|
|
|
|
microexpansion.load_module(name)
|
|
|
|
end
|
2017-02-15 04:35:06 +01:00
|
|
|
end
|