v0.6 intllib support added, max tube length bugfix

This commit is contained in:
Joachim Stolberg 2018-12-20 16:28:23 +01:00
parent 93b46e2fe7
commit 93ab8ead53
11 changed files with 174 additions and 10 deletions

@ -53,6 +53,8 @@ func(node, pos, out_dir, peer_pos, peer_in_dir) will be called for every change
## Dependencies
default
optional: intllib
# License
Copyright (C) 2017-2018 Joachim Stolberg
@ -60,9 +62,11 @@ Code: Licensed under the GNU LGPL version 2.1 or later.
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
Textures: CC0
## History
- 2018-10-20 v0.1 * Tested against hyperloop elevator.
- 2018-10-27 v0.2 * Tested against and enhanced for the hyperloop mod.
- 2018-10-27 v0.3 * Further improvements.
- 2018-11-09 v0.4 * on_update function for secondary nodes introduced
- 2018-12-16 v0.5 * meta data removed, memory cache added instead of
- 2018-12-20 v0.6 * intllib support added, max tube length bugfix

@ -1 +1,2 @@
default
intllib?

@ -1,7 +1,11 @@
tubelib2 = {}
dofile(minetest.get_modpath("tubelib2") .. "/internal2.lua")
dofile(minetest.get_modpath("tubelib2") .. "/internal1.lua")
dofile(minetest.get_modpath("tubelib2") .. "/tube_api.lua")
local MP = minetest.get_modpath("tubelib2")
-- Load support for intllib.
dofile(MP .. "/intllib.lua")
dofile(MP .. "/internal2.lua")
dofile(MP .. "/internal1.lua")
dofile(MP .. "/tube_api.lua")
-- Only for testing/demo purposes
dofile(minetest.get_modpath("tubelib2") .. "/tube_test.lua")
--dofile(MP .. "/tube_test.lua")

@ -19,6 +19,10 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("tubelib2")
local I,IS = dofile(MP.."/intllib.lua")
local Tube = tubelib2.Tube
local Turn180Deg = tubelib2.Turn180Deg
local Dir6dToVector = tubelib2.Dir6dToVector
@ -99,6 +103,16 @@ function Tube:update_secondary_node(pos1, dir1, pos2, dir2)
end
end
function Tube:infotext(pos1, pos2)
if self.show_infotext then
if vector.equals(pos1, pos2) then
M(pos1):set_string("infotext", I("Not connected!"))
else
M(pos1):set_string("infotext", I("Connected with ")..S(pos2))
end
end
end
--------------------------------------------------------------------------------------
-- pairing functions
--------------------------------------------------------------------------------------
@ -109,7 +123,7 @@ function Tube:store_teleport_data(pos, peer_pos)
meta:set_string("tele_pos", S(peer_pos))
meta:set_string("channel", nil)
meta:set_string("formspec", nil)
meta:set_string("infotext", "Connected with "..S(peer_pos))
meta:set_string("infotext", I("Connected with ")..S(peer_pos))
return meta:get_int("tube_dir")
end

@ -17,6 +17,9 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("tubelib2")
local I,IS = dofile(MP.."/intllib.lua")
local Turn180Deg = {[0]=0,3,4,1,2,6,5}
tubelib2.Turn180Deg = Turn180Deg
@ -311,7 +314,7 @@ function Tube:store_teleport_data(pos, peer_pos)
meta:set_string("tele_pos", S(peer_pos))
meta:set_string("channel", nil)
meta:set_string("formspec", nil)
meta:set_string("infotext", "Connected with "..S(peer_pos))
meta:set_string("infotext", I("Connected with ")..S(peer_pos))
return meta:get_int("tube_dir")
end
@ -351,6 +354,9 @@ function Tube:walk_tube_line(pos, dir)
pos, dir = new_pos, new_dir
cnt = cnt + 1
end
if cnt > self.max_tube_length then
return
end
if cnt > 0 then
return pos, dir, cnt
end

45
intllib.lua Normal file

@ -0,0 +1,45 @@
-- 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

3
intllib.sh Executable file

@ -0,0 +1,3 @@
#!/bin/bash
../intllib/tools/xgettext.sh ./tube_api.lua ./internal1.lua ./internal2.lua

BIN
locale/de.mo Normal file

Binary file not shown.

34
locale/de.po Normal file

@ -0,0 +1,34 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-20 16:17+0100\n"
"PO-Revision-Date: 2018-12-20 16:19+0100\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Last-Translator: \n"
"Language-Team: \n"
"X-Generator: Poedit 2.0.6\n"
#: tube_api.lua
msgid "Maximum length reached!"
msgstr "Maximale Länge erreicht!"
#: tube_api.lua
msgid "Unconnected"
msgstr "Nicht verbunden"
#: internal1.lua
msgid "Not connected!"
msgstr "Nicht verbunden!"
#: internal1.lua internal2.lua
msgid "Connected with "
msgstr "Verbunden mit "

34
locale/template.pot Normal file

@ -0,0 +1,34 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-20 16:17+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: tube_api.lua
msgid "Maximum length reached!"
msgstr ""
#: tube_api.lua
msgid "Unconnected"
msgstr ""
#: internal1.lua
msgid "Not connected!"
msgstr ""
#: internal1.lua internal2.lua
msgid "Connected with "
msgstr ""

@ -19,6 +19,10 @@ tubelib2.version = 0.5
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local M = minetest.get_meta
-- Load support for intllib.
local MP = minetest.get_modpath("tubelib2")
local I,IS = dofile(MP.."/intllib.lua")
local Dir2Str = {"north", "east", "south", "west", "down", "up"}
function tubelib2.dir_to_string(dir)
@ -45,6 +49,8 @@ end
local function update1(self, pos, dir)
local fpos,fdir = self:walk_tube_line(pos, dir)
self:infotext(get_pos(pos, dir), fpos)
self:infotext(fpos, get_pos(pos, dir))
-- Translate pos/dir pointing to the secondary node into
-- spos/sdir of the secondary node pointing to the tube.
local spos, sdir = get_pos(fpos,fdir), Turn180Deg[fdir]
@ -58,6 +64,16 @@ end
local function update2(self, pos1, dir1, pos2, dir2)
local fpos1,fdir1 = self:walk_tube_line(pos1, dir1)
local fpos2,fdir2 = self:walk_tube_line(pos2, dir2)
if not fdir1 or not fdir2 then -- line to long?
-- reset next tube(s) to head tube(s) again
local param2 = tubelib2.encode_param2(dir1, dir2, 2)
self:update_after_dig_tube(pos1, param2)
M(get_pos(pos1, dir1)):set_string("infotext", I("Maximum length reached!"))
M(get_pos(pos1, dir2)):set_string("infotext", I("Maximum length reached!"))
return false
end
self:infotext(fpos1, fpos2)
self:infotext(fpos2, fpos1)
-- Translate fpos/fdir pointing to the secondary node into
-- spos/sdir of the secondary node pointing to the tube.
local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1]
@ -68,12 +84,15 @@ local function update2(self, pos1, dir1, pos2, dir2)
self:add_to_cache(spos2, sdir2, spos1, sdir1)
self:update_secondary_node(spos1, sdir1, spos2, sdir2)
self:update_secondary_node(spos2, sdir2, spos1, sdir1)
return true
end
local function update3(self, pos, dir1, dir2)
if pos and dir1 and dir2 then
local fpos1,fdir1,cnt1 = self:walk_tube_line(pos, dir1)
local fpos2,fdir2,cnt2 = self:walk_tube_line(pos, dir2)
self:infotext(fpos1, fpos2)
self:infotext(fpos2, fpos1)
-- Translate fpos/fdir pointing to the secondary node into
-- spos/sdir of the secondary node pointing to the tube.
local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1]
@ -143,7 +162,7 @@ function Tube:after_place_tube(pos, placer, pointed_thing)
-- s..secondary, f..far, n..near, x..node to be placed
local res,dir1,dir2 = self:update_after_place_tube(pos, placer, pointed_thing)
if res then -- node placed?
update2(self, pos, dir1, pos, dir2)
return update2(self, pos, dir1, pos, dir2)
end
return res
end
@ -228,7 +247,7 @@ function Tube:prepare_pairing(pos, tube_dir, sFormspec)
else
meta:set_int("tube_dir", tube_dir)
meta:set_string("channel", nil)
meta:set_string("infotext", "Unconnected")
meta:set_string("infotext", I("Unconnected"))
meta:set_string("formspec", sFormspec)
end
end
@ -246,7 +265,7 @@ function Tube:pairing(pos, channel)
self.pairingList[channel] = pos
local meta = M(pos)
meta:set_string("channel", channel)
meta:set_string("infotext", "Unconnected ("..channel..")")
meta:set_string("infotext", I("Unconnected").." ("..channel..")")
return false
end
end
@ -262,7 +281,7 @@ function Tube:stop_pairing(pos, oldmetadata, sFormspec)
peer_meta:set_string("channel", nil)
peer_meta:set_string("tele_pos", nil)
peer_meta:set_string("formspec", sFormspec)
peer_meta:set_string("infotext", "Unconnected")
peer_meta:set_string("infotext", I("Unconnected"))
end
elseif oldmetadata.fields.channel then
self.pairingList[oldmetadata.fields.channel] = nil