Add styling to grid and allow moving ephemeral tiles

This commit is contained in:
Joel Therrien 2023-08-10 21:43:14 -07:00
parent 5dc11de37d
commit cbd76895ac
2 changed files with 88 additions and 28 deletions

View file

@ -17,6 +17,41 @@ enum CellType {
Start = "Start", Start = "Start",
} }
function cell_type_to_details(cell_type: CellType): {className: string, text: string} {
let className: string;
let text: string;
switch (cell_type) {
case CellType.Normal:
className = "grid-spot-normal";
text = "";
break;
case CellType.DoubleWord:
className = "grid-spot-double-word";
text = "Double Word Score";
break;
case CellType.DoubleLetter:
className = "grid-spot-double-letter";
text = "Double Letter Score";
break;
case CellType.TripleLetter:
className = "grid-spot-triple-letter";
text = "Triple Letter Score";
break;
case CellType.TripleWord:
className = "grid-spot-triple-word";
text = "Triple Word Score";
break;
case CellType.Start:
className = "grid-spot-start";
text = "★";
break;
}
return {className: className, text: text};
}
export interface CoordinateData { export interface CoordinateData {
location: LocationType; location: LocationType;
index: number; index: number;
@ -83,7 +118,7 @@ export function Game(props: {wasm: GameWasm}) {
return <> return <>
<Grid cellTypes={cellTypes} /> <Grid cellTypes={cellTypes} playerLetters={playerLetters} dispatch={dispatch}/>
<TileTray letters={playerLetters} trayLength={7} dispatch={dispatch}/> <TileTray letters={playerLetters} trayLength={7} dispatch={dispatch}/>
<button onClick={(e) => { <button onClick={(e) => {
dispatch({ dispatch({
@ -92,7 +127,7 @@ export function Game(props: {wasm: GameWasm}) {
"index": 0 "index": 0
}, },
"end": { "end": {
"location": LocationType.TRAY, "location": LocationType.GRID,
"index": 3 "index": 3
}, },
}) })
@ -176,33 +211,35 @@ export function TileTray(props: { letters: Array<PlayableLetterData>, trayLength
} }
function Grid(props: {cellTypes: CellType[]}) { function Grid(props: {cellTypes: CellType[], playerLetters: Array<PlayableLetterData>, dispatch: TileDispatch}) {
const elements = props.cellTypes.map((ct, i) => { const elements = props.cellTypes.map((ct, i) => {
let className: string; const {className, text} = cell_type_to_details(ct);
switch (ct) {
case CellType.Normal: return <div key={i} className={"grid-spot " + className}>
className = "grid-spot-normal" <span>{text}</span>
break; <TileSlot
case CellType.DoubleWord: tile={undefined}
className = "grid-spot-double-word" location={{location: LocationType.GRID, index: i}}
break; dispatch={props.dispatch} />
case CellType.DoubleLetter: </div>;
className = "grid-spot-double-letter" });
break;
case CellType.TripleLetter: for (let letter of props.playerLetters) {
className = "grid-spot-triple-letter" if (letter.location === LocationType.GRID) {
break; const ct = props.cellTypes[letter.index];
case CellType.TripleWord: const {className, text} = cell_type_to_details(ct);
className = "grid-spot-triple-word"
break; elements[letter.index] =
case CellType.Start: <div key={"letter" + letter.index} className={"grid-spot " + className}>
className = "grid-spot-start" <TileSlot
break; tile={<Letter data={letter} />}
location={{location: LocationType.GRID, index: letter.index}}
dispatch={props.dispatch} />
</div>;
} }
}
return <div key={i} className={className}></div>;
});
return <div className="board-grid"> return <div className="board-grid">
{elements} {elements}

View file

@ -23,6 +23,25 @@
user-select: none; user-select: none;
} }
.grid-spot {
font-size: 12px;
text-align: center;
background-color: #bbb59d;
position: relative;
span {
vertical-align: middle;
z-index: 0;
}
.tileSpot {
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
}
.grid-spot-normal{ .grid-spot-normal{
} }
@ -46,12 +65,16 @@
.grid-spot-start { .grid-spot-start {
background-color: #f9b4a5; background-color: #f9b4a5;
font-size: @tile-star-size; font-size: @tile-star-size;
span { // undo the vertical align other cells have
vertical-align: unset;
}
} }
.tileSpot { .tileSpot {
height: 100%; height: @tile-width;
width: 100%; width: @tile-width;
} }
.letter { .letter {