first working version

This commit is contained in:
OgelGames 2021-01-23 21:27:31 +11:00
parent 93660fc546
commit ad86fe1142
17 changed files with 324 additions and 0 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
files/

15
.luacheckrc Normal file

@ -0,0 +1,15 @@
globals = {
"digilines",
"digicontrol"
}
read_globals = {
"vector",
"screwdriver",
"minetest",
"default",
"pipeworks",
"dump",
"VoxelArea",
}

37
diode.lua Normal file

@ -0,0 +1,37 @@
minetest.register_node("digicontrol:diode", {
description = "Digilines Diode",
inventory_image = "digicontrol_diode.png",
tiles = {
"digicontrol_diode.png",
"digicontrol_bottom.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png",
"digicontrol_side.png",
"digicontrol_side.png"
},
drawtype = "nodebox",
node_box = digicontrol.node_box,
selection_box = digicontrol.selection_box,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = {digicontrol = 1, dig_immediate = 2},
digiline = {
semiconductor = {
rules = function(node)
return {
digicontrol.get_rule(1, node.param2)
}
end
},
wire = {
rules = function(node)
return {
digicontrol.get_rule(1, node.param2),
digicontrol.get_rule(3, node.param2)
}
end
}
}
})

46
filter.lua Normal file

@ -0,0 +1,46 @@
minetest.register_node("digicontrol:filter", {
description = "Digilines Filter",
inventory_image = "digicontrol_filter.png",
tiles = {
"digicontrol_filter.png",
"digicontrol_bottom.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png",
"digicontrol_side.png",
"digicontrol_side.png"
},
drawtype = "nodebox",
node_box = digicontrol.node_box,
selection_box = digicontrol.selection_box,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = {digicontrol = 1, dig_immediate = 2},
digiline = {
semiconductor = {
rules = function(node, pos, from, channel)
local setchannel = minetest.get_meta(pos):get_string("channel")
if channel ~= setchannel then return {} end
local side = digicontrol.get_side(pos, from, node.param2)
if side == 3 then
return {
digicontrol.get_rule(1, node.param2)
}
else
return {
digicontrol.get_rule(3, node.param2)
}
end
end
},
wire = {
rules = function(node)
return {
digicontrol.get_rule(1, node.param2),
digicontrol.get_rule(3, node.param2)
}
end
}
}
})

49
init.lua Normal file

@ -0,0 +1,49 @@
digicontrol = {}
digicontrol.selection_box = {
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 }
}
digicontrol.node_box = {
type = "fixed",
fixed = {
{ -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 },
{ -6/16, -7/16, -6/16, 6/16, -6/16, 6/16 }
},
}
local BASE_RULES = {
{x = 0, y = 0, z = 1}, -- Up (side 0)
{x = 1, y = 0, z = 0}, -- Right (side 1)
{x = 0, y = 0, z =-1}, -- Down (side 2)
{x =-1, y = 0, z = 0} -- Left (side 3)
}
digicontrol.all_rules = BASE_RULES
function digicontrol.get_rule(side, param2)
if param2 >= 4 then return nil end
return BASE_RULES[((side + param2) % 4) + 1]
end
function digicontrol.get_side(pos, from, param2)
if param2 >= 4 then return nil end
local dir = vector.subtract(from, pos)
local facedir = minetest.dir_to_facedir(dir)
return ((facedir - param2) + 4) % 4
end
local MP = minetest.get_modpath("digicontrol")
-- Overrides to digilines functions
dofile(MP.."/override.lua")
-- Nodes
dofile(MP.."/diode.lua")
dofile(MP.."/splitter.lua")
dofile(MP.."/trisplitter.lua")
dofile(MP.."/filter.lua")
--dofile(MP.."/limiter.lua")
--dofile(MP.."/router.lua")

5
mod.conf Normal file

@ -0,0 +1,5 @@
name = digicontrol
description = Adds nodes to control the flow of digiline messages
depends = default, digilines
optional_depends = digiline_routing
min_minetest_version = 5.0

81
override.lua Normal file

@ -0,0 +1,81 @@
-- Override digilines.transmit and digilines.receptor_send to add more functionality
-- Mostly copied from https://github.com/minetest-mods/digilines/blob/master/internal.lua
local function queue_new()
return {nextRead = 1, nextWrite = 1}
end
local function queue_empty(queue)
return queue.nextRead == queue.nextWrite
end
local function queue_enqueue(queue, object)
local nextWrite = queue.nextWrite
queue[nextWrite] = object
queue.nextWrite = nextWrite + 1
end
local function queue_dequeue(queue)
local nextRead = queue.nextRead
local object = queue[nextRead]
queue[nextRead] = nil
queue.nextRead = nextRead + 1
return object[1], object[2]
end
function digilines.transmit(pos, channel, msg, checked, origin)
local checkedID = minetest.hash_node_position(pos)
if checked[checkedID] or not origin then
return
end
checked[checkedID] = true
digilines.vm_begin()
local queue = queue_new()
queue_enqueue(queue, {pos, origin})
while not queue_empty(queue) do
local curPos, fromPos = queue_dequeue(queue)
local node = digilines.get_node_force(curPos)
local spec = digilines.getspec(node)
if spec then
-- Effector actions --> Receive
if spec.effector then
spec.effector.action(curPos, node, channel, msg, fromPos)
end
-- Cable actions --> Transmit
local rules
-- Custom semiconductor def for digicontrol nodes
if spec.semiconductor then
rules = spec.semiconductor.rules(node, curPos, fromPos, channel)
elseif spec.wire then
rules = digilines.importrules(spec.wire.rules, node)
end
if rules then
for _, rule in ipairs(rules) do
local nextPos = digilines.addPosRule(curPos, rule)
if digilines.rules_link(curPos, nextPos) then
checkedID = minetest.hash_node_position(nextPos)
if not checked[checkedID] then
checked[checkedID] = true
queue_enqueue(queue, {nextPos, curPos})
end
end
end
end
end
end
digilines.vm_end()
end
function digilines.receptor_send(pos, rules, channel, msg)
local checked = {}
checked[minetest.hash_node_position(pos)] = true -- exclude itself
for _,rule in ipairs(rules) do
if digilines.rules_link(pos, digilines.addPosRule(pos, rule)) then
digilines.transmit(digilines.addPosRule(pos, rule), channel, msg, checked, pos)
end
end
end

46
splitter.lua Normal file

@ -0,0 +1,46 @@
minetest.register_node("digicontrol:splitter", {
description = "Digilines Splitter",
inventory_image = "digicontrol_splitter.png",
tiles = {
"digicontrol_splitter.png",
"digicontrol_bottom.png",
"digicontrol_side.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png"
},
drawtype = "nodebox",
node_box = digicontrol.node_box,
selection_box = digicontrol.selection_box,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = {digicontrol = 1, dig_immediate = 2},
digiline = {
semiconductor = {
rules = function(node, pos, from)
local side = digicontrol.get_side(pos, from, node.param2)
if side == 3 then
return {
digicontrol.get_rule(0, node.param2),
digicontrol.get_rule(2, node.param2)
}
elseif side == 0 or side == 2 then
return {
digicontrol.get_rule(3, node.param2)
}
end
end
},
wire = {
rules = function(node)
return {
digicontrol.get_rule(0, node.param2),
digicontrol.get_rule(2, node.param2),
digicontrol.get_rule(3, node.param2)
}
end
}
}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

44
trisplitter.lua Normal file

@ -0,0 +1,44 @@
minetest.register_node("digicontrol:trisplitter", {
description = "Digilines Tri-Splitter",
inventory_image = "digicontrol_trisplitter.png",
tiles = {
"digicontrol_trisplitter.png",
"digicontrol_bottom.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png",
"digicontrol_side_port.png"
},
drawtype = "nodebox",
node_box = digicontrol.node_box,
selection_box = digicontrol.selection_box,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
groups = {digicontrol = 1, dig_immediate = 2},
digiline = {
semiconductor = {
rules = function(node, pos, from)
local side = digicontrol.get_side(pos, from, node.param2)
if side == 3 then
return {
digicontrol.get_rule(0, node.param2),
digicontrol.get_rule(1, node.param2),
digicontrol.get_rule(2, node.param2)
}
else
return {
digicontrol.get_rule(3, node.param2)
}
end
end
},
wire = {
rules = function(node)
if node.param2 >= 4 then return {} end
return digicontrol.all_rules
end
}
}
})