-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhunter.html
More file actions
186 lines (153 loc) · 4.07 KB
/
hunter.html
File metadata and controls
186 lines (153 loc) · 4.07 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Streamer Hunt – Hunter View</title>
<style>
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
background: #000;
}
#next-update-box {
position: absolute;
top: 10px;
left: 10px;
background: rgba(0,0,0,0.6);
padding: 8px 14px;
color: #6bd4ff;
font-size: 16px;
font-weight: bold;
border-radius: 8px;
z-index: 3000;
}
#paused-overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0,0,0,0.7);
padding: 20px 50px;
font-size: 42px;
font-weight: bold;
border-radius: 12px;
color: #fff;
display: none;
z-index: 4000;
}
</style>
</head>
<body>
<div id="paused-overlay">GAME PAUSED</div>
<div id="map"></div>
<div id="next-update-box">--:--</div>
<script>
let map;
let config;
let runnerMarker;
let roundStart;
let revealAtSec;
let intervalSec;
let cameraInitialized = false;
let gameStatus = "paused";
// 🔁 Config + State laden
Promise.all([
fetch("api.php?action=config").then(r => r.json()),
fetch("api.php?action=state").then(r => r.json())
]).then(([cfg, state]) => {
config = cfg;
roundStart = state.round_start;
revealAtSec = roundStart + (config.runner_runtime_minutes * 60);
intervalSec = config.position_frequency_minutes * 60;
const script = document.createElement("script");
script.src =
"https://maps.googleapis.com/maps/api/js?key=" +
cfg.google_maps_key +
"&callback=initMap";
script.async = true;
document.head.appendChild(script);
});
// 🔁 Game State pollen (für Pause-Overlay)
function pollGameState() {
fetch("api.php?action=state&_=" + Date.now())
.then(r => r.json())
.then(state => {
gameStatus = state.status;
const overlay = document.getElementById("paused-overlay");
if (gameStatus === "paused") {
overlay.style.display = "block";
// Marker ausblenden, Kamera zurücksetzen
if (runnerMarker) runnerMarker.setMap(null);
cameraInitialized = false;
} else {
overlay.style.display = "none";
}
});
}
setInterval(pollGameState, 2000);
pollGameState();
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: config.lat, lng: config.lng },
zoom: config.zoom ?? 14,
disableDefaultUI: true
});
runnerMarker = new google.maps.Marker({
map: null,
icon: {
path: "M -10,0 L 10,0 M 0,-10 L 0,10",
strokeColor: "#FF0000",
strokeWeight: 3
}
});
loadSnapshot();
setInterval(loadSnapshot, 5000);
setInterval(updateTimer, 1000);
}
// 📍 Snapshot laden (NIE Live!)
function loadSnapshot() {
if (gameStatus !== "running") return;
fetch("api.php?action=runner_snapshot&_=" + Date.now())
.then(r => r.json())
.then(snap => {
if (!snap || snap.lat === null) return;
const pos = { lat: snap.lat, lng: snap.lng };
runnerMarker.setPosition(pos);
runnerMarker.setMap(map);
if (!cameraInitialized) {
map.setCenter(pos);
map.setZoom(18);
cameraInitialized = true;
} else {
map.panTo(pos);
}
});
}
// ⏱ Countdown
function updateTimer() {
const box = document.getElementById("next-update-box");
// ⛔ Bei Pause komplett ausblenden
if (gameStatus !== "running") {
box.style.display = "none";
return;
}
const now = Math.floor(Date.now() / 1000);
// ⏳ Vor Reveal
if (now < revealAtSec) {
const left = revealAtSec - now;
box.textContent =
`Reveal in ${Math.floor(left/60)}:${String(left%60).padStart(2,"0")}`;
box.style.display = "block";
return;
}
// 🔁 Nächster Slot
const elapsed = now - revealAtSec;
const untilNext = intervalSec - (elapsed % intervalSec);
box.textContent =
`Next update in ${Math.floor(untilNext/60)}:${String(untilNext%60).padStart(2,"0")}`;
box.style.display = "block";
}
</script>
</body>
</html>