From 20d1fd30947bc58a8438c990b7cae1da38507da0 Mon Sep 17 00:00:00 2001 From: aronmal Date: Wed, 8 Feb 2023 20:17:02 +0100 Subject: [PATCH] Refactoring --- leaky-ships/components/BurgerMenu.tsx | 15 ++ .../{ => Gamefield}/BorderTiles.tsx | 4 +- .../components/{ => Gamefield}/EventBar.tsx | 2 +- .../components/{ => Gamefield}/FogImages.tsx | 0 .../components/{ => Gamefield}/Gamefield.tsx | 2 +- .../{ => Gamefield}/GamefieldPointer.tsx | 2 +- .../components/{ => Gamefield}/HitElems.tsx | 2 +- .../components/{ => Gamefield}/Item.tsx | 0 .../components/{ => Gamefield}/Labeling.tsx | 4 +- .../components/{ => Gamefield}/Ships.tsx | 0 .../components/{ => Gamefield}/Targets.tsx | 2 +- leaky-ships/components/Lobby/Icon.tsx | 25 ++ leaky-ships/components/Lobby/LobbyFrame.tsx | 61 +++++ leaky-ships/components/Lobby/Player.tsx | 43 +++ leaky-ships/components/Logo.tsx | 17 ++ .../components/SettingsFrame/Setting.tsx | 49 ++++ .../components/SettingsFrame/Settings.tsx | 55 ++++ leaky-ships/lib/hooks/useGameEvent.ts | 2 +- leaky-ships/pages/dev/gamefield.tsx | 2 +- leaky-ships/pages/dev/lobby.tsx | 248 +----------------- 20 files changed, 282 insertions(+), 253 deletions(-) create mode 100644 leaky-ships/components/BurgerMenu.tsx rename leaky-ships/components/{ => Gamefield}/BorderTiles.tsx (92%) rename leaky-ships/components/{ => Gamefield}/EventBar.tsx (94%) rename leaky-ships/components/{ => Gamefield}/FogImages.tsx (100%) rename leaky-ships/components/{ => Gamefield}/Gamefield.tsx (95%) rename leaky-ships/components/{ => Gamefield}/GamefieldPointer.tsx (94%) rename leaky-ships/components/{ => Gamefield}/HitElems.tsx (91%) rename leaky-ships/components/{ => Gamefield}/Item.tsx (100%) rename leaky-ships/components/{ => Gamefield}/Labeling.tsx (91%) rename leaky-ships/components/{ => Gamefield}/Ships.tsx (100%) rename leaky-ships/components/{ => Gamefield}/Targets.tsx (92%) create mode 100644 leaky-ships/components/Lobby/Icon.tsx create mode 100644 leaky-ships/components/Lobby/LobbyFrame.tsx create mode 100644 leaky-ships/components/Lobby/Player.tsx create mode 100644 leaky-ships/components/Logo.tsx create mode 100644 leaky-ships/components/SettingsFrame/Setting.tsx create mode 100644 leaky-ships/components/SettingsFrame/Settings.tsx diff --git a/leaky-ships/components/BurgerMenu.tsx b/leaky-ships/components/BurgerMenu.tsx new file mode 100644 index 0000000..485535e --- /dev/null +++ b/leaky-ships/components/BurgerMenu.tsx @@ -0,0 +1,15 @@ +import React from "react" + +function BurgerMenu() { + return ( + + ) +} + +export default BurgerMenu diff --git a/leaky-ships/components/BorderTiles.tsx b/leaky-ships/components/Gamefield/BorderTiles.tsx similarity index 92% rename from leaky-ships/components/BorderTiles.tsx rename to leaky-ships/components/Gamefield/BorderTiles.tsx index eef503b..d55f3c1 100644 --- a/leaky-ships/components/BorderTiles.tsx +++ b/leaky-ships/components/Gamefield/BorderTiles.tsx @@ -1,6 +1,6 @@ import { CSSProperties, Dispatch, SetStateAction } from "react" -import { borderCN, cornerCN, fieldIndex } from "../lib/utils/helpers" -import { Position, MouseCursor } from "../interfaces/frontend" +import { borderCN, cornerCN, fieldIndex } from "../../lib/utils/helpers" +import { Position, MouseCursor } from "../../interfaces/frontend" type TilesType = { key: number diff --git a/leaky-ships/components/EventBar.tsx b/leaky-ships/components/Gamefield/EventBar.tsx similarity index 94% rename from leaky-ships/components/EventBar.tsx rename to leaky-ships/components/Gamefield/EventBar.tsx index cdb1353..897f2f6 100644 --- a/leaky-ships/components/EventBar.tsx +++ b/leaky-ships/components/Gamefield/EventBar.tsx @@ -1,5 +1,5 @@ import React, { Dispatch, SetStateAction } from "react" -import { Items, Target } from "../interfaces/frontend" +import { Items, Target } from "../../interfaces/frontend" import Item from "./Item" function EventBar({ diff --git a/leaky-ships/components/FogImages.tsx b/leaky-ships/components/Gamefield/FogImages.tsx similarity index 100% rename from leaky-ships/components/FogImages.tsx rename to leaky-ships/components/Gamefield/FogImages.tsx diff --git a/leaky-ships/components/Gamefield.tsx b/leaky-ships/components/Gamefield/Gamefield.tsx similarity index 95% rename from leaky-ships/components/Gamefield.tsx rename to leaky-ships/components/Gamefield/Gamefield.tsx index 8a9b630..3ca4420 100644 --- a/leaky-ships/components/Gamefield.tsx +++ b/leaky-ships/components/Gamefield/Gamefield.tsx @@ -6,7 +6,7 @@ import EventBar from "./EventBar" import HitElems from "./HitElems" import Labeling from "./Labeling" import Ships from "./Ships" -import useGameEvent from "../lib/hooks/useGameEvent" +import useGameEvent from "../../lib/hooks/useGameEvent" import Targets from "./Targets" function Gamefield() { diff --git a/leaky-ships/components/GamefieldPointer.tsx b/leaky-ships/components/Gamefield/GamefieldPointer.tsx similarity index 94% rename from leaky-ships/components/GamefieldPointer.tsx rename to leaky-ships/components/Gamefield/GamefieldPointer.tsx index c90cc9e..89473b0 100644 --- a/leaky-ships/components/GamefieldPointer.tsx +++ b/leaky-ships/components/Gamefield/GamefieldPointer.tsx @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { CSSProperties } from "react" import classNames from "classnames" import { faRadar } from "@fortawesome/pro-thin-svg-icons" -import { Target, TargetList } from "../interfaces/frontend" +import { Target, TargetList } from "../../interfaces/frontend" export interface PointerProps extends Target, TargetList { imply: boolean diff --git a/leaky-ships/components/HitElems.tsx b/leaky-ships/components/Gamefield/HitElems.tsx similarity index 91% rename from leaky-ships/components/HitElems.tsx rename to leaky-ships/components/Gamefield/HitElems.tsx index 0a39749..c94d832 100644 --- a/leaky-ships/components/HitElems.tsx +++ b/leaky-ships/components/Gamefield/HitElems.tsx @@ -1,7 +1,7 @@ import { faBurst, faXmark } from "@fortawesome/pro-solid-svg-icons" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { CSSProperties } from "react" -import { Hit } from "../interfaces/frontend" +import { Hit } from "../../interfaces/frontend" function HitElems({ hits }: { hits: Hit[] }) { return ( diff --git a/leaky-ships/components/Item.tsx b/leaky-ships/components/Gamefield/Item.tsx similarity index 100% rename from leaky-ships/components/Item.tsx rename to leaky-ships/components/Gamefield/Item.tsx diff --git a/leaky-ships/components/Labeling.tsx b/leaky-ships/components/Gamefield/Labeling.tsx similarity index 91% rename from leaky-ships/components/Labeling.tsx rename to leaky-ships/components/Gamefield/Labeling.tsx index 6244ed5..bbdf784 100644 --- a/leaky-ships/components/Labeling.tsx +++ b/leaky-ships/components/Gamefield/Labeling.tsx @@ -1,7 +1,7 @@ import classNames from "classnames" import { CSSProperties } from "react" -import { fieldIndex } from "../lib/utils/helpers" -import { Field } from "../interfaces/frontend" +import { fieldIndex } from "../../lib/utils/helpers" +import { Field } from "../../interfaces/frontend" function Labeling({ count }: { count: number }) { let elems: (Field & { diff --git a/leaky-ships/components/Ships.tsx b/leaky-ships/components/Gamefield/Ships.tsx similarity index 100% rename from leaky-ships/components/Ships.tsx rename to leaky-ships/components/Gamefield/Ships.tsx diff --git a/leaky-ships/components/Targets.tsx b/leaky-ships/components/Gamefield/Targets.tsx similarity index 92% rename from leaky-ships/components/Targets.tsx rename to leaky-ships/components/Gamefield/Targets.tsx index 6388a5b..38c2f29 100644 --- a/leaky-ships/components/Targets.tsx +++ b/leaky-ships/components/Gamefield/Targets.tsx @@ -1,5 +1,5 @@ import React from "react" -import { Target } from "../interfaces/frontend" +import { Target } from "../../interfaces/frontend" import GamefieldPointer, { PointerProps } from "./GamefieldPointer" function Targets({ diff --git a/leaky-ships/components/Lobby/Icon.tsx b/leaky-ships/components/Lobby/Icon.tsx new file mode 100644 index 0000000..ac663d5 --- /dev/null +++ b/leaky-ships/components/Lobby/Icon.tsx @@ -0,0 +1,25 @@ +function Icon({ + src, + text, + onClick, +}: { + src: string + text: string + onClick?: () => void +}) { + return ( + + ) +} + +export default Icon diff --git a/leaky-ships/components/Lobby/LobbyFrame.tsx b/leaky-ships/components/Lobby/LobbyFrame.tsx new file mode 100644 index 0000000..ad4852e --- /dev/null +++ b/leaky-ships/components/Lobby/LobbyFrame.tsx @@ -0,0 +1,61 @@ +import { useEffect, useState } from "react" +import Settings from "../SettingsFrame/Settings" +import Icon from "./Icon" +import Player from "./Player" + +function LobbyFrame() { + const [settings, setSettings] = useState(false) + const [enemy, setEnemy] = useState(false) + const [dots, setDots] = useState(0) + + useEffect(() => { + if (enemy) return + const interval = setInterval(() => setDots((e) => (e % 3) + 1), 1000) + return () => clearInterval(interval) + }, []) + + return ( +
+
+ +

+ Game-PIN: 3169 +

+ setSettings(true)} + /> +
+
+ +

setEnemy((e) => !e)} + > + VS +

+ {enemy ? ( + + ) : ( +

+ Warte auf Spieler 2 {Array.from(Array(dots), () => ".").join("")} +

+ )} +
+
+ +
+ {settings ? setSettings(false)} /> : <>} +
+ ) +} + +export default LobbyFrame diff --git a/leaky-ships/components/Lobby/Player.tsx b/leaky-ships/components/Lobby/Player.tsx new file mode 100644 index 0000000..1e4e0dd --- /dev/null +++ b/leaky-ships/components/Lobby/Player.tsx @@ -0,0 +1,43 @@ +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import { faCaretDown } from "@fortawesome/sharp-solid-svg-icons" +import classNames from "classnames" + +function Player({ + src, + text, + primary, + edit, +}: { + src: string + text: string + primary?: boolean + edit?: boolean +}) { + return ( +
+

+ {text} +

+
+ {src} + {edit ? ( + + ) : ( + <> + )} +
+
+ ) +} + +export default Player diff --git a/leaky-ships/components/Logo.tsx b/leaky-ships/components/Logo.tsx new file mode 100644 index 0000000..a56afad --- /dev/null +++ b/leaky-ships/components/Logo.tsx @@ -0,0 +1,17 @@ +import React from "react" + +function Logo() { + return ( +
+
+

+ Leaky +
+ Ships +

+
+
+ ) +} + +export default Logo diff --git a/leaky-ships/components/SettingsFrame/Setting.tsx b/leaky-ships/components/SettingsFrame/Setting.tsx new file mode 100644 index 0000000..8cb5b6b --- /dev/null +++ b/leaky-ships/components/SettingsFrame/Setting.tsx @@ -0,0 +1,49 @@ +import { + faToggleLargeOff, + faToggleLargeOn, +} from "@fortawesome/pro-solid-svg-icons" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import classNames from "classnames" + +function Setting({ + props: { key, state, onClick }, +}: { + props: { + key: string + state: boolean + onClick: () => void + } +}) { + return ( + <> + + + + + ) +} + +export default Setting diff --git a/leaky-ships/components/SettingsFrame/Settings.tsx b/leaky-ships/components/SettingsFrame/Settings.tsx new file mode 100644 index 0000000..c9ccc30 --- /dev/null +++ b/leaky-ships/components/SettingsFrame/Settings.tsx @@ -0,0 +1,55 @@ +import { faXmark } from "@fortawesome/pro-solid-svg-icons" +import { faRotateLeft } from "@fortawesome/pro-regular-svg-icons" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import { useState } from "react" +import Setting from "./Setting" + +const settingOptionsInit: { [key: string]: boolean } = { + allowSpectators: false, + allowSpecials: false, + allowChat: false, + allowMarkDraw: false, +} + +function Settings({ closeSettings }: { closeSettings: () => void }) { + const [settingOptions, setSettingOptions] = useState(settingOptionsInit) + return ( +
+
+

+ Settings +

+ +
+ +
+ {Object.keys(settingOptions).map((key) => { + const state = settingOptions[key] + const onClick = () => + setSettingOptions((e) => ({ ...e, [key]: !e[key] })) + return + })} +
+
+
+
+ ) +} + +export default Settings diff --git a/leaky-ships/lib/hooks/useGameEvent.ts b/leaky-ships/lib/hooks/useGameEvent.ts index 64f28cd..9cd45ce 100644 --- a/leaky-ships/lib/hooks/useGameEvent.ts +++ b/leaky-ships/lib/hooks/useGameEvent.ts @@ -13,7 +13,7 @@ import { Target, Position, } from "../../interfaces/frontend" -import { PointerProps } from "../../components/GamefieldPointer" +import { PointerProps } from "../../components/Gamefield/GamefieldPointer" const modes: Mode[] = [ { diff --git a/leaky-ships/pages/dev/gamefield.tsx b/leaky-ships/pages/dev/gamefield.tsx index b44a91d..3ed50bb 100644 --- a/leaky-ships/pages/dev/gamefield.tsx +++ b/leaky-ships/pages/dev/gamefield.tsx @@ -1,5 +1,5 @@ import Head from "next/head" -import Gamefield from "../../components/Gamefield" +import Gamefield from "../../components/Gamefield/Gamefield" export default function Home() { return ( diff --git a/leaky-ships/pages/dev/lobby.tsx b/leaky-ships/pages/dev/lobby.tsx index 6789d0e..b0b493d 100644 --- a/leaky-ships/pages/dev/lobby.tsx +++ b/leaky-ships/pages/dev/lobby.tsx @@ -1,34 +1,9 @@ -import { - faToggleLargeOff, - faToggleLargeOn, - faXmark, -} from "@fortawesome/pro-solid-svg-icons" -import { faRotateLeft } from "@fortawesome/pro-regular-svg-icons" -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" -import { faCaretDown } from "@fortawesome/sharp-solid-svg-icons" -import classNames from "classnames" import Head from "next/head" -import { Dispatch, SetStateAction, useEffect, useState } from "react" - -const settingOptionsInit: { [key: string]: boolean } = { - allowSpectators: false, - allowSpecials: false, - allowChat: false, - allowMarkDraw: false, -} +import Logo from "../../components/Logo" +import LobbyFrame from "../../components/Lobby/LobbyFrame" +import BurgerMenu from "../../components/BurgerMenu" export default function Home() { - const [enemy, setEnemy] = useState(false) - const [settings, setSettings] = useState(false) - const [dots, setDots] = useState(0) - const [settingOptions, setSettingOptions] = useState(settingOptionsInit) - - useEffect(() => { - if (enemy) return - const interval = setInterval(() => setDots((e) => (e % 3) + 1), 1000) - return () => clearInterval(interval) - }, []) - return (
@@ -37,220 +12,9 @@ export default function Home() { - -
-
-

- Leaky -
- Ships -

-
-
-
-
- -

- Game-PIN: 3169 -

- setSettings(true)} - /> -
-
- -

setEnemy((e) => !e)} - > - VS -

- {enemy ? ( - - ) : ( -

- Warte auf Spieler 2 {Array.from(Array(dots), () => ".").join("")} -

- )} -
-
- -
-
- {settings ? ( - setSettings(false), - }} - /> - ) : ( - <> - )} + + +
) } - -function Icon({ - src, - text, - onClick, -}: { - src: string - text: string - onClick?: () => void -}) { - return ( - - ) -} -function Player({ - src, - text, - primary, - edit, -}: { - src: string - text: string - primary?: boolean - edit?: boolean -}) { - return ( -
-

- {text} -

-
- {src} - {edit ? ( - - ) : ( - <> - )} -
-
- ) -} -function Settings({ - props: { settingOptions, setSettingOptions, closeSettings }, -}: { - props: { - settingOptions: typeof settingOptionsInit - setSettingOptions: Dispatch> - closeSettings: () => void - } -}) { - return ( -
-
-

- Settings -

- -
- -
- {Object.keys(settingOptions).map((key) => { - const state = settingOptions[key] - const onClick = () => - setSettingOptions((e) => ({ ...e, [key]: !e[key] })) - return - })} -
-
-
-
- ) -} -function Setting({ - props: { key, state, onClick }, -}: { - props: { - key: string - state: boolean - onClick: () => void - } -}) { - return ( - <> - - - - - ) -}