Compare commits
58 Commits
master
...
conquest_d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1694dd2d34 | ||
![]() |
3361885882 | ||
![]() |
99e6fce695 | ||
![]() |
ac3d9b5a69 | ||
![]() |
4e35a13577 | ||
![]() |
374c521e71 | ||
![]() |
5ce95038f2 | ||
![]() |
439873de95 | ||
![]() |
393cc6e523 | ||
![]() |
aa84cd1a9e | ||
![]() |
ff7455495d | ||
![]() |
4108069671 | ||
![]() |
ca4cf5408b | ||
![]() |
cd49b07448 | ||
![]() |
6762d3cbde | ||
![]() |
8acca64264 | ||
![]() |
44b724fd71 | ||
![]() |
ee1eaa1d90 | ||
![]() |
9cf466c78e | ||
![]() |
978d6f8627 | ||
![]() |
2315bd9fc3 | ||
![]() |
e02c7ba14b | ||
![]() |
836911ee89 | ||
![]() |
3e25c8a13f | ||
![]() |
d987018664 | ||
![]() |
25e90c350f | ||
![]() |
2d0c9e31b3 | ||
![]() |
80db00890d | ||
![]() |
4496903663 | ||
![]() |
4457d51f07 | ||
![]() |
4cd033bf12 | ||
![]() |
7626bb6a76 | ||
![]() |
664aa63833 | ||
![]() |
500915b947 | ||
![]() |
36d6e5c9bf | ||
![]() |
7574117d9a | ||
![]() |
f0d33f0354 | ||
![]() |
e2e5477661 | ||
![]() |
8abeca3d1e | ||
![]() |
aadd9a61a8 | ||
![]() |
c3c40c594e | ||
![]() |
b46a5920f7 | ||
![]() |
52fc284f5a | ||
![]() |
ef925b1621 | ||
![]() |
719e8903fd | ||
![]() |
07b90c30a0 | ||
![]() |
a1b89c9f9d | ||
![]() |
f93986e65f | ||
![]() |
11258d3e76 | ||
![]() |
0b4e0310f9 | ||
![]() |
5fff65c7d5 | ||
![]() |
8012a20ddb | ||
![]() |
3b156d8275 | ||
![]() |
ae200eb911 | ||
![]() |
7161e8e28c | ||
![]() |
03b42b04ef | ||
![]() |
42aab1e801 | ||
![]() |
dc8d314713 |
BIN
conquest/Map Ideas/162770_ww2v3_basetiles.png
Normal file
After Width: | Height: | Size: 366 KiB |
BIN
conquest/Map Ideas/EU4_Blank_map.png
Normal file
After Width: | Height: | Size: 364 KiB |
BIN
conquest/Map Ideas/HOI4_combined_map.png
Normal file
After Width: | Height: | Size: 416 KiB |
BIN
conquest/Map Ideas/HOI4_province_map.png
Normal file
After Width: | Height: | Size: 348 KiB |
BIN
conquest/Map Ideas/HOI4_state_map.png
Normal file
After Width: | Height: | Size: 205 KiB |
@ -1,7 +1,6 @@
|
||||
from redbot.core import data_manager
|
||||
|
||||
from .conquest import Conquest
|
||||
from .mapmaker import MapMaker
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
@ -10,6 +9,3 @@ async def setup(bot):
|
||||
await cog.load_data()
|
||||
|
||||
bot.add_cog(cog)
|
||||
|
||||
cog2 = MapMaker(bot)
|
||||
bot.add_cog(cog2)
|
||||
|
186
conquest/conquestgame.py
Normal file
@ -0,0 +1,186 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import pathlib
|
||||
from shutil import copyfile
|
||||
from types import SimpleNamespace
|
||||
from typing import Optional, Union
|
||||
|
||||
import discord
|
||||
from PIL import Image, ImageOps
|
||||
from redbot.core import commands
|
||||
|
||||
from conquest.regioner import ConquestMap, composite_regions
|
||||
|
||||
log = logging.getLogger("red.fox_v3.conquest.conquestgame")
|
||||
|
||||
|
||||
class ConquestGame:
|
||||
ext = "PNG"
|
||||
ext_format = "PNG"
|
||||
|
||||
default_zoom_json = {"enabled": False, "x": -1, "y": -1, "zoom": 1.0}
|
||||
|
||||
def __init__(self, map_path: pathlib.Path, game_name: str, custom_map_path: pathlib.Path):
|
||||
self.source_map = ConquestMap(map_path)
|
||||
self.source_map.load_data()
|
||||
self.game_name = game_name
|
||||
self.current_map_folder = custom_map_path
|
||||
|
||||
self.settings_json = self.current_map_folder / "settings.json"
|
||||
|
||||
self.current_filename = f"current.{self.ext}"
|
||||
self.current_map = self.current_map_folder / self.current_filename
|
||||
|
||||
self.zoomed_current_filename = f"current_zoomed.{self.ext}"
|
||||
self.zoomed_current_map = self.current_map_folder / self.zoomed_current_filename
|
||||
|
||||
self.numbered_current_filename = f"current_numbered.{self.ext}"
|
||||
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_map = (
|
||||
self.current_map_folder / self.zoomed_numbered_current_filename
|
||||
)
|
||||
|
||||
self.region_max = self.source_map.region_max
|
||||
|
||||
# self.zoom_is_out_of_date = {'current': True, 'blank': True}
|
||||
|
||||
async def save_region(self, region):
|
||||
if not self.custom:
|
||||
return False
|
||||
pass # TODO: region data saving
|
||||
|
||||
async def start_game(self):
|
||||
if not self.current_map_folder.exists():
|
||||
self.current_map_folder.mkdir()
|
||||
copyfile(self.source_map.blank_path(), self.current_map)
|
||||
|
||||
async def resume_game(self, ctx: commands.Context, reset: bool):
|
||||
|
||||
if not reset and self.current_map.exists():
|
||||
await ctx.maybe_send_embed(
|
||||
"This map is already in progress, resuming from last game\n"
|
||||
"Use `[p]conquest set map [mapname] True` to start a new game"
|
||||
)
|
||||
else:
|
||||
await self.start_game()
|
||||
|
||||
async def _process_take_regions(self, color, regions):
|
||||
im = Image.open(self.current_map)
|
||||
|
||||
out: Optional[Image.Image] = await composite_regions(
|
||||
im,
|
||||
regions,
|
||||
color,
|
||||
self.source_map.masks_path(),
|
||||
)
|
||||
out.save(self.current_map, self.ext_format) # Overwrite current map with new map
|
||||
# self.zoom_is_out_of_date.current = True
|
||||
|
||||
async def create_numbered_map(self):
|
||||
if (
|
||||
not self.source_map.numbers_path().exists()
|
||||
): # No numbers map, can't add numbers to current
|
||||
return self.source_map.numbered_path()
|
||||
|
||||
current_map = Image.open(self.current_map)
|
||||
numbers = Image.open(self.source_map.numbers_path()).convert("L")
|
||||
|
||||
inverted_map = ImageOps.invert(current_map)
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
current_numbered_img = await loop.run_in_executor(
|
||||
None, Image.composite, current_map, inverted_map, numbers
|
||||
)
|
||||
|
||||
current_numbered_img.save(self.numbered_current_map, self.ext_format)
|
||||
|
||||
return self.numbered_current_map
|
||||
|
||||
async def create_zoomed_map(
|
||||
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"""
|
||||
# if out_of_date:
|
||||
# self.zoom_is_out_of_date.current = True
|
||||
|
||||
# if current_map is None:
|
||||
# current_map = Image.open(self.current_map_folder)
|
||||
# target_map = self.zoomed_current_map
|
||||
|
||||
if not isinstance(source_map, Image.Image):
|
||||
source_map = Image.open(source_map)
|
||||
|
||||
w, h = source_map.size
|
||||
zoom2 = zoom * 2
|
||||
zoomed_map = source_map.crop((x - w / zoom2, y - h / zoom2, x + w / zoom2, y + h / zoom2))
|
||||
# zoomed_map = zoomed_map.resize((w, h), Image.LANCZOS)
|
||||
zoomed_map.save(target_path, self.ext_format)
|
||||
|
||||
return True
|
||||
|
||||
async def get_maybe_zoomed_map(self, version):
|
||||
zoom_data = {"enabled": False}
|
||||
|
||||
if self.settings_json.exists():
|
||||
with self.settings_json.open() as zoom_json:
|
||||
zoom_data = json.load(zoom_json)
|
||||
|
||||
if version == "numbered":
|
||||
map_path = self.create_numbered_map()
|
||||
zoomed_path = self.zoomed_numbered_current_map
|
||||
else: # version == "current"
|
||||
map_path = self.current_map
|
||||
zoomed_path = self.zoomed_current_map
|
||||
|
||||
if zoom_data["enabled"]: # Send zoomed map instead of current map
|
||||
# if self.zoom_is_out_of_date:
|
||||
await self.create_zoomed_map(**zoom_data, source_map=map_path, target_map=zoomed_path)
|
||||
map_path = zoomed_path
|
||||
# self.zoom_is_out_of_date = False
|
||||
|
||||
return discord.File(fp=map_path) # lol file names
|
||||
|
||||
async def reset_zoom(self):
|
||||
if not self.settings_json.exists():
|
||||
return False
|
||||
|
||||
with self.settings_json.open("w+") as zoom_json:
|
||||
json.dump({"enabled": False}, zoom_json, sort_keys=True, indent=4)
|
||||
|
||||
# self.zoom_is_out_of_date = True
|
||||
|
||||
return True
|
||||
|
||||
async def set_zoom(self, x, y, zoom):
|
||||
|
||||
zoom_data = self.default_zoom_json.copy()
|
||||
zoom_data["enabled"] = True
|
||||
zoom_data["x"] = x
|
||||
zoom_data["y"] = y
|
||||
zoom_data["zoom"] = zoom
|
||||
|
||||
# self.zoom_is_out_of_date = True
|
||||
|
||||
with self.settings_json.open("w+") as zoom_json:
|
||||
json.dump(zoom_data, zoom_json, sort_keys=True, indent=4)
|
||||
|
||||
async def save_as(self, save_name):
|
||||
copyfile(self.current_map, self.current_map_folder / f"{save_name}.{self.ext}")
|
||||
|
||||
async def load_from(self, save_name):
|
||||
saved_map = self.current_map_folder / f"{save_name}.{self.ext}"
|
||||
|
||||
if not saved_map.exists():
|
||||
return False
|
||||
|
||||
copyfile(saved_map, self.current_map) # Overwrite current map with saved map
|
||||
return True
|
Before Width: | Height: | Size: 345 KiB After Width: | Height: | Size: 374 KiB |
BIN
conquest/data/assets/ck2/masks/1.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
conquest/data/assets/ck2/masks/10.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
conquest/data/assets/ck2/masks/100.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
conquest/data/assets/ck2/masks/1000.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1001.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1002.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1003.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
conquest/data/assets/ck2/masks/1004.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1005.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
conquest/data/assets/ck2/masks/1006.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1007.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
conquest/data/assets/ck2/masks/1008.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1009.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/101.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
conquest/data/assets/ck2/masks/1010.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1011.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
conquest/data/assets/ck2/masks/1012.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1013.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1014.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1015.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1016.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1017.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1018.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1019.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/102.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1020.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1021.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
conquest/data/assets/ck2/masks/1022.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1023.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1024.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1025.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1026.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1027.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1028.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1029.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/103.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1030.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1031.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1032.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1033.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1034.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
conquest/data/assets/ck2/masks/1035.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1036.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
conquest/data/assets/ck2/masks/1037.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1038.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
conquest/data/assets/ck2/masks/1039.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/104.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
conquest/data/assets/ck2/masks/1040.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1041.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1042.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1043.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1044.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1045.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1046.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1047.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1048.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1049.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
conquest/data/assets/ck2/masks/105.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
conquest/data/assets/ck2/masks/1050.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1051.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1052.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1053.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1054.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1055.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1056.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1057.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
conquest/data/assets/ck2/masks/1058.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
conquest/data/assets/ck2/masks/1059.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/106.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
conquest/data/assets/ck2/masks/1060.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1061.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1062.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1063.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1064.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1065.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1066.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
conquest/data/assets/ck2/masks/1067.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1068.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1069.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/107.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1070.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1071.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1072.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1073.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
conquest/data/assets/ck2/masks/1074.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
conquest/data/assets/ck2/masks/1075.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
conquest/data/assets/ck2/masks/1076.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1077.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
conquest/data/assets/ck2/masks/1078.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
conquest/data/assets/ck2/masks/1079.png
Normal file
After Width: | Height: | Size: 4.3 KiB |