From a9a09fceaa3be07b1d81b8af2fb221e245f44b48 Mon Sep 17 00:00:00 2001 From: Signal Date: Mon, 26 Jan 2026 15:28:26 -0500 Subject: [PATCH] Fix models and buttons, and let containers handle inventories properly. --- init.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 8cad266..2a6858b 100644 --- a/init.lua +++ b/init.lua @@ -163,9 +163,9 @@ local function get(e, x) local item = e[x] local mt = getmetatable(item) if mt == state or mt == DerivedState then - return fe(item()) + return fe(tostring(item())) end - return fe(item) + return fe(tostring(item)) end -- MARK: Elements @@ -362,27 +362,30 @@ local fs_model = { out[#out +1] = x:render() end out[#out +1] = string.format( - "model[%f,%f;%f,%f;%s;%s;%s;%f;%s;%s;%s;%f]", + "model[%f,%f;%f,%f;%s;%s;%s;%s;%s;%s;%s;%s]", x or get(e, "x"), y or get(e, "y"), w or get(e, "w"), h or get(e, "h"), e.__id, get(e, "mesh"), get(e, "textures"), get(e, "_rotation") or "", get(e, "_continuous") or "", - get(e, "_mouse_control"), - get(e, "_animation") or "", get(e, "_animation_speed") + get(e, "_mouse_control") or "", + get(e, "_animation") or "", get(e, "_animation_speed") or "" ) return table.concat(out) end, rotation = function(e, rot, continuous) e._rotation = rot e._continuous = continuous + return e end, mouse_control = function(e, mouse_control) e._mouse_control = mouse_control ~= false and true or false + return e end, animated = function(frames, speed) e._animation = frames e._animation_speed = speed or 1 + return e end, style = add_elem_style, tooltip = add_elem_tooltip, @@ -390,7 +393,7 @@ local fs_model = { fs_model.__index = fs_model setmetatable(fs_model, { __call = function(_, x, y, w, h, mesh, textures) - local e = {x = x, y = y, w = w, h = h, mesh = mesh, textures = textures, mouse_control = true} + local e = {x = x, y = y, w = w, h = h, mesh = mesh, textures = textures, _mouse_control = true, _styles = {}} e.__id = new_id() setmetatable(e, fs_model) table.insert(ctx, e) @@ -421,12 +424,15 @@ local fs_button = { image = function(e, img, pressed_img) e._image = img e._image_pressed = pressed_img + return e end, item_image = function(e, item) e._item = item + return e end, exit = function(e) e._exit = true + return e end, onclick = function(e, fn) ctx._events.on_click[e.__id] = fn @@ -472,17 +478,13 @@ local fs_list = { w = w or get(e, "w") h = h or get(e, "h") - -- These lines will cause `w` and `h` to be interpreted as formspec coordinates rather than numbers of slots. - -- w = w -((w -1) /4) - -- h = h -((h -1) /4) - return string.format("list[%s;%s;%f,%f;%d,%d;%s]", get(e, "location"), get(e, "list"), x or get(e, "x"), y or get(e, "y"), w, h, get(e, "start")) end } fs_list.__index = fs_list setmetatable(fs_list, { __call = function(_, x, y, w, h, location, list, start) - local e = {x = x, y = y, w = w, h = h, location = location or "current_player", list = list or "main", start = start or ""} + local e = {x = x, y = y, w = type(w == "string") and w or w +((w -1) /4), h = type(h) == "string" and h or h +((h -1) /4), location = location or "current_player", list = list or "main", start = start or ""} e.__id = new_id() setmetatable(e, fs_list) table.insert(ctx, e)