mirror of
https://github.com/louisroyer/minetest-toolranks-extras.git
synced 2024-09-28 15:50:57 +02:00
Fix #2
This commit is contained in:
parent
96cb1092f4
commit
da24f4fbf6
17
.luacheckrc
17
.luacheckrc
@ -28,3 +28,20 @@ read_globals = {
|
||||
"toolranks",
|
||||
"farming",
|
||||
}
|
||||
|
||||
files["tool_types.lua"] = {
|
||||
read_globals = {
|
||||
toolranks = {
|
||||
fields = {
|
||||
get_tool_type = {
|
||||
read_only = false,
|
||||
other_fields = false
|
||||
},
|
||||
create_description = {
|
||||
read_only = false,
|
||||
otherfields = false
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
README.md
20
README.md
@ -1,14 +1,30 @@
|
||||
# minetest-toolranks-extras [![Build Status](https://travis-ci.org/louisroyer/minetest-toolranks-extras.svg?branch=master)](https://travis-ci.org/louisroyer/minetest-toolranks-extras)
|
||||
|
||||
This minetest mod adds [toolranks](https://github.com/lisacvuk/minetest-toolranks) support for `minetest-games`’s mods (except `default`).
|
||||
This minetest mod extends [toolranks](https://github.com/lisacvuk/minetest-toolranks). It adds support for `minetest-games`’s mods (except `default`).
|
||||
This mod currently adds support for hoes from `farming` mod.
|
||||
This mod is compatible with [farming redo](https://notabug.org/tenplus1/farming) (nothing breaks if you have both installed).
|
||||
|
||||
This mod also adds an API to register new types of tools for toolranks.
|
||||
|
||||
## API
|
||||
|
||||
```lua
|
||||
--[[
|
||||
-- `keyword` is a string to be detected in tool description
|
||||
-- `tool_type` is a localized tool type (if nil, then unregister the keyword)
|
||||
--]]
|
||||
toolranks_extras.register_tool_type(keyword, tool_type)
|
||||
|
||||
-- example
|
||||
toolranks_extras.register_tool_type("battle_axe", S("battle axe"))
|
||||
```
|
||||
|
||||
![Screenshot](screenshot.png)
|
||||
|
||||
## License
|
||||
- CC0-1.0, Louis Royer 2020
|
||||
|
||||
## Settings
|
||||
Settings are available to disable support of some mods (currently only `farming`). This is useful if you want to reimplement minetest-games modules
|
||||
- Settings are available to disable support of some mods (currently only `farming`). This is useful if you want to reimplement minetest-games modules
|
||||
with a `toolranks` support. It is also possible to ask me to automatically disabling support if your mod is detected (like it is done with farming redo).
|
||||
- Extras tool types registering can be disabled (registering function will still be available, but will do nothing).
|
||||
|
10
init.lua
10
init.lua
@ -3,11 +3,13 @@ local MP = minetest.get_modpath("toolranks_extras")
|
||||
toolranks_extras = {}
|
||||
|
||||
-- mod information
|
||||
toolranks_extras.mod = {version = "1.3.3", author = "Louis Royer"}
|
||||
toolranks_extras.mod = {version = "1.4.0", author = "Louis Royer"}
|
||||
|
||||
-- settings
|
||||
toolranks_extras.settings =
|
||||
{enable_farming_tools = minetest.settings:get_bool("toolranks_extra.farming", true)}
|
||||
toolranks_extras.settings = {
|
||||
enable_farming_tools = minetest.settings:get_bool("toolranks_extras.farming", true),
|
||||
enable_tool_types = minetest.settings:get_bool("toolranks_extras.tool_types", true),
|
||||
}
|
||||
|
||||
-- XXX: when https://github.com/minetest/minetest/pull/7377
|
||||
-- is merged, we can remove this function
|
||||
@ -33,7 +35,7 @@ if toolranks.add_tool == nil then
|
||||
.." toolranks (at least version 1.2).")
|
||||
end
|
||||
|
||||
|
||||
dofile(MP.."/tool_types.lua")
|
||||
if use_farming and (not use_farming_redo)
|
||||
and toolranks_extras.settings.enable_farming_tools then
|
||||
dofile(MP.."/hoe.lua")
|
||||
|
@ -1 +1,2 @@
|
||||
toolranks_extra.farming (Enable toolranks on farming tools) bool true
|
||||
toolranks_extras.farming (Enable toolranks on farming tools) bool true
|
||||
toolranks_extras.tool_types (Enable registering of extras tool types) bool true
|
||||
|
74
tool_types.lua
Normal file
74
tool_types.lua
Normal file
@ -0,0 +1,74 @@
|
||||
toolranks_extras.registered_tool_types = {}
|
||||
--[[
|
||||
-- `keyword` is a string to be detected in tool description
|
||||
-- `tool_type` is a localized tool type (if nil, then unregister the keyword)
|
||||
-- example
|
||||
-- `toolranks_extras.register_tool_type("battle_axe", S("battle axe"))`
|
||||
--]]
|
||||
toolranks_extras.register_tool_type = function(keyword, tool_type)
|
||||
toolranks_extras.registered_tool_types[string.lower(keyword)] = tool_type
|
||||
end
|
||||
|
||||
toolranks_extras.ignored_toolranks_tool_types = {}
|
||||
--[[
|
||||
-- `keyword` is a string to be detected in tool description
|
||||
-- `tool_type` is a localized tool type
|
||||
--
|
||||
-- example
|
||||
-- `toolranks_extras.ignore_toolranks_tool_type("pickaxe")`
|
||||
-- This only works with tool types built in toolranks default get_tool_types function.
|
||||
--]]
|
||||
toolranks_extras.ignore_toolranks_tool_type = function(keyword)
|
||||
table.insert(toolranks_extras.ignored_toolranks_tool_types, string.lower(keyword))
|
||||
end
|
||||
toolranks_extras.ignore_toolranks_tool_type("tool")
|
||||
|
||||
if toolranks_extras.settings.enable_tool_types then
|
||||
local TR = minetest.get_translator("toolranks")
|
||||
local origin_get_tool_type = toolranks.get_tool_type
|
||||
--[[
|
||||
-- Returns nil if the keyword is ignored, else returns the keyword.
|
||||
--]]
|
||||
local function check_ignore(keyword)
|
||||
for _, k in ipairs(toolranks_extras.ignored_toolranks_tool_types) do
|
||||
if keyword == k then
|
||||
return
|
||||
end
|
||||
end
|
||||
return keyword
|
||||
end
|
||||
|
||||
-- overwrite of toolranks.get_tool_type(description)
|
||||
toolranks.get_tool_type = function(description)
|
||||
-- execute original function
|
||||
local tool_type = check_ignore(origin_get_tool_type(description))
|
||||
if tool_type ~= nil then
|
||||
return TR(tool_type)
|
||||
end
|
||||
-- search for registered tool types
|
||||
local d = string.lower(description)
|
||||
for k, desc in pairs(toolranks_extras.registered_tool_types) do
|
||||
if string.find(d, k) then
|
||||
return desc
|
||||
end
|
||||
end
|
||||
-- fallback
|
||||
return TR("tool")
|
||||
end
|
||||
|
||||
-- overwrite of toolranks.create_description(name, uses)
|
||||
toolranks.create_description = function(name, uses)
|
||||
local tooltype = toolranks.get_tool_type(name)
|
||||
local newdesc = TR(
|
||||
"@1@2\n@3Level @4 @5\n@6@Node dug: @7",
|
||||
toolranks.colors.green,
|
||||
name,
|
||||
toolranks.colors.gold,
|
||||
toolranks.get_level(uses),
|
||||
tooltype,
|
||||
toolranks.colors.grey,
|
||||
(type(uses) == "number" and uses or 0)
|
||||
)
|
||||
return newdesc
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user