generated from your-land/yl_template
Planning
This commit is contained in:
parent
854a72f75c
commit
13470bea00
4
api.lua
Normal file
4
api.lua
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
yl_announcements.list_anncouncements
|
||||
|
||||
yl_announcements.get_announcement
|
5
init.lua
5
init.lua
@ -11,7 +11,7 @@ yl_announcements = {}
|
||||
yl_announcements.error = {}
|
||||
yl_announcements.modstorage = core.get_mod_storage()
|
||||
yl_announcements.modpath = core.get_modpath("yl_announcements") .. DIR_DELIM
|
||||
yl_announcements.worldpath = core.get_worldpath() .. DIR_DELIM
|
||||
-- yl_announcements.worldpath = core.get_worldpath() .. DIR_DELIM
|
||||
|
||||
yl_announcements.information = {}
|
||||
yl_announcements.information.version = "0.0.1"
|
||||
@ -23,11 +23,8 @@ yl_announcements.information.additional = "Displays messages once per timeframe.
|
||||
|
||||
dofile(yl_announcements.modpath .. "config.lua")
|
||||
dofile(yl_announcements.modpath .. "setup.lua")
|
||||
dofile(yl_announcements.modpath .. "privs.lua")
|
||||
dofile(yl_announcements.modpath .. "internal.lua")
|
||||
dofile(yl_announcements.modpath .. "api.lua")
|
||||
dofile(yl_announcements.modpath .. "distinct_feature.lua")
|
||||
dofile(yl_announcements.modpath .. "overwrite_feature.lua")
|
||||
dofile(yl_announcements.modpath .. "globalsteps.lua")
|
||||
dofile(yl_announcements.modpath .. "chatcommands.lua")
|
||||
|
||||
|
51
internal.lua
51
internal.lua
@ -1,53 +1,24 @@
|
||||
|
||||
-- The functions and variables in this file are only for use in the mod itself. Those that do real work should be local and wrapped in public functions
|
||||
|
||||
local debug = true
|
||||
|
||||
local function say(text)
|
||||
if yl_announcements.debug then
|
||||
core.log("action", "[MOD] yl_announcements : " .. text)
|
||||
end
|
||||
function yl_announcements.load_announcements()
|
||||
yl_announcements.data = minetest.parse_json(mod_storage:get_string("data")) or {}
|
||||
end
|
||||
|
||||
local function save_path(file)
|
||||
return yl_announcements.worldpath .. file .. ".json"
|
||||
function yl_announcements.save_announcements()
|
||||
mod_storage:set_string("data", minetest.write_json(yl_announcements.data))
|
||||
end
|
||||
|
||||
local function save_json(filename, content)
|
||||
if type(filename) ~= "string" or type(content) ~= "table" then
|
||||
return false
|
||||
end
|
||||
local savepath = save_path(filename)
|
||||
local savecontent = minetest.write_json(content)
|
||||
return minetest.safe_file_write(savepath, savecontent)
|
||||
end
|
||||
-- Chatcommands
|
||||
|
||||
yl_announcements.chatcommand_announcement_list
|
||||
|
||||
local function load_json(filename) -- returns the saved dialog
|
||||
local savepath = save_path(filename)
|
||||
yl_announcements.chatcommand_announcement_list_all
|
||||
|
||||
local file, err = io.open(savepath, "r")
|
||||
if err then
|
||||
return {}
|
||||
end
|
||||
io.input(file)
|
||||
local savecontent = io.read()
|
||||
local content = minetest.parse_json(savecontent)
|
||||
io.close(file)
|
||||
yl_announcements.chatcommand_announcement_delete
|
||||
|
||||
if type(content) ~= "table" then
|
||||
content = {}
|
||||
end
|
||||
yl_announcements.chatcommand_announcement_add
|
||||
|
||||
return content
|
||||
end
|
||||
yl_announcements.chatcommand_announcement_say
|
||||
|
||||
-- Public functions wrap the private ones, so they can be exchanged easily
|
||||
|
||||
function yl_announcements.load(filename, ...)
|
||||
return load_json(filename, ...)
|
||||
end
|
||||
|
||||
function yl_announcements.save(filename, content, ...)
|
||||
return save_json(filename, content, ...)
|
||||
end
|
||||
yl_announcements.chatcommand_announcement_say_all
|
16
setup.lua
16
setup.lua
@ -1,16 +1,8 @@
|
||||
|
||||
yl_announcements.data = {}
|
||||
|
||||
local function run_once()
|
||||
local dl = minetest.get_dir_list(yl_announcements.worldpath, true)
|
||||
local create = true
|
||||
|
||||
for _, v in ipairs(dl) do
|
||||
if v == yl_announcements.settings.save_path then
|
||||
create = false
|
||||
end
|
||||
end
|
||||
|
||||
if create then
|
||||
minetest.mkdir(yl_announcements.worldpath .. DIR_DELIM .. yl_announcements.settings.save_path)
|
||||
end
|
||||
yl_announcements.data = minetest.parse_json(yl_announcements.modstorage:get_string("data")) or {}
|
||||
end
|
||||
|
||||
run_once()
|
||||
|
Loading…
Reference in New Issue
Block a user