Working ship placement

This commit is contained in:
aronmal 2023-06-11 22:09:36 +02:00
parent 0317a3343c
commit c2af2dffa2
Signed by: aronmal
GPG key ID: 816B7707426FC612
14 changed files with 1155 additions and 281 deletions

View file

@ -0,0 +1,34 @@
import { ShipProps } from "../../interfaces/frontend"
import { useGameProps } from "@hooks/useGameProps"
import classNames from "classnames"
import React, { CSSProperties } from "react"
function Ship({
props: { size, variant, x, y },
preview,
}: {
props: ShipProps
preview?: boolean
}) {
const { payload, removeShip } = useGameProps()
const filename = `ship_blue_${size}x_${variant}.gif`
return (
<div
className={classNames("ship", "s" + size, {
preview: preview,
interactive: payload?.game?.state === "starting",
})}
style={{ "--x": x, "--y": y } as CSSProperties}
onClick={() => {
if (payload?.game?.state !== "starting") return
removeShip({ size, variant, x, y })
useGameProps.setState({ mode: size - 2 })
}}
>
<img src={"/assets/" + filename} alt={filename} />
</div>
)
}
export default Ship