From 93ab8ead533db9105d1f1a1412fd7d865bc40d58 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Thu, 20 Dec 2018 16:28:23 +0100 Subject: [PATCH] v0.6 intllib support added, max tube length bugfix --- README.md | 4 ++++ depends.txt | 1 + init.lua | 12 ++++++++---- internal1.lua | 16 +++++++++++++++- internal2.lua | 8 +++++++- intllib.lua | 45 ++++++++++++++++++++++++++++++++++++++++++++ intllib.sh | 3 +++ locale/de.mo | Bin 0 -> 526 bytes locale/de.po | 34 +++++++++++++++++++++++++++++++++ locale/template.pot | 34 +++++++++++++++++++++++++++++++++ tube_api.lua | 27 ++++++++++++++++++++++---- 11 files changed, 174 insertions(+), 10 deletions(-) create mode 100644 intllib.lua create mode 100755 intllib.sh create mode 100644 locale/de.mo create mode 100644 locale/de.po create mode 100644 locale/template.pot diff --git a/README.md b/README.md index b818087..53660ad 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/depends.txt b/depends.txt index 4ad96d5..9207dab 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,2 @@ default +intllib? diff --git a/init.lua b/init.lua index 2ab9e4d..0600c45 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/internal1.lua b/internal1.lua index e05d469..c1a92d6 100644 --- a/internal1.lua +++ b/internal1.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 diff --git a/internal2.lua b/internal2.lua index 30b1a7f..7b90514 100644 --- a/internal2.lua +++ b/internal2.lua @@ -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 diff --git a/intllib.lua b/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- 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 diff --git a/intllib.sh b/intllib.sh new file mode 100755 index 0000000..5b9294f --- /dev/null +++ b/intllib.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +../intllib/tools/xgettext.sh ./tube_api.lua ./internal1.lua ./internal2.lua \ No newline at end of file diff --git a/locale/de.mo b/locale/de.mo new file mode 100644 index 0000000000000000000000000000000000000000..d7fa725d3b9b1b10fc3680b6a26a913bfd1295f3 GIT binary patch literal 526 zcmZXQze)o^5XM)H2q&o6h+wg)W#ioyAx3O8Q38pEa1q<~&s+kFdEhwJnnFtvzfrc&SxZjTU^L(f=@`Bt z8TKhEva{6ka8_GnUH#{9XqfwlRAVs)+E;=+; zd6B3|OI7Z>UPXAm@LleetKR;u>$$GelsX>C82N~tR-;v)xAsb|gRL!TD}vi0N-Rz6 z-Y}6$AMmg*O-A;x8=Q#Byv|6SU6B!W>>Vi`S9ztUEXHJLk|z^sQ-cL(gGE4c0RK{) zk|s0Fwo{6f<$lR6l^ur1_C`7)%?Aihe@-UEo3BqgCQinX3i}p+mkS@y%Krt}FGt{w AasU7T literal 0 HcmV?d00001 diff --git a/locale/de.po b/locale/de.po new file mode 100644 index 0000000..767e80b --- /dev/null +++ b/locale/de.po @@ -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 , 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 " diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..7abdda1 --- /dev/null +++ b/locale/template.pot @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 "" diff --git a/tube_api.lua b/tube_api.lua index 7ba70f6..a7ffc55 100644 --- a/tube_api.lua +++ b/tube_api.lua @@ -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