diff --git a/conquest/__init__.py b/conquest/__init__.py index bb8992e..e190e58 100644 --- a/conquest/__init__.py +++ b/conquest/__init__.py @@ -1,7 +1,6 @@ from redbot.core import data_manager from .conquest import Conquest -from .mapmaker import MapMaker async def setup(bot): @@ -9,7 +8,4 @@ async def setup(bot): data_manager.bundled_data_path(cog) await cog.load_data() - bot.add_cog(cog) - - cog2 = MapMaker(bot) - bot.add_cog(cog2) + bot.add_cog(cog) \ No newline at end of file diff --git a/conquest/conquest.py b/conquest/conquest.py index fb8b280..3959c2f 100644 --- a/conquest/conquest.py +++ b/conquest/conquest.py @@ -2,7 +2,6 @@ import asyncio import json import os import pathlib -from abc import ABC from shutil import copyfile from typing import Optional @@ -41,6 +40,9 @@ class Conquest(commands.Cog): self.ext = None self.ext_format = None + self.mm_current_map = None + self.mm_im = None + async def red_delete_data_for_user(self, **kwargs): """Nothing to delete""" return @@ -62,6 +64,47 @@ class Conquest(commands.Cog): self.ext = self.map_data["extension"] self.ext_format = "JPEG" if self.ext.upper() == "JPG" else self.ext.upper() + @commands.group() + async def mapmaker(self, ctx: commands.context): + """ + Base command for managing current maps or creating new ones + """ + if ctx.invoked_subcommand is None: + pass + + @mapmaker.command(name="save") + async def _mapmaker_save(self, ctx: commands.Context, *, map_name: str): + """Save the current map to the specified map name""" + + @mapmaker.command(name="upload") + async def _mapmaker_upload(self, ctx: commands.Context, map_path=""): + """Load a map image to be modified. Upload one with this command or provide a path""" + message: discord.Message = ctx.message + if not message.attachments and not map_path: + await ctx.maybe_send_embed( + "Either upload an image with this command or provide a path to the image" + ) + return + + if map_path: + map_path = pathlib.Path(map_path) + + if not map_path.exist(): + await ctx.maybe_send_embed("Map not found at that path") + return + + self.mm_im = Image.open(map_path) + + if message.attachments: + attch: discord.Attachment = message.attachments[0] + self.mm_im = Image.frombytes("RGBA", (attch.width, attch.height), attch.read()) + + + @mapmaker.command(name="load") + async def _mapmaker_load(self, ctx: commands.Context, map_name=""): + """Load an existing map to be modified.""" + await ctx.maybe_send_embed("WIP") + @commands.group() async def conquest(self, ctx: commands.Context): """ diff --git a/conquest/info.json b/conquest/info.json index 2687209..d0014fb 100644 --- a/conquest/info.json +++ b/conquest/info.json @@ -2,11 +2,7 @@ "author": [ "Bobloy" ], - "bot_version": [ - 3, - 4, - 0 - ], + "min_bot_version": "3.3.0", "description": "Handle war games by filling in specified territories with colors", "hidden": false, "install_msg": "Thank you for installing Conquest. Get started with `[p]load conquest`, then `[p]help Conquest`", @@ -23,6 +19,8 @@ "axisandallies", "heartsofiron", "conquest", - "rpg" + "rpg", + "mapmaker", + "tool" ] } diff --git a/conquest/mapmaker.py b/conquest/mapmaker.py deleted file mode 100644 index 0cde96a..0000000 --- a/conquest/mapmaker.py +++ /dev/null @@ -1,50 +0,0 @@ -import discord -from redbot.core import Config, commands -from redbot.core.bot import Red - - -class MapMaker(commands.Cog): - """ - Create Maps to be used with Conquest - """ - - def __init__(self, bot: Red): - super().__init__() - self.bot = bot - - self.config = Config.get_conf( - self, identifier=77971127797107101114, force_registration=True - ) - - default_guild = {} - default_global = {} - self.config.register_guild(**default_guild) - self.config.register_global(**default_global) - - async def red_delete_data_for_user(self, **kwargs): - """Nothing to delete""" - return - - @commands.group() - async def mapmaker(self, ctx: commands.context): - """ - Base command for managing current maps or creating new ones - """ - if ctx.invoked_subcommand is None: - pass - - @mapmaker.command(name="upload") - async def _mapmaker_upload(self, ctx: commands.Context, map_path=""): - """Load a map image to be modified. Upload one with this command or provide a path""" - message: discord.Message = ctx.message - if not message.attachments and not map_path: - await ctx.maybe_send_embed( - "Either upload an image with this command or provide a path to the image" - ) - return - await ctx.maybe_send_embed("WIP") - - @mapmaker.command(name="load") - async def _mapmaker_load(self, ctx: commands.Context, map_name=""): - """Load an existing map to be modified.""" - await ctx.maybe_send_embed("WIP") diff --git a/conquest/regioner.py b/conquest/regioner.py index dc77373..cb5b5ea 100644 --- a/conquest/regioner.py +++ b/conquest/regioner.py @@ -121,12 +121,15 @@ class Regioner: already_processed.update(filled) + # TODO: save mask_centers to json + + return self.create_number_mask(base_img, mask_centers) + + def create_number_mask(self, base_img, mask_centers): number_img = Image.new("L", base_img.size, 255) fnt = ImageFont.load_default() d = ImageDraw.Draw(number_img) for mask_num, center in mask_centers.items(): d.text(center, str(mask_num), font=fnt, fill=0) - number_img.save(self.filepath / f"numbers.png", "PNG") - return mask_centers