summaryrefslogtreecommitdiff
path: root/test-client
diff options
context:
space:
mode:
Diffstat (limited to 'test-client')
-rw-r--r--test-client/main.ts19
-rw-r--r--test-client/visual.ts12
2 files changed, 13 insertions, 18 deletions
diff --git a/test-client/main.ts b/test-client/main.ts
index b2deeca5..8eab832d 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -20,7 +20,7 @@
import { init_locale } from "./locale.ts";
import { MovementBase, collide_player_player, update_movement } from "./movement.ts";
import { particle_splash, tick_particles } from "./particles.ts";
-import { Gamedata, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts";
+import { Gamedata, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PacketS, PlayerID, Score, TileIndex } from "./protocol.ts";
import { V2, lerp_exp_v2_mut, normalize, lerp_exp } from "./util.ts";
import { draw_ingame, draw_wait } from "./visual.ts";
@@ -32,7 +32,7 @@ const KEY_LEFT = "KeyA"
const KEY_RIGHT = "KeyD"
const KEY_CHAT = "Enter"
const KEY_CLOSE = "Escape"
-const HANDLED_KEYS = [KEY_BOOST, KEY_CHAT, KEY_CLOSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT]
+const HANDLED_KEYS = [KEY_INTERACT, KEY_BOOST, KEY_CHAT, KEY_CLOSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT]
export let ctx: CanvasRenderingContext2D;
export let canvas: HTMLCanvasElement;
@@ -111,12 +111,9 @@ export const server_hints = new Map<string, MessageData>()
export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0], tile_collide: [], tile_interact: [], maps: [] }
-export let time_remaining: number | null = null
export let global_message: MessageData | undefined = undefined
export let my_id: PlayerID = -1
-export let points = 0
-export let demands_completed = 0
-export let demands_failed = 0
+export const score: Score = { active_recipes: 0, demands_completed: 0, demands_failed: 0, instant_recipes: 0, passive_recipes: 0, players: 0, points: 0, stars: 0, time_remaining: 0 }
export const camera: V2 = { x: 0, y: 0 }
export let camera_scale = 0.05;
export const interact_target_anim: V2 = { x: 0, y: 0 }
@@ -233,10 +230,10 @@ function packet(p: PacketC) {
break;
}
case "score":
- demands_completed = p.demands_completed
- demands_failed = p.demands_failed
- points = p.points
- time_remaining = p.time_remaining ?? null
+ score.demands_completed = p.demands_completed
+ score.demands_failed = p.demands_failed
+ score.points = p.points
+ score.time_remaining = p.time_remaining ?? null
break;
case "error":
global_message = { inner: { text: p.message }, anim_size: 0., anim_position: { x: 0, y: 0 }, timeout: { initial: 5, remaining: 5 } }
@@ -342,7 +339,7 @@ function frame_update(dt: number) {
const p = players.get(my_id)
if (!p) return
- if (time_remaining != null) time_remaining -= dt
+ score.time_remaining -= dt
const direction = normalize({
x: (+keys_down.has(KEY_RIGHT) - +keys_down.has(KEY_LEFT)),
diff --git a/test-client/visual.ts b/test-client/visual.ts
index cf8e6bf1..ece31b8b 100644
--- a/test-client/visual.ts
+++ b/test-client/visual.ts
@@ -16,7 +16,7 @@
*/
import { tr } from "./locale.ts";
-import { ItemData, MessageData, PlayerData, TileData, camera, camera_scale, canvas, ctx, data, demands_completed, demands_failed, get_interact_target, global_message, interact_active_anim, interact_possible_anim, interact_target_anim, is_lobby, items_removed, keys_down, my_id, nametag_scale_anim, players, points, server_hints, tiles, time_remaining } from "./main.ts";
+import { ItemData, MessageData, PlayerData, TileData, camera, camera_scale, canvas, ctx, data, get_interact_target, global_message, interact_active_anim, interact_possible_anim, interact_target_anim, is_lobby, items_removed, keys_down, my_id, nametag_scale_anim, players, score, server_hints, tiles } from "./main.ts";
import { PLAYER_SIZE } from "./movement.ts";
import { draw_item_sprite, draw_tile_sprite, ItemName, TileName } from "./tiles.ts";
import { V2, ceil_v2, floor_v2 } from "./util.ts";
@@ -39,7 +39,6 @@ export function draw_wait(text: string) {
ctx.fillText(text, canvas.width / 2, canvas.height / 2)
}
-
export function draw_ingame() {
ctx.fillStyle = "#111"
ctx.fillRect(0, 0, canvas.width, canvas.height)
@@ -95,13 +94,12 @@ function draw_score() {
ctx.textAlign = "left"
ctx.textBaseline = "bottom"
ctx.font = "20px sans-serif"
- if (time_remaining != undefined)
- ctx.fillText(`${tr("c.score.time_remaining")}: ${time_remaining?.toFixed(2)}`, 10, canvas.height - 90)
+ ctx.fillText(`${tr("c.score.time_remaining")}: ${score.time_remaining?.toFixed(2)}`, 10, canvas.height - 90)
ctx.font = "30px sans-serif"
- ctx.fillText(`${tr("c.score.points")}: ${points}`, 10, canvas.height - 60)
+ ctx.fillText(`${tr("c.score.points")}: ${score.points}`, 10, canvas.height - 60)
ctx.font = "20px sans-serif"
- ctx.fillText(`${tr("c.score.completed")}: ${demands_completed}`, 10, canvas.height - 30)
- ctx.fillText(`${tr("c.score.failed")}: ${demands_failed}`, 10, canvas.height - 10)
+ ctx.fillText(`${tr("c.score.completed")}: ${score.demands_completed}`, 10, canvas.height - 30)
+ ctx.fillText(`${tr("c.score.failed")}: ${score.demands_failed}`, 10, canvas.height - 10)
}
function draw_debug() {