commit b1f6ea57ef42b4e5e798c4be607f7231f9a71c66 Author: your-flight <> Date: Wed Apr 20 16:00:41 2022 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..282e624 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ + +# yl_template + +## Purpose + +This mod is not meant to bring functionality by itself, but to serve as a template you can base your mod on. + +## Download + +Get it from https://gitea.your-land.de/your-land/yl_template + +## Installation + +Being a template, you shouldn't install the mod itself. Your mod could look like this: + + + +## Usage +## Uninstall +## License + diff --git a/chatcommand_admin.lua b/chatcommand_admin.lua new file mode 100644 index 0000000..fbc90e3 --- /dev/null +++ b/chatcommand_admin.lua @@ -0,0 +1,19 @@ +local chatcommand_cmd = "admin_example" +local chatcommand_definition = { + params = " ", -- Short parameter description + description = "Example description", -- Full description + privs = {[yl_template.admin_priv] = true}, -- Require the "privs" privilege to run + func = function(name, param) + local success = true + if success then + return true, "Sucess message" + else + return false, "Fail message" + end + end + -- Called when command is run. Returns boolean success and text output. + -- Special case: The help message is shown to the player if `func` + -- returns false without a text output. +} + +minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) diff --git a/chatcommand_player.lua b/chatcommand_player.lua new file mode 100644 index 0000000..90a426a --- /dev/null +++ b/chatcommand_player.lua @@ -0,0 +1,19 @@ +local chatcommand_cmd = "player_example" +local chatcommand_definition = { + params = " ", -- Short parameter description + description = "Example description", -- Full description + privs = {privs = true}, -- Require the "privs" privilege to run + func = function(name, param) + local success = true + if success then + return true, "Sucess message" + else + return false, "Fail message" + end + end + -- Called when command is run. Returns boolean success and text output. + -- Special case: The help message is shown to the player if `func` + -- returns false without a text output. +} + +minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) diff --git a/chatcommands.lua b/chatcommands.lua new file mode 100644 index 0000000..89cd404 --- /dev/null +++ b/chatcommands.lua @@ -0,0 +1,2 @@ +dofile(yl_template.modpath .. "chatcommand_admin.lua") +dofile(yl_template.modpath .. "chatcommand_player.lua") \ No newline at end of file diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..a8a6bf2 --- /dev/null +++ b/config.lua @@ -0,0 +1,8 @@ + +-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken. + +yl_template.external_value = "mod_default" or minetest.settings:get("yl_template.external_value") or "default" + +yl_template.save_path = "yl_template" or minetest.settings:get("yl_template.save_path") or "default" + +yl_template.admin_priv = "admin_priv" or minetest.settings:get("yl_template.admin_priv") or "server" \ No newline at end of file diff --git a/dev/whatdowedo.txt b/dev/whatdowedo.txt new file mode 100644 index 0000000..5ca6f6f --- /dev/null +++ b/dev/whatdowedo.txt @@ -0,0 +1,4 @@ +This file holds a couple of editors notes regarding the mod. + +Todo's can be noted here, known issues, the path to ressources or general annotations. + diff --git a/globalsteps.lua b/globalsteps.lua new file mode 100644 index 0000000..8d22fe3 --- /dev/null +++ b/globalsteps.lua @@ -0,0 +1,13 @@ +local timer = 0 + +local gs = function(dtime) + timer = timer + dtime + if timer <= yl_template.config.interval then + return + end + timer = 0 + + -- do stuff +end + +minetest.register_globalstep(gs) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..7c30bbd --- /dev/null +++ b/init.lua @@ -0,0 +1,35 @@ +-- Version 0.0.1 +-- Author AliasAlreadyTaken +-- License MIT + +-- Changelog + +local mod_start_time = core.get_us_time() +core.log("action", "[MOD] yl_template loading") + +yl_template = {} +yl_template.error = {} +yl_template.modstorage = core.get_mod_storage() +yl_template.modpath = core.get_modpath("yl_template") .. DIR_DELIM +yl_template.worldpath = core.get_worldpath() .. DIR_DELIM + +yl_template.information = {} +yl_template.information.version = "0.0.1" +yl_template.information.author = "AliasAlreadyTaken" +yl_template.information.license = "MIT" +yl_template.information.name = "yl_template" +yl_template.information.source = "https://gitea.your-land.de/your-land/yl_template" +yl_template.information.additional = "Additional information" + +dofile(yl_template.modpath .. "config.lua") +dofile(yl_template.modpath .. "setup.lua") +dofile(yl_template.modpath .. "privs.lua") +dofile(yl_template.modpath .. "internal.lua") +dofile(yl_template.modpath .. "api.lua") +dofile(yl_template.modpath .. "distinct_feature.lua") +dofile(yl_template.modpath .. "overwrite_feature.lua") +dofile(yl_template.modpath .. "globalsteps.lua") +dofile(yl_template.modpath .. "chatcommands.lua") + +local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000 +core.log("action", "[MOD] yl_template loaded in [" .. mod_end_time .. "s]") diff --git a/internal.lua b/internal.lua new file mode 100644 index 0000000..54856da --- /dev/null +++ b/internal.lua @@ -0,0 +1,53 @@ + +-- 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_template.debug then + core.log("action", "[MOD] yl_template : " .. text) + end +end + +local function save_path(file) + return yl_template.worldpath .. file .. ".json" +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 + + +local function load_json(filename) -- returns the saved dialog + local savepath = save_path(filename) + + 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) + + if type(content) ~= "table" then + content = {} + end + + return content +end + +-- Public functions wrap the private ones, so they can be exchanged easily + +function yl_template.load(filename, ...) + return load_json(filename, ...) +end + +function yl_template.save(filename, content, ...) + return save_json(filename, content, ...) +end \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..58188ed --- /dev/null +++ b/mod.conf @@ -0,0 +1,7 @@ +name = yl_template +description = A template with best practices +depends = default +optional_depends = moreblocks +author = AliasAlreadyTaken +release = 202106161537 +title = Template \ No newline at end of file diff --git a/priv_example.lua b/priv_example.lua new file mode 100644 index 0000000..75392cc --- /dev/null +++ b/priv_example.lua @@ -0,0 +1,58 @@ +local priv_name = "example" +local priv_definition = { + description = "Can do example task", + -- Privilege description + + give_to_singleplayer = false, + -- Whether to grant the privilege to singleplayer. + + give_to_admin = true, + -- Whether to grant the privilege to the server admin. + -- Uses value of 'give_to_singleplayer' by default. + + on_grant = function(name, granter_name) + -- logging + if not granter_name then + granter_name = "MOD" + end + if not name then + name = "ERROR" + end + if not priv_name then + priv_name = "ERROR" + end + core.log( + "action", + "[MOD] yl_template: User " .. granter_name .. " granted user " .. name .. " priv " .. priv_name + ) + end, + -- Called when given to player 'name' by 'granter_name'. + -- 'granter_name' will be nil if the priv was granted by a mod. + + on_revoke = function(name, revoker_name) + -- logging + if not revoker_name then + revoker_name = "MOD" + end + if not name then + name = "ERROR" + end + if not priv_name then + priv_name = "ERROR" + end + core.log( + "action", + "[MOD] yl_template: User " .. revoker_name .. " revoked user " .. name .. " priv " .. priv_name + ) + end + -- Called when taken from player 'name' by 'revoker_name'. + -- 'revoker_name' will be nil if the priv was revoked by a mod. + + -- Note that the above two callbacks will be called twice if a player is + -- responsible, once with the player name, and then with a nil player + -- name. + -- Return true in the above callbacks to stop register_on_priv_grant or + -- revoke being called. +} + +minetest.register_privilege(priv_name, priv_definition) diff --git a/privs.lua b/privs.lua new file mode 100644 index 0000000..8d26d4e --- /dev/null +++ b/privs.lua @@ -0,0 +1 @@ +dofile(yl_template.modpath .. "priv_example.lua") \ No newline at end of file diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..fedca9a Binary files /dev/null and b/screenshot.png differ diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..61368ba --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,6 @@ +[category] + +# First line: Name the settings +# Second line: Say what it does, how to use it, what it changes +# Third line: Is it optional? What's the default value? Does it expect a certain set of values? +yl_template.external_value (Description of the setting) string "default_value" diff --git a/setup.lua b/setup.lua new file mode 100644 index 0000000..494602d --- /dev/null +++ b/setup.lua @@ -0,0 +1,16 @@ +local function run_once() + local dl = minetest.get_dir_list(yl_template.worldpath, true) + local create = true + + for _, v in ipairs(dl) do + if v == yl_template.save_path then + create = false + end + end + + if create then + minetest.mkdir(yl_template.worldpath .. DIR_DELIM .. yl_template.save_path) + end +end + +run_once()