-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokemonCommunityGame.html
More file actions
201 lines (181 loc) · 4.93 KB
/
PokemonCommunityGame.html
File metadata and controls
201 lines (181 loc) · 4.93 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
<html>
<head>
<style>
body,
fieldset,
legend,
img,
h1 {
display: flex;
box-sizing: content-box;
}
body {
justify-content: center;
align-items: center;
overflow: hidden;
}
fieldset {
flex-direction: column;
align-items: center;
justify-content: center;
padding: unset;
margin: unset;
border-color: #fdc331;
border-radius: 10px;
aspect-ratio: 1 / 1;
height: 146px;
filter: drop-shadow(0 1px 1px #000);
}
legend {
margin: auto;
color: #fdc331;
filter: drop-shadow(0 1px #000);
height: 18px;
}
legend:after {
content: "Next Pokemon";
}
legend.catchPokemon:after {
content: "!pokecatch";
}
img {
height: 80px;
width: 80px;
object-fit: scale-down;
display: flex;
justify-content: center;
align-items: center;
filter: drop-shadow(1px 1px 1px #000);
}
h1 {
margin: 0px;
color: #fdc331;
filter: drop-shadow(1px 1px 1px #000);
font-size: 2.5em;
}
</style>
</head>
<body>
<fieldset id="fieldset">
<legend id="legend" ></legend>
<img id="sprite-image" loading="lazy" src="https://dev.bframework.de/static/pokedex/sprites/question512.png"> </img>
<h1 id="countdown">00:00</h1>
</fieldset>
<audio id="audio-1" src="https://www.myinstants.com/media/sounds/wild-pokemon-battle.mp3" type="audio/mpeg"></audio>
<audio id="audio-2" src="https://www.myinstants.com/media/sounds/pokemon-redblueyellow-run-away-sound-effect.mp3" type="audio/mpeg"></audio>
<script>
/* How To Use:
Use Any Mode and add parameters to the URL.
Params:
- spawn: Show/Hide the Spawn Image
No Param: Default Parameter set to 'pic'.
gif: Show the Spawn GIF.
pic: Show the Spawn IMG.
hide: Hide Spawn Image.
- timer: Show/Hide the Timer
No Param: Default Parameter shows the Timer.
true: Show Timer
false: Hide Timer
- audio: Play/Mute Audio
No Param: Default to Mute Audio.
true: Play Audio.
false: Mute Audio.
*/
const backend_url = "https://poketwitch.bframework.de/",
image_url = "https://dev.bframework.de/";
const urlParams = new URLSearchParams(window.location.search),
spawn = urlParams.get("spawn") ?? "pic",
timer = urlParams.get("timer") !== "false",
audio = urlParams.get("audio") === "true";
var sprite = document.getElementById("sprite-image"),
countdown = document.getElementById("countdown"),
legend = document.getElementById("legend"),
sAud1 = document.getElementById("audio-1"),
sAud2 = document.getElementById("audio-2");
var last_pokedex_id = 0,
next_spawn,
pokedex_id,
order;
sAud1.volume = 0.1;
sAud2.volume = 0.1;
if(spawn === "hide") {
sprite.style = "display:none;";
}
if(timer !== true) {
countdown.style = "display: none;";
}
function display_image(string) {
sprite.src = image_url + string;
}
function str_pad_left(string, pad, length) {
return (new Array(length + 1).join(pad) + string).slice(-length);
}
async function fetch_data() {
await fetch(backend_url + "info/events/last_spawn/")
.then((res) => res.json())
.then((data) => {
next_spawn = data.next_spawn;
pokedex_id = data.pokedex_id;
order = data.order;
})
.catch((error) => {
next_spawn = 0;
pokedex_id = 0;
order = 0;
display_image("static/pokedex/sprites/question512.png");
});
}
async function mainloop() {
await fetch_data();
function cooldown_wait() {
if (next_spawn >= 0) {
if(timer) {
// setup timer
var minutes = Math.floor(next_spawn / 60);
var seconds = next_spawn - minutes * 60;
countdown.innerHTML =
str_pad_left(minutes, "0", 2) + ":" + str_pad_left(seconds, "0", 2);
}
if (next_spawn > 810 && last_pokedex_id !== pokedex_id) {
// 13 minutes 30 seconds and different pokemon
last_pokedex_id = pokedex_id;
if(audio) {
sAud1.play();
setTimeout(function () {
sAud1.pause();
sAud1.currentTime = 0;
}, 3000);
}
legend.classList.toggle("catchPokemon");
if(spawn === "gif") {
display_image("static/pokedex/sprites/front/" + pokedex_id + ".gif");
} else if(spawn === "pic") {
display_image("static/pokedex/png-high-res-sprites/pokemon/" + order + ".png");
}
// remove picture in 90 seconds
var hide_picture_seconds = next_spawn - 810;
setTimeout(function () {
legend.classList.toggle("catchPokemon");
display_image("static/pokedex/sprites/question512.png");
if(audio) {
sAud2.play();
}
}, hide_picture_seconds * 1000);
// reset image at 810 seconds
}
setTimeout(function () {
cooldown_wait();
}, 1000);
} else {
setTimeout(function () {
mainloop();
}, 1000);
}
next_spawn -= 1;
}
cooldown_wait();
}
mainloop();
</script>
</body>
</html>