diff --git a/items.lua b/items.lua index 26444e0..f5d1065 100644 --- a/items.lua +++ b/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, }; diff --git a/map_api.lua b/map_api.lua index 95e7cd9..2e3ec31 100644 --- a/map_api.lua +++ b/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 diff --git a/table.lua b/table.lua index 709f675..eabaa98 100644 --- a/table.lua +++ b/table.lua @@ -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