-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Description
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_grid element, because that element string consists of multiple item_image or item_image_button.
Possible solutions:
- Change how elements are stored in metadata so that the
modifycommand does not need to use pattern matching. - Add code specifically for
item_gridmodification. (and tables too) - Something else?
Relevant code:
Lines 20 to 33 in 71b606c
| local function modify_element_string(old, values) | |
| local e = string.match(old, "^(.-)%[") | |
| local element = formspec_elements[e] | |
| if type(element) == "function" then | |
| return old -- No-op for special elements, as there is no format string | |
| end | |
| local old_values = {string.match(old, element[5])} | |
| local new_values = {} | |
| for i,name in ipairs(element[2]) do | |
| local value = element[4][i](values[name], old_values[i] or element[3][i]) | |
| table.insert(new_values, value) | |
| end | |
| return string.format(element[1], unpack(new_values)) | |
| end |
digistuff/formspec_elements.lua
Lines 351 to 383 in 71b606c
| 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 |
SwissalpS
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request