|
|
|
@ -176,7 +176,7 @@ class ConquestMap:
|
|
|
|
|
"name": self.name,
|
|
|
|
|
"custom": self.custom,
|
|
|
|
|
"region_max": self.region_max,
|
|
|
|
|
"regions": {num: r.get_json() for num, r in self.regions.items()}
|
|
|
|
|
"regions": {num: r.get_json() for num, r in self.regions.items()},
|
|
|
|
|
}
|
|
|
|
|
with self.data_path().open("w+") as dp:
|
|
|
|
|
json.dump(to_save, dp, sort_keys=True, indent=4)
|
|
|
|
@ -210,6 +210,7 @@ class ConquestMap:
|
|
|
|
|
self.region_max = len(regions) + 1
|
|
|
|
|
|
|
|
|
|
await self.save_data()
|
|
|
|
|
return regions
|
|
|
|
|
|
|
|
|
|
async def create_number_mask(self):
|
|
|
|
|
regioner = Regioner(filename="blank.png", filepath=self.path)
|
|
|
|
@ -223,14 +224,19 @@ class ConquestMap:
|
|
|
|
|
if not lowest:
|
|
|
|
|
return lowest
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
elim_regions = [self.regions[n] for n in eliminated]
|
|
|
|
|
lowest_region = self.regions[lowest]
|
|
|
|
|
except KeyError:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# points = [self.mm["regions"][f"{n}"]["center"] for n in mask_list]
|
|
|
|
|
#
|
|
|
|
|
# points = [(r.center, r.weight) for r in elim_regions]
|
|
|
|
|
|
|
|
|
|
weighted_points = [r.center for r in elim_regions for _ in range(r.weight)]
|
|
|
|
|
weighted_points = [r.center for r in elim_regions for _ in range(r.weight)] + [
|
|
|
|
|
lowest_region.center for _ in range(lowest_region.weight)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
lowest_region.center = get_center(weighted_points)
|
|
|
|
|
|
|
|
|
@ -245,7 +251,7 @@ class ConquestMap:
|
|
|
|
|
|
|
|
|
|
await self.save_data()
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
return lowest
|
|
|
|
|
|
|
|
|
|
def _img_combine_masks(self, mask_list: List[int]):
|
|
|
|
|
if not mask_list:
|
|
|
|
@ -345,11 +351,7 @@ class Region:
|
|
|
|
|
self.data = kwargs
|
|
|
|
|
|
|
|
|
|
def get_json(self):
|
|
|
|
|
return {
|
|
|
|
|
"center": self.center,
|
|
|
|
|
"weight": self.weight,
|
|
|
|
|
"data": self.data.copy()
|
|
|
|
|
}
|
|
|
|
|
return {"center": self.center, "weight": self.weight, "data": self.data.copy()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Regioner:
|
|
|
|
@ -404,9 +406,7 @@ class Regioner:
|
|
|
|
|
mask = mask.convert("L")
|
|
|
|
|
mask.save(masks_path / f"{mask_count}.png", "PNG")
|
|
|
|
|
|
|
|
|
|
regions[mask_count] = Region(
|
|
|
|
|
center=get_center(filled), weight=len(filled)
|
|
|
|
|
)
|
|
|
|
|
regions[mask_count] = Region(center=get_center(filled), weight=len(filled))
|
|
|
|
|
|
|
|
|
|
already_processed.update(filled)
|
|
|
|
|
|
|
|
|
|