]> git.lizzy.rs Git - xdecor.git/blob - handlers/nodeboxes.lua
Init
[xdecor.git] / handlers / nodeboxes.lua
1 xdecor.box = {
2         slab_y = function(height, shift) return { -0.5, -0.5+(shift or 0), -0.5, 0.5, -0.5+height+(shift or 0), 0.5 } end,
3         slab_z = function(depth) return { -0.5, -0.5, -0.5+depth, 0.5, 0.5, 0.5 } end,
4         bar_y = function(radius) return {-radius, -0.5, -radius, radius, 0.5, radius} end,
5         cuboid = function(radius_x, radius_y, radius_z) return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end
6 }
7
8 xdecor.nodebox = {
9         regular = { type="regular" },
10         null = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } }
11 }
12
13 local mt = {}
14 mt.__index = function(table, key)
15         local ref = xdecor.box[key]
16         local ref_type = type(ref)
17         if ref_type == "function" then
18                 return function(...)
19                         return { type = "fixed", fixed = ref(...) }
20                 end
21         elseif ref_type == "table" then
22                 return { type = "fixed", fixed = ref }
23         elseif ref_type == "nil" then
24                 error(key .. "could not be found among nodebox presets and functions")
25         end
26         error("unexpected datatype " .. tostring(type(ref)) .. " while looking for " .. key)
27 end
28 setmetatable(xdecor.nodebox, mt)