-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapcode.py
More file actions
232 lines (162 loc) · 6.22 KB
/
Copy pathmapcode.py
File metadata and controls
232 lines (162 loc) · 6.22 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
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
#Thanks for reading our code!
#Credits:
# - Casinii (map generation)
# - m10610 (pathfinding, Hubble discord bot and many awesome things!)
# - James Taxidi (for being an absolute madman and documenting all ~4600 systems. Thank you!)
import folium
from folium import plugins
import os
import json
import branca
import urllib.request
m = folium.Map(crs="Simple", tiles=None, location=(-18, -18), zoom_start=1, min_zoom=0.1)
##folium.LayerControl().add_to(m)
WormholeLines = folium.FeatureGroup(name="WormholeLines", control=False).add_to(m)
Lines = folium.FeatureGroup(name="Lines", control=False).add_to(m)
SecurityClass_Systems = folium.FeatureGroup(name="SecurityClass_Systems", control=False).add_to(m)
folium.plugins.Fullscreen(
position="topright",
force_separate_button=True,
).add_to(m)
folium.plugins.Search(
SecurityClass_Systems,
search_label="title"
).add_to(m)
img = folium.raster_layers.ImageOverlay(
name="background",
control=False,
image=os.path.join("..", "Resources", "Background.png"),
bounds=[[-10000, -10000], [10000, 10000]],
opacity=1,
interactive=True,
cross_origin=False,
zindex=1,
).add_to(m)
datafilepath=os.path.join("..", "Data", "data.json")
with open(datafilepath) as f:
jsondata = f.read()
parsedjsondata = json.loads(jsondata)
def getsystemdata(system, key): #getsystemdata("Gatinsir","spice")
# NOTHING HAPPENED IN GATINSIR SQUARE.
return(parsedjsondata[system][key])
##wormholefilepath=GET M10610 TO MAKE API FOR WORMHOLE BOT
##
##with urllib.request.urlopen("http://maps.googleapis.com/maps/api/geocode/json?address=google") as url:
## wormholedata = json.load(url)
##
##parsedwormholedata = json.loads(wormholedata)
##
##def getwormholedata(system):
## return(parsedwormholedata[system])
wormholefilepath=os.path.join("..", "Data", "wormholes.json")
with open(wormholefilepath) as f:
wormholedata = f.read()
parsedwormholedata = json.loads(wormholedata)
def getwormholedata(system):
return(parsedwormholedata[system]["links"])
currentkey = "Kegleo'iarg"
nxt_key = None
def nextkey():
for k1, k2 in zip(parsedjsondata, list(parsedjsondata)[1:]):
if k1 == currentkey:
nxt_key = k2
return nxt_key
break
donelines = []
def placesystem():
security = getsystemdata(currentkey, "security")
region = getsystemdata(currentkey, "region")
sector = getsystemdata(currentkey, "sector")
faction = getsystemdata(currentkey, "faction")
spice = getsystemdata(currentkey, "spice")
spectralclass = getsystemdata(currentkey, "spectralClass")
if security == "Core":
syscolour = "#01ff13"
elif security == "Secure":
syscolour = "#0092ff"
elif security == "Contested":
syscolour = "#ca6c1f"
elif security == "Unsecure":
syscolour = "#ca2022" #If COVID postponed your travel plans, just remember: 2022 is 2020, too!
# From a motivational sign at a local pub during COVID. This hex code made me think of the sign, and during COVID it really made my day :)
elif security == "Wild":
syscolour = "#aa21cc"
coords = getsystemdata(currentkey, "position")
xcoord = -coords[0]/10 #Reason these are negative is to combat the map flipping and rotating
ycoord = -coords[1]/10
html = f"""
<h1 style="color:{syscolour};"> {currentkey} </h1>
<p>Security Class: {security}</p>
<p>Region: {region}</p>
<p>Sector: {sector}</p>
<p>Faction: {faction}</p>
<p>Spice: {spice}</p>
<p>Spectral Class: {spectralclass}</p>
"""
iframe = branca.element.IFrame(html=html, width=250, height=275)
popup = folium.Popup(iframe, max_width=500)
radius = 0.7
folium.Circle(
title=currentkey,
location=[xcoord, ycoord],
radius=radius,
stroke=False,
fill_opacity=1,
opacity=1,
fill_color=syscolour,
fill=False,
tooltip=currentkey,
zindex = 1000,
popup = popup
).add_to(SecurityClass_Systems)
global donelines
borderingsystems = getsystemdata(currentkey, "links")
for i in borderingsystems:
first = f"{currentkey}_{i}"
second = f"{i}_{currentkey}"
if not first in donelines or not second in donelines:
donelines.append(first)
donelines.append(second)
coordsother = getsystemdata(i,"position")
xcoordother = -coordsother[0]/10
ycoordother = -coordsother[1]/10
ycoord = ycoord
xcoord = xcoord
linecoords = [
(xcoord, ycoord),
(xcoordother, ycoordother)
]
folium.PolyLine(
linecoords,
color="#AAAAAA", #AAAAAAAAAHHHHHHHH!
weight=1.5,
zindex = 3
).add_to(Lines)
if currentkey in parsedwormholedata:
wormholelinks = getwormholedata(currentkey)
for i in wormholelinks:
coordsother = getsystemdata(i, "position")
xcoordother = -coordsother[0]/10 #Not checking original system coordinates here because they were defined when drawing normal system lines, can reuse here
ycoordother = -coordsother[1]/10
linecoords = [
(xcoord, ycoord),
(xcoordother, ycoordother)
]
folium.PolyLine(
linecoords,
color="#FF00FF",
weight=3.5,
zindex = 2
).add_to(WormholeLines)
counter = 0
broken = False
while broken == False:
placesystem()
counter = counter+1
print(counter)
if currentkey == "Orcla":
broken = True
else:
currentkey = nextkey()
###################################################################
m.save("index.html")