Add icons for special cells and fix piece placement issues

pull/14/head
MiguelMLorente 2024-12-04 12:25:24 +01:00
parent 45cbf885a3
commit b72a74789c
6 changed files with 37 additions and 67 deletions

View File

@ -63,7 +63,7 @@ export class Cell {
trackType: track.type, trackType: track.type,
}; };
}) })
.some(({ trackExternalNodes, trackType }) => { .reduce((isConnected, { trackExternalNodes, trackType }) => {
let isTrackConnected: boolean = false; let isTrackConnected: boolean = false;
trackExternalNodes trackExternalNodes
.filter((node) => node.traverseBorder() instanceof Exit) .filter((node) => node.traverseBorder() instanceof Exit)
@ -98,8 +98,8 @@ export class Cell {
} }
}); });
return isTrackConnected; return isConnected || isTrackConnected;
}); }, false);
if (!hasAnyConnection) { if (!hasAnyConnection) {
throw Error("No adjacent exit or piece available to connect to"); throw Error("No adjacent exit or piece available to connect to");

BIN
web/public/factory-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
web/public/house-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -3,18 +3,12 @@
height: 100px; height: 100px;
border: 2px solid black; border: 2px solid black;
border-radius: 10%; border-radius: 10%;
position: relative;
.piece { .piece {
border-radius: 10%; border-radius: 10%;
position: relative; position: absolute;
top: 0;
&:nth-child(2) {
top: -20px;
}
&:nth-child(3) {
top: -40px;
}
&.rotate-90 { &.rotate-90 {
transform: rotate(-90deg); transform: rotate(-90deg);
@ -29,33 +23,23 @@
} }
} }
&.house { .cell-type-icon {
background-color: blue; width: 25px;
height: 25px;
padding: 2px;
margin: 2px;
position: absolute;
top: 0;
left: 0;
} }
}
&.university { .cell .exit {
background-color: orange; position: absolute;
} width: 20px;
height: 20px;
&.factory { &:has(.exit-road) {
background-color: grey;
}
.exit:has(.exit-road) {
border: solid black;
border-width: 0 1px;
.exit-road {
margin: auto;
width: 0;
height: 100%;
border: dashed black;
border-width: 0 1px;
transform: translate(calc(50% - 1px));
}
}
.exit:has(.exit-road) {
border: solid black; border: solid black;
border-width: 0 1px; border-width: 0 1px;
@ -69,7 +53,7 @@
} }
} }
.exit:has(.exit-rail) { &:has(.exit-rail) {
border-width: 0 1px; border-width: 0 1px;
.exit-rail { .exit-rail {
@ -82,7 +66,7 @@
} }
} }
.exit:has(.exit-ambivalent) { &:has(.exit-ambivalent) {
border-width: 0 1px; border-width: 0 1px;
border-style: dotted; border-style: dotted;
@ -95,47 +79,30 @@
transform: translate(calc(50%)); transform: translate(calc(50%));
} }
} }
} &:has(.exit-north), &:has(.exit-south) {
left: 50%;
.exit { }
position: relative;
width: 20px;
height: 20px;
&:has(.exit-north) { &:has(.exit-north) {
left: 50%;
transform: translate(calc(-50% - 1px), -100%); transform: translate(calc(-50% - 1px), -100%);
} }
&:has(.exit-south) { &:has(.exit-south) {
left: 50%;
top: 100%; top: 100%;
transform: translate(calc(-50% - 1px), 0%); transform: translate(calc(-50% - 1px), 0%);
} }
&:has(.exit-east), &:has(.exit-west) {
top: 50%;
}
&:has(.exit-east) { &:has(.exit-east) {
left: 100%; left: 100%;
top: 50%;
transform: rotate(90deg) translate(-50%, 0); transform: rotate(90deg) translate(-50%, 0);
} }
&:has(.exit-west) { &:has(.exit-west) {
left: 0%; left: 0%;
top: 50%;
transform: rotate(90deg) translate(-50%, 100%); transform: rotate(90deg) translate(-50%, 100%);
} }
&:has(.exit-north), &:has(.exit-south) {
+ .exit:has(.exit-east) {
left: 100%;
transform: rotate(90deg) translate(-150%, 0);
}
}
&:has(.exit-north), &:has(.exit-south) {
+ .exit:has(.exit-west) {
top: 50%;
transform: rotate(90deg) translate(-150%, 100%);
}
}
} }

View File

@ -1,4 +1,4 @@
import { Cell, directions, Exit, PieceId } from "interface"; import { Cell, CellType, directions, Exit, PieceId } from "interface";
import "./BoardCell.scss"; import "./BoardCell.scss";
import { useState } from "react"; import { useState } from "react";
@ -54,10 +54,7 @@ const BoardCell = (props: BoardCellProps) => {
}; };
return ( return (
<div <div className={"cell"} onClick={handleBoardCellClick}>
className={"cell " + cell.cellType.toLowerCase()}
onClick={handleBoardCellClick}
>
{directions.map((direction) => { {directions.map((direction) => {
const traversedNode = cell.getNodeAt(direction).traverseBorder(); const traversedNode = cell.getNodeAt(direction).traverseBorder();
const isExit = traversedNode instanceof Exit; const isExit = traversedNode instanceof Exit;
@ -77,6 +74,12 @@ const BoardCell = (props: BoardCellProps) => {
src={`pieces/${cell.placedPiece.id}.jpeg`} src={`pieces/${cell.placedPiece.id}.jpeg`}
></img> ></img>
)} )}
{cell.cellType !== CellType.NORMAL && (
<img
className="cell-type-icon"
src={`./${cell.cellType.toLowerCase()}-icon.png`}
></img>
)}
</div> </div>
); );
}; };