Add additional formspec input checks

This commit is contained in:
Hugues Ross 2020-06-13 12:24:04 -04:00
parent cef6495f4a
commit ed967ddd0d

View File

@ -639,7 +639,7 @@ local function table_formspec(player)
end end
if data.tab == 1 then if data.tab == 1 then
minetest.show_formspec(player, "simple_table", minetest.show_formspec(player, "cartographer:table",
fs.header(10.25, 7.375, rank, data.tab, skin) .. fs.header(10.25, 7.375, rank, data.tab, skin) ..
fs.materials(0.25, 0.1875, meta, skin) .. fs.materials(0.25, 0.1875, meta, skin) ..
fs.separator(0.6875, skin.separator) .. fs.separator(0.6875, skin.separator) ..
@ -648,7 +648,7 @@ local function table_formspec(player)
fs.inv(0.25, 2.375, skin) fs.inv(0.25, 2.375, skin)
); );
elseif data.tab == 2 then elseif data.tab == 2 then
minetest.show_formspec(player, "simple_table", minetest.show_formspec(player, "cartographer:table",
fs.header(10.25, 8.25, rank, data.tab, skin) .. fs.header(10.25, 8.25, rank, data.tab, skin) ..
fs.materials(0.25, 0.1875, meta, skin) .. fs.materials(0.25, 0.1875, meta, skin) ..
fs.separator(0.6875, skin.separator) .. fs.separator(0.6875, skin.separator) ..
@ -657,7 +657,7 @@ local function table_formspec(player)
fs.inv(0.25, 3.25, skin) fs.inv(0.25, 3.25, skin)
); );
elseif data.tab == 3 then elseif data.tab == 3 then
minetest.show_formspec(player, "simple_table", minetest.show_formspec(player, "cartographer:table",
fs.header(10.25, 7.375, rank, data.tab, skin) .. fs.header(10.25, 7.375, rank, data.tab, skin) ..
fs.materials(0.25, 0.1875, meta, skin) .. fs.materials(0.25, 0.1875, meta, skin) ..
fs.separator(0.6875, skin.separator) .. fs.separator(0.6875, skin.separator) ..
@ -675,9 +675,17 @@ end
-- name: The formspec name -- name: The formspec name
-- fields: A table containing the input -- fields: A table containing the input
minetest.register_on_player_receive_fields(function(player, name, fields) minetest.register_on_player_receive_fields(function(player, name, fields)
if name == "simple_table" then if name == "cartographer:table" then
local meta = minetest.get_meta(player_tables[player:get_player_name()].pos); local meta = minetest.get_meta(player_tables[player:get_player_name()].pos);
local rank = 1;
local name = minetest.get_node(player_tables[player:get_player_name()].pos).name;
if name == "cartographer:standard_table" then
rank = 2;
elseif name == "cartographer:advanced_table" then
rank = 3;
end
if fields["convert"] then if fields["convert"] then
local inv = meta:get_inventory(); local inv = meta:get_inventory();
local stack = inv:get_stack("input", 1); local stack = inv:get_stack("input", 1);
@ -718,7 +726,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
audio.play_feedback("cartographer_write", player); audio.play_feedback("cartographer_write", player);
end end
elseif fields["copy"] then elseif fields["copy"] and rank >= 2 then
local cost = get_copy_material_cost(meta); local cost = get_copy_material_cost(meta);
if can_afford(cost, meta) then if can_afford(cost, meta) then
meta:set_int("paper", meta:get_int("paper") - cost.paper); meta:set_int("paper", meta:get_int("paper") - cost.paper);
@ -733,17 +741,17 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
meta:set_int("detail", 0); meta:set_int("detail", 0);
elseif fields["2"] then elseif fields["2"] then
meta:set_int("detail", 1); meta:set_int("detail", 1);
elseif fields["3"] then elseif fields["3"] and rank > 1 then
meta:set_int("detail", 2); meta:set_int("detail", 2);
elseif fields["4"] then elseif fields["4"] and rank > 2 then
meta:set_int("detail", 3); meta:set_int("detail", 3);
elseif fields["1x"] then elseif fields["1x"] and rank > 1 then
meta:set_int("scale", SCALE_SMALL); meta:set_int("scale", SCALE_SMALL);
elseif fields["2x"] then elseif fields["2x"] and rank > 1 then
meta:set_int("scale", SCALE_MEDIUM); meta:set_int("scale", SCALE_MEDIUM);
elseif fields["4x"] then elseif fields["4x"] and rank > 2 then
meta:set_int("scale", SCALE_LARGE); meta:set_int("scale", SCALE_LARGE);
elseif fields["8x"] then elseif fields["8x"] and rank > 2 then
meta:set_int("scale", SCALE_HUGE); meta:set_int("scale", SCALE_HUGE);
elseif fields["tab1"] then elseif fields["tab1"] then
player_tables[player:get_player_name()].tab = 1; player_tables[player:get_player_name()].tab = 1;
@ -751,7 +759,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
elseif fields["tab2"] then elseif fields["tab2"] then
player_tables[player:get_player_name()].tab = 2; player_tables[player:get_player_name()].tab = 2;
audio.play_feedback("cartographer_turn_page", player); audio.play_feedback("cartographer_turn_page", player);
elseif fields["tab3"] then elseif fields["tab3"] and rank >= 2 then
player_tables[player:get_player_name()].tab = 3; player_tables[player:get_player_name()].tab = 3;
audio.play_feedback("cartographer_turn_page", player); audio.play_feedback("cartographer_turn_page", player);
end end