-
Notifications
You must be signed in to change notification settings - Fork 0
/
site_manager.py
120 lines (90 loc) · 3.87 KB
/
site_manager.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
import ui
import os
from utils import file2list, push_to_json, load_json
from data_processor import process_data
from cartographer import create_images
from a_star import run_astar
from subprocess import run
import sys
from time import time
class Save:
# If "load=False", then the declared folder_path when making the save is just a path to /Saves
def __init__(self, folder_path: str, load: bool = False):
if load:
self.folder_path = folder_path
self.site_name = os.path.basename(folder_path).split('_')[-1].strip() # Parse name from <folder_path>
else:
self.site_name = ui.new_site_name()
self.folder_path = folder_path + "/Save_" + self.site_name
self.size = None
self.data_folder = self.folder_path + "/Data"
self.images_folder = self.folder_path + "/Images"
self.astar_path_image = self.images_folder + "/AStar_Path.png"
self.heightkey_surface_image = self.images_folder + "/heightkey_surface.png"
self.interface_heightkey_image = self.images_folder + "/interface_heightkey_image.png"
self.interface_slopemap_image = self.images_folder + "/interface_slopemap.png"
self.interface_texture_image = self.images_folder + "/interface_texture.png"
self.minimap_image = self.images_folder + "/minimap.png"
self.moon_surface_texture_image = self.images_folder + "/moon_surface_texture.png"
self.raw_heightmap_image = self.images_folder + "/RAW_heightmap.png"
self.slopemap_image = self.images_folder + "/slopemap.png"
self.processed_heightmap = self.images_folder + "/processed_heightmap.png"
self.info_json = self.data_folder + "/info.json"
self.data_file = self.data_folder + "/AStarRawData.npy"
self.latitude_path, self.longitude_path, self.height_path, self.slope_path = None, None, None, None
if load:
self.size = load_json(self.info_json)["SIZE_CONSTANT"]
else:
self.set_up()
def set_up(self):
print(f'starting {self.site_name} first time setup...')
start = time()
os.makedirs(self.folder_path, exist_ok=True)
os.makedirs(self.data_folder, exist_ok=True)
os.makedirs(self.images_folder, exist_ok=True)
# Paths to each data file
lat, long, ht, slope = ui.path_fetcher()
data: dict = {
"LATITUDE_PATH": lat,
"LONGITUDE_PATH": long,
"HEIGHT_PATH": ht,
"SLOPE_PATH": slope,
"SIZE_CONSTANT": len(file2list(lat)),
}
push_to_json(self.info_json, data)
self.latitude_path, self.longitude_path, self.height_path, self.slope_path = lat, long, ht, slope
self.size = data["SIZE_CONSTANT"]
process_data(self)
create_images(self)
run_astar(self)
print(f'{self.site_name} setup complete in {round(time() - start, 2)}s')
def to_string(self):
return f"{self.folder_path}"
def check_save():
save_folder = os.getcwd() + "/Saves"
if not os.path.exists(save_folder):
os.mkdir(save_folder)
path = ui.on_start()
if path:
save_ = Save(folder_path=path, load=True)
else:
save_ = Save(folder_path=save_folder, load=False)
if save_:
return save_
exit(1)
def run_smpy():
save = check_save()
# Since Display is a script, run it via Subprocess.
print(f'loading {save.site_name} visualization')
result = run([sys.executable, 'display.py'] + [save.folder_path, str(True)], text=True, capture_output=True)
# print(result.stdout)
print(f'cleared temporary files and paths')
print(f'ended {save.site_name} visualization.')
if not result.returncode == 2:
return False
return True
if __name__ == '__main__':
while True:
reset = run_smpy()
if not reset:
break