From df50af0a8ca8a5cbac038a48218b1bfaf5797be0 Mon Sep 17 00:00:00 2001 From: AliasAlreadyTaken Date: Wed, 12 Jun 2024 17:54:39 +0200 Subject: [PATCH] Renames mod to yl_api_food --- LICENSE.md | 2 +- README.md | 14 +++++++------- api.lua | 14 +++++++------- chatcommand_admin.lua | 10 +++++----- chatcommand_player.lua | 8 ++++---- chatcommands.lua | 4 ++-- config.lua | 8 ++++---- globalsteps.lua | 2 +- information.lua | 14 +++++++------- init.lua | 35 +++++++++++++++-------------------- initialize.lua | 6 +++--- internal.lua | 20 ++++++++++---------- mod.conf | 2 +- priv_example.lua | 34 +++++++++++++++++----------------- privs.lua | 2 +- settingtypes.txt | 2 +- setup.lua | 4 ++-- texts.lua | 21 +++------------------ 18 files changed, 91 insertions(+), 111 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 32f0563..250077a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -9,4 +9,4 @@ Code: Media: -* screenshot.png [CC0](https://gitea.your-land.de/your-land/yl_template/src/LICENSE-CC0) Styxcolor +* screenshot.png [CC0](https://gitea.your-land.de/your-land/yl_api_food/src/LICENSE-CC0) Styxcolor diff --git a/README.md b/README.md index b60ac44..5648a6b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# yl_template +# yl_api_food ## Purpose @@ -7,22 +7,22 @@ This mod is not meant to bring functionality by itself, but to serve as a templa ## Download -Get it from https://gitea.your-land.de/your-land/yl_template +Get it from https://gitea.your-land.de/your-land/yl_api_food ## Installation -1. Copy the "yl_template" folder to your mod directory. +1. Copy the "yl_api_food" folder to your mod directory. 2. Enable the mod in your world.mt file. ## Configuration ``` -yl_template.debug = false +yl_api_food.debug = false ``` Set to true to enable debug mode ``` -yl_template.save_path +yl_api_food.save_path ``` Set this to where in the worldfolder you want the JSON files stored. @@ -41,7 +41,7 @@ Use the following public functions to `[achieve your goals]` ## 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. +If you use yl_api_food, but something is wrong, please [file a bug](https://gitea.your-land.de/your-land/yl_api_food/issues/new). PRs also welcome. There is no reason to believe it doesn't work anywhere, but you never know. @@ -59,7 +59,7 @@ Mods that depend on it will cease to work, if the mod is removed without proper [Shorthand of your chosen license: MIT, LGPLv3+, GPLv3+, AGPL, ...]. Please choose one of the major license that is compatible with as much of the MT universe over some obscure and incompatible license. If you use the screenshot.png, keep Styxcolor in there because she made that screenshot.png, if you add your own, replace the line with whoever made it. Example for MIT and CC0: -See [LICENSE.md](https://gitea.your-land.de/your-land/yl_template/src/LICENSE.md) +See [LICENSE.md](https://gitea.your-land.de/your-land/yl_api_food/src/LICENSE.md) * Code MIT Developername * Screenshot CC0 Styxcolor diff --git a/api.lua b/api.lua index 097b053..c73ab03 100644 --- a/api.lua +++ b/api.lua @@ -4,31 +4,31 @@ -- 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) +function yl_api_food.some_api_call(target, message, color) if (type(target) ~= "string") then - return false, yl_template.t("error_not_a_string", "target") + return false, yl_api_food.t("error_not_a_string", "target") end if (minetest.get_player_by_name(target) == nil) then - return false, yl_template.t("error_player_not_online", target) + return false, yl_api_food.t("error_player_not_online", target) end if (type(message) ~= "string") then - return false, yl_template.t("error_not_a_string", "message") + return false, yl_api_food.t("error_not_a_string", "message") 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, yl_template.t("error_not_a_colorspec", "color") + return false, yl_api_food.t("error_not_a_colorspec", "color") end if (minetest.colorize == nil) then - return false, yl_template.t("error_function_not_available", + return false, yl_api_food.t("error_function_not_available", "minetest.colorize") end local message_with_color = minetest.colorize(color, message) minetest.chat_send_player(target, message_with_color) - return true, yl_template.t("api_sent_x_to_y", message_with_color, target) + return true, yl_api_food.t("api_sent_x_to_y", message_with_color, target) end diff --git a/chatcommand_admin.lua b/chatcommand_admin.lua index 122faa4..3d2240a 100644 --- a/chatcommand_admin.lua +++ b/chatcommand_admin.lua @@ -1,14 +1,14 @@ local chatcommand_cmd = "admin_example" local chatcommand_definition = { - params = yl_template.t("chatcommand_admin_parameters"), -- Short parameter description - description = yl_template.t("chatcommand_admin_description"), -- Full description - privs = {[yl_template.settings.admin_priv] = true}, -- Require the "privs" privilege to run + params = yl_api_food.t("chatcommand_admin_parameters"), -- Short parameter description + description = yl_api_food.t("chatcommand_admin_description"), -- Full description + privs = {[yl_api_food.settings.admin_priv] = true}, -- Require the "privs" privilege to run func = function(name, param) local success = true if success then - return true, yl_template.t("chatcommand_admin_success_message") + return true, yl_api_food.t("chatcommand_admin_success_message") else - return false, yl_template.t("chatcommand_admin_fail_message") + return false, yl_api_food.t("chatcommand_admin_fail_message") end end -- Called when command is run. Returns boolean success and text output. diff --git a/chatcommand_player.lua b/chatcommand_player.lua index 7280abf..a8dadcc 100644 --- a/chatcommand_player.lua +++ b/chatcommand_player.lua @@ -1,14 +1,14 @@ local chatcommand_cmd = "player_example" local chatcommand_definition = { - params = yl_template.t("chatcommand_player_parameters"), -- Short parameter description - description = yl_template.t("chatcommand_player_parameters"), -- Full description + params = yl_api_food.t("chatcommand_player_parameters"), -- Short parameter description + description = yl_api_food.t("chatcommand_player_parameters"), -- Full description privs = {privs = true}, -- Require the "privs" privilege to run func = function(name, param) local success = true if success then - return true, yl_template.t("chatcommand_player_parameters") + return true, yl_api_food.t("chatcommand_player_parameters") else - return false, yl_template.t("chatcommand_player_parameters") + return false, yl_api_food.t("chatcommand_player_parameters") end end -- Called when command is run. Returns boolean success and text output. diff --git a/chatcommands.lua b/chatcommands.lua index 89cd404..0778961 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -1,2 +1,2 @@ -dofile(yl_template.modpath .. "chatcommand_admin.lua") -dofile(yl_template.modpath .. "chatcommand_player.lua") \ No newline at end of file +dofile(yl_api_food.modpath .. "chatcommand_admin.lua") +dofile(yl_api_food.modpath .. "chatcommand_player.lua") \ No newline at end of file diff --git a/config.lua b/config.lua index b42cdf3..00a6f6e 100644 --- a/config.lua +++ b/config.lua @@ -1,10 +1,10 @@ -- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken. -yl_template.settings = {} +yl_api_food.settings = {} -yl_template.settings.external_value = "mod_default" or minetest.settings:get("yl_template.external_value") or "default" +yl_api_food.settings.external_value = "mod_default" or minetest.settings:get("yl_api_food.external_value") or "default" -yl_template.settings.save_path = "yl_template" or minetest.settings:get("yl_template.save_path") or "default" +yl_api_food.settings.save_path = "yl_api_food" or minetest.settings:get("yl_api_food.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 +yl_api_food.settings.admin_priv = "admin_priv" or minetest.settings:get("yl_api_food.admin_priv") or "server" \ No newline at end of file diff --git a/globalsteps.lua b/globalsteps.lua index 8d22fe3..f505b6d 100644 --- a/globalsteps.lua +++ b/globalsteps.lua @@ -2,7 +2,7 @@ local timer = 0 local gs = function(dtime) timer = timer + dtime - if timer <= yl_template.config.interval then + if timer <= yl_api_food.config.interval then return end timer = 0 diff --git a/information.lua b/information.lua index f5dc1f8..a2917ca 100644 --- a/information.lua +++ b/information.lua @@ -1,7 +1,7 @@ -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" -- Name of the mod -yl_template.information.source = "https://gitea.your-land.de/your-land/yl_template" -yl_template.information.additional = yl_template.t("information_additional") +yl_api_food.information = {} +yl_api_food.information.version = "0.0.1" +yl_api_food.information.author = "AliasAlreadyTaken" +yl_api_food.information.license = "MIT" +yl_api_food.information.name = "yl_api_food" -- Name of the mod +yl_api_food.information.source = "https://gitea.your-land.de/your-land/yl_api_food" +yl_api_food.information.additional = yl_api_food.t("YL Food API") diff --git a/init.lua b/init.lua index 20741c2..86f9c58 100644 --- a/init.lua +++ b/init.lua @@ -5,27 +5,22 @@ -- Changelog local mod_start_time = minetest.get_us_time() -minetest.log("action", "[MOD] yl_template loading") +minetest.log("action", "[MOD] yl_api_food loading") -yl_template = {} -yl_template.error = {} -yl_template.modname = minetest.get_current_modname() -yl_template.modstorage = minetest.get_mod_storage() -yl_template.modpath = minetest.get_modpath("yl_template") .. DIR_DELIM -yl_template.worldpath = minetest.get_worldpath() .. DIR_DELIM +yl_api_food = {} +yl_api_food.error = {} +yl_api_food.modname = minetest.get_current_modname() +yl_api_food.modstorage = minetest.get_mod_storage() +yl_api_food.modpath = minetest.get_modpath("yl_api_food") .. DIR_DELIM +yl_api_food.worldpath = minetest.get_worldpath() .. DIR_DELIM -dofile(yl_template.modpath .. "texts.lua") -dofile(yl_template.modpath .. "information.lua") -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") +dofile(yl_api_food.modpath .. "texts.lua") +dofile(yl_api_food.modpath .. "information.lua") +dofile(yl_api_food.modpath .. "config.lua") + +dofile(yl_api_food.modpath .. "internal.lua") +dofile(yl_api_food.modpath .. "api.lua") +dofile(yl_api_food.modpath .. "initialize.lua") local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000 -minetest.log("action", "[MOD] yl_template loaded in [" .. mod_end_time .. "s]") +minetest.log("action", "[MOD] yl_api_food loaded in [" .. mod_end_time .. "s]") diff --git a/initialize.lua b/initialize.lua index 1eed203..3e7559d 100644 --- a/initialize.lua +++ b/initialize.lua @@ -1,9 +1,9 @@ -- Use this file to initialize variables once after server start and check everything is in place local function run_each_serverstart() - yl_template.data = {} - --minetest.on_mods_loaded(0.0, yl_template.on_mods_loaded) - --minetest.after(0.0, yl_template.after) + yl_api_food.data = {} + --minetest.on_mods_loaded(0.0, yl_api_food.on_mods_loaded) + --minetest.after(0.0, yl_api_food.after) end run_each_serverstart() diff --git a/internal.lua b/internal.lua index 9a2581f..8e43f72 100644 --- a/internal.lua +++ b/internal.lua @@ -1,22 +1,22 @@ -- 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 log(text) - local logmessage = yl_template.t("log_prefix", yl_template.modname, text) - if yl_template.settings.debug then minetest.log("action", logmessage) end + local logmessage = yl_api_food.t("log_prefix", yl_api_food.modname, text) + if yl_api_food.settings.debug then minetest.log("action", logmessage) end return logmessage end -function yl_template.log(text) return log(text) end +function yl_api_food.log(text) return log(text) end local function get_savepath() - local savepath = yl_template.worldpath .. yl_template.settings.save_path - log(yl_template.t("log_prefix", dump(savepath))) + local savepath = yl_api_food.worldpath .. yl_api_food.settings.save_path + log(yl_api_food.t("log_prefix", dump(savepath))) return savepath end local function get_filepath(filename) local path_to_file = get_savepath() .. DIR_DELIM .. filename .. ".json" - log(yl_template.t("get_filepath", dump(filename), dump(path_to_file))) + log(yl_api_food.t("get_filepath", dump(filename), dump(path_to_file))) return path_to_file end @@ -32,14 +32,14 @@ end local function load_json(path) local file = io.open(path, "r") if not file then - return false, yl_template.t("error_cannot_open_file", dump(path)) + return false, yl_api_food.t("error_cannot_open_file", dump(path)) end local content = file:read("*all") file:close() if not content then - return false, yl_template.t("error_cannot_read_file", dump(path)) + return false, yl_api_food.t("error_cannot_read_file", dump(path)) end return true, minetest.parse_json(content) @@ -47,8 +47,8 @@ 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_api_food.load(filename, ...) return load_json(filename, ...) end -function yl_template.save(filename, content, ...) +function yl_api_food.save(filename, content, ...) return save_json(filename, content, ...) end diff --git a/mod.conf b/mod.conf index 678958b..99ae6d3 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ -name = yl_template +name = yl_api_food description = A template with best practices depends = default optional_depends = moreblocks diff --git a/priv_example.lua b/priv_example.lua index 7cfa4ce..ee6e8d8 100644 --- a/priv_example.lua +++ b/priv_example.lua @@ -1,6 +1,6 @@ local priv_name = "example" local priv_definition = { - description = yl_template.t("privs_example_description"), + description = yl_api_food.t("privs_example_description"), -- Privilege description give_to_singleplayer = false, @@ -13,27 +13,27 @@ local priv_definition = { on_grant = function(name, granter_name) -- logging if (type(granter_name) ~= "string") then - local errormessage = yl_template.t("error_name_not_found", + local errormessage = yl_api_food.t("error_name_not_found", dump(granter_name)) - yl_template.log(errormessage) + yl_api_food.log(errormessage) return false, errormessage end if not name then - local errormessage = yl_template.t("error_name_not_found", + local errormessage = yl_api_food.t("error_name_not_found", dump(name)) - yl_template.log(errormessage) + yl_api_food.log(errormessage) return false, errormessage end if not priv_name then - local errormessage = yl_template.t("error_priv_not_found", + local errormessage = yl_api_food.t("error_priv_not_found", dump(priv_name)) - yl_template.log(errormessage) + yl_api_food.log(errormessage) return false, errormessage end - local text = yl_template.t("privs_example_grant_logmessage", + local text = yl_api_food.t("privs_example_grant_logmessage", dump(granter_name), dump(priv_name), dump(name)) - yl_template.log(text) + yl_api_food.log(text) end, -- Called when given to player 'name' by 'granter_name'. -- 'granter_name' will be nil if the priv was granted by a mod. @@ -41,27 +41,27 @@ local priv_definition = { on_revoke = function(name, revoker_name) -- logging if (type(revoker_name) ~= "string") then - local errormessage = yl_template.t("error_name_not_found", + local errormessage = yl_api_food.t("error_name_not_found", dump(revoker_name)) - yl_template.log(errormessage) + yl_api_food.log(errormessage) return false, errormessage end if not name then - local errormessage = yl_template.t("error_name_not_found", + local errormessage = yl_api_food.t("error_name_not_found", dump(name)) - yl_template.log(errormessage) + yl_api_food.log(errormessage) return false, errormessage end if not priv_name then - local errormessage = yl_template.t("error_priv_not_found", + local errormessage = yl_api_food.t("error_priv_not_found", dump(priv_name)) - yl_template.log(errormessage) + yl_api_food.log(errormessage) return false, errormessage end - local text = yl_template.t("privs_example_revoke_logmessage", + local text = yl_api_food.t("privs_example_revoke_logmessage", dump(revoker_name), dump(priv_name), dump(name)) - yl_template.log(text) + yl_api_food.log(text) end -- Called when taken from player 'name' by 'revoker_name'. -- 'revoker_name' will be nil if the priv was revoked by a mod. diff --git a/privs.lua b/privs.lua index 8d26d4e..1bb9b35 100644 --- a/privs.lua +++ b/privs.lua @@ -1 +1 @@ -dofile(yl_template.modpath .. "priv_example.lua") \ No newline at end of file +dofile(yl_api_food.modpath .. "priv_example.lua") \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt index 61368ba..b28daa4 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -3,4 +3,4 @@ # 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" +yl_api_food.external_value (Description of the setting) string "default_value" diff --git a/setup.lua b/setup.lua index b9767d2..54b2554 100644 --- a/setup.lua +++ b/setup.lua @@ -3,10 +3,10 @@ -- this code not to run again local mkdir = minetest.mkdir -local save_path = yl_template.settings.save_path +local save_path = yl_api_food.settings.save_path local function run_once() - local path = yl_template.worldpath .. DIR_DELIM .. save_path + local path = yl_api_food.worldpath .. DIR_DELIM .. save_path local file = io.open(path, "r") if not file then mkdir(path) diff --git a/texts.lua b/texts.lua index 4ae57fb..d34783d 100644 --- a/texts.lua +++ b/texts.lua @@ -1,8 +1,8 @@ -local S = minetest.get_translator(yl_template.modname) +local S = minetest.get_translator(yl_api_food.modname) local texts = {} -function yl_template.t(key, ...) return S(texts[key], ...) or "" end +function yl_api_food.t(key, ...) return S(texts[key], ...) or "" end -- Fixed texts @@ -13,25 +13,10 @@ texts["get_filepath"] = "get_filepath : @1" -- Translateable texts -texts["information_additional"] = "Additional information" - -texts["chatcommand_admin_description"] = "Admin Chatcommand description" -texts["chatcommand_admin_parameters"] = " " -texts["chatcommand_admin_success_message"] = "Sucess message" -texts["chatcommand_admin_fail_message"] = "Fail message" - -texts["chatcommand_player_description"] = "Player Chatcommand description" -texts["chatcommand_player_parameters"] = " " -texts["chatcommand_player_success_message"] = "Sucess message" -texts["chatcommand_player_fail_message"] = "Fail message" +texts["information_additional"] = "" texts["api_sent_x_to_y"] = "Sent @1 to @2" -texts["privs_example_description"] = "Can do example task" -texts["privs_example_grant_logmessage"] = "User @1 granted priv @2 to user @3" -texts["privs_example_revoke_logmessage"] = - "User @1 revoked priv @2 from user @3" - -- Errormessages texts["error_not_a_string"] = "@1 not a string"