diff options
author | JP Guerrero <jeanpatrick.guerrero@gmail.com> | 2016-12-13 13:10:11 +0100 |
---|---|---|
committer | JP Guerrero <jeanpatrick.guerrero@gmail.com> | 2016-12-13 14:01:51 +0100 |
commit | f141fbf806e5440fb94052d3b561e7217fcb0427 (patch) | |
tree | 665ad41334c86daf5dcd83b4ac6a2818a1e7f0d8 | |
parent | c2011f4bfc9d50a671bb99b850cc7e6187282b6d (diff) |
Make formspec size a setting in minetest.conf
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | init.lua | 48 |
2 files changed, 25 insertions, 26 deletions
@@ -10,7 +10,8 @@ list the items in the crafting guide for which you already have the ingredients in your inventory. The progressive mode is disabled by default and can be enabled with `craftguide_progressive_mode = true` in `minetest.conf`. -The formspec size is also easily configurable by the user, see [here](https://github.com/minetest-mods/craftguide/blob/master/init.lua#L3-L6). +The formspec size is also easily configurable with this setting in `minetest.conf`: +`craftguide_size = WxH` (default: `8x3`). The minimum accepted size is `8x1`. ![Preview](http://i.imgur.com/xblp1Vs.png) @@ -1,17 +1,14 @@ -local min, ceil, max = math.min, math.ceil, math.max - ---------- Formspec configuration ----------- -local iX = 8 -- item list width (min. 8) -local iY = 3 -- item list height (min. 1) --------------------------------------------- +local craftguide, datas = {}, {} +local min, max, ceil, floor = math.min, math.max, math.ceil, math.floor +local function round(n) return floor((floor(n * 2) + 1) / 2) end -iX, iY = max(8, ceil(iX)), max(1, ceil(iY)) +local progressive_mode = minetest.setting_getbool("craftguide_progressive_mode") +local iX, iY = (minetest.setting_get("craftguide_size") or "8x3"):match( + "([%d]+[.%d+]*)[%s+]*x[%s+]*([%d]+[.%d+]*)") +iX, iY = max(8, round(iX or 8)), max(1, round(iY or 3)) local ipp = iX * iY local offset_X = (iX / 2) + (iX % 2 == 0 and 0.5 or 0) -local craftguide, datas = {}, {} -local progressive_mode = minetest.setting_getbool("craftguide_progressive_mode") - local group_stereotypes = { wool = "wool:white", dye = "dye:white", @@ -259,25 +256,26 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) craftguide:get_formspec(player_name) elseif fields.prev or fields.next then data.pagenum = data.pagenum - (fields.prev and 1 or -1) - data.pagenum = data.pagenum > data.pagemax and 1 or data.pagenum - data.pagenum = data.pagenum < 1 and data.pagemax or data.pagenum + if data.pagenum > data.pagemax then + data.pagenum = 1 + elseif data.pagenum == 0 then + data.pagenum = data.pagemax + end craftguide:get_formspec(player_name) else for item in pairs(fields) do - if not item:find(":") then return end - item = item:sub(-4) == "_inv" and item:sub(1,-5) or item + if not item:find(":") then return end + item = item:sub(-4) == "_inv" and item:sub(1,-5) or item - if minetest.get_craft_recipe(item) then - if progressive_mode then - local _, player_has_item = - craftguide:recipe_in_inv(player_name, item) - if not player_has_item then return end - end + if progressive_mode then + local _, player_has_item = + craftguide:recipe_in_inv(player_name, item) + if not player_has_item then return end + end - data.item = item - data.recipe_num = 1 - data.recipes_item = minetest.get_all_craft_recipes(item) - craftguide:get_formspec(player_name) - end + data.item = item + data.recipe_num = 1 + data.recipes_item = minetest.get_all_craft_recipes(item) + craftguide:get_formspec(player_name) end end end) |