~starkingdoms/starkingdoms

ref: f0286e5ee2e4f56e49f820809a9f246974d18111 starkingdoms/starkingdoms-client/src/pages/Play.svelte -rw-r--r-- 3.4 KiB
f0286e5e — core rewrite the client in svelte (part 1) 1 year, 11 months 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
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
<script lang="ts">
  import HeartIcon from "../icons/HeartIcon.svelte";

  import createDebug from "debug";
  import { hub_connect } from "../hub.ts";
  import "../css/style.scss";
  import "../css/themes/catppuccin-mocha.scss";
  import { DEFAULT_CONFIG, loadConfig } from "../config.ts";
  import Chatbox from "../components/Chatbox.svelte";
  import { onMount } from "svelte";

  let config = DEFAULT_CONFIG;

  let chatbox: Chatbox;

  const logger = createDebug("main");
  logger(
    `Hello, world! StarKingdoms ${APP_VERSION} (${COMMIT_HASH}) at your service!`,
  );
  logger("Current view: /play");

  onMount(async () => {
    config = await loadConfig();

    chatbox.addMessage("server-message", "Connecting to the game server...");

    let params = new URLSearchParams(window.location.search);

    if (!params.has("srv")) {
      chatbox.addMessage(
        "server-error",
        "Server ID missing. Redirecting to main menu in 5 seconds.",
      );
      setTimeout(() => {
        window.location.href = "/";
      }, 5000);
      return;
    }
    if (!params.has("username")) {
      chatbox.addMessage(
        "server-error",
        "Username missing. Redirecting to main menu in 5 seconds.",
      );
      setTimeout(() => {
        window.location.href = "/";
      }, 5000);
      return;
    }
    let server_id = params.get("srv")!;
    let username = params.get("username")!;

    if (!Object.keys(config.servers).includes(server_id)) {
      chatbox.addMessage(
        "server-error",
        "The selected server is currently unavailable. Redirecting to main menu in 5 seconds.",
      );
      setTimeout(() => {
        window.location.href = "/";
      }, 5000);
      return;
    }

    let server = config.servers[server_id];

    await hub_connect(server.clientHubUrl, username, chatbox);
  });
</script>

<div class="game" id="gamewindow"></div>

<div
  class="popup popup-wmin log-hidden log-container popup-max-width-300"
  id="packet_log">
  <h1>Packet Log</h1>
  <table class="log">
    <thead>
      <tr class="log-wfull">
        <th class="log-wfull log-lalign log-header log-w50">#</th>
        <th class="log-wfull log-lalign log-header">Dir</th>
        <th class="log-wfull log-lalign log-header log-w240">Type</th>
        <th class="log-wfull log-lalign log-header">Delta</th>
      </tr>
    </thead>
    <tbody id="log_body"></tbody>
  </table>
  <hr />
  <h1>Packet Explorer</h1>
  <p id="explorer_selected" class="mono">Selected: --</p>
  <table class="mono json" id="explorer_json"></table>
</div>

<Chatbox bind:this={chatbox} />

<div class="hud" id="hud">
  <div class="popup" id="hud-content-wrapper">
    <table>
      <thead>
        <tr>
          <th class="hud-d">Position</th>
          <th class="hud-d">Velocity</th>
          <th class="hud-d">Track Angle</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td id="pos">
            <span id="pos-val-x">--</span>
            ,
            <span id="pos-val-y">--</span>
          </td>
          <td id="velocity">
            <span id="velocity-val">--</span>
          </td>
          <td id="track">
            <span id="track-val">--</span>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

<span class="footer-left">
  StarKingdoms Client {APP_VERSION} ({COMMIT_HASH})
</span>
<span class="footer-right">
  Made with <HeartIcon class="footer-icon" /> by the StarKingdoms team
</span>