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

Initial shop logic #170

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"caughtErrorsIgnorePattern": "_"
}
],
"no-unneeded-ternary": ["error"],
"no-unneeded-ternary": ["warn"],
"max-len": [
"warn",
{
Expand All @@ -56,8 +56,8 @@
"ignoreStrings": true
}
],
"comma-dangle": ["error", "always-multiline"],
"camelcase": ["error"],
"comma-dangle": ["warn", "always-multiline"],
"camelcase": ["warn"],
"no-constant-condition": "off"
}
}
2 changes: 1 addition & 1 deletion development/code/LogicAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function onActionTriggered(
onPlayerAction(draggedPiece, targetPiece);
} else if (targetElement.classList.contains('item')) {
game.getItems().forEach((item) => {
if (item.position && comparePositions(item.position, targetElementPosition)) {
if (comparePositions(item.position, targetElementPosition)) {
onPlayerAction(draggedPiece, item);
}
});
Expand Down
6 changes: 3 additions & 3 deletions development/code/logic/PieceLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function validatePlayerAction(
if (draggedPiece.position.boardId !== target.position?.boardId) return false;

const legalMoves = draggedPiece.getLegalMoves();
return legalMoves.some(position => target.position && comparePositions(position, target.position));
return legalMoves.some(position => comparePositions(position, target.position));
}

function getPathPositions(start: Position, end: Position): Array<Position> {
Expand Down Expand Up @@ -56,7 +56,7 @@ function simulatePath(piece: Piece, targetPosition: Position) {

pathPositions.forEach(position => {
game.getItems().forEach(item => {
if (item.position && comparePositions(item.position, position)) {
if (comparePositions(item.position, position)) {
onActionPieceToItem(piece, item);
}
});
Expand Down Expand Up @@ -251,7 +251,7 @@ function handlePieceSpawning(targetPiece: Piece) {
});

game.getItems().forEach((item) => {
if (item.position && comparePositions(targetPiece.position, item.position)) {
if (comparePositions(targetPiece.position, item.position)) {
onActionPieceToItem(targetPiece, item);
}
});
Expand Down
6 changes: 4 additions & 2 deletions development/code/logic/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Piece } from './pieces/Pieces';
import { Position } from './pieces/PiecesUtilities';

export function comparePositions(
firstPosition: Position,
secondPosition: Position,
firstPosition: Position | undefined,
secondPosition: Position | undefined,
): boolean {
if (!firstPosition|| !secondPosition) return false;
Ido-Barnea marked this conversation as resolved.
Show resolved Hide resolved

const arePositionsEqual =
firstPosition.coordinates[0] === secondPosition.coordinates[0] &&
firstPosition.coordinates[1] === secondPosition.coordinates[1];
Expand Down
2 changes: 1 addition & 1 deletion development/code/logic/pieces/PiecesUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export interface PieceType {
export function getItemByPosition(
position: Position,
): Item | undefined {
return game.getItems().find((item) => item.position && comparePositions(position, item.position));
return game.getItems().find((item) => comparePositions(position, item.position));
}

Loading