Update intllib support to avoid using deprecated functions

This commit is contained in:
Hugo Locurcio 2019-03-03 20:11:10 +01:00
parent 8bb6f0fece
commit 199180ee80
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
7 changed files with 86 additions and 43 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Changed
- Update intllib support to avoid using deprecated functions.
## 1.0.0 - 2017-02-19
- Initial versioned release.

View File

@ -5,7 +5,7 @@ Copyright © 2012-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local S = maptools.intllib
local S = maptools.S
maptools.creative = maptools.config["hide_from_creative_inventory"]

View File

@ -5,7 +5,7 @@ Copyright © 2012-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local S = maptools.intllib
local S = maptools.S
maptools.creative = maptools.config["hide_from_creative_inventory"]

View File

@ -10,20 +10,11 @@ Licensed under the zlib license. See LICENSE.md for more information.
maptools = {}
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(s) return s end
end
maptools.intllib = S
local modpath = minetest.get_modpath("maptools")
maptools.drop_msg = function(itemstack, player)
local name = player:get_player_name()
minetest.chat_send_player(name, S("[maptools] tools/nodes do not drop!"))
end
local S, NS = dofile(modpath .. "/intllib.lua")
maptools.S = S
maptools.NS = NS
dofile(modpath .. "/config.lua")
dofile(modpath .. "/aliases.lua")
@ -32,6 +23,11 @@ dofile(modpath .. "/default_nodes.lua")
dofile(modpath .. "/nodes.lua")
dofile(modpath .. "/tools.lua")
maptools.drop_msg = function(itemstack, player)
local name = player:get_player_name()
minetest.chat_send_player(name, S("[maptools] tools/nodes do not drop!"))
end
if minetest.setting_getbool("log_mods") then
minetest.log("action", S("[maptools] loaded."))
end

44
intllib.lua Normal file
View File

@ -0,0 +1,44 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

View File

@ -5,11 +5,11 @@ Copyright © 2012-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local S = maptools.intllib
local S = maptools.S
maptools.creative = maptools.config["hide_from_creative_inventory"]
-- Redefine cloud so that the admin pickaxe can mine it:
-- Redefine cloud so that the admin pickaxe can mine it
minetest.register_node(":default:cloud", {
description = S("Cloud"),
tiles = {"default_cloud.png"},
@ -20,7 +20,6 @@ minetest.register_node(":default:cloud", {
})
-- Nodes
-- =====
minetest.register_node("maptools:black", {
description = S("Black"),
@ -239,29 +238,29 @@ minetest.register_node("maptools:playerclip_top", {
})
for pusher_num=1,10,1 do
minetest.register_node("maptools:pusher_" .. pusher_num, {
description = S("Pusher (%s)"):format(pusher_num),
range = 12,
stack_max = 10000,
inventory_image = "default_steel_block.png^default_apple.png",
drawtype = "nodebox",
tiles = {"invisible.png"},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4999, 0.5},
},
drop = "",
groups = {
unbreakable = 1,
not_in_creative_inventory = maptools.creative,
fall_damage_add_percent = -100,
bouncy = pusher_num * 100,
},
on_drop = maptools.drop_msg
})
minetest.register_node("maptools:pusher_" .. pusher_num, {
description = S("Pusher (%s)"):format(pusher_num),
range = 12,
stack_max = 10000,
inventory_image = "default_steel_block.png^default_apple.png",
drawtype = "nodebox",
tiles = {"invisible.png"},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4999, 0.5},
},
drop = "",
groups = {
unbreakable = 1,
not_in_creative_inventory = maptools.creative,
fall_damage_add_percent = -100,
bouncy = pusher_num * 100,
},
on_drop = maptools.drop_msg
})
end
minetest.register_node("maptools:lightbulb", {

View File

@ -5,7 +5,7 @@ Copyright © 2012-2019 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local S = maptools.intllib
local S = maptools.S
maptools.creative = maptools.config["hide_from_creative_inventory"]
@ -66,9 +66,9 @@ minetest.register_on_punchnode(function(pos, node, puncher)
" using an Admin Pickaxe."
)
-- The node is removed directly, which means it even works
-- on non-empty containers and group-less nodes.
-- on non-empty containers and group-less nodes
minetest.remove_node(pos)
-- Run node update actions like falling nodes.
-- Run node update actions like falling nodes
minetest.check_for_falling(pos)
end
end)