Compare commits
2 Commits
83a8edf94c
...
1da050232c
Author | SHA1 | Date | |
---|---|---|---|
1da050232c | |||
3c76eb4844 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@
|
||||
__pycache__
|
||||
.doit.db
|
||||
*.kate-swp
|
||||
/vanilla
|
||||
|
155
dodo.py
155
dodo.py
@ -3,15 +3,17 @@ from pathlib import Path
|
||||
from doit import get_var
|
||||
|
||||
DOIT_CONFIG = {
|
||||
'default_tasks': ['build'],
|
||||
'action_string_formatting': 'new'
|
||||
'default_tasks': ['build'],
|
||||
'action_string_formatting': 'both'
|
||||
}
|
||||
|
||||
|
||||
def files(p):
|
||||
for i in p:
|
||||
if i.is_file():
|
||||
yield i
|
||||
|
||||
|
||||
class RawFiles(list):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.src_path = Path(kwargs.pop('src_path'))
|
||||
@ -21,26 +23,33 @@ class RawFiles(list):
|
||||
def sources(self):
|
||||
for i in self:
|
||||
yield self.src_path/i
|
||||
|
||||
def targets(self):
|
||||
for i in self:
|
||||
yield self.image_path/i
|
||||
|
||||
|
||||
class BasePatchwork(dict):
|
||||
patches_path = None
|
||||
patchwork_path = None
|
||||
vanilla_path = None
|
||||
|
||||
def __init__(self, *arkg, **kwargs):
|
||||
self.patches_path = Path(kwargs.pop('patches_path'))
|
||||
self.patchwork_path = Path(kwargs.pop('patchwork_path'))
|
||||
self.vanilla_path = Path(kwargs.pop('vanilla_path'))
|
||||
super().__init__(*arkg, **kwargs)
|
||||
|
||||
def targets(self):
|
||||
for i in self.keys():
|
||||
yield self.patchwork_path/i
|
||||
|
||||
def key_vanilla(self, orig_key):
|
||||
return self.vanilla_path/orig_key
|
||||
|
||||
def key_target(self, orig_key):
|
||||
return self.patchwork_path/orig_key
|
||||
|
||||
def tasks(self, actions):
|
||||
def repack_action(action, **kwargs):
|
||||
if callable(action):
|
||||
@ -54,29 +63,28 @@ class BasePatchwork(dict):
|
||||
patch = self.patches_path/v
|
||||
target = self.patchwork_path/k
|
||||
yield {
|
||||
'name' : k,
|
||||
'file_dep' : [ original, patch ],
|
||||
'targets' : [ target ],
|
||||
'actions' : [ repack_action(action, original=original, patch=patch, target=target)
|
||||
for action in actions ],
|
||||
'clean' : True
|
||||
'name': k,
|
||||
'file_dep': [original, patch],
|
||||
'targets': [target],
|
||||
'actions': [repack_action(action, original=original, patch=patch, target=target)
|
||||
for action in actions],
|
||||
'clean': True
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Patchwork(BasePatchwork):
|
||||
def tasks_(self, actions):
|
||||
for k, v in self.items():
|
||||
yield {
|
||||
'name' : k,
|
||||
'file_dep' : [ self.patches_path/v, self.vanilla_path/k ],
|
||||
'targets' : [ self.patchwork_path/k ],
|
||||
'actions' : [
|
||||
'name': k,
|
||||
'file_dep': [self.patches_path/v, self.vanilla_path/k],
|
||||
'targets': [self.patchwork_path/k],
|
||||
'actions': [
|
||||
f"mkdir -p {self.patchwork_path}/{Path(k).parent}",
|
||||
f"patch -u --binary -N -o '{self.patchwork_path}/{k}' "\
|
||||
f"patch -u --binary -N -o '{self.patchwork_path}/{k}' "
|
||||
f"'{self.vanilla_path}/{k}' '{self.patches_path}/{v}'"
|
||||
], # action ( mkdir, patch )
|
||||
'clean' : True
|
||||
], # action ( mkdir, patch )
|
||||
'clean': True
|
||||
}
|
||||
|
||||
|
||||
@ -87,9 +95,15 @@ class ScriptedPatchwork(BasePatchwork):
|
||||
super().__init__(*args, **kwargs)
|
||||
with open(file) as s:
|
||||
for key, data in safe_load(s).items():
|
||||
discovered_source = next((Path(self.vanilla_path)/'history'/'states').glob(f"{key}*"))
|
||||
relative_path = discovered_source.relative_to(self.vanilla_path)
|
||||
self[relative_path] = data
|
||||
try:
|
||||
discovered_source = next(
|
||||
(Path(self.vanilla_path)/'history'/'states').glob(f"{key}*"))
|
||||
relative_path = discovered_source.relative_to(
|
||||
self.vanilla_path)
|
||||
self[relative_path] = data
|
||||
except StopIteration:
|
||||
print(f"{key}: not found")
|
||||
|
||||
|
||||
class RasterPatchwork(BasePatchwork):
|
||||
@staticmethod
|
||||
@ -135,44 +149,46 @@ class Patchset(list):
|
||||
|
||||
|
||||
mod_name = 'randchgs'
|
||||
mod_install_path = get_var('descriptor_mod_path', 'C:/Users/User/Documents/Paradox Interactive/Hearts of Iron IV/mod/randchgs')
|
||||
dir_vanilla = Path(get_var('vanilla_path', '../vanilla/current'))
|
||||
mod_install_path = get_var(
|
||||
'descriptor_mod_path', 'C:/Users/User/Documents/Paradox Interactive/Hearts of Iron IV/mod/randchgs')
|
||||
dir_vanilla = Path(get_var('vanilla_path', './vanilla/current'))
|
||||
if not dir_vanilla.is_dir():
|
||||
raise EnvironmentError(dir_vanilla)
|
||||
dir_image = Path('build/image')
|
||||
dir_modimage = dir_image/mod_name
|
||||
dir_src_raw = Path('src/raw')
|
||||
dir_src_raw_files = RawFiles(
|
||||
files(Path(dir_src_raw).rglob("*")),
|
||||
src_path = dir_src_raw,
|
||||
image_path = dir_image
|
||||
src_path=dir_src_raw,
|
||||
image_path=dir_image
|
||||
)
|
||||
dir_patches_path = Path('src/patches')
|
||||
dir_patchwork_path = Path('build/patched')
|
||||
|
||||
patchwork = Patchwork(
|
||||
{
|
||||
'map/definition.csv': 'map_definition.patch',
|
||||
'history/countries/ISR - Israel.txt': 'history_countries_ISR.patch',
|
||||
'history/states/454-Israel.txt': 'history_states_454.patch',
|
||||
},
|
||||
patches_path = dir_patches_path,
|
||||
patchwork_path = dir_patchwork_path,
|
||||
vanilla_path = dir_vanilla
|
||||
},
|
||||
patches_path=dir_patches_path,
|
||||
patchwork_path=dir_patchwork_path,
|
||||
vanilla_path=dir_vanilla
|
||||
)
|
||||
|
||||
patchwork_scripted = ScriptedPatchwork(
|
||||
source_file = dir_patches_path/'extrapoint.yaml',
|
||||
patches_path = '.',
|
||||
patchwork_path = dir_patchwork_path,
|
||||
vanilla_path = dir_vanilla
|
||||
source_file=dir_patches_path/'extrapoint.yaml',
|
||||
patches_path='.',
|
||||
patchwork_path=dir_patchwork_path,
|
||||
vanilla_path=dir_vanilla
|
||||
)
|
||||
|
||||
patchwork_raster = RasterPatchwork(
|
||||
{
|
||||
'map/terrain.bmp' : 'terrain.bmp',
|
||||
'map/terrain.bmp': 'terrain.bmp',
|
||||
},
|
||||
patches_path = dir_patches_path,
|
||||
patchwork_path = dir_patchwork_path,
|
||||
vanilla_path = dir_vanilla
|
||||
patches_path=dir_patches_path,
|
||||
patchwork_path=dir_patchwork_path,
|
||||
vanilla_path=dir_vanilla
|
||||
)
|
||||
|
||||
patch_set = Patchset(
|
||||
@ -182,9 +198,10 @@ patch_set = Patchset(
|
||||
patchwork_scripted,
|
||||
patchwork_raster,
|
||||
),
|
||||
modimage_path = dir_modimage
|
||||
modimage_path=dir_modimage
|
||||
)
|
||||
|
||||
|
||||
def task_patch_history_states_scripted():
|
||||
def history_state_patch(task, provinces):
|
||||
source = Path(next(iter(task.file_dep)))
|
||||
@ -195,45 +212,50 @@ def task_patch_history_states_scripted():
|
||||
with source.open(newline='') as infile, target.open('w') as outfile:
|
||||
for line_in in infile:
|
||||
outfile.write(line_in)
|
||||
seen_history = seen_history or ( 'history' in line_in )
|
||||
seen_history = seen_history or ('history' in line_in)
|
||||
if not wrote_history and seen_history and '{' in line_in:
|
||||
for province_id, province_info in provinces.items():
|
||||
outfile.write(
|
||||
"\t\tvictory_points = {\r\n"\
|
||||
f"\t\t\t{province_id} {province_info['points']}\r\n"\
|
||||
"\t\t}\r\n"\
|
||||
"\t\tvictory_points = {\r\n"
|
||||
f"\t\t\t{province_id} {
|
||||
province_info['points']}\r\n"
|
||||
"\t\t}\r\n"
|
||||
)
|
||||
wrote_history = True
|
||||
for state_src, state_data in patchwork_scripted.items():
|
||||
for state_src, state_data in patchwork_scripted.items():
|
||||
yield {
|
||||
'name' : state_src,
|
||||
'file_dep' : [ patchwork_scripted.key_vanilla(state_src) ],
|
||||
'targets' : [ patchwork_scripted.key_target(state_src) ],
|
||||
'actions' : [ ( history_state_patch, [], {'provinces' : state_data}) ],
|
||||
'clean' : True
|
||||
'name': state_src,
|
||||
'file_dep': [patchwork_scripted.key_vanilla(state_src)],
|
||||
'targets': [patchwork_scripted.key_target(state_src)],
|
||||
'actions': [(history_state_patch, [], {'provinces': state_data})],
|
||||
'clean': True
|
||||
}
|
||||
|
||||
|
||||
def task_patch_raster():
|
||||
yield from patchwork_raster.tasks([patchwork_raster.patch_action])
|
||||
|
||||
|
||||
def task_patch():
|
||||
def mkdir(target, original, patch):
|
||||
Path(target).parent.mkdir(parents=True, exist_ok=True)
|
||||
yield from patchwork.tasks([
|
||||
mkdir,
|
||||
"patch -u --binary -N -o '{target}' '{original}' '{patch}'"
|
||||
])
|
||||
mkdir,
|
||||
"patch -u --binary -N -o '{target}' '{original}' '{patch}'"
|
||||
])
|
||||
|
||||
|
||||
def task_image():
|
||||
return {
|
||||
'file_dep' : list(patch_set.image_sources()),
|
||||
'targets' : list(patch_set.image_files()),
|
||||
'actions' : [f"mkdir -p {dir_modimage}",
|
||||
f"rsync -rv {dir_src_raw}/ {patchwork.patchwork_path}/"\
|
||||
f" {dir_modimage}/" ],
|
||||
'clean' : True
|
||||
'file_dep': list(patch_set.image_sources()),
|
||||
'targets': list(patch_set.image_files()),
|
||||
'actions': [f"mkdir -p {dir_modimage}",
|
||||
f"rsync -rv {dir_src_raw}/ {patchwork.patchwork_path}/"
|
||||
f" {dir_modimage}/"],
|
||||
'clean': True
|
||||
}
|
||||
|
||||
|
||||
def task_image_mod():
|
||||
def prepare_modname_mod(task):
|
||||
source = Path(next(iter(task.file_dep)))
|
||||
@ -244,18 +266,19 @@ def task_image_mod():
|
||||
o.write(s.read())
|
||||
o.write(f"\npath=\"{mod_install_path}\"\n")
|
||||
return {
|
||||
'file_dep' : [ 'src/raw/descriptor.mod' ],
|
||||
'targets' : [f"{dir_image}/{mod_name}.mod" ],
|
||||
'actions' : [ prepare_modname_mod ],
|
||||
'clean' : True
|
||||
'file_dep': ['src/raw/descriptor.mod'],
|
||||
'targets': [f"{dir_image}/{mod_name}.mod"],
|
||||
'actions': [prepare_modname_mod],
|
||||
'clean': True
|
||||
}
|
||||
|
||||
|
||||
def task_build():
|
||||
return {
|
||||
'file_dep' : [f"{dir_image}/{mod_name}.mod" ] + list (patch_set.image_files()),
|
||||
'targets' : [f"{dir_image}/{mod_name}.zip" ],
|
||||
'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}.mod" ],
|
||||
'clean' : [ 'rm -rf build' ]
|
||||
'file_dep': [f"{dir_image}/{mod_name}.mod"] + list(patch_set.image_files()),
|
||||
'targets': [f"{dir_image}/{mod_name}.zip"],
|
||||
'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}.mod"],
|
||||
'clean': ['rm -rf build']
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,29 +0,0 @@
|
||||
--- ../vanilla/current/map/definition.csv 2023-10-10 13:46:35.000000000 +0400
|
||||
+++ build/image/randchgs/map/definition.csv 2023-11-27 23:45:22.219054356 +0400
|
||||
@@ -1013,7 +1013,7 @@
|
||||
1012;5;17;244;sea;false;ocean;0
|
||||
1013;5;18;30;land;true;plains;5
|
||||
1014;5;18;85;land;true;jungle;6
|
||||
-1015;5;18;135;land;true;desert;7
|
||||
+1015;5;18;135;land;true;urban;7
|
||||
1016;5;19;240;sea;false;ocean;0
|
||||
1017;5;20;248;sea;false;ocean;0
|
||||
1018;5;21;50;land;true;forest;6
|
||||
@@ -1063,7 +1063,7 @@
|
||||
1062;5;54;170;land;false;mountain;5
|
||||
1063;5;57;30;land;true;forest;6
|
||||
1064;5;57;85;land;false;desert;5
|
||||
-1065;5;57;135;land;true;plains;7
|
||||
+1065;5;57;135;land;true;urban;7
|
||||
1066;5;60;50;land;false;mountain;6
|
||||
1067;5;60;200;land;true;hills;6
|
||||
1068;5;63;15;land;false;desert;5
|
||||
@@ -1084,7 +1084,7 @@
|
||||
1083;5;78;145;land;false;forest;6
|
||||
1084;5;81;5;land;false;plains;6
|
||||
1085;5;81;60;land;true;jungle;4
|
||||
-1086;5;81;210;land;false;desert;7
|
||||
+1086;5;81;210;land;false;urban;7
|
||||
1087;5;84;25;land;false;plains;6
|
||||
1088;5;84;70;land;true;plains;7
|
||||
1089;5;84;175;land;true;hills;6
|
@ -1,5 +0,0 @@
|
||||
ISR_create_ships={
|
||||
create_ship {
|
||||
type = ship_hull_light_1
|
||||
}
|
||||
}
|
@ -144,3 +144,4 @@
|
||||
VICTORY_POINTS_11977:0 "Тэтджон"
|
||||
VICTORY_POINTS_6928:0 "Ханнам"
|
||||
VICTORY_POINTS_8136:0 "Ондангва"
|
||||
VICTORY_POINTS_9215:0 "Сосновка"
|
||||
|
Loading…
Reference in New Issue
Block a user