forked from minetest-mods/digilines
Compare commits
10 Commits
nalc-1.2.0
...
dd8432ef34
Author | SHA1 | Date | |
---|---|---|---|
dd8432ef34 | |||
af4a699e19 | |||
c3f1b4ef41 | |||
ff525c09a4 | |||
45991bf124 | |||
dc6cc0b04a | |||
4e6b34da34 | |||
ab2eb4af43 | |||
2800b237c5 | |||
021c521c65 |
11
.github/workflows/build.yml
vendored
Normal file
11
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
on: [push, pull_request]
|
||||||
|
name: build
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
- name: lint
|
||||||
|
uses: Roang-zero1/factorio-mod-luacheck@master
|
||||||
|
with:
|
||||||
|
luacheckrc_url: ""
|
@ -7,6 +7,7 @@ read_globals = {
|
|||||||
"pipeworks",
|
"pipeworks",
|
||||||
"dump",
|
"dump",
|
||||||
"VoxelArea",
|
"VoxelArea",
|
||||||
|
"ItemStack",
|
||||||
}
|
}
|
||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
Digilines
|
Digilines
|
||||||
==========
|
==========
|
||||||
- The minetest counterpart for bus systems like i2c, SPI, RS232, USB -
|
|
||||||
|
|
||||||
|
[](https://github.com/minetest-mods/digilines/actions)
|
||||||
|
|
||||||
|
- The minetest counterpart for bus systems like i2c, SPI, RS232, USB -
|
||||||
|
- Minetest 5.0.0+ is required to use this mod.
|
||||||
|
|
||||||
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
|
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
|
||||||
Can be used together with the luacontroller from mesecons. See the luacontroller manual for more information.
|
Can be used together with the luacontroller from mesecons. See the luacontroller manual for more information.
|
||||||
|
@ -1 +0,0 @@
|
|||||||
default
|
|
@ -1 +0,0 @@
|
|||||||
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen. Can be used together with the luacontroller from mesecons.
|
|
@ -112,9 +112,9 @@ function digilines.transmit(pos, channel, msg, checked)
|
|||||||
for _, rule in ipairs(rules) do
|
for _, rule in ipairs(rules) do
|
||||||
local nextPos = digilines.addPosRule(curPos, rule)
|
local nextPos = digilines.addPosRule(curPos, rule)
|
||||||
if digilines.rules_link(curPos, nextPos) then
|
if digilines.rules_link(curPos, nextPos) then
|
||||||
local checkedID = minetest.hash_node_position(nextPos)
|
local checkedID2 = minetest.hash_node_position(nextPos)
|
||||||
if not checked[checkedID] then
|
if not checked[checkedID2] then
|
||||||
checked[checkedID] = true
|
checked[checkedID2] = true
|
||||||
queue_enqueue(queue, nextPos)
|
queue_enqueue(queue, nextPos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -97,7 +97,7 @@ minetest.register_node("digilines:chest", {
|
|||||||
minetest.get_meta(pos):set_string("channel",fields.channel)
|
minetest.get_meta(pos):set_string("channel",fields.channel)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
digiline = {
|
digilines = {
|
||||||
receptor = {},
|
receptor = {},
|
||||||
effector = {
|
effector = {
|
||||||
action = function() end
|
action = function() end
|
||||||
@ -229,7 +229,7 @@ minetest.register_node("digilines:chest", {
|
|||||||
last_inventory_take_index = index
|
last_inventory_take_index = index
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
on_metadata_inventory_move = function(pos, _, from_index, _, to_index, count, player)
|
||||||
-- See what would happen if we were to move the items back from in the
|
-- See what would happen if we were to move the items back from in the
|
||||||
-- opposite direction. In the event of a normal move, this must
|
-- opposite direction. In the event of a normal move, this must
|
||||||
-- succeed, because a normal move subtracts some items from the from
|
-- succeed, because a normal move subtracts some items from the from
|
||||||
|
115
lcd.lua
115
lcd.lua
@ -5,7 +5,6 @@
|
|||||||
-- load characters map
|
-- load characters map
|
||||||
local chars_file = io.open(minetest.get_modpath("digilines").."/characters", "r")
|
local chars_file = io.open(minetest.get_modpath("digilines").."/characters", "r")
|
||||||
local charmap = {}
|
local charmap = {}
|
||||||
local max_chars = 12
|
|
||||||
if not chars_file then
|
if not chars_file then
|
||||||
print("[digilines] E: LCD: character map file not found")
|
print("[digilines] E: LCD: character map file not found")
|
||||||
else
|
else
|
||||||
@ -21,7 +20,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- CONSTANTS
|
-- CONSTANTS
|
||||||
local LCD_WITH = 100
|
local LCD_WIDTH = 100
|
||||||
local LCD_PADDING = 8
|
local LCD_PADDING = 8
|
||||||
|
|
||||||
local LINE_LENGTH = 12
|
local LINE_LENGTH = 12
|
||||||
@ -30,31 +29,95 @@ local NUMBER_OF_LINES = 5
|
|||||||
local LINE_HEIGHT = 14
|
local LINE_HEIGHT = 14
|
||||||
local CHAR_WIDTH = 5
|
local CHAR_WIDTH = 5
|
||||||
|
|
||||||
|
|
||||||
|
assert((CHAR_WIDTH+1) * LINE_LENGTH <= LCD_WIDTH - LCD_PADDING*2, "LCD: Lines set too long!")
|
||||||
|
assert((LINE_HEIGHT+1) * NUMBER_OF_LINES <= LCD_WIDTH - LCD_PADDING*2, "LCD: Too many lines!")
|
||||||
|
|
||||||
|
|
||||||
|
local split = function(s, pat)
|
||||||
|
-- adapted from https://stackoverflow.com/a/1647577/4067384
|
||||||
|
-- simplified for our only usecase
|
||||||
|
local st, g = 1, s:gmatch("()("..pat..")")
|
||||||
|
local function getter()
|
||||||
|
if st then
|
||||||
|
local segs, seps, sep = st, g()
|
||||||
|
st = sep and seps + #sep
|
||||||
|
return s:sub(segs, (seps or 0) - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return getter
|
||||||
|
end
|
||||||
|
|
||||||
local create_lines = function(text)
|
local create_lines = function(text)
|
||||||
|
--[[
|
||||||
|
Typeset the lines according to these rules (in order of subjective significance):
|
||||||
|
- words that fit on the screen but would let the current line overflow are placed on a new line instead
|
||||||
|
- " | " always forces a linebreak
|
||||||
|
- spaces are included, except when there is a linebreak anyway
|
||||||
|
- words with more characters than fit on screen are just chopped up, filling the lines as full as possible
|
||||||
|
- don't bother typesetting more lines than fit on screen
|
||||||
|
- if we are on the last line that will fit on screen
|
||||||
|
]]--
|
||||||
local line = ""
|
local line = ""
|
||||||
local line_num = 1
|
local line_num = 1
|
||||||
local tab = {}
|
local tab = {}
|
||||||
for word in string.gmatch(text, "%S+") do
|
local flush_line_and_check_for_return = function()
|
||||||
if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then
|
table.insert(tab, line)
|
||||||
if line ~= "" then
|
line_num = line_num+1
|
||||||
|
if line_num > NUMBER_OF_LINES then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
line = ""
|
||||||
|
end
|
||||||
|
for par in split(text, " | ") do
|
||||||
|
for word in split(par, "%s") do
|
||||||
|
if string.len(word) <= LINE_LENGTH and line_num < NUMBER_OF_LINES then
|
||||||
|
local line_len = string.len(line)
|
||||||
|
if line_len > 0 then
|
||||||
|
-- remember the space
|
||||||
|
line_len = line_len + 1
|
||||||
|
end
|
||||||
|
if line_len + string.len(word) <= LINE_LENGTH then
|
||||||
|
if line_len > 0 then
|
||||||
line = line.." "..word
|
line = line.." "..word
|
||||||
else
|
else
|
||||||
line = word
|
line = word
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(tab, line)
|
-- don't add the space since we have a line break
|
||||||
if word ~= "|" then
|
if word ~= " " then
|
||||||
|
if line_len > 0 then
|
||||||
|
-- ok, we need the new line
|
||||||
|
if flush_line_and_check_for_return() then return tab end
|
||||||
|
end
|
||||||
line = word
|
line = word
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
-- chop up word to make it fit
|
||||||
|
local remaining
|
||||||
|
while true do
|
||||||
|
remaining = LINE_LENGTH - string.len(line)
|
||||||
|
if remaining < LINE_LENGTH then
|
||||||
|
line = line .. " "
|
||||||
|
remaining = remaining - 1
|
||||||
|
end
|
||||||
|
if remaining < string.len(word) then
|
||||||
|
line = line .. string.sub(word, 1, remaining)
|
||||||
|
word = string.sub(word, remaining+1)
|
||||||
|
if flush_line_and_check_for_return() then return tab end
|
||||||
|
else
|
||||||
|
-- used up the word
|
||||||
|
line = line .. word
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- end of paragraph
|
||||||
|
if flush_line_and_check_for_return() then return tab end
|
||||||
line = ""
|
line = ""
|
||||||
end
|
end
|
||||||
line_num = line_num+1
|
|
||||||
if line_num > NUMBER_OF_LINES then
|
|
||||||
return tab
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.insert(tab, line)
|
|
||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,7 +126,7 @@ local generate_line = function(s, ypos)
|
|||||||
local parsed = {}
|
local parsed = {}
|
||||||
local width = 0
|
local width = 0
|
||||||
local chars = 0
|
local chars = 0
|
||||||
while chars < max_chars and i <= #s do
|
while chars < LINE_LENGTH and i <= #s do
|
||||||
local file = nil
|
local file = nil
|
||||||
if charmap[s:sub(i, i)] ~= nil then
|
if charmap[s:sub(i, i)] ~= nil then
|
||||||
file = charmap[s:sub(i, i)]
|
file = charmap[s:sub(i, i)]
|
||||||
@ -73,10 +136,13 @@ local generate_line = function(s, ypos)
|
|||||||
i = i + 2
|
i = i + 2
|
||||||
else
|
else
|
||||||
print("[digilines] W: LCD: unknown symbol in '"..s.."' at "..i)
|
print("[digilines] W: LCD: unknown symbol in '"..s.."' at "..i)
|
||||||
|
if charmap[" "] ~= nil then
|
||||||
|
file = charmap[" "]
|
||||||
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
width = width + CHAR_WIDTH
|
width = width + CHAR_WIDTH + 1
|
||||||
table.insert(parsed, file)
|
table.insert(parsed, file)
|
||||||
chars = chars + 1
|
chars = chars + 1
|
||||||
end
|
end
|
||||||
@ -84,7 +150,7 @@ local generate_line = function(s, ypos)
|
|||||||
width = width - 1
|
width = width - 1
|
||||||
|
|
||||||
local texture = ""
|
local texture = ""
|
||||||
local xpos = math.floor((LCD_WITH - 2 * LCD_PADDING - width) / 2 + LCD_PADDING)
|
local xpos = math.floor((LCD_WIDTH - width) / 2)
|
||||||
for ii = 1, #parsed do
|
for ii = 1, #parsed do
|
||||||
texture = texture..":"..xpos..","..ypos.."="..parsed[ii]..".png"
|
texture = texture..":"..xpos..","..ypos.."="..parsed[ii]..".png"
|
||||||
xpos = xpos + CHAR_WIDTH + 1
|
xpos = xpos + CHAR_WIDTH + 1
|
||||||
@ -93,8 +159,8 @@ local generate_line = function(s, ypos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local generate_texture = function(lines)
|
local generate_texture = function(lines)
|
||||||
local texture = "[combine:"..LCD_WITH.."x"..LCD_WITH
|
local texture = "[combine:"..LCD_WIDTH.."x"..LCD_WIDTH
|
||||||
local ypos = 16
|
local ypos = math.floor((LCD_WIDTH - LINE_HEIGHT*NUMBER_OF_LINES) / 2)
|
||||||
for i = 1, #lines do
|
for i = 1, #lines do
|
||||||
texture = texture..generate_line(lines[i], ypos)
|
texture = texture..generate_line(lines[i], ypos)
|
||||||
ypos = ypos + LINE_HEIGHT
|
ypos = ypos + LINE_HEIGHT
|
||||||
@ -225,12 +291,12 @@ minetest.register_node("digilines:lcd", {
|
|||||||
end,
|
end,
|
||||||
on_construct = reset_meta,
|
on_construct = reset_meta,
|
||||||
on_destruct = clearscreen,
|
on_destruct = clearscreen,
|
||||||
on_punch = function(pos, node, puncher, pointed_thing)
|
on_punch = function(pos, _, puncher, _)
|
||||||
if minetest.is_player(puncher) then
|
if minetest.is_player(puncher) then
|
||||||
spawn_entity(pos)
|
spawn_entity(pos)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, _, _, mode, new_param2)
|
||||||
if mode ~= screwdriver.ROTATE_FACE then
|
if mode ~= screwdriver.ROTATE_FACE then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -246,7 +312,7 @@ minetest.register_node("digilines:lcd", {
|
|||||||
minetest.get_meta(pos):set_string("channel", fields.channel)
|
minetest.get_meta(pos):set_string("channel", fields.channel)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
digiline = {
|
digilines = {
|
||||||
receptor = {},
|
receptor = {},
|
||||||
effector = {
|
effector = {
|
||||||
action = on_digiline_receive
|
action = on_digiline_receive
|
||||||
@ -273,7 +339,10 @@ minetest.register_craft({
|
|||||||
output = "digilines:lcd 2",
|
output = "digilines:lcd 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"default:steel_ingot", "digilines:wire_std_00000000", "default:steel_ingot"},
|
{"default:steel_ingot", "digilines:wire_std_00000000", "default:steel_ingot"},
|
||||||
{"mesecons_lightstone:lightstone_green_off","mesecons_lightstone:lightstone_green_off","mesecons_lightstone:lightstone_green_off"},
|
{"mesecons_lightstone:lightstone_green_off",
|
||||||
|
"mesecons_lightstone:lightstone_green_off",
|
||||||
|
"mesecons_lightstone:lightstone_green_off"},
|
||||||
|
|
||||||
{"default:glass","default:glass","default:glass"}
|
{"default:glass","default:glass","default:glass"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -39,7 +39,7 @@ minetest.register_node("digilines:lightsensor", {
|
|||||||
groups = {dig_immediate=2},
|
groups = {dig_immediate=2},
|
||||||
selection_box = lsensor_selbox,
|
selection_box = lsensor_selbox,
|
||||||
node_box = lsensor_nodebox,
|
node_box = lsensor_nodebox,
|
||||||
digiline =
|
digilines =
|
||||||
{
|
{
|
||||||
receptor = {},
|
receptor = {},
|
||||||
effector = {
|
effector = {
|
||||||
|
5
mod.conf
5
mod.conf
@ -1 +1,6 @@
|
|||||||
name = digilines
|
name = digilines
|
||||||
|
depends = default
|
||||||
|
description = """
|
||||||
|
This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen.
|
||||||
|
Can be used together with the luacontroller from mesecons.
|
||||||
|
"""
|
||||||
|
2
rtc.lua
2
rtc.lua
@ -35,7 +35,7 @@ minetest.register_node("digilines:rtc", {
|
|||||||
groups = {dig_immediate=2},
|
groups = {dig_immediate=2},
|
||||||
selection_box = rtc_selbox,
|
selection_box = rtc_selbox,
|
||||||
node_box = rtc_nodebox,
|
node_box = rtc_nodebox,
|
||||||
digiline =
|
digilines =
|
||||||
{
|
{
|
||||||
receptor = {},
|
receptor = {},
|
||||||
effector = {
|
effector = {
|
||||||
|
@ -90,7 +90,7 @@ for zmy=0, 1 do
|
|||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
digiline =
|
digilines =
|
||||||
{
|
{
|
||||||
wire =
|
wire =
|
||||||
{
|
{
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
minetest.register_on_placenode(function(pos, node)
|
|
||||||
if minetest.registered_nodes[node.name].digiline then
|
|
||||||
digilines.update_autoconnect(pos)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_dignode(function(pos, node)
|
local function check_and_update(pos, node)
|
||||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then
|
if digilines.getspec(node) then
|
||||||
-- need to make sure that node exists (unknown nodes!)
|
|
||||||
digilines.update_autoconnect(pos)
|
digilines.update_autoconnect(pos)
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
minetest.register_on_placenode(check_and_update)
|
||||||
|
minetest.register_on_dignode(check_and_update)
|
||||||
|
|
||||||
function digilines.update_autoconnect(pos, secondcall)
|
function digilines.update_autoconnect(pos, secondcall)
|
||||||
local xppos = {x=pos.x+1, y=pos.y, z=pos.z}
|
local xppos = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||||
@ -42,8 +39,7 @@ function digilines.update_autoconnect(pos, secondcall)
|
|||||||
digilines.update_autoconnect(zmympos, true)
|
digilines.update_autoconnect(zmympos, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
local digilinespec = digilines.getspec(minetest.get_node(pos))
|
||||||
local digilinespec = def and def.digiline
|
|
||||||
if not (digilinespec and digilinespec.wire and
|
if not (digilinespec and digilinespec.wire and
|
||||||
digilinespec.wire.use_autoconnect) then
|
digilinespec.wire.use_autoconnect) then
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user