Make formspec size a setting in minetest.conf

This commit is contained in:
JP Guerrero 2016-12-13 13:10:11 +01:00
parent c2011f4bfc
commit f141fbf806
2 changed files with 25 additions and 26 deletions

View File

@ -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 in your inventory. The progressive mode is disabled by default and can be enabled with
`craftguide_progressive_mode = true` in `minetest.conf`. `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) ![Preview](http://i.imgur.com/xblp1Vs.png)

View File

@ -1,17 +1,14 @@
local min, ceil, max = math.min, math.ceil, math.max 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
--------- Formspec configuration ----------- local progressive_mode = minetest.setting_getbool("craftguide_progressive_mode")
local iX = 8 -- item list width (min. 8) local iX, iY = (minetest.setting_get("craftguide_size") or "8x3"):match(
local iY = 3 -- item list height (min. 1) "([%d]+[.%d+]*)[%s+]*x[%s+]*([%d]+[.%d+]*)")
-------------------------------------------- iX, iY = max(8, round(iX or 8)), max(1, round(iY or 3))
iX, iY = max(8, ceil(iX)), max(1, ceil(iY))
local ipp = iX * iY local ipp = iX * iY
local offset_X = (iX / 2) + (iX % 2 == 0 and 0.5 or 0) 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 = { local group_stereotypes = {
wool = "wool:white", wool = "wool:white",
dye = "dye:white", dye = "dye:white",
@ -259,14 +256,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
craftguide:get_formspec(player_name) craftguide:get_formspec(player_name)
elseif fields.prev or fields.next then elseif fields.prev or fields.next then
data.pagenum = data.pagenum - (fields.prev and 1 or -1) data.pagenum = data.pagenum - (fields.prev and 1 or -1)
data.pagenum = data.pagenum > data.pagemax and 1 or data.pagenum if data.pagenum > data.pagemax then
data.pagenum = data.pagenum < 1 and data.pagemax or data.pagenum data.pagenum = 1
elseif data.pagenum == 0 then
data.pagenum = data.pagemax
end
craftguide:get_formspec(player_name) craftguide:get_formspec(player_name)
else for item in pairs(fields) do else for item in pairs(fields) do
if not item:find(":") then return end if not item:find(":") then return end
item = item:sub(-4) == "_inv" and item:sub(1,-5) or item item = item:sub(-4) == "_inv" and item:sub(1,-5) or item
if minetest.get_craft_recipe(item) then
if progressive_mode then if progressive_mode then
local _, player_has_item = local _, player_has_item =
craftguide:recipe_in_inv(player_name, item) craftguide:recipe_in_inv(player_name, item)
@ -279,7 +278,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
craftguide:get_formspec(player_name) craftguide:get_formspec(player_name)
end end
end end
end
end) end)
minetest.register_craftitem("craftguide:book", { minetest.register_craftitem("craftguide:book", {