<!DOCTYPE html>
<html lang="en-US">
<head>
<title>StarKingdoms.TK</title>
<link rel="stylesheet" href="/static/css/play.css"></link>
<meta charset="utf-8">
</head>
<body>
<div class="chatbox">
<div id="chats">
</div>
<input id="chat-value" type="text" placeholder="chat text goes here" />
<button id="chat-submit">submit</button>
<p id="status">Loading WASM module...</p>
<div id="textures">
</div>
</div>
<canvas style="width: 100%; height: 100%" id="canvas"></canvas>
<script type="module">
// If you're getting build errors here | you need to run `just build_client_bundle` first, to compile client code
// v
import init, { rust_init, send_chat, update_socket, set_status, get_texture, render_frame } from "./dist/starkingdoms_client.js";
init().then(() => {
const urlSearchParams = new URLSearchParams(window.location.search);
if (!(urlSearchParams.has("server") || urlSearchParams.has("username") || urlSearchParams.has("textures"))) {
window.location.href = "/index.html";
}
rust_init(urlSearchParams.get("server"), urlSearchParams.get("username"), urlSearchParams.get("textures")).then(() => {
document.getElementById("chat-submit").addEventListener("click", e => {
send_chat(document.getElementById("chat-value").value);
});
let interval_id;
interval_id = setInterval(() => {
update_socket().catch((e) => {
clearInterval(interval_id);
set_status("There was an error. Reload the page to reconnect.")
throw e;
});
}, 5);
let start;
function animateFrame(time) {
if (start === undefined) {
start = time;
}
let delta = time - start;
render_frame(delta);
start = time;
requestAnimationFrame(animateFrame)
}
requestAnimationFrame(animateFrame);
if (urlSearchParams.has("showTextures")) {
let textures = ["autoplr_cfg", "autoplr_error", "autoplr_on", "cargo_off", "cargo_on", "earth", "ecothruster_on", "hearty", "hub_off", "hub_on", "landingleg", "landingthruster_off", "landingthruster_on", "powerhub_off", "powerhub_on", "superthruster_off", "superthruster_on", "thruster_off", "thruster_on"];
for (let i = 0; i < textures.length; i++) {
let texture = textures[i];
let fieldset_elem = document.createElement("fieldset");
fieldset_elem.style = "width: min-content;";
fieldset_elem.classList.add("texturebox")
let legend_elem = document.createElement("legend");
legend_elem.innerText = texture;
let img_elem = document.createElement("img");
img_elem.src = get_texture(texture);
fieldset_elem.appendChild(legend_elem);
fieldset_elem.appendChild(img_elem);
document.body.appendChild(fieldset_elem);
}
}
});
})
</script>
</body>
</html>