Functioning map maker

conquest_develop
bobloy 3 years ago
parent 978d6f8627
commit 9cf466c78e

@ -161,7 +161,7 @@ class Conquest(commands.Cog):
@mapmaker.command(name="save") @mapmaker.command(name="save")
async def _mapmaker_save(self, ctx: Context, *, map_name: str): async def _mapmaker_save(self, ctx: Context, *, map_name: str):
"""Save the current map to the specified map name""" """Save the current map to a different map name"""
if not self.mm: if not self.mm:
await ctx.maybe_send_embed("No map currently being worked on") await ctx.maybe_send_embed("No map currently being worked on")
return return
@ -179,10 +179,10 @@ class Conquest(commands.Cog):
await ctx.maybe_send_embed(f"Map successfully saved to {target_save}") await ctx.maybe_send_embed(f"Map successfully saved to {target_save}")
@mapmaker.command(name="upload") @mapmaker.command(name="upload")
async def _mapmaker_upload(self, ctx: Context, map_name: str, map_path=""): async def _mapmaker_upload(self, ctx: Context, map_name: str, path_to_image=""):
"""Load a map image to be modified. Upload one with this command or provide a path""" """Load a map image to be modified. Upload one with this command or provide a path"""
message: discord.Message = ctx.message message: discord.Message = ctx.message
if not message.attachments and not map_path: if not message.attachments and not path_to_image:
await ctx.maybe_send_embed( await ctx.maybe_send_embed(
"Either upload an image with this command or provide a path to the image" "Either upload an image with this command or provide a path to the image"
) )
@ -202,18 +202,24 @@ class Conquest(commands.Cog):
if not pred.result: if not pred.result:
return return
if not self.mm: if self.mm: # Only one map can be worked on at a time
self.mm = MapMaker(self.custom_map_folder) await ctx.maybe_send_embed(
"An existing map is in progress, close it before opening a new one. (`[p]mapmaker close`)"
)
return
async with ctx.typing():
self.mm = MapMaker(target_save)
self.mm.custom = True self.mm.custom = True
if map_path: if path_to_image:
map_path = pathlib.Path(map_path) path_to_image = pathlib.Path(path_to_image)
if not map_path.exists(): if not path_to_image.exists():
await ctx.maybe_send_embed("Map not found at that path") await ctx.maybe_send_embed("Map not found at that path")
return return
mm_img = Image.open(map_path) mm_img = Image.open(path_to_image)
elif message.attachments: elif message.attachments:
attch: discord.Attachment = message.attachments[0] attch: discord.Attachment = message.attachments[0]
@ -248,15 +254,19 @@ class Conquest(commands.Cog):
await ctx.maybe_send_embed(f"Map successfully uploaded to {target_save}") await ctx.maybe_send_embed(f"Map successfully uploaded to {target_save}")
@mapmaker.command(name="sample") @mapmaker.command(name="sample")
async def _mapmaker_sample(self, ctx: Context): async def _mapmaker_sample(self, ctx: Context, region: int = None):
"""Print the currently being modified map as a sample""" """Print the currently being modified map as a sample"""
if not self.mm: if not self.mm:
await ctx.maybe_send_embed("No map currently being worked on") await ctx.maybe_send_embed("No map currently being worked on")
return return
if region is not None and region not in self.mm.regions:
await ctx.send("This region doesn't exist or was deleted")
return
async with ctx.typing(): async with ctx.typing():
files = await self.mm.get_sample() files = await self.mm.get_sample(region)
for f in files: for f in files:
await ctx.send(file=discord.File(f, filename="map.png")) await ctx.send(file=discord.File(f, filename="map.png"))
@ -277,7 +287,7 @@ class Conquest(commands.Cog):
return return
self.mm = MapMaker(map_path) self.mm = MapMaker(map_path)
# await self.mm.load_data() self.mm.load_data()
await ctx.tick() await ctx.tick()
@ -338,11 +348,11 @@ class Conquest(commands.Cog):
else: else:
await ctx.maybe_send_embed(f"Failed to delete masks") await ctx.maybe_send_embed(f"Failed to delete masks")
@_mapmaker_masks.command(name="combine") @_mapmaker_masks.command(name="merge", aliases=["combine"])
async def _mapmaker_masks_combine( async def _mapmaker_masks_combine(
self, ctx: Context, mask_list: Greedy[int], recommended=False self, ctx: Context, mask_list: Greedy[int], recommended=False
): ):
"""Generate masks for the map""" """Merge masks into a single mask"""
if not mask_list and not recommended: if not mask_list and not recommended:
await ctx.send_help() await ctx.send_help()
return return

@ -23,6 +23,7 @@ class ConquestGame:
def __init__(self, map_path: pathlib.Path, game_name: str, custom_map_path: pathlib.Path): def __init__(self, map_path: pathlib.Path, game_name: str, custom_map_path: pathlib.Path):
self.source_map = ConquestMap(map_path) self.source_map = ConquestMap(map_path)
self.source_map.load_data()
self.game_name = game_name self.game_name = game_name
self.current_map_folder = custom_map_path self.current_map_folder = custom_map_path

@ -107,7 +107,7 @@ def floodfill(image, xy, value, border=None, thresh=0) -> set:
new_edge.add((s, t)) new_edge.add((s, t))
full_edge = edge # discard pixels processed full_edge = edge # discard pixels processed
edge = new_edge edge = new_edge
return filled_pixels return filled_pixels # Modified to returned the filled pixels
def create_number_mask(regions, filepath, filename): def create_number_mask(regions, filepath, filename):
@ -140,8 +140,6 @@ class ConquestMap:
self.region_max = None self.region_max = None
self.regions = {} self.regions = {}
self.load_data()
def masks_path(self): def masks_path(self):
return self.path / "masks" return self.path / "masks"
@ -202,7 +200,7 @@ class ConquestMap:
return lowest_num, eliminated_masks, mask return lowest_num, eliminated_masks, mask
async def get_sample(self): async def get_sample(self, region=None):
files = [self.blank_path()] files = [self.blank_path()]
masks_dir = self.masks_path() masks_dir = self.masks_path()
@ -210,7 +208,14 @@ class ConquestMap:
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
current_map = Image.open(self.blank_path()) current_map = Image.open(self.blank_path())
if region is not None:
if region in self.regions:
current_map = await composite_regions(
current_map, [region], ImageColor.getrgb("red"), self.masks_path()
)
else:
regions = list(self.regions.keys()) regions = list(self.regions.keys())
fourth = len(regions) // 4 fourth = len(regions) // 4
current_map = await composite_regions( current_map = await composite_regions(

Loading…
Cancel
Save