ALl masks, mostly working commands
@ -1,15 +1,15 @@
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
from io import BytesIO
|
||||
from shutil import copyfile
|
||||
from typing import Optional
|
||||
|
||||
import discord
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageColor
|
||||
from discord.ext.commands import Greedy
|
||||
from redbot.core import Config, commands
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.data_manager import bundled_data_path, cog_data_path
|
||||
from shutil import copyfile
|
||||
|
||||
|
||||
class Conquest(commands.Cog):
|
||||
@ -39,6 +39,7 @@ class Conquest(commands.Cog):
|
||||
|
||||
async def load_data(self):
|
||||
self.asset_path = bundled_data_path(self) / "assets"
|
||||
print(self.asset_path)
|
||||
|
||||
@commands.group()
|
||||
async def conquest(self, ctx: commands.Context):
|
||||
@ -54,34 +55,55 @@ class Conquest(commands.Cog):
|
||||
List currently available maps
|
||||
"""
|
||||
maps_json = self.asset_path / "maps.json"
|
||||
|
||||
async with maps_json.open() as maps:
|
||||
map_list = "\n".join(map_name for map_name in maps["maps"])
|
||||
|
||||
with maps_json.open() as maps:
|
||||
maps_json = json.load(maps)
|
||||
map_list = "\n".join(map_name for map_name in maps_json["maps"])
|
||||
await ctx.maybe_send_embed(f"Current maps:\n{map_list}")
|
||||
|
||||
@conquest.command(name="current")
|
||||
async def _conquest_current(self, ctx: commands.Context):
|
||||
"""
|
||||
Send the current map.
|
||||
"""
|
||||
if self.current_map:
|
||||
await ctx.maybe_send_embed(
|
||||
"No map is currently set. See `[p]conquestset map`"
|
||||
)
|
||||
return
|
||||
|
||||
current_jpg = self.data_path / self.current_map / "current.jpg"
|
||||
with current_jpg.open() as map_file:
|
||||
await ctx.send(file=discord.File(fp=map_file, filename="current_map.jpg"))
|
||||
|
||||
@conquest.group(name="set")
|
||||
async def conquest_set(self, ctx: commands.Context):
|
||||
"""Base command for admin actions like selecting a map"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
pass
|
||||
|
||||
@conquest_set.command(name="save")
|
||||
async def _conquest_set_save(self, ctx: commands.Context, *, save_name):
|
||||
"""Save the current map to be loaded later"""
|
||||
if self.current_map is None:
|
||||
await ctx.maybe_send_embed("No map is currently set. See `[p]conquest set map`")
|
||||
return
|
||||
|
||||
current_map_folder = self.data_path / self.current_map
|
||||
current_map = current_map_folder / "current.jpg"
|
||||
|
||||
if not current_map_folder.exists() or not current_map.exists():
|
||||
await ctx.maybe_send_embed("Current map doesn't exist! Try settin a new one")
|
||||
return
|
||||
|
||||
copyfile(current_map, current_map_folder / f"{save_name}.jpg")
|
||||
await ctx.tick()
|
||||
|
||||
@conquest_set.command(name="load")
|
||||
async def _conquest_set_load(self, ctx: commands.Context, *, save_name):
|
||||
"""Load a saved map to be 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_folder = self.data_path / self.current_map
|
||||
current_map = current_map_folder / "current.jpg"
|
||||
saved_map = current_map_folder / f"{save_name}.jpg"
|
||||
|
||||
if not current_map_folder.exists() or not saved_map.exists():
|
||||
await ctx.maybe_send_embed(f"Saved map not found in the {self.current_map} folder")
|
||||
return
|
||||
|
||||
copyfile(saved_map, current_map)
|
||||
await ctx.tick()
|
||||
|
||||
@conquest_set.command(name="map")
|
||||
async def _conquest_set_map(self, ctx: commands.Context, mapname: str):
|
||||
async def _conquest_set_map(self, ctx: commands.Context, mapname: str, reset: bool = False):
|
||||
"""
|
||||
Select a map from current available maps
|
||||
|
||||
@ -95,32 +117,48 @@ class Conquest(commands.Cog):
|
||||
return
|
||||
|
||||
self.current_map = mapname
|
||||
async with open(self.asset_path / mapname / "data.json") as mapdata:
|
||||
map_data_path = self.asset_path / mapname / "data.json"
|
||||
with map_data_path.open() as mapdata:
|
||||
self.map_data = json.load(mapdata)
|
||||
|
||||
current_map = self.data_path / self.current_map / "current.jpg"
|
||||
if current_map.exists():
|
||||
current_map_folder = self.data_path / self.current_map
|
||||
current_map = current_map_folder / "current.jpg"
|
||||
|
||||
if not reset and current_map.exists():
|
||||
await ctx.maybe_send_embed(
|
||||
"This map is already in progress, resuming from last game"
|
||||
"This map is already in progress, resuming from last game\n"
|
||||
"Use `[p]conquest set map [mapname] True` to start a new game"
|
||||
)
|
||||
else:
|
||||
if not current_map_folder.exists():
|
||||
os.makedirs(current_map_folder)
|
||||
copyfile(self.asset_path / mapname / "blank.jpg", current_map)
|
||||
|
||||
await ctx.tick()
|
||||
|
||||
@conquest.command(name="current")
|
||||
async def _conquest_current(self, ctx: commands.Context):
|
||||
"""
|
||||
Send 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_jpg = self.data_path / self.current_map / "current.jpg"
|
||||
await ctx.send(file=discord.File(fp=current_jpg, filename="current_map.jpg"))
|
||||
|
||||
@conquest.command("blank")
|
||||
async def _conquest_blank(self, ctx: commands.Context):
|
||||
"""
|
||||
Print the blank version of the current map, for reference.
|
||||
"""
|
||||
if self.current_map is None:
|
||||
await ctx.maybe_send_embed(
|
||||
"No map is currently set. See `[p]conquest set map`"
|
||||
)
|
||||
await ctx.maybe_send_embed("No map is currently set. See `[p]conquest set map`")
|
||||
return
|
||||
|
||||
with open(self.asset_path / self.current_map / "blank.jpg") as map_file:
|
||||
await ctx.send(file=discord.File(fp=map_file, filename="blank_map.jpg"))
|
||||
current_blank_jpg = self.asset_path / self.current_map / "blank.jpg"
|
||||
await ctx.send(file=discord.File(fp=current_blank_jpg, filename="blank_map.jpg"))
|
||||
|
||||
@conquest.command("numbered")
|
||||
async def _conquest_numbered(self, ctx: commands.Context):
|
||||
@ -128,18 +166,14 @@ class Conquest(commands.Cog):
|
||||
Print the numbered version of the current map, for reference.
|
||||
"""
|
||||
if self.current_map is None:
|
||||
await ctx.maybe_send_embed(
|
||||
"No map is currently set. See `[p]conquest set map`"
|
||||
)
|
||||
await ctx.maybe_send_embed("No map is currently set. See `[p]conquest set map`")
|
||||
return
|
||||
|
||||
with open(self.asset_path / self.current_map / "numbered.jpg") as map_file:
|
||||
await ctx.send(file=discord.File(fp=map_file, filename="numbered_map.jpg"))
|
||||
current_numbered_jpg = self.asset_path / self.current_map / "numbered.jpg"
|
||||
await ctx.send(file=discord.File(fp=current_numbered_jpg, filename="numbered_map.jpg"))
|
||||
|
||||
@conquest.command(name="take")
|
||||
async def _conquest_take(
|
||||
self, ctx: commands.Context, regions: Greedy[int], color: str
|
||||
):
|
||||
async def _conquest_take(self, ctx: commands.Context, regions: Greedy[int], *, color: str):
|
||||
"""
|
||||
Claim a territory or list of territories for a specified color
|
||||
|
||||
@ -151,9 +185,13 @@ class Conquest(commands.Cog):
|
||||
return
|
||||
|
||||
if self.current_map is None:
|
||||
await ctx.maybe_send_embed(
|
||||
"No map is currently set. See `[p]conquest set map`"
|
||||
)
|
||||
await ctx.maybe_send_embed("No map is currently set. See `[p]conquest set map`")
|
||||
return
|
||||
|
||||
try:
|
||||
color = ImageColor.getrgb(color)
|
||||
except ValueError:
|
||||
await ctx.maybe_send_embed(f"Invalid color {color}")
|
||||
return
|
||||
|
||||
for region in regions:
|
||||
@ -162,23 +200,22 @@ class Conquest(commands.Cog):
|
||||
f"Max region number is {self.map_data['region_max']}, minimum is 1"
|
||||
)
|
||||
|
||||
im = Image.open(self.data_path / self.current_map / "current.jpg")
|
||||
current_jpg_path = self.data_path / self.current_map / "current.jpg"
|
||||
im = Image.open(current_jpg_path)
|
||||
out: Image.Image = await self._composite_image(im, regions, color)
|
||||
|
||||
out.save(self.data_path / self.current_map / "current.jpg", "jpeg")
|
||||
out.save(current_jpg_path, "jpeg")
|
||||
|
||||
output_buffer = BytesIO()
|
||||
out.save(output_buffer, "jpeg")
|
||||
output_buffer.seek(0)
|
||||
|
||||
await ctx.send(file=discord.File(fp=output_buffer, filename="map.jpg"))
|
||||
await ctx.send(file=discord.File(fp=current_jpg_path, filename="map.jpg"))
|
||||
|
||||
async def _composite_image(self, im, regions, color) -> Image.Image:
|
||||
|
||||
im2 = Image.new("RGB", im.size, color)
|
||||
|
||||
out = None
|
||||
for region in regions:
|
||||
mask = Image.open(
|
||||
self.asset_path / f"simple_blank_map/masks/{region}.jpg"
|
||||
self.asset_path / self.current_map / "masks" / f"{region}.jpg"
|
||||
).convert("L")
|
||||
if out is None:
|
||||
out = Image.composite(im, im2, mask)
|
||||
|
BIN
conquest/data/assets/HoI_blank.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/10.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/11.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/12.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/13.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/14.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/15.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/16.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/17.jpg
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/18.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/19.jpg
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/2.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/20.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/21.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/22.jpg
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/23.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/24.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/25.jpg
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/26.jpg
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/27.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/28.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/29.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/3.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/30.jpg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/31.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/32.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/33.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/34.jpg
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/35.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/36.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/37.jpg
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/38.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/39.jpg
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/4.jpg
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/40.jpg
Normal file
After Width: | Height: | Size: 56 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/41.jpg
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/42.jpg
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/43.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/44.jpg
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/45.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/46.jpg
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/47.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/48.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/49.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/5.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/50.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/51.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/52.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/53.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/54.jpg
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/55.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/56.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/57.jpg
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/58.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/59.jpg
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/6.jpg
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/60.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/61.jpg
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/62.jpg
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/63.jpg
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/64.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/65.jpg
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/66.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/67.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/68.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/69.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/7.jpg
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/70.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/8.jpg
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
conquest/data/assets/simple_blank_map/masks/9.jpg
Normal file
After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 334 KiB After Width: | Height: | Size: 480 KiB |