Compare commits
28 Commits
2019-05-25
...
master
Author | SHA1 | Date | |
---|---|---|---|
3d00c81f55 | |||
7a8b53474d | |||
5fb766921f | |||
528d8b7a58 | |||
e389885f32 | |||
0f0f74a3e5 | |||
0cc8f9e7a4 | |||
0e3a251da5 | |||
4732886317 | |||
386a67bf05 | |||
52e4fe1b0b | |||
2bf2651cee | |||
aafa748f92 | |||
efb6d93204 | |||
39f571f788 | |||
c09527c029 | |||
0f31f4832c | |||
108f0dad1a | |||
023966f9c4 | |||
63de1f5ab5 | |||
79bc4755dd | |||
642aec419a | |||
caf6e24d04 | |||
b081594e2c | |||
31a938693a | |||
45c89704f0 | |||
8d3a0e92de | |||
db78e3dcdb |
10
.github/workflows/luacheck.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
name: luacheck
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: Roang-zero1/factorio-mod-luacheck@master
|
||||
with:
|
||||
luacheckrc_url: ""
|
11
.luacheckrc
Normal file
@ -0,0 +1,11 @@
|
||||
unused_args = false
|
||||
|
||||
read_globals = {
|
||||
table = {fields = {"copy"}},
|
||||
"minetest",
|
||||
"digilines"
|
||||
}
|
||||
|
||||
globals = {
|
||||
"led_marquee"
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
default
|
||||
digilines
|
||||
mesecons_luacontroller
|
||||
mesecons_microcontroller?
|
||||
mesecons_lamp?
|
@ -1 +0,0 @@
|
||||
This mod provides a simple LED marquee that accepts single characters, strings, and special control words via digilines.
|
97
init.lua
@ -2,13 +2,17 @@
|
||||
-- by Vanessa Dannenberg
|
||||
|
||||
led_marquee = {}
|
||||
led_marquee.scheduled_messages = {}
|
||||
|
||||
local S
|
||||
if minetest.get_modpath("intllib") then
|
||||
S = intllib.make_gettext_pair()
|
||||
else
|
||||
S = function(s) return s end
|
||||
end
|
||||
-- settings
|
||||
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 = minetest.get_translator(minetest.get_current_modname())
|
||||
local FS = function(...) return minetest.formspec_escape(S(...)) end
|
||||
|
||||
local color_to_char = {
|
||||
"0",
|
||||
@ -96,24 +100,15 @@ local char_to_color = {
|
||||
-- the following functions based on the so-named ones in Jeija's digilines mod
|
||||
|
||||
local reset_meta = function(pos)
|
||||
minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]")
|
||||
end
|
||||
|
||||
local on_digiline_receive_std = function(pos, node, channel, msg)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local setchan = meta:get_string("channel")
|
||||
if setchan ~= channel then return end
|
||||
local num = tonumber(msg)
|
||||
if msg == "colon" or msg == "period" or msg == "off" or (num and (num >= 0 and num <= 9)) then
|
||||
minetest.swap_node(pos, { name = "led_marquee:marquee_"..msg, param2 = node.param2})
|
||||
end
|
||||
minetest.get_meta(pos):set_string("formspec",
|
||||
"formspec_version[4]"..
|
||||
"size[8,4]"..
|
||||
"button_exit[3,2.5;2,0.5;proceed;"..FS("Proceed").."]"..
|
||||
"field[1.75,1.5;4.5,0.5;channel;"..FS("Channel")..";${channel}]"
|
||||
)
|
||||
end
|
||||
|
||||
-- convert Lua's idea of a UTF-8 char to ISO-8859-1
|
||||
|
||||
-- first char is non-break space, 0xA0
|
||||
local iso_chars=" ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
|
||||
|
||||
local get_iso = function(c)
|
||||
local hb = string.byte(c,1) or 0
|
||||
local lb = string.byte(c,2) or 0
|
||||
@ -128,7 +123,12 @@ local make_iso = function(s)
|
||||
local s2 = ""
|
||||
while i <= string.len(s) do
|
||||
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
|
||||
else
|
||||
s2 = s2..string.sub(s, i, i)
|
||||
@ -143,7 +143,7 @@ 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 not timeout or timeout < led_marquee.message_minimum_time or timeout > 5 then return false end
|
||||
|
||||
if timeout > 0 then
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -184,7 +184,7 @@ led_marquee.scroll_text = function(pos, elapsed, skip)
|
||||
break
|
||||
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)
|
||||
if not elapsed or elapsed < 0.2 then return false end
|
||||
@ -213,6 +213,27 @@ led_marquee.decode_color = function(msg)
|
||||
|
||||
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)
|
||||
msg = string.sub(msg, 1, 6144).." "
|
||||
if string.sub(msg,1,1) == string.char(255) then -- treat it as incoming UTF-8
|
||||
@ -312,13 +333,13 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
||||
led_marquee.set_timer(pos, 0)
|
||||
msg = string.rep(" ", 2048)
|
||||
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)
|
||||
elseif msg == "allon" then
|
||||
led_marquee.set_timer(pos, 0)
|
||||
msg = string.rep(string.char(144), 2048)
|
||||
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)
|
||||
elseif msg == "start_scroll" then
|
||||
local timeout = meta:get_int("timeout")
|
||||
@ -327,30 +348,31 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
||||
led_marquee.set_timer(pos, 0)
|
||||
return
|
||||
elseif string.sub(msg, 1, 12) == "scroll_speed" then
|
||||
local timeout = tonumber(string.sub(msg, 13))
|
||||
led_marquee.set_timer(pos, timeout)
|
||||
local timeout = tonumber(string.sub(msg, 13)) or 0
|
||||
led_marquee.set_timer(pos, math.max(timeout, led_marquee.message_minimum_time))
|
||||
elseif string.sub(msg, 1, 11) == "scroll_step" then
|
||||
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
|
||||
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, digilines.rules.default, channel,
|
||||
tonumber(string.match(minetest.get_node(pos).name,"led_marquee:char_(.+)")))
|
||||
elseif msg == "getstr" then -- get the last stored message
|
||||
digilines.receptor_send(pos, digiline.rules.default, channel, meta:get_string("last_msg"))
|
||||
digilines.receptor_send(pos, digilines.rules.default, channel, meta:get_string("last_msg"))
|
||||
elseif msg == "getindex" then -- get the scroll index
|
||||
digilines.receptor_send(pos, digiline.rules.default, channel, meta:get_int("index"))
|
||||
digilines.receptor_send(pos, digilines.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)
|
||||
led_marquee.schedule_msg(pos, channel, msg)
|
||||
if last_msg ~= msg then
|
||||
meta:set_int("index", 1)
|
||||
end
|
||||
end
|
||||
else
|
||||
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)})
|
||||
meta:set_string("last_msg", tostring(msg))
|
||||
meta:set_int("index", 1)
|
||||
@ -358,7 +380,7 @@ local on_digiline_receive_string = function(pos, node, channel, msg)
|
||||
end
|
||||
elseif msg and type(msg) == "number" then
|
||||
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)
|
||||
end
|
||||
end
|
||||
@ -367,8 +389,8 @@ end
|
||||
|
||||
for i = 31, 255 do
|
||||
local groups = { cracky = 2, not_in_creative_inventory = 1}
|
||||
local light = LIGHT_MAX-2
|
||||
local description = S("LED marquee panel ("..i..")")
|
||||
local light = minetest.LIGHT_MAX-2
|
||||
local description = S("LED marquee panel (@1)", i)
|
||||
local leds = "led_marquee_char_"..i..".png^[mask:led_marquee_leds_on.png"
|
||||
|
||||
if i == 31 then
|
||||
@ -397,9 +419,9 @@ for i = 31, 255 do
|
||||
},
|
||||
overlay_tiles = { "", leds },
|
||||
inventory_image = wimage,
|
||||
is_ground_content = false,
|
||||
wield_image = wimage,
|
||||
palette="led_marquee_palette.png",
|
||||
use_texture_alpha = true,
|
||||
groups = groups,
|
||||
paramtype = "light",
|
||||
paramtype2 = "colorwallmounted",
|
||||
@ -441,3 +463,4 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
minetest.log("action", "[led_marquee] loaded.")
|
||||
|
5
locale/led_marquee.de.tr
Normal file
@ -0,0 +1,5 @@
|
||||
# textdomain: led_marquee
|
||||
LED marquee panel (@1)=LED-Anzeigetafel (@1)
|
||||
LED marquee panel=LED-Anzeigetafel
|
||||
Proceed=Fortsetzen
|
||||
Channel=Kanal
|
5
locale/template.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# textdomain: led_marquee
|
||||
LED marquee panel (@1)=
|
||||
LED marquee panel=
|
||||
Proceed=
|
||||
Channel=
|
5
mod.conf
@ -1 +1,6 @@
|
||||
name = led_marquee
|
||||
title = LED marquee
|
||||
description = This mod provides a simple LED marquee that accepts single characters, strings, and special control words via digilines.
|
||||
depends = default, digilines
|
||||
optional_depends = mesecons_luacontroller, mesecons_microcontroller, mesecons_lamp
|
||||
min_minetest_version = 5.2.0
|
||||
|
Before Width: | Height: | Size: 649 KiB After Width: | Height: | Size: 649 KiB |
Before Width: | Height: | Size: 649 KiB |
8
settingtypes.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# Minimal marquee interval
|
||||
led_marquee_message_minimum_time (Minimal marquee interval) float 0.5
|
||||
|
||||
# Marquee globalstep update interval
|
||||
led_marquee_message_schedule_dtime (Marquee globalstep update interval) float 0.2
|
||||
|
||||
# Global message queue size
|
||||
led_marquee_message_schedule_size (Global message queue size) int 10
|
Before Width: | Height: | Size: 137 B After Width: | Height: | Size: 145 B |
Before Width: | Height: | Size: 165 B After Width: | Height: | Size: 135 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 115 B After Width: | Height: | Size: 83 B |