From 6a2fa5a3e49ce3612e857b39a0c12ea8420e6795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Wed, 1 Mar 2017 00:57:58 -0300 Subject: [PATCH] Rename global table to `digilines`. This also adds a backwards compat alias so other mods shouldn't break. --- init.lua | 12 +++++++---- internal.lua | 30 +++++++++++++-------------- inventory.lua | 2 +- lightsensor.lua | 2 +- presetrules.lua | 4 ++-- rtc.lua | 2 +- util.lua | 16 +++++++------- wires_common.lua | 54 ++++++++++++++++++++++++------------------------ 8 files changed, 63 insertions(+), 59 deletions(-) diff --git a/init.lua b/init.lua index bffd4e7..7f9696e 100644 --- a/init.lua +++ b/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 diff --git a/internal.lua b/internal.lua index 45cd5d7..e189130 100644 --- a/internal.lua +++ b/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() diff --git a/inventory.lua b/inventory.lua index 0134e5c..c926bd9 100644 --- a/inventory.lua +++ b/inventory.lua @@ -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) diff --git a/lightsensor.lua b/lightsensor.lua index 86a29c9..21f66f9 100644 --- a/lightsensor.lua +++ b/lightsensor.lua @@ -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 diff --git a/presetrules.lua b/presetrules.lua index 8d5e35b..d8e94f7 100644 --- a/presetrules.lua +++ b/presetrules.lua @@ -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}, diff --git a/rtc.lua b/rtc.lua index f8f6af4..0ad3f84 100644 --- a/rtc.lua +++ b/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 diff --git a/util.lua b/util.lua index cec75be..bea91d3 100644 --- a/util.lua +++ b/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 diff --git a/wires_common.lua b/wires_common.lua index c5f761b..6806d01 100644 --- a/wires_common.lua +++ b/wires_common.lua @@ -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