-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate.py
322 lines (209 loc) · 13.1 KB
/
generate.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import bookmark
import csvspreadsheets
import religion
import riverGen
import spreadsheets
import rasterMaps
import BFS
import os
import modFiles
import culture
import sys
import character
import localization
import openpyxl
import pandas as pd
import xlwt
import hextorgb
import modFiles
def runGenExcel(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
modFiles.modFile(modname, output_dir, modpath)
#CREATES DIRECTORIES
# Create "map_data" subfolder
map_data_dir = os.path.join(output_dir, "map_data")
if not os.path.exists(map_data_dir):
os.makedirs(map_data_dir)
# Create "map_data" subfolder
map_data_dir = os.path.join(output_dir, "_mapFiller")
if not os.path.exists(map_data_dir):
os.makedirs(map_data_dir)
# Create "gfx/map/terrain/" subfolder
map_data_dir = os.path.join(output_dir, "gfx/map/terrain/")
if not os.path.exists(map_data_dir):
os.makedirs(map_data_dir)
# Create "gfx/map/terrain/" subfolder
map_data_dir = os.path.join(output_dir, "gfx/map/terrain/")
if not os.path.exists(map_data_dir):
os.makedirs(map_data_dir)
#RUN SPREADSHEET GENERATORS
# Remove emoji from JSON file
spreadsheets.remove_emoji_from_json(os.path.join(modpath, "input.json"),
os.path.join(output_dir, "noemoji.json"))
print("Emoji data removed from json")
# Assign colors to Baronies in GeoJSON file
spreadsheets.colorRandom(os.path.join(modpath, "input.geojson"), os.path.join(output_dir, "output.geojson"))
print("Colors Assigned to Baronies for Cells method")
# Convert JSON to Excel spreadsheet
spreadsheets.json_to_sheet(os.path.join(output_dir, "noemoji.json"), os.path.join(output_dir, "combined_data.xlsx"))
print("Json extracted")
# Convert GeoJSON to Excel spreadsheet
spreadsheets.cells_geojson_to_sheet(os.path.join(output_dir, "output.geojson"),
os.path.join(output_dir, "cellsData.xlsx"))
print("Geojson extracted")
# Correct cell names in Excel spreadsheet
spreadsheets.nameCorrector(os.path.join(output_dir, "cellsData.xlsx"),
os.path.join(output_dir, "combined_data.xlsx"),
os.path.join(output_dir, "updated_file.xlsx"))
print("Geojson data updated with Json names")
# Generate ProvinceDef.xlsx file for Cells
spreadsheets.provinceDefCells(os.path.join(output_dir, "updated_file.xlsx"),
os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"))
print("Generate ProvinceDef.xlsx file for Cells")
#csvspreadsheets.jsontocsv(output_dir)
def runGenRaster(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname,CharGen_response, gamedir, output_dir,blur_amount):
#DATA TO RASTERIZED IMAGE
#heightmap scaling methods
if scaling_method == 1:
rasterMaps.heightmap(os.path.join(output_dir, "output.geojson"),
os.path.join(output_dir, "map_data", "heightmap.png"), scaling_factor)
print("Generating Heightmap")
elif scaling_method == 2:
rasterMaps.heightmapAutoScaledfunc(os.path.join(output_dir, "output.geojson"),
os.path.join(output_dir, "map_data", "heightmap.png"))
print("Generating Auto-Scaled Heightmap")
else:
print("Invalid scaling method")
# Generate provinces image
rasterMaps.provincesCells(os.path.join(output_dir, "output.geojson"),
os.path.join(output_dir, "map_data", "provinces.png"), scaling_factor)
print("Generating Cells provinces")
# Generate biomes images
if scaling_method == 1:
rasterMaps.biomes(os.path.join(output_dir, "output.geojson"), os.path.join(output_dir, "gfx", "map", "terrain"),
scaling_factor)
print("Generated Biomes")
elif scaling_method == 2:
rasterMaps.biomesAutoScaled(os.path.join(output_dir, "output.geojson"),
os.path.join(output_dir, "gfx", "map", "terrain"))
print("Generated Auto-Scaled Biomes")
else:
print("Invalid scaling method")
#Rename biome files to CK3 texture names using the json data
modFiles.biomeWrite(os.path.join(output_dir, 'noemoji.json'),
os.path.join(output_dir, 'biomes.xlsx'),
os.path.join(output_dir, 'gfx/map/terrain'))
input_zip_file = os.path.join(modpath, "tcs.zip")
# Call the extract_zip_file function
modFiles.extract_zip_file(input_zip_file, output_dir)
rasterMaps.heightmap_to_mountain_biome(output_dir)
rasterMaps.heightmap_blur_and_noise(output_dir,blur_amount)
#rasterMaps.gradient_map(output_dir)
def runGenPaper(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
print(output_dir)
print("Paper Map Generating...")
rasterMaps.paint_land_sea_mask(os.path.join(output_dir,"map_data/heightmap_for_paper.png"),os.path.join(output_dir,"masksea.png"))
rasterMaps.create_masked_image(os.path.join(output_dir, 'sea_image.png'), os.path.join(output_dir, 'land_image.png'),os.path.join(output_dir, 'masksea.png'), os.path.join(output_dir, 'flatmap1.dds'))
rasterMaps.produce_outline(os.path.join(output_dir,'masksea.png'), os.path.join(output_dir, 'flatmapBorder.png'))
rasterMaps.overlay_png_on_dds(os.path.join(output_dir,'flatmapBorder.png'), os.path.join(output_dir,'flatmap1.dds'), os.path.join(output_dir,'gfx/map/terrain/flatmap.dds'))
print("Paper Map Generated")
def runGenRelCult(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
print("Extracting tcs.zip")
input_zip_file = os.path.join(modpath, "tcs.zip")
# Call the extract_zip_file function
modFiles.extract_zip_file(input_zip_file, output_dir)
print("Finished extracting tcs.zip")
#Runs Religion Generator
print("Running religion family gen")
religion.familyGen(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, "common/religion/religion_families"))
print("Running religion children gen")
religion.religionChildren(os.path.join(output_dir, "combined_data.xlsx"),
os.path.join(output_dir, "religionChildren.xlsx"))
print("running religion genchil")
religion.relGenChil(os.path.join(output_dir, "religionChildren.xlsx"),
os.path.join(output_dir, "religionChildren_cName.xlsx"))
print("running ")
religion.religionGen(os.path.join(output_dir, "religionChildren_cName.xlsx"),
os.path.join(output_dir, "common/religion/religions"))
#Runs Culture Generator
culture.heritage_gen(os.path.join(output_dir, 'combined_data.xlsx'), os.path.join(output_dir, 'common/culture/pillars'))
culture.culture_gen(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, 'common/culture/cultures'))
def runGenBFS(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
#BFS Functions
print("Breadth First search started, this generates Baronies from cells and may take some time to run")
# Run Breadth First search to generate Baronies
BFS.bfs_distance(os.path.join(output_dir, "combined_data.xlsx"), os.path.join(output_dir, "cellsData.xlsx"),
os.path.join(output_dir, "BFSoutput.xlsx"))
print("")
print("Breadth First search Complete")
# Assign unique color to Baronies
BFS.colorRandomBFS(os.path.join(output_dir, "BFSoutput.xlsx"))
print("Assigning unique color to Baronies")
if scaling_method == 1:
# Generate BFS provinces image
BFS.provinceMapBFS(os.path.join(output_dir, "BFSoutput.xlsx"), scaling_factor,
os.path.join(output_dir, "map_data", "provinces.png"))
print("Generating BFS provinces")
elif scaling_method == 2:
rasterMaps.provinceMapBFSAutoScaled(os.path.join(output_dir, "BFSoutput.xlsx"),
os.path.join(output_dir, "map_data", "provinces.png"))
#BFSProvDef
BFS.extractBFS(os.path.join(output_dir, "BFSoutput.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"))
BFS.BaronyId(os.path.join(output_dir, "combined_data.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"))
BFS.ProvData(os.path.join(output_dir,"updated_file.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"))
BFS.cOrder(os.path.join(output_dir,"_mapFiller/provinceDef.xlsx"))
BFS.finalorder(os.path.join(output_dir,"_mapFiller/provinceDef.xlsx"))
BFS.convert_xlsx_to_xls(os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xls"))
spreadsheets.combined_data_empires(os.path.join(output_dir, "combined_data.xlsx"))
print("Applied Vassal/Suzerain relationships to combined data")
spreadsheets.combined_data_empires_id_to_name(os.path.join(output_dir, "combined_data.xlsx"))
print("Applied Name to Vassal/Suzerain ID relationships to combined data")
spreadsheets.update_provincedef_empires_vassalsuzerain(os.path.join(output_dir, "combined_data.xlsx"),
os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"))
BFS.convert_xlsx_to_xls(os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xls"))
def runMapFill(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
# Get output directory path from user input
print("Automatic Map Filler Running")
config_file_path = os.path.join(mapfilldir, "config.properties")
print(config_file_path)
moddir = output_dir
modFiles.modify_config(moddir, gamedir, config_file_path)
jar_path = os.path.join(mapfilldir, "CK3Tools.jar")
cwd = mapfilldir
modFiles.run_jar(jar_path, cwd)
print("Map Filler Complete")
localization.religionLoc(output_dir)
def Terrains(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
BFS.BaronyIdBiomes(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, "cellsData.xlsx"),os.path.join(output_dir, "townBiomes.csv"))
spreadsheets.terrainGenIdtoName(os.path.join(output_dir, 'townBiomes.csv'), os.path.join(output_dir, 'biomes.xlsx'))
spreadsheets.terrainGenRGB(os.path.join(output_dir, 'townBiomes.csv'), (os.path.join(output_dir, '_mapFiller/provinceDef.xlsx')))
spreadsheets.terrainGen(os.path.join(output_dir, 'townBiomes.csv'), (os.path.join(output_dir, 'common/province_terrain/00_province_terrain.txt')))
def runCharBook(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response, gamedir,output_dir):
localization.religionLoc(output_dir)
if CharGen_response.lower() == "yes":
print("Character Generation running:")
character.rulerGenXL(os.path.join(output_dir, "combined_data.xlsx"),
os.path.join(output_dir, "characters.xlsx"))
character.rulerWrite(os.path.join(output_dir, "characters.xlsx"),
os.path.join(output_dir, "history/characters/"))
character.modHistory(os.path.join(output_dir, "characters.xlsx"),
os.path.join(output_dir, "history/titles/"))
bookmark.bm_groups(output_dir)
bookmark.bm_generator(output_dir, 3)
elif CharGen_response.lower() == "no":
print("Shattered World Mode.")
else:
print("Invalid response. Please enter 'yes' or 'no'.")
def GenerateRivers(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
rasterMaps.rivermap(output_dir)
def printValues(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir):
print("Modpath: ", modpath)
print("mapfilldir: ", mapfilldir)
print("installdir: ", installdir)
print("scaling_method: ", scaling_method)
print("scaling_factor: ", scaling_factor)
print("modname: ", modname)
print("CharGen_response: ", CharGen_response)
print("Gamedir:",gamedir)
print("output_dir:",output_dir)