Skip to content

Commit

Permalink
v-2.1.3 use light & dark squares (instead of white & black)
Browse files Browse the repository at this point in the history
  • Loading branch information
nakednous committed Nov 16, 2024
1 parent eba878e commit 70b24a0
Showing 1 changed file with 51 additions and 23 deletions.
74 changes: 51 additions & 23 deletions p5.quadrille.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,65 @@ class Quadrille {
// chess specific stuff

/**
* Default chess black squares.
* Default chess dark squares.
*/
static _darkSquare = '#D28C45'; // Wikipedia; '#769555' // chess.com

// Getter for darkSquare
static get darkSquare() {
return this._darkSquare;
}

// Setter for darkSquare with type checking
static set darkSquare(value) {
this._darkSquare = typeof value === 'string' || this._isColor(value) ? value : this._darkSquare;
}

/**
* Default chess light squares.
*/
static _blackSquare = '#D28C45'; // wikipedia; '#769656' // chess.com
static _lightSquare = '#FDCDAA'; // Wikipedia; '#EBECCF' // chess.com

// Getter for lightSquare
static get lightSquare() {
return this._lightSquare;
}

// Getter for blackSquare
// Setter for lightSquare with type checking
static set lightSquare(value) {
this._lightSquare = typeof value === 'string' || this._isColor(value) ? value : this._lightSquare;
}

/**
* Deprecated: Getter for blackSquare (use darkSquare instead)
*/
static get blackSquare() {
return this._blackSquare;
console.warn('Warning: blackSquare is deprecated and will be removed in a future release. Use darkSquare instead.');
return this._darkSquare;
}

// Setter for blackSquare with type checking
/**
* Deprecated: Setter for blackSquare (use darkSquare instead)
*/
static set blackSquare(value) {
this._blackSquare = typeof value === 'string' || this._isColor(value) ? value : this._blackSquare;
console.warn('Warning: blackSquare is deprecated and will be removed in a future release. Use darkSquare instead.');
this.darkSquare = value;
}

/**
* Default chess white squares.
* Deprecated: Getter for whiteSquare (use lightSquare instead)
*/
static _whiteSquare = '#FDCDAA'; // wikipedia; '#EEEED2' //chess.com

// Getter for whiteSquare
static get whiteSquare() {
return this._whiteSquare;
console.warn('Warning: whiteSquare is deprecated and will be removed in a future release. Use lightSquare instead.');
return this._lightSquare;
}

// Setter for whiteSquare with type checking
/**
* Deprecated: Setter for whiteSquare (use lightSquare instead)
*/
static set whiteSquare(value) {
this._whiteSquare = typeof value === 'string' || this._isColor(value) ? value : this._whiteSquare;
console.warn('Warning: whiteSquare is deprecated and will be removed in a future release. Use lightSquare instead.');
this.lightSquare = value;
}

static chessSymbols = {
Expand Down Expand Up @@ -263,7 +295,7 @@ class Quadrille {
* 1. Pass no params.
* 2. Pass width and height to construct and empty quadrille (filled with null's).
* 3. Pass two colors (either p5.Color instances or HTML color strings) to construct an 8x8 chessboard pattern
* using the specified colors for white and black squares.
* using the specified colors for light and dark squares.
* 4. Pass jagged array (of colors, images, graphics, arrays, objects, strings, numbers and null).
* 5. Pass array (of colors, images, graphics arrays, objects, strings, numbers and null).
* 6. Pass width and array (of colors, images, graphics arrays, objects, strings, numbers and null).
Expand All @@ -284,17 +316,15 @@ class Quadrille {
this._origin = 'corner';
if (args.length === 0) {
this._memory2D = Array(8).fill().map(() => Array(8).fill(null));
visitQuadrille(this, (row, col) => this._memory2D[row][col] = color((row + col) % 2 === 0 ? this.constructor.whiteSquare : this.constructor.blackSquare));
visitQuadrille(this, (row, col) => this._memory2D[row][col] = color((row + col) % 2 === 0 ? this.constructor.lightSquare : this.constructor.darkSquare));
}
if (args.length === 1) {
this.memory2D = args[0];
}
if (args.length === 2 && (this.constructor._isColor(args[0]) || typeof args[0] === 'string') &&
(this.constructor._isColor(args[1]) || typeof args[1] === 'string')) {
const color1 = color(args[0]);
const color2 = color(args[1]);
this._memory2D = Array(8).fill().map(() => Array(8).fill(null));
visitQuadrille(this, (row, col) => this._memory2D[row][col] = (row + col) % 2 === 0 ? color1 : color2);
visitQuadrille(this, (row, col) => this._memory2D[row][col] = (row + col) % 2 === 0 ? color(args[0]) : color(args[1]));
return;
}
if (args.length === 2 && typeof args[0] === 'number') {
Expand Down Expand Up @@ -1006,7 +1036,7 @@ class Quadrille {
if (args.length === 0) {
visitQuadrille(this, (row, col) => {
this._memory2D[row][col] = this._clearCell(this._memory2D[row][col]);
this._memory2D[row][col] = color((row + col) % 2 === 0 ? this.constructor.whiteSquare : this.constructor.blackSquare);
this._memory2D[row][col] = color((row + col) % 2 === 0 ? this.constructor.lightSquare : this.constructor.darkSquare);
});
}
if (args.length === 1 && args[0] !== undefined) {
Expand All @@ -1019,11 +1049,9 @@ class Quadrille {
}
if (args.length === 2 && (this.constructor._isColor(args[0]) || typeof args[0] === 'string') &&
(this.constructor._isColor(args[1]) || typeof args[1] === 'string')) {
const color1 = color(args[0]);
const color2 = color(args[1]);
visitQuadrille(this, (row, col) => {
this._memory2D[row][col] = this._clearCell(this._memory2D[row][col]);
this._memory2D[row][col] = (row + col) % 2 === 0 ? color1 : color2;
this._memory2D[row][col] = (row + col) % 2 === 0 ? color(args[0]) : color(args[1]);
});
}
if (args.length === 2 && typeof args[0] === 'number' && args[1] !== undefined) {
Expand Down Expand Up @@ -1566,7 +1594,7 @@ class Quadrille {
const INFO =
{
LIBRARY: 'p5.quadrille.js',
VERSION: '2.1.2',
VERSION: '2.1.3',
HOMEPAGE: 'https://github.com/objetos/p5.quadrille.js'
};

Expand Down

0 comments on commit 70b24a0

Please sign in to comment.