diff options
author | Niklp <89982526+Niklp09@users.noreply.github.com> | 2023-07-24 09:59:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-24 09:59:26 +0200 |
commit | 1440f35fa62fd2c01b4844261290c88e42d2430f (patch) | |
tree | e42db53056e5d6f1c4fd562a924934081ae787c4 /signs_api | |
parent | e0e03058362e038d07d4063c4fbd6999ad27109c (diff) | |
download | display_modpack_no_craft-1440f35fa62fd2c01b4844261290c88e42d2430f.tar.gz display_modpack_no_craft-1440f35fa62fd2c01b4844261290c88e42d2430f.zip |
Add luacheck, update translations, replace ABMs, bug fixes (#1)
* luacheck, mt 5 translation, german translation, maintenance
* fix luacheck warnings
* Fix digital clock nodebox and texture
* Fix luacheck usage
* Add comment why fonts are not split into several lines
Diffstat (limited to 'signs_api')
-rw-r--r-- | signs_api/init.lua | 66 | ||||
-rw-r--r-- | signs_api/intllib.lua | 45 | ||||
-rw-r--r-- | signs_api/locale/fr.po | 49 | ||||
-rw-r--r-- | signs_api/locale/ms.po | 46 | ||||
-rw-r--r-- | signs_api/locale/signs_api.de.tr | 5 | ||||
-rw-r--r-- | signs_api/locale/signs_api.fr.tr | 5 | ||||
-rw-r--r-- | signs_api/locale/signs_api.ms.tr | 5 | ||||
-rw-r--r-- | signs_api/locale/template.pot | 31 | ||||
-rw-r--r-- | signs_api/locale/template.txt | 5 | ||||
-rw-r--r-- | signs_api/mod.conf | 1 | ||||
-rwxr-xr-x | signs_api/tools/updatepo.sh | 25 |
11 files changed, 38 insertions, 245 deletions
diff --git a/signs_api/init.lua b/signs_api/init.lua index 1bd00d6..325ba78 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -22,10 +22,9 @@ signs_api = {} signs_api.name = minetest.get_current_modname() signs_api.path = minetest.get_modpath(signs_api.name) --- Load support for intllib. -local S, NS = dofile(signs_api.path.."/intllib.lua") -signs_api.intllib = S -local F = function(...) return minetest.formspec_escape(S(...)) end +-- Translation support +local S = minetest.get_translator(signs_api.name) +local FS = function(...) return minetest.formspec_escape(S(...)) end function signs_api.set_display_text(pos, text, font) local meta = minetest.get_meta(pos) @@ -50,22 +49,22 @@ function signs_api.set_formspec(pos) local fs, y if maxlines == 1 then - fs = "field[0.5,0.7;5.5,1;display_text;"..F("Text").. + fs = "field[0.5,0.7;5.5,1;display_text;"..FS("Text").. ";${display_text}]" y = 1.2 else local extralabel = "" if maxlines then - extralabel = F(" (first %s lines only)"):format(maxlines) + extralabel = FS(" (first @1 lines only)", maxlines) end - fs = "textarea[0.5,0.7;5.5,2;display_text;"..F("Text").."".. + fs = "textarea[0.5,0.7;5.5,2;display_text;"..FS("Text").."".. extralabel..";${display_text}]" y = 2.4 end - fs = fs.."button[1,"..y..";2,1;font;"..F("Font").."]" - fs = fs.."button_exit[3,"..y..";2,1;ok;"..F("Write").."]" + fs = fs.."button[1,"..y..";2,1;font;"..FS("Font").."]" + fs = fs.."button_exit[3,"..y..";2,1;ok;"..FS("Write").."]" y = y + 0.8 fs = "size[6,"..y.."]"..default.gui_bg.. default.gui_bg_img..default.gui_slots..fs @@ -91,7 +90,6 @@ end function signs_api.on_place_direction(itemstack, placer, pointed_thing) local name = itemstack:get_name() local ndef = minetest.registered_nodes[name] - local restriction = display_api.is_rotation_restricted() local bdir = { x = pointed_thing.under.x - pointed_thing.above.x, @@ -102,33 +100,25 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing) local ndir, test - if ndef.paramtype2 == "facedir" then - -- If legacy mode, only accept upright nodes - if restriction and bdir.x == 0 and bdir.z == 0 then - -- Ceiling or floor pointed (facedir chosen from player dir) - ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z}) - else - -- Wall pointed or no rotation restriction - ndir = minetest.dir_to_facedir(bdir, not restriction) - end + if ndef and ndef.paramtype2 == "facedir" then + -- Wall pointed + ndir = minetest.dir_to_facedir(bdir, true) test = { [0]=-pdir.x, pdir.z, pdir.x, -pdir.z, -pdir.x, [8]=pdir.x } end - if ndef.paramtype2 == "wallmounted" then + if ndef and ndef.paramtype2 == "wallmounted" then ndir = minetest.dir_to_wallmounted(bdir) - -- If legacy mode, only accept upright nodes - if restriction and (ndir == 0 or ndir == 1) then - ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z}) - end test = { [0]=-pdir.x, -pdir.x, pdir.z, -pdir.z, -pdir.x, pdir.x} end -- Only for direction signs -- TODO:Maybe improve ground and ceiling placement in every directions - if ndef.signs_other_dir then - if test[ndir] > 0 then + if ndef and ndef.signs_other_dir then + if not test[ndir] then -- https://github.com/pyrollo/display_modpack/issues/48 + return itemstack + elseif test[ndir] > 0 then itemstack:set_name(ndef.signs_other_dir) end itemstack = minetest.item_place(itemstack, placer, pointed_thing, ndir) @@ -141,13 +131,12 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing) end -- Handles screwdriver rotation --- (see "if" block below for rotation restriction mode). signs_api.on_rotate = function(pos, node, player, mode, new_param2) -- If rotation mode is 1 and sign is directional, swap direction between -- each rotation. if mode == 1 then local ndef = minetest.registered_nodes[node.name] - if ndef.signs_other_dir then + if ndef and ndef.signs_other_dir then -- Switch direction node = {name = ndef.signs_other_dir, param1 = node.param1, param2 = node.param2} @@ -165,25 +154,6 @@ signs_api.on_rotate = function(pos, node, player, mode, new_param2) return display_api.on_rotate(pos, node, player, mode, new_param2) end --- Legacy mode with rotation restriction --- TODO:When MT < 5.0 no more in use, to be removed -if display_api.is_rotation_restricted() then - signs_api.on_rotate = function(pos, node, player, mode, new_param2) - -- If rotation mode is 2 and sign is directional, swap direction. - -- Otherwise use display_api's on_rotate function. - if mode == 2 then - local ndef = minetest.registered_nodes[node.name] - if ndef.signs_other_dir then - minetest.swap_node(pos, {name = ndef.signs_other_dir, - param1 = node.param1, param2 = node.param2}) - display_api.update_entities(pos) - return true - end - end - return display_api.on_rotate(pos, node, player, mode, new_param2) - end -end - function signs_api.register_sign(mod, name, model) -- Default fields local fields = { @@ -212,7 +182,7 @@ function signs_api.register_sign(mod, name, model) on_construct = function(pos) local ndef = minetest.registered_nodes[minetest.get_node(pos).name] local meta = minetest.get_meta(pos) - meta:set_string("font", ndef.display_entities.font_name or + meta:set_string("font", ndef and ndef.display_entities.font_name or font_api.get_default_font_name()) signs_api.set_formspec(pos) display_api.on_construct(pos) diff --git a/signs_api/intllib.lua b/signs_api/intllib.lua deleted file mode 100644 index 6669d72..0000000 --- a/signs_api/intllib.lua +++ /dev/null @@ -1,45 +0,0 @@ - --- 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 diff --git a/signs_api/locale/fr.po b/signs_api/locale/fr.po deleted file mode 100644 index e490d1b..0000000 --- a/signs_api/locale/fr.po +++ /dev/null @@ -1,49 +0,0 @@ -# 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-02-01 05:56+0100\n" -"PO-Revision-Date: 2017-05-08 07:08+0200\n" -"Last-Translator: Peppy <peppy@twang-factory.com>\n" -"Language-Team: \n" -"Language: fr\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.12\n" - -#: common.lua -msgid "Text" -msgstr "Texte" - -#: common.lua -msgid "Write" -msgstr "Écrire" - -#: common.lua -#, lua-format -msgid " (first %s lines only)" -msgstr " (uniquement les %s premières lignes)" - -#~ msgid "Title" -#~ msgstr "Titre" - -#~ msgid "Close" -#~ msgstr "Fermer" - -#~ msgid "(right-click to read more text)" -#~ msgstr "(Clic-droit pour afficher le texte entier)" - -#~ msgid "Wooden direction sign" -#~ msgstr "Panneau de direction en bois" - -#~ msgid "Poster" -#~ msgstr "Affiche" - -#~ msgid "Textd" -#~ msgstr "Texte" diff --git a/signs_api/locale/ms.po b/signs_api/locale/ms.po deleted file mode 100644 index 0d90222..0000000 --- a/signs_api/locale/ms.po +++ /dev/null @@ -1,46 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# Yaya (Nurul Azeera Hidayah @ Muhammad Nur Hidayat) <translation@mnh48.moe>, 2017. -msgid "" -msgstr "" -"Project-Id-Version: Display Modpack\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-02-01 05:56+0100\n" -"PO-Revision-Date: 2020-07-05 11:31+0000\n" -"Last-Translator: Yaya MNH48 <translation@mnh48.moe>\n" -"Language-Team: Malay <translation@mnh48.moe>\n" -"Language: ms\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Poedit 2.3\n" - -#: common.lua -msgid "Text" -msgstr "Teks" - -#: common.lua -msgid "Write" -msgstr "Tulis" - -#: common.lua -#, lua-format -msgid " (first %s lines only)" -msgstr " (%s baris pertama sahaja)" - -#~ msgid "Title" -#~ msgstr "Tajuk" - -#~ msgid "Close" -#~ msgstr "Tutup" - -#~ msgid "(right-click to read more text)" -#~ msgstr "(klik-kanan untuk baca teks penuh)" - -#~ msgid "Wooden direction sign" -#~ msgstr "Papan tanda arah kayu" - -#~ msgid "Poster" -#~ msgstr "Poster" diff --git a/signs_api/locale/signs_api.de.tr b/signs_api/locale/signs_api.de.tr new file mode 100644 index 0000000..12a389f --- /dev/null +++ b/signs_api/locale/signs_api.de.tr @@ -0,0 +1,5 @@ +# textdomain: signs_api +Text=Text + (first @1 lines only)= (nur die ersten @1 Zeilen) +Font=Schriftart +Write=Schreiben diff --git a/signs_api/locale/signs_api.fr.tr b/signs_api/locale/signs_api.fr.tr new file mode 100644 index 0000000..e47ecc9 --- /dev/null +++ b/signs_api/locale/signs_api.fr.tr @@ -0,0 +1,5 @@ +# textdomain: signs_api +Text=Texte + (first @1 lines only)= (uniquement les @1 premières lignes) +Font= +Write=Écrire diff --git a/signs_api/locale/signs_api.ms.tr b/signs_api/locale/signs_api.ms.tr new file mode 100644 index 0000000..76f95f1 --- /dev/null +++ b/signs_api/locale/signs_api.ms.tr @@ -0,0 +1,5 @@ +# textdomain: signs_api +Text=Teks + (first @1 lines only)= (@1 baris pertama sahaja) +Font= +Write=Tulis diff --git a/signs_api/locale/template.pot b/signs_api/locale/template.pot deleted file mode 100644 index 6004024..0000000 --- a/signs_api/locale/template.pot +++ /dev/null @@ -1,31 +0,0 @@ -# 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-02-01 05:56+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" - -#: common.lua -msgid "Text" -msgstr "" - -#: common.lua -msgid "Write" -msgstr "" - -#: common.lua -#, lua-format -msgid " (first %s lines only)" -msgstr "" diff --git a/signs_api/locale/template.txt b/signs_api/locale/template.txt new file mode 100644 index 0000000..a3993b2 --- /dev/null +++ b/signs_api/locale/template.txt @@ -0,0 +1,5 @@ +# textdomain: signs_api +Text= + (first @1 lines only)= +Font= +Write= diff --git a/signs_api/mod.conf b/signs_api/mod.conf index f4f91b7..cdc6a10 100644 --- a/signs_api/mod.conf +++ b/signs_api/mod.conf @@ -2,4 +2,3 @@ name = signs_api title = Signs API description = A library providing various helper functions for registereing signs with text display depends = default,display_api,font_api -optional_depends = intllib diff --git a/signs_api/tools/updatepo.sh b/signs_api/tools/updatepo.sh deleted file mode 100755 index feb2504..0000000 --- a/signs_api/tools/updatepo.sh +++ /dev/null @@ -1,25 +0,0 @@ -#! /bin/bash - -# To create a new translation: -# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot - -cd "$(dirname "${BASH_SOURCE[0]}")/.."; - -# Extract translatable strings. -xgettext --from-code=UTF-8 \ - --language=Lua \ - --sort-by-file \ - --keyword=S \ - --keyword=NS:1,2 \ - --keyword=N_ \ - --keyword=F \ - --add-comments='Translators:' \ - --add-location=file \ - -o locale/template.pot \ - $(find . -name '*.lua') - -# Update translations. -find locale -name '*.po' | while read -r file; do - echo $file - msgmerge --update $file locale/template.pot; -done |