commit b6a3a9a7529bf6db7403ec3e51a3f110be8cd08e Author: AliasAlreadyTaken Date: Sun May 12 09:37:39 2024 +0000 Initial commit diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..83b7697 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,19 @@ +unused_args = false +allow_defined_top = true + +globals = { + "minetest", + "core" +} + +read_globals = { + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + + -- Builtin + "vector", "ItemStack", + "dump", "DIR_DELIM", "VoxelArea", "Settings", + + -- MTG + "default", "sfinv", "creative", +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..3b1e806 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ + +# 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. Remove the components you do not want and expand on those you want. + +## Download + +Get it from https://gitea.your-land.de/your-land/yl_template + +## Installation + +1. Copy the "yl_template" folder to your mod directory. +2. Enable the mod in your world.mt file. + +## Configuration + +``` +yl_template.debug = false +``` +Set to true to enable debug mode + +``` +yl_template.save_path +``` +Set this to where in the worldfolder you want the JSON files stored. + +## Usage + +This mod targets $[servers|singleplayer|...], but should work in $[[servers|singleplayer|...], too. It comes with no direct content but exposes functions you can use in your mod. + +### Chatcommands + + +### Modmakers + +Use the following public functions to $[achieve your goals] + +## Limitations +## Alternatives +## Supported versions + +If you use yl_template, but something is wrong, please [file a bug](https://gitea.your-land.de/your-land/yl_template/issues/new). PRs also welcome. + +There is no reason to believe it doesn't work anywhere, but you never know. + +## Allied projects + +If you know a project that uses this mod tell us and we will add it to the list. + +## Uninstall + +Remove it from your mod folder or deactivate it in your world.mt + +Mods that depend on it will cease to work, if the mod is removed without proper replacement. + +## License + +[Shorthand of your chosen license: MIT, LGPLv3+, GPLv3+, AGPL, ...]. Please chose one of the major license that is compatible with as much of the MT universe over some obscure and incompatible license. + +## Thank you diff --git a/chatcommand_admin.lua b/chatcommand_admin.lua new file mode 100644 index 0000000..b274f80 --- /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.settings.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..b42cdf3 --- /dev/null +++ b/config.lua @@ -0,0 +1,10 @@ + +-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken. + +yl_template.settings = {} + +yl_template.settings.external_value = "mod_default" or minetest.settings:get("yl_template.external_value") or "default" + +yl_template.settings.save_path = "yl_template" or minetest.settings:get("yl_template.save_path") or "default" + +yl_template.settings.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..e2fac4b --- /dev/null +++ b/init.lua @@ -0,0 +1,36 @@ +-- 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 .. "initialize.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/initialize.lua b/initialize.lua new file mode 100644 index 0000000..473fbe9 --- /dev/null +++ b/initialize.lua @@ -0,0 +1,7 @@ +local function run_each_serverstart() + yl_template.data = {} + --minetest.after(0.0, yl_template.load_all_data) + --minetest.after(0.0, yl_template.check_privs) +end + +run_each_serverstart() diff --git a/internal.lua b/internal.lua new file mode 100644 index 0000000..7dacb5f --- /dev/null +++ b/internal.lua @@ -0,0 +1,49 @@ +-- 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 function say(text) + if yl_template.debug then + core.log("action", "[MOD] yl_template : " .. text) + end +end + +local function get_savepath() + local savepath = yl_template.worldpath .. yl_template.settings.save_path + say("get_savepath : " .. dump(savepath)) + return savepath +end + +local function get_filepath(filename) + local path_to_file = get_savepath() .. DIR_DELIM .. filename .. ".json" + say("get_filepath : " .. dump(filename) .. ":" .. dump(path_to_file)) + return path_to_file +end + +local function save_json(filename, content) + if type(filename) ~= "string" or type(content) ~= "table" then + return false + end + local savepath = get_filepath(filename) + local savecontent = minetest.write_json(content) + return minetest.safe_file_write(savepath, savecontent) +end + +local function load_json(path) + local file = io.open(path, "r") + if not file then return false, "Error opening file: " .. path end + + local content = file:read("*all") + file:close() + + if not content then return false, "Error reading file: " .. path end + + return true, minetest.parse_json(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 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..3695312 --- /dev/null +++ b/setup.lua @@ -0,0 +1,15 @@ +local mkdir = minetest.mkdir +local save_path = yl_template.settings.save_path + +local function run_once() + local path = yl_template.worldpath .. DIR_DELIM .. save_path + local file = io.open(path, "r") + if not file then + mkdir(path) + else + file:close() + end + +end + +run_once()