mapmapker back to conquest.py
This commit is contained in:
parent
0b4e0310f9
commit
11258d3e76
@ -1,7 +1,6 @@
|
|||||||
from redbot.core import data_manager
|
from redbot.core import data_manager
|
||||||
|
|
||||||
from .conquest import Conquest
|
from .conquest import Conquest
|
||||||
from .mapmaker import MapMaker
|
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
@ -9,7 +8,4 @@ async def setup(bot):
|
|||||||
data_manager.bundled_data_path(cog)
|
data_manager.bundled_data_path(cog)
|
||||||
await cog.load_data()
|
await cog.load_data()
|
||||||
|
|
||||||
bot.add_cog(cog)
|
bot.add_cog(cog)
|
||||||
|
|
||||||
cog2 = MapMaker(bot)
|
|
||||||
bot.add_cog(cog2)
|
|
@ -2,7 +2,6 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from abc import ABC
|
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -41,6 +40,9 @@ class Conquest(commands.Cog):
|
|||||||
self.ext = None
|
self.ext = None
|
||||||
self.ext_format = None
|
self.ext_format = None
|
||||||
|
|
||||||
|
self.mm_current_map = None
|
||||||
|
self.mm_im = None
|
||||||
|
|
||||||
async def red_delete_data_for_user(self, **kwargs):
|
async def red_delete_data_for_user(self, **kwargs):
|
||||||
"""Nothing to delete"""
|
"""Nothing to delete"""
|
||||||
return
|
return
|
||||||
@ -62,6 +64,47 @@ class Conquest(commands.Cog):
|
|||||||
self.ext = self.map_data["extension"]
|
self.ext = self.map_data["extension"]
|
||||||
self.ext_format = "JPEG" if self.ext.upper() == "JPG" else self.ext.upper()
|
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()
|
@commands.group()
|
||||||
async def conquest(self, ctx: commands.Context):
|
async def conquest(self, ctx: commands.Context):
|
||||||
"""
|
"""
|
||||||
|
@ -2,11 +2,7 @@
|
|||||||
"author": [
|
"author": [
|
||||||
"Bobloy"
|
"Bobloy"
|
||||||
],
|
],
|
||||||
"bot_version": [
|
"min_bot_version": "3.3.0",
|
||||||
3,
|
|
||||||
4,
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"description": "Handle war games by filling in specified territories with colors",
|
"description": "Handle war games by filling in specified territories with colors",
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"install_msg": "Thank you for installing Conquest. Get started with `[p]load conquest`, then `[p]help Conquest`",
|
"install_msg": "Thank you for installing Conquest. Get started with `[p]load conquest`, then `[p]help Conquest`",
|
||||||
@ -23,6 +19,8 @@
|
|||||||
"axisandallies",
|
"axisandallies",
|
||||||
"heartsofiron",
|
"heartsofiron",
|
||||||
"conquest",
|
"conquest",
|
||||||
"rpg"
|
"rpg",
|
||||||
|
"mapmaker",
|
||||||
|
"tool"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -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")
|
|
@ -121,12 +121,15 @@ class Regioner:
|
|||||||
|
|
||||||
already_processed.update(filled)
|
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)
|
number_img = Image.new("L", base_img.size, 255)
|
||||||
fnt = ImageFont.load_default()
|
fnt = ImageFont.load_default()
|
||||||
d = ImageDraw.Draw(number_img)
|
d = ImageDraw.Draw(number_img)
|
||||||
for mask_num, center in mask_centers.items():
|
for mask_num, center in mask_centers.items():
|
||||||
d.text(center, str(mask_num), font=fnt, fill=0)
|
d.text(center, str(mask_num), font=fnt, fill=0)
|
||||||
|
|
||||||
number_img.save(self.filepath / f"numbers.png", "PNG")
|
number_img.save(self.filepath / f"numbers.png", "PNG")
|
||||||
|
|
||||||
return mask_centers
|
return mask_centers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user