Skip to content

Commit

Permalink
refactor(web): remove PieceId instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Neosoulink committed Oct 5, 2024
1 parent db47129 commit 16fc298
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
11 changes: 3 additions & 8 deletions apps/web/src/core/pieces/pieces.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ export class PiecesComponent {
coord: BoardCoord
): MatrixPieceModel<Type, Color> | 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 &&
Expand All @@ -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<Type, Color>;
}

public movePieceByPosition<
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/shared/interfaces/piece.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -187,12 +187,12 @@ export class InstancedPieceModel<
}

public dropPiece(
id: PieceId,
instanceId: number,
physics?: Physics
): InstancedPieceModel<Type, Color> | 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);
}
Expand Down

0 comments on commit 16fc298

Please sign in to comment.