~starkingdoms/starkingdoms

ref: 5eaa81cc1ccc43e7b1e086071a3e9b32c6dd8568 starkingdoms/web/play.html -rw-r--r-- 1.8 KiB
5eaa81cc — c0repwn3r recv position and planet data on the client 2 years ago
                                                                                
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
<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>StarKingdoms.TK</title>
    <link rel="stylesheet" href="/static/css/stylemain.css"></link>
    <link rel="favicon" href="/static/img/favicon.ico"></link>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</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>

        <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 } from "./dist/starkingdoms_client.js";
            init().then(() => {
                const urlSearchParams = new URLSearchParams(window.location.search);

                rust_init(urlSearchParams.get("server"), urlSearchParams.get("username")).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);
                });
            })
        </script>
    </body>
</html>