Adds api example, initialze and documentation

This commit is contained in:
AliasAlreadyTaken 2024-05-12 12:14:16 +02:00
parent 04555390ae
commit 1eb5401191
4 changed files with 37 additions and 3 deletions

28
api.lua Normal file
View File

@ -0,0 +1,28 @@
-- Use this file for functions that can be called from other mods
-- Make sure the functions are well defended against wrong input and
-- document them on the readme, what they do, what types and values
-- they expect as parameters and what types and values they return.
-- If you ever change those, consider adding backwards compatibility,
-- since other mods may rely on them.
function yl_template.some_api_call(target, message, color)
if (type(target) ~= "string") then return false, "Target not a string" end
if (minetest.get_player_by_name(target) == nil) then
return false, "Target not an online player"
end
if (type(message) ~= "string") then return false, "Nessage not a string" end
-- is_color(color) does not exist, you need to implement it if you want to use it
if (is_color(color) == false) then return false, "color not a ColorSpec" end
if (minetest.colorize == nil) then
return false, "minetest.colorize not available"
end
local message_with_color = minetest.colorize(color, message)
minetest.chat_send_player(target, message_with_color)
return true, "Sent " .. message_with_color .. " to " .. target
end

View File

@ -1,7 +1,9 @@
-- Use this file to initialize variables once after server start and check everything is in place
local function run_each_serverstart() local function run_each_serverstart()
yl_template.data = {} yl_template.data = {}
--minetest.after(0.0, yl_template.load_all_data) --minetest.on_mods_loaded(0.0, yl_template.on_mods_loaded)
--minetest.after(0.0, yl_template.check_privs) --minetest.after(0.0, yl_template.after)
end end
run_each_serverstart() run_each_serverstart()

View File

@ -2,7 +2,7 @@
-- Those that do real work should be local and wrapped in public functions -- Those that do real work should be local and wrapped in public functions
local function say(text) local function say(text)
if yl_template.debug then if yl_template.settings.debug then
core.log("action", "[MOD] yl_template : " .. text) core.log("action", "[MOD] yl_template : " .. text)
end end
end end

View File

@ -1,3 +1,7 @@
-- Use this file to set up folder and variables once after installation of the mod
-- Afterwards you could disable this part of the code or set a variable that tells
-- this code not to run again
local mkdir = minetest.mkdir local mkdir = minetest.mkdir
local save_path = yl_template.settings.save_path local save_path = yl_template.settings.save_path