Add map scale support to the advanced table

This commit is contained in:
Hugues Ross
2020-03-08 10:34:20 -04:00
parent 85eeb529b6
commit 8f786cda9a
4 changed files with 53 additions and 24 deletions

View File

@ -1,5 +1,7 @@
local SIZE_SMALL = 20;
local SIZE_LARGE = 40;
local SCALE_SMALL = 1;
local SCALE_LARGE = 4;
local separator = [[
formspec_version[3]
@ -74,11 +76,6 @@ function fs.materials(x, y, rank, meta)
]];
data = data:format(x, y, paper, pigment);
if rank > 1 then
data = data .. "label[6,0.25;Stuff x %d]";
data = data:format(0);
end
return data .. "container_end[]";
end
@ -132,6 +129,20 @@ function fs.craft(x, y, pos, rank, meta)
data = data:format(size);
end
if rank > 2 then
local scale = "1x";
if meta:get_int("scale") == SCALE_LARGE then
scale = "4x";
end
data = data .. [[
style[%s;bgcolor=blue]
button[3.5,0;0.5,0.5;1x;1x]
button[4.0,0;0.5,0.5;4x;4x]
]];
data = data:format(scale);
end
local detail = tostring(meta:get_int("detail") + 1);
data = data .. [[
style[%s;bgcolor=blue]
@ -269,6 +280,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
elseif fields["craft"] ~= nil then
local size = meta:get_int("size");
local detail = meta:get_int("detail");
local scale = meta:get_int("scale");
local paper = meta:get_int("paper");
local pigment = meta:get_int("pigment");
@ -285,7 +297,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
meta:set_int("paper", paper);
meta:set_int("pigment", pigment);
inv:set_stack("output", 1, cartographer.create_map_item(size, 1 + detail));
inv:set_stack("output", 1, cartographer.create_map_item(size, 1 + detail, scale));
end
else
local smeta = stack:get_meta();
@ -354,6 +366,12 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
elseif fields["4"] ~= nil then
meta:set_int("detail", 3);
table_formspec(player:get_player_name(), 2)
elseif fields["1x"] ~= nil then
meta:set_int("scale", SCALE_SMALL);
table_formspec(player:get_player_name(), 2)
elseif fields["4x"] ~= nil then
meta:set_int("scale", SCALE_LARGE);
table_formspec(player:get_player_name(), 2)
elseif fields["tabs"] ~= nil then
table_formspec(player:get_player_name(), tonumber(fields["tabs"]));
end
@ -368,7 +386,7 @@ local function setup_table_node(pos)
meta:get_inventory():set_size("copy_output", 1);
meta:set_int("size", SIZE_SMALL);
meta:set_int("scale", 1);
meta:set_int("scale", SCALE_SMALL);
meta:set_int("detail", 0);
end