-
Notifications
You must be signed in to change notification settings - Fork 8
/
runprogram.py
294 lines (216 loc) · 10.7 KB
/
runprogram.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
import tkinter as tk
import customtkinter
import shutil
import subprocess
import PIL
from PIL import Image, ImageOps, ImageTk, ImageFilter
from tkinter import filedialog
from tkinter import *
import simulation
from PIL import Image
import sys
from split_image import split_image
import cv2
global path_argv_sim
path_argv_sim = sys.argv[0]
scaling_factor = 50
def select_geojson_file():
global file_path
file_path = filedialog.askopenfilename(initialdir="/", title="Select Cells Geojson file",
filetypes=(("geojson files", "*.geojson"), ("all files", "*.*")))
print(file_path)
def select_riversgeojson_file():
global rivers_file_path
rivers_file_path = filedialog.askopenfilename(initialdir="/", title="Select Rivers Geojson file",
filetypes=(("geojson files", "*.geojson"), ("all files", "*.*")))
print(rivers_file_path)
def select_json_file():
global json_file_path
json_file_path = filedialog.askopenfilename(initialdir="/", title="Select JSON file",
filetypes=(("JSON files", "*.json"), ("all files", "*.*")))
print(json_file_path)
def select_output_folder():
global folder_path
folder_path = filedialog.askdirectory(initialdir="/", title="Select output folder")
print(folder_path)
shutil.copy(file_path, folder_path + "/input.geojson")
shutil.copy(json_file_path, folder_path + "/emoji.json")
shutil.copy(rivers_file_path, folder_path + "/rivers.geojson")
print("scaling_factor:", scaling_factor)
def run_generator():
global scaling_factor
global provinceMethod
scaling_factor = float(scaling_factor_entry.get())
PM = provinceMethod.get()
print("Scaling factor:", scaling_factor)
print("Province Method:", PM)
if PM == "BFS":
subprocess.run(["python", "colorrandom.py"], cwd=folder_path)
subprocess.run(["python", "provinces.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "heightmap.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "biomes.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "jsonread.py"], cwd=folder_path)
subprocess.run(["python", "xlsoutput.py"], cwd=folder_path)
subprocess.run(["python", "jsontoxlsxprovinces.py"], cwd=folder_path)
subprocess.run(["python", "namecorrector.py"], cwd=folder_path)
subprocess.run(["python", "provdefcolumns.py"], cwd=folder_path)
subprocess.run(["python", "religionfamilygen.py"], cwd=folder_path)
subprocess.run(["python", "religionChildren.py"], cwd=folder_path)
subprocess.run(["python", "relGenChil.py"], cwd=folder_path)
subprocess.run(["python", "religionGen.py"], cwd=folder_path)
subprocess.run(["python", "riverGen.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "biomeWrite.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "baronyBFS.py"], cwd=folder_path)
subprocess.run(["python", "colorRandomBFS.py"], cwd=folder_path)
subprocess.run(["python", "BFSProvincemap.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "BFSbaronyXLS.py"], cwd=folder_path)
subprocess.run(["python", "religionGen.py"], cwd=folder_path)
elif PM == "Cells":
subprocess.run(["python", "colorrandom.py"], cwd=folder_path)
subprocess.run(["python", "provinces.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "heightmap.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "biomes.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "jsonread.py"], cwd=folder_path)
subprocess.run(["python", "xlsoutput.py"], cwd=folder_path)
subprocess.run(["python", "jsontoxlsxprovinces.py"], cwd=folder_path)
subprocess.run(["python", "namecorrector.py"], cwd=folder_path)
subprocess.run(["python", "provdefcolumns.py"], cwd=folder_path)
subprocess.run(["python", "religionfamilygen.py"], cwd=folder_path)
subprocess.run(["python", "religionChildren.py"], cwd=folder_path)
subprocess.run(["python", "relGenChil.py"], cwd=folder_path)
subprocess.run(["python", "religionGen.py"], cwd=folder_path)
subprocess.run(["python", "riverGen.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "biomeWrite.py", str(scaling_factor)], cwd=folder_path)
subprocess.run(["python", "religionGen.py"], cwd=folder_path)
#def store_scaling_factor(value):
#global scaling_factor
#scaling_factor = int(value)
#def select_scaling_factor():
#global scaling_factor
#scaling_factor = float(scaling_factor_entry.get())
#print("Scaling factor:", scaling_factor)
#def store_tile_number(value):
#global scaling_factor
#scaling_factor = int(value)
def add_image():
global image_file_path
#PIL appears to have an issue with 16-bit greyscale images, so requires conversion using CV2
# Load the 16-bit depth grayscale image
img_16bit = cv2.imread('map_data/heightmap.png', cv2.IMREAD_GRAYSCALE)
# Normalize the image to the 0-255 range
cv2.normalize(img_16bit, img_16bit, 0, 255, cv2.NORM_MINMAX)
# Convert the 16-bit depth grayscale image to an 8-bit depth grayscale image
img_8bit = cv2.convertScaleAbs(img_16bit)
# Save the 8-bit depth grayscale image
cv2.imwrite('map_data/heightmapTemp.png', img_8bit)
image_file_path = "map_data/heightmapTemp.png"
image = Image.open(image_file_path)
width, height = int(image.width / 4), int(image.height / 4)
image = image.resize((width, height),Image.BILINEAR )
canvas.config(width=image.width, height=image.height)
image = ImageTk.PhotoImage(image)
canvas.image = image
canvas.create_image(0, 0, image=image, anchor="nw")
def refresh_image():
global image_file_path
# Re-open the image and resize it
image = Image.open(image_file_path)
width, height = int(image.width / 4), int(image.height / 4)
image = image.resize((width, height))
# Update the canvas size and image
canvas.config(width=image.width, height=image.height)
image = ImageTk.PhotoImage(image)
canvas.image = image
canvas.create_image(0, 0, image=image, anchor="nw")
def erodeSim():
image = Image.open("map_data/heightmap.png")
final_iter = int(e_iter.get())
# Crop the center of the image
width, height = image.size
left = (width - 4096) / 2
top = (height - 4096) / 2
right = (width + 4096) / 2
bottom = (height + 4096) / 2
cropped_image = image.crop((left, top, right, bottom))
print(cropped_image.mode)
# Resize the image to 1024x1024
resized_image = cropped_image.resize((1024, 1024),Image.NEAREST)
# Save the resized image to the output path
resized_image.save("map_data/heightmapCrop.png", mode="L", bits=8)
# Load the 16-bit depth grayscale image
img_16bit = cv2.imread('map_data/heightmapCrop.png', cv2.IMREAD_GRAYSCALE)
# Normalize the image to the 0-255 range
cv2.normalize(img_16bit, img_16bit, 0, 255, cv2.NORM_MINMAX)
# Convert the 16-bit depth grayscale image to an 8-bit depth grayscale image
img_8bit = cv2.convertScaleAbs(img_16bit)
# Save the 8-bit depth grayscale image
cv2.imwrite('map_data/heightmap8.png', img_8bit)
global path_argv_sim
path_argv_sim = sys.argv[0]
print("WIP")
print(final_iter)
simulation.simulate("map_data/heightmap8.png", final_iter, "map_data", path_argv_sim)
customtkinter.set_appearance_mode("dark")
root = customtkinter.CTk()
root.title("Azgaar to CK3")
root.geometry("1200x700")
frame = customtkinter.CTkFrame(master=root, width = 200, height =600)
frame.pack(side="left", fill="y")
canvas = tk.Canvas(root, width=1366, height=1024)
canvas.pack(pady=15)
provinceMethod = customtkinter.StringVar(value="BFS") # set initial value
# Create label for scaling factor
scaling_factor_label = customtkinter.CTkLabel(frame, text="Enter scaling factor:")
scaling_factor_label.pack()
global scaling_factor_entry
scaling_factor_entry = customtkinter.CTkEntry(frame)
scaling_factor_entry.insert(0,"50")
scaling_factor_entry.pack()
scaling_factor = scaling_factor_entry.get()
select_geojson_file_button = customtkinter.CTkButton(frame, text="Select Cells geojson file", command=select_geojson_file)
select_geojson_file_button.pack(padx=20, pady=10)
select_riversgeojson_file_button = customtkinter.CTkButton(frame,text="Select Rivers geojson file", command=select_riversgeojson_file)
select_riversgeojson_file_button.pack(padx=20, pady=10)
select_json_file_button = customtkinter.CTkButton(frame,text="Select JSON file", command=select_json_file)
select_json_file_button.pack(padx=20, pady=10)
select_output_folder_button = customtkinter.CTkButton(frame,text="Select output folder", command=select_output_folder)
select_output_folder_button.pack(padx=20, pady=10)
generate_button = customtkinter.CTkButton(frame,text="Generate maps", command=run_generator)
generate_button.pack(padx=20, pady=10)
scaling_factor_label = customtkinter.CTkLabel(frame, text="Province Generation Method:")
scaling_factor_label.pack()
def combobox_callback(choice):
print("combobox dropdown clicked:", choice)
combobox = customtkinter.CTkComboBox(master=frame,
values=["BFS", "Cells"],
command=combobox_callback,
variable=provinceMethod)
combobox.pack(padx=20, pady=10)
label = customtkinter.CTkLabel(frame, text="Output folder must be same folder as the .exe and .py files")
label.pack(padx=20, pady=10)
image_button = customtkinter.CTkButton(frame,text="View Heightmap Image", command=add_image)
image_button.pack(padx=20, pady=10)
label = customtkinter.CTkLabel(frame, text="Heightmap Erosion Tool")
label.pack(padx=20, pady=10)
scaling_factor_label = customtkinter.CTkLabel(frame, text="Tile Number:")
scaling_factor_label.pack()
global tNum
tNum = customtkinter.CTkEntry(frame)
tNum.insert(0,"4")
tNum.pack()
tNumber = int(tNum.get())
scaling_factor_label = customtkinter.CTkLabel(frame, text="Enter Iterations:")
scaling_factor_label.pack()
global e_iter
e_iter = customtkinter.CTkEntry(frame)
e_iter.insert(0,"128")
e_iter.pack()
generate_button = customtkinter.CTkButton(frame,text="Run Erosion", command=erodeSim)
generate_button.pack(padx=20, pady=10)
label = customtkinter.CTkLabel(frame, text="The Erosion process is slow and runs at the speed of ((NxN)^3)*T")
label.pack()
label = customtkinter.CTkLabel(frame, text="where N is resolution and T is Number of Tiles")
label.pack()
root.mainloop()
if __name__ == '__main__':
main(sys.argv)