rest converted, time to fix maps
This commit is contained in:
		
							parent
							
								
									2315bd9fc3
								
							
						
					
					
						commit
						978d6f8627
					
				| @ -1,5 +1,6 @@ | |||||||
| import asyncio | import asyncio | ||||||
| import json | import json | ||||||
|  | import logging | ||||||
| import pathlib | import pathlib | ||||||
| from collections import defaultdict | from collections import defaultdict | ||||||
| from io import BytesIO | from io import BytesIO | ||||||
| @ -20,6 +21,8 @@ from conquest.regioner import ConquestMap, MapMaker, composite_regions | |||||||
| 
 | 
 | ||||||
| ERROR_CONQUEST_SET_MAP = "No map is currently set. See `[p]conquest set map`" | ERROR_CONQUEST_SET_MAP = "No map is currently set. See `[p]conquest set map`" | ||||||
| 
 | 
 | ||||||
|  | log = logging.getLogger("red.fox_v3.conquest") | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class Conquest(commands.Cog): | class Conquest(commands.Cog): | ||||||
|     """ |     """ | ||||||
| @ -83,28 +86,28 @@ class Conquest(commands.Cog): | |||||||
|         """ |         """ | ||||||
|         self.asset_path = bundled_data_path(self) / "assets" |         self.asset_path = bundled_data_path(self) / "assets" | ||||||
|         for guild in self.bot.guilds: |         for guild in self.bot.guilds: | ||||||
|             game_name = await self.config.guild(guild).current_game() |             game_data = await self.config.guild(guild).current_game() | ||||||
|             if game_name is not None: |             if game_data is not None: | ||||||
|                 await self.load_guild_data(guild, game_name) |                 await self.load_guild_data(guild, **game_data) | ||||||
| 
 | 
 | ||||||
|         # for guild_id, game_name in self.current_maps.items(): |         # for guild_id, game_name in self.current_maps.items(): | ||||||
|         #     await self.current_map_load(guild_id, game_name) |         #     await self.current_map_load(guild_id, game_name) | ||||||
| 
 | 
 | ||||||
|     async def load_guild_data(self, guild: discord.Guild, game_name: str): |     async def load_guild_data(self, guild: discord.Guild, map_name: str, is_custom: bool): | ||||||
|         map_data = await self.config.games.get_raw(game_name) |         # map_data = await self.config.games.get_raw(game_name) | ||||||
|         if map_data is None: |         # if map_data is None: | ||||||
|             return False |         #     return False | ||||||
|         map_name = map_data["map_name"] |         # map_name = map_data["map_name"] | ||||||
|         map_path = self._path_if_custom(map_data["is_custom"]) / map_name |         map_path = self._path_if_custom(is_custom) / map_name | ||||||
| 
 | 
 | ||||||
|         if ( |         if ( | ||||||
|             not (self.current_map_folder / guild.id).exists() |             not (self.current_map_folder / str(guild.id)).exists() | ||||||
|             or not (self.current_map_folder / guild.id / map_name).exists() |             or not (self.current_map_folder / str(guild.id) / map_name).exists() | ||||||
|         ): |         ): | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         self.current_games[guild.id] = ConquestGame( |         self.current_games[guild.id] = ConquestGame( | ||||||
|             map_path, map_name, self.current_map_folder / guild.id / map_name |             map_path, map_name, self.current_map_folder / str(guild.id) / map_name | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         return True |         return True | ||||||
| @ -274,7 +277,7 @@ class Conquest(commands.Cog): | |||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         self.mm = MapMaker(map_path) |         self.mm = MapMaker(map_path) | ||||||
|         await self.mm.load_data() |         # await self.mm.load_data() | ||||||
| 
 | 
 | ||||||
|         await ctx.tick() |         await ctx.tick() | ||||||
| 
 | 
 | ||||||
| @ -500,7 +503,7 @@ class Conquest(commands.Cog): | |||||||
| 
 | 
 | ||||||
|     @conquest_set.command(name="map") |     @conquest_set.command(name="map") | ||||||
|     async def _conquest_set_map( |     async def _conquest_set_map( | ||||||
|         self, ctx: Context, mapname: str, is_custom: bool = False, reset: bool = False |         self, ctx: Context, mapname: str, reset: bool = False, is_custom: bool = False | ||||||
|     ): |     ): | ||||||
|         """ |         """ | ||||||
|         Select a map from current available maps |         Select a map from current available maps | ||||||
| @ -516,9 +519,10 @@ class Conquest(commands.Cog): | |||||||
|             ) |             ) | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         self.current_games[ctx.guild.id] = ConquestGame( |         guild_folder = self.current_map_folder / str(ctx.guild.id) | ||||||
|             map_dir, mapname, self.current_map_folder / ctx.guild.id / mapname |         if not guild_folder.exists(): | ||||||
|         ) |             guild_folder.mkdir() | ||||||
|  |         self.current_games[ctx.guild.id] = ConquestGame(map_dir, mapname, guild_folder / mapname) | ||||||
| 
 | 
 | ||||||
|         # self.current_map = mapname |         # self.current_map = mapname | ||||||
|         # self.is_custom = is_custom |         # self.is_custom = is_custom | ||||||
| @ -529,6 +533,12 @@ class Conquest(commands.Cog): | |||||||
| 
 | 
 | ||||||
|         await self.current_games[ctx.guild.id].resume_game(ctx, reset) |         await self.current_games[ctx.guild.id].resume_game(ctx, reset) | ||||||
| 
 | 
 | ||||||
|  |         new_game = self.default_games.copy() | ||||||
|  |         new_game["map_name"] = mapname | ||||||
|  |         new_game["is_custom"] = is_custom | ||||||
|  | 
 | ||||||
|  |         await self.config.guild(ctx.guild).current_game.set(new_game) | ||||||
|  | 
 | ||||||
|         # current_map_folder = await self._get_current_map_folder() |         # current_map_folder = await self._get_current_map_folder() | ||||||
|         # current_map = current_map_folder / f"current.{self.ext}" |         # current_map = current_map_folder / f"current.{self.ext}" | ||||||
|         # |         # | ||||||
| @ -603,7 +613,7 @@ class Conquest(commands.Cog): | |||||||
|             await ctx.maybe_send_embed(f"Invalid color {color}") |             await ctx.maybe_send_embed(f"Invalid color {color}") | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         if start_region < end_region: |         if start_region > end_region: | ||||||
|             start_region, end_region = end_region, start_region |             start_region, end_region = end_region, start_region | ||||||
| 
 | 
 | ||||||
|         if end_region > current_game.region_max or start_region < 1: |         if end_region > current_game.region_max or start_region < 1: | ||||||
| @ -654,4 +664,3 @@ class Conquest(commands.Cog): | |||||||
|             map_file = await current_game.get_maybe_zoomed_map("current") |             map_file = await current_game.get_maybe_zoomed_map("current") | ||||||
| 
 | 
 | ||||||
|         await ctx.send(file=map_file) |         await ctx.send(file=map_file) | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| import asyncio | import asyncio | ||||||
| import json | import json | ||||||
|  | import logging | ||||||
| import pathlib | import pathlib | ||||||
| from shutil import copyfile | from shutil import copyfile | ||||||
| from types import SimpleNamespace | from types import SimpleNamespace | ||||||
| @ -11,6 +12,8 @@ from redbot.core import commands | |||||||
| 
 | 
 | ||||||
| from conquest.regioner import ConquestMap, composite_regions | from conquest.regioner import ConquestMap, composite_regions | ||||||
| 
 | 
 | ||||||
|  | log = logging.getLogger("red.fox_v3.conquest.conquestgame") | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class ConquestGame: | class ConquestGame: | ||||||
|     ext = "PNG" |     ext = "PNG" | ||||||
| @ -35,7 +38,9 @@ class ConquestGame: | |||||||
|         self.numbered_current_map = self.current_map_folder / self.numbered_current_filename |         self.numbered_current_map = self.current_map_folder / self.numbered_current_filename | ||||||
| 
 | 
 | ||||||
|         self.zoomed_numbered_current_filename = f"current_zoomed_numbered.{self.ext}" |         self.zoomed_numbered_current_filename = f"current_zoomed_numbered.{self.ext}" | ||||||
|         self.zoomed_numbered_current_map = self.current_map_folder / self.zoomed_numbered_current_filename |         self.zoomed_numbered_current_map = ( | ||||||
|  |             self.current_map_folder / self.zoomed_numbered_current_filename | ||||||
|  |         ) | ||||||
| 
 | 
 | ||||||
|         self.region_max = self.source_map.region_max |         self.region_max = self.source_map.region_max | ||||||
| 
 | 
 | ||||||
| @ -64,7 +69,7 @@ class ConquestGame: | |||||||
|     async def _process_take_regions(self, color, regions): |     async def _process_take_regions(self, color, regions): | ||||||
|         im = Image.open(self.current_map) |         im = Image.open(self.current_map) | ||||||
| 
 | 
 | ||||||
|         out: Image.Image = await composite_regions( |         out: Optional[Image.Image] = await composite_regions( | ||||||
|             im, |             im, | ||||||
|             regions, |             regions, | ||||||
|             color, |             color, | ||||||
| @ -74,7 +79,9 @@ class ConquestGame: | |||||||
|         # self.zoom_is_out_of_date.current = True |         # self.zoom_is_out_of_date.current = True | ||||||
| 
 | 
 | ||||||
|     async def create_numbered_map(self): |     async def create_numbered_map(self): | ||||||
|         if not self.source_map.numbers_path().exists():  # No numbers map, can't add numbers to current |         if ( | ||||||
|  |             not self.source_map.numbers_path().exists() | ||||||
|  |         ):  # No numbers map, can't add numbers to current | ||||||
|             return self.source_map.numbered_path() |             return self.source_map.numbered_path() | ||||||
| 
 | 
 | ||||||
|         current_map = Image.open(self.current_map) |         current_map = Image.open(self.current_map) | ||||||
| @ -92,7 +99,13 @@ class ConquestGame: | |||||||
|         return self.numbered_current_map |         return self.numbered_current_map | ||||||
| 
 | 
 | ||||||
|     async def create_zoomed_map( |     async def create_zoomed_map( | ||||||
|         self, x, y, zoom, source_map: Union[Image.Image, pathlib.Path], target_path: pathlib.Path, **kwargs |         self, | ||||||
|  |         x, | ||||||
|  |         y, | ||||||
|  |         zoom, | ||||||
|  |         source_map: Union[Image.Image, pathlib.Path], | ||||||
|  |         target_path: pathlib.Path, | ||||||
|  |         **kwargs, | ||||||
|     ): |     ): | ||||||
|         """Pass out_of_date when created a zoomed map based on something other than the settings json""" |         """Pass out_of_date when created a zoomed map based on something other than the settings json""" | ||||||
|         # if out_of_date: |         # if out_of_date: | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| import asyncio | import asyncio | ||||||
| import json | import json | ||||||
|  | import logging | ||||||
| import pathlib | import pathlib | ||||||
| import shutil | import shutil | ||||||
| from io import BytesIO | from io import BytesIO | ||||||
| @ -8,6 +9,8 @@ from typing import List, Union | |||||||
| from PIL import Image, ImageChops, ImageColor, ImageDraw, ImageFont, ImageOps | from PIL import Image, ImageChops, ImageColor, ImageDraw, ImageFont, ImageOps | ||||||
| from PIL.ImageDraw import _color_diff | from PIL.ImageDraw import _color_diff | ||||||
| 
 | 
 | ||||||
|  | log = logging.getLogger("red.fox_v3.conquest.regioner") | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| async def composite_regions(im, regions, color, masks_path) -> Union[Image.Image, None]: | async def composite_regions(im, regions, color, masks_path) -> Union[Image.Image, None]: | ||||||
|     im2 = Image.new("RGB", im.size, color) |     im2 = Image.new("RGB", im.size, color) | ||||||
| @ -137,6 +140,8 @@ 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" | ||||||
| 
 | 
 | ||||||
| @ -152,7 +157,7 @@ class ConquestMap: | |||||||
|     def numbered_path(self): |     def numbered_path(self): | ||||||
|         return self.path / "numbered.png" |         return self.path / "numbered.png" | ||||||
| 
 | 
 | ||||||
|     async def load_data(self): |     def load_data(self): | ||||||
|         with self.data_path().open() as dp: |         with self.data_path().open() as dp: | ||||||
|             data = json.load(dp) |             data = json.load(dp) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 bobloy
						bobloy