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 | |
| parent | 428fa6fb8dac18c541c0c231f1b640ba172e52b9 (diff) | |
| download | hurrycurry-6f0424b9b4cddc0495eb673d314c570e27e61e83.tar hurrycurry-6f0424b9b4cddc0495eb673d314c570e27e61e83.tar.bz2 hurrycurry-6f0424b9b4cddc0495eb673d314c570e27e61e83.tar.zst | |
everything indexed
Diffstat (limited to 'test-client')
| -rw-r--r-- | test-client/main.ts | 19 | ||||
| -rw-r--r-- | test-client/protocol.ts | 31 | 
2 files changed, 29 insertions, 21 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)          } diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 707c09a3..d5cb2034 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -1,7 +1,13 @@ -export type ID = number;  export type Vec2 = [number, number] -export type Item = string -export type Tile = string +export type PlayerID = number +export type ItemID = number +export type ItemIndex = number +export type TileIndex = number + +export interface Gamedata { +    item_names: string[], +    tile_names: string[], +}  export type PacketS =      { join: { name: string } } @@ -9,16 +15,15 @@ export type PacketS =      | { position: { pos: Vec2, rot: number } }      | { interact: { pos: Vec2, edge: boolean } } -  export type PacketC = -    { joined: { id: ID } } -    | { add_player: { id: ID, name: string, hand?: [number, Item] } } -    | { remove_player: { id: ID } } -    | { position: { player: ID, pos: Vec2, rot: number } } -    | { take_item: { item: ID, player: ID } } -    | { put_item: { item: ID, pos: Vec2 } } -    | { produce_item: { id: ID, pos: Vec2, kind: Item } } -    | { consume_item: { id: ID, pos: Vec2 } } +    { joined: { id: PlayerID, data: Gamedata } } +    | { add_player: { id: PlayerID, name: string, hand?: [ItemID, ItemIndex] } } +    | { remove_player: { id: PlayerID } } +    | { position: { player: PlayerID, pos: Vec2, rot: number } } +    | { take_item: { item: ItemID, player: PlayerID } } +    | { put_item: { item: ItemID, pos: Vec2 } } +    | { produce_item: { id: ItemID, pos: Vec2, kind: ItemIndex } } +    | { consume_item: { id: ItemID, pos: Vec2 } }      | { set_active: { tile: Vec2 } } -    | { update_map: { pos: Vec2, tile: Tile } } +    | { update_map: { pos: Vec2, tile: TileIndex } } | 
