basic object for patchset grouping (#3)
- [x] create basic object for grouping patchsets Reviewed-on: #3
This commit is contained in:
parent
eb857ddde4
commit
b91e497ed4
88
dodo.py
88
dodo.py
@ -92,7 +92,46 @@ class ScriptedPatchwork(BasePatchwork):
|
|||||||
self[relative_path] = data
|
self[relative_path] = data
|
||||||
|
|
||||||
class RasterPatchwork(BasePatchwork):
|
class RasterPatchwork(BasePatchwork):
|
||||||
pass
|
@staticmethod
|
||||||
|
def patch_action(target, original, patch):
|
||||||
|
from PIL import Image
|
||||||
|
with Image.open(original) as base, Image.open(patch) as patch:
|
||||||
|
def mask():
|
||||||
|
for bg, p in zip(base.tobytes(), patch.tobytes()):
|
||||||
|
if p == 35:
|
||||||
|
yield bg
|
||||||
|
else:
|
||||||
|
yield p
|
||||||
|
|
||||||
|
output = Image.frombytes(base.mode, base.size, bytes(mask()))
|
||||||
|
output.putpalette(base.palette)
|
||||||
|
output.save(target)
|
||||||
|
output.close()
|
||||||
|
|
||||||
|
|
||||||
|
class Patchset(list):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.modimage_path = Path(kwargs.pop('modimage_path'))
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def image_files(self):
|
||||||
|
for patches in self:
|
||||||
|
if isinstance(patches, BasePatchwork):
|
||||||
|
for target in patches:
|
||||||
|
yield self.modimage_path/target
|
||||||
|
elif isinstance(patches, RawFiles):
|
||||||
|
for target in patches:
|
||||||
|
yield self.modimage_path/target.relative_to(patches.src_path)
|
||||||
|
|
||||||
|
def image_sources(self):
|
||||||
|
for patches in self:
|
||||||
|
if isinstance(patches, BasePatchwork):
|
||||||
|
for target in patches:
|
||||||
|
yield patches.patchwork_path/target
|
||||||
|
elif isinstance(patches, RawFiles):
|
||||||
|
for target in patches:
|
||||||
|
yield target
|
||||||
|
|
||||||
|
|
||||||
mod_name = 'randchgs'
|
mod_name = 'randchgs'
|
||||||
mod_install_path = get_var('descriptor_mod_path', 'C:/Users/User/Documents/Paradox Interactive/Hearts of Iron IV/mod/randchgs')
|
mod_install_path = get_var('descriptor_mod_path', 'C:/Users/User/Documents/Paradox Interactive/Hearts of Iron IV/mod/randchgs')
|
||||||
@ -135,17 +174,15 @@ patchwork_raster = RasterPatchwork(
|
|||||||
vanilla_path = dir_vanilla
|
vanilla_path = dir_vanilla
|
||||||
)
|
)
|
||||||
|
|
||||||
|
patch_set = Patchset(
|
||||||
def collect_image_files(patchworks, dir_modimage):
|
(
|
||||||
for pw in patchworks:
|
dir_src_raw_files,
|
||||||
for target in pw:
|
patchwork,
|
||||||
yield dir_modimage/target
|
patchwork_scripted,
|
||||||
dir_image_files = list(collect_image_files(
|
patchwork_raster,
|
||||||
[patchwork, patchwork_scripted, patchwork_raster],
|
),
|
||||||
dir_modimage=dir_modimage
|
modimage_path = dir_modimage
|
||||||
))
|
)
|
||||||
dir_image_files += [ dir_modimage/f.relative_to(dir_src_raw) for f in dir_src_raw_files ]
|
|
||||||
|
|
||||||
|
|
||||||
def task_patch_history_states_scripted():
|
def task_patch_history_states_scripted():
|
||||||
def history_state_patch(task, provinces):
|
def history_state_patch(task, provinces):
|
||||||
@ -176,22 +213,7 @@ def task_patch_history_states_scripted():
|
|||||||
}
|
}
|
||||||
|
|
||||||
def task_patch_raster():
|
def task_patch_raster():
|
||||||
def raster_patch(target, original, patch):
|
yield from patchwork_raster.tasks([patchwork_raster.patch_action])
|
||||||
from PIL import Image
|
|
||||||
with Image.open(original) as base, Image.open(patch) as patch:
|
|
||||||
def mask():
|
|
||||||
for bg, p in zip(base.tobytes(), patch.tobytes()):
|
|
||||||
if p == 35:
|
|
||||||
yield bg
|
|
||||||
else:
|
|
||||||
yield p
|
|
||||||
|
|
||||||
output = Image.frombytes(base.mode, base.size, bytes(mask()))
|
|
||||||
output.putpalette(base.palette)
|
|
||||||
output.save(target)
|
|
||||||
output.close()
|
|
||||||
|
|
||||||
yield from patchwork_raster.tasks([raster_patch])
|
|
||||||
|
|
||||||
def task_patch():
|
def task_patch():
|
||||||
def mkdir(target, original, patch):
|
def mkdir(target, original, patch):
|
||||||
@ -202,13 +224,9 @@ def task_patch():
|
|||||||
])
|
])
|
||||||
|
|
||||||
def task_image():
|
def task_image():
|
||||||
filelist = dir_src_raw_files + \
|
|
||||||
list(patchwork.targets()) + \
|
|
||||||
list(patchwork_scripted.targets()) + \
|
|
||||||
list(patchwork_raster.targets())
|
|
||||||
return {
|
return {
|
||||||
'file_dep' : filelist,
|
'file_dep' : list(patch_set.image_sources()),
|
||||||
'targets' : dir_image_files,
|
'targets' : list(patch_set.image_files()),
|
||||||
'actions' : [f"mkdir -p {dir_modimage}",
|
'actions' : [f"mkdir -p {dir_modimage}",
|
||||||
f"rsync -rv {dir_src_raw}/ {patchwork.patchwork_path}/"\
|
f"rsync -rv {dir_src_raw}/ {patchwork.patchwork_path}/"\
|
||||||
f" {dir_modimage}/" ],
|
f" {dir_modimage}/" ],
|
||||||
@ -233,7 +251,7 @@ def task_image_mod():
|
|||||||
|
|
||||||
def task_build():
|
def task_build():
|
||||||
return {
|
return {
|
||||||
'file_dep' : [f"{dir_image}/{mod_name}.mod" ] + dir_image_files,
|
'file_dep' : [f"{dir_image}/{mod_name}.mod" ] + list (patch_set.image_files()),
|
||||||
'targets' : [f"{dir_image}/{mod_name}.zip" ],
|
'targets' : [f"{dir_image}/{mod_name}.zip" ],
|
||||||
'actions' : [ "rm -f %(targets)s",
|
'actions' : [ "rm -f %(targets)s",
|
||||||
f"cd {dir_image} && zip -r {mod_name}.zip {mod_name}",
|
f"cd {dir_image} && zip -r {mod_name}.zip {mod_name}",
|
||||||
|
Loading…
Reference in New Issue
Block a user