Merge remote-tracking branch 'upstream/master'
commit
c2637cfd30
82
README.md
82
README.md
|
@ -1,5 +1,5 @@
|
|||
# Display Modpack
|
||||
Version 1.2.1
|
||||
# Display Modpack
|
||||
Version 1.3.1
|
||||
|
||||
This modpack provides mods with dynamic display. Mods are :
|
||||
|
||||
|
@ -22,100 +22,94 @@ For more information, see the [forum topic](https://forum.minetest.net/viewtopic
|
|||
|
||||
*Metro* and *Tiny Cursive* fonts are provided in **Display Modpack** (in **font_metro** and **boards** mods) but you can add more fonts by installing font mods. Be aware that each font mod comes with numerous textures. This can result in slowing media downloading and/or client display.
|
||||
|
||||
Extra font mods can be found here:
|
||||
Extra font mods can be found here:
|
||||
* [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 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);
|
||||
* `font_lib` global table (use `font_api` global table instead);
|
||||
|
||||
These objects will be removed in the future.
|
||||
|
||||
## Changelog
|
||||
### 2019-03-14 (Version 1.3.1)
|
||||
- __dispay_api__: Display API now detects automatically whenr rotation restrictions have to be applied.
|
||||
- __sign_api__: Screwdriver behavior changed. Now, left click rotates and changes direction.
|
||||
|
||||
### 2019-03-09 (Version 1.3)
|
||||
- __display_api__: Display nodes can be rotated in every directions (if running Minetest 5 or above).
|
||||
- __display_api__: New setting to restrict rotations to Minetest 0.4 abilities (restriction enabled by default).
|
||||
- __sign_api__: Changed behavior of screwdriver if no rotation restriction.
|
||||
|
||||
### 2018-12-14 (Version 1.2.3)
|
||||
- __display_api__: New `yaw` attributes, entities can now have different angles with node.
|
||||
- __font_api__: New `Font:render` method for texture creation
|
||||
- __font_api__: Specific management for fixed width font. Allows number of columns based texture width.
|
||||
- __font_api__: Improve `display_api` integration into `font_api`. Display API fully optional. `font_api.on_display_update` defined only if `display_api` enabled.
|
||||
- __font_api__: Improve management of invalid UTF strings (should not crash anymore)
|
||||
- __font_api__: Deprecation of `font_lib`
|
||||
- __signs__: Fixed craft recipe for labels
|
||||
|
||||
### 2018-12-02 (Version 1.2.2)
|
||||
- Fixed a bug that prevented Display API from working on some systems (Raspberry Pi)
|
||||
|
||||
### 2018-11-01 (Version 1.2.1)
|
||||
|
||||
- Now font can be chosen per sign / stele
|
||||
|
||||
### 2018-11-01 (Version 1.2)
|
||||
|
||||
- Labels and woodend signs added.
|
||||
|
||||
- Fallback mechanism for missing chars (For example: "é" --> "e" --> "E").
|
||||
|
||||
- Several bug fixes by 12Me21 and naturefreshmilk.
|
||||
|
||||
### 2018-07-16 (Version 1.1.1)
|
||||
|
||||
- Boards mod added.
|
||||
|
||||
- Bug fix in default font chosing when multiple font registered.
|
||||
- Bug fix in default font chosing when multiple font registered.
|
||||
|
||||
### 2018-07-13 (Version 1.1.0)
|
||||
|
||||
- Font API rework introducing Font class.
|
||||
|
||||
- Replaced default Epilepsy Font by Metro Font for licensing purposes,
|
||||
|
||||
- Rework of all nodes displaying text accordingly to the Font API rework.
|
||||
|
||||
As font_epilepsy mod has been replaced by font_metro mod, **don't forget to activate font_metro mod after updating** or you won't have any text displayed.
|
||||
|
||||
### 2018-05-30 (Version 1.0.1)
|
||||
|
||||
Mostly bug fixes :
|
||||
|
||||
- Fix steles orientation when placing
|
||||
|
||||
- Update entity on mapblock load
|
||||
|
||||
- Use default formspec style
|
||||
|
||||
- Fix ndef nill value in steles mod when technics not installed
|
||||
|
||||
- Seperate signs API from signs définitions
|
||||
|
||||
- Allow a greater offset between display and block
|
||||
|
||||
### 2018-01-13 (Version 1.0)
|
||||
|
||||
- Switch to Epilepsy font by KREATIVE SOFTWARE
|
||||
|
||||
- Add settings "default_font"
|
||||
|
||||
- Add horizontal alignment
|
||||
|
||||
- Add tool for creating font textures from .ttf font files
|
||||
|
||||
- Fix UTF 8 to Unicode decoding
|
||||
|
||||
- Fix UTF 8 to Unicode decoding
|
||||
- Updated forum thread link in README.md
|
||||
|
||||
### 2017-12-19
|
||||
|
||||
This change is a preparation to merge Andrzej Pieńkowski fork (apienk) : new font and support of UTF chars.
|
||||
|
||||
- Font\_lib support for multiple fonts (nothing yet visible in mods) ;
|
||||
|
||||
- Font\_lib support for Unicode characters (limited to Unicode Plane 0: 0000-FFFF, see [Wikipedia](https://en.wikipedia.org/wiki/Unicode)) ;
|
||||
|
||||
- Font\_lib support for Unicode characters (limited to Unicode Plane 0: 0000-FFFF, see [Wikipedia](https://en.wikipedia.org/wiki/Unicode)) ;
|
||||
- New "default" font with original textures from Vanessa Ezekowitz (VanessaE) ;
|
||||
|
||||
### 2017-12-10
|
||||
|
||||
- Compatibility of signs mod with signs_lib (thanks to gpcf) ;
|
||||
|
||||
- Added large banner in road signs (thanks to gpcf) ;
|
||||
|
||||
### 2017-08-26
|
||||
|
||||
- Changed signs from wallmounted to facedir to improve textures and make it possible to use screwdriver.
|
||||
- Changed signs from wallmounted to facedir to improve textures and make it possible to use screwdriver.
|
||||
**IMPORTANT** : Map will be updated to change to new nodes but inventory items will turn into "Unknown items" and have to be re-crafted.
|
||||
|
||||
- Intllib support added with french translation (whole modpack, thanks to fat115) ;
|
||||
|
||||
- Punch on nodes to update entity (signs, signs_road and steles). Usefull in case of /clearobjects ;
|
||||
|
||||
- Changed wooden direction sign textures (signs) ;
|
||||
|
||||
- Added back and side textures to all signs (road_signs) ;
|
||||
|
||||
- Added more sign types : White/yellow/green signs and direction signs (signs_road) ;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
name=boards
|
||||
description=Writable school boards using sign_api
|
||||
depends=default,signs_api
|
|
@ -1,58 +1,56 @@
|
|||
# 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.
|
||||
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_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).
|
||||
`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).
|
||||
|
||||
## Howto register a display node
|
||||
* 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_modpack_node` 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 `top`: 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), `top` 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.
|
||||
|
||||
|
@ -61,12 +59,12 @@ In order to avoid flickering text, it's better to have text a little behind node
|
|||
display_api.register_display_entity("mymod:entity1")
|
||||
display_api.register_display_entity("mymod:entity2")
|
||||
|
||||
function my_display_update1(pos, objref)
|
||||
function my_display_update1(pos, objref)
|
||||
objref:set_properties({ textures= {"mytexture1.png"},
|
||||
visual_size = {x=1, y=1} })
|
||||
end
|
||||
|
||||
function my_display_update2(pos, objref)
|
||||
function my_display_update2(pos, objref)
|
||||
objref:set_properties({ textures= {"mytexture2.png"},
|
||||
visual_size = {x=1, y=1} })
|
||||
end
|
||||
|
@ -75,14 +73,14 @@ In order to avoid flickering text, it's better to have text a little behind node
|
|||
...
|
||||
paramtype2 = "facedir",
|
||||
...
|
||||
groups = { display_modpack_node = 1, ... },
|
||||
groups = { display_api = 1, ... },
|
||||
...
|
||||
display_entities = {
|
||||
["mymod:entity1"] = {
|
||||
["mymod:entity1"] = {
|
||||
depth = 0.3,
|
||||
on_display_update = my_display_update1 },
|
||||
["mymod:entity1"] = {
|
||||
depth = 0.2, height = 0.1,
|
||||
["mymod:entity1"] = {
|
||||
depth = 0.2, top = 0.1,
|
||||
on_display_update = my_display_update2 },
|
||||
},
|
||||
...
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
This library's purpose is to ease creation of nodes with one or more displays on sides. For example, signs and clocks. Display can be dynamic and/or different for each node instance.
|
||||
|
||||
**Limitations**: This lib uses entities to draw display. This means display has to be vertical. So display nodes rotation are limitated to "upside up" positions.
|
||||
**Limitations**: This lib uses entities to draw display. This means display has to be vertical (and "upside up") on Minetest before version 5.0.
|
||||
|
||||
**Dependancies**:default
|
||||
|
||||
|
@ -12,3 +12,23 @@ 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.
|
||||
|
||||
## Change log
|
||||
### 2019-03-14
|
||||
- __dispay_api__: Display API now detects automatically whenr rotation restrictions have to be applied.
|
||||
|
||||
### 2019-03-09
|
||||
- __display_api__: Display nodes can be rotated in every directions (if running Minetest 5 or above).
|
||||
- __display_api__: New setting to restrict rotations to Minetest 0.4 abilities (restriction enabled by default).
|
||||
|
||||
### 2018-12-14
|
||||
- __display_api__: New `yaw` attributes, entities can now have different angles with node.
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
--[[
|
||||
display_api mod for Minetest - Library to add dynamic display
|
||||
capabilities to nodes
|
||||
(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 <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Deprecation
|
||||
|
||||
function deprecated_group(deprecated_group, replacement_group)
|
||||
for name, ndef in pairs(minetest.registered_nodes) do
|
||||
if ndef.groups and ndef.groups[deprecated_group] then
|
||||
minetest.log("warning", string.format(
|
||||
'Node %s belongs to deprecated "%s" group which should be replaced with new "%s" group.',
|
||||
name, deprecated_group, replacement_group))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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, "deprecated global does not exist.")
|
||||
if _G[replacement_global_name] == nil then
|
||||
minetest.log('warning', string.format(
|
||||
'Replacement global "%s" does not exists.', replacement_global_name))
|
||||
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(
|
||||
'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(
|
||||
'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(1) -- December 2018 - Deprecation of groups display_modpack_node and display_lib_node
|
||||
-- Group to be removed from display API register_lbm
|
||||
minetest.after(0, function()
|
||||
deprecated_group("display_modpack_node", "display_api")
|
||||
deprecated_group("display_lib_node", "display_api")
|
||||
end)
|
||||
|
||||
-- deprecated(2) -- December 2018 - Deprecation of display_lib
|
||||
deprecated_global_table('display_lib', 'display_api')
|
|
@ -0,0 +1,318 @@
|
|||
--[[
|
||||
display_api mod for Minetest - Library to add dynamic display
|
||||
capabilities to nodes
|
||||
(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 <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Prefered gap between node and entity
|
||||
-- Entity positionment is up to mods but it is a good practice to use this
|
||||
-- variable as spacing between entity and node
|
||||
display_api.entity_spacing = 0.002
|
||||
|
||||
-- Maximum entity position relative to the node pos
|
||||
local max_entity_pos = 1.5
|
||||
|
||||
local wallmounted_rotations = {
|
||||
[0]={x=1, y=0, z=0}, [1]={x=3, y=0, z=0},
|
||||
[2]={x=0, y=3, z=0}, [3]={x=0, y=1, z=0},
|
||||
[4]={x=0, y=0, z=0}, [5]={x=0, y=2, z=0},
|
||||
}
|
||||
|
||||
local facedir_rotations = {
|
||||
[ 0]={x=0, y=0, z=0}, [ 1]={x=0, y=3, z=0},
|
||||
[ 2]={x=0, y=2, z=0}, [ 3]={x=0, y=1, z=0},
|
||||
[ 4]={x=3, y=0, z=0}, [ 5]={x=0, y=3, z=3},
|
||||
[ 6]={x=1, y=0, z=2}, [ 7]={x=0, y=1, z=1},
|
||||
[ 8]={x=1, y=0, z=0}, [ 9]={x=0, y=3, z=1},
|
||||
[10]={x=3, y=0, z=2}, [11]={x=0, y=1, z=3},
|
||||
[12]={x=0, y=0, z=1}, [13]={x=3, y=0, z=1},
|
||||
[14]={x=2, y=0, z=1}, [15]={x=1, y=0, z=1},
|
||||
[16]={x=0, y=0, z=3}, [17]={x=1, y=0, z=3},
|
||||
[18]={x=2, y=0, z=3}, [19]={x=3, y=0, z=3},
|
||||
[20]={x=0, y=0, z=2}, [21]={x=0, y=1, z=2},
|
||||
[22]={x=0, y=2, z=2}, [23]={x=0, y=3, z=2},
|
||||
}
|
||||
|
||||
-- Compute other useful values depending on wallmounted and facedir param
|
||||
local wallmounted_values = {}
|
||||
local facedir_values = {}
|
||||
|
||||
local function compute_values(r)
|
||||
local function rx(v) return { x=v.x, y=v.z, z=-v.y} end
|
||||
local function ry(v) return { x=-v.z, y=v.y, z=v.x} end
|
||||
local function rz(v) return { x=v.y, y=-v.x, z=v.z} end
|
||||
|
||||
local d = { x = 0, y = 0, z = 1 }
|
||||
local w = { x = 1, y = 0, z = 0 }
|
||||
local h = { x = 0, y = 1, z = 0 }
|
||||
|
||||
-- Important to keep z rotation first (not same results)
|
||||
for _ = 1, r.z do d, w, h = rz(d), rz(w), rz(h) end
|
||||
for _ = 1, r.x do d, w, h = rx(d), rx(w), rx(h) end
|
||||
for _ = 1, r.y do d, w, h = ry(d), ry(w), ry(h) end
|
||||
|
||||
return {
|
||||
rotation=r, depth=d, width=w, height=h,
|
||||
restricted=(r.x==0 and r.z==0) }
|
||||
end
|
||||
|
||||
for i, r in pairs(facedir_rotations) do
|
||||
facedir_values[i] = compute_values(r)
|
||||
end
|
||||
|
||||
for i, r in pairs(wallmounted_rotations) do
|
||||
wallmounted_values[i] = compute_values(r)
|
||||
end
|
||||
|
||||
-- Detect rotation restriction
|
||||
local rotation_restricted = nil
|
||||
minetest.register_entity('display_api:dummy_entity', {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "upright_sprite",
|
||||
textures = {} })
|
||||
|
||||
function display_api.is_rotation_restricted()
|
||||
if rotation_restricted == nil then
|
||||
local objref = minetest.add_entity(
|
||||
{x=0, y=0, z=0}, 'display_api:dummy_entity')
|
||||
if objref then
|
||||
rotation_restricted = objref.set_rotation == nil
|
||||
objref:remove()
|
||||
end
|
||||
end
|
||||
return rotation_restricted
|
||||
end
|
||||
|
||||
-- Clip position property to maximum entity position
|
||||
|
||||
local function clip_pos_prop(posprop)
|
||||
if posprop then
|
||||
return math.max(-max_entity_pos, math.min(max_entity_pos, posprop))
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
-- Get values needed for orientation computation of node
|
||||
|
||||
local function get_orientation_values(node)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
if ndef then
|
||||
local paramtype2 = ndef.paramtype2
|
||||
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
||||
return wallmounted_values[node.param2 % 8]
|
||||
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
||||
return facedir_values[node.param2 % 32]
|
||||
else
|
||||
-- No orientation or unknown orientation type
|
||||
return facedir_values[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Gets the display entities attached with a node.
|
||||
-- Add missing and remove duplicates
|
||||
|
||||
local function get_display_objrefs(pos, create)
|
||||
local objrefs = {}
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
if ndef and ndef.display_entities then
|
||||
for _, objref in
|
||||
ipairs(minetest.get_objects_inside_radius(pos, max_entity_pos)) do
|
||||
local entity = objref:get_luaentity()
|
||||
if entity and ndef.display_entities[entity.name] and
|
||||
entity.nodepos and vector.equals(pos, entity.nodepos) then
|
||||
if objrefs[entity.name] then
|
||||
objref:remove() -- Remove duplicates
|
||||
else
|
||||
objrefs[entity.name] = objref
|
||||
end
|
||||
end
|
||||
end
|
||||
if create then
|
||||
-- Add missing
|
||||
for name, _ in pairs(ndef.display_entities) do
|
||||
if not objrefs[name] then
|
||||
objrefs[name] = minetest.add_entity(pos, name,
|
||||
minetest.serialize({ nodepos = pos }))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return objrefs
|
||||
end
|
||||
|
||||
--- Force entity update : position and texture
|
||||
function display_api.update_entities(pos)
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
local ov = get_orientation_values(node)
|
||||
|
||||
for _, objref in pairs(get_display_objrefs(pos, true)) do
|
||||
local edef = ndef.display_entities[objref:get_luaentity().name]
|
||||
local depth = clip_pos_prop(edef.depth)
|
||||
local right = clip_pos_prop(edef.right)
|
||||
local top = clip_pos_prop(edef.top)
|
||||
|
||||
objref:set_pos({
|
||||
x = pos.x + ov.depth.x*depth + ov.width.x*right - ov.height.x*top,
|
||||
y = pos.y + ov.depth.y*depth + ov.width.y*right - ov.height.y*top,
|
||||
z = pos.z + ov.depth.z*depth + ov.width.z*right - ov.height.z*top,
|
||||
})
|
||||
|
||||
if objref.set_rotation then
|
||||
objref:set_rotation({
|
||||
x = ov.rotation.x*math.pi/2,
|
||||
y = ov.rotation.y*math.pi/2 + (edef.yaw or 0),
|
||||
z = ov.rotation.z*math.pi/2,
|
||||
})
|
||||
else
|
||||
if ov.rotation.x ~=0 or ov.rotation.y ~= 0 then
|
||||
minetest.log("warning", string.format(
|
||||
"[display_api] unable to rotate correctly entity for node at %s without set_rotation method.",
|
||||
minetest.pos_to_string(pos)))
|
||||
end
|
||||
objref:set_yaw(ov.rotation.y*math.pi/2 + (edef.yaw or 0))
|
||||
end
|
||||
|
||||
-- Call on_display_update callback of a node for one of its display entities
|
||||
if edef.on_display_update then
|
||||
edef.on_display_update(pos, objref)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- On_activate callback for display_api entities. Calls on_display_update callbacks
|
||||
--- of corresponding node for each entity.
|
||||
function display_api.on_activate(entity, staticdata)
|
||||
if entity then
|
||||
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
||||
local data = minetest.deserialize(staticdata)
|
||||
if data and type(data) == "table" then
|
||||
entity.nodepos = data.nodepos
|
||||
end
|
||||
entity.object:set_armor_groups({immortal=1})
|
||||
end
|
||||
|
||||
if entity.nodepos then
|
||||
local node = minetest.get_node(entity.nodepos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if ndef and ndef.display_entities then
|
||||
local edef = ndef.display_entities[entity.name]
|
||||
if edef then
|
||||
-- Call on_display_update callback of the entity to build texture
|
||||
if edef.on_display_update then
|
||||
edef.on_display_update(entity.nodepos, entity.object)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
-- If we got here, this display entity is buggy and should be removed
|
||||
entity.object:remove()
|
||||
end
|
||||
end
|
||||
|
||||
--- On_place callback for display_api items.
|
||||
-- Does nothing more than preventing node from being placed on ceiling or ground
|
||||
-- TODO:When MT<5 is not in use anymore, simplify this
|
||||
function display_api.on_place(itemstack, placer, pointed_thing, override_param2)
|
||||
local ndef = itemstack:get_definition()
|
||||
local dir = {
|
||||
x = pointed_thing.under.x - pointed_thing.above.x,
|
||||
y = pointed_thing.under.y - pointed_thing.above.y,
|
||||
z = pointed_thing.under.z - pointed_thing.above.z,
|
||||
}
|
||||
|
||||
local rotation_restriction = display_api.is_rotation_restricted()
|
||||
|
||||
if rotation_restriction then
|
||||
-- If item is not placed on a wall, use the player's view direction instead
|
||||
if dir.x == 0 and dir.z == 0 then
|
||||
dir = placer:get_look_dir()
|
||||
end
|
||||
dir.y = 0
|
||||
end
|
||||
|
||||
local param2 = 0
|
||||
if ndef then
|
||||
if ndef.paramtype2 == "wallmounted" or
|
||||
ndef.paramtype2 == "colorwallmounted" then
|
||||
param2 = minetest.dir_to_wallmounted(dir)
|
||||
|
||||
elseif ndef.paramtype2 == "facedir" or
|
||||
ndef.paramtype2 == "colorfacedir" then
|
||||
param2 = minetest.dir_to_facedir(dir, not rotation_restriction)
|
||||
end
|
||||
end
|
||||
return minetest.item_place(itemstack, placer, pointed_thing,
|
||||
param2 + (override_param2 or 0))
|
||||
end
|
||||
|
||||
--- On_construct callback for display_api items.
|
||||
-- Creates entities and update them.
|
||||
function display_api.on_construct(pos)
|
||||
display_api.update_entities(pos)
|
||||
end
|
||||
|
||||
--- On_destruct callback for display_api items.
|
||||
-- Removes entities.
|
||||
function display_api.on_destruct(pos)
|
||||
for _, objref in pairs(get_display_objrefs(pos)) do
|
||||
objref:remove()
|
||||
end
|
||||
end
|
||||
|
||||
-- On_rotate (screwdriver) callback for display_api items. Prevents invalid
|
||||
-- rotations and reorients entities.
|
||||
function display_api.on_rotate(pos, node, user, _, new_param2)
|
||||
node.param2 = new_param2
|
||||
local ov = get_orientation_values(node)
|
||||
|
||||
if ov.restricted or not display_api.is_rotation_restricted() then
|
||||
minetest.swap_node(pos, node)
|
||||
display_api.update_entities(pos)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- Creates display entity with some fields and the on_activate callback
|
||||
function display_api.register_display_entity(entity_name)
|
||||
if not minetest.registered_entities[entity_name] then
|
||||
minetest.register_entity(':'..entity_name, {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "upright_sprite",
|
||||
textures = {},
|
||||
on_activate = display_api.on_activate,
|
||||
get_staticdata = function(self)
|
||||
return minetest.serialize({ nodepos = self.nodepos })
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "Update display_api entities",
|
||||
name = "display_api:update_entities",
|
||||
run_at_every_load = true,
|
||||
nodenames = {"group:display_api",
|
||||
"group:display_modpack_node", "group:display_lib_node"}, -- See deprecated(1)
|
||||
action = function(pos, node) display_api.update_entities(pos) end,
|
||||
})
|
|
@ -1,242 +1,31 @@
|
|||
--[[
|
||||
display_api mod for Minetest - Library to add dynamic display
|
||||
capabilities to nodes
|
||||
(c) Pierre-Yves Rollo
|
||||
display_api mod for Minetest - Library to add dynamic display
|
||||
capabilities to nodes
|
||||
(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 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.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Global variables
|
||||
-------------------
|
||||
|
||||
display_api = {}
|
||||
display_api.name = minetest.get_current_modname()
|
||||
display_api.path = minetest.get_modpath(display_api.name)
|
||||
|
||||
-- Prefered gap between node and entity
|
||||
-- Entity positionment is up to mods but it is a good practice to use this
|
||||
-- variable as spacing between entity and node
|
||||
display_api.entity_spacing = 0.002
|
||||
-- Inclusions
|
||||
-------------
|
||||
|
||||
-- Miscelaneous values depending on wallmounted param2
|
||||
local wallmounted_values = {
|
||||
[2]={dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2},
|
||||
[3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 },
|
||||
[4]={dx=0, dz=-1, rx=1, rz=0, yaw=0 },
|
||||
[5]={dx=0, dz=1, rx=-1, rz=0, yaw=math.pi }
|
||||
}
|
||||
|
||||
-- Miscelaneous values depending on facedir param2
|
||||
local facedir_values = {
|
||||
[0]={dx=0, dz=-1, rx=1, rz=0, yaw=0 },
|
||||
[1]={dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2},
|
||||
[2]={dx=0, dz=1, rx=-1, rz=0, yaw=math.pi },
|
||||
[3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 }
|
||||
}
|
||||
|
||||
-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity,
|
||||
local function get_values(node)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
if ndef then
|
||||
local paramtype2 = ndef.paramtype2
|
||||
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
||||
return wallmounted_values[node.param2 % 8]
|
||||
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
||||
return facedir_values[node.param2 % 32]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Checks if the object is related to the given position
|
||||
local function check_entity_pos(pos, objref)
|
||||
local real_pos = vector.round(objref:get_pos())
|
||||
local pos_hash = objref:get_luaentity().pos
|
||||
if pos_hash == nil then
|
||||
return vector.equals(real_pos, vector.round(pos))
|
||||
else
|
||||
return vector.equals(minetest.get_position_from_hash(pos_hash), pos)
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets the display entities attached with a node. Removes extra ones
|
||||
local function get_entities(pos)
|
||||
local objrefs = {}
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
if ndef and ndef.display_entities then
|
||||
for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 1.5)) do
|
||||
local entity = objref:get_luaentity()
|
||||
if entity and ndef.display_entities[entity.name] and check_entity_pos(pos, objref) then
|
||||
if objrefs[entity.name] then
|
||||
objref:remove()
|
||||
else
|
||||
objrefs[entity.name] = objref
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return objrefs
|
||||
end
|
||||
|
||||
local function clip_pos_prop(posprop)
|
||||
if posprop then
|
||||
return math.max(-1.5, math.min(1.5, posprop))
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
--- (Create and) place display entities according to the node orientation
|
||||
local function place_entities(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
local values = get_values(node)
|
||||
local objrefs = get_entities(pos)
|
||||
|
||||
if values and ndef and ndef.display_entities then
|
||||
|
||||
for entity_name, props in pairs(ndef.display_entities) do
|
||||
local depth = clip_pos_prop(props.depth)
|
||||
local right = clip_pos_prop(props.right)
|
||||
local top = clip_pos_prop(props.top)
|
||||
if not objrefs[entity_name] then
|
||||
objrefs[entity_name] = minetest.add_entity(pos, entity_name)
|
||||
end
|
||||
|
||||
objrefs[entity_name]:setpos({
|
||||
x = pos.x - values.dx * depth + values.rx * right,
|
||||
y = pos.y - top,
|
||||
z = pos.z - values.dz * depth + values.rz * right})
|
||||
|
||||
objrefs[entity_name]:setyaw(values.yaw)
|
||||
end
|
||||
end
|
||||
return objrefs
|
||||
end
|
||||
|
||||
--- Call on_display_update callback of a node for one of its display entities
|
||||
local function call_node_on_display_update(pos, objref)
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local entity = objref:get_luaentity()
|
||||
if ndef and ndef.display_entities and entity and ndef.display_entities[entity.name] then
|
||||
ndef.display_entities[entity.name].on_display_update(pos, objref)
|
||||
end
|
||||
end
|
||||
|
||||
--- Force entity update
|
||||
function display_api.update_entities(pos)
|
||||
local objrefs = place_entities(pos)
|
||||
for _, objref in pairs(objrefs) do
|
||||
objref:get_luaentity().pos = minetest.hash_node_position(pos)
|
||||
call_node_on_display_update(pos, objref)
|
||||
end
|
||||
end
|
||||
|
||||
--- On_activate callback for display_api entities. Calls on_display_update callbacks
|
||||
--- of corresponding node for each entity.
|
||||
function display_api.on_activate(entity, staticdata)
|
||||
if entity then
|
||||
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
||||
local data = core.deserialize(staticdata)
|
||||
if data and type(data) == "table" then
|
||||
entity.pos = data.pos
|
||||
end
|
||||
end
|
||||
entity.object:set_armor_groups({immortal=1})
|
||||
local pos
|
||||
if entity.pos then
|
||||
pos = minetest.get_position_from_hash(entity.pos)
|
||||
else
|
||||
pos = entity.object:getpos()
|
||||
end
|
||||
display_api.update_entities(pos)
|
||||
end
|
||||
end
|
||||
|
||||
--- On_place callback for display_api items. Does nothing more than preventing item
|
||||
--- from being placed on ceiling or ground
|
||||
function display_api.on_place(itemstack, placer, pointed_thing, override_param2)
|
||||
local ndef = itemstack:get_definition()
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local dir = {x = under.x - above.x,
|
||||
y = 0,
|
||||
z = under.z - above.z}
|
||||
|
||||
-- If item is not placed on a wall, use the player's view direction instead
|
||||
if dir.x == 0 and dir.z == 0 then
|
||||
dir = placer:get_look_dir()
|
||||
dir.y = 0
|
||||
end
|
||||
|
||||
local param2 = 0
|
||||
if ndef then
|
||||
local paramtype2 = ndef.paramtype2
|
||||
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
||||
param2 = minetest.dir_to_wallmounted(dir)
|
||||
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
||||
param2 = minetest.dir_to_facedir(dir)
|
||||
end
|
||||
end
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, param2 + (override_param2 or 0))
|
||||
end
|
||||
|
||||
--- On_construct callback for display_api items. Creates entities and update them.
|
||||
function display_api.on_construct(pos)
|
||||
display_api.update_entities(pos)
|
||||
end
|
||||
|
||||
--- On_destruct callback for display_api items. Removes entities.
|
||||
function display_api.on_destruct(pos)
|
||||
local objrefs = get_entities(pos)
|
||||
|
||||
for _, objref in pairs(objrefs) do
|
||||
objref:remove()
|
||||
end
|
||||
end
|
||||
|
||||
-- On_rotate (screwdriver) callback for display_api items. Prevents invalid rotations and reorients entities.
|
||||
function display_api.on_rotate(pos, node, user, _, new_param2)
|
||||
node.param2 = new_param2
|
||||
if get_values(node) then
|
||||
minetest.swap_node(pos, node)
|
||||
place_entities(pos)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- Creates display entity with some fields and the on_activate callback
|
||||
function display_api.register_display_entity(entity_name)
|
||||
if not minetest.registered_entity then
|
||||
minetest.register_entity(':'..entity_name, {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "upright_sprite",
|
||||
textures = {},
|
||||
on_activate = display_api.on_activate,
|
||||
get_staticdata = function(self)
|
||||
return minetest.serialize({
|
||||
pos = self.pos,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "Update display_api entities",
|
||||
name = "display_api:update_entities",
|
||||
run_at_every_load = true,
|
||||
nodenames = {"group:display_modpack_node", "group:display_lib_node"},
|
||||
action = function(pos, node) display_api.update_entities(pos) end,
|
||||
})
|
||||
|
||||
-- Compatibility
|
||||
display_lib = display_api
|
||||
dofile(display_api.path.."/display.lua")
|
||||
dofile(display_api.path.."/deprecation.lua")
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
name=display_api
|
||||
description=A library for adding dynamic textures on nodes
|
168
font_api/API.md
168
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
|
||||
|
@ -7,35 +7,114 @@ Name of the font to be used when no font is given. The font should be registered
|
|||
|
||||
If no default\_font given or if default\_font given but not registered, the first registered font will be used as default.
|
||||
|
||||
## Provided methods
|
||||
## Use font_api with display_api (to display text on nodes)
|
||||
### Base setup
|
||||
Font_api offers a direct integration with display_api to display text on nodes.
|
||||
|
||||
First of all, create a display node with an entity.
|
||||
To do this, refer to API.md in display_api mod, in particular "Howto register a display node".
|
||||
|
||||
The only requirement then is to connect the `on_display_update` callback of the display entity to `font_api.on_display_update`:
|
||||
|
||||
```
|
||||
minetest.register_node("mymod:test_text_node", {
|
||||
...
|
||||
paramtype2 = "facedir",
|
||||
...
|
||||
groups = { display_api = 1, ... },
|
||||
...
|
||||
display_entities = {
|
||||
["mymod:text"] = {
|
||||
depth = -0.5 - display_api.entity_spacing,
|
||||
on_display_update = font_api.on_display_update },
|
||||
}
|
||||
...
|
||||
on_place = display_api.on_place,
|
||||
on_construct = display_api.on_construct,
|
||||
on_destruct = display_api.on_destruct,
|
||||
on_rotate = display_api.on_rotate,
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
At this step, your node already displays text form "display_text" (by default) node meta. If you want to store your text into another meta data field, add a `meta_text` field to display entity definition.
|
||||
|
||||
But it uses defaults (default font, default size, default color). Likely you need something more.
|
||||
|
||||
### Style your text
|
||||
Font style and size can be chosen by adding some more entries to the display_entities definition table.
|
||||
|
||||
#### Font size
|
||||
Font size can be defined in various ways (maybe more in the future).
|
||||
Start with a number of lines, and font_api will make it fit to the entity size.
|
||||
* `maxlines` or `lines`: Number of maximum lines of text to be displayed. The font height will be adjusted accordingly.
|
||||
|
||||
Then specify the char width. Two methods available:
|
||||
* `aspect_ratio`: Defines the aspect ratio of chars. Works with all fonts. Should not be used if `columns` is specified.
|
||||
* `columns`: Only if using a fixed width font, specifies the number of columns to display.
|
||||
|
||||
#### Font style
|
||||
* `font_name`: name of the font to use. Should correspond to a registered font (from a font mod). If not specified or font not found, default font is used.
|
||||
* `color`: color to be used (default black).
|
||||
* `halign`: Horizontal alignment: "left", "center" or "right" (default "center").
|
||||
* `valign`: Vertical alignement: "top", "middle" or "bottom" (default "middle").
|
||||
|
||||
### Example
|
||||
Using blue //botic// font, three lines height, aligned top left. Text stored in "text" node meta.
|
||||
```
|
||||
minetest.register_node("mymod:test_text_node", {
|
||||
...
|
||||
...
|
||||
display_entities = {
|
||||
["mymod:text"] = {
|
||||
depth = -0.5 - display_api.entity_spacing,
|
||||
on_display_update = font_api.on_display_update
|
||||
meta_text = "text",
|
||||
font_name = "botic",
|
||||
color = "#0000FF",
|
||||
maxlines = 3,
|
||||
aspect_ratio = 0.5,
|
||||
halign = "left",
|
||||
valign = "top",
|
||||
},
|
||||
}
|
||||
...
|
||||
})
|
||||
```
|
||||
## Provided methods
|
||||
### font_api.get_default_font_name()
|
||||
Returns de default font name.
|
||||
|
||||
### font_api.register_font(font_name, font_def)
|
||||
Register a new font.
|
||||
**font_name**: Name of the font to register. If registering different sizes of the same font, add size in the font name (e.g. times_10, times_12...).
|
||||
**font_def**: Font definition table (see **Font definition table** below).
|
||||
* `font_name`: Name of the font to register. If registering different sizes of the same font, add size in the font name (e.g. times_10, times_12...).
|
||||
* `font_def`: Font definition table (see **Font definition table** below).
|
||||
|
||||
### font_api.on_display_update(pos, objref)
|
||||
Standard on_display_update entity callback.
|
||||
|
||||
**pos**: Node position
|
||||
|
||||
**objref**: Object reference of entity
|
||||
* `pos`: Node position
|
||||
* `objref`: Object reference of entity
|
||||
|
||||
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) .
|
||||
* **widths** (required): Array of character widths in pixels, indexed by UTF codepoints.
|
||||
* **margintop** (optional): Margin (in texture pixels) added on top of each char texture.
|
||||
* **marginbottom** (optional): Margin (in texture pixels) added at bottom of each char texture.
|
||||
* **linespacing** (optional): Spacing (in texture pixels) between each lines.
|
||||
* `height` (required): Font height in pixels (all font textures should have the same height) .
|
||||
* `widths` (required): Array of character widths in pixels, indexed by UTF codepoints.
|
||||
* `margintop` (optional): Margin (in texture pixels) added on top of each char texture.
|
||||
* `marginbottom` (optional): Margin (in texture pixels) added at bottom of each char texture.
|
||||
* `linespacing` (optional): Spacing (in texture pixels) between each lines.
|
||||
|
||||
**margintop**, **marginbottom** and **linespacing** can be negative numbers (default 0) and are to be used to adjust various font styles to each other.
|
||||
`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.
|
||||
|
||||
|
@ -57,7 +136,7 @@ Still in early stage of development, these tools are helpers to create font mods
|
|||
|
||||
### make_font_texture.sh
|
||||
|
||||
This scripts takes a .ttf file as input and create one .png file per char, that can be used as font texture. Launch it from your future font mod directory.
|
||||
This scripts takes a .ttf file as input and create one .png file per char, that can be used as font texture. Launch it from your future font mod directory.
|
||||
|
||||
__Advice__
|
||||
|
||||
|
@ -95,51 +174,28 @@ __Syntax__
|
|||
A font usable with font API. This class is supposed to be for internal use but who knows.
|
||||
|
||||
### font\_api.Font:new(def)
|
||||
Create a new font object.
|
||||
Create a new font object.
|
||||
* `def` is a table containing font definition. See **Font definition table** above.
|
||||
|
||||
**def** is a table containing font definition. See **Font definition table** above.
|
||||
|
||||
### font:get_char_width(char)
|
||||
Returns the width of char **char** in texture pixels.
|
||||
|
||||
**char**: Unicode codepoint of char.
|
||||
### font:get_char_width(codepoint)
|
||||
Returns the width of char `codepoint` in texture pixels.
|
||||
* `codepoint`: Unicode codepoint of char.
|
||||
|
||||
### font:get_height(nb_of_lines)
|
||||
Returns line(s) height. Takes care of top and bottom margins and line spacing.
|
||||
|
||||
**nb_of_lines**: Number of lines in the text.
|
||||
* `nb_of_lines`: Number of lines in the text.
|
||||
|
||||
### font:get_width(line)
|
||||
|
||||
Returns the width of a text line. Beware, if line contains any new line char, they are ignored.
|
||||
* `line`: Line of text which the width will be computed.
|
||||
|
||||
**line**: Line of text which the width will be computed.
|
||||
|
||||
### font:make_line_texture(line, texturew, x, y)
|
||||
Create a texture for a text line.
|
||||
|
||||
**line**: Line of text to be rendered in texture.
|
||||
|
||||
**texturew**: Width of the texture (extra text is not rendered).
|
||||
|
||||
**x**: Starting x position in texture.
|
||||
|
||||
**y**: Vertical position of the line in texture.
|
||||
|
||||
### font:make_text_texture(text, texturew, textureh, maxlines, halign, valign, color)
|
||||
### font:renter(text, texturew, textureh, style)
|
||||
Builds texture for a multiline colored text.
|
||||
|
||||
**text**: Text to be rendered.
|
||||
|
||||
**texturew**: Width of the texture (extra text will be truncated).
|
||||
|
||||
**textureh**: Height of the texture.
|
||||
|
||||
**maxlines**: Maximum number of lines.
|
||||
|
||||
**halign**: Horizontal text align ("left"/"center"/"right") (optional).
|
||||
|
||||
**valign**: Vertical text align ("top"/"center"/"bottom") (optional).
|
||||
|
||||
**color**: Color of the text (optional).
|
||||
|
||||
* `text`: Text to be rendered.
|
||||
* `texturew`: Width of the texture (extra text will be truncated).
|
||||
* `textureh`: Height of the texture (extra text will be truncated).
|
||||
* `style`: A table with style indications:
|
||||
- `lines` or `maxlines`: Maximum number of lines (default none).
|
||||
- `halign`: Horizontal text align: "left"/"center"/"right" (default "center")
|
||||
- `valign`: Vertical text align: "top"/"middle"/"bottom" (default "middle")
|
||||
- `color`: Color of the text (default black)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Font API
|
||||
|
||||
This library for font display on entities (to be used with display_api for sign creation).
|
||||
A library for rendernig text on textures (to be used with display_api for sign creation).
|
||||
|
||||
**Dependancies**: default
|
||||
|
||||
|
@ -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.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
display_api?
|
|
@ -0,0 +1,59 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library creating 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 <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- 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, "deprecated global does not exist.")
|
||||
if _G[replacement_global_name] == nil then
|
||||
minetest.log('warning', string.format(
|
||||
'Replacement global "%s" does not exists.', replacement_global_name))
|
||||
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(
|
||||
'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(
|
||||
'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')
|
|
@ -0,0 +1,76 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library creating 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 <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
-- Integration with display API
|
||||
|
||||
if minetest.get_modpath("display_api") then
|
||||
--- Standard on_display_update entity callback.
|
||||
-- Node should have properly configured display_entity.
|
||||
-- @param pos Node position
|
||||
-- @param objref Object reference of entity
|
||||
|
||||
font_api.on_display_update = function (pos, objref)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local entity = objref:get_luaentity()
|
||||
|
||||
if not entity or not ndef.display_entities[entity.name] then
|
||||
return
|
||||
end
|
||||
|
||||
local def = ndef.display_entities[entity.name]
|
||||
local font = font_api.get_font(meta:get_string("font") ~= ""
|
||||
and meta:get_string("font") or def.font_name)
|
||||
|
||||
local text = meta:get_string(def.meta_text or "display_text")
|
||||
|
||||
-- Compute entity resolution accroding to given attributes
|
||||
local texturew, textureh
|
||||
textureh = font:get_height(def.lines or def.maxlines or 1)
|
||||
|
||||
if def.columns then
|
||||
if font.fixedwidth then
|
||||
texturew = def.columns * font.fixedwidth
|
||||
if def.aspect_ratio then
|
||||
minetest.log('warning', "[font_api] 'aspect_ratio' ignored because 'columns' is specified")
|
||||
end
|
||||
else
|
||||
minetest.log('warning', "[font_api] 'columns' ignored because '"..font.name.."' is not a fixed width font.")
|
||||
end
|
||||
end
|
||||
|
||||
if not texturew then
|
||||
if not def.aspect_ratio then
|
||||
minetest.log('warning', "[font_api] No 'aspect_ratio' specified, using default 1.")
|
||||
end
|
||||
texturew = textureh * def.size.x / def.size.y / (def.aspect_ratio or 1)
|
||||
end
|
||||
|
||||
objref:set_properties({
|
||||
textures={ font:render(text, texturew, textureh, {
|
||||
lines = def.maxlines or def.lines,
|
||||
halign = def.halign,
|
||||
valign = def.valign,
|
||||
color = def.color} ) },
|
||||
visual_size = def.size,
|
||||
})
|
||||
end
|
||||
else
|
||||
font_api.on_display_update = function (pos, objref)
|
||||
minetest.log('error', '[font_api] font_api.on_display_update called but display_api mod not enabled.')
|
||||
end
|
||||
end
|
|
@ -1,20 +1,19 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library to add font display capability
|
||||
to display_api mod.
|
||||
(c) Pierre-Yves Rollo
|
||||
font_api mod for Minetest - Library creating 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 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.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- This is the unicode char fallback map. If a char is not present in
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library to add font display capability
|
||||
to display_api mod.
|
||||
(c) Pierre-Yves Rollo
|
||||
font_api mod for Minetest - Library creating 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 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.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Fallback table
|
||||
|
@ -39,14 +38,15 @@ local function char_to_codepoint(str)
|
|||
local bytes = get_char_bytes(str)
|
||||
if bytes == 1 then
|
||||
return str:byte(1)
|
||||
elseif bytes == 2 then
|
||||
elseif bytes == 2 and str:byte(2) ~= nil then
|
||||
return (str:byte(1) - 0xC2) * 0x40
|
||||
+ str:byte(2)
|
||||
elseif bytes == 3 then
|
||||
elseif bytes == 3 and str:byte(2) ~= nil and str:byte(3) ~= nil then
|
||||
return (str:byte(1) - 0xE0) * 0x1000
|
||||
+ str:byte(2) % 0x40 * 0x40
|
||||
+ str:byte(3) % 0x40
|
||||
elseif bytes == 4 then -- Not tested
|
||||
elseif bytes == 4 and str:byte(2) ~= nil and str:byte(3) ~= nil
|
||||
and str:byte(4) ~= nil then -- Not tested
|
||||
return (str:byte(1) - 0xF0) * 0x40000
|
||||
+ str:byte(2) % 0x40 * 0x1000
|
||||
+ str:byte(3) % 0x40 * 0x40
|
||||
|
@ -54,20 +54,6 @@ local function char_to_codepoint(str)
|
|||
end
|
||||
end
|
||||
|
||||
-- Split multiline text into array of lines, with <maxlines> maximum lines.
|
||||
-- Can not use minetest string.split as it has bug if first line(s) empty
|
||||
local function split_lines(text, maxlines)
|
||||
local lines = {}
|
||||
local pos = 1
|
||||
repeat
|
||||
local found = string.find(text, "\n", pos)
|
||||
found = found or #text + 1
|
||||
lines[#lines + 1] = string.sub(text, pos, found - 1)
|
||||
pos = found + 1
|
||||
until (maxlines and (#lines >= maxlines)) or (pos > (#text + 1))
|
||||
return lines
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--- Font class
|
||||
|
||||
|
@ -103,6 +89,16 @@ function Font:new(def)
|
|||
local font = table.copy(def)
|
||||
setmetatable(font, self)
|
||||
self.__index = self
|
||||
|
||||
-- Check if fixedwidth
|
||||
for codepoint, width in pairs(font.widths) do
|
||||
font.fixedwidth = font.fixedwidth or width
|
||||
if width ~= font.fixedwidth then
|
||||
font.fixedwidth = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return font
|
||||
end
|
||||
|
||||
|
@ -121,6 +117,12 @@ function Font:get_next_char(text)
|
|||
|
||||
local codepoint = char_to_codepoint(text)
|
||||
|
||||
if codepoint == nil then
|
||||
minetest.log("warning",
|
||||
"[font_api] Encountered a non UTF char, not displaying text.")
|
||||
return nil, ''
|
||||
end
|
||||
|
||||
-- Fallback mechanism
|
||||
if self.widths[codepoint] == nil then
|
||||
local char = text:sub(1, bytes)
|
||||
|
@ -138,11 +140,11 @@ end
|
|||
--- Returns the width of a given char
|
||||
-- @param char : codepoint of the char
|
||||
-- @return Char width
|
||||
|
||||
function Font:get_char_width(char)
|
||||
-- Replace chars with no texture by the NULL(0) char
|
||||
if self.widths[char] ~= nil then
|
||||
return self.widths[char]
|
||||
function Font:get_char_width(codepoint)
|
||||
if self.fixedwidth then
|
||||
return self.fixedwidth
|
||||
elseif self.widths[codepoint] then
|
||||
return self.widths[codepoint]
|
||||
else
|
||||
return self.widths[0]
|
||||
end
|
||||
|
@ -179,94 +181,94 @@ function Font:get_width(line)
|
|||
|
||||
while line ~= "" do
|
||||
codepoint, line = self:get_next_char(line)
|
||||
if codepoint == nil then return 0 end -- UTF Error
|
||||
width = width + self:get_char_width(codepoint)
|
||||
end
|
||||
|
||||
return width
|
||||
end
|
||||
|
||||
--- Builds texture part for a text line
|
||||
-- @param line Text line to be rendered
|
||||
-- @param texturew Width of the texture (extra text is not rendered)
|
||||
-- @param x Starting x position in texture
|
||||
-- @param y Vertical position of the line in texture
|
||||
-- @return Texture string
|
||||
|
||||
function Font:make_line_texture(line, texturew, x, y)
|
||||
local codepoint
|
||||
local texture = ""
|
||||
line = line or ''
|
||||
|
||||
while line ~= '' do
|
||||
codepoint, line = self:get_next_char(line)
|
||||
|
||||
-- Add image only if it is visible (at least partly)
|
||||
if x + self.widths[codepoint] >= 0 and x <= texturew then
|
||||
texture = texture..
|
||||
string.format(":%d,%d=font_%s_%04x.png",
|
||||
x, y, self.name, codepoint)
|
||||
end
|
||||
x = x + self.widths[codepoint]
|
||||
end
|
||||
|
||||
return texture
|
||||
end
|
||||
|
||||
--- Builds texture for a multiline colored text
|
||||
-- @param text Text to be rendered
|
||||
-- @param texturew Width of the texture (extra text will be truncated)
|
||||
-- @param textureh Height of the texture
|
||||
-- @param maxlines Maximum number of lines
|
||||
-- @param halign Horizontal text align ("left"/"center"/"right") (optional)
|
||||
-- @param valign Vertical text align ("top"/"center"/"bottom") (optional)
|
||||
-- @param color Color of the text (optional)
|
||||
-- @return Texture string
|
||||
--- Legacy make_text_texture method (replaced by "render" - Dec 2018)
|
||||
|
||||
function Font:make_text_texture(text, texturew, textureh, maxlines,
|
||||
halign, valign, color)
|
||||
local texture = ""
|
||||
local lines = {}
|
||||
local textheight = 0
|
||||
local y
|
||||
halign, valign, color)
|
||||
return self:render(text, texturew, textureh, {
|
||||
lines = maxlines,
|
||||
valign = valign,
|
||||
halign = halign,
|
||||
color = color
|
||||
})
|
||||
end
|
||||
|
||||
-- Split text into lines (limited to maxlines fist lines)
|
||||
for num, line in pairs(split_lines(text, maxlines)) do
|
||||
lines[num] = { text = line, width = self:get_width(line) }
|
||||
--- Render text with the font in a view
|
||||
-- @param text Text to be rendered
|
||||
-- @param texturew Width (in pixels) of the texture (extra text will be truncated)
|
||||
-- @param textureh Height (in pixels) of the texture (extra text will be truncated)
|
||||
-- @param style Style of the rendering:
|
||||
-- - lines: maximum number of text lines (if text is limited)
|
||||
-- - halign: horizontal align ("left"/"center"/"right")
|
||||
-- - valign: vertical align ("top"/"center"/"bottom")
|
||||
-- - color: color of the text ("#rrggbb")
|
||||
-- @return Texture string
|
||||
|
||||
function Font:render(text, texturew, textureh, style)
|
||||
local style = style or {}
|
||||
|
||||
-- Split text into lines (and limit to style.lines # of lines)
|
||||
local lines = {}
|
||||
local pos = 1
|
||||
local found, line
|
||||
repeat
|
||||
found = string.find(text, "\n", pos) or (#text + 1)
|
||||
line = string.sub(text, pos, found - 1)
|
||||
lines[#lines + 1] = { text = line, width = self:get_width(line) }
|
||||
pos = found + 1
|
||||
until (style.lines and (#lines >= style.lines)) or (pos > (#text + 1))
|
||||
|
||||
if not #lines then
|
||||
return ""
|
||||
end
|
||||
|
||||
textheight = self:get_height(#lines)
|
||||
local x, y, codepoint
|
||||
local texture = ""
|
||||
local textheight = self:get_height(#lines)
|
||||
|
||||
if #lines then
|
||||
if valign == "top" then
|
||||
y = 0
|
||||
elseif valign == "bottom" then
|
||||
y = textureh - textheight
|
||||
else
|
||||
y = (textureh - textheight) / 2
|
||||
end
|
||||
if style.valign == "top" then
|
||||
y = 0
|
||||
elseif style.valign == "bottom" then
|
||||
y = textureh - textheight
|
||||
else
|
||||
y = (textureh - textheight) / 2
|
||||
end
|
||||
|
||||
y = y + (self.margintop or 0)
|
||||
|
||||
for _, line in pairs(lines) do
|
||||
if halign == "left" then
|
||||
texture = texture..
|
||||
self:make_line_texture(line.text, texturew,
|
||||
0, y)
|
||||
elseif halign == "right" then
|
||||
texture = texture..
|
||||
self:make_line_texture(line.text, texturew,
|
||||
texturew - line.width, y)
|
||||
if style.halign == "left" then
|
||||
x = 0
|
||||
elseif style.halign == "right" then
|
||||
x = texturew - line.width
|
||||
else
|
||||
texture = texture..
|
||||
self:make_line_texture(line.text, texturew,
|
||||
(texturew - line.width) / 2, y)
|
||||
x = (texturew - line.width) / 2
|
||||
end
|
||||
|
||||
while line.text ~= '' do
|
||||
codepoint, line.text = self:get_next_char(line.text)
|
||||
if codepoint == nil then return '' end -- UTF Error
|
||||
|
||||
-- Add image only if it is visible (at least partly)
|
||||
if x + self.widths[codepoint] >= 0 and x <= texturew then
|
||||
texture = texture..
|
||||
string.format(":%d,%d=font_%s_%04x.png", x, y, self.name, codepoint)
|
||||
end
|
||||
x = x + self.widths[codepoint]
|
||||
end
|
||||
|
||||
y = y + self:get_height() + (self.linespacing or 0)
|
||||
end
|
||||
|
||||
texture = string.format("[combine:%dx%d", texturew, textureh)..texture
|
||||
if color then texture = texture.."^[colorize:"..color end
|
||||
if style.color then
|
||||
texture = texture.."^[colorize:"..style.color
|
||||
end
|
||||
return texture
|
||||
end
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library to add font display capability
|
||||
to display_api mod.
|
||||
(c) Pierre-Yves Rollo
|
||||
font_api mod for Minetest - Library creating 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 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.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library to add font display capability
|
||||
to display_api mod.
|
||||
(c) Pierre-Yves Rollo
|
||||
font_api mod for Minetest - Library creating 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 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.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Global variables
|
||||
|
@ -30,36 +29,7 @@ font_api.path = minetest.get_modpath(font_api.name)
|
|||
dofile(font_api.path.."/font.lua")
|
||||
dofile(font_api.path.."/registry.lua")
|
||||
dofile(font_api.path.."/fontform.lua")
|
||||
|
||||
--- 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
|
||||
-- @param pos Node position
|
||||
-- @param objref Object reference of entity
|
||||
|
||||
function font_api.on_display_update(pos, objref)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local text = meta:get_string("display_text")
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local entity = objref:get_luaentity()
|
||||
|
||||
if entity and ndef.display_entities[entity.name] then
|
||||
local def = ndef.display_entities[entity.name]
|
||||
local font = font_api.get_font(meta:get_string("font") ~= ""
|
||||
and meta:get_string("font") or def.font_name)
|
||||
|
||||
local maxlines = def.maxlines or 1 -- TODO:How to do w/o maxlines ?
|
||||
|
||||
objref:set_properties({
|
||||
textures={font:make_text_texture(text,
|
||||
font:get_height(maxlines) * def.size.x / def.size.y
|
||||
/ (def.aspect_ratio or 1),
|
||||
font:get_height(maxlines),
|
||||
def.maxlines, def.halign, def.valign, def.color)},
|
||||
visual_size = def.size
|
||||
})
|
||||
end
|
||||
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")
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
name=font_api
|
||||
description=A library for rendernig text on textures
|
||||
optional_depends=display_api
|
|
@ -1,20 +1,19 @@
|
|||
--[[
|
||||
font_api mod for Minetest - Library to add font display capability
|
||||
to display_api mod.
|
||||
(c) Pierre-Yves Rollo
|
||||
font_api mod for Minetest - Library creating 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 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.
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Global variables
|
||||
|
@ -124,9 +123,9 @@ end
|
|||
-- @param def font definition. A associative array with following keys :
|
||||
-- @key default True (by default) if this font may be used as default font
|
||||
-- @key height (mandatory) Height in pixels of all font textures
|
||||
-- @key widths (mandatory) Array of character widths in pixels, indexed by
|
||||
-- @key widths (mandatory) Array of character widths in pixels, indexed by
|
||||
-- UTF codepoints
|
||||
-- @key margintop (optional) Margin (in texture pixels) added on top of each
|
||||
-- @key margintop (optional) Margin (in texture pixels) added on top of each
|
||||
-- char texture.
|
||||
-- @key marginbottom (optional) dded at bottom of each char texture.
|
||||
-- @key linespacing (optional) Spacing (in texture pixels) between each lines.
|
||||
|
@ -144,19 +143,18 @@ function font_api.register_font(font_name, font_def)
|
|||
|
||||
local font = font_api.Font:new(font_def)
|
||||
|
||||
if font == nil then
|
||||
if font == nil then
|
||||
minetest.log("error", "Unable to register font \""..font_name.."\".")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
font.name = font_name
|
||||
font_api.registered_fonts[font_name] = font
|
||||
font_api.registered_fonts_number = font_api.registered_fonts_number + 1
|
||||
|
||||
|
||||
-- Force to choose again default font
|
||||
-- (allows use of fonts registered after start)
|
||||
default_font = false
|
||||
|
||||
|
||||
minetest.log("action", "New font registered in font_api: "..font_name..".")
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
name=font_metro
|
||||
description=Metro font (latin, accents, cyrillic, greek) for font_api
|
||||
depends=font_api
|
|
@ -0,0 +1,4 @@
|
|||
name=ontime_clocks
|
||||
description=Clocks displaing real ingame time
|
||||
depends=default,dye,display_api
|
||||
optional_depends=intllib
|
|
@ -1,5 +1,5 @@
|
|||
--[[
|
||||
ontime_clocks mod for Minetest - Clock nodes displaying ingame time
|
||||
ontime_clocks mod for Minetest - Clock nodes displaying ingame time
|
||||
(c) Pierre-Yves Rollo
|
||||
|
||||
This file is part of ontime_clocks.
|
||||
|
@ -31,11 +31,11 @@ minetest.register_node("ontime_clocks:green_digital", {
|
|||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_side = { -0.5, -3/16, -7/16, -13/32, 7/32, 7/16 },
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
wall_top = { -7/16, 0.5, -7/32, 7/16, 13/32, 3/16 },
|
||||
wall_bottom = { -7/16, -0.5, -3/16, 7/16, -13/32, 7/32 },
|
||||
},
|
||||
tiles = {"ontime_clocks_digital.png"},
|
||||
groups = {oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1},
|
||||
display_entities = {
|
||||
["ontime_clocks:display"] = {
|
||||
depth = 13/32 - 0.01,
|
||||
|
@ -69,11 +69,11 @@ minetest.register_node("ontime_clocks:red_digital", {
|
|||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_side = { -0.5, -3/16, -7/16, -13/32, 7/32, 7/16 },
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
},
|
||||
tiles = {"ontime_clocks_digital.png"},
|
||||
groups = {oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1},
|
||||
display_entities = {
|
||||
["ontime_clocks:display"] = {
|
||||
depth = 13/32 - 0.01,
|
||||
|
@ -107,12 +107,12 @@ minetest.register_node("ontime_clocks:white", {
|
|||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_side = { -0.5, -7/16, -7/16, -6/16, 7/16, 7/16},
|
||||
wall_bottom = { -7/16, -0.5, -7/16, 7/16, -7/16, 7/16},
|
||||
wall_top = { -7/16, 0.5, -7/16, 7/16, 7/16, 7/16},
|
||||
wall_bottom = { -7/16, -0.5, -7/16, 7/16, -7/16, 7/16},
|
||||
wall_top = { -7/16, 0.5, -7/16, 7/16, 7/16, 7/16},
|
||||
},
|
||||
tiles = {"ontime_clocks_white.png"},
|
||||
groups = {choppy = 1, oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
display_entities = {
|
||||
groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1},
|
||||
display_entities = {
|
||||
["ontime_clocks:display"] = {
|
||||
depth = 6/16 - 0.01,
|
||||
on_display_update = function(pos, objref)
|
||||
|
@ -144,12 +144,12 @@ minetest.register_node("ontime_clocks:frameless_black", {
|
|||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_side = { -0.5, -7/16, -7/16, -0.45, 7/16, 7/16 },
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
},
|
||||
tiles = {"ontime_clocks_frameless.png"},
|
||||
groups = {choppy = 1, oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
display_entities = {
|
||||
groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1},
|
||||
display_entities = {
|
||||
["ontime_clocks:display"] = {
|
||||
depth = 7/16,
|
||||
on_display_update = function(pos, objref)
|
||||
|
@ -181,12 +181,12 @@ minetest.register_node("ontime_clocks:frameless_gold", {
|
|||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_side = { -0.5, -7/16, -7/16, -0.45, 7/16, 7/16 },
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
},
|
||||
tiles = {"ontime_clocks_frameless.png^[colorize:#FF0"},
|
||||
groups = {choppy = 1, oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
display_entities = {
|
||||
groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1},
|
||||
display_entities = {
|
||||
["ontime_clocks:display"] = {
|
||||
depth = 7/16,
|
||||
on_display_update = function(pos, objref)
|
||||
|
@ -218,12 +218,12 @@ minetest.register_node("ontime_clocks:frameless_white", {
|
|||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_side = { -0.5, -7/16, -7/16, -0.45, 7/16, 7/16 },
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
||||
wall_top = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
|
||||
},
|
||||
tiles = {"ontime_clocks_frameless.png^[colorize:#FFF"},
|
||||
groups = {choppy = 1, oddly_breakable_by_hand = 1, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
display_entities = {
|
||||
groups = {oddly_breakable_by_hand=1, not_blocking_trains=1, display_api=1},
|
||||
display_entities = {
|
||||
["ontime_clocks:display"] = {
|
||||
depth = 7/16,
|
||||
on_display_update = function(pos, objref)
|
||||
|
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 353 KiB After Width: | Height: | Size: 348 KiB |
|
@ -54,7 +54,7 @@ minetest.register_craft({
|
|||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'signs:label_small',
|
||||
output = 'signs:label_medium',
|
||||
recipe = {
|
||||
{'default:paper', 'default:paper', 'dye:black'},
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
default
|
||||
dye
|
||||
display_api
|
||||
font_api
|
||||
signs_api
|
||||
intllib?
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
name=signs
|
||||
description=Basic signs and posters with text display using signs_api
|
||||
depends=default,dye,signs_api
|
||||
optional_depends=intllib
|
|
@ -33,9 +33,8 @@ local function display_poster(pos, node, player)
|
|||
node.name, minetest.pos_to_string(pos))
|
||||
|
||||
-- Title texture
|
||||
local titletexture = font:make_text_texture(
|
||||
meta:get_string("display_text"), font:get_height()*8.4,
|
||||
font:get_height(), 1, "center")
|
||||
local titletexture = font:render(meta:get_string("display_text"),
|
||||
font:get_height()*8.4, font:get_height(), { lines = 1 })
|
||||
|
||||
fs = string.format([=[
|
||||
size[7,9]bgcolor[#0000]
|
||||
|
|
|
@ -27,3 +27,7 @@ Handles screwdriver rotation. Direction is affected for direction signs.
|
|||
|
||||
### `signs_api.register_sign(mod, name, model)`
|
||||
A method to quickly register signs.
|
||||
|
||||
## Changelog
|
||||
### 2019-03-14
|
||||
- __sign_api__: Screwdriver behavior changed. Now, left click rotates and changes direction.
|
||||
|
|
|
@ -91,37 +91,42 @@ 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,
|
||||
y = pointed_thing.under.y - pointed_thing.above.y,
|
||||
z = pointed_thing.under.z - pointed_thing.above.z}
|
||||
|
||||
local bdir = {x = pointed_thing.under.x - pointed_thing.above.x,
|
||||
y = pointed_thing.under.y - pointed_thing.above.y,
|
||||
z = pointed_thing.under.z - pointed_thing.above.z}
|
||||
local pdir = placer:get_look_dir()
|
||||
|
||||
local ndir, test
|
||||
|
||||
if ndef.paramtype2 == "facedir" then
|
||||
if bdir.x == 0 and bdir.z == 0 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
|
||||
ndir = minetest.dir_to_facedir(bdir)
|
||||
-- Wall pointed or no rotation restriction
|
||||
ndir = minetest.dir_to_facedir(bdir, not restriction)
|
||||
end
|
||||
|
||||
test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z}
|
||||
end
|
||||
test = { [0]=-pdir.x, pdir.z, pdir.x, -pdir.z, -pdir.x, [8]=pdir.x }
|
||||
end
|
||||
|
||||
if ndef.paramtype2 == "wallmounted" then
|
||||
ndir = minetest.dir_to_wallmounted(bdir)
|
||||
if ndir == 0 or ndir == 1 then
|
||||
-- Ceiling or floor
|
||||
-- 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.z, -pdir.z, -pdir.x, pdir.x}
|
||||
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
|
||||
itemstack:set_name(ndef.signs_other_dir)
|
||||
|
@ -135,20 +140,48 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
|
|||
end
|
||||
end
|
||||
|
||||
-- Handles screwdriver rotation. Direction is affected for direction signs
|
||||
-- If rotation mode is 2 and sign is directional, swap direction.
|
||||
-- Otherwise use display_api's on_rotate function.
|
||||
function signs_api.on_rotate(pos, node, player, mode, new_param2)
|
||||
if mode == 2 then
|
||||
-- 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
|
||||
minetest.swap_node(pos, {name = ndef.signs_other_dir,
|
||||
param1 = node.param1, param2 = node.param2})
|
||||
-- Switch direction
|
||||
node = {name = ndef.signs_other_dir,
|
||||
param1 = node.param1, param2 = node.param2}
|
||||
minetest.swap_node(pos, node)
|
||||
display_api.update_entities(pos)
|
||||
return true
|
||||
-- Rotate only if not "main" sign
|
||||
-- TODO:Improve detection of "main" direction sign
|
||||
if ndef.groups and ndef.groups.not_in_creative_inventory then
|
||||
return display_api.on_rotate(pos, node, player, mode, new_param2)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return display_api.on_rotate(pos, node, user, 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)
|
||||
|
@ -163,7 +196,7 @@ function signs_api.register_sign(mod, name, model)
|
|||
fixed = {-model.width/2, -model.height/2, 0.5,
|
||||
model.width/2, model.height/2, 0.5 - model.depth},
|
||||
},
|
||||
groups = {choppy=2, dig_immediate=2, not_blocking_trains = 1, display_modpack_node = 1},
|
||||
groups = {choppy=2, dig_immediate=2, not_blocking_trains=1, display_api=1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
display_entities = {
|
||||
["signs:display_text"] = {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
name=signs_api
|
||||
description=A library providing various helper functions for registereing signs with text display
|
||||
depends=default,display_api,font_api
|
||||
optional_depends=intllib
|
|
@ -2,6 +2,4 @@ default
|
|||
intllib?
|
||||
bakedclay
|
||||
dye
|
||||
display_api
|
||||
font_api
|
||||
signs_api
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
name=signs_road
|
||||
description=Various road signs with text display using signs_api
|
||||
depends=default,dye,signs_api
|
||||
optional_depends=intllib
|
|
@ -0,0 +1,4 @@
|
|||
name=steles
|
||||
description=Stone steles with text display on them
|
||||
depends=default,display_api,font_api
|
||||
optional_depends=intllib,technic
|
|
@ -30,7 +30,7 @@ for i, material in ipairs(steles.materials) do
|
|||
if ndef then
|
||||
local groups = table.copy(ndef.groups)
|
||||
local parts = material:split(":")
|
||||
groups.display_modpack_node = 1
|
||||
groups.display_api = 1
|
||||
|
||||
minetest.register_node("steles:"..parts[2].."_stele", {
|
||||
description = steles.materials_desc[i],
|
||||
|
|
Loading…
Reference in New Issue