diff options
Diffstat (limited to 'test-client')
-rw-r--r-- | test-client/main.ts | 23 | ||||
-rw-r--r-- | test-client/protocol.ts | 3 | ||||
-rw-r--r-- | test-client/visual.ts | 6 |
3 files changed, 23 insertions, 9 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index 2990c685..c2843192 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -68,10 +68,14 @@ export interface ItemData { x: number, y: number, tracking?: V2, - progress?: number - progress_warn?: boolean + active?: Involvement remove_anim?: number } +export interface Involvement { + position: number, + speed: number, + warn: boolean +} export interface PlayerData extends MovementBase { id: number, name: string, @@ -125,7 +129,7 @@ function get_item_location(loc: ItemLocation): PlayerData | TileData { function send(p: PacketS) { ws.send(JSON.stringify(p)) } function packet(p: PacketC) { - if (!["movement", "set_progress", "update_map"].includes(p.type)) + if (!["movement", "update_map"].includes(p.type)) console.log(p); switch (p.type) { case "version": @@ -186,11 +190,18 @@ function packet(p: PacketC) { if (p.item !== undefined && p.item !== null) slot.item = { kind: p.item, x: slot.position.x, y: slot.position.y, tracking: slot.position } break; } + case "clear_progress": { + delete get_item_location(p.item).item!.active + break; + } case "set_progress": { const slot = get_item_location(p.item) if (!slot.item) return - slot.item.progress = p.progress - slot.item.progress_warn = p.warn + slot.item.active = { + position: p.position, + speed: p.speed, + warn: p.warn + } break; } case "update_map": @@ -336,6 +347,8 @@ function frame_update(dt: number) { const update_item = (item: ItemData) => { if (item.tracking) lerp_exp_v2_mut(item, item.tracking, dt * 10.) + if (item.active) item.active.position += item.active.speed * dt + } for (const [pid, player] of players) { if (pid == my_id) player.anim_position.x = player.position.x, player.anim_position.y = player.position.y diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 40532c08..16cfec2c 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -53,7 +53,8 @@ export type PacketC = | { type: "movement_sync" } // Your movement is difference on the server, you should update your position from a `position` packet | { type: "move_item", from: ItemLocation, to: ItemLocation } // Item moved | { type: "set_item", location: ItemLocation, item?: ItemIndex } // the item contained in a tile or player changed - | { type: "set_progress", item: ItemLocation, progress?: number, warn: boolean } // A tile is doing something. progress goes from 0 to 1, then null when finished + | { type: "set_progress", item: ItemLocation, position: number, speed: number, warn: boolean } // A tile is doing something. position goes from 0 to 1, speed unit is in 1 per second + | { type: "clear_progress", item: ItemLocation } | { type: "update_map", tile: Vec2, kind: TileIndex | null, neighbors: [TileIndex | null] } // A map tile was changed | { type: "communicate", player: PlayerID, message?: Message, timeout?: MessageTimeout } // A player wants to communicate something, message is null when cleared | { type: "server_message", text: string } // Text message from the server diff --git a/test-client/visual.ts b/test-client/visual.ts index a54ca143..4c0a8ecc 100644 --- a/test-client/visual.ts +++ b/test-client/visual.ts @@ -120,9 +120,9 @@ function draw_item(item: ItemData) { ctx.translate(item.x, item.y) if (item.remove_anim) ctx.scale(1 - item.remove_anim, 1 - item.remove_anim) draw_item_sprite(ctx, data.item_names[item.kind] as ItemName) - if (item.progress !== null && item.progress !== undefined) { - ctx.fillStyle = item.progress_warn ? "rgba(230, 58, 58, 0.66)" : "rgba(115, 230, 58, 0.66)" - ctx.fillRect(-0.5, -0.5, 1, item.progress) + if (item.active) { + ctx.fillStyle = item.active.warn ? "rgba(230, 58, 58, 0.66)" : "rgba(115, 230, 58, 0.66)" + ctx.fillRect(-0.5, -0.5, 1, item.active.position) } ctx.restore() } |