-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
181 lines (165 loc) · 4.06 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
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
<html>
<head>
<style>
body {
background-color: black;
color: white;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
#info {
position: fixed;
outline: dashed gray 1px;
width: 300px;
text-align: center;
padding: 10px;
background-color: black;
}
.clickable-text {
cursor: pointer;
color: #3391ff;
}
.clickable-text:hover {
text-decoration: underline;
}
#wrapper {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
user-select: none;
font-size: 20px;
overflow: hidden;
}
#content {
display: flex;
flex-direction: column;
text-align: center;
}
#content div {
display: inline-table;
justify-content: center;
align-items: center;
width: 20px;
height: 20px;
box-shadow: inset 0px 0px 0px 0.25px #111;
}
.nav {
cursor: pointer;
}
.nav:hover {
box-shadow: inset 0px 0px 0px 2px #fff !important;
}
</style>
<script type="module">
import init, { click } from './pkg/roguelike.js';
window.wasmclick = click;
await init();
window.clickready = true;
window.fnc = function c(x, y) {
if (window.clickready) {
window.clickready = false;
render(window.wasmclick(x, y));
}
}
function render(wasm_out) {
let canvases = JSON.parse(wasm_out)["canvases"];
if (!window.elems) {
window.elems = [];
let content = document.getElementById("content");
content.innerHTML = "";
let canvas = canvases[0];
for (let y = canvases[0][0].length - 1; y >= 0; y--) {
let row_div = document.createElement("div");
for (let x = 0; x < canvases[0].length; x++) {
let elem = document.createElement("div");
if (!(x in window.elems)) {
window.elems[x] = [];
}
window.elems[x][y] = elem;
row_div.appendChild(elem);
}
content.appendChild(row_div);
}
}
window.frame = 0;
let interval = setInterval(() => {
let canvas = canvases[window.frame];
for (let x in canvas) {
for (let y in canvas[x]) {
let elem = window.elems[x][y];
if ("bg" in canvas[x][y]) {
elem.style.backgroundColor = canvas[x][y]["bg"];
} else {
elem.style.backgroundColor = null;
}
if (canvas[x][y]["c"] === " " && "bg" in canvas[x][y]) {
elem.innerText = ".";
elem.style.color = canvas[x][y]["bg"];
} else {
elem.innerText = canvas[x][y]["c"];
}
if (window.frame === canvases.length - 1) {
elem.setAttribute("onmousedown", "window.fnc(" + x + "," + y + ")");
if ("m" in canvas[x][y]) {
elem.classList.add("nav");
}
} else if (window.frame === 0) {
elem.classList.remove("nav");
elem.removeAttribute("onmousedown");
}
}
}
window.frame++;
if (window.frame === canvases.length) {
clearInterval(interval);
window.clickready = true;
}
}, 1);
}
window.fnc(0, 0);
</script>
</head>
<body>
<div id="info">
<span id="whatisthis" class="clickable-text" onclick="toggleInfo()">
What is this?
</span>
<div id="expandedinfo" style="display:none">
This is a Rust learning project.<br />
It is a bare-bones roguelike engine written in Rust and compiled to WebAssembly.<br />
It is open-source on <a class="clickable-text"
href="https://github.com/Elgenzay/rust-wasm-roguelike">GitHub</a>.
<div class="clickable-text" style="padding-top:10px" onclick="toggleInfo()">
Close
</div>
</div>
<script>
function toggleInfo() {
let whatisthis = document.getElementById("whatisthis");
let expandedinfo = document.getElementById("expandedinfo");
if (whatisthis.style.display !== "none") {
whatisthis.style.display = "none";
expandedinfo.style.display = "unset";
} else {
whatisthis.style.display = "unset";
expandedinfo.style.display = "none";
}
}
</script>
</div>
<div id="wrapper">
<pre id="content">
<div>
<div>l</div>
<div>o</div>
<div>a</div>
<div>d</div>
<div>i</div>
<div>n</div>
<div>g</div>
</div>
</pre>
</div>
</body>
</html>