diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-18 17:55:02 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-18 17:55:02 +0200 |
commit | a182706feb0f4112063f73a3cca8ef133cd2aa66 (patch) | |
tree | e653d8691edf7b0cd2db6c94978471dff87fb60b /test-client/main.ts | |
parent | 4c135371e37a20d458a4cbbc48e2222b67c0f994 (diff) | |
download | hurrycurry-a182706feb0f4112063f73a3cca8ef133cd2aa66.tar hurrycurry-a182706feb0f4112063f73a3cca8ef133cd2aa66.tar.bz2 hurrycurry-a182706feb0f4112063f73a3cca8ef133cd2aa66.tar.zst |
colorize message if hint or error
Diffstat (limited to 'test-client/main.ts')
-rw-r--r-- | test-client/main.ts | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index 2f828576..c4340fe8 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -98,6 +98,7 @@ export interface TileData { item?: ItemData } export interface MessageData { + style: "hint" | "normal" | "error" inner: Message anim_position: V2, anim_size: number, @@ -221,7 +222,13 @@ function packet(p: PacketC) { case "communicate": { const player = players.get(p.player)! if (p.message) { - const message = { inner: p.message, anim_size: 0., anim_position: player.anim_position, timeout: p.timeout ?? { initial: 5, remaining: 5 } }; + const message = { + inner: p.message, + anim_size: 0., + anim_position: player.anim_position, + timeout: p.timeout ?? { initial: 5, remaining: 5 }, + style: "normal" as const + }; if (p.timeout === undefined) player.message = message else player.message_persist = message } else if (p.timeout !== undefined) { @@ -236,8 +243,13 @@ function packet(p: PacketC) { score.time_remaining = p.time_remaining ?? null break; case "server_message": - // TODO error -> red - global_message = { inner: p.message, anim_size: 0., anim_position: { x: 0, y: 0 }, timeout: { initial: 5, remaining: 5 } } + global_message = { + inner: p.message, + style: p.error ? "error" : "normal", + anim_size: 0., + anim_position: { x: 0, y: 0 }, + timeout: { initial: 5, remaining: 5 } + } break; case "set_ingame": console.log(`ingame ${p.state}`); @@ -249,7 +261,14 @@ function packet(p: PacketC) { break; } case "server_hint": - if (p.message) server_hints.set(p.position + "", { inner: p.message, anim_size: 0., anim_position: p.position ? { x: p.position[0] + 0.5, y: p.position[1] + 0.5 } : players.get(my_id)!.anim_position }) + if (p.message) server_hints.set(p.position + "", { + inner: p.message, + anim_size: 0., + anim_position: p.position ? + { x: p.position[0] + 0.5, y: p.position[1] + 0.5 } : + players.get(my_id)!.anim_position, + style: "hint" + }) else server_hints.delete(p.position + "") break; case "environment": @@ -259,7 +278,15 @@ function packet(p: PacketC) { case "menu": switch (p.menu) { case "book": open("https://s.metamuffin.org/static/hurrycurry/book.pdf"); break - case "score": global_message = { timeout: { initial: 5, remaining: 5 }, inner: { text: `Score: ${JSON.stringify(p.data, null, 4)}` }, anim_position: { x: 0, y: 0 }, anim_size: 0 }; break + case "score": + global_message = { + timeout: { initial: 5, remaining: 5 }, + inner: { text: `Score: ${JSON.stringify(p.data, null, 4)}` }, + anim_position: { x: 0, y: 0 }, + anim_size: 0, + style: "normal" + }; + break default: console.warn("unknown menu"); } break; |