Skip to content

Commit

Permalink
improve puzzle visual feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 20, 2024
1 parent 41c3bee commit 53a1638
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions ui/puzzle/src/autoShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NormalMove } from 'chessops/types';

interface Opts {
node: Tree.Node;
nodeList: Tree.Node[];
showComputer(): boolean;
ceval: CevalCtrl;
ground: CgApi;
Expand Down Expand Up @@ -71,15 +72,20 @@ export default function (opts: Opts): DrawShape[] {
});
} else shapes = shapes.concat(makeAutoShapesFromUci(opposite(color), n.threat.pvs[0].moves[0], 'red'));
}
const feedback = feedbackAnnotation(n, opts.nodeList[opts.nodeList.length - 2]);
return shapes.concat(annotationShapes(n)).concat(feedback ? annotationShapes(feedback) : []);
}

function feedbackAnnotation(n: Tree.Node, prev?: Tree.Node): Tree.Node | undefined {
let glyph: Tree.Glyph | undefined;
switch (n.puzzle) {
const node = n.puzzle ? n : prev?.puzzle ? prev : undefined;
switch (node?.puzzle) {
case 'good':
case 'win':
glyph = { id: 7, name: 'good', symbol: '✓' };
break;
case 'fail':
glyph = { id: 4, name: 'fail', symbol: '✗' };
}
const withPuzzleGlyphs = glyph ? { ...n, glyphs: [glyph] } : n;
return shapes.concat(annotationShapes(withPuzzleGlyphs));
return node && glyph && { ...node, glyphs: [glyph] };
}
3 changes: 2 additions & 1 deletion ui/puzzle/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export default class PuzzleCtrl implements ParentCtrl {
this.withGround(g => g.playPremove());

const progress = moveTest(this);
this.setAutoShapes();
if (progress === 'fail') site.sound.say('incorrect');
if (progress) this.applyProgress(progress);
this.reorderChildren(path);
Expand Down Expand Up @@ -349,7 +350,7 @@ export default class PuzzleCtrl implements ParentCtrl {

revertUserMove = (): void => {
if (site.blindMode) this.instantRevertUserMove();
else setTimeout(this.instantRevertUserMove, 100);
else setTimeout(this.instantRevertUserMove, 300);
};

applyProgress = (progress: undefined | 'fail' | 'win' | MoveTest): void => {
Expand Down

0 comments on commit 53a1638

Please sign in to comment.