Extends API to allow redefinition of "Node dug" display

This commit is contained in:
Louis 2020-08-11 16:01:59 +02:00
parent 39ba44bca2
commit bb02ed7095
6 changed files with 59 additions and 8 deletions

@ -12,11 +12,14 @@ This mod also adds an API to register new types of tools for toolranks.
--[[
-- `keyword` is a string to be detected in tool description
-- `tool_type` is a localized tool type (if nil, then unregister the keyword)
-- `node_dug_display` is an (optional) alternative localized display
-- of "Node Dug" (if false, then unregister the display)
--]]
toolranks_extras.register_tool_type(keyword, tool_type)
toolranks_extras.register_tool_type(keyword, tool_type, [node_dug_display])
-- example
toolranks_extras.register_tool_type("battle_axe", S("battle axe"))
toolranks_extras.register_tool_type("bow", S("bow"), S("Arrows thrown"))
```
![Screenshot](screenshot.png)

@ -3,7 +3,7 @@ local MP = minetest.get_modpath("toolranks_extras")
toolranks_extras = {}
-- mod information
toolranks_extras.mod = {version = "1.4.0", author = "Louis Royer"}
toolranks_extras.mod = {version = "1.4.1", author = "Louis Royer"}
-- settings
toolranks_extras.settings = {

6
locale/template.txt Normal file

@ -0,0 +1,6 @@
# textdomain: toolranks_extras
### tool_types.lua ###
@1@2@n@3Level @4 @5@n@6@7: @8=

@ -0,0 +1,6 @@
# textdomain: toolranks_extras
### tool_types.lua ###
@1@2@n@3Level @4 @5@n@6@7: @8=@1@2@n@3@5 niveau @4@n@6@7 : @8

@ -1,5 +1,5 @@
name = toolranks_extras
description = Adds toolranks support for minetest-gamess mods (except default).
description = Extended Tool Ranks support.
depends = toolranks
optional_depends = farming
min_minetest_version = 5.0

@ -1,12 +1,36 @@
local S = minetest.get_translator("toolranks_extras")
toolranks_extras.registered_tool_types = {}
toolranks_extras.node_dug_display = {}
--[[
-- `keyword` is a string to be detected in tool description
-- `tool_type` is a localized tool type (if nil, then unregister the keyword)
-- `node_dug_display` is an (optional) alternative localized display
-- of "Node Dug" (if false, then unregister the display)
-- example
-- `toolranks_extras.register_tool_type("battle_axe", S("battle axe"))`
-- `toolranks_extras.register_tool_type("bow", S("bow"), S("Arrows thrown"))`
--]]
toolranks_extras.register_tool_type = function(keyword, tool_type)
toolranks_extras.registered_tool_types[string.lower(keyword)] = tool_type
toolranks_extras.register_tool_type = function(keyword, tool_type, node_dug_display)
local k = string.lower(keyword)
toolranks_extras.registered_tool_types[k] = tool_type
if node_dug_display == false then
toolranks_extras.node_dug_display[k] = nil
elseif node_dug_display ~= nil then
toolranks_extras.node_dug_display[k] = node_dug_display
end
end
--[[
-- Returns alternative node dug display if registered, or nil.
--]]
toolranks_extras.get_node_dug_display = function(description)
local d = string.lower(description)
for k, desc in pairs(toolranks_extras.node_dug_display) do
if string.find(d, k) then
return desc
end
end
return
end
toolranks_extras.ignored_toolranks_tool_types = {}
@ -59,7 +83,20 @@ if toolranks_extras.settings.enable_tool_types then
-- overwrite of toolranks.create_description(name, uses)
toolranks.create_description = function(name, uses)
local tooltype = toolranks.get_tool_type(name)
local newdesc = TR(
local alt_display = toolranks_extras.get_node_dug_display(name)
if alt_display ~= nil then
return S("@1@2\n@3Level @4 @5\n@6@7: @8",
toolranks.colors.green,
name,
toolranks.colors.gold,
toolranks.get_level(uses),
tooltype,
toolranks.colors.grey,
alt_display,
(type(uses) == "number" and uses or 0)
)
end
return TR(
"@1@2\n@3Level @4 @5\n@6@Node dug: @7",
toolranks.colors.green,
name,
@ -68,7 +105,6 @@ if toolranks_extras.settings.enable_tool_types then
tooltype,
toolranks.colors.grey,
(type(uses) == "number" and uses or 0)
)
return newdesc
)
end
end