Rename global table to digilines.

This also adds a backwards compat alias so other mods
shouldn't break.
This commit is contained in:
Diego Martínez 2017-03-01 00:57:58 -03:00 committed by Auke Kok
parent 54b1b3fe91
commit 6a2fa5a3e4
8 changed files with 63 additions and 59 deletions

@ -1,4 +1,8 @@
digiline = {}
digilines = {}
-- Backwards compat.
rawset(_G, "digiline", digilines)
local modpath = minetest.get_modpath("digilines") local modpath = minetest.get_modpath("digilines")
dofile(modpath .. "/presetrules.lua") dofile(modpath .. "/presetrules.lua")
@ -7,12 +11,12 @@ dofile(modpath .. "/internal.lua")
dofile(modpath .. "/wires_common.lua") dofile(modpath .. "/wires_common.lua")
dofile(modpath .. "/wire_std.lua") dofile(modpath .. "/wire_std.lua")
function digiline:receptor_send(pos, rules, channel, msg) function digilines:receptor_send(pos, rules, channel, msg)
local checked = {} local checked = {}
checked[minetest.hash_node_position(pos)] = true -- exclude itself checked[minetest.hash_node_position(pos)] = true -- exclude itself
for _,rule in ipairs(rules) do for _,rule in ipairs(rules) do
if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then if digilines:rules_link(pos, digilines:addPosRule(pos, rule)) then
digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) digilines:transmit(digilines:addPosRule(pos, rule), channel, msg, checked)
end end
end end
end end

@ -1,15 +1,15 @@
function digiline:getspec(node) function digilines:getspec(node)
if not minetest.registered_nodes[node.name] then return false end if not minetest.registered_nodes[node.name] then return false end
return minetest.registered_nodes[node.name].digiline return minetest.registered_nodes[node.name].digiline
end end
function digiline:importrules(spec, node) function digilines:importrules(spec, node)
if type(spec) == 'function' then if type(spec) == 'function' then
return spec(node) return spec(node)
elseif spec then elseif spec then
return spec return spec
else else
return digiline.rules.default return digilines.rules.default
end end
end end
@ -19,10 +19,10 @@ function digiline:getAnyInputRules(pos)
if not spec then return end if not spec then return end
if spec.wire then if spec.wire then
return digiline:importrules(spec.wire.rules, node) return digilines:importrules(spec.wire.rules, node)
end end
if spec.effector then if spec.effector then
return digiline:importrules(spec.effector.rules, node) return digilines:importrules(spec.effector.rules, node)
end end
end end
@ -32,24 +32,24 @@ function digiline:getAnyOutputRules(pos)
if not spec then return end if not spec then return end
if spec.wire then if spec.wire then
return digiline:importrules(spec.wire.rules, node) return digilines:importrules(spec.wire.rules, node)
end end
if spec.receptor then if spec.receptor then
return digiline:importrules(spec.receptor.rules, node) return digilines:importrules(spec.receptor.rules, node)
end end
end end
function digiline:rules_link(output, input) function digilines:rules_link(output, input)
local outputrules = digiline:getAnyOutputRules(output) local outputrules = digilines:getAnyOutputRules(output)
local inputrules = digiline:getAnyInputRules (input) local inputrules = digilines:getAnyInputRules (input)
if not outputrules or not inputrules then return false end if not outputrules or not inputrules then return false end
for _, orule in ipairs(outputrules) do 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 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 return true
end end
end end
@ -58,9 +58,9 @@ function digiline:rules_link(output, input)
return false return false
end end
function digiline:rules_link_anydir(output, input) function digilines:rules_link_anydir(output, input)
return digiline:rules_link(output, input) return digilines:rules_link(output, input)
or digiline:rules_link(input, output) or digilines:rules_link(input, output)
end end
local function queue_new() local function queue_new()

@ -2,7 +2,7 @@ local function sendMessage(pos, msg, channel)
if channel == nil then if channel == nil then
channel = minetest.get_meta(pos):get_string("channel") channel = minetest.get_meta(pos):get_string("channel")
end end
digiline:receptor_send(pos,digiline.rules.default,channel,msg) digilines:receptor_send(pos,digilines.rules.default,channel,msg)
end end
local function maybeString(stack) 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") local setchan = minetest.get_meta(pos):get_string("channel")
if channel == setchan and msg == GET_COMMAND then if channel == setchan and msg == GET_COMMAND then
local lightval = minetest.get_node_light(pos) 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
end end

@ -1,6 +1,6 @@
digiline.rules = {} digilines.rules = {}
digiline.rules.default = digilines.rules.default =
{{x=0, y=0, z=-1}, {{x=0, y=0, z=-1},
{x=1, y=0, z=0}, {x=1, y=0, z=0},
{x=-1, y=0, z=0}, {x=-1, y=0, z=0},

@ -20,7 +20,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
local setchan = minetest.get_meta(pos):get_string("channel") local setchan = minetest.get_meta(pos):get_string("channel")
if channel == setchan and msg == GET_COMMAND then if channel == setchan and msg == GET_COMMAND then
local timeofday = minetest.get_timeofday() 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
end end

@ -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} return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
end 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) return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z)
end end
--Rules rotation Functions: --Rules rotation Functions:
function digiline:rotate_rules_right(rules) function digilines:rotate_rules_right(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -18,7 +18,7 @@ function digiline:rotate_rules_right(rules)
return nr return nr
end end
function digiline:rotate_rules_left(rules) function digilines:rotate_rules_left(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -29,7 +29,7 @@ function digiline:rotate_rules_left(rules)
return nr return nr
end end
function digiline:rotate_rules_down(rules) function digilines:rotate_rules_down(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -40,7 +40,7 @@ function digiline:rotate_rules_down(rules)
return nr return nr
end end
function digiline:rotate_rules_up(rules) function digilines:rotate_rules_up(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -51,13 +51,13 @@ function digiline:rotate_rules_up(rules)
return nr return nr
end 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 if type(table) ~= "table" then return table end -- no need to copy
local newtable = {} local newtable = {}
for idx, item in pairs(table) do for idx, item in pairs(table) do
if type(item) == "table" then if type(item) == "table" then
newtable[idx] = digiline:tablecopy(item) newtable[idx] = digilines:tablecopy(item)
else else
newtable[idx] = item newtable[idx] = item
end end

@ -1,17 +1,17 @@
minetest.register_on_placenode(function(pos, node) minetest.register_on_placenode(function(pos, node)
if minetest.registered_nodes[node.name].digiline then if minetest.registered_nodes[node.name].digiline then
digiline:update_autoconnect(pos) digilines:update_autoconnect(pos)
end end
end) end)
minetest.register_on_dignode(function(pos, node) minetest.register_on_dignode(function(pos, node)
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then
-- need to make sure that node exists (unknown nodes!) -- need to make sure that node exists (unknown nodes!)
digiline:update_autoconnect(pos) digilines:update_autoconnect(pos)
end end
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 xppos = {x=pos.x+1, y=pos.y, z=pos.z}
local zppos = {x=pos.x, y=pos.y, z=pos.z+1} local zppos = {x=pos.x, y=pos.y, z=pos.z+1}
local xmpos = {x=pos.x-1, y=pos.y, z=pos.z} 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} local zmypos = {x=pos.x, y=pos.y+1, z=pos.z-1}
if secondcall == nil then if secondcall == nil then
digiline:update_autoconnect(xppos, true) digilines:update_autoconnect(xppos, true)
digiline:update_autoconnect(zppos, true) digilines:update_autoconnect(zppos, true)
digiline:update_autoconnect(xmpos, true) digilines:update_autoconnect(xmpos, true)
digiline:update_autoconnect(zmpos, true) digilines:update_autoconnect(zmpos, true)
digiline:update_autoconnect(xpypos, true) digilines:update_autoconnect(xpypos, true)
digiline:update_autoconnect(zpypos, true) digilines:update_autoconnect(zpypos, true)
digiline:update_autoconnect(xmypos, true) digilines:update_autoconnect(xmypos, true)
digiline:update_autoconnect(zmypos, true) digilines:update_autoconnect(zmypos, true)
digiline:update_autoconnect(xpympos, true) digilines:update_autoconnect(xpympos, true)
digiline:update_autoconnect(zpympos, true) digilines:update_autoconnect(zpympos, true)
digiline:update_autoconnect(xmympos, true) digilines:update_autoconnect(xmympos, true)
digiline:update_autoconnect(zmympos, true) digilines:update_autoconnect(zmympos, true)
end end
local def = minetest.registered_nodes[minetest.get_node(pos).name] local def = minetest.registered_nodes[minetest.get_node(pos).name]
@ -49,20 +49,20 @@ function digiline:update_autoconnect(pos, secondcall)
return nil return nil
end end
local zmg = digiline:rules_link_anydir(pos, zmpos) local zmg = digilines:rules_link_anydir(pos, zmpos)
local zmymg = digiline:rules_link_anydir(pos, zmympos) local zmymg = digilines:rules_link_anydir(pos, zmympos)
local xmg = digiline:rules_link_anydir(pos, xmpos) local xmg = digilines:rules_link_anydir(pos, xmpos)
local xmymg = digiline:rules_link_anydir(pos, xmympos) local xmymg = digilines:rules_link_anydir(pos, xmympos)
local zpg = digiline:rules_link_anydir(pos, zppos) local zpg = digilines:rules_link_anydir(pos, zppos)
local zpymg = digiline:rules_link_anydir(pos, zpympos) local zpymg = digilines:rules_link_anydir(pos, zpympos)
local xpg = digiline:rules_link_anydir(pos, xppos) local xpg = digilines:rules_link_anydir(pos, xppos)
local xpymg = digiline:rules_link_anydir(pos, xpympos) local xpymg = digilines:rules_link_anydir(pos, xpympos)
local xpyg = digiline:rules_link_anydir(pos, xpypos) local xpyg = digilines:rules_link_anydir(pos, xpypos)
local zpyg = digiline:rules_link_anydir(pos, zpypos) local zpyg = digilines:rules_link_anydir(pos, zpypos)
local xmyg = digiline:rules_link_anydir(pos, xmypos) local xmyg = digilines:rules_link_anydir(pos, xmypos)
local zmyg = digiline:rules_link_anydir(pos, zmypos) local zmyg = digilines:rules_link_anydir(pos, zmypos)
local zm, xm, zp, xp, xpy, zpy, xmy, zmy local zm, xm, zp, xp, xpy, zpy, xmy, zmy
if zmg or zmymg then zm = 1 else zm = 0 end if zmg or zmymg then zm = 1 else zm = 0 end