Skip to content

Commit

Permalink
no need to hardcode all 64 squares
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 1, 2024
1 parent cf93775 commit 214e846
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
10 changes: 0 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ export type KHz = number;
export const colors = ['white', 'black'] as const;
export const files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] as const;
export const ranks = ['1', '2', '3', '4', '5', '6', '7', '8'] as const;
export const squares = {
a: ['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8'],
b: ['b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8'],
c: ['c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8'],
d: ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8'],
e: ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8'],
f: ['f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8'],
g: ['g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7', 'g8'],
h: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8'],
} as { [key: string]: string[] };

export type RanksPosition = 'left' | 'right';

Expand Down
16 changes: 8 additions & 8 deletions src/wrap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HeadlessState } from './state.js';
import { setVisible, createEl } from './util.js';
import { colors, files, ranks, squares, Elements } from './types.js';
import { colors, files, ranks, Elements } from './types.js';
import { createElement as createSVG, setAttributes, createDefs } from './svg.js';

export function renderWrap(element: HTMLElement, s: HeadlessState): Elements {
Expand Down Expand Up @@ -66,14 +66,14 @@ export function renderWrap(element: HTMLElement, s: HeadlessState): Elements {
const ranksPositionClass = s.ranksPosition === 'left' ? ' left' : '';

if (s.coordinatesOnSquares) {
let rank = 1;
Object.keys(squares).forEach(file => {
const rankClass = ' rank' + rank;
files.forEach((f, i) =>
container.appendChild(
renderCoords(squares[file], 'squares' + rankClass + orientClass + ranksPositionClass),
);
rank++;
});
renderCoords(
ranks.map(r => f + r),
'squares rank' + (i + 1) + orientClass + ranksPositionClass,
),
),
);
} else {
container.appendChild(renderCoords(ranks, 'ranks' + orientClass + ranksPositionClass));
container.appendChild(renderCoords(files, 'files' + orientClass));
Expand Down

0 comments on commit 214e846

Please sign in to comment.