-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfly-in.py
More file actions
115 lines (91 loc) · 3.8 KB
/
Copy pathfly-in.py
File metadata and controls
115 lines (91 loc) · 3.8 KB
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
import sys
from parser import MapParser
from schemas import MapDataDTO
from models import SimulationLevel
from playlist import MapPlaylist
from pathfinder import SpaceTimePathfinder
from engine import SimulationEngine
from controller import SimulationController
def verify_level_build(
filepath: str,
playlist: MapPlaylist,
use_gui: bool = False,
show_capacity: bool = False
) -> None:
"""Executes Simulation Pipeline"""
print(f"--- Executing Simulation Pipeline: {filepath} ---")
try:
dto: MapDataDTO = MapParser(filepath).parse()
level = SimulationLevel(dto)
print("\n[+] Calculating Cooperative Space-Time Routes...")
pathfinder = SpaceTimePathfinder(dto)
fleet_routes = pathfinder.route_fleet()
# :Establish engine and call execution lines
engine = SimulationEngine(fleet_routes, level, pathfinder.res_table)
execution_lines = engine.generate_output(show_capacity)
print("\n[+] SIMULATION TERMINAL OUTPUT:")
print("-------------------------------------------------")
for line in execution_lines:
print(line)
print("-------------------------------------------------")
# Print performance Simulation Metrics
engine.display_metrics()
if use_gui:
print("\n[+] Launching Pygame MVC Engine...")
controller = SimulationController(
level, engine, filepath, playlist
)
controller.run()
print("[+] Simulation window closed.\n")
else:
print("\n[+] Simulation complete. "
"Use --visual to see the graphical playback.")
except Exception as err:
# Cleaning Pydantic's verbose forbidden dash/space error msg
err_msg: str = str(err)
if "validation error" in err_msg:
prefix: str = err_msg.split("1 validation error")[0].strip()
# Ensure spacing after the colon
if not prefix.endswith(" "):
prefix += " "
# Slice off validation formatting
for line in err_msg.split("\n"):
if "contains forbidden characters" in line:
# Strip "Value error, " prefix
if "Value error, " in line:
line = line.split("Value error, ")[1]
# Strip "[type=value_error ...]"
clean_err: str = line.split(" [type=")[0].strip()
err_msg = f"{prefix}{clean_err}"
break
print(f"[!] Pipeline Execution Failed: {err_msg}\n")
if __name__ == "__main__":
"""Main program"""
playlist = MapPlaylist()
# :Capacity flag
show_capacity = "--capacity-info" in sys.argv
if show_capacity:
sys.argv.remove("--capacity-info")
use_gui = "--visual" in sys.argv
if use_gui:
sys.argv.remove("--visual")
if len(sys.argv) > 1:
target_file: str = sys.argv[1]
if target_file not in playlist.playlist:
playlist.playlist.insert(0, target_file)
playlist.current_index = playlist.playlist.index(target_file)
# :Verify and build level
verify_level_build(target_file, playlist, use_gui, show_capacity)
else:
print("--- Initializing Dynamic Directory Scanner ---")
if not playlist.playlist:
print("[!] CRITICAL ERROR: Directory scan yielded 0 maps.")
print(" Please ensure the 'maps/' directory exists "
"and contains valid .txt files.\n")
sys.exit(1)
print(f"[+] Scan Complete: Discovered "
f"{len(playlist.playlist)} maps.\n")
# :Call full level build
verify_level_build(
playlist.current_map_path, playlist, use_gui, show_capacity
)