forked from Flame1994/CosmicTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getMap.php
114 lines (100 loc) · 6.01 KB
/
getMap.php
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
<?php
// ============================================================================
// Checks if player has jumped to a new region and loads the region map, if so.
// ============================================================================
include "php/routes.php";
session_start();
if (isset($_SESSION['CharacterID']) && isset($_GET['system'])) {
$conn = connect();
$main_system_id = $_GET['system'];
$prepared = $conn->prepare("SELECT * FROM neighbours WHERE neighbour_id = ?");
$prepared->bind_param('s', $main_system_id);
$prepared->execute();
$result = get_result($prepared);
if ($prepared->num_rows == 0) {
// If system has not been stored in database
// Get system info
$url = file_get_contents("https://esi.tech.ccp.is/dev/universe/systems/".$main_system_id."/?datasource=tranquility&language=en-us");
$content = json_decode($url, true);
$const_id = $content['constellation_id'];
$main_system_name = $content['name'];
$url2 = file_get_contents("https://esi.tech.ccp.is/latest/universe/constellations/".$const_id."/?datasource=tranquility&language=en-us");
$content2 = json_decode($url2, true);
$const_name = $content2['name'];
$region_id = $content2['region_id'];
$url3 = file_get_contents("https://esi.tech.ccp.is/latest/universe/regions/".$region_id."/?datasource=tranquility&language=en-us");
$content3 = json_decode($url3, true);
$region_name = $content3['name'];
// Checks if the region of the current system is the same as the region stored in the session
if ($region_name != $_SESSION['CharacterRegionName']) {
// If not, update the region info and load new map
$_SESSION["CharacterRegionName"] = $region_name;
$_SESSION["CharacterRegionID"] = $region_id;
echo '<canvas id="canvas" width="1000" height="800"></canvas>';
$r = str_replace(" ","_",$region_name);
$url = file_get_contents("maps/".$r.".svg.json");
$content = json_decode($url, true);
$systems = $content['map']['systems'];
foreach($systems as $system) {
echo '<div class="system current-system" id="'.$system['name'].'" style="position: absolute; left: '.($system['x']+36).'px; top: '.($system['y']+5).'px; width: 16px; height: 16px; cursor: pointer; z-index:23; background-color: #FFF;">
<div class="system-name"><h5>'.$system['name'].'</h5></div>
</div>';
}
$connections = $content['map']['connections'];
foreach($connections as $connection) {
echo '<script> drawConnection('.$connection['x1'].','.$connection['y1'].','.$connection['x2'].','.$connection['y2'].'); </script>';
}
echo '</canvas>';
}
} else {
// If system has been stored in database
// Get system info from database
while ($row = array_shift($result)) {
$region_name = $row['region'];
$region_id = $row['region_id'];
}
// Checks if the region of the current system is the same as the region stored in the session
if ($region_name != $_SESSION['CharacterRegionName']) {
$_SESSION["CharacterRegionName"] = $region_name;
$_SESSION["CharacterRegionID"] = $region_id;
echo '<canvas id="canvas" width="1000" height="800"></canvas>';
$r = str_replace(" ","_",$region_name);
$url = file_get_contents("maps/".$r.".svg.json");
$content = json_decode($url, true);
$systems = $content['map']['systems'];
foreach($systems as $system) {
if ($system['id'] == $main_system_id) {
echo ' <div class="system current-system" id="'.$system['name'].'" onmouseover="showSystemInfo(\''.$system['name'].'\', \''.$system['id'].'\')" onmouseout="hideSystemInfo(\''.$system['name'].'\')" style="position: absolute; left: '.($system['x']+36).'px; top: '.($system['y']+5).'px; width: 16px; height: 16px; cursor: pointer; background-color: #337ab7;">
<div class="system-name"><h5>'.$system['name'].'</h5></div>
<div id="'.$system['name'].'-info" class="system-info-popup">
<div class="col-xs-12">
<h5>'.$system['name'].'</h5>
<div id="'.$system['name'].'-sites"></div>
<button onclick="setDestenation('.$system['id'].')" class="btn btn-default btn-dest">Set Destination</button>
</div>
</div>
</div>';
} else {
echo ' <div class="system" id="'.$system['name'].'" onmouseover="showSystemInfo(\''.$system['name'].'\', \''.$system['id'].'\')" onmouseout="hideSystemInfo(\''.$system['name'].'\')" style="position: absolute; left: '.($system['x']+36).'px; top: '.($system['y']+5).'px; width: 16px; height: 16px; cursor: pointer; background-color: #FFF;">
<div class="system-name"><h5>'.$system['name'].'</h5></div>
<div id="'.$system['name'].'-info" class="system-info-popup">
<div class="col-xs-12">
<h5>'.$system['name'].'</h5>
<div id="'.$system['name'].'-sites"></div>
<button onclick="setDestenation('.$system['id'].')" class="btn btn-default btn-dest">Set Destination</button>
</div>
</div>
</div>';
}
}
$connections = $content['map']['connections'];
foreach($connections as $connection) {
echo '<script> drawConnection('.$connection['x1'].','.$connection['y1'].','.$connection['x2'].','.$connection['y2'].'); </script>';
}
echo '</canvas>';
}
}
$conn->close();
} else {
}
?>