diff options
Diffstat (limited to 'led_marquee')
22 files changed, 155 insertions, 42 deletions
diff --git a/led_marquee/README.md b/led_marquee/README.md index 00508dc..b8aef6c 100644 --- a/led_marquee/README.md +++ b/led_marquee/README.md @@ -24,7 +24,7 @@ If the program finds something other than a panel, it wraps to the next line. If Lines of panels don't need to be all the same length, the program will wrap as needed, with the left margin always being aligned with the panel the LuaController is connected to. -Strings are trimmed to 1 kB. +Strings are trimmed to 6 kB. Panels are not erased between prints. @@ -43,13 +43,13 @@ If a string is prefixed with character code 255, it is treated as UTF-8 and pass The panels also respond to these control messages: -* "clear" turns all panels in a lineup or wall off - essentially a "clear screen" command. -* "allon" fills all panels in a lineup/wall with char(144), i.e. the reverse of "clear". +* "clear" turns all panels in a lineup or wall off, or up to 2048 of them, anyway - essentially a "clear screen" command. +* "allon" fills all panels in a lineup/wall, up to a max of 2048 of 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. 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). * "stop_scroll" does just what it says - it stops the auto-scroll timer. -* "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.2s, 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. 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 characters to skip. * "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). Note that even if the message has been or is being scrolled, you'll get the original stored message. @@ -59,7 +59,7 @@ During a scroll event, the printed string is padded with spaces (one in auto mod If you need vertical scrolling, you will have to handle that yourself (since the size of a screen/wall is not hard-coded). -A byte value of 0 to 27 in a string will change colors (i.e. string.char(0 to 27) ). +To change colors, put a "/" followed by a digit or a letter from "A" to "R" (or "a" to "r") into your printed string. Digits 0 to 9 trigger colors 0 to 9 (obviously :-) ), while A/a through R/r set colors 10 to 27. Any other sequence is invalid and will just be printed literally. Two slashes "//" will translated to a single char(30) internally, and displayed as a single slash (doing it that way makes the code easier). Color values 0 to 11 are: @@ -71,9 +71,9 @@ Colors 24 - 27 are white, light grey, medium grey, and dim grey (or think of the The last color that was used is stored in the left-most/upper-left "master" panel's metadata, and defaults to red. It should persist across reboots. -A byte value of 28 in a string will act as a line feed (I would have used 10, but that's a color code :-P ) +char(10) will do its job as linefeed/newline. -A byte value of 29 in a string signals a cursor position command. The next two byte values select a column and row, respectively. The next character after the row byte will be printed there, and the rest of the string then continues printing from that spot onward with normal line wrapping, colors and so forth. Note that any string that does NOT contain cursor positioning commands will automatically start printing at the upper-left. +char(29) signals a cursor position command. The next two byte values select a column and row, respectively. The next character after the row byte will be printed there, and the rest of the string then continues printing from that spot onward with normal line wrapping, colors and so forth. Note that any string that does NOT contain cursor positioning commands will automatically start printing at the upper-left. Any number of color, line feed, and cursor position commands may be present in a string, making it possible to "frame-buffer" a screen full of text into a string before printing it. diff --git a/led_marquee/init.lua b/led_marquee/init.lua index 5bfc1e0..cb52e66 100644 --- a/led_marquee/init.lua +++ b/led_marquee/init.lua @@ -10,6 +10,89 @@ else S = function(s) return s end end +local color_to_char = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "A", + "B", + "C", + "D", + "E", + "F", + "G", + "H", + "I", + "J", + "K", + "L", + "M", + "N", + "O", + "P", + "Q", + "R" +} + +local char_to_color = { + ["0"] = 0, + ["1"] = 1, + ["2"] = 2, + ["3"] = 3, + ["4"] = 4, + ["5"] = 5, + ["6"] = 6, + ["7"] = 7, + ["8"] = 8, + ["9"] = 9, + + ["A"] = 10, + ["B"] = 11, + ["C"] = 12, + ["D"] = 13, + ["E"] = 14, + ["F"] = 15, + ["G"] = 16, + ["H"] = 17, + ["I"] = 18, + ["J"] = 19, + ["K"] = 20, + ["L"] = 21, + ["M"] = 22, + ["N"] = 23, + ["O"] = 24, + ["P"] = 25, + ["Q"] = 26, + ["R"] = 27, + + ["a"] = 10, + ["b"] = 11, + ["c"] = 12, + ["d"] = 13, + ["e"] = 14, + ["f"] = 15, + ["g"] = 16, + ["h"] = 17, + ["i"] = 18, + ["j"] = 19, + ["k"] = 20, + ["l"] = 21, + ["m"] = 22, + ["n"] = 23, + ["o"] = 24, + ["p"] = 25, + ["q"] = 26, + ["r"] = 27 + +} + -- the following functions based on the so-named ones in Jeija's digilines mod local reset_meta = function(pos) @@ -60,43 +143,51 @@ end led_marquee.set_timer = function(pos, timeout) local timer = minetest.get_node_timer(pos) timer:stop() + if not timeout or timeout < 0.2 or timeout > 5 then return false end + if timeout > 0 then local meta = minetest.get_meta(pos) + meta:set_int("timeout", timeout) timer:start(timeout) end end led_marquee.scroll_text = function(pos, elapsed, skip) + skip = skip or 1 local meta = minetest.get_meta(pos) local msg = meta:get_string("last_msg") local channel = meta:get_string("channel") local index = meta:get_int("index") - if not index or index < 1 or not string.byte(msg, index) then index = 1 end + local color = meta:get_int("last_color") + local colorchar = color_to_char[color+1] + if not index or index < 1 then index = 1 end local len = string.len(msg) - skip = skip or 1 - index = index + skip + if index > len then index = 1 end - while index < len and string.byte(msg, index) < 28 do - index = index + 1 - if index > len then index = 1 break end + -- search backward to find the most recent color code in the string + local r = index + while r > 0 and not string.match(string.sub(msg, r, r+1), "/[0-9A-Ra-r]") do + r = r - 1 + end + if r == 0 then r = 1 end + if string.match(string.sub(msg, r, r+1), "/[0-9A-Ra-r]") then + colorchar = string.sub(msg, r+1, r+1) end - if string.byte(msg, index - 1) < 28 then - led_marquee.display_msg(pos, channel, string.sub(msg, index - 1)..string.rep(" ", skip + 1)) - else - local i = index - 1 - local color = "" - while i > 0 and string.byte(msg, i) > 27 do - i = i - 1 - if i == 0 then break end + -- search forward to find the next printable symbol after the current index + local f = index + while f < len do + if string.match(string.sub(msg, f-1, f), "/[0-9A-Ra-r]") then + f = f + 2 + else + break end - if i > 0 then color = string.sub(msg, i, i) end - led_marquee.display_msg(pos, channel, color..string.sub(msg, index)..string.rep(" ", skip + 1)) end + led_marquee.display_msg(pos, channel, "/"..colorchar..string.sub(msg, f)..string.rep(" ", skip + 1)) - meta:set_int("index", index) - if not elapsed or elapsed < 0.5 then return false end + meta:set_int("index", f) + if not elapsed or elapsed < 0.2 then return false end return true end @@ -118,10 +209,14 @@ local cbox = { wall_side = { -8/16, -8/16, -8/16, -7/16, 8/16, 8/16 } } +led_marquee.decode_color = function(msg) + +end + led_marquee.display_msg = function(pos, channel, msg) - msg = string.sub(msg, 1, 4096) + msg = string.sub(msg, 1, 6144).." " if string.sub(msg,1,1) == string.char(255) then -- treat it as incoming UTF-8 - msg = make_iso(string.sub(msg, 2, 4096)) + msg = make_iso(string.sub(msg, 2, 6144)) end local master_fdir = minetest.get_node(pos).param2 % 8 @@ -154,7 +249,7 @@ led_marquee.display_msg = function(pos, channel, msg) elseif string.match(node.name, "led_marquee:char_") and fdir ~= master_fdir or (setchan ~= nil and setchan ~= "" and setchan ~= channel) then break - elseif asc == 28 then + elseif asc == 10 then pos2.x = pos.x pos2.y = pos2.y-1 pos2.z = pos.z @@ -168,17 +263,34 @@ led_marquee.display_msg = function(pos, channel, msg) pos2.z = pos.z + (fdir_to_right[fdir+1][2])*c i = i + 3 wrapped = nil + elseif asc == 30 then -- translate to slash for printing + minetest.swap_node(pos2, { name = "led_marquee:char_47", param2 = master_fdir + (last_color*8)}) + pos2.x = pos2.x + fdir_to_right[fdir+1][1] + pos2.z = pos2.z + fdir_to_right[fdir+1][2] + i = i + 1 + elseif asc == 47 then -- slash + local ccode = string.sub(msg, i+1, i+1) + if ccode then + if char_to_color[ccode] then + last_color = char_to_color[ccode] + i = i + 2 + else + minetest.swap_node(pos2, { name = "led_marquee:char_47", param2 = master_fdir + (last_color*8)}) + pos2.x = pos2.x + fdir_to_right[fdir+1][1] + pos2.z = pos2.z + fdir_to_right[fdir+1][2] + i = i + 1 + end + end + master_meta:set_int("last_color", last_color) + wrapped = nil elseif asc > 30 and asc < 256 then minetest.swap_node(pos2, { name = "led_marquee:char_"..asc, param2 = master_fdir + (last_color*8)}) pos2.x = pos2.x + fdir_to_right[fdir+1][1] pos2.z = pos2.z + fdir_to_right[fdir+1][2] i = i + 1 wrapped = nil - elseif asc < 28 then - last_color = asc - master_meta:set_int("last_color", asc) + else i = i + 1 - wrapped = nil end end end @@ -210,15 +322,12 @@ local on_digiline_receive_string = function(pos, node, channel, msg) meta:set_int("index", 1) elseif msg == "start_scroll" then local timeout = meta:get_int("timeout") - if not timeout or timeout < 0.5 or timeout > 5 then timeout = 0 end led_marquee.set_timer(pos, timeout) elseif msg == "stop_scroll" then led_marquee.set_timer(pos, 0) return elseif string.sub(msg, 1, 12) == "scroll_speed" then local timeout = tonumber(string.sub(msg, 13)) - if not timeout or timeout < 0.5 or timeout > 5 then timeout = 0 end - meta:set_int("timeout", timeout) led_marquee.set_timer(pos, timeout) elseif string.sub(msg, 1, 11) == "scroll_step" then local skip = tonumber(string.sub(msg, 12)) @@ -230,20 +339,21 @@ local on_digiline_receive_string = function(pos, node, channel, msg) elseif msg == "getindex" then -- get the scroll index digilines.receptor_send(pos, digiline.rules.default, channel, meta:get_int("index")) else + msg = string.gsub(msg, "//", string.char(30)) led_marquee.set_timer(pos, 0) + local last_msg = meta:get_string("last_msg") meta:set_string("last_msg", msg) led_marquee.display_msg(pos, channel, msg) - meta:set_int("index", 1) + if last_msg ~= msg then + meta:set_int("index", 1) + end end else local asc = string.byte(msg) - if asc > 30 and asc < 256 then + if asc > 29 and asc < 256 then minetest.swap_node(pos, { name = "led_marquee:char_"..asc, param2 = fdir + (last_color*8)}) meta:set_string("last_msg", tostring(msg)) meta:set_int("index", 1) - elseif asc < 28 then - last_color = asc - meta:set_int("last_color", asc) end end elseif msg and type(msg) == "number" then @@ -258,7 +368,7 @@ end for i = 31, 255 do local groups = { cracky = 2, not_in_creative_inventory = 1} local light = LIGHT_MAX-2 - local description = S("Alphanumeric LED marquee panel ("..i..")") + local description = S("LED marquee panel ("..i..")") local tiles = { { name="led_marquee_base.png", color="white"}, { name="led_marquee_leds_off.png", color="white"}, @@ -279,7 +389,8 @@ for i = 31, 255 do if i == 32 then groups = {cracky = 2} light = nil - description = S("Alphanumeric LED marquee panel") + description = S("LED marquee panel") + wimage = "led_marquee_leds_off.png^(led_marquee_char_155.png^[multiply:red)" end minetest.register_node("led_marquee:char_"..i, { @@ -287,6 +398,8 @@ for i = 31, 255 do drawtype = "mesh", mesh = "led_marquee.obj", tiles = tiles, + inventory_image = wimage, + wield_image = wimage, palette="led_marquee_palette.png", use_texture_alpha = true, groups = groups, diff --git a/led_marquee/textures/led_marquee_char_107.png b/led_marquee/textures/led_marquee_char_107.png Binary files differindex 364a43d..47d7c60 100644 --- a/led_marquee/textures/led_marquee_char_107.png +++ b/led_marquee/textures/led_marquee_char_107.png diff --git a/led_marquee/textures/led_marquee_char_121.png b/led_marquee/textures/led_marquee_char_121.png Binary files differindex 29382c9..454818f 100644 --- a/led_marquee/textures/led_marquee_char_121.png +++ b/led_marquee/textures/led_marquee_char_121.png diff --git a/led_marquee/textures/led_marquee_char_143.png b/led_marquee/textures/led_marquee_char_143.png Binary files differindex 4b58ec9..6293a97 100644 --- a/led_marquee/textures/led_marquee_char_143.png +++ b/led_marquee/textures/led_marquee_char_143.png diff --git a/led_marquee/textures/led_marquee_char_144.png b/led_marquee/textures/led_marquee_char_144.png Binary files differindex 995a284..fda87a1 100644 --- a/led_marquee/textures/led_marquee_char_144.png +++ b/led_marquee/textures/led_marquee_char_144.png diff --git a/led_marquee/textures/led_marquee_char_194.png b/led_marquee/textures/led_marquee_char_194.png Binary files differindex e8429f7..7401be4 100644 --- a/led_marquee/textures/led_marquee_char_194.png +++ b/led_marquee/textures/led_marquee_char_194.png diff --git a/led_marquee/textures/led_marquee_char_197.png b/led_marquee/textures/led_marquee_char_197.png Binary files differindex 8c13e35..4445568 100644 --- a/led_marquee/textures/led_marquee_char_197.png +++ b/led_marquee/textures/led_marquee_char_197.png diff --git a/led_marquee/textures/led_marquee_char_202.png b/led_marquee/textures/led_marquee_char_202.png Binary files differindex b069c41..e65878a 100644 --- a/led_marquee/textures/led_marquee_char_202.png +++ b/led_marquee/textures/led_marquee_char_202.png diff --git a/led_marquee/textures/led_marquee_char_206.png b/led_marquee/textures/led_marquee_char_206.png Binary files differindex 8b324d9..0a00f82 100644 --- a/led_marquee/textures/led_marquee_char_206.png +++ b/led_marquee/textures/led_marquee_char_206.png diff --git a/led_marquee/textures/led_marquee_char_212.png b/led_marquee/textures/led_marquee_char_212.png Binary files differindex cae030a..b748c3e 100644 --- a/led_marquee/textures/led_marquee_char_212.png +++ b/led_marquee/textures/led_marquee_char_212.png diff --git a/led_marquee/textures/led_marquee_char_216.png b/led_marquee/textures/led_marquee_char_216.png Binary files differindex b131232..5dfa7da 100644 --- a/led_marquee/textures/led_marquee_char_216.png +++ b/led_marquee/textures/led_marquee_char_216.png diff --git a/led_marquee/textures/led_marquee_char_219.png b/led_marquee/textures/led_marquee_char_219.png Binary files differindex 5d978b5..cbd4474 100644 --- a/led_marquee/textures/led_marquee_char_219.png +++ b/led_marquee/textures/led_marquee_char_219.png diff --git a/led_marquee/textures/led_marquee_char_221.png b/led_marquee/textures/led_marquee_char_221.png Binary files differindex 3350367..5aecca9 100644 --- a/led_marquee/textures/led_marquee_char_221.png +++ b/led_marquee/textures/led_marquee_char_221.png diff --git a/led_marquee/textures/led_marquee_char_226.png b/led_marquee/textures/led_marquee_char_226.png Binary files differindex aee1188..9a41d88 100644 --- a/led_marquee/textures/led_marquee_char_226.png +++ b/led_marquee/textures/led_marquee_char_226.png diff --git a/led_marquee/textures/led_marquee_char_234.png b/led_marquee/textures/led_marquee_char_234.png Binary files differindex 7349dde..bad0987 100644 --- a/led_marquee/textures/led_marquee_char_234.png +++ b/led_marquee/textures/led_marquee_char_234.png diff --git a/led_marquee/textures/led_marquee_char_238.png b/led_marquee/textures/led_marquee_char_238.png Binary files differindex c63a1d3..9679927 100644 --- a/led_marquee/textures/led_marquee_char_238.png +++ b/led_marquee/textures/led_marquee_char_238.png diff --git a/led_marquee/textures/led_marquee_char_244.png b/led_marquee/textures/led_marquee_char_244.png Binary files differindex 47e4dfd..027c715 100644 --- a/led_marquee/textures/led_marquee_char_244.png +++ b/led_marquee/textures/led_marquee_char_244.png diff --git a/led_marquee/textures/led_marquee_char_251.png b/led_marquee/textures/led_marquee_char_251.png Binary files differindex 63134a0..9fe4cb3 100644 --- a/led_marquee/textures/led_marquee_char_251.png +++ b/led_marquee/textures/led_marquee_char_251.png diff --git a/led_marquee/textures/led_marquee_char_253.png b/led_marquee/textures/led_marquee_char_253.png Binary files differindex a3111a3..6282658 100644 --- a/led_marquee/textures/led_marquee_char_253.png +++ b/led_marquee/textures/led_marquee_char_253.png diff --git a/led_marquee/textures/led_marquee_char_255.png b/led_marquee/textures/led_marquee_char_255.png Binary files differindex 9855706..58a756c 100644 --- a/led_marquee/textures/led_marquee_char_255.png +++ b/led_marquee/textures/led_marquee_char_255.png diff --git a/led_marquee/textures/led_marquee_char_76.png b/led_marquee/textures/led_marquee_char_76.png Binary files differindex 36afd27..7809c03 100644 --- a/led_marquee/textures/led_marquee_char_76.png +++ b/led_marquee/textures/led_marquee_char_76.png |