mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-12-05 02:33:49 +01:00
Rename global table to digilines
.
This also adds a backwards compat alias so other mods shouldn't break.
This commit is contained in:
parent
54b1b3fe91
commit
6a2fa5a3e4
12
init.lua
12
init.lua
@ -1,4 +1,8 @@
|
||||
digiline = {}
|
||||
|
||||
digilines = {}
|
||||
|
||||
-- Backwards compat.
|
||||
rawset(_G, "digiline", digilines)
|
||||
|
||||
local modpath = minetest.get_modpath("digilines")
|
||||
dofile(modpath .. "/presetrules.lua")
|
||||
@ -7,12 +11,12 @@ dofile(modpath .. "/internal.lua")
|
||||
dofile(modpath .. "/wires_common.lua")
|
||||
dofile(modpath .. "/wire_std.lua")
|
||||
|
||||
function digiline:receptor_send(pos, rules, channel, msg)
|
||||
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 digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then
|
||||
digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked)
|
||||
if digilines:rules_link(pos, digilines:addPosRule(pos, rule)) then
|
||||
digilines:transmit(digilines:addPosRule(pos, rule), channel, msg, checked)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
30
internal.lua
30
internal.lua
@ -1,15 +1,15 @@
|
||||
function digiline:getspec(node)
|
||||
function digilines:getspec(node)
|
||||
if not minetest.registered_nodes[node.name] then return false end
|
||||
return minetest.registered_nodes[node.name].digiline
|
||||
end
|
||||
|
||||
function digiline:importrules(spec, node)
|
||||
function digilines:importrules(spec, node)
|
||||
if type(spec) == 'function' then
|
||||
return spec(node)
|
||||
elseif spec then
|
||||
return spec
|
||||
else
|
||||
return digiline.rules.default
|
||||
return digilines.rules.default
|
||||
end
|
||||
end
|
||||
|
||||
@ -19,10 +19,10 @@ function digiline:getAnyInputRules(pos)
|
||||
if not spec then return end
|
||||
|
||||
if spec.wire then
|
||||
return digiline:importrules(spec.wire.rules, node)
|
||||
return digilines:importrules(spec.wire.rules, node)
|
||||
end
|
||||
if spec.effector then
|
||||
return digiline:importrules(spec.effector.rules, node)
|
||||
return digilines:importrules(spec.effector.rules, node)
|
||||
end
|
||||
end
|
||||
|
||||
@ -32,24 +32,24 @@ function digiline:getAnyOutputRules(pos)
|
||||
if not spec then return end
|
||||
|
||||
if spec.wire then
|
||||
return digiline:importrules(spec.wire.rules, node)
|
||||
return digilines:importrules(spec.wire.rules, node)
|
||||
end
|
||||
if spec.receptor then
|
||||
return digiline:importrules(spec.receptor.rules, node)
|
||||
return digilines:importrules(spec.receptor.rules, node)
|
||||
end
|
||||
end
|
||||
|
||||
function digiline:rules_link(output, input)
|
||||
local outputrules = digiline:getAnyOutputRules(output)
|
||||
local inputrules = digiline:getAnyInputRules (input)
|
||||
function digilines:rules_link(output, input)
|
||||
local outputrules = digilines:getAnyOutputRules(output)
|
||||
local inputrules = digilines:getAnyInputRules (input)
|
||||
|
||||
if not outputrules or not inputrules then return false end
|
||||
|
||||
|
||||
for _, orule in ipairs(outputrules) do
|
||||
if digiline:cmpPos(digiline:addPosRule(output, orule), input) then
|
||||
if digilines:cmpPos(digilines:addPosRule(output, orule), input) then
|
||||
for _, irule in ipairs(inputrules) do
|
||||
if digiline:cmpPos(digiline:addPosRule(input, irule), output) then
|
||||
if digilines:cmpPos(digilines:addPosRule(input, irule), output) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -58,9 +58,9 @@ function digiline:rules_link(output, input)
|
||||
return false
|
||||
end
|
||||
|
||||
function digiline:rules_link_anydir(output, input)
|
||||
return digiline:rules_link(output, input)
|
||||
or digiline:rules_link(input, output)
|
||||
function digilines:rules_link_anydir(output, input)
|
||||
return digilines:rules_link(output, input)
|
||||
or digilines:rules_link(input, output)
|
||||
end
|
||||
|
||||
local function queue_new()
|
||||
|
@ -2,7 +2,7 @@ local function sendMessage(pos, msg, channel)
|
||||
if channel == nil then
|
||||
channel = minetest.get_meta(pos):get_string("channel")
|
||||
end
|
||||
digiline:receptor_send(pos,digiline.rules.default,channel,msg)
|
||||
digilines:receptor_send(pos,digilines.rules.default,channel,msg)
|
||||
end
|
||||
|
||||
local function maybeString(stack)
|
||||
|
@ -25,7 +25,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
|
||||
local setchan = minetest.get_meta(pos):get_string("channel")
|
||||
if channel == setchan and msg == GET_COMMAND then
|
||||
local lightval = minetest.get_node_light(pos)
|
||||
digiline:receptor_send(pos, digiline.rules.default, channel, lightval)
|
||||
digilines:receptor_send(pos, digilines.rules.default, channel, lightval)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
digiline.rules = {}
|
||||
digilines.rules = {}
|
||||
|
||||
digiline.rules.default =
|
||||
digilines.rules.default =
|
||||
{{x=0, y=0, z=-1},
|
||||
{x=1, y=0, z=0},
|
||||
{x=-1, y=0, z=0},
|
||||
|
2
rtc.lua
2
rtc.lua
@ -20,7 +20,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
|
||||
local setchan = minetest.get_meta(pos):get_string("channel")
|
||||
if channel == setchan and msg == GET_COMMAND then
|
||||
local timeofday = minetest.get_timeofday()
|
||||
digiline:receptor_send(pos, digiline.rules.default, channel, timeofday)
|
||||
digilines:receptor_send(pos, digilines.rules.default, channel, timeofday)
|
||||
end
|
||||
end
|
||||
|
||||
|
16
util.lua
16
util.lua
@ -1,13 +1,13 @@
|
||||
function digiline:addPosRule(p, r)
|
||||
function digilines:addPosRule(p, r)
|
||||
return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
|
||||
end
|
||||
|
||||
function digiline:cmpPos(p1, p2)
|
||||
function digilines:cmpPos(p1, p2)
|
||||
return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z)
|
||||
end
|
||||
|
||||
--Rules rotation Functions:
|
||||
function digiline:rotate_rules_right(rules)
|
||||
function digilines:rotate_rules_right(rules)
|
||||
local nr={}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
@ -18,7 +18,7 @@ function digiline:rotate_rules_right(rules)
|
||||
return nr
|
||||
end
|
||||
|
||||
function digiline:rotate_rules_left(rules)
|
||||
function digilines:rotate_rules_left(rules)
|
||||
local nr={}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
@ -29,7 +29,7 @@ function digiline:rotate_rules_left(rules)
|
||||
return nr
|
||||
end
|
||||
|
||||
function digiline:rotate_rules_down(rules)
|
||||
function digilines:rotate_rules_down(rules)
|
||||
local nr={}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
@ -40,7 +40,7 @@ function digiline:rotate_rules_down(rules)
|
||||
return nr
|
||||
end
|
||||
|
||||
function digiline:rotate_rules_up(rules)
|
||||
function digilines:rotate_rules_up(rules)
|
||||
local nr={}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
@ -51,13 +51,13 @@ function digiline:rotate_rules_up(rules)
|
||||
return nr
|
||||
end
|
||||
|
||||
function digiline:tablecopy(table) -- deep table copy
|
||||
function digilines:tablecopy(table) -- deep table copy
|
||||
if type(table) ~= "table" then return table end -- no need to copy
|
||||
local newtable = {}
|
||||
|
||||
for idx, item in pairs(table) do
|
||||
if type(item) == "table" then
|
||||
newtable[idx] = digiline:tablecopy(item)
|
||||
newtable[idx] = digilines:tablecopy(item)
|
||||
else
|
||||
newtable[idx] = item
|
||||
end
|
||||
|
@ -1,17 +1,17 @@
|
||||
minetest.register_on_placenode(function(pos, node)
|
||||
if minetest.registered_nodes[node.name].digiline then
|
||||
digiline:update_autoconnect(pos)
|
||||
digilines:update_autoconnect(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos, node)
|
||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then
|
||||
-- need to make sure that node exists (unknown nodes!)
|
||||
digiline:update_autoconnect(pos)
|
||||
digilines:update_autoconnect(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
function digiline:update_autoconnect(pos, secondcall)
|
||||
function digilines:update_autoconnect(pos, secondcall)
|
||||
local xppos = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||
local zppos = {x=pos.x, y=pos.y, z=pos.z+1}
|
||||
local xmpos = {x=pos.x-1, y=pos.y, z=pos.z}
|
||||
@ -26,20 +26,20 @@ function digiline:update_autoconnect(pos, secondcall)
|
||||
local zmypos = {x=pos.x, y=pos.y+1, z=pos.z-1}
|
||||
|
||||
if secondcall == nil then
|
||||
digiline:update_autoconnect(xppos, true)
|
||||
digiline:update_autoconnect(zppos, true)
|
||||
digiline:update_autoconnect(xmpos, true)
|
||||
digiline:update_autoconnect(zmpos, true)
|
||||
digilines:update_autoconnect(xppos, true)
|
||||
digilines:update_autoconnect(zppos, true)
|
||||
digilines:update_autoconnect(xmpos, true)
|
||||
digilines:update_autoconnect(zmpos, true)
|
||||
|
||||
digiline:update_autoconnect(xpypos, true)
|
||||
digiline:update_autoconnect(zpypos, true)
|
||||
digiline:update_autoconnect(xmypos, true)
|
||||
digiline:update_autoconnect(zmypos, true)
|
||||
digilines:update_autoconnect(xpypos, true)
|
||||
digilines:update_autoconnect(zpypos, true)
|
||||
digilines:update_autoconnect(xmypos, true)
|
||||
digilines:update_autoconnect(zmypos, true)
|
||||
|
||||
digiline:update_autoconnect(xpympos, true)
|
||||
digiline:update_autoconnect(zpympos, true)
|
||||
digiline:update_autoconnect(xmympos, true)
|
||||
digiline:update_autoconnect(zmympos, true)
|
||||
digilines:update_autoconnect(xpympos, true)
|
||||
digilines:update_autoconnect(zpympos, true)
|
||||
digilines:update_autoconnect(xmympos, true)
|
||||
digilines:update_autoconnect(zmympos, true)
|
||||
end
|
||||
|
||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
@ -49,20 +49,20 @@ function digiline:update_autoconnect(pos, secondcall)
|
||||
return nil
|
||||
end
|
||||
|
||||
local zmg = digiline:rules_link_anydir(pos, zmpos)
|
||||
local zmymg = digiline:rules_link_anydir(pos, zmympos)
|
||||
local xmg = digiline:rules_link_anydir(pos, xmpos)
|
||||
local xmymg = digiline:rules_link_anydir(pos, xmympos)
|
||||
local zpg = digiline:rules_link_anydir(pos, zppos)
|
||||
local zpymg = digiline:rules_link_anydir(pos, zpympos)
|
||||
local xpg = digiline:rules_link_anydir(pos, xppos)
|
||||
local xpymg = digiline:rules_link_anydir(pos, xpympos)
|
||||
local zmg = digilines:rules_link_anydir(pos, zmpos)
|
||||
local zmymg = digilines:rules_link_anydir(pos, zmympos)
|
||||
local xmg = digilines:rules_link_anydir(pos, xmpos)
|
||||
local xmymg = digilines:rules_link_anydir(pos, xmympos)
|
||||
local zpg = digilines:rules_link_anydir(pos, zppos)
|
||||
local zpymg = digilines:rules_link_anydir(pos, zpympos)
|
||||
local xpg = digilines:rules_link_anydir(pos, xppos)
|
||||
local xpymg = digilines:rules_link_anydir(pos, xpympos)
|
||||
|
||||
|
||||
local xpyg = digiline:rules_link_anydir(pos, xpypos)
|
||||
local zpyg = digiline:rules_link_anydir(pos, zpypos)
|
||||
local xmyg = digiline:rules_link_anydir(pos, xmypos)
|
||||
local zmyg = digiline:rules_link_anydir(pos, zmypos)
|
||||
local xpyg = digilines:rules_link_anydir(pos, xpypos)
|
||||
local zpyg = digilines:rules_link_anydir(pos, zpypos)
|
||||
local xmyg = digilines:rules_link_anydir(pos, xmypos)
|
||||
local zmyg = digilines:rules_link_anydir(pos, zmypos)
|
||||
|
||||
local zm, xm, zp, xp, xpy, zpy, xmy, zmy
|
||||
if zmg or zmymg then zm = 1 else zm = 0 end
|
||||
|
Loading…
Reference in New Issue
Block a user