From ff3b6cf2a5e3d298cecba03ad077d9a3fea27496 Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 10 Aug 2020 15:24:00 -0400 Subject: [PATCH] Save to config, test zoom levels --- conquest/conquest.py | 46 ++++++++++++++++-- .../assets/ck2/{ck2_blank.png => blank.png} | Bin conquest/data/assets/ck2/data.json | 3 ++ .../ck2/{ck2_numbered.png => numbered.png} | Bin 4 files changed, 45 insertions(+), 4 deletions(-) rename conquest/data/assets/ck2/{ck2_blank.png => blank.png} (100%) create mode 100644 conquest/data/assets/ck2/data.json rename conquest/data/assets/ck2/{ck2_numbered.png => numbered.png} (100%) diff --git a/conquest/conquest.py b/conquest/conquest.py index c5febfa..890605b 100644 --- a/conquest/conquest.py +++ b/conquest/conquest.py @@ -22,11 +22,13 @@ class Conquest(commands.Cog): def __init__(self, bot: Red): super().__init__() self.bot = bot - self.config = Config.get_conf(self, identifier=0, force_registration=True) + self.config = Config.get_conf(self, identifier=67111110113117101115116, force_registration=True) default_guild = {} - + default_global = {"current_map": None} self.config.register_guild(**default_guild) + self.config.register_global(**default_global) + self.data_path: pathlib.Path = cog_data_path(self) self.asset_path: Optional[pathlib.Path] = None @@ -39,7 +41,7 @@ class Conquest(commands.Cog): async def load_data(self): self.asset_path = bundled_data_path(self) / "assets" - print(self.asset_path) + self.current_map = await self.config.current_map() @commands.group() async def conquest(self, ctx: commands.Context): @@ -67,6 +69,30 @@ class Conquest(commands.Cog): if ctx.invoked_subcommand is None: pass + @conquest_set.command(name="zoomtest") + async def _conquest_set_zoomtest(self, ctx: commands.Context, x: int, y: int, zoom: float): + """Test the zoom level and position of the current map""" + if self.current_map is None: + await ctx.maybe_send_embed("No map is currently set. See `[p]conquest set map`") + return + + current_map = Image.open(self.data_path / self.current_map / "current.jpg") + + w, h = current_map.size + zoom2 = zoom * 2 + zoomed_map = current_map.crop((x - w / zoom2, y - h / zoom2, x + w / zoom2, y + h / zoom2)) + + # zoomed_map = zoomed_map.resize((w, h), Image.LANCZOS) + + zoomed_map.save(self.data_path / self.current_map / "current_zoomed.jpg", "jpeg") + + await ctx.send( + file=discord.File( + fp=self.data_path / self.current_map / "current_zoomed.jpg", + filename="current_zoomed.jpg", + ) + ) + @conquest_set.command(name="save") async def _conquest_set_save(self, ctx: commands.Context, *, save_name): """Save the current map to be loaded later""" @@ -117,6 +143,8 @@ class Conquest(commands.Cog): return self.current_map = mapname + await self.config.current_map.set(self.current_map) # Save to config too + map_data_path = self.asset_path / mapname / "data.json" with map_data_path.open() as mapdata: self.map_data = json.load(mapdata) @@ -169,8 +197,18 @@ class Conquest(commands.Cog): await ctx.maybe_send_embed("No map is currently set. See `[p]conquest set map`") return + numbers_path = self.asset_path / self.current_map / "numbers.jpg" + if not numbers_path.exists(): + await ctx.send( + file=discord.File( + fp=self.asset_path / self.current_map / "numbered.jpg", + filename="numbered.jpg", + ) + ) + return + current_map = Image.open(self.data_path / self.current_map / "current.jpg") - numbers = Image.open(self.asset_path / self.current_map / "numbers.jpg").convert("L") + numbers = Image.open(numbers_path).convert("L") inverted_map = ImageOps.invert(current_map) diff --git a/conquest/data/assets/ck2/ck2_blank.png b/conquest/data/assets/ck2/blank.png similarity index 100% rename from conquest/data/assets/ck2/ck2_blank.png rename to conquest/data/assets/ck2/blank.png diff --git a/conquest/data/assets/ck2/data.json b/conquest/data/assets/ck2/data.json new file mode 100644 index 0000000..9baa7fa --- /dev/null +++ b/conquest/data/assets/ck2/data.json @@ -0,0 +1,3 @@ +{ + "region_max": 70 +} \ No newline at end of file diff --git a/conquest/data/assets/ck2/ck2_numbered.png b/conquest/data/assets/ck2/numbered.png similarity index 100% rename from conquest/data/assets/ck2/ck2_numbered.png rename to conquest/data/assets/ck2/numbered.png