Added facedir node support to display_lib, created font_lib, updated mods accordingly
@@ -3,6 +3,8 @@
 | 
			
		||||
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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
# Display Lib API
 | 
			
		||||
This document describes Display Lib API. Display Lib allows to add a dynamic display on a node. Node must be wallmounted and Display Lib limits its rotation to vertical positions. 
 | 
			
		||||
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)**
 | 
			
		||||
@@ -38,7 +39,12 @@ This is a helper to register entities used for display.
 | 
			
		||||
* Register display entities with **register\_display\_entity**
 | 
			
		||||
* Register node with :
 | 
			
		||||
	- **on\_place**, **on\_construct**, **on\_destruct** and **on\_rotate** callbacks using **display\_lib** callbacks.
 | 
			
		||||
	- a **display\_entities** field in node definition containing a entity name indexed table. For each entity, two fields : **depth** indicates the entity position (-0.5 to 0.5) and **on_display_update** is a callback in charge of setting up entity texture.
 | 
			
		||||
	- 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
 | 
			
		||||
 | 
			
		||||
@@ -60,9 +66,9 @@ This is a helper to register entities used for display.
 | 
			
		||||
			paramtype2 = "wallmounted",
 | 
			
		||||
			...
 | 
			
		||||
			display_entities = {
 | 
			
		||||
				["mymod:entity1"] = { depth = -0.3, 
 | 
			
		||||
				["mymod:entity1"] = { depth = 0.3,
 | 
			
		||||
					on_display_update = my_display_update1},
 | 
			
		||||
				["mymod:entity1"] = { depth = -0.2, 
 | 
			
		||||
				["mymod:entity1"] = { depth = 0.2, height = 0.1,
 | 
			
		||||
					on_display_update = my_display_update2},
 | 
			
		||||
			},
 | 
			
		||||
			...
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
# Dislpay Lib
 | 
			
		||||
 | 
			
		||||
This library's purpose is to ease creation of wallmounted nodes with a display on front side. For example, signs and clocks. Display can be dynamic and/or different for each node instance.
 | 
			
		||||
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 are only wallmounted vertically.
 | 
			
		||||
**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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,14 +6,59 @@ display_lib = {}
 | 
			
		||||
 | 
			
		||||
-- Miscelaneous values depending on wallmounted param2
 | 
			
		||||
local wallmounted_values = {
 | 
			
		||||
	[0]={dx=0,  dz=0,  lx=0, lz=0,  yaw=0,          rotate=0}, -- Should never be used
 | 
			
		||||
		{dx=1,  dz=0,  lx=0, lz=0,  yaw=0,          rotate=1}, -- Should never be used 
 | 
			
		||||
		{dx=1,  dz=0,  lx=0, lz=-1, yaw=-math.pi/2, rotate=4},
 | 
			
		||||
		{dx=-1, dz=0,  lx=0, lz=1,  yaw=math.pi/2,  rotate=5},
 | 
			
		||||
		{dx=0,  dz=1,  lx=1, lz=0,  yaw=0,          rotate=3},
 | 
			
		||||
		{dx=0,  dz=-1, lx=-1, lz=0, yaw=math.pi,    rotate=2}
 | 
			
		||||
	[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 = {}
 | 
			
		||||
@@ -45,23 +90,24 @@ end
 | 
			
		||||
local function place_entities(pos)
 | 
			
		||||
	local node = minetest.get_node(pos)
 | 
			
		||||
	local ndef = minetest.registered_nodes[node.name]
 | 
			
		||||
	local values = wallmounted_values[node.param2]
 | 
			
		||||
	local values = get_values(node)
 | 
			
		||||
	local objrefs = get_entities(pos)
 | 
			
		||||
 | 
			
		||||
	if ndef and ndef.display_entities then
 | 
			
		||||
	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 top = clip_pos_prop(props.top)
 | 
			
		||||
			local left = clip_pos_prop(props.left)
 | 
			
		||||
			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.lx * left,
 | 
			
		||||
				y = pos.y + top,
 | 
			
		||||
				z = pos.z - values.dz * depth + values.lz * left})
 | 
			
		||||
				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
 | 
			
		||||
@@ -97,19 +143,26 @@ 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}
 | 
			
		||||
	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)
 | 
			
		||||
	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
 | 
			
		||||
	return minetest.item_place(itemstack, placer, pointed_thing, wdir) 
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
--- On_construct callback for display_lib items. Creates entities and update them.
 | 
			
		||||
@@ -126,13 +179,14 @@ function display_lib.on_destruct(pos)
 | 
			
		||||
	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
 | 
			
		||||
 | 
			
		||||
	if wallmounted_values[node.param2] then
 | 
			
		||||
		minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = wallmounted_values[node.param2].rotate})
 | 
			
		||||
	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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										47
									
								
								font_lib/API.md
									
									
									
									
									
										Normal 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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								font_lib/LICENSE.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,13 @@
 | 
			
		||||
          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 | 
			
		||||
                   Version 2, December 2004
 | 
			
		||||
 
 | 
			
		||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
 | 
			
		||||
 
 | 
			
		||||
Everyone is permitted to copy and distribute verbatim or modified
 | 
			
		||||
copies of this license document, and changing it is allowed as long
 | 
			
		||||
as the name is changed.
 | 
			
		||||
 
 | 
			
		||||
           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 | 
			
		||||
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 | 
			
		||||
 
 | 
			
		||||
 0. You just DO WHAT THE FUCK YOU WANT TO.
 | 
			
		||||
							
								
								
									
										14
									
								
								font_lib/README.md
									
									
									
									
									
										Normal 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**: WTFPL
 | 
			
		||||
 | 
			
		||||
(Font taken from VanessaE's homedecor/signs_lib)
 | 
			
		||||
 | 
			
		||||
**API**: See API.md document please.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								font_lib/depends.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1 @@
 | 
			
		||||
default
 | 
			
		||||
							
								
								
									
										139
									
								
								font_lib/init.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,139 @@
 | 
			
		||||
-- Font lib mod by P.Y. Rollo
 | 
			
		||||
--
 | 
			
		||||
-- License: WTFPL
 | 
			
		||||
 | 
			
		||||
font_lib = {}
 | 
			
		||||
font_lib.path = minetest.get_modpath("font_lib")
 | 
			
		||||
font_lib.font_height = 10
 | 
			
		||||
font_lib.font = {}
 | 
			
		||||
 | 
			
		||||
-- Get png width, suposing png width is less than 256 (it is the case for all font textures)
 | 
			
		||||
local function get_png_width(filename)
 | 
			
		||||
	local file=assert(io.open(filename,"rb"))
 | 
			
		||||
	-- All font png are smaller than 256x256 --> read only last byte
 | 
			
		||||
	file:seek("set",19)
 | 
			
		||||
	local w = file:read(1)
 | 
			
		||||
	file:close()
 | 
			
		||||
	return w:byte()
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
	for p=1,#text
 | 
			
		||||
	do
 | 
			
		||||
		char = text:sub(p,p):byte()
 | 
			
		||||
		if font_lib.font[char] then
 | 
			
		||||
			width = width + font_lib.font[char].width
 | 
			
		||||
		end
 | 
			
		||||
	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 = ""
 | 
			
		||||
 | 
			
		||||
	for p=1,#text
 | 
			
		||||
	do
 | 
			
		||||
		char = text:sub(p,p):byte()
 | 
			
		||||
		if font_lib.font[char] then
 | 
			
		||||
			-- 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
 | 
			
		||||
	end
 | 
			
		||||
	return texture
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
--- 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
 | 
			
		||||
	else		
 | 
			
		||||
		y = (textureh - font_lib.font_height * #lines) / 2 + 1 
 | 
			
		||||
	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 w, filename
 | 
			
		||||
for charnum=32,126 do
 | 
			
		||||
	filename = string.format("font_lib_%02x.png", charnum)
 | 
			
		||||
	w = get_png_width(font_lib.path.."/textures/"..filename)
 | 
			
		||||
	font_lib.font[charnum] = {filename=filename, width=w}
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 232 B  | 
| 
		 Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 235 B After Width: | Height: | Size: 235 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  | 
| 
		 Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B  | 
| 
		 Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_29.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B  | 
| 
		 Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 241 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_2c.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 238 B  | 
| 
		 Before Width: | Height: | Size: 237 B After Width: | Height: | Size: 237 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_2e.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 236 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_2f.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 239 B  | 
| 
		 Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 239 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 237 B After Width: | Height: | Size: 237 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B  | 
| 
		 Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B  | 
| 
		 Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 259 B After Width: | Height: | Size: 259 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  | 
| 
		 Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  | 
| 
		 Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B  | 
| 
		 Before Width: | Height: | Size: 249 B After Width: | Height: | Size: 249 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_4f.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B  | 
| 
		 Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 247 B  | 
| 
		 Before Width: | Height: | Size: 237 B After Width: | Height: | Size: 237 B  | 
| 
		 Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  | 
| 
		 Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 248 B After Width: | Height: | Size: 248 B  | 
| 
		 Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 234 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 234 B  | 
| 
		 Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_5f.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 233 B  | 
| 
		 Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 234 B  | 
| 
		 Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B  | 
| 
		 Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_64.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_67.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 239 B  | 
| 
		 Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  | 
| 
		 Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B  | 
| 
		 Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 239 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_6f.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_71.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 243 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_72.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B  | 
| 
		 Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 239 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
| 
		 Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B  | 
| 
		 Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B  | 
							
								
								
									
										
											BIN
										
									
								
								font_lib/textures/font_lib_79.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 241 B  | 
| 
		 Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B  |