2013-03-25 11:58:34 +01:00
|
|
|
--* parts are currently not possible because you cannot set the pitch of an entity from lua
|
|
|
|
|
|
|
|
-- Font: 04.jp.org
|
|
|
|
|
|
|
|
-- load characters map
|
2016-05-28 01:08:53 +02:00
|
|
|
local chars_file = io.open(minetest.get_modpath("digilines").."/characters", "r")
|
2013-03-25 11:58:34 +01:00
|
|
|
local charmap = {}
|
|
|
|
local max_chars = 12
|
|
|
|
if not chars_file then
|
2016-05-28 01:08:53 +02:00
|
|
|
print("[digilines] E: LCD: character map file not found")
|
2013-03-25 11:58:34 +01:00
|
|
|
else
|
|
|
|
while true do
|
|
|
|
local char = chars_file:read("*l")
|
|
|
|
if char == nil then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
local img = chars_file:read("*l")
|
|
|
|
chars_file:read("*l")
|
|
|
|
charmap[char] = img
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-01 05:05:53 +01:00
|
|
|
-- CONSTANTS
|
|
|
|
local LCD_WITH = 100
|
|
|
|
local LCD_PADDING = 8
|
|
|
|
|
|
|
|
local LINE_LENGTH = 12
|
|
|
|
local NUMBER_OF_LINES = 5
|
|
|
|
|
|
|
|
local LINE_HEIGHT = 14
|
|
|
|
local CHAR_WIDTH = 5
|
|
|
|
|
|
|
|
local create_lines = function(text)
|
|
|
|
local line = ""
|
|
|
|
local line_num = 1
|
|
|
|
local tab = {}
|
|
|
|
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
|
|
|
|
else
|
|
|
|
line = word
|
|
|
|
end
|
|
|
|
else
|
|
|
|
table.insert(tab, line)
|
|
|
|
if word ~= "|" then
|
|
|
|
line = word
|
|
|
|
else
|
|
|
|
line = ""
|
|
|
|
end
|
|
|
|
line_num = line_num+1
|
|
|
|
if line_num > NUMBER_OF_LINES then
|
|
|
|
return tab
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(tab, line)
|
|
|
|
return tab
|
|
|
|
end
|
|
|
|
|
|
|
|
local generate_line = function(s, ypos)
|
|
|
|
local i = 1
|
|
|
|
local parsed = {}
|
|
|
|
local width = 0
|
|
|
|
local chars = 0
|
|
|
|
while chars < max_chars and i <= #s do
|
|
|
|
local file = nil
|
|
|
|
if charmap[s:sub(i, i)] ~= nil then
|
|
|
|
file = charmap[s:sub(i, i)]
|
|
|
|
i = i + 1
|
|
|
|
elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then
|
|
|
|
file = charmap[s:sub(i, i + 1)]
|
|
|
|
i = i + 2
|
|
|
|
else
|
|
|
|
print("[digilines] W: LCD: unknown symbol in '"..s.."' at "..i)
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
if file ~= nil then
|
|
|
|
width = width + CHAR_WIDTH
|
|
|
|
table.insert(parsed, file)
|
|
|
|
chars = chars + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
width = width - 1
|
|
|
|
|
|
|
|
local texture = ""
|
|
|
|
local xpos = math.floor((LCD_WITH - 2 * LCD_PADDING - width) / 2 + LCD_PADDING)
|
|
|
|
for ii = 1, #parsed do
|
|
|
|
texture = texture..":"..xpos..","..ypos.."="..parsed[ii]..".png"
|
|
|
|
xpos = xpos + CHAR_WIDTH + 1
|
|
|
|
end
|
|
|
|
return texture
|
|
|
|
end
|
|
|
|
|
|
|
|
local generate_texture = function(lines)
|
|
|
|
local texture = "[combine:"..LCD_WITH.."x"..LCD_WITH
|
|
|
|
local ypos = 16
|
|
|
|
for i = 1, #lines do
|
|
|
|
texture = texture..generate_line(lines[i], ypos)
|
|
|
|
ypos = ypos + LINE_HEIGHT
|
|
|
|
end
|
|
|
|
return texture
|
|
|
|
end
|
|
|
|
|
2013-03-25 11:58:34 +01:00
|
|
|
local lcds = {
|
|
|
|
-- on ceiling
|
|
|
|
--* [0] = {delta = {x = 0, y = 0.4, z = 0}, pitch = math.pi / -2},
|
|
|
|
-- on ground
|
|
|
|
--* [1] = {delta = {x = 0, y =-0.4, z = 0}, pitch = math.pi / 2},
|
|
|
|
-- sides
|
|
|
|
[2] = {delta = {x = 0.4, y = 0, z = 0}, yaw = math.pi / -2},
|
|
|
|
[3] = {delta = {x = -0.4, y = 0, z = 0}, yaw = math.pi / 2},
|
|
|
|
[4] = {delta = {x = 0, y = 0, z = 0.4}, yaw = 0},
|
|
|
|
[5] = {delta = {x = 0, y = 0, z = -0.4}, yaw = math.pi},
|
|
|
|
}
|
|
|
|
|
|
|
|
local reset_meta = function(pos)
|
2014-02-13 21:45:31 +01:00
|
|
|
minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]")
|
2013-03-25 11:58:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local clearscreen = function(pos)
|
2014-02-13 21:45:31 +01:00
|
|
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
2013-03-25 11:58:34 +01:00
|
|
|
for _, o in ipairs(objects) do
|
2015-08-20 18:28:51 +02:00
|
|
|
local o_entity = o:get_luaentity()
|
|
|
|
if o_entity and o_entity.name == "digilines_lcd:text" then
|
2013-03-25 11:58:34 +01:00
|
|
|
o:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-26 14:17:01 +01:00
|
|
|
local prepare_writing = function(pos)
|
2015-08-20 18:28:51 +02:00
|
|
|
local lcd_info = lcds[minetest.get_node(pos).param2]
|
2013-03-25 11:58:34 +01:00
|
|
|
if lcd_info == nil then return end
|
2014-02-13 21:45:31 +01:00
|
|
|
local text = minetest.add_entity(
|
2013-03-25 11:58:34 +01:00
|
|
|
{x = pos.x + lcd_info.delta.x,
|
|
|
|
y = pos.y + lcd_info.delta.y,
|
|
|
|
z = pos.z + lcd_info.delta.z}, "digilines_lcd:text")
|
2014-02-26 15:58:24 +01:00
|
|
|
text:setyaw(lcd_info.yaw or 0)
|
2013-03-25 11:58:34 +01:00
|
|
|
--* text:setpitch(lcd_info.yaw or 0)
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
2017-03-01 11:31:48 +01:00
|
|
|
local on_digiline_receive = function(pos, _, channel, msg)
|
2014-02-26 14:17:01 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-02-26 15:58:24 +01:00
|
|
|
local setchan = meta:get_string("channel")
|
2013-03-25 11:58:34 +01:00
|
|
|
if setchan ~= channel then return end
|
|
|
|
|
2014-02-26 15:58:24 +01:00
|
|
|
meta:set_string("text", msg)
|
2015-02-14 19:21:44 +01:00
|
|
|
meta:set_string("infotext", msg)
|
2013-04-03 19:42:59 +02:00
|
|
|
clearscreen(pos)
|
2014-02-26 15:58:24 +01:00
|
|
|
if msg ~= "" then
|
|
|
|
prepare_writing(pos)
|
|
|
|
end
|
2013-03-25 11:58:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local lcd_box = {
|
|
|
|
type = "wallmounted",
|
2014-02-26 15:58:24 +01:00
|
|
|
wall_top = {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}
|
2013-03-25 11:58:34 +01:00
|
|
|
}
|
|
|
|
|
2016-05-28 01:08:53 +02:00
|
|
|
minetest.register_alias("digilines_lcd:lcd", "digilines:lcd")
|
|
|
|
minetest.register_node("digilines:lcd", {
|
2013-03-25 11:58:34 +01:00
|
|
|
drawtype = "nodebox",
|
|
|
|
description = "Digiline LCD",
|
|
|
|
inventory_image = "lcd_lcd.png",
|
|
|
|
wield_image = "lcd_lcd.png",
|
|
|
|
tiles = {"lcd_anyside.png"},
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "wallmounted",
|
|
|
|
node_box = lcd_box,
|
|
|
|
selection_box = lcd_box,
|
2014-02-26 15:58:24 +01:00
|
|
|
groups = {choppy = 3, dig_immediate = 2},
|
2013-03-25 11:58:34 +01:00
|
|
|
|
2017-03-01 11:31:48 +01:00
|
|
|
after_place_node = function (pos)
|
2014-02-13 21:45:31 +01:00
|
|
|
local param2 = minetest.get_node(pos).param2
|
2013-03-25 11:58:34 +01:00
|
|
|
if param2 == 0 or param2 == 1 then
|
2016-05-28 01:08:53 +02:00
|
|
|
minetest.add_node(pos, {name = "digilines:lcd", param2 = 3})
|
2013-03-25 11:58:34 +01:00
|
|
|
end
|
|
|
|
prepare_writing (pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
reset_meta(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_destruct = function(pos)
|
|
|
|
clearscreen(pos)
|
|
|
|
end,
|
|
|
|
|
2017-03-01 11:31:48 +01:00
|
|
|
on_receive_fields = function(pos, _, fields, sender)
|
2016-05-23 20:13:24 +02:00
|
|
|
local name = sender:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
minetest.record_protection_violation(pos, name)
|
|
|
|
return
|
|
|
|
end
|
2014-04-24 10:59:16 +02:00
|
|
|
if (fields.channel) then
|
|
|
|
minetest.get_meta(pos):set_string("channel", fields.channel)
|
|
|
|
end
|
2013-03-25 11:58:34 +01:00
|
|
|
end,
|
|
|
|
|
2017-03-01 05:05:53 +01:00
|
|
|
digiline =
|
2013-03-25 11:58:34 +01:00
|
|
|
{
|
|
|
|
receptor = {},
|
|
|
|
effector = {
|
|
|
|
action = on_digiline_receive
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
light_source = 6,
|
|
|
|
})
|
|
|
|
|
2016-05-28 01:08:53 +02:00
|
|
|
minetest.register_entity(":digilines_lcd:text", {
|
2013-03-25 11:58:34 +01:00
|
|
|
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
|
|
|
visual = "upright_sprite",
|
|
|
|
textures = {},
|
|
|
|
|
|
|
|
on_activate = function(self)
|
2014-02-13 21:45:31 +01:00
|
|
|
local meta = minetest.get_meta(self.object:getpos())
|
2013-03-25 11:58:34 +01:00
|
|
|
local text = meta:get_string("text")
|
|
|
|
self.object:set_properties({textures={generate_texture(create_lines(text))}})
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2013-05-10 22:56:47 +02:00
|
|
|
minetest.register_craft({
|
2016-05-28 01:08:53 +02:00
|
|
|
output = "digilines:lcd 2",
|
2013-05-10 22:56:47 +02:00
|
|
|
recipe = {
|
|
|
|
{"default:steel_ingot", "digilines:wire_std_00000000", "default:steel_ingot"},
|
|
|
|
{"mesecons_lightstone:lightstone_green_off","mesecons_lightstone:lightstone_green_off","mesecons_lightstone:lightstone_green_off"},
|
|
|
|
{"default:glass","default:glass","default:glass"}
|
|
|
|
}
|
|
|
|
})
|