diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-17 17:39:39 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:20:50 +0200 |
commit | 6f0424b9b4cddc0495eb673d314c570e27e61e83 (patch) | |
tree | 3ca2f5c8f1d16020dfa432d8a93fb1f53be93c4b /test-client/main.ts | |
parent | 428fa6fb8dac18c541c0c231f1b640ba172e52b9 (diff) | |
download | hurrycurry-6f0424b9b4cddc0495eb673d314c570e27e61e83.tar hurrycurry-6f0424b9b4cddc0495eb673d314c570e27e61e83.tar.bz2 hurrycurry-6f0424b9b4cddc0495eb673d314c570e27e61e83.tar.zst |
everything indexed
Diffstat (limited to 'test-client/main.ts')
-rw-r--r-- | test-client/main.ts | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index 3e04dc05..5f4475f2 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -1,6 +1,6 @@ /// <reference lib="dom" /> -import { ID, Item, PacketC, PacketS, Tile } from "./protocol.ts"; +import { Gamedata, ItemID, ItemIndex, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts"; import { FALLBACK_TILE, TILES } from "./tiles.ts"; import { V2, add_v2, ceil_v2, floor_v2, length, lerp_exp_v2_mut, normalize } from "./util.ts"; @@ -32,14 +32,16 @@ document.addEventListener("DOMContentLoaded", () => { setInterval(tick_update, 1000 / 25); }) -interface PlayerData { x: number; y: number, name: string, rot: number, hand?: ID, facing: V2 } -const players = new Map<number, PlayerData>() -interface ItemData { kind: Item, tile?: V2, player?: ID, tracking_player: boolean, x: number, y: number } -const items = new Map<number, ItemData>() -interface TileData { x: number; y: number, kind: Tile, items: ID[], active: boolean } +interface PlayerData { x: number; y: number, name: string, rot: number, hand?: ItemID, facing: V2 } +const players = new Map<PlayerID, PlayerData>() +interface ItemData { kind: ItemIndex, tile?: V2, player?: PlayerID, tracking_player: boolean, x: number, y: number } +const items = new Map<ItemID, ItemData>() +interface TileData { x: number; y: number, kind: TileIndex, items: ItemID[], active: boolean } const tiles = new Map<string, TileData>() -let my_id: number = -1 +let data: Gamedata = { item_names: [], tile_names: [] } + +let my_id: PlayerID = -1 const camera: V2 = { x: 0, y: 0 } const interact_target_anim: V2 = { x: 0, y: 0 } let scale = 0 @@ -49,6 +51,7 @@ function packet(p: PacketC) { if (!("position" in p)) console.log(p); if ("joined" in p) { my_id = p.joined.id + data = p.joined.data } else if ("add_player" in p) { if (p.add_player.hand) items.set(p.add_player.hand[0], { kind: p.add_player.hand[1], player: p.add_player.id, tracking_player: true, x: 0, y: 0 }) players.set(p.add_player.id, { x: 0, y: 0, name: p.add_player.name, rot: 0, hand: p.add_player.hand?.[0], facing: { x: 0, y: 1 } }) @@ -188,7 +191,7 @@ function draw_ingame() { for (const [_, tile] of tiles) { ctx.save() ctx.translate(tile.x, tile.y) - const comps = TILES[tile.kind] ?? FALLBACK_TILE + const comps = TILES[data.tile_names[tile.kind]] ?? FALLBACK_TILE for (const c of comps) { c(ctx) } |