|
formspec_elements.item_grid = function(values) |
|
for v,d in pairs({X = 0, Y = 0, W = 1, H = 1, spacing = 0, size = 1, offset = 1}) do |
|
if type(values[v]) ~= "number" then |
|
values[v] = d |
|
end |
|
end |
|
local name = str(values.name, "grid").."_" |
|
local items = type(values.items) == "table" and values.items or {} |
|
local offset = math.max(1, math.floor(values.offset)) - 1 |
|
local x, y, n, item = values.X, values.Y, 1 |
|
local grid = {} |
|
for _=1, values.H do |
|
for _=1, values.W do |
|
item = items[n + offset] |
|
if type(item) ~= "string" then |
|
return table.concat(grid) |
|
end |
|
item = string.match(item, "^[^ %[%]\\,;]* ?%d* ?%d*") |
|
if values.interactable ~= false then |
|
grid[n] = string.format("item_image_button[%s,%s;%s,%s;%s;%s;]", |
|
x, y, values.size, values.size, item, name..n) |
|
else |
|
grid[n] = string.format("item_image[%s,%s;%s,%s;%s]", |
|
x, y, values.size, values.size, item) |
|
end |
|
n = n + 1 |
|
x = x + values.size + values.spacing |
|
end |
|
x = values.X |
|
y = y + values.size + values.spacing |
|
end |
|
return table.concat(grid) |
|
end |
Currently the modify command looks at the start of the element string to identify the element that it contains, however this does not work with the custom
item_gridelement, because that element string consists of multipleitem_imageoritem_image_button.Possible solutions:
modifycommand does not need to use pattern matching.item_gridmodification. (and tables too)Relevant code:
digistuff/touchscreen.lua
Lines 20 to 33 in 71b606c
digistuff/formspec_elements.lua
Lines 351 to 383 in 71b606c