From 602f891e5e2d3855717ee12b6033089c5152cb2c Mon Sep 17 00:00:00 2001 From: Filip Stojanovic Date: Sun, 12 May 2024 21:22:24 +0200 Subject: [PATCH] Added in version 1 of the menu --- src/app.tsx | 42 +++++++++++++++++++++++++++++++++++++++- src/components/catan.tsx | 19 +++++++++++++++--- src/components/modal.css | 10 ++++++++++ src/components/modal.tsx | 42 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/components/modal.css create mode 100644 src/components/modal.tsx diff --git a/src/app.tsx b/src/app.tsx index 76d0d74..8c97550 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,5 +1,6 @@ import { useState } from 'preact/hooks' import { TextInput, TextArrayInput, SelectInput, CheckboxInput } from './components/input.tsx' +import { Modal, ModalProps } from './components/modal' import { Resource } from './lib/catan_hex.ts' import { Catan, CatanBoard, Extension } from './components/catan.tsx' @@ -14,6 +15,45 @@ function App() { const [extensions, setExtensions] = useState([]) const catan = new Catan({pointA, deserts, players, resources, extensions}) + interface HexModalProps extends ModalProps { + cords: number[] + hexNum: number + } + + function HexModal({open, setOpen, cords, hexNum}: HexModalProps) { + return ( + + {catan.field.corners().includes(cords.join(' ')) && + cords.some((e, i) => e !== catan.field.pointA[i]) && <> + +
+ } + + {deserts.map((desert, i) => ( + cords.some((e, i) => e !== desert[i]) && <> + +
+ + ))} +
+ + {deserts.every(desert => desert.some((e, i) => e !== cords[i])) && + ['wood', 'clay', 'wheat', 'sheep', 'stone'].map(resource => ( + resource !== catan.field.board[cords[0]][cords[1]].resource && <> + +
+ + ))} +
+ ) + } + return ( <>