Cleanup and minor fix

This commit is contained in:
Paul Ouellette 2020-06-25 12:08:33 -04:00
parent 1339fefa4b
commit 444485209d
3 changed files with 25 additions and 24 deletions

View file

@ -16,34 +16,34 @@ local group_stereotypes = {
local group_names = { local group_names = {
coal = S("Any coal"), coal = S("Any coal"),
wool = S("Any wool"),
wood = S("Any wood planks"),
sand = S("Any sand"), sand = S("Any sand"),
wool = S("Any wool"),
stick = S("Any stick"), stick = S("Any stick"),
stone = S("Any kind of stone block"),
vessel = S("Any vessel"), vessel = S("Any vessel"),
wood = S("Any wood planks"),
stone = S("Any kind of stone block"),
["color_red,flower"] = S("Any red flower"), ["color_red,flower"] = S("Any red flower"),
["color_blue,flower"] = S("Any blue flower"), ["color_blue,flower"] = S("Any blue flower"),
["color_black,flower"] = S("Any black flower"), ["color_black,flower"] = S("Any black flower"),
["color_white,flower"] = S("Any white flower"),
["color_green,flower"] = S("Any green flower"), ["color_green,flower"] = S("Any green flower"),
["color_white,flower"] = S("Any white flower"),
["color_orange,flower"] = S("Any orange flower"), ["color_orange,flower"] = S("Any orange flower"),
["color_yellow,flower"] = S("Any yellow flower"),
["color_violet,flower"] = S("Any violet flower"), ["color_violet,flower"] = S("Any violet flower"),
["color_yellow,flower"] = S("Any yellow flower"),
["color_red,dye"] = S("Any red dye"), ["color_red,dye"] = S("Any red dye"),
["color_blue,dye"] = S("Any blue dye"), ["color_blue,dye"] = S("Any blue dye"),
["color_cyan,dye"] = S("Any cyan dye"),
["color_grey,dye"] = S("Any grey dye"), ["color_grey,dye"] = S("Any grey dye"),
["color_pink,dye"] = S("Any pink dye"), ["color_pink,dye"] = S("Any pink dye"),
["color_cyan,dye"] = S("Any cyan dye"),
["color_black,dye"] = S("Any black dye"), ["color_black,dye"] = S("Any black dye"),
["color_white,dye"] = S("Any white dye"),
["color_brown,dye"] = S("Any brown dye"), ["color_brown,dye"] = S("Any brown dye"),
["color_green,dye"] = S("Any green dye"), ["color_green,dye"] = S("Any green dye"),
["color_white,dye"] = S("Any white dye"),
["color_orange,dye"] = S("Any orange dye"), ["color_orange,dye"] = S("Any orange dye"),
["color_yellow,dye"] = S("Any yellow dye"),
["color_violet,dye"] = S("Any violet dye"), ["color_violet,dye"] = S("Any violet dye"),
["color_yellow,dye"] = S("Any yellow dye"),
["color_magenta,dye"] = S("Any magenta dye"), ["color_magenta,dye"] = S("Any magenta dye"),
["color_dark_grey,dye"] = S("Any dark grey dye"), ["color_dark_grey,dye"] = S("Any dark grey dye"),
["color_dark_green,dye"] = S("Any dark green dye") ["color_dark_green,dye"] = S("Any dark green dye")
@ -61,6 +61,7 @@ local function extract_groups(str)
if str:sub(1, 6) == "group:" then if str:sub(1, 6) == "group:" then
return str:sub(7):split() return str:sub(7):split()
end end
return nil
end end
local function item_has_groups(item_groups, groups) local function item_has_groups(item_groups, groups)
@ -94,7 +95,7 @@ end
local function get_craftable_recipes(output) local function get_craftable_recipes(output)
local recipes = minetest.get_all_craft_recipes(output) local recipes = minetest.get_all_craft_recipes(output)
if not recipes then if not recipes then
return return nil
end end
for i = #recipes, 1, -1 do for i = #recipes, 1, -1 do
@ -201,7 +202,13 @@ local function recipe_fs(fs, data)
cooktime, width = width, 1 cooktime, width = width, 1
elseif width == 0 then elseif width == 0 then
shapeless = true shapeless = true
width = #recipe.items <= 4 and 2 or math.min(3, #recipe.items) if #recipe.items == 1 then
width = 1
elseif #recipe.items <= 4 then
width = 2
else
width = 3
end
end end
table.insert(fs, ("label[5.5,6.6;%s]"):format(esc(data.show_usages table.insert(fs, ("label[5.5,6.6;%s]"):format(esc(data.show_usages
@ -278,7 +285,7 @@ local function get_formspec(player)
end end
local x = i % 8 local x = i % 8
local y = (i % 32 - x) / 8 local y = (i % 32 - x) / 8
item_button_fs(fs, x, y, item, item.."_inv") item_button_fs(fs, x, y, item, item)
end end
end end
@ -311,20 +318,16 @@ local function execute_search(data)
end end
end end
local function reset_data(data)
data.filter = ""
data.pagenum = 1
data.prev_item = nil
data.recipes = nil
data.items = init_items
end
local function on_receive_fields(player, fields) local function on_receive_fields(player, fields)
local name = player:get_player_name() local name = player:get_player_name()
local data = player_data[name] local data = player_data[name]
if fields.clear then if fields.clear then
reset_data(data) data.filter = ""
data.pagenum = 1
data.prev_item = nil
data.recipes = nil
data.items = init_items
return true return true
elseif fields.key_enter_field == "filter" or fields.search then elseif fields.key_enter_field == "filter" or fields.search then
@ -369,9 +372,6 @@ local function on_receive_fields(player, fields)
if not item then if not item then
return return
end end
if item:sub(-4) == "_inv" then
item = item:sub(1, -5)
end
if item == data.prev_item then if item == data.prev_item then
data.show_usages = not data.show_usages data.show_usages = not data.show_usages

View file

@ -4,7 +4,7 @@ License of source code
The MIT License (MIT) The MIT License (MIT)
Copyright (C) 2015-2019 Jean-Patrick Guerrero and contributors. Copyright (C) 2015-2019 Jean-Patrick Guerrero and contributors.
Copyright (C) 2019 pauloue Copyright (C) 2020 pauloue
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -32,6 +32,7 @@ Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Copyright (C) 2018 paramat Copyright (C) 2018 paramat
Copyright (C) Neuromancer Copyright (C) Neuromancer
Copyright (C) 2017 Wuzzy
You are free to: You are free to:
Share — copy and redistribute the material in any medium or format. Share — copy and redistribute the material in any medium or format.