Skip to content

Commit 6f3c4f0

Browse files
committed
set pgn moves
1 parent 7664bcd commit 6f3c4f0

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/components/Analysis/Pgn.vue

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<div class="pgn-display">
3-
<div class="pgn-move" v-for="move in formattedPgn" :key="move">
3+
<div
4+
class="pgn-move"
5+
v-for="(move, index) in formattedPgn"
6+
@click="sendPGNMoves(index)"
7+
>
48
{{ move }}
59
</div>
610
</div>
@@ -35,6 +39,23 @@ export default {
3539
return formatted;
3640
},
3741
},
42+
methods: {
43+
sendPGNMoves(moveIndex: number) {
44+
const formatted = this.formattedPgn;
45+
let pgn = "";
46+
47+
formatted.forEach((move, index) => {
48+
if (index > moveIndex) {
49+
return;
50+
}
51+
52+
pgn += move.trim() + " ";
53+
});
54+
55+
pgn = pgn.trim();
56+
this.$emit("send-pgn-moves", pgn);
57+
},
58+
},
3859
};
3960
</script>
4061

src/views/Analysis.vue

+26-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,26 @@ export default defineComponent({
200200
},
201201
});
202202
203-
// await this.sendEngineCommand("go");
203+
this.currentFen = this.game.fen();
204+
this.currentPgn = this.game.pgn();
205+
},
206+
async newPgnMoves(pgn: string) {
207+
await this.sendEngineCommand("stop");
208+
this.engineLines.clear();
209+
210+
this.game.loadPgn(pgn);
211+
212+
this.cg?.set({
213+
fen: this.game.fen(),
214+
turnColor: this.toColor(),
215+
lastMove: undefined,
216+
movable: {
217+
color: this.toColor(),
218+
dests: this.toDests(),
219+
},
220+
});
221+
222+
this.moveHistory = this.game.history().join(" ") + " ";
204223
205224
this.currentFen = this.game.fen();
206225
this.currentPgn = this.game.pgn();
@@ -623,7 +642,12 @@ export default defineComponent({
623642
/>
624643
</div>
625644
<div class="nav-secondary-content">
626-
<Pgn class="game-pgn" :gamePgn="currentPgn" :key="currentFen" />
645+
<Pgn
646+
class="game-pgn"
647+
@send-pgn-moves="newPgnMoves"
648+
:gamePgn="currentPgn"
649+
:key="currentFen"
650+
/>
627651
<div class="analysis-graph"></div>
628652
</div>
629653
</div>

0 commit comments

Comments
 (0)