forked from mtcontrib/led_marquee
add optional stepping value to "scroll_step"
This commit is contained in:
parent
0cacd9af9c
commit
c703dbfa74
10
README.md
10
README.md
@ -45,13 +45,15 @@ The panels also respond to these control messages:
|
|||||||
|
|
||||||
* "off_multi" or "clear" turns all panels in a lineup or wall off - essentially a "clear screen" command.
|
* "off_multi" or "clear" turns all panels in a lineup or wall off - essentially a "clear screen" command.
|
||||||
* "allon_multi" turns on all LEDs of all panels in a lineup/wall (by filling them with char #144, i.e. the reverse of "clear").
|
* "allon_multi" turns on all LEDs of all panels in a lineup/wall (by filling them with char #144, i.e. the reverse of "clear").
|
||||||
* "start_scroll" starts the automatic scrolling function, repeatedly moving the last displayed message to the left one character space each time the scroll timer runs out (and automatically restarting it, natch). The scroll action will spread across the line, and down a multi-line wall (just set a new, different channel on the first row you want to exclude), and will continue until "stop_scroll" or any displayable message is received.
|
* "start_scroll" starts the automatic scrolling function, repeatedly moving the last displayed message to the left one character space each time the scroll timer runs out (and automatically restarting it, natch). The scroll action will spread across the line, and down a multi-line wall (just set a new, different channel on the first row you want to exclude), and will continue until "stop_scroll" or any displayable message is received.
|
||||||
* "stop_scroll" does just what it says - it stops the auto-scroll timer.
|
* "stop_scroll" does just what it says - it stops the auto-scroll timer. As it advances through the message, the scroll code will search through the message for a printable character, on each scroll step, basically stripping-out color code, and using just the last one before the new start position. This is done in order to keep a constant visible speed (the text will still be colored properly though).
|
||||||
* "scroll_speed" followed by a decimal number (in the string, not a byte value) sets the time between scroll steps. Minimum 0.5s, maximum 5s.
|
* "scroll_speed" followed by a decimal number (in the string, not a byte value) sets the time between scroll steps. Minimum 0.5s, maximum 5s.
|
||||||
* "scroll_step" will immediately advance the last-displayed message by one character. Omit the above automatic scrolling keywords, and use ONLY this keyword instead if you want to let your LuaController control the scrolling speed.
|
* "scroll_step" will immediately advance the last-displayed message by one character. Omit the above automatic scrolling keywords, and use ONLY this keyword instead if you want to let your LuaController control the scrolling speed. Optionally, you can follow this with a number and the scroll code will skip forward that many bytes into the message, starting from the current position, before starting the above-mentioned color-vs-character search. Essentially, this value will roughly translate to the number of printable
|
||||||
* "get" will read the one character (as a numerical character value) currently displayed by the master panel (by reading its node name)
|
* "get" will read the one character (as a numerical character value) currently displayed by the master panel (by reading its node name)
|
||||||
* "getstr" will read the last-stored message for the entire lineup/wall (from the master panel's meta), respectively. Note that even if the message has been or is being scrolled, you'll get the original stored message.
|
* "getstr" will read the last-stored message for the entire lineup/wall (from the master panel's meta), respectively. Note that even if the message has been or is being scrolled, you'll get the original stored message.
|
||||||
* "getindex" will read the scroll index position in that message
|
* "getindex" will read the scroll index position in that message, which will always point at a printable character, per the above color-versus-character search.
|
||||||
|
|
||||||
|
During a scroll event, the printed string is padded with spaces (one in auto mode, or as many as the skip value when manually stepping).
|
||||||
|
|
||||||
If you need vertical scrolling, you will have to handle that yourself (since the size of a screen/wall is not hard-coded).
|
If you need vertical scrolling, you will have to handle that yourself (since the size of a screen/wall is not hard-coded).
|
||||||
|
|
||||||
|
16
init.lua
16
init.lua
@ -66,15 +66,16 @@ led_marquee.set_timer = function(pos, timeout)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
led_marquee.scroll_text = function(pos, elapsed)
|
led_marquee.scroll_text = function(pos, elapsed, skip)
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local msg = meta:get_string("last_msg")
|
local msg = meta:get_string("last_msg")
|
||||||
local channel = meta:get_string("channel")
|
local channel = meta:get_string("channel")
|
||||||
local index = meta:get_int("index")
|
local index = meta:get_int("index")
|
||||||
if not index or index < 1 or not string.byte(msg, index) then index = 1 end
|
if not index or index < 1 or not string.byte(msg, index) then index = 1 end
|
||||||
local len = string.len(msg)
|
local len = string.len(msg)
|
||||||
index = index + 1
|
skip = skip or 1
|
||||||
|
|
||||||
|
index = index + skip
|
||||||
|
|
||||||
while index < len and string.byte(msg, index) < 28 do
|
while index < len and string.byte(msg, index) < 28 do
|
||||||
index = index + 1
|
index = index + 1
|
||||||
@ -82,7 +83,7 @@ led_marquee.scroll_text = function(pos, elapsed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if string.byte(msg, index - 1) < 28 then
|
if string.byte(msg, index - 1) < 28 then
|
||||||
led_marquee.display_msg(pos, channel, string.sub(msg, index - 1).." ")
|
led_marquee.display_msg(pos, channel, string.sub(msg, index - 1)..string.rep(" ", skip + 1))
|
||||||
else
|
else
|
||||||
local i = index - 1
|
local i = index - 1
|
||||||
local color = ""
|
local color = ""
|
||||||
@ -91,7 +92,7 @@ led_marquee.scroll_text = function(pos, elapsed)
|
|||||||
if i == 0 then break end
|
if i == 0 then break end
|
||||||
end
|
end
|
||||||
if i > 0 then color = string.sub(msg, i, i) end
|
if i > 0 then color = string.sub(msg, i, i) end
|
||||||
led_marquee.display_msg(pos, channel, color..string.sub(msg, index).." ")
|
led_marquee.display_msg(pos, channel, color..string.sub(msg, index)..string.rep(" ", skip + 1))
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_int("index", index)
|
meta:set_int("index", index)
|
||||||
@ -219,8 +220,9 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
|||||||
if not timeout or timeout < 0.5 or timeout > 5 then timeout = 0 end
|
if not timeout or timeout < 0.5 or timeout > 5 then timeout = 0 end
|
||||||
meta:set_int("timeout", timeout)
|
meta:set_int("timeout", timeout)
|
||||||
led_marquee.set_timer(pos, timeout)
|
led_marquee.set_timer(pos, timeout)
|
||||||
elseif msg == "scroll_step" then
|
elseif string.sub(msg, 1, 11) == "scroll_step" then
|
||||||
led_marquee.scroll_text(pos)
|
local skip = tonumber(string.sub(msg, 12))
|
||||||
|
led_marquee.scroll_text(pos, nil, skip)
|
||||||
elseif msg == "get" then -- get the master panel's displayed char as ASCII numerical value
|
elseif msg == "get" then -- get the master panel's displayed char as ASCII numerical value
|
||||||
digilines.receptor_send(pos, digiline.rules.default, channel, tonumber(string.match(minetest.get_node(pos).name,"led_marquee:char_(.+)"))) -- wonderfully horrible string manipulaiton
|
digilines.receptor_send(pos, digiline.rules.default, channel, tonumber(string.match(minetest.get_node(pos).name,"led_marquee:char_(.+)"))) -- wonderfully horrible string manipulaiton
|
||||||
elseif msg == "getstr" then -- get the last stored message
|
elseif msg == "getstr" then -- get the last stored message
|
||||||
|
Loading…
Reference in New Issue
Block a user