mirror of
https://github.com/mt-mods/led_marquee.git
synced 2025-06-28 22:36:41 +02:00
Compare commits
11 Commits
2019-05-25
...
2021-04-14
Author | SHA1 | Date | |
---|---|---|---|
2bf2651cee | |||
aafa748f92 | |||
39f571f788 | |||
108f0dad1a | |||
63de1f5ab5 | |||
642aec419a | |||
caf6e24d04 | |||
31a938693a | |||
45c89704f0 | |||
8d3a0e92de | |||
db78e3dcdb |
62
init.lua
62
init.lua
@ -2,6 +2,13 @@
|
|||||||
-- by Vanessa Dannenberg
|
-- by Vanessa Dannenberg
|
||||||
|
|
||||||
led_marquee = {}
|
led_marquee = {}
|
||||||
|
led_marquee.scheduled_messages = {}
|
||||||
|
|
||||||
|
led_marquee.message_minimum_time = tonumber(minetest.settings:get("led_marquee_message_minimum_time")) or 0.5
|
||||||
|
|
||||||
|
led_marquee.message_schedule_dtime = tonumber(minetest.settings:get("led_marquee_message_schedule_dtime")) or 0.2
|
||||||
|
led_marquee.message_schedule_size = tonumber(minetest.settings:get("led_marquee_message_schedule_size")) or 10
|
||||||
|
led_marquee.relay_timer = 0
|
||||||
|
|
||||||
local S
|
local S
|
||||||
if minetest.get_modpath("intllib") then
|
if minetest.get_modpath("intllib") then
|
||||||
@ -96,7 +103,12 @@ local char_to_color = {
|
|||||||
-- the following functions based on the so-named ones in Jeija's digilines mod
|
-- the following functions based on the so-named ones in Jeija's digilines mod
|
||||||
|
|
||||||
local reset_meta = function(pos)
|
local reset_meta = function(pos)
|
||||||
minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]")
|
minetest.get_meta(pos):set_string("formspec",
|
||||||
|
"formspec_version[4]"..
|
||||||
|
"size[8,4]"..
|
||||||
|
"button_exit[3,2.5;2,0.5;proceed;Proceed]"..
|
||||||
|
"field[1.75,1.5;4.5,0.5;channel;Channel;${channel}]"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local on_digiline_receive_std = function(pos, node, channel, msg)
|
local on_digiline_receive_std = function(pos, node, channel, msg)
|
||||||
@ -128,7 +140,12 @@ local make_iso = function(s)
|
|||||||
local s2 = ""
|
local s2 = ""
|
||||||
while i <= string.len(s) do
|
while i <= string.len(s) do
|
||||||
if string.byte(s,i) > 159 then
|
if string.byte(s,i) > 159 then
|
||||||
s2 = s2..string.char(get_iso(string.sub(s, i, i+1)))
|
local ciso = get_iso(string.sub(s, i, i+1))
|
||||||
|
if ciso >= 0 and ciso < 256 then
|
||||||
|
s2 = s2..string.char(ciso)
|
||||||
|
else
|
||||||
|
s2 = s2..string.char(127)
|
||||||
|
end
|
||||||
i = i + 2
|
i = i + 2
|
||||||
else
|
else
|
||||||
s2 = s2..string.sub(s, i, i)
|
s2 = s2..string.sub(s, i, i)
|
||||||
@ -143,7 +160,7 @@ end
|
|||||||
led_marquee.set_timer = function(pos, timeout)
|
led_marquee.set_timer = function(pos, timeout)
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
timer:stop()
|
timer:stop()
|
||||||
if not timeout or timeout < 0.2 or timeout > 5 then return false end
|
if not timeout or timeout < led_marquee.message_minimum_time or timeout > 5 then return false end
|
||||||
|
|
||||||
if timeout > 0 then
|
if timeout > 0 then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -184,7 +201,7 @@ led_marquee.scroll_text = function(pos, elapsed, skip)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
led_marquee.display_msg(pos, channel, "/"..colorchar..string.sub(msg, f)..string.rep(" ", skip + 1))
|
led_marquee.schedule_msg(pos, channel, "/"..colorchar..string.sub(msg, f)..string.rep(" ", skip + 1))
|
||||||
|
|
||||||
meta:set_int("index", f)
|
meta:set_int("index", f)
|
||||||
if not elapsed or elapsed < 0.2 then return false end
|
if not elapsed or elapsed < 0.2 then return false end
|
||||||
@ -213,6 +230,27 @@ led_marquee.decode_color = function(msg)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
if dtime <= led_marquee.message_schedule_dtime
|
||||||
|
and (#led_marquee.scheduled_messages) > 0 then
|
||||||
|
led_marquee.display_msg(
|
||||||
|
led_marquee.scheduled_messages[1].pos,
|
||||||
|
led_marquee.scheduled_messages[1].channel,
|
||||||
|
led_marquee.scheduled_messages[1].msg
|
||||||
|
)
|
||||||
|
end
|
||||||
|
table.remove(led_marquee.scheduled_messages, 1)
|
||||||
|
end)
|
||||||
|
|
||||||
|
led_marquee.schedule_msg = function(pos, channel, msg)
|
||||||
|
local idx = #led_marquee.scheduled_messages
|
||||||
|
led_marquee.scheduled_messages[idx+1] = { pos=pos, channel=channel, msg=msg }
|
||||||
|
|
||||||
|
if idx >= led_marquee.message_schedule_size then
|
||||||
|
table.remove(led_marquee.scheduled_messages, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
led_marquee.display_msg = function(pos, channel, msg)
|
led_marquee.display_msg = function(pos, channel, msg)
|
||||||
msg = string.sub(msg, 1, 6144).." "
|
msg = string.sub(msg, 1, 6144).." "
|
||||||
if string.sub(msg,1,1) == string.char(255) then -- treat it as incoming UTF-8
|
if string.sub(msg,1,1) == string.char(255) then -- treat it as incoming UTF-8
|
||||||
@ -312,13 +350,13 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
|||||||
led_marquee.set_timer(pos, 0)
|
led_marquee.set_timer(pos, 0)
|
||||||
msg = string.rep(" ", 2048)
|
msg = string.rep(" ", 2048)
|
||||||
meta:set_string("last_msg", msg)
|
meta:set_string("last_msg", msg)
|
||||||
led_marquee.display_msg(pos, channel, msg)
|
led_marquee.schedule_msg(pos, channel, msg)
|
||||||
meta:set_int("index", 1)
|
meta:set_int("index", 1)
|
||||||
elseif msg == "allon" then
|
elseif msg == "allon" then
|
||||||
led_marquee.set_timer(pos, 0)
|
led_marquee.set_timer(pos, 0)
|
||||||
msg = string.rep(string.char(144), 2048)
|
msg = string.rep(string.char(144), 2048)
|
||||||
meta:set_string("last_msg", msg)
|
meta:set_string("last_msg", msg)
|
||||||
led_marquee.display_msg(pos, channel, msg)
|
led_marquee.schedule_msg(pos, channel, msg)
|
||||||
meta:set_int("index", 1)
|
meta:set_int("index", 1)
|
||||||
elseif msg == "start_scroll" then
|
elseif msg == "start_scroll" then
|
||||||
local timeout = meta:get_int("timeout")
|
local timeout = meta:get_int("timeout")
|
||||||
@ -327,8 +365,8 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
|||||||
led_marquee.set_timer(pos, 0)
|
led_marquee.set_timer(pos, 0)
|
||||||
return
|
return
|
||||||
elseif string.sub(msg, 1, 12) == "scroll_speed" then
|
elseif string.sub(msg, 1, 12) == "scroll_speed" then
|
||||||
local timeout = tonumber(string.sub(msg, 13))
|
local timeout = tonumber(string.sub(msg, 13)) or 0
|
||||||
led_marquee.set_timer(pos, timeout)
|
led_marquee.set_timer(pos, math.max(timeout, led_marquee.message_minimum_time))
|
||||||
elseif string.sub(msg, 1, 11) == "scroll_step" then
|
elseif string.sub(msg, 1, 11) == "scroll_step" then
|
||||||
local skip = tonumber(string.sub(msg, 12))
|
local skip = tonumber(string.sub(msg, 12))
|
||||||
led_marquee.scroll_text(pos, nil, skip)
|
led_marquee.scroll_text(pos, nil, skip)
|
||||||
@ -343,14 +381,14 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
|||||||
led_marquee.set_timer(pos, 0)
|
led_marquee.set_timer(pos, 0)
|
||||||
local last_msg = meta:get_string("last_msg")
|
local last_msg = meta:get_string("last_msg")
|
||||||
meta:set_string("last_msg", msg)
|
meta:set_string("last_msg", msg)
|
||||||
led_marquee.display_msg(pos, channel, msg)
|
led_marquee.schedule_msg(pos, channel, msg)
|
||||||
if last_msg ~= msg then
|
if last_msg ~= msg then
|
||||||
meta:set_int("index", 1)
|
meta:set_int("index", 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local asc = string.byte(msg)
|
local asc = string.byte(msg)
|
||||||
if asc > 29 and asc < 256 then
|
if asc > 30 and asc < 256 then
|
||||||
minetest.swap_node(pos, { name = "led_marquee:char_"..asc, param2 = fdir + (last_color*8)})
|
minetest.swap_node(pos, { name = "led_marquee:char_"..asc, param2 = fdir + (last_color*8)})
|
||||||
meta:set_string("last_msg", tostring(msg))
|
meta:set_string("last_msg", tostring(msg))
|
||||||
meta:set_int("index", 1)
|
meta:set_int("index", 1)
|
||||||
@ -358,7 +396,7 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
|||||||
end
|
end
|
||||||
elseif msg and type(msg) == "number" then
|
elseif msg and type(msg) == "number" then
|
||||||
meta:set_string("last_msg", tostring(msg))
|
meta:set_string("last_msg", tostring(msg))
|
||||||
led_marquee.display_msg(pos, channel, tostring(msg))
|
led_marquee.schedule_msg(pos, channel, tostring(msg))
|
||||||
meta:set_int("index", 1)
|
meta:set_int("index", 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -399,7 +437,7 @@ for i = 31, 255 do
|
|||||||
inventory_image = wimage,
|
inventory_image = wimage,
|
||||||
wield_image = wimage,
|
wield_image = wimage,
|
||||||
palette="led_marquee_palette.png",
|
palette="led_marquee_palette.png",
|
||||||
use_texture_alpha = true,
|
use_texture_alpha = "blend",
|
||||||
groups = groups,
|
groups = groups,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "colorwallmounted",
|
paramtype2 = "colorwallmounted",
|
||||||
|
Reference in New Issue
Block a user