Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted jsutil to typescript #385

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/client/scripts/esm/chess/logic/movepiece.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import gameloader from '../../game/chess/gameloader.js';
* Type Definitions
* @typedef {import('./gamefile.js').gamefile} gamefile
* @typedef {import('../util/moveutil.js').Move} Move
* @typedef {import('../util/coordutil.js').Coords} Coords
*/

"use strict";
Expand All @@ -40,7 +41,7 @@ import gameloader from '../../game/chess/gameloader.js';
* The Piece Object.
* @typedef {Object} Piece
* @property {string} type - The type of the piece (e.g. `queensW`).
* @property {[number,number]} coords - The coordinates of the piece: `[x,y]`
* @property {Coords} coords - The coordinates of the piece: `[x,y]`
* @property {number} index - The index of the piece within the gamefile's piece list.
*/

Expand Down Expand Up @@ -222,8 +223,7 @@ function addPiece(gamefile, type, coords, desiredIndex, { updateData = true } =
if (isPieceAtCoords) throw new Error("Can't add a piece on top of another piece!");

// Remove the undefined from the undefineds list
const deleteSuccussful = jsutil.deleteValueFromOrganizedArray(gamefile.ourPieces[type].undefineds, desiredIndex) !== false;
if (!deleteSuccussful) throw new Error("Index to add a piece has an existing piece on it!");
gamefile.ourPieces[type].undefineds = jsutil.deleteElementFromOrganizedArray(gamefile.ourPieces[type].undefineds, desiredIndex);

list[desiredIndex] = coords;
}
Expand Down
3 changes: 1 addition & 2 deletions src/client/scripts/esm/chess/logic/movesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ type BlockingFunction = (friendlyColor: string, blockingPiece: Piece, gamefile?:


/** The default blocking function of each piece's sliding moves, if not specified. */
// eslint-disable-next-line no-unused-vars
function defaultBlockingFunction(friendlyColor: string, blockingPiece: Piece, gamefile?: gamefile): 0 | 1 | 2 {
function defaultBlockingFunction(friendlyColor: string, blockingPiece: Piece): 0 | 1 | 2 {
const colorOfBlockingPiece = colorutil.getPieceColorFromType(blockingPiece.type);
const isVoid = blockingPiece.type === 'voidsN';
if (friendlyColor === colorOfBlockingPiece || isVoid) return 1; // Block where it is if it is a friendly OR a void square.
Expand Down
3 changes: 1 addition & 2 deletions src/client/scripts/esm/chess/util/gamefileutility.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ function getPieceCount_IncludingUndefineds(gamefile) {
function deleteIndexFromPieceList(list, pieceIndex) {
list[pieceIndex] = undefined;
// Keep track of where the undefined indices are! Have an "undefineds" array property.
const undefinedsInsertIndex = jsutil.binarySearch_findSplitPoint(list.undefineds, pieceIndex);
list.undefineds.splice(undefinedsInsertIndex, 0, pieceIndex);
list.undefineds = jsutil.addElementToOrganizedArray(list.undefineds, pieceIndex);
}


Expand Down
3 changes: 1 addition & 2 deletions src/client/scripts/esm/chess/variants/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import omega4generator from './omega4generator.js';
import colorutil from '../util/colorutil.js';
// @ts-ignore
import typeutil from '../util/typeutil.js';
// @ts-ignore
import jsutil from '../../util/jsutil.js';
// @ts-ignore
import timeutil from '../../util/timeutil.js';
Expand Down Expand Up @@ -509,7 +508,7 @@ function getMovesets(movesetModifications: Movesets = {}, defaultSlideLimitForOl
} = {};

for (const [piece, moves] of Object.entries(origMoveset)) {
pieceMovesets[piece] = movesetModifications[piece] ? () => jsutil.deepCopyObject(movesetModifications[piece])
pieceMovesets[piece] = movesetModifications[piece] ? () => jsutil.deepCopyObject(movesetModifications[piece]!)
: () => jsutil.deepCopyObject(moves);
}

Expand Down
1 change: 0 additions & 1 deletion src/client/scripts/esm/game/chess/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import dragAnimation from '../rendering/draganimation.js';
import piecesmodel from '../rendering/piecesmodel.js';
// @ts-ignore
import loadbalancer from '../misc/loadbalancer.js';
// @ts-ignore
import jsutil from '../../util/jsutil.js';
import highlights from '../rendering/highlights/highlights.js';
import gameslot from './gameslot.js';
Expand Down
1 change: 0 additions & 1 deletion src/client/scripts/esm/game/chess/gameloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import onlinegame from "../misc/onlinegame.js";
import drawoffers from "../misc/drawoffers.js";
// @ts-ignore
import localstorage from "../../util/localstorage.js";
// @ts-ignore
import jsutil from "../../util/jsutil.js";
// @ts-ignore
import perspective from "../rendering/perspective.js";
Expand Down
4 changes: 2 additions & 2 deletions src/client/scripts/esm/game/misc/loadbalancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ function updateDeltaTime(runtime) {
lastFrameTime = runTime;
}

// Deletes frame timestamps from out list over 1 second ago
// Deletes frame timestamps from our list over 1 second ago
function trimFrames() {
// What time was it 1 second ago
const splitPoint = runTime - fpsWindow;

// Use binary search to find the split point.
const indexToSplit = jsutil.binarySearch_findValue(frames, splitPoint);
const indexToSplit = jsutil.findIndexOfPointInOrganizedArray(frames, splitPoint);

// This will not delete a timestamp if it falls exactly on the split point.
frames.splice(0, indexToSplit);
Expand Down
1 change: 0 additions & 1 deletion src/client/scripts/esm/game/rendering/spritesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { generateSpritesheet } from '../../chess/rendering/spritesheetGenerator.
import { convertSVGsToImages } from '../../chess/rendering/svgtoimageconverter.js';
// @ts-ignore
import typeutil from '../../chess/util/typeutil.js';
// @ts-ignore
import jsutil from '../../util/jsutil.js';
// @ts-ignore
import texture from './texture.js';
Expand Down
226 changes: 0 additions & 226 deletions src/client/scripts/esm/util/jsutil.js

This file was deleted.

Loading
Loading