From 16fc298961eecee9c2a82b9273599072a5dca0f6 Mon Sep 17 00:00:00 2001 From: Nathan Mande Date: Sat, 5 Oct 2024 17:19:26 +0200 Subject: [PATCH] refactor(web): remove `PieceId` instances --- apps/web/src/core/pieces/pieces.component.ts | 11 +++-------- apps/web/src/shared/interfaces/piece.interface.ts | 2 -- .../shared/models/instanceds/instanced-piece.model.ts | 8 ++++---- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/apps/web/src/core/pieces/pieces.component.ts b/apps/web/src/core/pieces/pieces.component.ts index e4bbfda..bbdead8 100644 --- a/apps/web/src/core/pieces/pieces.component.ts +++ b/apps/web/src/core/pieces/pieces.component.ts @@ -216,9 +216,7 @@ export class PiecesComponent { coord: BoardCoord ): MatrixPieceModel | undefined { const group = this.groups?.[pieceColor]?.[pieceGroup]; - const pieceId = Object.keys(group?.pieces ?? {}).find((id) => { - const piece = group?.pieces[parseInt(id)]; - + const piece = group?.pieces.find((piece) => { if ( group && piece && @@ -230,12 +228,9 @@ export class PiecesComponent { return false; }); - if (!group || !pieceId) return undefined; + if (!group || !piece) return undefined; - return group.pieces[parseInt(pieceId)] as unknown as MatrixPieceModel< - Type, - Color - >; + return piece as unknown as MatrixPieceModel; } public movePieceByPosition< diff --git a/apps/web/src/shared/interfaces/piece.interface.ts b/apps/web/src/shared/interfaces/piece.interface.ts index c212afa..7e55ac5 100644 --- a/apps/web/src/shared/interfaces/piece.interface.ts +++ b/apps/web/src/shared/interfaces/piece.interface.ts @@ -2,8 +2,6 @@ import { InstancedMesh, Intersection } from "three"; import { ColorVariant, PieceType } from "../enums"; import { MatrixPieceModel, InstancedPieceModel } from "../models"; -export type PieceId = number; - export type PieceNotificationPayload< T extends InstancedMesh = InstancedMesh, Extra extends object = object diff --git a/apps/web/src/shared/models/instanceds/instanced-piece.model.ts b/apps/web/src/shared/models/instanceds/instanced-piece.model.ts index b15df2d..afcd611 100644 --- a/apps/web/src/shared/models/instanceds/instanced-piece.model.ts +++ b/apps/web/src/shared/models/instanceds/instanced-piece.model.ts @@ -8,7 +8,7 @@ import { Subject, Subscription } from "rxjs"; import { Physics } from "@chess-d/rapier-physics"; import { PhysicsProperties } from "@chess-d/rapier-physics/dist/types"; -import { BoardCoord, PieceId } from "../../interfaces"; +import { BoardCoord } from "../../interfaces"; import { ColorVariant, PieceType } from "../../enums"; import { COLOR_BLACK, COLOR_WHITE } from "../../constants"; import { MatrixPieceModel } from "../matrixes/matrix-piece.model"; @@ -187,12 +187,12 @@ export class InstancedPieceModel< } public dropPiece( - id: PieceId, + instanceId: number, physics?: Physics ): InstancedPieceModel | undefined { - if (!this.pieces[id] || !physics) return undefined; + if (!this.pieces[instanceId] || !physics) return undefined; - this._deletePiece(id); + this._deletePiece(instanceId); return this._reConstruct(physics, this.pieces); }