summaryrefslogtreecommitdiff
path: root/tube_registration.lua
diff options
context:
space:
mode:
authorTim <t4im@users.noreply.github.com>2015-01-31 14:47:06 +0100
committerTim <t4im@users.noreply.github.com>2015-01-31 14:47:06 +0100
commit810ae99008667209508f553e6b08e53e63bf1029 (patch)
treee7252426166658fc833b7e5d956d9eadd2935d15 /tube_registration.lua
parent4dc3f159c9114d65571122909e252167579dc90b (diff)
downloadpipeworks-810ae99008667209508f553e6b08e53e63bf1029.tar
pipeworks-810ae99008667209508f553e6b08e53e63bf1029.tar.gz
pipeworks-810ae99008667209508f553e6b08e53e63bf1029.tar.bz2
pipeworks-810ae99008667209508f553e6b08e53e63bf1029.tar.xz
pipeworks-810ae99008667209508f553e6b08e53e63bf1029.zip
reduce texturename repetition via __index
Diffstat (limited to 'tube_registration.lua')
-rw-r--r--tube_registration.lua22
1 files changed, 16 insertions, 6 deletions
diff --git a/tube_registration.lua b/tube_registration.lua
index 6ef4fee..4f387d8 100644
--- a/tube_registration.lua
+++ b/tube_registration.lua
@@ -11,20 +11,30 @@ local REGISTER_COMPATIBILITY = true
local vti = {4, 3, 2, 1, 6, 5}
local default_textures = {
- noctrs = { "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png",
- "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png"},
- plain = { "pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png",
- "pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png"},
- ends = { "pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png",
- "pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png"},
+ noctrs = { "pipeworks_tube_noctr.png" },
+ plain = { "pipeworks_tube_plain.png" },
+ ends = { "pipeworks_tube_end.png" },
short = "pipeworks_tube_short.png",
inv = "pipeworks_tube_inv.png",
}
+local texture_mt = {
+ __index = function(table, key)
+ local size, idx = #table, tonumber(key)
+ if size > 0 then -- avoid endless loops with empty tables
+ while idx > size do idx = idx - size end
+ return table[idx]
+ end
+ end
+}
+
local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, ends, short, inv, special, connects, style)
noctrs = noctrs or default_textures.noctrs
+ setmetatable(noctrs, texture_mt)
plain = plain or default_textures.plain
+ setmetatable(plain, texture_mt)
ends = ends or default_textures.ends
+ setmetatable(ends, texture_mt)
short = short or default_textures.short
inv = inv or default_textures.inv