diff options
Diffstat (limited to 'digilines_lcd')
| -rw-r--r-- | digilines_lcd/characters | 3 | ||||
| -rw-r--r-- | digilines_lcd/init.lua | 60 | ||||
| -rw-r--r-- | digilines_lcd/textures/_co.png | bin | 0 -> 135 bytes | 
3 files changed, 24 insertions, 39 deletions
| diff --git a/digilines_lcd/characters b/digilines_lcd/characters index 83d6505..b36eea4 100644 --- a/digilines_lcd/characters +++ b/digilines_lcd/characters @@ -250,6 +250,9 @@ _eq  ;  _sm  1 +: +_co +1  ,  _cm  2 diff --git a/digilines_lcd/init.lua b/digilines_lcd/init.lua index 4fe3151..ed3fbd7 100644 --- a/digilines_lcd/init.lua +++ b/digilines_lcd/init.lua @@ -33,11 +33,11 @@ local lcds = {  }  local reset_meta = function(pos) -	minetest.env:get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]") +	minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]")  end  local clearscreen = function(pos) -	local objects = minetest.env:get_objects_inside_radius(pos, 0.5) +	local objects = minetest.get_objects_inside_radius(pos, 0.5)  	for _, o in ipairs(objects) do  		if o:get_entity_name() == "digilines_lcd:text" then  			o:remove() @@ -45,30 +45,33 @@ local clearscreen = function(pos)  	end  end -local prepare_writing = function (pos) -	lcd_info = lcds[minetest.env:get_node(pos).param2] +local prepare_writing = function(pos) +	lcd_info = lcds[minetest.get_node(pos).param2]  	if lcd_info == nil then return end -	local text = minetest.env:add_entity( +	local text = minetest.add_entity(  		{x = pos.x + lcd_info.delta.x,  		 y = pos.y + lcd_info.delta.y,  		 z = pos.z + lcd_info.delta.z}, "digilines_lcd:text") -	text:setyaw  (lcd_info.yaw or 0) +	text:setyaw(lcd_info.yaw or 0)  	--* text:setpitch(lcd_info.yaw or 0)  	return text  end  local on_digiline_receive = function(pos, node, channel, msg) -	local setchan = minetest.env:get_meta(pos):get_string("channel") +	local meta = minetest.get_meta(pos) +	local setchan = meta:get_string("channel")  	if setchan ~= channel then return end +	meta:set_string("text", msg)  	clearscreen(pos) -	local text = prepare_writing (pos) -	text:set_properties({textures={generate_texture(create_lines(msg))}}) +	if msg ~= "" then +		prepare_writing(pos) +	end  end  local lcd_box = {  	type = "wallmounted", -	wall_top    = {-8/16,  7/16, -8/16,  8/16,  8/16, 8/16} +	wall_top = {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}  }  minetest.register_node("digilines_lcd:lcd", { @@ -83,12 +86,12 @@ minetest.register_node("digilines_lcd:lcd", {  	paramtype2 = "wallmounted",  	node_box = lcd_box,  	selection_box = lcd_box, -	groups =  {choppy = 3, dig_immediate = 2}, +	groups = {choppy = 3, dig_immediate = 2},  	after_place_node = function (pos, placer, itemstack) -		local param2 = minetest.env:get_node(pos).param2 +		local param2 = minetest.get_node(pos).param2  		if param2 == 0 or param2 == 1 then -			minetest.env:add_node(pos, {name = "digilines_lcd:lcd", param2 = 3}) +			minetest.add_node(pos, {name = "digilines_lcd:lcd", param2 = 3})  		end  		prepare_writing (pos)  	end, @@ -102,7 +105,9 @@ minetest.register_node("digilines_lcd:lcd", {  	end,  	on_receive_fields = function(pos, formname, fields, sender) -		minetest.env:get_meta(pos):set_string("channel", fields.channel) +		if (fields.channel) then +			minetest.get_meta(pos):set_string("channel", fields.channel) +		end  	end,  	digiline =  @@ -122,7 +127,7 @@ minetest.register_entity("digilines_lcd:text", {  	textures = {},  	on_activate = function(self) -		local meta = minetest.env:get_meta(self.object:getpos()) +		local meta = minetest.get_meta(self.object:getpos())  		local text = meta:get_string("text")  		self.object:set_properties({textures={generate_texture(create_lines(text))}})  	end @@ -138,34 +143,11 @@ local NUMBER_OF_LINES = 5  local LINE_HEIGHT = 14  local CHAR_WIDTH = 5 -string_to_array = function(str) -	local tab = {} -	for i=1,string.len(str) do -		table.insert(tab, string.sub(str, i,i)) -	end -	return tab -end - -string_to_word_array = function(str) -	local tab = {} -	local current = 1 -	tab[1] = "" -	for _,char in ipairs(string_to_array(str)) do -		if char ~= " " then -			tab[current] = tab[current]..char -		else -			current = current+1 -			tab[current] = "" -		end -	end -	return tab -end -  create_lines = function(text)  	local line = ""  	local line_num = 1  	local tab = {} -	for _,word in ipairs(string_to_word_array(text)) do +	for word in string.gmatch(text, "%S+") do  		if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then  			if line ~= "" then  				line = line.." "..word diff --git a/digilines_lcd/textures/_co.png b/digilines_lcd/textures/_co.pngBinary files differ new file mode 100644 index 0000000..b161819 --- /dev/null +++ b/digilines_lcd/textures/_co.png | 
