-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (90 loc) · 2.98 KB
/
index.html
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
<html>
<head>
<title>MoroboxAIEditorWeb Sample</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
</head>
<body class="vertical">
<div class="container">
<div class="row justify-content-center align-items-center">
<div class="col-auto"><div id="editor"></div></div>
</div>
<div class="row justify-content-center">
<div class="col-auto">
<button id="attach"></button>
</div>
</div>
<div class="row justify-content-center">
<div class="col-auto info"></div>
</div>
</div>
</body>
<script type="module">
import * as MoroboxAIEditor from "./src/index.ts";
let editor = null;
const attachButton = document.getElementById("attach");
function attach() {
if (editor === null) {
// Attach editor to the DOM
editor = MoroboxAIEditor.init(
// Root element of the editor
document.getElementById("editor"),
// Options for the player
{
url: "https://raw.githubusercontent.com/moroboxai/moroboxai-games/master/pong/agent.*",
language: "lua",
width: "500px",
height: "400px",
onRun: (options) => console.log("run", options),
onStop: () => console.log("stop"),
onLanguageChanged: (language) =>
console.log("selected language", language)
}
);
attachButton.textContent = "Detach Editor";
} else {
// Remove editor from DOM
editor.remove();
editor = null;
attachButton.textContent = "Attach Editor";
}
}
attachButton.onclick = () => attach();
attach();
</script>
<style>
body {
height: 100%;
margin: 0;
padding: 0;
}
.vertical {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#editor {
background: #1e1e1e;
border-radius: 1em;
box-shadow: 4px 4px 8px rgb(0 0 0 / 50%);
padding: 1em 0.5em 1em;
overflow: hidden;
}
#editor textarea {
width: 100%;
height: 100%;
resize: none;
}
.info {
text-align: center;
}
.row + .row {
margin-top: 1em;
}
</style>
</html>