diff options
author | Tim <t4im@users.noreply.github.com> | 2015-01-31 14:47:06 +0100 |
---|---|---|
committer | Tim <t4im@users.noreply.github.com> | 2015-01-31 14:47:06 +0100 |
commit | 810ae99008667209508f553e6b08e53e63bf1029 (patch) | |
tree | e7252426166658fc833b7e5d956d9eadd2935d15 /tube_registration.lua | |
parent | 4dc3f159c9114d65571122909e252167579dc90b (diff) |
reduce texturename repetition via __index
Diffstat (limited to 'tube_registration.lua')
-rw-r--r-- | tube_registration.lua | 22 |
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 |