-
Notifications
You must be signed in to change notification settings - Fork 4
/
stargen.py
78 lines (54 loc) · 2.16 KB
/
stargen.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
import random
import os
import subprocess
import uuid
def get_system_data(BASE_DIR,
STARGEN_EXE_PATH,
STARGEN_DATA_PATH):
"""Generate a system and read the data from the resulting csv
"""
seed = random.randint(0, 10000000)
stargen_command = " ".join([os.path.join(BASE_DIR, STARGEN_EXE_PATH),
"-s{}".format(seed), # Looks like I need to provide a seed, if I call this too fast it gets the same seed inside stargen
"-n1",
"-e",
"-g",
# need code to handle moons in parser
# "-M"
])
output = subprocess.call(stargen_command, cwd='WinStarGen/')
f = open(os.path.join(BASE_DIR, STARGEN_DATA_PATH), 'r')
data = f.readlines()
f.close()
return data
def parse_system(data):
"""Parses a stargen system csv file
returns a dict with star and bodies keys
"""
data = [row.strip() for row in data]
headers_star = data[0]
headers_planet = data[2]
system = {}
bodies = []
star_data = zip([col.strip().replace("'", "")
for col in headers_star.split(',')],
[col.strip().replace("'", "")
for col in data[1].split(',')])
system['star'] = dict([col for col in star_data])
# add an id
system['star']['id'] = uuid.uuid4()
# Remove WinStarGen/StarGen.exe from star name
system['star']['name'] = system['star']['name'].split(' ')[1]
for body in data[3:]:
body_data = zip([col.strip().replace("'", "")
for col in headers_planet.split(',')],
[col.strip().replace("'", "")
for col in body.split(',')])
body = dict([col for col in body_data])
# Remove WinStarGen/StarGen.exe and Star name from body name
body['planet_no'] = body['planet_no'].split(' ')[2]
# add an id
body['id'] = uuid.uuid4()
bodies.append(body)
system['bodies'] = bodies
return system