Skip to content

Commit

Permalink
set pgn moves
Browse files Browse the repository at this point in the history
  • Loading branch information
Disservin committed Apr 10, 2023
1 parent 7664bcd commit 6f3c4f0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/components/Analysis/Pgn.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<div class="pgn-display">
<div class="pgn-move" v-for="move in formattedPgn" :key="move">
<div
class="pgn-move"
v-for="(move, index) in formattedPgn"
@click="sendPGNMoves(index)"
>
{{ move }}
</div>
</div>
Expand Down Expand Up @@ -35,6 +39,23 @@ export default {
return formatted;
},
},
methods: {
sendPGNMoves(moveIndex: number) {
const formatted = this.formattedPgn;
let pgn = "";
formatted.forEach((move, index) => {
if (index > moveIndex) {
return;
}
pgn += move.trim() + " ";
});
pgn = pgn.trim();
this.$emit("send-pgn-moves", pgn);
},
},
};
</script>

Expand Down
28 changes: 26 additions & 2 deletions src/views/Analysis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,26 @@ export default defineComponent({
},
});
// await this.sendEngineCommand("go");
this.currentFen = this.game.fen();
this.currentPgn = this.game.pgn();
},
async newPgnMoves(pgn: string) {
await this.sendEngineCommand("stop");
this.engineLines.clear();
this.game.loadPgn(pgn);
this.cg?.set({
fen: this.game.fen(),
turnColor: this.toColor(),
lastMove: undefined,
movable: {
color: this.toColor(),
dests: this.toDests(),
},
});
this.moveHistory = this.game.history().join(" ") + " ";
this.currentFen = this.game.fen();
this.currentPgn = this.game.pgn();
Expand Down Expand Up @@ -623,7 +642,12 @@ export default defineComponent({
/>
</div>
<div class="nav-secondary-content">
<Pgn class="game-pgn" :gamePgn="currentPgn" :key="currentFen" />
<Pgn
class="game-pgn"
@send-pgn-moves="newPgnMoves"
:gamePgn="currentPgn"
:key="currentFen"
/>
<div class="analysis-graph"></div>
</div>
</div>
Expand Down

0 comments on commit 6f3c4f0

Please sign in to comment.