2022-01-30 23:34:21 +01:00
|
|
|
<script lang="ts">
|
2022-02-02 19:36:18 +01:00
|
|
|
import { goto } from "$app/navigation";
|
2022-02-02 23:15:55 +01:00
|
|
|
import { onMount } from "svelte";
|
2022-02-02 19:36:18 +01:00
|
|
|
|
2022-02-02 23:15:55 +01:00
|
|
|
let editor;
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
const ace = await import("ace-builds");
|
|
|
|
editor = ace.edit("editor");
|
2022-02-04 22:41:05 +01:00
|
|
|
|
|
|
|
const python_mode = await import("ace-builds/src-noconflict/mode-python");
|
|
|
|
editor.getSession().setMode(new python_mode.Mode());
|
|
|
|
|
|
|
|
const gh_theme = await import ("ace-builds/src-noconflict/theme-github");
|
|
|
|
editor.setTheme(gh_theme);
|
2022-02-02 23:15:55 +01:00
|
|
|
});
|
2022-01-30 23:34:21 +01:00
|
|
|
|
|
|
|
async function submitCode() {
|
2022-02-02 23:15:55 +01:00
|
|
|
if (editor === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-30 23:34:21 +01:00
|
|
|
let response = await fetch("/api/submit_bot", {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2022-02-02 23:15:55 +01:00
|
|
|
code: editor.getValue(),
|
2022-01-30 23:34:21 +01:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw Error(response.statusText);
|
|
|
|
}
|
|
|
|
|
2022-02-02 19:36:18 +01:00
|
|
|
let responseData = await response.json();
|
|
|
|
let matchId = responseData["match_id"];
|
|
|
|
goto(`/submission_matches/${matchId}`);
|
2022-01-30 23:34:21 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<h1>Planetwars</h1>
|
2022-02-02 23:15:55 +01:00
|
|
|
<div id="editor" />
|
2022-02-02 19:36:18 +01:00
|
|
|
<button on:click={submitCode}>Submit</button>
|
2022-02-02 23:15:55 +01:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
#editor {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 800px;
|
|
|
|
height: 600px;
|
|
|
|
}
|
|
|
|
</style>
|