allow to use item slot to describe stack for preconditions

This commit is contained in:
Sokomine 2021-06-21 20:43:13 +02:00
parent 228faed97d
commit c24cce74b1

View File

@ -216,27 +216,51 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
-- are we talking about an inventory?
-- (inventory only applies to preconditions; not effects)
local data = yl_speak_up.speak_to[pname][ tmp_data_cache ]
if(fields.inv_stack_name and fields.inv_stack_name ~= ""
if(((fields.inv_stack_name and fields.inv_stack_name ~= "")
or (fields.store_item_name and fields.store_item_name ~= ""))
and id_prefix == "p_"
and data and data.what and data.what >= 5 and data.what <= 6) then
local parts = fields.inv_stack_name:split(" ")
local size = 1
if(parts and #parts > 1) then
size = tonumber(parts[2])
if(not(size) or size < 1) then
size = 1
local wanted = ""
local wanted_name = ""
if(not(fields.store_item_name)) then
local parts = fields.inv_stack_name:split(" ")
local size = 1
if(parts and #parts > 1) then
size = tonumber(parts[2])
if(not(size) or size < 1) then
size = 1
end
end
wanted = parts[1].." "..tostring(size)
wanted_name = parts[1]
else
local trade_inv = minetest.get_inventory({type="detached",
name="yl_speak_up_player_"..pname})
if(not(trade_inv) or trade_inv:is_empty("npc_wants", 1)) then
-- show error message
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[8,2]"..
"label[0.2,0.0;Please put an item(stack) into the slot "..
"next to the\n\"Store\" button first!]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return
end
local stack = trade_inv:get_stack("npc_wants", 1)
wanted = stack:get_name().." "..stack:get_count()
wanted_name = stack:get_name()
end
-- does the item exist?
if(minetest.registered_items[ parts[1] ]) then
data.inv_stack_name = parts[1].." "..tostring(size)
if(minetest.registered_items[ wanted_name ]) then
data.inv_stack_name = wanted
fields.inv_stack_name = wanted
else
-- show error message
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[8,2]"..
"label[0.2,0.5;Error: \""..
minetest.formspec_escape(fields.inv_stack_name)..
minetest.formspec_escape(wanted)..
"\" is not a valid item(stack).]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return
@ -665,7 +689,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
-- select a general direction/type first
-- but *not* when enter was pressed (enter sends them all)
if(fields.select_what and not(fields.key_enter)) then
if(fields.select_what and not(fields.key_enter) and not(fields.store_item_name)) then
local nr = table.indexof(check_what, fields.select_what)
yl_speak_up.speak_to[pname][ tmp_data_cache ] = { what = nr }
end
@ -728,6 +752,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
or fields.select_on_failure
or fields.select_on_action_failure
or fields.back_from_error_msg
or fields.store_item_name
or was_changed
or fields.key_enter
or fields.quit
@ -946,7 +971,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
if(id_prefix ~= "a_") then
formspec = formspec..
"label[1,9.0;If you are unsure if your setup of pre(C)onditions and (Ef)fects "..
"label[1,10.5;If you are unsure if your setup of pre(C)onditions and (Ef)fects "..
"works as intended,\ntype \"/npc_talk_debug "..tostring(n_id).."\" "..
"in chat in order to enter debug mode. You can leave it with "..
"\"/npc_talk_debug off\".]"
@ -1096,15 +1121,20 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
save_button = ""
end
formspec = formspec..
"label[0.2,3.3;The following shall be true about the inventory:]"..
"dropdown[4.0,3.5;16.0,0.6;select_inv;"..
"label[0.2,3.0;The following shall be true about the inventory:]"..
"dropdown[4.0,3.2;16.0,0.6;select_inv;"..
table.concat(check_inv, ",")..";"..
tostring(data.inv)..";]"..
"label[0.2,4.5;Name of the item(stack):]"..
"field[4.0,4.3;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]"..
"label[0.2,4.2;Name of the item(stack):]"..
"field[4.0,4.0;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]"..
"tooltip[inv_stack_name;Enter name of the block and amount.\n"..
"Example: \"default:apple 3\" for three apples,\n"..
" \"farming:bread\" for a bread.]"
" \"farming:bread\" for a bread.]"..
"label[0.2,5.7;Or put the item in here\nand click on \"Store\":]"..
"button[5.5,5.5;1.5,0.9;store_item_name;Store]"..
"list[detached:yl_speak_up_player_"..pname..";npc_wants;4.0,5.5;1,1;]"..
"label[8,4.9;Your inventory:]"..
"list[current_player;main;8,5.3;8,4;]"
-- "NPC crafts something", -- 4
-- (craft - only for effects - not for preconditions)