Properly update scale when upgrading a map
This commit is contained in:
parent
7b7f7548ce
commit
40e1f474c1
28
items.lua
28
items.lua
@ -422,7 +422,7 @@ local function copy_map_item(stack)
|
||||
copy_meta:set_int("cartographer:map_id", new_id);
|
||||
copy_meta:set_string("description", map_description(new_id,
|
||||
dest.x, dest.z,
|
||||
dest.w, dest.h));
|
||||
dest.w * dest.scale, dest.h * dest.scale));
|
||||
end
|
||||
|
||||
return copy;
|
||||
@ -446,9 +446,28 @@ local function resize_map_item(meta, size)
|
||||
local map = maps.get(id);
|
||||
map:resize(size, size);
|
||||
|
||||
meta:set_string("description", map_description(id,
|
||||
chunk.from(map.x), chunk.from(map.z),
|
||||
chunk.from(map.w), chunk.from(map.h)));
|
||||
meta:set_string("description", map_description(id, map.x, map.z, map.w * map.scale, map.h * map.scale));
|
||||
end
|
||||
end
|
||||
|
||||
-- Change the scale of the given map item
|
||||
--
|
||||
-- meta: A metadata object containing the map data
|
||||
-- scale: The new scale
|
||||
local function rescale_map_item(meta, scale)
|
||||
local old_scale = meta:get_int("cartographer:scale");
|
||||
|
||||
if old_scale >= scale then
|
||||
return;
|
||||
end
|
||||
|
||||
meta:set_int("cartographer:scale", scale);
|
||||
|
||||
local id = meta:get_int("cartographer:map_id");
|
||||
if id > 0 then
|
||||
local map = maps.get(id);
|
||||
map:rescale(scale);
|
||||
meta:set_string("description", map_description(id, map.x, map.z, map.w * map.scale, map.h * map.scale));
|
||||
end
|
||||
end
|
||||
|
||||
@ -456,4 +475,5 @@ return {
|
||||
create = create_map_item,
|
||||
copy = copy_map_item,
|
||||
resize = resize_map_item,
|
||||
rescale = rescale_map_item,
|
||||
};
|
||||
|
13
map_api.lua
13
map_api.lua
@ -11,6 +11,19 @@ for _,loaded_map in ipairs(map_data.maps) do
|
||||
setmetatable(loaded_map, Map);
|
||||
end
|
||||
|
||||
-- Rescale this map
|
||||
--
|
||||
-- scale: The new scale
|
||||
function Map.rescale(self, scale)
|
||||
if scale >= self.scale then
|
||||
local difference = math.floor(scale / self.scale);
|
||||
|
||||
self.fill = {};
|
||||
self.markers = {};
|
||||
self.scale = scale;
|
||||
end
|
||||
end
|
||||
|
||||
-- Resize this map
|
||||
--
|
||||
-- w: The new width
|
||||
|
@ -716,6 +716,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
||||
local smeta = stack:get_meta();
|
||||
smeta:set_int("cartographer:detail", 1 + detail);
|
||||
map_item.resize(smeta, size);
|
||||
map_item.rescale(smeta, scale);
|
||||
|
||||
local map = maps.get(smeta:get_int("cartographer:map_id"));
|
||||
if map then
|
||||
|
Loading…
Reference in New Issue
Block a user