Rename yl_api_food to yl_api_nodestages

This commit is contained in:
AliasAlreadyTaken 2024-07-02 15:32:48 +02:00
parent 5abd47c7d6
commit c1260d0ada
11 changed files with 68 additions and 68 deletions

View File

@ -2,7 +2,7 @@ unused_args = false
allow_defined_top = true
globals = {
"yl_api_food",
"yl_api_nodestages",
"minetest.registered_nodes"
}

View File

@ -5,8 +5,8 @@ Copyright (c) 2024 Developername, Styxcolor
Code:
* [MIT](https://gitea.your-land.de/your-land/yl_api_food/src/LICENSE-MIT) Developername
* [MIT](https://gitea.your-land.de/your-land/yl_api_nodestages/src/LICENSE-MIT) Developername
Media:
* screenshot.png [CC0](https://gitea.your-land.de/your-land/yl_api_food/src/LICENSE-CC0) Styxcolor
* screenshot.png [CC0](https://gitea.your-land.de/your-land/yl_api_nodestages/src/LICENSE-CC0) Styxcolor

View File

@ -1,5 +1,5 @@
# yl_api_food
# yl_api_nodestages
## Purpose
@ -7,22 +7,22 @@ This mod is a library which brings various food-related functions.
## Download
Get it from https://gitea.your-land.de/your-land/yl_api_food
Get it from https://gitea.your-land.de/your-land/yl_api_nodestages
## Installation
1. Copy the "yl_api_food" folder to your mod directory.
1. Copy the "yl_api_nodestages" folder to your mod directory.
2. Enable the mod in your world.mt file.
## Configuration
```
yl_api_food.debug = false
yl_api_nodestages.debug = false
```
Set to true to enable debug mode
```
yl_api_food.maximum_stages
yl_api_nodestages.maximum_stages
```
Set this to the maximum stages your food can have.
@ -44,7 +44,7 @@ This is in parts a rewrite of [canned_food](https://github.com/h-v-smacker/canne
## Supported versions
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.
If you use yl_api_nodestages, but something is wrong, please [file a bug](https://gitea.your-land.de/your-land/yl_api_nodestages/issues/new). PRs also welcome.
There is no reason to believe it doesn't work anywhere, but you never know.
@ -56,7 +56,7 @@ Mods that depend on it will cease to work, if the mod is removed without proper
## License
See [LICENSE.md](https://gitea.your-land.de/your-land/yl_api_food/src/LICENSE.md)
See [LICENSE.md](https://gitea.your-land.de/your-land/yl_api_nodestages/src/LICENSE.md)
* Code MIT Developername
* Screenshot CC0 Styxcolor

34
api.lua
View File

@ -1,31 +1,31 @@
function yl_api_food.create_stage(modname, itemname, stages, overwrite)
function yl_api_nodestages.create_stage(modname, itemname, stages, overwrite)
-- Creates a single stage
end
function yl_api_food.add_stage(modname, itemname, stages, overwrite)
function yl_api_nodestages.add_stage(modname, itemname, stages, overwrite)
-- Adds a stage to an existing block
end
function yl_api_food.register_stages(stages, overwrite)
function yl_api_nodestages.register_stages(stages, overwrite)
-- defense
if ((type(overwrite) ~= "boolean") and (overwrite ~= nil)) then
return false,
yl_api_food.t("error_not_a_boolean_or_nil", dump(overwrite))
yl_api_nodestages.t("error_not_a_boolean_or_nil", dump(overwrite))
end
--[[ modname is now part of the stage and needs to be validated there
if (minetest.get_modpath(modname) ~= "string") then
return false, yl_api_food.t("error_not_a_mod", dump(modname))
return false, yl_api_nodestages.t("error_not_a_mod", dump(modname))
end]] --
if (type(stages) ~= "table") then
return false, yl_api_food.t("error_not_a_table", dump(stages))
return false, yl_api_nodestages.t("error_not_a_table", dump(stages))
end
if (yl_api_food.is_valid(stages) == false) then
return false, yl_api_food.t("error_not_a_valid_table", dump(stages))
if (yl_api_nodestages.is_valid(stages) == false) then
return false, yl_api_nodestages.t("error_not_a_valid_table", dump(stages))
end
-- payload
@ -63,7 +63,7 @@ function yl_api_food.register_stages(stages, overwrite)
if (((overwrite == false) or (overwrite == nil)) and
(minetest.registered_nodes[nodename] ~= nil)) then
-- No overwrite, but item exists
return false, yl_api_food.t("error_item_exists", dump(nodename))
return false, yl_api_nodestages.t("error_item_exists", dump(nodename))
end
-- MT properties
@ -76,30 +76,30 @@ function yl_api_food.register_stages(stages, overwrite)
-- node functions
if ((minetest.registered_nodes[nodename] == nil) or
(minetest.registered_nodes[nodename].on_timer)) then
node_definition.on_timer = yl_api_food.on_timer
node_definition.on_timer = yl_api_nodestages.on_timer
end
node_definition.on_construct = yl_api_food.on_construct
node_definition.on_destruct = yl_api_food.on_destruct
node_definition.on_construct = yl_api_nodestages.on_construct
node_definition.on_destruct = yl_api_nodestages.on_destruct
minetest.register_node(":" .. nodename, node_definition)
num_stages = num_stages + 1
end
return true, yl_api_food.t("success_changed_num_stages", dump(num_stages))
return true, yl_api_nodestages.t("success_changed_num_stages", dump(num_stages))
end
-- Overwrite
--
function yl_api_food.overwrite_stages(stages)
return yl_api_food.register_stages(stages, true)
function yl_api_nodestages.overwrite_stages(stages)
return yl_api_nodestages.register_stages(stages, true)
end
-- Delete
--
function yl_api_food.remove_stages(modname, itemname)
return yl_api_food.register_stages(modname, itemname, {}, true)
function yl_api_nodestages.remove_stages(modname, itemname)
return yl_api_nodestages.register_stages(modname, itemname, {}, true)
end

View File

@ -1,8 +1,8 @@
-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken.
yl_api_food.settings = {}
yl_api_nodestages.settings = {}
yl_api_food.settings.debug = minetest.settings:get("yl_api_food.debug") or true
yl_api_nodestages.settings.debug = minetest.settings:get("yl_api_nodestages.debug") or true
yl_api_food.settings.maximum_stages = minetest.settings:get("yl_api_food.maximum_stages") or 8
yl_api_nodestages.settings.maximum_stages = minetest.settings:get("yl_api_nodestages.maximum_stages") or 8

View File

@ -1,7 +1,7 @@
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"
yl_api_food.information.source = "https://gitea.your-land.de/your-land/yl_api_food"
yl_api_food.information.additional = yl_api_food.t("information_additional")
yl_api_nodestages.information = {}
yl_api_nodestages.information.version = "0.0.1"
yl_api_nodestages.information.author = "AliasAlreadyTaken"
yl_api_nodestages.information.license = "MIT"
yl_api_nodestages.information.name = "yl_api_nodestages"
yl_api_nodestages.information.source = "https://gitea.your-land.de/your-land/yl_api_nodestages"
yl_api_nodestages.information.additional = yl_api_nodestages.t("information_additional")

View File

@ -5,20 +5,20 @@
-- Changelog
local mod_start_time = minetest.get_us_time()
minetest.log("action", "[MOD] yl_api_food loading")
minetest.log("action", "[MOD] yl_api_nodestages loading")
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
yl_api_nodestages = {}
yl_api_nodestages.error = {}
yl_api_nodestages.modname = minetest.get_current_modname()
yl_api_nodestages.modstorage = minetest.get_mod_storage()
yl_api_nodestages.modpath = minetest.get_modpath("yl_api_nodestages") .. DIR_DELIM
yl_api_nodestages.worldpath = minetest.get_worldpath() .. DIR_DELIM
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_nodestages.modpath .. "texts.lua")
dofile(yl_api_nodestages.modpath .. "information.lua")
dofile(yl_api_nodestages.modpath .. "config.lua")
dofile(yl_api_nodestages.modpath .. "internal.lua")
dofile(yl_api_nodestages.modpath .. "api.lua")
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000
minetest.log("action", "[MOD] yl_api_food loaded in [" .. mod_end_time .. "s]")
minetest.log("action", "[MOD] yl_api_nodestages loaded in [" .. mod_end_time .. "s]")

View File

@ -1,21 +1,21 @@
-- 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_api_food.t("log_prefix", yl_api_food.modname, text)
if yl_api_food.settings.debug then minetest.log("action", logmessage) end
local logmessage = yl_api_nodestages.t("log_prefix", yl_api_nodestages.modname, text)
if yl_api_nodestages.settings.debug then minetest.log("action", logmessage) end
return logmessage
end
function yl_api_food.log(text) return log(text) end
function yl_api_nodestages.log(text) return log(text) end
local function remove_timer(pos)
local t = minetest.get_node_timer(pos)
t:stop()
end
function yl_api_food.remove_timer(pos) return remove_timer(pos) end
function yl_api_nodestages.remove_timer(pos) return remove_timer(pos) end
function yl_api_food.on_destruct(pos) return remove_timer(pos) end
function yl_api_nodestages.on_destruct(pos) return remove_timer(pos) end
local function on_construct(pos)
local node = minetest.get_node(pos)
@ -29,7 +29,7 @@ local function on_construct(pos)
-- Only add a nodetimer if the node does not yet have one
(minetest.registered_nodes[nodename].on_timer)) then
node_definition.on_timer = function(tpos, elapsed)
yl_api_food.on_timer(tpos, elapsed, stage.duration)
yl_api_nodestages.on_timer(tpos, elapsed, stage.duration)
end
end
@ -40,7 +40,7 @@ local function on_construct(pos)
end
end
function yl_api_food.on_construct(pos) return on_construct(pos) end
function yl_api_nodestages.on_construct(pos) return on_construct(pos) end
local function get_next_stage(next_stages)
local sum = 0
@ -52,7 +52,7 @@ local function get_next_stage(next_stages)
end
-- should never return this
return yl_api_food.error
return yl_api_nodestages.error
end
local function on_timer(pos, elapsed)
@ -91,9 +91,9 @@ local function on_timer(pos, elapsed)
end
function yl_api_food.on_timer(pos, elapsed) return on_timer(pos, elapsed) end
function yl_api_nodestages.on_timer(pos, elapsed) return on_timer(pos, elapsed) end
function yl_api_food.is_valid(stages)
function yl_api_nodestages.is_valid(stages)
-- TODO: Implement stages validation once we know how stages look like
return true
end
@ -124,7 +124,7 @@ function calc_duration(duration)
d_min = tonumber(duration)
d_max = tonumber(duration)
else
return yl_api_food.error
return yl_api_nodestages.error
end
assert((d_min >= 0) and (d_max >= 0) and ((d_max >= d_min)), "TODO: ERROR")
@ -132,4 +132,4 @@ function calc_duration(duration)
return {min = d_min, max = d_max}
end
function yl_api_food.calc_duration(duration) return calc_duration(duration) end
function yl_api_nodestages.calc_duration(duration) return calc_duration(duration) end

View File

@ -1,4 +1,4 @@
name = yl_api_food
name = yl_api_nodestages
description = A template with best practices
author = AliasAlreadyTaken
title = Template

View File

@ -3,9 +3,9 @@
# Debug
# Set this to true to enable debug mode, it will output some more values to log
# Optional, default is false
yl_api_food.debug (Debug mode) bool false
yl_api_nodestages.debug (Debug mode) bool false
# Maximum stages
# Set this to the maximum number of stages including seed
# Optional, default is 8
yl_api_food.max_stages (Maximum stages) int 8
yl_api_nodestages.max_stages (Maximum stages) int 8

View File

@ -1,9 +1,9 @@
local S = minetest.get_translator(yl_api_food.modname)
local S = minetest.get_translator(yl_api_nodestages.modname)
local texts = {}
--function yl_api_food.t(key, ...) return S(texts[key], ...) or "" end
function yl_api_food.t(key, ...) return string.format(texts[key], ...) or "" end
--function yl_api_nodestages.t(key, ...) return S(texts[key], ...) or "" end
function yl_api_nodestages.t(key, ...) return string.format(texts[key], ...) or "" end
-- Fixed texts