aboutsummaryrefslogtreecommitdiff
path: root/assets/blender/mbb/modern_wagong_uv.blend1
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-02-02 23:07:09 +0100
committerorwell96 <mono96.mml@gmail.com>2017-02-02 23:07:09 +0100
commit4882abb1c08cdade0a56763cbc88e675a4600f2c (patch)
tree2789c986abc1d362f6d30ce45fca92ba5f1e33f6 /assets/blender/mbb/modern_wagong_uv.blend1
parentbcf82ed70d62aeb42b0f6d70aa5ef54ac2b046af (diff)
parent54b78023d7b1f15525658e61aa1dfba0040b99f8 (diff)
downloadadvtrains-4882abb1c08cdade0a56763cbc88e675a4600f2c.tar.gz
advtrains-4882abb1c08cdade0a56763cbc88e675a4600f2c.tar.bz2
advtrains-4882abb1c08cdade0a56763cbc88e675a4600f2c.zip
Merge PR from mbb: add better textures and crafts
Diffstat (limited to 'assets/blender/mbb/modern_wagong_uv.blend1')
0 files changed, 0 insertions, 0 deletions
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
local font = {}
signs.font_height = 10

-- 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
function signs.get_line_width(text)
	local char
	local width = 0

	for p=1,#text
	do
		char = text:sub(p,p):byte()
		if font[char] then
			width = width + font[char].width
		end
	end

	return width
end

--- Builds texture part for a text line
-- @param text Text to be rendered
-- @param x Starting x position in texture
-- @param width Width of the texture (extra text is not rendered)
-- @param y Vertical position of the line in texture
-- @return Texture string
function signs.make_line_texture(text, x, width, y)
	local char

	local texture = ""

	for p=1,#text
	do
		char = text:sub(p,p):byte()
		if font[char] then
			-- Add image only if it is visible (at least partly)
			if x + font[char].width >= 0 and x <= width then
				texture = texture..string.format(":%d,%d=%s", x, y, font[char].filename)
			end
			x = x + 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

function signs.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]
	if ndef and ndef.sign_model then
		local model = signs.sign_models[ndef.sign_model]
		local lines = split_lines(text, model.maxlines)

		local texturew = model.width/model.xscale
		local textureh = model.height/model.yscale

		local texture = ""

		local y
		if model.valing == "top" then
			y = signs.font_height / 2
		else		
			y = (textureh - signs.font_height * #lines) / 2 + 1 
		end

		for _, line in pairs(lines) do
			texture = texture..signs.make_line_texture(line, 
				(texturew - signs.get_line_width(line)) / 2, 
				texturew, y)
			y = y + signs.font_height
		end

		local texture = string.format("[combine:%dx%d", texturew, textureh)..texture
		if model.color then texture = texture.."^[colorize:"..model.color end

		objref:set_properties({ textures={texture}, visual_size = {x=model.width, y=model.height}})
	end
end

function signs.set_formspec(pos)
	local meta = minetest.get_meta(pos)
	local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
	if ndef and ndef.sign_model then
		local model = signs.sign_models[ndef.sign_model]
		local formspec

		if model.maxlines == 1 then
			formspec = "size[6,3]"..
				"field[0.5,0.7;5.5,1;display_text;Displayed text;${display_text}]"..
				"button_exit[2,2;2,1;ok;Write]"
		else
			local extralabel = ""
			if model.maxlines then
				extralabel = " (first "..model.maxlines.." lines only)"
			end

			formspec = "size[6,4]"..