mirror of
https://github.com/tuxitop/chessview.git
synced 2026-07-22 06:27:57 +00:00
null guarding fixes
This commit is contained in:
parent
ee903da160
commit
60de5f93d2
4 changed files with 38 additions and 33 deletions
|
|
@ -430,12 +430,12 @@ export class BoardManager {
|
|||
applyTheme(): void {
|
||||
const theme = this.settings.boardTheme;
|
||||
const colors =
|
||||
theme === 'custom'
|
||||
? {
|
||||
light: this.settings.lightSquareColor,
|
||||
dark: this.settings.darkSquareColor
|
||||
}
|
||||
: BOARD_THEMES[theme];
|
||||
theme === 'custom'
|
||||
? {
|
||||
light: this.settings.lightSquareColor,
|
||||
dark: this.settings.darkSquareColor
|
||||
}
|
||||
: BOARD_THEMES[theme] ?? BOARD_THEMES['brown'];
|
||||
|
||||
this.container.style.setProperty('--cv-light', colors.light);
|
||||
this.container.style.setProperty('--cv-dark', colors.dark);
|
||||
|
|
|
|||
|
|
@ -407,8 +407,13 @@ export class NavigationController {
|
|||
}
|
||||
|
||||
const move = this.moves[this.currentMoveIndex - 1];
|
||||
const hasNag = move?.nag;
|
||||
const hasComment = move?.comment;
|
||||
if (!move) {
|
||||
this.commentEl.addClass('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
const hasNag = !!move.nag;
|
||||
const hasComment = !!move.comment;
|
||||
|
||||
if (!hasNag && !hasComment) {
|
||||
this.commentEl.addClass('hidden');
|
||||
|
|
@ -417,12 +422,12 @@ export class NavigationController {
|
|||
|
||||
this.commentEl.removeClass('hidden');
|
||||
|
||||
if (hasNag) {
|
||||
const nagClass = NAG_CLASSES[move.nag!] || '';
|
||||
if (hasNag && move.nag) {
|
||||
const nagClass = NAG_CLASSES[move.nag] || '';
|
||||
const nagInfo = Object.values(NAG_SYMBOLS).find(
|
||||
(n) => n.symbol === move.nag
|
||||
);
|
||||
const label = nagInfo ? nagInfo.label : move.nag!;
|
||||
const label = nagInfo ? nagInfo.label : move.nag;
|
||||
|
||||
this.commentEl.createSpan({
|
||||
cls: `cv-comment-nag ${nagClass}`,
|
||||
|
|
@ -430,10 +435,10 @@ export class NavigationController {
|
|||
});
|
||||
}
|
||||
|
||||
if (hasComment) {
|
||||
if (hasComment && move.comment) {
|
||||
this.commentEl.createSpan({
|
||||
cls: 'cv-comment-text',
|
||||
text: move.comment!
|
||||
text: move.comment
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -371,26 +371,26 @@ export function parseMovesFromPgn(
|
|||
|
||||
try {
|
||||
const result = chess.move(moveStr, { sloppy: true });
|
||||
if (result) {
|
||||
const moveData: MoveData = {
|
||||
san: result.san,
|
||||
from: result.from,
|
||||
to: result.to,
|
||||
fen: chess.fen(),
|
||||
comment: pendingComment,
|
||||
nag: pendingNag,
|
||||
annotations: pendingAnnotation
|
||||
};
|
||||
if (!result) continue; // change from if (result) { ... } to guard clause
|
||||
|
||||
const moveData: MoveData = {
|
||||
san: result.san,
|
||||
from: result.from,
|
||||
to: result.to,
|
||||
fen: chess.fen(),
|
||||
comment: pendingComment,
|
||||
nag: pendingNag,
|
||||
annotations: pendingAnnotation
|
||||
};
|
||||
|
||||
if (inlineNag && NAG_SYMBOLS[inlineNag]) {
|
||||
moveData.nag = NAG_SYMBOLS[inlineNag].symbol;
|
||||
}
|
||||
|
||||
moves.push(moveData);
|
||||
pendingComment = undefined;
|
||||
pendingAnnotation = undefined;
|
||||
pendingNag = undefined;
|
||||
if (inlineNag && NAG_SYMBOLS[inlineNag]) {
|
||||
moveData.nag = NAG_SYMBOLS[inlineNag].symbol;
|
||||
}
|
||||
|
||||
moves.push(moveData);
|
||||
pendingComment = undefined;
|
||||
pendingAnnotation = undefined;
|
||||
pendingNag = undefined;
|
||||
} catch {
|
||||
if (warnings) {
|
||||
warnings.push(
|
||||
|
|
|
|||
|
|
@ -349,8 +349,8 @@ export class PuzzleController {
|
|||
|
||||
if (this.data.fen) {
|
||||
const parts = this.data.fen.split(/\s+/);
|
||||
if (parts[5]) startMoveNum = parseInt(parts[5]) || 1;
|
||||
if (parts[1] === 'b') startIsBlack = true;
|
||||
startMoveNum = parseInt(parts[5] ?? '1') || 1;
|
||||
startIsBlack = parts[1] === 'b';
|
||||
}
|
||||
|
||||
let moveNum = startMoveNum;
|
||||
|
|
|
|||
Loading…
Reference in a new issue