From bb02ed7095ea1ed7895267ebf80ca1772d5afee8 Mon Sep 17 00:00:00 2001 From: Louis <55180044+louisroyer@users.noreply.github.com> Date: Tue, 11 Aug 2020 16:01:59 +0200 Subject: [PATCH] Extends API to allow redefinition of "Node dug" display --- README.md | 5 +++- init.lua | 2 +- locale/template.txt | 6 +++++ locale/toolranks_extras.fr.tr | 6 +++++ mod.conf | 2 +- tool_types.lua | 46 +++++++++++++++++++++++++++++++---- 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 locale/template.txt create mode 100644 locale/toolranks_extras.fr.tr diff --git a/README.md b/README.md index 93005fa..65fb344 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/init.lua b/init.lua index f5db140..375135f 100644 --- a/init.lua +++ b/init.lua @@ -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 = { diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..abe4719 --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,6 @@ +# textdomain: toolranks_extras + + +### tool_types.lua ### + +@1@2@n@3Level @4 @5@n@6@7: @8= diff --git a/locale/toolranks_extras.fr.tr b/locale/toolranks_extras.fr.tr new file mode 100644 index 0000000..3192a34 --- /dev/null +++ b/locale/toolranks_extras.fr.tr @@ -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 diff --git a/mod.conf b/mod.conf index cbd3a2c..8982558 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = toolranks_extras -description = Adds toolranks support for minetest-games’s mods (except default). +description = Extended Tool Ranks support. depends = toolranks optional_depends = farming min_minetest_version = 5.0 diff --git a/tool_types.lua b/tool_types.lua index 3fde758..bf83d06 100644 --- a/tool_types.lua +++ b/tool_types.lua @@ -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