-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRocketHost.svelte
More file actions
369 lines (354 loc) · 10.7 KB
/
RocketHost.svelte
File metadata and controls
369 lines (354 loc) · 10.7 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<script lang="ts">
import toast from "svelte-5-french-toast";
import { App, RHostBot, RHostServer } from "../../bindings/gui/index.js";
import { MAPS_STANDARD } from "../arena-names";
import closeIcon from "../assets/close.svg";
import Plus from "../assets/plus.svg.svelte";
import LauncherSelector from "../components/LauncherSelector.svelte";
import { mapStore } from "../settings";
let waiting = $state(false);
let bots: RHostBot[] = $state([]);
let botFamilies = $derived.by(() => {
let families: {
[name: string]: string[];
} = {};
for (const bot of bots) {
const fam = bot.family !== "" ? bot.family : bot.name;
if (!Object.hasOwn(families, fam)) {
families[fam] = [];
}
families[fam].push(bot.name);
}
return families;
});
function refreshRHostBots() {
App.GetRHostBots()
.then((result) => {
bots = result;
})
.catch((error) => {
toast.error(`Couldn't resolve Rocket Host bots\n${error}`, {
position: "bottom-right",
duration: 5000,
});
});
}
refreshRHostBots();
let serverAddr: string = $state(
localStorage.getItem("RHOST_SERVER_ADDR") || "",
);
$effect(() => {
localStorage.setItem("RHOST_SERVER_ADDR", serverAddr);
});
let servers: RHostServer[] = $state([]);
$effect(() => {
if (servers.length > 0) {
serverAddr =
serverAddr === "" ? `${servers[0].ip}:${servers[0].port}` : serverAddr;
}
});
function refreshRHostServers() {
App.GetRHostServers()
.then((result) => {
servers = result;
})
.catch((error) => {
toast.error(`Couldn't resolve Rocket Host server addresses\n${error}`, {
position: "bottom-right",
duration: 5000,
});
});
}
refreshRHostServers();
let blueBots: string[] = $state([]);
let orangeBots: string[] = $state([]);
let launcherOptionsVisible = $state(false);
</script>
<div class="page">
<!-- <header>
<button onclick={onBack}>
<img src={arrow_left} alt="<-" class="leftArrowImage" />
</button>
</header> -->
<div class="availableBots">
<h2>Available bots</h2>
<div class="availableBotsList">
{#each Object.keys(botFamilies) as family, i}
<div class="botEntry">
{#if botFamilies[family].length == 1}
<p>{botFamilies[family][0]}</p>
<div class="expandMe"></div>
<button
class="addToTeam blue"
onclick={() => {blueBots.push(botFamilies[family][0].split("(")[0].trim())}}
>
<Plus />
</button>
<button
class="addToTeam orange"
onclick={() => {orangeBots.push(botFamilies[family][0].split("(")[0].trim())}}
>
<Plus />
</button>
{:else}
<p>{family}</p>
<select
name={botFamilies[family] + "-select"}
id={botFamilies[family] + "-select"}
>
{#each botFamilies[family] as version, i}
<option value={version.split("(")[0].trim()}
>{version}</option
>
{/each}
</select>
<div class="expandMe"></div>
<button class="addToTeam blue" onclick={() => {
blueBots.push((
document.getElementById(botFamilies[family] + "-select"
) as any).value);
}}>
<Plus />
</button>
<button class="addToTeam orange" onclick={() => {
orangeBots.push((
document.getElementById(botFamilies[family] + "-select"
) as any).value);
}}>
<Plus />
</button>
{/if}
</div>
{/each}
</div>
</div>
<div class="teams">
<div class="blue">
<h2>Blue</h2>
<div class="botList">
{#each blueBots as bot, i}
<div class="bot">
<p>{bot}</p>
<button class="close" onclick={()=>{blueBots.splice(i, 1)}}>
<img src={closeIcon} alt="X" />
</button>
</div>
{/each}
{#if blueBots.length == 0} <p>No bots selected for this team</p> {/if}
</div>
</div>
<div class="orange">
<h2>Orange</h2>
<div class="botList">
{#each orangeBots as bot, i}
<div class="bot">
<p>{bot}</p>
<button class="close" onclick={()=>{orangeBots.splice(i, 1)}}>
<img src={closeIcon} alt="X" />
</button>
</div>
{/each}
{#if orangeBots.length == 0} <p>No bots selected for this team</p> {/if}
</div>
</div>
</div>
<footer>
<div class="options">
<div>
<label for="serverselect">Server</label>
<select name="serverselect" id="serverselect" bind:value={serverAddr}>
{#each servers as value, i}
<option value={`${value.ip}:${value.port}`}>{value.location}</option>
{/each}
</select>
</div>
<div>
<label for="mapselect">Map</label>
<select name="mapselect" id="mapselect" bind:value={$mapStore}>
{#each Object.entries(MAPS_STANDARD) as map, i}
<option value={map[1]}>{map[0]}</option>
{/each}
</select>
</div>
<div>
<label for="mapselect">Launcher</label>
<LauncherSelector bind:visible={launcherOptionsVisible} />
</div>
</div>
<div class="buttons">
<button class="start" disabled={waiting} onclick={()=>{
let launcher = localStorage.getItem("MS_LAUNCHER");
if (!launcher) {
toast.error("Please select a launcher first", {
position: "bottom-right",
duration: 5000,
});
launcherOptionsVisible = true;
return;
}
waiting = true;
let id = toast.loading("Starting rocket host game...", {
position: "bottom-right"
})
App.StartRHostMatch({
server: serverAddr,
map: $mapStore,
blueBots,
orangeBots,
launcher,
launcherArg: localStorage.getItem("MS_LAUNCHER_ARG") || ''
}).then((addr)=>{
waiting = false;
toast.success(
`Started game with address ${addr}`,
{position: "bottom-right", duration: 10000, id}
)
}).catch((e)=>{
waiting = false;
toast.error(
"Failed to start Rocket Host game\n" + e,
{position: "bottom-right", duration: 8000, id}
)
})
}}>
Start
</button>
</div>
</footer>
</div>
<style>
.page {
display: flex;
width: fit-content;
height: 100%;
max-width: 60rem;
margin: 0px 3rem;
flex-direction: column;
align-items: center;
padding: 1rem;
gap: 1.5rem;
}
h2 {
margin-bottom: 0.5rem;
}
footer {
display: flex;
width: 100%;
justify-content: space-between;
}
.options {
display: flex;
gap: 1rem;
}
.options > div {
display: flex;
flex-direction: column;
}
.options select {
font-size: 1.0rem;
padding: 0.25rem;
}
.buttons {
height: 100%;
display: flex;
align-items: end;
gap: 0.5rem;
}
.buttons button {
font-size: 1.2rem;
height: fit-content;
}
button.start {
background-color: #15680e;
}
.availableBots {
display: flex;
flex-direction: column;
}
.availableBotsList {
display: inline-grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.4rem;
}
.expandMe {
flex-grow: 1;
}
.botEntry {
display: flex;
align-items: center;
padding: 0.1rem;
background-color: var(--background-alt);
user-select: none;
-webkit-user-select: none;
border-radius: 0.3rem;
}
.botEntry p {
margin: 0px;
margin-right: 1rem;
margin-left: 0.5rem;
font-size: 1.1rem;
}
.botEntry select {
margin: 0px;
margin-right: .6rem;
}
button.addToTeam {
display: flex;
align-items: center;
justify-content: center;
margin: 0px;
padding: 0.1rem;
border-radius: 50%;
margin: 0px 0.2rem;
height: 2rem;
width: 2rem;
}
button.addToTeam.blue {
background-color: #026df9aa;
}
button.addToTeam.orange {
background-color: #f95402cc;
}
.teams {
display: flex;
width: 100%;
justify-content: center;
gap: 1rem;
}
.teams > div {
display: flex;
flex-direction: column;
flex: 1;
}
.botList {
display: flex;
flex-direction: column;
border-top: solid 3px;
padding: 0.5rem;
gap: 0.3rem;
}
.blue > .botList {
border-color: #0054a6;
}
.orange > .botList {
border-color: #f26522;
}
.bot {
display: flex;
justify-content: space-between;
align-items: center;
background-color: var(--background-alt);
width: 100%;
padding: 0.3rem 0.5rem;
border-radius: 0.3rem;
font-size: 1.1rem;
}
button.close {
padding: 0px;
}
button.close > img {
filter: invert();
height: 28px;
width: 28px;
}
</style>