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 a6b5133

Browse files
authored
Update hoi4localisationadder.py
Added support for decisions and decision_categories files, fixed "l_english" not being appended correctly, fixed "_desc" keys not being treated like keyes
1 parent 205d60a commit a6b5133

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

‎python2/hoi4localisationadder.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@
1010
### HoI 4 Localisation Adder by Yard1, originally for Equestria at War mod
1111
### Written in Python 2.7
1212
###
13-
### Copyright (c) 2017 Antoni Baum (Yard1)
13+
### Copyright (c) 2018 Antoni Baum (Yard1)
1414
### 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:
1515
### The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1616
### 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.
1717
###
18-
### usage: hoi4LocalisationAdderApp.py [-h] [-t] input output
18+
### usage: hoi4localisationadder.py [-h] [-t] input output
1919
###
2020
### Given an event, national_focus or ideas file, add missing localisation entries
2121
### to a specified localisation file. Note: custom tooltips are not supported. In
2222
### case of events, title, description and option names will be added (triggered
2323
### titles and descriptions are supported). For national_focus and ideas, names
24-
### and descriptions will be added.
24+
### and descriptions will be added. For decisions and decision_categories, names
25+
### and category names will be added. WARNING: The script defaults to a decisions
26+
### file if it cannot determine the type of file.
2527
###
2628
### positional arguments:
27-
### input Event, national_focus or ideas file to parse
29+
### input Event, national_focus, decisions, decision_categories or ideas file to parse
2830
### output Localisation file to write to (if empty/non-existing, a new
2931
### English localisation file will be created)
3032
###
@@ -44,9 +46,11 @@ def readfile(name):
4446
is_event_file = False
4547
is_focus_file = False
4648
is_idea_file = False
49+
is_decision_file = False
50+
is_decision_categories_file = False
4751
for line in lines:
4852
line = re.sub('#.*', "", line)
49-
if not is_event_file and not is_focus_file and not is_idea_file:
53+
if not is_event_file and not is_focus_file and not is_idea_fileandnotis_decision_categories_file:
5054
if "focus_tree" in line:
5155
is_focus_file = True
5256
print("File " + name + " is a national_focus file...")
@@ -56,18 +60,40 @@ def readfile(name):
5660
elif "ideas" in line:
5761
is_idea_file = True
5862
print("File " + name + " is an ideas file...")
59-
if is_focus_file:
63+
elif "{" in line:
64+
is_decision_categories_file = True
65+
temp_tags = []
66+
print("File " + name + " is a decisions or decision_categories file...")
67+
if is_decision_categories_file:
68+
if open_blocks < 2 and "{" in line:
69+
temp_line = line
70+
temp_line = re.sub('\s|=(\s|){', "", temp_line)
71+
temp_line.strip()
72+
if not is_decision_file and open_blocks == 1:
73+
temp_tags.append(temp_line)
74+
else:
75+
tags[temp_line] = None
76+
tags[temp_line + "_desc"] = None
77+
if not is_decision_file and open_blocks == 2 and ("available" in line or "visible" in line or "fire_only_once" in line or "cost" in line or "days_remove" in line or "remove_effect" in line or "complete_effect" in line):
78+
print("File " + name + " is a decisions file...")
79+
is_decision_file = True
80+
for key in temp_tags:
81+
tags[key] = None
82+
tags[key + "_desc"] = None
83+
elif is_focus_file:
6084
if open_blocks == 2 and re.match('^.*id ?=', line):
6185
temp_line = re.sub('^.*id ?=', "", line)
6286
temp_line = re.sub('\s', "", temp_line)
6387
temp_line.strip()
6488
tags[temp_line] = None
89+
tags[temp_line + "_desc"] = None
6590
elif is_idea_file:
6691
if open_blocks == 2 and "{" in line:
6792
temp_line = line
6893
temp_line = re.sub('\s|=(\s|){', "", temp_line)
6994
temp_line.strip()
7095
tags[temp_line] = None
96+
tags[temp_line + "_desc"] = None
7197
elif is_event_file:
7298
if open_blocks > 0 and open_blocks < 3 and re.match('^.*(title|desc|name|text) ?=', line):
7399
temp_line = re.sub('^.*(title|desc|name|text) ?=', "", line)
@@ -78,11 +104,11 @@ def readfile(name):
78104
open_blocks -= line.count('}')
79105

80106
print("File " + name + " read successfully!")
81-
return list(tags.keys()), (is_event_file, is_focus_file, is_idea_file)
107+
return list(tags.keys()), (is_event_file, is_focus_file, is_idea_file, is_decision_categories_file)
82108
###################################################################
83-
parser = argparse.ArgumentParser(description='Given an event, national_focusor ideas file, add missing localisation entries to a specified localisation file. Note: custom tooltips are not supported. In case of events, title, description and option names will be added (triggered titles and descriptions are supported). For national_focus and ideas, names and descriptions will be added.')
109+
parser = argparse.ArgumentParser(description='Given an event, national_focus, decisions, decision_categories or ideas file, add missing localisation entries to a specified localisation file. Note: custom tooltips are not supported. In case of events, title, description and option names will be added (triggered titles and descriptions are supported). For national_focus and ideas, names and descriptions will be added. For decisions and decision_categories, names and category names will be added. WARNING: The script defaults to a decisions file if it cannot determine the type of file.')
84110
parser.add_argument('input', metavar='input',
85-
help='Event, national_focus or ideas file to parse')
111+
help='Event, national_focus, decisions, decision_categories or ideas file to parse')
86112
parser.add_argument( 'output', metavar='output',
87113
help='Localisation file to write to (if empty/non-existing, a new English localisation file will be created)')
88114
parser.add_argument( '-t', '--todo', action='store_true',
@@ -91,20 +117,20 @@ def readfile(name):
91117
args = parser.parse_args()
92118

93119
parsed_file = readfile(args.input)
94-
if not parsed_file[1][0] and not parsed_file[1][1] and not parsed_file[1][2:]:
95-
sys.exit("File " + args.input + " is not a valid event, national_focus or ideas file.")
120+
#if not parsed_file[1][0] and not parsed_file[1][1] and not parsed_file[1][2:]:
121+
# sys.exit("File " + args.input + " is not a valid event, national_focus or ideas file.")
96122
lines = list()
97123
with open(args.output,"r") as f:
98124
lines = f.read().splitlines()
125+
output_lines = list()
99126
if len(lines) < 1:
100127
print("Output file " + args.output + " is empty or doesn't exist, creating a new english localisation file.")
101-
lines.append("l_english:")
128+
output_lines.append("l_english:")
102129
for line in lines:
103130
for i,parsed_line in enumerate(parsed_file[0]):
104131
if parsed_line in line:
105132
print(parsed_line + " already in output file, skipping")
106133
parsed_file[0].remove(parsed_file[0][i])
107-
output_lines = list()
108134
if len(parsed_file[0]) > 0:
109135
if not args.todo:
110136
output_lines.append("\n #TODO")
@@ -114,8 +140,6 @@ def readfile(name):
114140
if args.todo:
115141
output_lines.append(" #TODO")
116142
output_lines.append(" " + line + ":0 \"\"")
117-
if parsed_file[1][1] or parsed_file[1][2]:
118-
output_lines.append(" " + line + "_desc:0 \"\"")
119143
with open(args.output,"a") as f:
120144
f.writelines(str(line) + "\n" for line in output_lines)
121145
print("Appended " + str(len(parsed_file[0])) + " lines to output file " + args.output + " successfully!")

0 commit comments

Comments
(0)

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