2020-05-31 23:31:18 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2022-07-11 21:24:44 +03:00
|
|
|
Copyright (C) 2019-2022 Joachim Stolberg
|
2020-05-31 23:31:18 +03:00
|
|
|
|
2020-10-25 23:32:47 +03:00
|
|
|
AGPL v3
|
2020-05-31 23:31:18 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
ICTA Controller - Display
|
|
|
|
|
|
|
|
]]--
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
local S = techage.S
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display = {}
|
|
|
|
|
2022-01-04 21:43:30 +03:00
|
|
|
local NUM_ROWS = 5
|
2020-05-31 23:31:18 +03:00
|
|
|
local RADIUS = 6
|
|
|
|
local Param2ToFacedir = {[0] = 0, 0, 3, 1, 2, 0}
|
2022-01-04 21:43:30 +03:00
|
|
|
|
|
|
|
local function lcdlib_bugfix(text_tbl)
|
2020-05-31 23:31:18 +03:00
|
|
|
if text_tbl and next(text_tbl) then
|
|
|
|
local t = {}
|
|
|
|
for _,txt in ipairs(text_tbl) do
|
|
|
|
if txt == "" then
|
|
|
|
t[#t+1] = " "
|
|
|
|
else
|
|
|
|
t[#t+1] = txt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return table.concat(t, "\n")
|
|
|
|
end
|
|
|
|
return ""
|
|
|
|
end
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
function techage.display.display_update(pos, objref)
|
2020-05-31 23:31:18 +03:00
|
|
|
pos = vector.round(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
2022-01-04 21:43:30 +03:00
|
|
|
local text = lcdlib_bugfix(nvm.text)
|
2020-05-31 23:31:18 +03:00
|
|
|
local texture = lcdlib.make_multiline_texture(
|
|
|
|
"default", text,
|
2023-08-26 11:27:15 +03:00
|
|
|
70, 70, NUM_ROWS, "top", "#000", nil, true)
|
2020-05-31 23:31:18 +03:00
|
|
|
objref:set_properties({ textures = {texture},
|
2021-10-30 17:52:44 +03:00
|
|
|
visual_size = {x=0.94, y=0.94} })
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
function techage.display.display_updateXL(pos, objref)
|
2020-05-31 23:31:18 +03:00
|
|
|
pos = vector.round(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
2022-01-04 21:43:30 +03:00
|
|
|
local text = lcdlib_bugfix(nvm.text)
|
2020-05-31 23:31:18 +03:00
|
|
|
local texture = lcdlib.make_multiline_texture(
|
|
|
|
"default", text,
|
2023-08-26 11:27:15 +03:00
|
|
|
126, 70, NUM_ROWS, "top", "#000", nil, true)
|
2020-05-31 23:31:18 +03:00
|
|
|
objref:set_properties({ textures = {texture},
|
2021-10-30 17:52:44 +03:00
|
|
|
visual_size = {x=0.94*1.9, y=0.94} })
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
function techage.display.on_timer(pos)
|
2020-05-31 23:31:18 +03:00
|
|
|
local mem = techage.get_mem(pos)
|
|
|
|
mem.ticks = mem.ticks or 0
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
if mem.ticks > 0 then
|
2022-01-04 21:43:30 +03:00
|
|
|
local node = minetest.get_node(pos)
|
2020-05-31 23:31:18 +03:00
|
|
|
-- check if display is loaded and a player in front of the display
|
2021-02-07 16:37:07 +03:00
|
|
|
if node.name ~= "ignore" then
|
2020-05-31 23:31:18 +03:00
|
|
|
local dir = minetest.facedir_to_dir(Param2ToFacedir[node.param2 % 6])
|
2021-05-14 19:50:16 +03:00
|
|
|
dir.y = 0
|
2020-05-31 23:31:18 +03:00
|
|
|
local pos2 = vector.add(pos, vector.multiply(dir, RADIUS))
|
|
|
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos2, RADIUS)) do
|
|
|
|
if obj:is_player() then
|
|
|
|
lcdlib.update_entities(pos)
|
|
|
|
mem.ticks = mem.ticks - 1
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.lcd_box = {
|
2020-05-31 23:31:18 +03:00
|
|
|
type = "wallmounted",
|
|
|
|
wall_top = {-8/16, 15/32, -8/16, 8/16, 8/16, 8/16}
|
|
|
|
}
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta4_display", {
|
|
|
|
description = S("TA4 Display"),
|
|
|
|
inventory_image = 'techage_display_inventory.png',
|
|
|
|
tiles = {"techage_display.png"},
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
2021-05-14 19:50:16 +03:00
|
|
|
use_texture_alpha = techage.CLIP,
|
2020-05-31 23:31:18 +03:00
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "wallmounted",
|
2020-12-11 20:07:29 +03:00
|
|
|
node_box = techage.display.lcd_box,
|
|
|
|
selection_box = techage.display.lcd_box,
|
2020-05-31 23:31:18 +03:00
|
|
|
light_source = 6,
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
display_entities = {
|
|
|
|
["techage:display_entity"] = { depth = 0.42,
|
2020-12-11 20:07:29 +03:00
|
|
|
on_display_update = techage.display.display_update},
|
2020-05-31 23:31:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local number = techage.add_node(pos, "techage:ta4_display")
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("number", number)
|
|
|
|
meta:set_string("infotext", S("Display no: ")..number)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.text = {"My", "Techage","TA4", "Display", "No: "..number}
|
|
|
|
lcdlib.update_entities(pos)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
|
|
|
end,
|
|
|
|
|
2020-06-19 00:23:53 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata)
|
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-05-31 23:31:18 +03:00
|
|
|
end,
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
on_timer = techage.display.on_timer,
|
2020-05-31 23:31:18 +03:00
|
|
|
on_place = lcdlib.on_place,
|
|
|
|
on_construct = lcdlib.on_construct,
|
|
|
|
on_destruct = lcdlib.on_destruct,
|
|
|
|
on_rotate = lcdlib.on_rotate,
|
|
|
|
groups = {cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_glass_defaults(),
|
|
|
|
})
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.lcd_boxXL = {
|
2020-05-31 23:31:18 +03:00
|
|
|
type = "fixed",
|
|
|
|
fixed = {-0.9, -8/16, -8/16, 0.9, -15/32, 8/16}
|
|
|
|
}
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta4_displayXL", {
|
|
|
|
description = S("TA4 Display XL"),
|
|
|
|
inventory_image = 'techage_display_inventoryXL.png',
|
|
|
|
tiles = {"techage_displayXL.png"},
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
2021-05-14 19:50:16 +03:00
|
|
|
use_texture_alpha = techage.CLIP,
|
2020-05-31 23:31:18 +03:00
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "wallmounted",
|
2020-12-11 20:07:29 +03:00
|
|
|
node_box = techage.display.lcd_boxXL,
|
|
|
|
selection_box = techage.display.lcd_boxXL,
|
2020-05-31 23:31:18 +03:00
|
|
|
light_source = 6,
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
display_entities = {
|
|
|
|
["techage:display_entityXL"] = { depth = 0.42,
|
2020-12-11 20:07:29 +03:00
|
|
|
on_display_update = techage.display.display_updateXL},
|
2020-05-31 23:31:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local number = techage.add_node(pos, "techage:ta4_displayXL")
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("number", number)
|
|
|
|
meta:set_string("infotext", S("Display no: ")..number)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.text = {"My", "Techage","TA4", "Display", "No: "..number}
|
|
|
|
lcdlib.update_entities(pos)
|
|
|
|
minetest.get_node_timer(pos):start(2)
|
|
|
|
end,
|
|
|
|
|
2020-06-19 00:23:53 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata)
|
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-05-31 23:31:18 +03:00
|
|
|
end,
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
on_timer = techage.display.on_timer,
|
2020-05-31 23:31:18 +03:00
|
|
|
on_place = lcdlib.on_place,
|
|
|
|
on_construct = lcdlib.on_construct,
|
|
|
|
on_destruct = lcdlib.on_destruct,
|
|
|
|
on_rotate = lcdlib.on_rotate,
|
|
|
|
groups = {cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_glass_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta4_display",
|
|
|
|
recipe = {
|
|
|
|
{"", "", ""},
|
|
|
|
{"techage:basalt_glass_thin", "dye:green", "techage:ta4_wlanchip"},
|
|
|
|
{"", "default:copper_ingot", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta4_displayXL",
|
|
|
|
recipe = {
|
|
|
|
{"techage:ta4_display", "techage:ta4_display"},
|
|
|
|
{"", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
function techage.display.add_line(pos, payload, cycle_time)
|
2020-05-31 23:31:18 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local mem = techage.get_mem(pos)
|
|
|
|
nvm.text = nvm.text or {}
|
|
|
|
mem.ticks = mem.ticks or 0
|
|
|
|
local str = tostring(payload) or "oops"
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
if mem.ticks == 0 then
|
|
|
|
mem.ticks = cycle_time
|
|
|
|
end
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
while #nvm.text >= NUM_ROWS do
|
|
|
|
table.remove(nvm.text, 1)
|
|
|
|
end
|
2021-02-07 16:37:07 +03:00
|
|
|
table.insert(nvm.text, str)
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
|
2022-07-11 21:24:44 +03:00
|
|
|
function techage.display.write_row(pos, payload, cycle_time, beduino)
|
2020-05-31 23:31:18 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local mem = techage.get_mem(pos)
|
2022-07-11 21:24:44 +03:00
|
|
|
local str, row
|
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
nvm.text = nvm.text or {}
|
|
|
|
mem.ticks = mem.ticks or 0
|
2022-07-11 21:24:44 +03:00
|
|
|
|
2023-03-05 13:54:37 +03:00
|
|
|
if beduino or type(payload) == "string" then
|
2022-07-11 21:24:44 +03:00
|
|
|
row = tonumber(payload:sub(1,1) or "1") or 1
|
|
|
|
str = payload:sub(2) or "oops"
|
|
|
|
else
|
|
|
|
str = tostring(payload.get("str")) or "oops"
|
|
|
|
row = tonumber(payload.get("row")) or 1
|
|
|
|
end
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
if mem.ticks == 0 then
|
|
|
|
mem.ticks = cycle_time
|
|
|
|
end
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
if row < 1 then row = 1 end
|
|
|
|
if row > NUM_ROWS then row = NUM_ROWS end
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
while #nvm.text < row do
|
|
|
|
table.insert(nvm.text, "")
|
|
|
|
end
|
|
|
|
nvm.text[row] = str
|
|
|
|
end
|
|
|
|
|
2020-12-11 20:07:29 +03:00
|
|
|
function techage.display.clear_screen(pos, cycle_time)
|
2020-05-31 23:31:18 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local mem = techage.get_mem(pos)
|
|
|
|
mem.ticks = mem.ticks or 0
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
if mem.ticks == 0 then
|
|
|
|
mem.ticks = cycle_time
|
|
|
|
end
|
|
|
|
|
|
|
|
nvm.text = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
techage.register_node({"techage:ta4_display"}, {
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
if topic == "add" then -- add one line and scroll if necessary
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.add_line(pos, payload, 1)
|
2020-05-31 23:31:18 +03:00
|
|
|
elseif topic == "set" then -- overwrite the given row
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.write_row(pos, payload, 1)
|
2020-05-31 23:31:18 +03:00
|
|
|
elseif topic == "clear" then -- clear the screen
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.clear_screen(pos, 1)
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
end,
|
2022-07-11 21:24:44 +03:00
|
|
|
on_beduino_receive_cmnd = function(pos, src, topic, payload)
|
|
|
|
if topic == 67 then -- add one line and scroll if necessary
|
|
|
|
techage.display.add_line(pos, payload, 1)
|
|
|
|
elseif topic == 68 then -- overwrite the given row
|
|
|
|
techage.display.write_row(pos, payload, 1, true)
|
|
|
|
elseif topic == 17 then -- clear the screen
|
|
|
|
techage.display.clear_screen(pos, 1)
|
|
|
|
else
|
|
|
|
return 2
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end,
|
2022-01-04 21:43:30 +03:00
|
|
|
})
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
techage.register_node({"techage:ta4_displayXL"}, {
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
if topic == "add" then -- add one line and scroll if necessary
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.add_line(pos, payload, 2)
|
2020-05-31 23:31:18 +03:00
|
|
|
elseif topic == "set" then -- overwrite the given row
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.write_row(pos, payload, 2)
|
2020-05-31 23:31:18 +03:00
|
|
|
elseif topic == "clear" then -- clear the screen
|
2020-12-11 20:07:29 +03:00
|
|
|
techage.display.clear_screen(pos, 2)
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
end,
|
2022-07-11 21:24:44 +03:00
|
|
|
on_beduino_receive_cmnd = function(pos, src, topic, payload)
|
|
|
|
if topic == 67 then -- add one line and scroll if necessary
|
|
|
|
techage.display.add_line(pos, payload, 2)
|
|
|
|
elseif topic == 68 then -- overwrite the given row
|
|
|
|
techage.display.write_row(pos, payload, 2, true)
|
|
|
|
elseif topic == 17 then -- clear the screen
|
|
|
|
techage.display.clear_screen(pos, 2)
|
|
|
|
else
|
|
|
|
return 2
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end,
|
2020-12-11 20:07:29 +03:00
|
|
|
})
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
lcdlib.register_display_entity("techage:display_entity")
|
|
|
|
lcdlib.register_display_entity("techage:display_entityXL")
|