mods that hopefully work for a TechAge-based pack
This commit is contained in:
@@ -0,0 +1,296 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2022 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
ICTA Controller - Display
|
||||
|
||||
]]--
|
||||
|
||||
local S = techage.S
|
||||
|
||||
techage.display = {}
|
||||
|
||||
local NUM_ROWS = 5
|
||||
local RADIUS = 6
|
||||
local Param2ToFacedir = {[0] = 0, 0, 3, 1, 2, 0}
|
||||
|
||||
local function lcdlib_bugfix(text_tbl)
|
||||
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
|
||||
|
||||
function techage.display.display_update(pos, objref)
|
||||
if pos and type(pos) == "table" then
|
||||
pos = vector.round(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local text = lcdlib_bugfix(nvm.text)
|
||||
local texture = lcdlib.make_multiline_texture(
|
||||
"default", text,
|
||||
70, 70, NUM_ROWS, "top", "#000", nil, true)
|
||||
objref:set_properties({ textures = {texture},
|
||||
visual_size = {x=0.94, y=0.94} })
|
||||
end
|
||||
end
|
||||
|
||||
function techage.display.display_updateXL(pos, objref)
|
||||
if pos and type(pos) == "table" then
|
||||
pos = vector.round(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local text = lcdlib_bugfix(nvm.text)
|
||||
local texture = lcdlib.make_multiline_texture(
|
||||
"default", text,
|
||||
126, 70, NUM_ROWS, "top", "#000", nil, true)
|
||||
objref:set_properties({ textures = {texture},
|
||||
visual_size = {x=0.94*1.9, y=0.94} })
|
||||
end
|
||||
end
|
||||
|
||||
function techage.display.on_timer(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
|
||||
if mem.update then
|
||||
local node = minetest.get_node(pos)
|
||||
-- check if display is loaded and a player in front of the display
|
||||
if node.name ~= "ignore" then
|
||||
local dir = minetest.facedir_to_dir(Param2ToFacedir[node.param2 % 6])
|
||||
dir.y = 0
|
||||
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.update = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
techage.display.lcd_box = {
|
||||
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",
|
||||
use_texture_alpha = techage.CLIP,
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "wallmounted",
|
||||
node_box = techage.display.lcd_box,
|
||||
selection_box = techage.display.lcd_box,
|
||||
light_source = 6,
|
||||
|
||||
display_entities = {
|
||||
["techage:display_entity"] = { depth = 0.42,
|
||||
on_display_update = techage.display.display_update},
|
||||
},
|
||||
|
||||
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,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
|
||||
on_timer = techage.display.on_timer,
|
||||
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(),
|
||||
})
|
||||
|
||||
techage.display.lcd_boxXL = {
|
||||
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",
|
||||
use_texture_alpha = techage.CLIP,
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "wallmounted",
|
||||
node_box = techage.display.lcd_boxXL,
|
||||
selection_box = techage.display.lcd_boxXL,
|
||||
light_source = 6,
|
||||
|
||||
display_entities = {
|
||||
["techage:display_entityXL"] = { depth = 0.42,
|
||||
on_display_update = techage.display.display_updateXL},
|
||||
},
|
||||
|
||||
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,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
|
||||
on_timer = techage.display.on_timer,
|
||||
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"},
|
||||
{"", ""},
|
||||
},
|
||||
})
|
||||
|
||||
function techage.display.add_line(pos, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
nvm.text = nvm.text or {}
|
||||
local str = tostring(payload) or "oops"
|
||||
|
||||
mem.update = true
|
||||
|
||||
while #nvm.text >= NUM_ROWS do
|
||||
table.remove(nvm.text, 1)
|
||||
end
|
||||
table.insert(nvm.text, str)
|
||||
end
|
||||
|
||||
function techage.display.write_row(pos, payload, beduino)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local str, row
|
||||
|
||||
nvm.text = nvm.text or {}
|
||||
|
||||
if beduino or type(payload) == "string" then
|
||||
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
|
||||
|
||||
mem.update = true
|
||||
|
||||
if row < 1 then row = 1 end
|
||||
if row > NUM_ROWS then row = NUM_ROWS end
|
||||
|
||||
while #nvm.text < row do
|
||||
table.insert(nvm.text, "")
|
||||
end
|
||||
nvm.text[row] = str
|
||||
end
|
||||
|
||||
function techage.display.clear_screen(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
mem.update = true
|
||||
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
|
||||
techage.display.add_line(pos, payload)
|
||||
elseif topic == "set" then -- overwrite the given row
|
||||
techage.display.write_row(pos, payload)
|
||||
elseif topic == "clear" then -- clear the screen
|
||||
techage.display.clear_screen(pos)
|
||||
end
|
||||
end,
|
||||
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)
|
||||
elseif topic == 68 then -- overwrite the given row
|
||||
techage.display.write_row(pos, payload, true)
|
||||
elseif topic == 17 then -- clear the screen
|
||||
techage.display.clear_screen(pos)
|
||||
else
|
||||
return 2
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
|
||||
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
|
||||
techage.display.add_line(pos, payload)
|
||||
elseif topic == "set" then -- overwrite the given row
|
||||
techage.display.write_row(pos, payload)
|
||||
elseif topic == "clear" then -- clear the screen
|
||||
techage.display.clear_screen(pos)
|
||||
end
|
||||
end,
|
||||
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)
|
||||
elseif topic == 68 then -- overwrite the given row
|
||||
techage.display.write_row(pos, payload, true)
|
||||
elseif topic == 17 then -- clear the screen
|
||||
techage.display.clear_screen(pos)
|
||||
else
|
||||
return 2
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
|
||||
lcdlib.register_display_entity("techage:display_entity")
|
||||
lcdlib.register_display_entity("techage:display_entityXL")
|
||||
@@ -0,0 +1,329 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2025 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Mono Displays
|
||||
|
||||
]]--
|
||||
|
||||
local S = techage.S
|
||||
local M = minetest.get_meta
|
||||
local color = techage.color
|
||||
local DESCR = S("TA4 Display II")
|
||||
local MENUL = {
|
||||
{
|
||||
type = "dropdown",
|
||||
choices = "16x8,20x10,24x12,28x14,32x16,36x18,40x20",
|
||||
name = "resolution",
|
||||
label = S("Resolution"),
|
||||
tooltip = S("Select resolution of the display in characters x lines"),
|
||||
default = "14",
|
||||
values = {8,10,12,14,16,18,20},
|
||||
},
|
||||
{
|
||||
type = "numbers",
|
||||
name = "colorno",
|
||||
label = S("Text color"),
|
||||
tooltip = S("Select color of the screen text (0..63)\nSee chat command '/ta_color64'"),
|
||||
default = "63",
|
||||
},
|
||||
{
|
||||
type = "numbers",
|
||||
name = "background",
|
||||
label = S("Background color"),
|
||||
tooltip = S("Select color of the display background (0..63)\nSee chat command '/ta_color64'"),
|
||||
default = "0",
|
||||
},
|
||||
}
|
||||
|
||||
local MENUS = {
|
||||
{
|
||||
type = "numbers",
|
||||
name = "background",
|
||||
label = S("Background color"),
|
||||
tooltip = S("Select color of the display background (0..63)\nSee chat command '/ta_color64'"),
|
||||
default = "0",
|
||||
},
|
||||
}
|
||||
|
||||
local function range(value, min, max)
|
||||
value = math.min(value, max)
|
||||
value = math.max(value, min)
|
||||
return value
|
||||
end
|
||||
|
||||
local function update(pos, objref)
|
||||
pos = vector.round(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
-- local t = core.get_us_time()
|
||||
lcdlib.on_mono_display_update(pos, objref, nvm.text or {})
|
||||
-- t = core.get_us_time() - t
|
||||
-- print("time =", t)
|
||||
end
|
||||
|
||||
local function on_timer(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
if mem.update then
|
||||
lcdlib.update_entities(pos)
|
||||
mem.update = false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function register_display(name, description, inventory_image, tiles, node_box, display_entities)
|
||||
minetest.register_node(name, {
|
||||
description = description,
|
||||
inventory_image = inventory_image,
|
||||
tiles = tiles,
|
||||
drawtype = "nodebox",
|
||||
paramtype2 = "color4dir",
|
||||
palette = "techage_palette64.png",
|
||||
node_box = node_box,
|
||||
paramtype = "light",
|
||||
use_texture_alpha = techage.CLIP,
|
||||
sunlight_propagates = true,
|
||||
light_source = 8,
|
||||
ta3_formspec = display_entities and MENUL or MENUS,
|
||||
ta_after_formspec = function(pos, fields, playername)
|
||||
if fields.save then
|
||||
-- Check if the colorno and background are in the range 0..63
|
||||
M(pos):set_int("colorno", range(M(pos):get_int("colorno"), 0, 63))
|
||||
M(pos):set_int("background", range(M(pos):get_int("background"), 0, 63))
|
||||
-- Set the background color of the display
|
||||
local background = M(pos):get_int("background")
|
||||
local node = minetest.get_node(pos)
|
||||
node.param2 = (node.param2 % 4) + background * 4
|
||||
minetest.swap_node(pos, node)
|
||||
-- Set the text color of the display
|
||||
local colorno = M(pos):get_int("colorno")
|
||||
M(pos):set_string("color", color.COLOR64[colorno + 1])
|
||||
lcdlib.update_entities(pos)
|
||||
-- Set the update time of the display
|
||||
local resolution = M(pos):get_int("resolution")
|
||||
local cycle_time = resolution * resolution / 64
|
||||
minetest.get_node_timer(pos):stop()
|
||||
minetest.get_node_timer(pos):start(cycle_time)
|
||||
end
|
||||
end,
|
||||
|
||||
display_entities = display_entities,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
local meta = M(pos)
|
||||
if ndef.display_entities then
|
||||
local number = techage.add_node(pos, node.name)
|
||||
meta:set_string("number", number)
|
||||
meta:set_string("infotext", DESCR .. " " .. number)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.text = {"My Techage", "TA4 Display II", "No: "..number}
|
||||
meta:set_int("resolution", 14)
|
||||
meta:set_string("color", "#F5F5F5")
|
||||
meta:set_int("colorno", 63)
|
||||
lcdlib.update_entities(pos)
|
||||
end
|
||||
meta:set_int("background", 4)
|
||||
node.param2 = (node.param2 % 4) + 4 * 4
|
||||
minetest.swap_node(pos, node)
|
||||
minetest.get_node_timer(pos):start(3)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
on_timer = on_timer,
|
||||
on_destruct = lcdlib.on_destruct,
|
||||
on_rotate = lcdlib.on_rotate,
|
||||
on_dig = color.on_dig,
|
||||
groups = {cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
||||
end
|
||||
|
||||
register_display(
|
||||
"techage:ta4_display2",
|
||||
DESCR,
|
||||
'techage_display2_inventory.png',
|
||||
{-- up, down, right, left, back, front
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_front.png',
|
||||
},
|
||||
{
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-16/32, -16/32, 14/32, 16/32, 16/32, 16/32},
|
||||
},
|
||||
},
|
||||
{
|
||||
["techage:display2_entity"] = {
|
||||
depth = 0.43,
|
||||
yoffs = 0.000,
|
||||
size = {x=0.94, y=0.94},
|
||||
on_display_update = update
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
register_display(
|
||||
"techage:ta4_displayXXL",
|
||||
S("TA4 Display II XXL inside"),
|
||||
'techage_display2_inventory.png^techage_displayXXL_inventory.png',
|
||||
{-- up, down, right, left, back, front
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_front2.png',
|
||||
},
|
||||
{
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-16/32, -16/32, 10/32, 16/32, 16/32, 16/32},
|
||||
},
|
||||
},
|
||||
{
|
||||
["techage:monitor_entity"] = {
|
||||
depth = 0.3,
|
||||
size = {x=2.8, y=2.8},
|
||||
on_display_update = update
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
register_display(
|
||||
"techage:ta4_displayXXL2",
|
||||
S("TA4 Display II XXL outside"),
|
||||
'techage_display2_inventory.png^techage_displayXXL_inventory.png',
|
||||
{-- up, down, right, left, back, front
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_side.png',
|
||||
'techage_display2_front2.png',
|
||||
},
|
||||
{
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-16/32, -16/32, 10/32, 16/32, 16/32, 16/32},
|
||||
},
|
||||
},
|
||||
nil
|
||||
)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta4_display2",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"techage:basalt_glass_thin", "dye:black", "techage:ta4_leds"},
|
||||
{"default:copper_ingot", "techage:ta4_wlanchip", "basic_materials:plastic_sheet"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta4_displayXXL2",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"techage:basalt_glass_thin", "dye:black", "techage:ta4_leds"},
|
||||
{"default:copper_ingot", "", "basic_materials:plastic_sheet"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta4_displayXXL",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"techage:ta4_leds", "dye:black", "techage:basalt_glass_thin"},
|
||||
{"default:copper_ingot", "techage:ta4_wlanchip", "basic_materials:plastic_sheet"},
|
||||
},
|
||||
})
|
||||
|
||||
local function add_line(pos, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local num_rows = M(pos):get_int("resolution") or 8
|
||||
nvm.text = nvm.text or {}
|
||||
local str = tostring(payload) or "oops"
|
||||
mem.update = true
|
||||
while #nvm.text >= num_rows do
|
||||
table.remove(nvm.text, 1)
|
||||
end
|
||||
table.insert(nvm.text, str)
|
||||
end
|
||||
|
||||
local function write_row(pos, payload, beduino)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local num_rows = M(pos):get_int("resolution") or 8
|
||||
local str, row
|
||||
nvm.text = nvm.text or {}
|
||||
|
||||
if beduino or type(payload) == "string" then
|
||||
-- split string into row and text on the first blank
|
||||
words = string.split(payload, " ", false, 1, false)
|
||||
row = tonumber(words[1] or "1") or 1
|
||||
str = words[2] or "oops"
|
||||
else
|
||||
str = tostring(payload.get("str")) or "oops"
|
||||
row = tonumber(payload.get("row")) or 1
|
||||
end
|
||||
mem.update = true
|
||||
if row < 1 then row = 1 end
|
||||
if row > num_rows then row = num_rows end
|
||||
|
||||
while #nvm.text < row do
|
||||
table.insert(nvm.text, "")
|
||||
end
|
||||
nvm.text[row] = str
|
||||
end
|
||||
|
||||
local function clear_screen(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
mem.update = true
|
||||
nvm.text = {}
|
||||
end
|
||||
|
||||
techage.register_node({"techage:ta4_display2", "techage:ta4_displayXXL"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
if topic == "add" then -- add one line and scroll if necessary
|
||||
add_line(pos, payload)
|
||||
elseif topic == "set" then -- overwrite the given row
|
||||
write_row(pos, payload)
|
||||
elseif topic == "clear" then -- clear the screen
|
||||
clear_screen(pos)
|
||||
end
|
||||
end,
|
||||
on_beduino_receive_cmnd = function(pos, src, topic, payload)
|
||||
if topic == 67 then -- add one line and scroll if necessary
|
||||
add_line(pos, payload)
|
||||
elseif topic == 68 then -- overwrite the given row
|
||||
write_row(pos, payload, true)
|
||||
elseif topic == 17 then -- clear the screen
|
||||
clear_screen(pos)
|
||||
else
|
||||
return 2
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
on_node_load = function(pos)
|
||||
lcdlib.update_entities(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
lcdlib.register_display_entity("techage:display2_entity")
|
||||
@@ -0,0 +1,225 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2025 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA3 CRT Monitor
|
||||
|
||||
]]--
|
||||
|
||||
local S = techage.S
|
||||
local M = minetest.get_meta
|
||||
|
||||
local MENU = {
|
||||
{
|
||||
type = "dropdown",
|
||||
choices = "16x8,20x10,24x12,28x14,32x16,36x18,40x20",
|
||||
name = "resolution",
|
||||
label = S("Resolution"),
|
||||
tooltip = S("Select resolution of the monitor in characters x lines"),
|
||||
default = "8",
|
||||
values = {8,10,12,14,16,18,20},
|
||||
},
|
||||
{
|
||||
type = "dropdown",
|
||||
choices = "green,amber,yellow,white",
|
||||
name = "color",
|
||||
label = S("Color"),
|
||||
tooltip = S("Select color of the screen text"),
|
||||
default = "#2DD204",
|
||||
values = {"#2DD204","#F8C800","#DFD700","#CCCCCC"},
|
||||
},
|
||||
}
|
||||
|
||||
local function update(pos, objref)
|
||||
pos = vector.round(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
-- local t = core.get_us_time()
|
||||
lcdlib.on_mono_display_update(pos, objref, nvm.text or {})
|
||||
-- t = core.get_us_time() - t
|
||||
-- print("time =", t)
|
||||
end
|
||||
|
||||
local function on_timer(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
mem.ticks = mem.ticks or 0
|
||||
if mem.ticks > 0 then
|
||||
lcdlib.update_entities(pos)
|
||||
mem.ticks = mem.ticks - 1
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta3_monitor", {
|
||||
description = S("TA3 CRT Monitor"),
|
||||
tiles = {-- up, down, right, left, back, front
|
||||
'techage_monitor_top.png',
|
||||
'techage_monitor_top.png',
|
||||
'techage_monitor_side.png^[transformFX',
|
||||
'techage_monitor_side.png',
|
||||
'techage_monitor_back.png',
|
||||
'techage_monitor_front.png',
|
||||
},
|
||||
drawtype = "nodebox",
|
||||
paramtype2 = "facedir",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-16/32, -16/32, -15/32, 16/32, 16/32, 8/32},
|
||||
{-10/32, -10/32, 8/32, 10/32, 10/32, 12/32},
|
||||
},
|
||||
},
|
||||
paramtype = "light",
|
||||
use_texture_alpha = techage.CLIP,
|
||||
sunlight_propagates = true,
|
||||
light_source = 8,
|
||||
ta3_formspec = MENU,
|
||||
ta_after_formspec = function(pos, fields, playername)
|
||||
if fields.save then
|
||||
lcdlib.update_entities(pos)
|
||||
local resolution = M(pos):get_int("resolution")
|
||||
local cycle_time = resolution * resolution / 64
|
||||
print("cycle_time =", cycle_time)
|
||||
minetest.get_node_timer(pos):start(cycle_time)
|
||||
end
|
||||
end,
|
||||
|
||||
display_entities = {
|
||||
["techage:monitor_entity"] = {
|
||||
depth = -0.48,
|
||||
yoffs = 0.025,
|
||||
size = {x=0.90, y=0.90},
|
||||
on_display_update = update
|
||||
},
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local number = techage.add_node(pos, "techage:ta3_monitor")
|
||||
local meta = M(pos)
|
||||
meta:set_string("number", number)
|
||||
meta:set_int("resolution", 8)
|
||||
meta:set_string("color", "#33FF00")
|
||||
meta:set_string("infotext", S("TA3 CRT Monitor no:") .. " " .. number)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.text = {"My", "Techage","TA3", "CRT Monitor", "No: " .. number}
|
||||
lcdlib.update_entities(pos)
|
||||
minetest.get_node_timer(pos):start(1)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
on_timer = on_timer,
|
||||
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:ta3_monitor",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"techage:basalt_glass_thin", "dye:green", ""},
|
||||
{"techage:vacuum_tube", "default:copper_ingot", "techage:vacuum_tube"},
|
||||
},
|
||||
})
|
||||
|
||||
local function add_line(pos, payload, cycle_time)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local num_rows = M(pos):get_int("resolution") or 8
|
||||
nvm.text = nvm.text or {}
|
||||
mem.ticks = mem.ticks or 0
|
||||
local str = tostring(payload) or "oops"
|
||||
|
||||
if mem.ticks == 0 then
|
||||
mem.ticks = cycle_time
|
||||
end
|
||||
|
||||
while #nvm.text >= num_rows do
|
||||
table.remove(nvm.text, 1)
|
||||
end
|
||||
table.insert(nvm.text, str)
|
||||
end
|
||||
|
||||
local function write_row(pos, payload, cycle_time, beduino)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local num_rows = M(pos):get_int("resolution") or 8
|
||||
local str, row
|
||||
|
||||
nvm.text = nvm.text or {}
|
||||
mem.ticks = mem.ticks or 0
|
||||
|
||||
if beduino or type(payload) == "string" then
|
||||
-- split string into row and text on the first blank
|
||||
words = string.split(payload, " ", false, 1, false)
|
||||
row = tonumber(words[1] or "1") or 1
|
||||
str = words[2] or "oops"
|
||||
else
|
||||
str = tostring(payload.get("str")) or "oops"
|
||||
row = tonumber(payload.get("row")) or 1
|
||||
end
|
||||
|
||||
if mem.ticks == 0 then
|
||||
mem.ticks = cycle_time
|
||||
end
|
||||
|
||||
if row < 1 then row = 1 end
|
||||
if row > num_rows then row = num_rows end
|
||||
|
||||
while #nvm.text < row do
|
||||
table.insert(nvm.text, "")
|
||||
end
|
||||
nvm.text[row] = str
|
||||
end
|
||||
|
||||
local function clear_screen(pos, cycle_time)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
mem.ticks = mem.ticks or 0
|
||||
|
||||
if mem.ticks == 0 then
|
||||
mem.ticks = cycle_time
|
||||
end
|
||||
|
||||
nvm.text = {}
|
||||
end
|
||||
|
||||
techage.register_node({"techage:ta3_monitor"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
if topic == "add" then -- add one line and scroll if necessary
|
||||
add_line(pos, payload, 1)
|
||||
elseif topic == "set" then -- overwrite the given row
|
||||
write_row(pos, payload, 1)
|
||||
elseif topic == "clear" then -- clear the screen
|
||||
clear_screen(pos, 1)
|
||||
end
|
||||
end,
|
||||
on_beduino_receive_cmnd = function(pos, src, topic, payload)
|
||||
if topic == 67 then -- add one line and scroll if necessary
|
||||
add_line(pos, payload, 1)
|
||||
elseif topic == 68 then -- overwrite the given row
|
||||
write_row(pos, payload, 1, true)
|
||||
elseif topic == 17 then -- clear the screen
|
||||
clear_screen(pos, 1)
|
||||
else
|
||||
return 2
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
on_node_load = function(pos)
|
||||
lcdlib.update_entities(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
lcdlib.register_display_entity("techage:monitor_entity")
|
||||
Reference in New Issue
Block a user