Skip to content

Commit 10dd2f4

Browse files
committed
Use color type
1 parent d76779a commit 10dd2f4

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

ui/learn/src/chess.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { isRole, PromotionChar, PromotionRole, roleToSan, setFenTurn } from './u
44

55
export interface ChessCtrl {
66
dests(opts?: { illegal?: boolean }): Partial<Record<Key, Key[]>>;
7-
color(c: 'black' | 'white'): void;
8-
color(): 'black' | 'white';
7+
color(c: Color): void;
8+
color(): Color;
99
fen(): string;
1010
move(orig: Key, dest: Key, prom?: PromotionRole | PromotionChar | ''): Move | null;
1111
occupation(): Partial<Record<Key, Piece>>;
12-
kingKey(color: 'black' | 'white'): Key | undefined;
12+
kingKey(color: Color): Key | undefined;
1313
findCapture(): CgMove;
1414
findUnprotectedCapture(): CgMove | undefined;
1515
checks(): CgMove[] | null;
@@ -46,7 +46,7 @@ export default function (fen: string, appleKeys: Key[]): ChessCtrl {
4646
return chess.turn() == 'w' ? 'white' : 'black';
4747
}
4848

49-
function setColor(c: 'black' | 'white') {
49+
function setColor(c: Color) {
5050
const turn = c === 'white' ? 'w' : 'b';
5151
let newFen = setFenTurn(chess.fen(), turn);
5252
chess.load(newFen);
@@ -73,9 +73,9 @@ export default function (fen: string, appleKeys: Key[]): ChessCtrl {
7373
});
7474
};
7575

76-
function color(): 'black' | 'white';
77-
function color(c: 'black' | 'white'): void;
78-
function color(c?: 'black' | 'white') {
76+
function color(): Color;
77+
function color(c: Color): void;
78+
function color(c?: Color) {
7979
if (c) return setColor(c);
8080
else return getColor();
8181
}
@@ -113,7 +113,7 @@ export default function (fen: string, appleKeys: Key[]): ChessCtrl {
113113
});
114114
return map;
115115
},
116-
kingKey: function (color: 'black' | 'white') {
116+
kingKey: function (color: Color) {
117117
for (const i in chess.SQUARES) {
118118
const p = chess.get(chess.SQUARES[i]);
119119
if (p && p.type === 'k' && p.color === (color === 'white' ? 'w' : 'b')) return chess.SQUARES[i];

ui/learn/src/ground.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface GroundOpts {
2626
chess: ChessCtrl;
2727
offerIllegalMove?: boolean;
2828
autoCastle?: boolean;
29-
orientation: 'black' | 'white';
29+
orientation: Color;
3030
onMove(orig: Key, dest: Key): void;
3131
items: {
3232
render(pos: unknown, key: Key): MNode | undefined;
@@ -87,7 +87,7 @@ export function set(opts: GroundOpts) {
8787

8888
export const stop = cg.stop;
8989

90-
export function color(color: 'black' | 'white', dests: Dests) {
90+
export function color(color: Color, dests: Dests) {
9191
cg.set({
9292
turnColor: color,
9393
movable: {
@@ -97,7 +97,7 @@ export function color(color: 'black' | 'white', dests: Dests) {
9797
});
9898
}
9999

100-
export function fen(fen: string, color: 'black' | 'white', dests: Dests, lastMove?: [Key, Key, ...unknown[]]) {
100+
export function fen(fen: string, color: Color, dests: Dests, lastMove?: [Key, Key, ...unknown[]]) {
101101
const config = {
102102
turnColor: color,
103103
fen: fen,
@@ -127,7 +127,7 @@ export function check(chess: ChessCtrl) {
127127
}
128128

129129
interface Piece {
130-
color: 'black' | 'white';
130+
color: Color;
131131
role: PromotionRole;
132132
promoted: boolean;
133133
}

ui/learn/src/promotion.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function renderPromotion(
4848
ctrl: Ctrl,
4949
dest: Key,
5050
pieces: PromotionRole[],
51-
color: 'black' | 'white',
52-
orientation: 'black' | 'white',
51+
color: Color,
52+
orientation: Color,
5353
explain: boolean
5454
) {
5555
if (!promoting) return;

ui/learn/src/stage/list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface LevelBase {
5050
export interface LevelDefaults {
5151
id: number;
5252
apples: string | Key[];
53-
color: 'black' | 'white';
53+
color: Color;
5454
detectCapture: 'unprotected' | boolean;
5555
}
5656

0 commit comments

Comments
 (0)