import { html } from "common-tags"; import Player from "../../player/Player"; import chunk_ from "@arrows/array/chunk_"; class Moves { constructor(private element: HTMLElement, private player: Player) { this.element.addEventListener("click", (e) => { const target = e.target as HTMLElement; if (target?.dataset?.type === "ply") { const ply = Number(target?.dataset?.ply); this.player.goto(ply); } }); } load(moves: string[]) { const items = chunk_(2, moves).map( ([white, black], i) => html`

${i + 1}. ${white} ${black}

` ); const content = html`
${items.join("\n")} `; this.element.innerHTML = content; return this; } } export default Moves;