summaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
authorAuke Kok <sofar+github@foo-projects.org>2016-05-27 16:08:53 -0700
committerAuke Kok <sofar+github@foo-projects.org>2016-05-27 16:08:53 -0700
commit7ecb29e87f1f272f92d0fec871dd525a80a9537c (patch)
tree9c57001d333fc36a0561a3e8bfdac0df0108532b /util.lua
parent4c743f9c4d1d263c5c36edb6a5dbaab7e2bdc6e4 (diff)
Convert digilines to a mod (not modpack). (#32)
Digilines is probably used by most people in its entirety. I've retained the ability to disable inventory, rtc, lightsensor and LCD by the minetest settings "diglines_enable_rtc" etc.. If set to "false", these components will not be loaded. It is assumed by default that these are enabled. In the conversion the digilines_lcd:lcd node was renamed to digilines:lcd (same for all the other nodes). To retain backwards compatibility I've provided aliases for each of these nodes.
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/util.lua b/util.lua
new file mode 100644
index 0000000..d138d63
--- /dev/null
+++ b/util.lua
@@ -0,0 +1,67 @@
+function digiline: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)
+ 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)
+ local nr={}
+ for i, rule in ipairs(rules) do
+ nr[i]={}
+ nr[i].z=rule.x
+ nr[i].x=-rule.z
+ nr[i].y=rule.y
+ end
+ return nr
+end
+
+function digiline:rotate_rules_left(rules)
+ local nr={}
+ for i, rule in ipairs(rules) do
+ nr[i]={}
+ nr[i].z=-rules[i].x
+ nr[i].x=rules[i].z
+ nr[i].y=rules[i].y
+ end
+ return nr
+end
+
+function digiline:rotate_rules_down(rules)
+ local nr={}
+ for i, rule in ipairs(rules) do
+ nr[i]={}
+ nr[i].y=rule.x
+ nr[i].x=-rule.y
+ nr[i].z=rule.z
+ end
+ return nr
+end
+
+function digiline:rotate_rules_up(rules)
+ local nr={}
+ for i, rule in ipairs(rules) do
+ nr[i]={}
+ nr[i].y=-rule.x
+ nr[i].x=rule.y
+ nr[i].z=rule.z
+ end
+ return nr
+end
+
+function digiline: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)
+ else
+ newtable[idx] = item
+ end
+ end
+
+ return newtable
+end