Skip to content

Commit

Permalink
#436 Logic for SAN (started, not finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
mliebelt committed May 7, 2023
1 parent 3a87463 commit bcc5616
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions modules/pgn-reader/package-lock.json

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

10 changes: 7 additions & 3 deletions modules/pgn-reader/src/pgn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from '@mliebelt/pgn-parser'
import { Color, Field, GameComment, Message, PgnReaderMove, PgnGame, PgnMove, PgnDate, PgnTime, TimeControl } from '@mliebelt/pgn-types'
import { Color, Field, GameComment, Message, PgnReaderMove, PgnGame, PgnMove, PgnDate, PgnTime, TimeControl, Tags } from '@mliebelt/pgn-types'
import { writeGame, PgnWriterConfiguration } from '@mliebelt/pgn-writer'
// import { PROMOTIONS} from "@mliebelt/pgn-types";
import { ParseTree} from '@mliebelt/pgn-parser'
Expand Down Expand Up @@ -162,7 +162,11 @@ export class PgnReader {
}
getGame(index: number): PgnGame {
// this.loadOne(index)
return { moves: this.getMoves(), gameComment: this.getGameComment(), tags: this.games[index].tags }
if ( (this.games === undefined) || ! this.games[index]) {
return { moves: [] }
}
let tags: Tags = this.games[index]?.tags || <Tags>{}
return { moves: this.getMoves(), gameComment: this.getGameComment(), tags: tags }
}
possibleMoves(move: number|string): Map<Field, Field[]> {
let _fen = typeof move === 'number' ? this.getMove(move as undefined as number).fen : move
Expand Down Expand Up @@ -411,7 +415,7 @@ export class PgnReader {
return this.getMoves()[move.prev] && (this.getMoves()[move.prev].variations.length > 0)
}
writePgn(configuration:PgnWriterConfiguration = {}): string {
if (this.getGames().length === 0) return ""
if (this.getGames()?.length === 0) return ""
return writeGame(this.getGame(this.currentGameIndex) || 0, configuration)
}

Expand Down

0 comments on commit bcc5616

Please sign in to comment.