Skip to content

Commit

Permalink
lib: ship wikimedia piece svgs as built-in data urls
Browse files Browse the repository at this point in the history
  • Loading branch information
zackschuster committed Oct 4, 2022
1 parent b030f0b commit 23b40fb
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 15 deletions.
9 changes: 6 additions & 3 deletions lib/chessboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-env browser */

import * as pieces from './pieces.svg.js';

// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -439,10 +441,10 @@ function expandConfig(config) {
// draggable must be true if sparePieces is enabled
if (config.sparePieces) config.draggable = true;

// default piece theme is wikipedia
// default piece theme is built-in svg
if (!Object.prototype.hasOwnProperty.call(config, 'pieceTheme') ||
(typeof config.pieceTheme !== 'string' && typeof config.pieceTheme !== 'function')) {
config.pieceTheme = 'img/chesspieces/wikipedia/{piece}.png';
config.pieceTheme = '{piece}';
}

// animation speeds
Expand Down Expand Up @@ -898,11 +900,12 @@ class Chessboard {

#buildPiece(piece, hidden, id) {
const pieceEl = new Image(this.#squareSize, this.#squareSize);
const src = this.#buildPieceImgSrc(piece);

pieceEl.src = src === piece ? pieces[src] : src;
pieceEl.alt = '';
pieceEl.classList.add(ClassNameLookup.piece);
pieceEl.dataset.piece = piece;
pieceEl.src = this.#buildPieceImgSrc(piece);

if (typeof id === 'string' && id.length > 0) {
pieceEl.id = id;
Expand Down
36 changes: 36 additions & 0 deletions lib/pieces.svg.js

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

Binary file removed website/img/chesspieces/wikipedia/bB.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/bK.png
Binary file not shown.
12 changes: 0 additions & 12 deletions website/img/chesspieces/wikipedia/bK.svg

This file was deleted.

Binary file removed website/img/chesspieces/wikipedia/bN.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/bP.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/bQ.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/bR.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/wB.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/wK.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/wN.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/wP.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/wQ.png
Binary file not shown.
Binary file removed website/img/chesspieces/wikipedia/wR.png
Binary file not shown.

0 comments on commit 23b40fb

Please sign in to comment.