aboutsummaryrefslogtreecommitdiff
path: root/font_api
diff options
context:
space:
mode:
authorNiklp <89982526+Niklp09@users.noreply.github.com>2023-07-24 09:59:26 +0200
committerGitHub <noreply@github.com>2023-07-24 09:59:26 +0200
commit1440f35fa62fd2c01b4844261290c88e42d2430f (patch)
treee42db53056e5d6f1c4fd562a924934081ae787c4 /font_api
parente0e03058362e038d07d4063c4fbd6999ad27109c (diff)
downloaddisplay_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 'font_api')
-rw-r--r--font_api/deprecation.lua2
-rw-r--r--font_api/fallbacks.lua2
-rw-r--r--font_api/font.lua12
-rw-r--r--font_api/fontform.lua7
-rw-r--r--font_api/init.lua3
-rw-r--r--font_api/locale/font_api.de.tr2
-rw-r--r--font_api/locale/template.txt2
-rw-r--r--font_api/registry.lua7
8 files changed, 22 insertions, 15 deletions
diff --git a/font_api/deprecation.lua b/font_api/deprecation.lua
index 1ffed11..93cf365 100644
--- a/font_api/deprecation.lua
+++ b/font_api/deprecation.lua
@@ -18,7 +18,7 @@
-- Deprecation
-function deprecated_global_table(deprecated_global_name, replacement_global_name)
+local function deprecated_global_table(deprecated_global_name, replacement_global_name)
assert(type(deprecated_global_name) == 'string', "deprecated_global_name should be a string.")
assert(type(replacement_global_name) == 'string', "replacement_global_name should be a string.")
assert(deprecated_global_name ~= '', "deprecated_global_name should not be empty.")
diff --git a/font_api/fallbacks.lua b/font_api/fallbacks.lua
index da3ff03..ebe8387 100644
--- a/font_api/fallbacks.lua
+++ b/font_api/fallbacks.lua
@@ -53,7 +53,7 @@ return {
['×'] = 'x', ['Ý'] = 'Y',
-- Lower case accents
- ['à'] = 'a', ['à'] = 'a', ['á'] = 'a', ['â'] = 'a',
+ ['à'] = 'a', ['á'] = 'a', ['â'] = 'a',
['ã'] = 'a', ['ä'] = 'a', ['å'] = 'a',
['æ'] = 'ae', ['ç'] = 'c',
['è'] = 'e', ['é'] = 'e', ['ê'] = 'e', ['ë'] = 'e',
diff --git a/font_api/font.lua b/font_api/font.lua
index 5794867..d7b67d7 100644
--- a/font_api/font.lua
+++ b/font_api/font.lua
@@ -212,7 +212,7 @@ end
-- @return Texture string
function Font:render(text, texturew, textureh, style)
- local style = style or {}
+ style = style or {}
-- Split text into lines (and limit to style.lines # of lines)
local lines = {}
@@ -243,17 +243,17 @@ function Font:render(text, texturew, textureh, style)
y = y + (self.margintop or 0)
- for _, line in pairs(lines) do
+ for _, l in pairs(lines) do
if style.halign == "left" then
x = 0
elseif style.halign == "right" then
- x = texturew - line.width
+ x = texturew - l.width
else
- x = (texturew - line.width) / 2
+ x = (texturew - l.width) / 2
end
- while line.text ~= '' do
- codepoint, line.text = self:get_next_char(line.text)
+ while l.text ~= '' do
+ codepoint, l.text = self:get_next_char(l.text)
if codepoint == nil then return '' end -- UTF Error
-- Add image only if it is visible (at least partly)
diff --git a/font_api/fontform.lua b/font_api/fontform.lua
index b7e6724..d019fba 100644
--- a/font_api/fontform.lua
+++ b/font_api/fontform.lua
@@ -16,6 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
--]]
+local S = font_api.S
+local FS = function(...) return minetest.formspec_escape(S(...)) end
+
local modname = minetest.get_current_modname()
local contexts = {}
@@ -101,9 +104,9 @@ local function show_font_formspec(playername)
table.sort(fonts)
local fs = string.format(
- "size[4,%s]%s%s%sbutton_exit[0,%s;4,1;cancel;Cancel]",
+ "size[4,%s]%s%s%sbutton_exit[0,%s;4,1;cancel;%s]",
#fonts + 0.8, default.gui_bg, default.gui_bg_img, default.gui_slots,
- #fonts)
+ #fonts, FS("Cancel"))
for line = 1, #fonts do
local font = font_api.get_font(fonts[line])
diff --git a/font_api/init.lua b/font_api/init.lua
index c5858f4..a0a2969 100644
--- a/font_api/init.lua
+++ b/font_api/init.lua
@@ -23,6 +23,9 @@ font_api = {}
font_api.name = minetest.get_current_modname()
font_api.path = minetest.get_modpath(font_api.name)
+-- Translation support
+font_api.S = minetest.get_translator(font_api.name)
+
-- Inclusions
-------------
diff --git a/font_api/locale/font_api.de.tr b/font_api/locale/font_api.de.tr
new file mode 100644
index 0000000..5536527
--- /dev/null
+++ b/font_api/locale/font_api.de.tr
@@ -0,0 +1,2 @@
+# textdomain: font_api
+Cancel=Schließen
diff --git a/font_api/locale/template.txt b/font_api/locale/template.txt
new file mode 100644
index 0000000..a2ffa72
--- /dev/null
+++ b/font_api/locale/template.txt
@@ -0,0 +1,2 @@
+# textdomain: font_api
+Cancel=
diff --git a/font_api/registry.lua b/font_api/registry.lua
index e183675..b497453 100644
--- a/font_api/registry.lua
+++ b/font_api/registry.lua
@@ -58,12 +58,9 @@ local function get_default_font()
end
end
- -- If failed, chose first font
+ -- If failed, choose the first registered font
if default_font == nil then
- for _, font in pairs(font_api.registered_fonts) do
- default_font = font
- break
- end
+ default_font = next(font_api.registered_fonts)
end
-- Error, no font registered