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

View File

@ -1,7 +1,8 @@
local SIZE_SMALL = 20; local MAP_SIZE = 40;
local SIZE_LARGE = 40;
local SCALE_SMALL = 1; local SCALE_SMALL = 1;
local SCALE_MEDIUM = 2;
local SCALE_LARGE = 4; local SCALE_LARGE = 4;
local SCALE_HUGE = 8;
-- Draw background elements in the same arrangement as inventory slots -- Draw background elements in the same arrangement as inventory slots
-- x: The x position of the inventory -- x: The x position of the inventory
@ -25,20 +26,23 @@ local function inventory_bg(x, y, cols, rows, skin)
return data; return data;
end end
local function get_material_cost(size, detail) -- Get the material cost for the given map scale and detail level
local paper = 0; -- scale: The map scale
local pigment = 0; -- detail: The detail level
local function get_material_cost(scale, detail)
local paper = scale * 4;
local pigment = detail * 5;
if size == SIZE_SMALL then if scale == SCALE_SMALL then
paper = paper + 4;
pigment = pigment + 5; pigment = pigment + 5;
elseif size == SIZE_LARGE then elseif scale == SCALE_MEDIUM then
paper = paper + 16; pigment = pigment + 10;
elseif scale == SCALE_LARGE then
pigment = pigment + 15;
elseif scale == SCALE_HUGE then
pigment = pigment + 20; pigment = pigment + 20;
end end
pigment = pigment + (detail * 5);
return { return {
paper = math.max(paper, 0), paper = math.max(paper, 0),
pigment = math.max(pigment, 0), pigment = math.max(pigment, 0),
@ -51,13 +55,13 @@ end
-- Returns a table with the material costs, and a boolean indicating if the -- Returns a table with the material costs, and a boolean indicating if the
-- costs were positive or negative before clamping. -- costs were positive or negative before clamping.
local function get_craft_material_cost(meta) 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 stack = meta:get_inventory():get_stack("output", 1);
local is_positive = true; local is_positive = true;
if stack:get_name() == "cartographer:map" then if stack:get_name() == "cartographer:map" then
local smeta = stack:get_meta(); 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; is_positive = cost.paper >= sub_cost.paper and cost.pigment >= sub_cost.pigment;
cost.paper = math.max(cost.paper - sub_cost.paper, 0); cost.paper = math.max(cost.paper - sub_cost.paper, 0);
cost.pigment = math.max(cost.pigment - sub_cost.pigment, 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 if out_stack:is_empty() and in_stack:get_name() == "cartographer:map" then
local smeta = in_stack:get_meta(); 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; local detail = smeta:get_int("cartographer:detail") or 1;
return get_material_cost(size, detail - 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); .. fs.cost(1.25, 0.875, cost, skin);
if rank > 1 then if rank > 1 then
local size = "s"; 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)
if meta:get_int("size") == SIZE_LARGE then .. "button[2.5,0;0.5,0.5;1x;1x]"
size = "l"; .. "button[3.0,0;0.5,0.5;2x;2x]";
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 if rank > 2 then
local scale = "1x"; data = data .. "button[3.5,0;0.5,0.5;4x;4x]"
if meta:get_int("scale") == SCALE_LARGE then .. "button[4.0,0;0.5,0.5;8x;8x]";
scale = "4x";
end 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 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) 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[0.0,0;0.5,0.5;1;1]"
.. "button[1.75,0;0.5,0.5;2;2]"; .. "button[0.5,0;0.5,0.5;2;2]";
if rank > 1 then 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 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
end end
@ -455,10 +448,6 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
local inv = meta:get_inventory(); local inv = meta:get_inventory();
inv:set_stack("copy_output", 1, cartographer.copy_map_item(inv:get_stack("copy_input", 1))); inv:set_stack("copy_output", 1, cartographer.copy_map_item(inv:get_stack("copy_input", 1)));
end 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 elseif fields["1"] then
meta:set_int("detail", 0); meta:set_int("detail", 0);
elseif fields["2"] then elseif fields["2"] then
@ -469,8 +458,12 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
meta:set_int("detail", 3); meta:set_int("detail", 3);
elseif fields["1x"] then elseif fields["1x"] then
meta:set_int("scale", SCALE_SMALL); meta:set_int("scale", SCALE_SMALL);
elseif fields["2x"] then
meta:set_int("scale", SCALE_MEDIUM);
elseif fields["4x"] then elseif fields["4x"] then
meta:set_int("scale", SCALE_LARGE); meta:set_int("scale", SCALE_LARGE);
elseif fields["8x"] then
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;
cartographer.map_sound("cartographer_turn_page", player); 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_input", 1);
meta:get_inventory():set_size("copy_output", 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("scale", SCALE_SMALL);
meta:set_int("detail", 0); meta:set_int("detail", 0);
end end