Skip to content

Commit

Permalink
Fixed all ESLint complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
Naviary2 committed Dec 23, 2024
1 parent 1186f50 commit 1554e4a
Show file tree
Hide file tree
Showing 28 changed files with 77 additions and 164 deletions.
2 changes: 1 addition & 1 deletion src/client/scripts/cjs/game/htmlscript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

'use strict';

/* global sound */
/* global main sound */

/**
* The server injects this script directly into the html document
Expand Down
52 changes: 26 additions & 26 deletions src/client/scripts/cjs/views/createaccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ element_usernameInput.addEventListener('input', () => { // When username field c
updateSubmitButton();
});
element_usernameInput.addEventListener('focusout', () => {
// Check username availability...
if (element_usernameInput.value.length === 0 || usernameHasError) return;

fetch(`/createaccount/username/${element_usernameInput.value}`, fetchOptions)
.then((response) => response.json())
.then((result) => {
// { allowed, reason }
// We've got the result back from the server,
// Is this username available to use?
if (result.allowed === true) return; // Not in use

// ERROR! In use!
usernameHasError = true;
createErrorElement('usernameerror', "usernameinputline");
// Change input box to red outline
element_usernameInput.style.outline = 'solid 1px red';
// Reset variable because it now exists.
const usernameError = document.getElementById("usernameerror");

// translate the message from the server if a translation is available
let result_message = result.reason;
if (translations[result_message]) result_message = translations[result_message];
usernameError.textContent = result_message;
updateSubmitButton();
});
// Check username availability...
if (element_usernameInput.value.length === 0 || usernameHasError) return;

fetch(`/createaccount/username/${element_usernameInput.value}`, fetchOptions)
.then((response) => response.json())
.then((result) => {
// { allowed, reason }
// We've got the result back from the server,
// Is this username available to use?
if (result.allowed === true) return; // Not in use

// ERROR! In use!
usernameHasError = true;
createErrorElement('usernameerror', "usernameinputline");
// Change input box to red outline
element_usernameInput.style.outline = 'solid 1px red';
// Reset variable because it now exists.
const usernameError = document.getElementById("usernameerror");

// translate the message from the server if a translation is available
let result_message = result.reason;
if (translations[result_message]) result_message = translations[result_message];
usernameError.textContent = result_message;
updateSubmitButton();
});
});


Expand Down Expand Up @@ -255,7 +255,7 @@ function validEmail(string) {

function validPassword(string) {

const regex = /^[a-zA-Z0-9!@#$%^&*\?]+$/;
const regex = /^[a-zA-Z0-9!@#$%^&*?]+$/;

if (regex.test(string) === true) return true;
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/client/scripts/esm/chess/logic/checkdetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function detectCheck(gamefile, color, attackers) {
// Input validation
if (!gamefile) throw new Error("Cannot detect check of an undefined game!");
if (color !== 'white' && color !== 'black') throw new Error(`Cannot detect check of the team of color ${color}!`);
if (attackers != null && attackers.length !== 0) throw new Error(`Attackers parameter must be an empty array []! Received: ${JSON.stringify(attackers)}`);
if (attackers !== undefined && attackers.length !== 0) throw new Error(`Attackers parameter must be an empty array []! Received: ${JSON.stringify(attackers)}`);

// Coordinates of ALL royals of this color!
const royalCoords = gamefileutility.getRoyalCoordsOfColor(gamefile, color); // [ coords1, coords2 ]
Expand Down
1 change: 0 additions & 1 deletion src/client/scripts/esm/chess/logic/checkmate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import gamefileutility from '../util/gamefileutility.js';
import moveutil from '../util/moveutil.js';
import legalmoves from './legalmoves.js';
import typeutil from '../util/typeutil.js';
import colorutil from '../util/colorutil.js';
// Import End

/**
Expand Down
2 changes: 1 addition & 1 deletion src/client/scripts/esm/chess/logic/gamefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function gamefile(metadata, { moves = [], variantOptions, gameConclusion, clockV
// Do we need to convert any checkmate win conditions to royalcapture?
if (!wincondition.isCheckmateCompatibleWithGame(this)) gamerules.swapCheckmateForRoyalCapture(this.gameRules);

organizedlines.initOrganizedPieceLists(this, { appendUndefineds: false });
organizedlines.initOrganizedPieceLists(this);
// THIS HAS TO BE AFTER gamerules.swapCheckmateForRoyalCapture() AS THIS DOES GAME-OVER CHECKS!!!
movepiece.makeAllMovesInGame(this, moves);
/** The game's conclusion, if it is over. For example, `'white checkmate'`
Expand Down
12 changes: 6 additions & 6 deletions src/client/scripts/esm/chess/logic/insufficientmaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function has_more_pieces(a, b) {
* @returns {number} sum of tuple entries
*/
function sum_tuple_coords(tuple) {
return tuple[0] + tuple [1];
return tuple[0] + tuple[1];
}

/**
Expand All @@ -153,7 +153,7 @@ function ordered_tuple_descending(tuple) {
function detectInsufficientMaterial(gamefile) {
// Only make the draw check if the win condition is checkmate for both players
if (!gamerules.doesColorHaveWinCondition(gamefile.gameRules, 'white', 'checkmate') || !gamerules.doesColorHaveWinCondition(gamefile.gameRules, 'black', 'checkmate')) return false;
if (gamerules.getWinConditionCountOfColor(gamefile.gameRules, 'white') != 1 || gamerules.getWinConditionCountOfColor(gamefile.gameRules, 'black') != 1) return false;
if (gamerules.getWinConditionCountOfColor(gamefile.gameRules, 'white') !== 1 || gamerules.getWinConditionCountOfColor(gamefile.gameRules, 'black') !== 1) return false;

// Only make the draw check if the last move was a capture or if there is no last move
const lastMove = moveutil.getLastMove(gamefile.moves);
Expand Down Expand Up @@ -181,17 +181,17 @@ function detectInsufficientMaterial(gamefile) {
}

// add bishop tuples to scenario, and make sure the first entry of the bishop lists is the largest one
if (sum_tuple_coords(bishopsW_count) != 0) scenario.bishopsW = ordered_tuple_descending(bishopsW_count);
if (sum_tuple_coords(bishopsB_count) != 0) scenario.bishopsB = ordered_tuple_descending(bishopsB_count);
if (sum_tuple_coords(bishopsW_count) !== 0) scenario.bishopsW = ordered_tuple_descending(bishopsW_count);
if (sum_tuple_coords(bishopsB_count) !== 0) scenario.bishopsB = ordered_tuple_descending(bishopsB_count);

// Temporary: Short-circuit insuffmat check if a player has a pawn that he can promote
// This is fully enough for the checkmate practice mode, for now
// Future TODO: Create new scenarios for each possible promotion combination and check them all as well
if (gamefile.gameRules.promotionRanks) {
const promotionListWhite = gamefile.gameRules.promotionsAllowed.white;
const promotionListBlack = gamefile.gameRules.promotionsAllowed.black;
if ("pawnsW" in scenario && promotionListWhite.length != 0) return false;
if ("pawnsB" in scenario && promotionListBlack.length != 0) return false;
if ("pawnsW" in scenario && promotionListWhite.length !== 0) return false;
if ("pawnsB" in scenario && promotionListBlack.length !== 0) return false;
}

// Create scenario object with inverted colors
Expand Down
14 changes: 7 additions & 7 deletions src/client/scripts/esm/chess/logic/movepiece.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function makeMove(gamefile, move, { flipTurn = true, recordMove = true, pushCloc
let specialMoveMade;
if (gamefile.specialMoves[trimmedType]) specialMoveMade = gamefile.specialMoves[trimmedType](gamefile, piece, move, { updateData, animate, updateProperties, simulated });
if (!specialMoveMade) movePiece_NoSpecial(gamefile, piece, move, { updateData, recordMove, animate, simulated }); // Move piece regularly (no special tag)
const wasACapture = move.captured != null;
const wasACapture = move.captured !== undefined;

gamefile.moveIndex++;
if (recordMove) gamefile.moves.push(move);
Expand Down Expand Up @@ -113,7 +113,7 @@ function makeMove(gamefile, move, { flipTurn = true, recordMove = true, pushCloc
* - `simulated`: Whether you plan on undo'ing this move. If *true*, then `capturedIndex` and `pawnIndex` will also be remembered, so the mesh doesn't get screwed up when rewinding. Default: *false*
*/
function storeRewindInfoOnMove(gamefile, move, pieceIndex, { simulated = false } = {}) {
const rewindInfoAlreadyPresent = move.rewindInfo != null;
const rewindInfoAlreadyPresent = move.rewindInfo !== undefined;
const rewindInfo = move.rewindInfo || {};

if (simulated && move.promotion) rewindInfo.pawnIndex = pieceIndex; // `capturedIndex` is saved elsewhere within movePiece_NoSpecial()
Expand All @@ -122,7 +122,7 @@ function storeRewindInfoOnMove(gamefile, move, pieceIndex, { simulated = false }
rewindInfo.gameConclusion = gamefile.gameConclusion;
if (gamefile.attackers) rewindInfo.attackers = jsutil.deepCopyObject(gamefile.attackers);
if (gamefile.enpassant) rewindInfo.enpassant = gamefile.enpassant;
if (gamefile.moveRuleState != null) rewindInfo.moveRuleState = gamefile.moveRuleState;
if (gamefile.moveRuleState !== undefined) rewindInfo.moveRuleState = gamefile.moveRuleState;
if (gamefile.checksGiven) rewindInfo.checksGiven = gamefile.checksGiven;
let key = coordutil.getKeyFromCoords(move.startCoords);
if (gamefile.specialRights[key]) rewindInfo.specialRightStart = true;
Expand Down Expand Up @@ -209,15 +209,15 @@ function addPiece(gamefile, type, coords, desiredIndex, { updateData = true } =
const list = gamefile.ourPieces[type];

// If no index specified, make the default the first undefined in the list!
if (desiredIndex == null) desiredIndex = list.undefineds[0];
if (desiredIndex === undefined) desiredIndex = list.undefineds[0];

// If there are no undefined placeholders left, updateData better be false, because we are going to append on the end!
if (desiredIndex == null && updateData) throw new Error("Cannot add a piece and update the data when there are no undefined placeholders remaining!");
if (desiredIndex === undefined && updateData) throw new Error("Cannot add a piece and update the data when there are no undefined placeholders remaining!");

if (desiredIndex == null) list.push(coords);
if (desiredIndex === undefined) list.push(coords);
else { // desiredIndex specified

const isPieceAtCoords = gamefileutility.getPieceTypeAtCoords(gamefile, coords) != null;
const isPieceAtCoords = gamefileutility.getPieceTypeAtCoords(gamefile, coords) !== undefined;
if (isPieceAtCoords) throw new Error("Can't add a piece on top of another piece!");

// Remove the undefined from the undefineds list
Expand Down
26 changes: 1 addition & 25 deletions src/client/scripts/esm/chess/logic/organizedlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import coordutil from '../util/coordutil.js';
* if we know the coordinates of a piece, we don't have to iterate
* through the entire list of pieces to find its type.
* @param {gamefile} gamefile - The gamefile
* @param {Object} [options] - An object that may contain the `appendUndefineds` option. If false, no undefined *null* placeholder pieces will be left for the mesh generation. Defaults to *true*. Set to false if you're planning on regenerating manually.
*/
function initOrganizedPieceLists(gamefile, { appendUndefineds = true} = {}) {
function initOrganizedPieceLists(gamefile) {
if (!gamefile.ourPieces) return console.error("Cannot init the organized lines before ourPieces is defined.");

// console.log("Begin organizing lists...")
Expand All @@ -49,10 +48,7 @@ function initOrganizedPieceLists(gamefile, { appendUndefineds = true} = {}) {

// console.log("Finished organizing lists!")

// Add extra undefined pieces into each type array!
initUndefineds(gamefile);

if (appendUndefineds) appendUndefineds(gamefile);
}

function resetOrganizedLists(gamefile) {
Expand Down Expand Up @@ -137,26 +133,6 @@ function initUndefineds(gamefile) {
// }
}


/**
* Adds more undefined placeholders, or *null* pieces, into the piece lists,
* to allocate more space in the mesh of all the pieces.
* Only called within `initOrganizedPieceLists()` because this assumes
* each piece list has zero, so it adds the exact same amount to each list.
* These placeholders are used up when pawns promote.
* @param {gamefile} gamefile - The gamefile
*/
function appendUndefineds(gamefile) {
typeutil.forEachPieceType(append);

function append(listType) {
if (!isTypeATypeWereAppendingUndefineds(gamefile, listType)) return;

const list = gamefile.ourPieces[listType];
for (let i = 0; i < pieces.extraUndefineds; i++) insertUndefinedIntoList(list);
}
}

function areWeShortOnUndefineds(gamefile) {

let weShort = false;
Expand Down
2 changes: 1 addition & 1 deletion src/client/scripts/esm/chess/logic/specialdetect.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function transferSpecialFlags_FromMoveToCoords(move, coords) {
*/
function transferSpecialFlags_FromCoordsToCoords(srcCoords, destCoords) {
for (const special of allSpecials) {
if (srcCoords[special] != null) destCoords[special] = jsutil.deepCopyObject(srcCoords[special]);
if (srcCoords[special] !== undefined) destCoords[special] = jsutil.deepCopyObject(srcCoords[special]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/scripts/esm/chess/logic/specialmove.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function pawns(gamefile, piece, move, { updateData = true, animate = true, updat
// Delete original pawn
movepiece.deletePiece(gamefile, piece, { updateData });

movepiece.addPiece(gamefile, promotionTag, move.endCoords, null, { updateData });
movepiece.addPiece(gamefile, promotionTag, move.endCoords, undefined, { updateData });

} else /* enpassantTag */ {
// Move the pawn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function generateSpritesheet(gl: WebGL2RenderingContext, images: HTMLImage
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const ctx = canvas.getContext('2d');
if (ctx === null) throw new Error('2D context null.')
if (ctx === null) throw new Error('2D context null.');

// Positioning variables
let xIndex = 0;
Expand Down
1 change: 0 additions & 1 deletion src/client/scripts/esm/chess/variants/gamerules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import jsutil from "../../util/jsutil.js";
import winconutil from "../util/winconutil.js";

/**
* This script contains the gameRules constructor,
Expand Down
3 changes: 2 additions & 1 deletion src/client/scripts/esm/components/header/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import languagedropdown from "./dropdowns/languagedropdown.js";
import boarddropdown from "./dropdowns/boarddropdown.js";
import legalmovedropdown from "./dropdowns/legalmovedropdown.js";
import perspectivedropdown from "./dropdowns/perspectivedropdown.js";
import preferences from "./preferences.js";
// Only imported so its code runs
// eslint-disable-next-line no-unused-vars
import pingmeter from "./pingmeter.js";
import preferences from "./preferences.js";


// Document Elements -------------------------------------------------------------------------
Expand Down
15 changes: 7 additions & 8 deletions src/client/scripts/esm/game/gui/guiclock.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ function set(gamefile) {
// The 10s drum countdown...
/** Reschedules the timer to play the 10-second countdown effect. */
function rescheduleCountdown(gamefile) {
const now = Date.now();
rescheduleDrum(gamefile, now);
rescheduleTicking(gamefile, now);
rescheduleTick(gamefile, now);
rescheduleDrum(gamefile);
rescheduleTicking(gamefile);
rescheduleTick(gamefile);
}

/**
Expand All @@ -249,7 +248,7 @@ function push(gamefile) {
}
}

function rescheduleDrum(gamefile, now) {
function rescheduleDrum(gamefile) {
clearTimeout(countdown.drum.timeoutID);
if (onlinegame.areInOnlineGame() && gamefile.clocks.colorTicking !== onlinegame.getOurColor()) return; // Don't play the sound effect for our opponent.
const timeUntil10SecsRemain = gamefile.clocks.currentTime[gamefile.clocks.colorTicking] - 10000;
Expand All @@ -263,7 +262,7 @@ function rescheduleDrum(gamefile, now) {
countdown.drum.timeoutID = setTimeout(playDrumAndQueueNext, timeNextDrum, gamefile, secsRemaining);
}

function rescheduleTicking(gamefile, now) {
function rescheduleTicking(gamefile) {
clearTimeout(countdown.ticking.timeoutID);
countdown.ticking.sound?.fadeOut(countdown.ticking.fadeOutDuration);
if (onlinegame.areInOnlineGame() && gamefile.clocks.colorTicking !== onlinegame.getOurColor()) return; // Don't play the sound effect for our opponent.
Expand All @@ -277,11 +276,11 @@ function rescheduleTicking(gamefile, now) {
}

// Tick sound effect right BEFORE 10 seconds is hit
function rescheduleTick(gamefile, now) {
function rescheduleTick(gamefile) {
clearTimeout(countdown.tick.timeoutID);
countdown.tick.sound?.fadeOut(countdown.tick.fadeOutDuration);
if (onlinegame.areInOnlineGame() && gamefile.clocks.colorTicking !== onlinegame.getOurColor()) return; // Don't play the sound effect for our opponent.
const timeRemain = gamefile.clocks.currentTime[gamefile.clocks.colorTicking] - countdown.tick.timeToStartFromEnd;;
const timeRemain = gamefile.clocks.currentTime[gamefile.clocks.colorTicking] - countdown.tick.timeToStartFromEnd;
if (timeRemain > 0) countdown.tick.timeoutID = setTimeout(playTickEffect, timeRemain);
else {
const offset = -timeRemain;
Expand Down
2 changes: 0 additions & 2 deletions src/client/scripts/esm/game/gui/guiguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function callback_Back() {
}

function callback_FairyBack(event) {
event = event || window.event;
if (fairyIndex === 0) return;
hideCurrentFairy();
fairyIndex--;
Expand All @@ -66,7 +65,6 @@ function callback_FairyBack(event) {
}

function callback_FairyForward(event) {
event = event || window.event;
if (fairyIndex === maxFairyIndex) return;
hideCurrentFairy();
fairyIndex++;
Expand Down
7 changes: 0 additions & 7 deletions src/client/scripts/esm/game/gui/guinavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,28 @@ function callback_CoordsChange() {
}

function callback_Back(event) {
event = event || window.event;
transition.telToPrevTel();
}

function callback_Expand(event) {
event = event || window.event;
const allCoords = gamefileutility.getCoordsOfAllPieces(game.getGamefile());
area.initTelFromCoordsList(allCoords);
}

function callback_Recenter(event) {
event = event || window.event;

const boundingBox = game.getGamefile().startSnapshot.box;
if (!boundingBox) return console.error("Cannot recenter when the bounding box of the starting position is undefined!");
area.initTelFromUnpaddedBox(boundingBox); // If you know the bounding box, you don't need a coordinate list
}

function callback_MoveRewind(event) {
event = event || window.event;
if (rewindIsLocked) return;
if (!isItOkayToRewindOrForward()) return;
lastRewindOrForward = Date.now();
rewindMove();
}

function callback_MoveForward(event) {
event = event || window.event;
if (!isItOkayToRewindOrForward()) return;
lastRewindOrForward = Date.now();
forwardMove();
Expand All @@ -244,7 +238,6 @@ function update_MoveButtons() {
}

function callback_Pause(event) {
event = event || window.event;
guipause.open();
}

Expand Down
Loading

0 comments on commit 1554e4a

Please sign in to comment.