blob: d647b466cfd5f1e673dd31a5b8a92d7e90728628 (
plain)
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
|
<script lang="ts">
import { createEventDispatcher, onMount } from "svelte";
import Select from "svelte-select";
let availableBots: object[] = [];
let selectedOpponent = "simplebot";
let botName: string | undefined = undefined;
const optionIdentifier = "name";
const labelIdentifier = "name";
onMount(async () => {
const res = await fetch("/api/bots", {
headers: {
"Content-Type": "application/json",
},
});
if (res.ok) {
availableBots = await res.json();
console.log(availableBots);
}
});
const dispatch = createEventDispatcher();
function submitBot() {
dispatch("submitBot");
}
function saveBot() {
dispatch("saveBot", {
botName: botName,
});
}
</script>
<div class="submit-pane">
<div class="match-form">
<div class="play-text">Select an opponent to test your bot</div>
<div class="opponentSelect">
<Select
optionIdentifier="name"
labelIdentifier="name"
items={availableBots}
bind:value={selectedOpponent}
/>
</div>
<button class="submit-button play-button" on:click={submitBot}>Play</button>
</div>
<div class="save-form">
<h4>Save your bot</h4>
<input type="text" class="bot-name-input" placeholder="bot name" bind:value={botName} />
<button class="submit-button save-button" on:click={saveBot}>Save</button>
</div>
</div>
<style lang="scss">
.submit-pane {
margin: 20px;
flex: 1;
display: flex;
flex-direction: column;
}
.opponentSelect {
margin: 20px 0;
}
.save-form {
margin-top: 8em;
}
.submit-button {
padding: 8px 16px;
border-radius: 8px;
border: 0;
font-size: 18pt;
display: block;
margin: 10px auto;
background-color: lightgreen;
cursor: pointer;
}
.play-button {
padding: 8px 16px;
border-radius: 8px;
border: 0;
font-size: 18pt;
display: block;
margin: 10px auto;
background-color: lightgreen;
cursor: pointer;
}
.bot-name-input {
width: 100%;
}
.save-button {
background-color: lightgreen;
cursor: pointer;
padding: 8px 16px;
border: 0;
}
</style>
|