forked from Fr33L4nc3r/EffectsEnhancement
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_patch.py
executable file
·91 lines (60 loc) · 2.45 KB
/
get_patch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
"""
DON'T RUN THIS FILE
- it's only here for reference sake in terms of how I made the patch file.
RUN ./update.py INSTEAD
"""
import sys
sys.path.append("../pa_tools")
import loader
from collections import OrderedDict
import patcher
import utils
import os
# get base pa directory
base_path = utils.pa_media_dir()
# the directory where the mod files are (right here in this case xD)
mod_path = '.'
# get the unit list file dir
unit_list_path = os.path.join(base_path, "pa/units/unit_list.json")
# unit list files for comparing
unit_list = loader.load(unit_list_path)
patches = []
# iterate over all the units
for unit_file in unit_list['units']:
# get rid of the extra slash at the start so that path join works
unit_file = unit_file[1:]
base_unit_path = os.path.join(base_path, unit_file)
unit_base = loader.load(base_unit_path)
# check to see if it's actually a file we've bothered shadowing or not:
mod_unit_path = os.path.join(mod_path, unit_file)
# the mod doesn't shadow this file; no need to compare them
if not os.path.exists(mod_unit_path): continue
unit_mod = loader.load(mod_unit_path)
# compute diff in terms of json diff
diff = patcher.from_diff(unit_base, unit_mod)
# remove anything that isn't to do with fx_offsets (since those changes represent balance/configuration changes)
diff = [op for op in diff if op['path'].startswith('/fx_offsets')]
for op in diff:
# here just to make things robust, we use the more generic version of 'add' to array
if op['path'].startswith('/fx_offsets/'):
# this path just means append to the end of the array
# which means we are not relying on the number of fx that are already on a unit in PA's base game files
# this makes the patch itself more robust
op['path'] = '/fx_offsets/-'
# store this patch
loader.dump(OrderedDict([('target', unit_file),('patch', diff )]), 'src/' + unit_file + '.patch', indent=2)
patches.append({'from_file' : unit_file + '.patch'})
options = loader.loads("""{
"output_dir" : "..",
"pretty_print_effects" : true,
"indent" : 2
}""")
modinfo = loader.load("modinfo.json")
patcher_mod_file = OrderedDict([
('options', options),
('modinfo', modinfo),
('mod', patches)
])
# now store all these patches in a single file
loader.dump(patcher_mod_file, 'src/mod.json', indent=2)