Añadido soporte para diferentes tipos de signs.

-- Yawin
master
Yawin 2017-01-18 00:41:56 +01:00
parent 4b2d1b19cb
commit a16ad19ed1
236 changed files with 3061 additions and 13 deletions

View File

@ -0,0 +1,3 @@
[Dolphin]
Timestamp=2017,1,18,0,41,1
Version=3

View File

@ -0,0 +1,10 @@
# Display Modpack
This modpack provides mods with dynamic display. Mods are :
- **display_lib**: A library for adding display entities to nodes;
- **font_lib**: A library for displaying fonts on entities;
- **ontime_clocks**: A mod providing clocks which display the ingame time;
- **signs**: A mod providing signs and direction signs displaying text;
- **signs_road**: A mod providing road signs displaying text;
- **steles**: A mod providing stone steles with text;

View File

@ -0,0 +1,83 @@
# 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).
## Provided methods
### update\_entities
**display\_lib.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)**
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)**
**On_place** node callback implementation. Display nodes should have this callback (avoid placement of horizontal display node).
### on_construct
**display\_lib.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)**
**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)**
**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)**
**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\_lib** callbacks.
- 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
**depth**, **right** and **height** : Entity position regarding to node facedir/wallmounted main axis. Values for these fields can be any number between -0.5 and 0.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 **height** 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.
### Example
display_lib.register_display_entity("mymod:entity1")
display_lib.register_display_entity("mymod:entity2")
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)
objref:set_properties({ textures= {"mytexture2.png"},
visual_size = {x=1, y=1} })
end
minetest.register_node("mymod:test_display_node", {
...
paramtype2 = "wallmounted",
...
display_entities = {
["mymod:entity1"] = { depth = 0.3,
on_display_update = my_display_update1},
["mymod:entity1"] = { depth = 0.2, height = 0.1,
on_display_update = my_display_update2},
},
...
on_place = display_lib.on_place,
on_construct = display_lib.on_construct,
on_destruct = display_lib.on_destruct,
on_rotate = display_lib.on_rotate,
...
})

View File

@ -0,0 +1,166 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -0,0 +1,11 @@
# Dislpay Lib
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.
**Dependancies**:default
**License**: LPGL
**API**: See API.md document please.

View File

@ -0,0 +1,225 @@
--[[
display_lib 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/>.
--]]
display_lib = {}
-- Miscelaneous values depending on wallmounted param2
local wallmounted_values = {
[0]={dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, -- Should never be used
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=1}, -- Should never be used
{dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=5},
{dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=4},
{dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=2},
{dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3}
}
-- Miscelaneous values depending on facedir param2
local facedir_values = {
[0]={dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=1},
{dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2},
{dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3},
{dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=0},
-- Forbiden values :
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
}
-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity,
-- rotate = next facedir/wallmount on rotate
local function get_values(node)
local ndef = minetest.registered_nodes[node.name]
if ndef then
if ndef.paramtype2 == "wallmounted" then
return wallmounted_values[node.param2]
end
if ndef.paramtype2 == "facedir" then
return facedir_values[node.param2]
end
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, 0.5)) do
local entity = objref:get_luaentity()
if entity and ndef.display_entities[entity.name] 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(-0.5, math.min(0.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 height = clip_pos_prop(props.height)
local right = clip_pos_prop(props.right)
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 + height,
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_lib.update_entities(pos)
local objrefs = place_entities(pos)
for _, objref in pairs(objrefs) do
call_node_on_display_update(pos, objref)
end
end
--- On_activate callback for display_lib entities. Calls on_display_update callbacks
--- of corresponding node for each entity.
function display_lib.on_activate(entity, staticdata)
if entity then
call_node_on_display_update(entity.object:getpos(), entity.object)
end
end
--- On_place callback for display_lib items. Does nothing more than preventing item
--- from being placed on ceiling or ground
function display_lib.on_place(itemstack, placer, pointed_thing)
local ndef = minetest.registered_nodes[itemstack.name]
local above = pointed_thing.above
local under = pointed_thing.under
local dir = {x = under.x - above.x,
y = under.y - above.y,
z = under.z - above.z}
if ndef and ndef.paramtype2 == "wallmounted" then
local wdir = minetest.dir_to_wallmounted(dir)
if wdir == 0 or wdir == 1 then
dir = placer:get_look_dir()
dir.y = 0
wdir = minetest.dir_to_wallmounted(dir)
end
return minetest.item_place(itemstack, placer, pointed_thing, wdir)
else
return minetest.item_place(itemstack, placer, pointed_thing)
end
end
--- On_construct callback for display_lib items. Creates entities and update them.
function display_lib.on_construct(pos)
display_lib.update_entities(pos)
end
--- On_destruct callback for display_lib items. Removes entities.
function display_lib.on_destruct(pos)
local objrefs = get_entities(pos)
for _, objref in pairs(objrefs) do
objref:remove()
end
end
-- On_rotate (screwdriver) callback for display_lib items. Prevents axis rotation and reorients entities.
function display_lib.on_rotate(pos, node, user, mode, new_param2)
if mode ~= screwdriver.ROTATE_FACE then return false end
local values = get_values(node)
if values then
minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = values.rotate})
place_entities(pos)
return true
else
return false
end
end
--- Creates display entity with some fields and the on_activate callback
function display_lib.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_lib.on_activate,
})
end
end

View File

@ -0,0 +1,47 @@
# Font Lib API
This document describes Font Lib API. Font Lib creates textures for font display on entities.
## Provided methods
### get\_line\_width
**font\_lib.get\_line\_width(text)**
Computes line width for a given font height and text
**text**: Text to be rendered
**Returns**: rendered text width
### make\_line\_texture
**font\_lib.make\_line\_texture(text, texturew, x, y)**
Builds texture part for a text line
**text**: Text to be rendered
**texturew**: Width of the texture (extra text is not rendered)
**x**: Starting x position in texture
**y**: Vertical position of the line in texture
**Returns**: Texture string
### make\_multiline\_texture
**font\_lib.make\_multiline\_texture(text, texturew, textureh, maxlines, valign, color)**
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
**valign**: Vertical text align ("top" or "center")
**color**: Color of the text
**Returns**: Texture string

View File

@ -0,0 +1,166 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -0,0 +1,14 @@
# Font Lib
This library for font display on entities (to be used with display_lib for sign creation).
**Dependancies**: default
**License**: LGPL
(Font taken from VanessaE's homedecor/signs_lib, originally under WTFPL)
**API**: See API.md document please.

View File

@ -0,0 +1,2 @@
Code by Pierre-Yves Rollo
Textures by Vanessa Ezekowitz

View File

@ -0,0 +1,174 @@
--[[
font_lib mod for Minetest - Library to add font display capability
to display_lib mod.
(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/>.
--]]
-- Global variables
font_lib = {}
font_lib.path = minetest.get_modpath("font_lib")
font_lib.font_height = 12
font_lib.font = {}
-- Local functions
local function get_next_char(text, pos)
pos = pos + 1
local char = text:sub(pos, pos):byte()
if char >= 0x80 then
if char == 0xc2 or char == 0xc3 then
pos = pos + 1
char = (char - 0xc2) * 0x40 + text:sub(pos, pos):byte()
else
char = 0
end
end
if font_lib.font[char] == nil then char=0 end
return char, pos
end
local function split_lines(text, maxlines)
local splits = text:split("\n")
if maxlines then
local lines = {}
for num = 1,maxlines do
lines[num] = splits[num]
end
return lines
else
return splits
end
end
-- Computes line width for a given font height and text
-- @param text Text to be rendered
-- @return Rendered text width
function font_lib.get_line_width(text)
local char
local width = 0
p=0
while p < #text do
char, p = get_next_char(text, p)
width = width + font_lib.font[char].width
end
return width
end
--- Builds texture part for a text line
-- @param text Text 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_lib.make_line_texture(text, texturew, x, y)
local char
local texture = ""
p=0
while p < #text do
char, p = get_next_char(text, p)
-- Add image only if it is visible (at least partly)
if x + font_lib.font[char].width >= 0 and x <= texturew then
texture = texture..string.format(":%d,%d=%s", x, y, font_lib.font[char].filename)
end
x = x + font_lib.font[char].width
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 valign Vertical text align ("top" or "center")
-- @param color Color of the text
-- @return Texture string
function font_lib.make_multiline_texture(text, texturew, textureh, maxlines, valign, color)
local texture = ""
local lines = split_lines(text, maxlines)
local y
if valign == "top" then
y = font_lib.font_height / 2 - 1
else
y = (textureh - font_lib.font_height * #lines) / 2
end
for _, line in pairs(lines) do
texture = texture..font_lib.make_line_texture(line, texturew,
(texturew - font_lib.get_line_width(line)) / 2, y)
y = y + font_lib.font_height
end
texture = string.format("[combine:%dx%d", texturew, textureh)..texture
if color then texture = texture.."^[colorize:"..color end
return texture
end
--- Standard on_display_update entity callback.
-- Node should have a corresponding display_entity with size, resolution and maxlines fields and
-- optionally valign and color fields
-- @param pos Node position
-- @param objref Object reference of entity
function font_lib.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]
objref:set_properties({
textures={font_lib.make_multiline_texture(
text, def.size.x*def.resolution.x, def.size.y*def.resolution.y,
def.maxlines, def.valign, def.color)},
visual_size = def.size
})
end
end
-- Populate fonts table
local filename
for char = 0,255 do
filename = string.format("font_lib_%02x.png", char)
local file=io.open(font_lib.path.."/textures/"..filename,"rb")
if file~=nil then
-- Get png width, suposing png width is less than 256 (it is the case for all font textures)
-- All font png are smaller than 256x256 --> read only last byte
file:seek("set",19)
local w = file:read(1)
file:close()
font_lib.font[char] = {filename=filename, width=w:byte()}
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Some files were not shown because too many files have changed in this diff Show More