diff --git a/conquest/conquest.py b/conquest/conquest.py index bd806d7..9b7eec6 100644 --- a/conquest/conquest.py +++ b/conquest/conquest.py @@ -58,7 +58,7 @@ class Conquest(commands.Cog): self.asset_path: Optional[pathlib.Path] = None - self.current_games: Dict[int, Optional[ConquestGame]] = defaultdict(lambda: None) # key, value = guild.id, game_name + self.current_games: Dict[int, Optional[ConquestGame]] = defaultdict(lambda: None) # key: guild_id self.map_data = {} # key, value = guild.id, ConquestGame self.mm: Optional[MapMaker] = None @@ -462,10 +462,7 @@ class Conquest(commands.Cog): await ctx.send_help() return - map_folder = await self._get_current_map_folder(ctx.guild) - zoomed_path = await self._create_zoomed_map( - map_folder, map_folder / f"current.{self.ext}", x, y, zoom - ) + zoomed_path = await self.current_games[ctx.guild.id].create_zoomed_map(x, y, zoom, out_of_date=True) await ctx.send(file=discord.File(fp=zoomed_path, filename=f"current_zoomed.{self.ext}")) diff --git a/conquest/conquestgame.py b/conquest/conquestgame.py index 2bdaec6..ecc5fcf 100644 --- a/conquest/conquestgame.py +++ b/conquest/conquestgame.py @@ -45,9 +45,6 @@ class ConquestGame: self.zoom_is_out_of_date = True async def create_zoomed_map(self, x, y, zoom, **kwargs): - if not self.zoom_is_out_of_date: - return self.zoomed_map - current_map = Image.open(self.current_map_folder) w, h = current_map.size @@ -67,8 +64,10 @@ class ConquestGame: map_path = self.current_map - if zoom_data["enabled"]: - map_path = await self.create_zoomed_map(**zoom_data) # Send zoomed map instead of current map + if zoom_data["enabled"]: # Send zoomed map instead of current map + map_path = self.zoomed_map + if self.zoom_is_out_of_date: + await self.create_zoomed_map(**zoom_data) return discord.File(fp=map_path, filename=filename) @@ -79,6 +78,8 @@ class ConquestGame: with self.settings_json.open("w+") as zoom_json: json.dump({"enabled": False}, zoom_json, sort_keys=True, indent=4) + self.zoom_is_out_of_date = True + return True async def set_zoom(self, x, y, zoom): @@ -89,6 +90,8 @@ class ConquestGame: zoom_data["y"] = y zoom_data["zoom"] = zoom + self.zoom_is_out_of_date = True + with self.settings_json.open("w+") as zoom_json: json.dump(zoom_data, zoom_json, sort_keys=True, indent=4)