From f46dd0a72ecf04937cef661a2e599ffb71417ba7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Wed, 5 Dec 2018 15:41:56 +0100 Subject: New Font:render method --- display_api/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'display_api') diff --git a/display_api/init.lua b/display_api/init.lua index bf95ded..d4f7dcd 100644 --- a/display_api/init.lua +++ b/display_api/init.lua @@ -120,7 +120,7 @@ function update_entity(entity) if not entity then return end - + if not entity.nodepos then entity.object:remove() -- Remove old/buggy entity return -- cgit v1.2.3 From 81e6dc89aecb06986908b48959751956d4be2e4d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Tue, 11 Dec 2018 11:52:55 +0100 Subject: Added font_lib deprecation and corresponding notices in READMEs --- display_api/README.md | 9 ++++++++ font_api/README.md | 10 ++++++++- font_api/deprecation.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ font_api/init.lua | 4 +--- 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 font_api/deprecation.lua (limited to 'display_api') diff --git a/display_api/README.md b/display_api/README.md index 26b26f0..079ce6d 100644 --- a/display_api/README.md +++ b/display_api/README.md @@ -12,3 +12,12 @@ This library's purpose is to ease creation of nodes with one or more displays on For more information, see the [forum topic](https://forum.minetest.net/viewtopic.php?t=19365) at the Minetest forums. +## Deprecation notice (for modders) + +### December 2018 +Following objects are deprecated, shows a warning in log when used: +* `display_modpack_node` group (use `display_api` group instead); +* `display_lib_node` group (use `display_api` group instead); +* `display_lib` global table (use `display_api` global table instead); + +These objects will be removed in the future. diff --git a/font_api/README.md b/font_api/README.md index 33af92b..13d287f 100644 --- a/font_api/README.md +++ b/font_api/README.md @@ -16,8 +16,16 @@ For more information, see the [forum topic](https://forum.minetest.net/viewtopic You can add fonts by installing fonts mod. Be aware that each font comes with numerous textures. This can result in slowing media downloading and/or client display. -Font mods can be found here: +Font mods can be found here: * [Metro](https://github.com/pyrollo/display_modpack/tree/master/font_metro): A multipurpose font with many chars (uppercase, lowercase and accentuated latin letters, usual signs, cyrillic and greek letters). * [OldWizard](https://github.com/pyrollo/font_oldwizard): An old style gothic font. * [Botic](https://github.com/pyrollo/font_botic): A scifi style font. + + ## Deprecation notice (for modders) + + ### December 2018 + Following object is deprecate, shows a warning in log when used: + * `font_lib` global table (use `font_api` global table instead); + + This object will be removed in the future. diff --git a/font_api/deprecation.lua b/font_api/deprecation.lua new file mode 100644 index 0000000..5c0bed6 --- /dev/null +++ b/font_api/deprecation.lua @@ -0,0 +1,54 @@ +--[[ + font_api mod for Minetest - Library to create textures with fonts and text + (c) Pierre-Yves Rollo + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +--]] + +-- Deprecation + +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.") + assert(replacement_global_name ~= '', "replacement_global_name should not be empty.") + assert(rawget(_G, deprecated_global_name) == nil, "replacement global already exists.") + if _G[replacement_global_name] == nil then + print('warn_deprecated_functions: Warning, replacement global "'..replacement_global_name..'" does not exists.') + return + end + local meta = { + deprecated = deprecated_global_name, + replacement = replacement_global_name, + __index = function(table, key) + local meta = getmetatable(table) + local dbg = debug.getinfo(2, "lS") + minetest.log("warning", string.format('Warning: Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).', + meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'), (dbg.currentline or 0))) + return _G[meta.replacement][key] + end, + __newindex = function(table, key, value) + local meta = getmetatable(table) + local dbg = debug.getinfo(2, "lS") + minetest.log("warning", string.format('Warning: Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).', + meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'), (dbg.currentline or 0))) + _G[meta.replacement][key]=value + end, + } + rawset(_G, deprecated_global_name, {}) + setmetatable(_G[deprecated_global_name], meta) +end + +-- deprecated(2) -- December 2018 - Deprecation of font_lib +deprecated_global_table('font_lib', 'font_api') diff --git a/font_api/init.lua b/font_api/init.lua index 7fbedf9..80fc98a 100644 --- a/font_api/init.lua +++ b/font_api/init.lua @@ -33,6 +33,4 @@ dofile(font_api.path.."/fontform.lua") if minetest.get_modpath("display_api") then dofile(font_api.path.."/display_api.lua") end - --- Compatibility -font_lib = font_api +dofile(font_api.path.."/deprecation.lua") -- cgit v1.2.3 From c9329d378976ee0fea0bd3486befcd3a1af551c1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Tue, 11 Dec 2018 14:57:42 +0100 Subject: Added display entity yaw attribute --- display_api/display.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'display_api') diff --git a/display_api/display.lua b/display_api/display.lua index a8cee66..3cc52b7 100644 --- a/display_api/display.lua +++ b/display_api/display.lua @@ -106,13 +106,12 @@ local function place_entities(pos) y = pos.y - top, z = pos.z - values.dz * depth + values.rz * right}) - objrefs[entity_name]:setyaw(values.yaw) + objrefs[entity_name]:setyaw(values.yaw + (props.yaw or 0)) end end return objrefs end - --- Entity update function update_entity(entity) if not entity then -- cgit v1.2.3 From fc40e54ed2227f29b4b4ddd4b42aafea2e47a791 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Tue, 11 Dec 2018 14:58:11 +0100 Subject: Update API documentation --- display_api/API.md | 35 +++++++++++++++++------------------ font_api/API.md | 14 +++++++++++--- 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'display_api') diff --git a/display_api/API.md b/display_api/API.md index b214585..e69ae60 100644 --- a/display_api/API.md +++ b/display_api/API.md @@ -1,38 +1,38 @@ -# Display Lib API -This document describes Display Lib API. Display Lib allows to add a dynamic display on a node. Display Lib limits node rotations. For wallmounted, only vertical positionning is available, and for facedir, only first four position are availabel (those with default axis). +# Display API +This document describes Display API. Display API allows to add a dynamic display on a node. Display API limits node rotations. For wallmounted, only vertical positionning is available. For facedir, only first four position are availabel (those with default axis). ## Provided methods ### update\_entities -**display\_lib.update\_entities(pos)** +**display\_api.update\_entities(pos)** This method triggers entities update for the display node at pos. Actual entity update is made by `on_display_update` callback associated to the entity. `pos`: Position of the node ### register\_display\_entity -**display\_lib.register\_display\_entity(entity_name)** +**display\_api.register\_display\_entity(entity_name)** This is a helper to register entities used for display. `entity_name`: Name of the entity to register. ## Provided callback implementations ### on_place -**display\_lib.on\_place(itemstack, placer, pointed\_thing)** +**display\_api.on\_place(itemstack, placer, pointed\_thing)** `on_place` node callback implementation. Display nodes should have this callback (avoid placement of horizontal display node). ### on_construct -**display\_lib.on\_construct(pos)** +**display\_api.on\_construct(pos)** `on_construct` node callback implementation. Display nodes should have this callback (creates, places and updates display entities on node construction). ### on_destruct -**display\_lib.on_destruct(pos)** +**display\_api.on_destruct(pos)** `on_destruct` node callback implementation. Display nodes should have this callback (removes display entities on node destruction). ### on_rotate -**display\_lib.on\_rotate(pos, node, user, mode, new_param2)** +**display\_api.on\_rotate(pos, node, user, mode, new_param2)** `on_rotate` node callback implementation. Display nodes should have this callback (restricts rotations and rotates display entities associated with node). ### on_activate -**display\_lib.on_activate(entity, staticdata)** +**display\_api.on_activate(entity, staticdata)** `On_activate` entity callback implementation for display entities. No need of this method if display entities have been registered using `register_display_entity` (callback is already set). @@ -40,17 +40,16 @@ This is a helper to register entities used for display. * Register display entities with `register_display_entity` * Register node with : - - `on_place`, `on_construct`, `on_destruct` and `on_rotate` callbacks using display_api callbacks. - - `display_api` group. This will make this node have their entities updated as soon as the mapblock is loaded (Useful after /clearobjects). - - a `display_entities` field in node definition containing a entity name indexed table. See below for description of each display_entities fields. + - `on_place`, `on_construct`, `on_destruct` and `on_rotate` callbacks using display_api callbacks.\ + - `display_api` group. This will make this node have their entities updated as soon as the mapblock is loaded (Useful after /clearobjects).\ + - a `display_entities` field in node definition containing a entity name indexed table. See below for description of each display_entities fields.\ ### Display_entities fields -`on_display_update` is a callback in charge of setting up entity texture. If not set, entity will have no texture and will be displayed as unknown item. - -`depth`, `right` and `height`: Entity position regarding to node facedir/wallmounted main axis. -Values for these fields can be any number between -1.5 and 1.5 (default value is 0). -Position 0,0,0 is the center of the node. -`depth` goes from front (-0.5) to rear (0.5), `height` goes from bottom (-0.5) to top (0.5) and `right` goes from left (-0.5) to right (0.5). +`on_display_update` is a callback in charge of setting up entity texture. If not set, entity will have no texture and will be displayed as unknown item.\ +`depth`, `right` and `height`: Entity position regarding to node facedir/wallmounted main axis.\ +Values for these fields can be any number between -1.5 and 1.5 (default value is 0). Position 0,0,0 is the center of the node.\ +`depth` goes from front (-0.5) to rear (0.5), `height` goes from bottom (-0.5) to top (0.5) and `right` goes from left (-0.5) to right (0.5).\ +`yaw`: Entity yaw in radians, regarding to main axis. Default is 0, aligned to node face. In order to avoid flickering text, it's better to have text a little behind node surface. A good spacing value is given by `display_api.entity_spacing` variable. diff --git a/font_api/API.md b/font_api/API.md index f3f4437..80b1121 100644 --- a/font_api/API.md +++ b/font_api/API.md @@ -1,5 +1,5 @@ -# Font Lib API -This document describes Font Lib API. Font Lib creates textures for font display on entities. +# Font API +This document describes Font API. Font API creates textures for font display on entities. ## Settings ### default_font @@ -97,7 +97,7 @@ Standard on_display_update entity callback. Node should have a corresponding display_entity with size, resolution and maxlines fields and optionally halign, valign and color fields. -### Font definition table +## Font definition table Font definition table used by **font_api.register_font** and **font\_api.Font:new** may/can contain following elements: * `height` (required): Font height in pixels (all font textures should have the same height) . @@ -108,6 +108,14 @@ Font definition table used by **font_api.register_font** and **font\_api.Font:ne `margintop`, `marginbottom` and `linespacing` can be negative numbers (default 0) and are to be used to adjust various font styles to each other. +Font attributes around a single char:\ +![Font attributes on a char](doc/font.svg) + +Font attributes effects on several lines:\ +![Font attributes on lines](doc/lines.svg) + +#### Additional requirements + Font must have a char 0 which will be used to display any unknown char. All textures corresponding to the indexes in widths array should be present in textures directory with a name matching the pattern : -- cgit v1.2.3