Skip to content

Commit

Permalink
Add types for chess.js
Browse files Browse the repository at this point in the history
- needed to rename chess.gts to chess-game.gts because of typed-ember/glint#724
  • Loading branch information
ef4 authored and jurgenwerk committed Jun 19, 2024
1 parent 388b9f5 commit d575e18
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"meta": {
"adoptsFrom": {
"module": "../chess",
"module": "../chess-game",
"name": "Chess"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import {

//@ts-ignore
import { action } from '@ember/object';

//@ts-ignore
import { Chess as ChessJS } from 'https://cdn.jsdelivr.net/npm/chess.js/+esm';
import { Chess as _ChessJS } from 'https://cdn.jsdelivr.net/npm/chess.js/+esm';
import type { Chess as _ChessJSType } from 'chess.js';
type ChessJS = _ChessJSType;
const ChessJS: typeof _ChessJSType = _ChessJS;

//@ts-ignore
import {
MARKER_TYPE,
Expand Down Expand Up @@ -124,6 +129,7 @@ class ChessboardModifier extends Modifier<ChessboardModifierSignature> {
}
return result;
}
return undefined;
}
if (this.chessboard === undefined) {
this.chessboard = new Chessboard(element, {
Expand Down Expand Up @@ -157,9 +163,9 @@ interface ChessJSResourceArgs {
}

class ChessJSResource extends Resource<ChessJSResourceArgs> {
game: ChessJS;
snapshot: ChessJS;
private future: any[] = [];
game!: ChessJS;
snapshot!: ChessJS;
private future: string[] = [];
@tracked snapshotPgn: string | undefined;

modify(_positional: never[], named: ChessJSResourceArgs['named']) {
Expand All @@ -171,7 +177,7 @@ class ChessJSResource extends Resource<ChessJSResourceArgs> {

if (this.snapshotPgn) {
this.snapshot.loadPgn(this.snapshotPgn);
} else {
} else if (named.pgn) {
this.snapshot.loadPgn(named.pgn);
}
}
Expand Down Expand Up @@ -343,26 +349,23 @@ class ChessGameComponent extends Component<ChessGameComponentSignature> {
}

get notAtMostCurrentMove() {
return (
!this.args.analysis &&
!(this.pgnDisplay === this.game.pgn({ strict: true }))
);
return !this.args.analysis && !(this.pgnDisplay === this.game.pgn());
}

//Game state
get game() {
return this.chessJSResource.game;
}
get pgnDisplay() {
return this.snapshot.pgn({ strict: true });
return this.snapshot.pgn();
}

get isGameOver() {
return this.game.isGameOver();
}

get moves() {
return this.game.history({ verbose: true }).map((move: any) => move.san);
return this.game.history({ verbose: true }).map((move) => move.san);
}

@action
Expand All @@ -379,7 +382,7 @@ class ChessGameComponent extends Component<ChessGameComponentSignature> {
return this.snapshot.history({ verbose: true });
}
get snapshotMoves() {
return this.snapshotHistory.map((move: any) => move.san);
return this.snapshotHistory.map((move) => move.san);
}

get fen() {
Expand Down
1 change: 1 addition & 0 deletions packages/drafts-realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@cardstack/boxel-ui": "workspace:*",
"@cardstack/runtime-common": "workspace:*",
"@types/lodash": "^4.14.182",
"chess.js": "1.0.0-beta.8",
"ember-modifier": "^4.1.0",
"tracked-built-ins": "^3.3.0"
},
Expand Down
41 changes: 24 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d575e18

Please sign in to comment.