~starkingdoms/starkingdoms

ref: 0ab54c7e68714b9102ffe58c4e7b4d6285af00bd starkingdoms/starkingdoms-client/src/pages/Play.svelte -rw-r--r-- 4.3 KiB
0ab54c7eTerraMaster85 Enable antialiasing (until configurator menu) 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
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
<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";
  import Popup from "../components/ui/Popup.svelte";
  import Checkbox from "../components/ui/Checkbox.svelte";
  import { global } from "../globals.ts";
  import * as PIXI from "pixi.js";

  let config = DEFAULT_CONFIG;

  let velocity;
  let x_pos;
  let y_pos;

  //let antialiasing: boolean = false;

  let chatbox: Chatbox;

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

  /*function toggleAntialiasing() {
    global.rendering!.app.renderer.reset();
    PIXI.settings.RENDER_OPTIONS.antialias = antialiasing;
    logger("Antialiasing is now", antialiasing ? "on" : "off");
  }*/

  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,
      velocity,
      x_pos,
      y_pos,
    );
  });
</script>

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

<Popup
  draggable
  title="Packet Log"
  style="max-width: 300px; width: min-content;"
  class="log-hidden log-container"
  id="packet-log">
  <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>
</Popup>

<Chatbox bind:this={chatbox} />

<div class="options">
  <Popup
    title="Options"
    id="options"
    draggable
    minimizable
    style="width: 20vw; position: absolute;">
    <label for="dev_mode">Developer mode (Advanced)</label>
    <Checkbox
      title="Enables tools intended only for the developers. Buggy. Use at your own risk." />
  </Popup>
</div>

<div class="hud" id="hud">
  <Popup notitle title="" 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" bind:this={x_pos}>--</span>
            ,
            <span id="pos-val-y" bind:this={y_pos}>--</span>
          </td>
          <td id="velocity">
            <span id="velocity-val" bind:this={velocity}>--</span>
          </td>
          <td id="track">
            <span id="track-val">--</span>
          </td>
        </tr>
      </tbody>
    </table>
  </Popup>
</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>