summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2014-06-13 12:15:50 +0100
committerDiego Martinez <kaeza@users.sf.net>2014-06-13 09:28:39 -0300
commit4c982dd667828888958116cf13dbd868d374555c (patch)
tree20c99f0c0798ba10a012b1c3a1ceb536f6a67978 /api.lua
parenta8c8ef08901f9d1bbe81045bd12a47fe3a82e5ea (diff)
Fix and enhance grid shapes in craft guide
Commit 043f6081452365daaa033c58e0738527ccb64c3d made shaped crafting recipes display in a grid of the recipe's minimum bounding box, but broke the use of a fixed 1x1 grid shape for cooking recipes. This commit generalises the dynamic-grid-shape facility, putting the craft type registration in charge. This restores the correct shape for cooking recipes. Also change the logic for dynamic grid sizes for regular shaped and shapeless crafting. We'd like to always use a grid shape that is reminiscent of a regular crafting grid, as a visual cue to the crafting method. But it's also nice to show smaller recipes in a smaller grid. In the expectation that crafting grids will always be square, show the recipe in the smallest square grid that will accommodate it.
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/api.lua b/api.lua
index 3314645..882971e 100644
--- a/api.lua
+++ b/api.lua
@@ -134,6 +134,13 @@ unified_inventory.register_craft_type("normal", {
description = "Crafting",
width = 3,
height = 3,
+ get_shaped_craft_width = function (craft) return craft.width end,
+ dynamic_display_size = function (craft)
+ local w = craft.width
+ local h = math.ceil(table.maxn(craft.items) / craft.width)
+ local g = w < h and h or w
+ return { width = g, height = g }
+ end,
uses_crafting_grid = true,
})
@@ -142,6 +149,12 @@ unified_inventory.register_craft_type("shapeless", {
description = "Mixing",
width = 3,
height = 3,
+ dynamic_display_size = function (craft)
+ local maxn = table.maxn(craft.items)
+ local g = 1
+ while g*g < maxn do g = g + 1 end
+ return { width = g, height = g }
+ end,
uses_crafting_grid = true,
})