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 9fe9638

Browse files
authored
Update hoi4statemapgenerator.py
1 parent 7355978 commit 9fe9638

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

‎python3/hoi4statemapgenerator.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ def load_provinces(name):
137137
def load_definition(name):
138138
print("Reading file " + name + "...")
139139
try:
140-
with open(name, "r", encoding='utf-8-sig') as f:
140+
with open(name, "r") as f:
141141
lines = f.read().splitlines()
142142
except:
143143
try:
144144
with open(name, "r", encoding='utf-8') as f:
145145
lines = f.read().splitlines()
146146
except:
147147
try:
148-
with open(name, "r") as f:
148+
with open(name, "r", encoding='utf-8-sig') as f:
149149
lines = f.read().splitlines()
150150
except:
151151
print("Could not read file " + name + "!")
@@ -161,15 +161,15 @@ def load_state_file(name, states_dict):
161161
print("Reading file " + name + "...")
162162
file_str = ""
163163
try:
164-
with open(name, "r", encoding='utf-8-sig') as f:
164+
with open(name, "r") as f:
165165
file_str = f.read()
166166
except:
167167
try:
168168
with open(name, "r", encoding='utf-8') as f:
169169
file_str = f.read()
170170
except:
171171
try:
172-
with open(name, "r") as f:
172+
with open(name, "r", encoding='utf-8-sig') as f:
173173
file_str = f.read()
174174
except:
175175
print("Could not read file " + name + "!")
@@ -219,15 +219,15 @@ def load_state_file(name, states_dict):
219219
def load_pdx_colors_file(name):
220220
print("Reading file " + name + "...")
221221
try:
222-
with open(name, "r", encoding='utf-8-sig') as f:
222+
with open(name, "r") as f:
223223
file_str = f.read()
224224
except:
225225
try:
226226
with open(name, "r", encoding='utf-8') as f:
227227
file_str = f.read()
228228
except:
229229
try:
230-
with open(name, "r") as f:
230+
with open(name, "r", encoding='utf-8-sig') as f:
231231
file_str = f.read()
232232
except:
233233
print("Could not read file " + name + "!")
@@ -248,11 +248,12 @@ def count_colors(states_dict, provinces_rev, provinces_image):
248248
statpix = 0
249249
for i in range(provinces_image.size[0]):
250250
for j in range(provinces_image.size[1]):
251-
totpix += 1
252-
provid = provinces_rev[pixels[i, j]]
253-
if provid in providstate:
254-
statpix += 1
255-
providstate[provid].pixels += 1
251+
if pixels[i,j] in provinces_rev:
252+
totpix += 1
253+
provid = provinces_rev[pixels[i, j]]
254+
if provid in providstate:
255+
statpix += 1
256+
providstate[provid].pixels += 1
256257
print(totpix, statpix)
257258

258259
def create_states_map(colors_replacement_dict, provinces_image, water_color):
@@ -578,7 +579,10 @@ def main():
578579
if mode == 1:
579580
color = get_state_color(state.manpower/state.pixels, space, colors)
580581
elif mode == 2:
581-
color = colors[state.owner]
582+
try:
583+
color = colors[state.owner]
584+
except:
585+
print("%s not in colors" % state.owner)
582586
elif mode == 3:
583587
color = get_state_color(state.industrial_complex+state.arms_factory+state.dockyard, space, colors)
584588
elif mode == 4:
@@ -598,7 +602,8 @@ def main():
598602

599603
#print("STATE %s: COLOR: %s" % (str(state_id), color))
600604
for province in state.provinces:
601-
colors_replacement_dict[provinces[province]] = ((color[0], color[1], color[2]), state_id)
605+
if province in provinces:
606+
colors_replacement_dict[provinces[province]] = ((color[0], color[1], color[2]), state_id)
602607

603608
print("Generating map image...")
604609
if args.no_ids:

0 commit comments

Comments
(0)

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