Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4adc43

Browse files
authored
Add focusgfxshine.py
1 parent 9fe9638 commit d4adc43

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

‎python3/focusgfxshine.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/python
2+
import argparse
3+
import re
4+
5+
#############################
6+
###
7+
### HoI 4 Focus GFX entry generator by Yard1, originally for Equestria at War mod
8+
### Written in Python 3.8
9+
###
10+
### Copyright (c) 2020 Antoni Baum (Yard1)
11+
### Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
### The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14+
###
15+
### usage: focusgfxshine.py [-h] goals goals_shine
16+
###
17+
### Given a goals GFX file, add all missing shine entries to the goals_shine GFX file.
18+
###
19+
### positional arguments:
20+
### goals Name of the goals file
21+
### goals_shine Name of the goals_shine file
22+
###
23+
### optional arguments:
24+
### -h, --help show this help message and exit
25+
###
26+
#############################
27+
28+
29+
def get_shine_def(name, path):
30+
return """ SpriteType = {
31+
name = "%s_shine"
32+
texturefile = "%s"
33+
effectFile = "gfx/FX/buttonstate.lua"
34+
animation = {
35+
animationmaskfile = "%s"
36+
animationtexturefile = "gfx/interface/goals/shine_overlay.dds"
37+
animationrotation = -90.0
38+
animationlooping = no
39+
animationtime = 0.75
40+
animationdelay = 0
41+
animationblendmode = "add"
42+
animationtype = "scrolling"
43+
animationrotationoffset = { x = 0.0 y = 0.0 }
44+
animationtexturescale = { x = 1.0 y = 1.0 }
45+
}
46+
47+
animation = {
48+
animationmaskfile = "%s"
49+
animationtexturefile = "gfx/interface/goals/shine_overlay.tga"
50+
animationrotation = 90.0
51+
animationlooping = no
52+
animationtime = 0.75
53+
animationdelay = 0
54+
animationblendmode = "add"
55+
animationtype = "scrolling"
56+
animationrotationoffset = { x = 0.0 y = 0.0 }
57+
animationtexturescale = { x = 1.0 y = 1.0 }
58+
}
59+
legacy_lazy_load = no
60+
}\n""" % (
61+
name,
62+
path,
63+
path,
64+
path,
65+
)
66+
67+
68+
def main():
69+
parser = argparse.ArgumentParser(
70+
description="Given a goals GFX file, add all missing shine entries to the goals_shine GFX file."
71+
)
72+
parser.add_argument("goals", metavar="goals", help="Name of the goals file")
73+
parser.add_argument(
74+
"goals_shine", metavar="goals_shine", help="Name of the goals_shine file"
75+
)
76+
77+
args = parser.parse_args()
78+
79+
goal_regex = re.compile(
80+
r"name\s*=\s*\"([^\"]+)?\"\s*texturefile\s*=\s*\"([^\"]+)?\""
81+
)
82+
83+
print(f"Reading {args.goals_shine}...")
84+
with open(args.goals_shine, "r") as f:
85+
goals_shine = f.read()
86+
87+
goals_shine_matches = goal_regex.findall(
88+
goals_shine, re.MULTILINE | re.DOTALL | re.IGNORECASE
89+
)
90+
goals_shine_matches = {k: v for k, v in goals_shine_matches}
91+
92+
last_bracket_idx = 0
93+
94+
for i in range(len(goals_shine) - 1, -1, -1):
95+
if goals_shine[i] == "}":
96+
last_bracket_idx = abs(i)
97+
break
98+
99+
goals_shine_split = [goals_shine[:last_bracket_idx], goals_shine[last_bracket_idx:]]
100+
101+
print(f"Reading {args.goals}...")
102+
with open(args.goals, "r") as f:
103+
goals = f.read()
104+
105+
goals_matches = goal_regex.findall(
106+
goals, re.MULTILINE | re.DOTALL | re.IGNORECASE
107+
)
108+
goals_matches = {
109+
k: v for k, v in goals_matches if not f"{k}_shine" in goals_shine_matches
110+
}
111+
112+
print(f"Found {len(goals_matches)} missing shine entries...")
113+
114+
for k, v in goals_matches.items():
115+
print(f'"{k}" not found in "{args.goals_shine}", adding as "{k}_shine"...')
116+
goals_shine_split.insert(1, get_shine_def(k, v))
117+
118+
print(f"Saving modified {args.goals_shine}...")
119+
with open(args.goals_shine, "w") as f:
120+
f.write("\n".join(goals_shine_split))
121+
122+
123+
if __name__ == "__main__":
124+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /