ngx-chess-board
Version:
Chess game component
54 lines (44 loc) • 1.86 kB
text/typescript
import { Component, ElementRef, Input, ViewChild } from '@angular/core';
import { PieceIconInput } from '../../utils/inputs/piece-icon-input';
export class PiecePromotionModalComponent {
modal: ElementRef;
pieceIconInput: PieceIconInput;
color = 'white';
opened = false;
private onCloseCallback: (index: number) => void;
open(closeCallback: (index: number) => void) {
this.opened = true;
this.onCloseCallback = closeCallback;
this.modal.nativeElement.style.display = 'block';
}
changeSelection(index: number){
this.modal.nativeElement.style.display = 'none';
this.opened = false;
this.onCloseCallback(index);
}
getPieceIcon(piece: string): string {
let coloredPiece = '';
switch (piece.toLowerCase()) {
case 'queen':
coloredPiece = this.color === 'white' ? this.pieceIconInput.whiteQueenUrl : this.pieceIconInput.blackQueenUrl;
break;
case 'rook':
coloredPiece = this.color === 'white' ? this.pieceIconInput.whiteRookUrl : this.pieceIconInput.blackRookUrl;
break;
case 'bishop':
coloredPiece = this.color === 'white' ? this.pieceIconInput.whiteBishopUrl : this.pieceIconInput.blackBishopUrl;
break;
case 'knight':
coloredPiece = this.color === 'white' ? this.pieceIconInput.whiteKnightUrl : this.pieceIconInput.blackKnightUrl;
break;
}
return coloredPiece;
}
}