Rework size/scaling

- Size is now always large
- Size settings replaced by 4 scaling levels: 1x, 2x, 4x, and 8x
This commit is contained in:
Hugues Ross 2020-04-20 19:38:33 -04:00
parent bb6b1233cd
commit e6035d9e2b
1 changed files with 34 additions and 41 deletions

View File

@ -1,7 +1,8 @@
local SIZE_SMALL = 20;
local SIZE_LARGE = 40;
local MAP_SIZE = 40;
local SCALE_SMALL = 1;
local SCALE_MEDIUM = 2;
local SCALE_LARGE = 4;
local SCALE_HUGE = 8;
-- Draw background elements in the same arrangement as inventory slots
-- x: The x position of the inventory
@ -25,20 +26,23 @@ local function inventory_bg(x, y, cols, rows, skin)
return data;
end
local function get_material_cost(size, detail)
local paper = 0;
local pigment = 0;
-- Get the material cost for the given map scale and detail level
-- scale: The map scale
-- detail: The detail level
local function get_material_cost(scale, detail)
local paper = scale * 4;
local pigment = detail * 5;
if size == SIZE_SMALL then
paper = paper + 4;
if scale == SCALE_SMALL then
pigment = pigment + 5;
elseif size == SIZE_LARGE then
paper = paper + 16;
elseif scale == SCALE_MEDIUM then
pigment = pigment + 10;
elseif scale == SCALE_LARGE then
pigment = pigment + 15;
elseif scale == SCALE_HUGE then
pigment = pigment + 20;
end
pigment = pigment + (detail * 5);
return {
paper = math.max(paper, 0),
pigment = math.max(pigment, 0),
@ -51,13 +55,13 @@ end
-- Returns a table with the material costs, and a boolean indicating if the
-- costs were positive or negative before clamping.
local function get_craft_material_cost(meta)
local cost = get_material_cost(meta:get_int("size") or SIZE_SMALL, meta:get_int("detail") or 0);
local cost = get_material_cost(meta:get_int("scale") or SCALE_SMALL, meta:get_int("detail") or 0);
local stack = meta:get_inventory():get_stack("output", 1);
local is_positive = true;
if stack:get_name() == "cartographer:map" then
local smeta = stack:get_meta();
local sub_cost = get_material_cost(smeta:get_int("cartographer:size") or SIZE_SMALL, (smeta:get_int("cartographer:detail") or 1) - 1);
local sub_cost = get_material_cost(smeta:get_int("cartographer:scale") or SCALE_SMALL, (smeta:get_int("cartographer:detail") or 1) - 1);
is_positive = cost.paper >= sub_cost.paper and cost.pigment >= sub_cost.pigment;
cost.paper = math.max(cost.paper - sub_cost.paper, 0);
cost.pigment = math.max(cost.pigment - sub_cost.pigment, 0);
@ -90,7 +94,7 @@ local function get_copy_material_cost(meta)
if out_stack:is_empty() and in_stack:get_name() == "cartographer:map" then
local smeta = in_stack:get_meta();
local size = smeta:get_int("cartographer:size") or SIZE_SMALL;
local scale = smeta:get_int("cartographer:scale") or SCALE_SMALL;
local detail = smeta:get_int("cartographer:detail") or 1;
return get_material_cost(size, detail - 1);
@ -267,34 +271,23 @@ function fs.craft(x, y, pos, rank, meta, skin)
.. fs.cost(1.25, 0.875, cost, skin);
if rank > 1 then
local size = "s";
if meta:get_int("size") == SIZE_LARGE then
size = "l";
data = data .. string.format("style[%dx;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", meta:get_int("scale"), skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
.. "button[2.5,0;0.5,0.5;1x;1x]"
.. "button[3.0,0;0.5,0.5;2x;2x]";
if rank > 2 then
data = data .. "button[3.5,0;0.5,0.5;4x;4x]"
.. "button[4.0,0;0.5,0.5;8x;8x]";
end
data = data .. string.format("style[%s;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", size, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
.. "button[0,0;0.5,0.5;s;S]"
.. "button[0.5,0;0.5,0.5;l;L]";
end
if rank > 2 then
local scale = "1x";
if meta:get_int("scale") == SCALE_LARGE then
scale = "4x";
end
data = data .. string.format("style[%s;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", scale, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
.. "button[3.5,0;0.5,0.5;1x;1x]"
.. "button[4.0,0;0.5,0.5;4x;4x]";
end
data = data .. string.format("style[%d;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", meta:get_int("detail") + 1, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
.. "button[1.25,0;0.5,0.5;1;1]"
.. "button[1.75,0;0.5,0.5;2;2]";
.. "button[0.0,0;0.5,0.5;1;1]"
.. "button[0.5,0;0.5,0.5;2;2]";
if rank > 1 then
data = data .. "button[2.25,0;0.5,0.5;3;3]";
data = data .. "button[1.0,0;0.5,0.5;3;3]";
if rank > 2 then
data = data .. "button[2.75,0;0.5,0.5;4;4]";
data = data .. "button[1.5,0;0.5,0.5;4;4]";
end
end
@ -455,10 +448,6 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
local inv = meta:get_inventory();
inv:set_stack("copy_output", 1, cartographer.copy_map_item(inv:get_stack("copy_input", 1)));
end
elseif fields["s"] then
meta:set_int("size", SIZE_SMALL);
elseif fields["l"] then
meta:set_int("size", SIZE_LARGE);
elseif fields["1"] then
meta:set_int("detail", 0);
elseif fields["2"] then
@ -469,8 +458,12 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
meta:set_int("detail", 3);
elseif fields["1x"] then
meta:set_int("scale", SCALE_SMALL);
elseif fields["2x"] then
meta:set_int("scale", SCALE_MEDIUM);
elseif fields["4x"] then
meta:set_int("scale", SCALE_LARGE);
elseif fields["8x"] then
meta:set_int("scale", SCALE_HUGE);
elseif fields["tab1"] then
player_tables[player:get_player_name()].tab = 1;
cartographer.map_sound("cartographer_turn_page", player);
@ -497,7 +490,7 @@ local function setup_table_node(pos)
meta:get_inventory():set_size("copy_input", 1);
meta:get_inventory():set_size("copy_output", 1);
meta:set_int("size", SIZE_SMALL);
meta:set_int("size", MAP_SIZE);
meta:set_int("scale", SCALE_SMALL);
meta:set_int("detail", 0);
end