diff --git a/.gitignore b/.gitignore index 20137b6..04bc9a7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.user *.userosscache *.sln.docstates +*.db # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/client/src/App.tsx b/client/src/App.tsx index 4660566..e22cfb7 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -7,7 +7,6 @@ import ShowScores from './views/ShowScores'; import Settings from './views/Settings'; import CreateGame from './views/CreateGame'; import JoinGame from './views/JoinGame'; -import EnterSessionId from './views/EnterSessionId'; const App = () => { const [settings, setSettings] = useState({ @@ -30,7 +29,6 @@ const App = () => { } /> } /> {/* Stelle sicher, dass onSubmit übergeben wird */} } /> - } /> ); diff --git a/client/src/components/QuestionDialog.tsx b/client/src/components/QuestionDialog.tsx index 8f7e49e..754c168 100644 --- a/client/src/components/QuestionDialog.tsx +++ b/client/src/components/QuestionDialog.tsx @@ -1,11 +1,5 @@ import React, { useEffect, useState, useCallback, useRef } from "react"; import { Question, QuestionDialogProps, gamepad } from "../utils/types"; -import { - addGamePadListener, - isDownPressed, - isUpPressed, - removeGamePadListener, -} from "../utils/gamepad"; import { gameDefaults } from "../views/Game"; import correctSound from "../assets/correct.mp3"; import wrongSound from "../assets/wrong.mp3"; @@ -82,33 +76,14 @@ const QuestionDialogCmp: React.FC = ({ [handleSpace] ); - const gamePadhandler = useCallback( - (input: gamepad) => { - if (input.type === "button" && input.pressed) { - handleSpace(); - return; - } - - if (isDownPressed(input)) { - setActiveIndex((prevIndex) => (prevIndex > 0 ? prevIndex - 1 : 0)); - } - - if (isUpPressed(input)) { - setActiveIndex((prevIndex) => (prevIndex < 3 ? prevIndex + 1 : 3)); - } - }, - [handleSpace] - ); useEffect(() => { window.addEventListener("keydown", handleKeyPress); - const padIndex = addGamePadListener(gamePadhandler); return () => { window.removeEventListener("keydown", handleKeyPress); - removeGamePadListener(gamePadhandler, padIndex); }; - }, [handleKeyPress, gamePadhandler]); + }, [handleKeyPress]); return (
diff --git a/client/src/utils/gamepad.ts b/client/src/utils/gamepad.ts deleted file mode 100644 index daae285..0000000 --- a/client/src/utils/gamepad.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { gameDefaults } from "../views/Game"; -import { gamepad } from './types'; - - -export let pressedPads: { gamepadIndex: number, index: number }[] = []; - -const padListeners = [] as any[]; -const animationFrameIds = {} as any; - - -export const addGamePadListener = (callbackFunc: any) => { - let gamepadIndexActive = [] as number[]; - padListeners.push(callbackFunc); - const index = Math.random() * 1000000; - - async function handle(args?: any) { - if (gamepadIndexActive.includes(args.gamepadIndex)) return; - - gamepadIndexActive.push(args.gamepadIndex); - callbackFunc(args) - await new Promise((resolve) => setTimeout(resolve, gameDefaults.pushInterval)); - gamepadIndexActive = gamepadIndexActive.filter(o => o != args.gamepadIndex); - } - - const handleGamePadInput = () => { - const gamepads = navigator.getGamepads(); - if (!gamepads) { - animationFrameIds[index] = requestAnimationFrame(handleGamePadInput); - return; - } - - for (const gamepad of gamepads) { - if (!gamepad) continue; - - // button presses - gamepad.buttons.forEach((button, index) => { - if (button.pressed) { - handle({ - type: 'button', - index: index, - pressed: button.pressed, - gamepadIndex: gamepad.index - }); - } - }); - - // axis movements - gamepad.axes.forEach((axis, index) => { - - if (axis === 1 || axis === -1) { - handle({ - type: 'pad', - index: index, - value: axis, - gamepadIndex: gamepad.index - }); - - if (!pressedPads.find(o => o.gamepadIndex === gamepad.index && o.index === index)) { - pressedPads.push({ gamepadIndex: gamepad.index, index: index }); - } - return; - } - - - - if (pressedPads.find(o => o.gamepadIndex === gamepad.index && o.index === index)) { - callbackFunc({ - type: 'pad', - index: index, - value: axis, - gamepadIndex: gamepad.index, - isRelease: true - }); - - pressedPads = pressedPads.filter((pad) => pad.gamepadIndex !== gamepad.index && pad.index !== index); - } - }); - } - - animationFrameIds[index] = requestAnimationFrame(handleGamePadInput); - }; - - animationFrameIds[index] = requestAnimationFrame(handleGamePadInput); - - return index; -}; - -export const debounce = any>( - func: T, - delay: number -): ((...args: Parameters) => void) => { - let timeoutId: ReturnType | undefined; - - return (...args: Parameters): void => { - clearTimeout(timeoutId); - timeoutId = setTimeout(() => func(...args), delay); - }; -}; - -export const removeGamePadListener = (func: any, index: number) => { - padListeners.splice(padListeners.indexOf(func), 1); - if (animationFrameIds[index]) { - cancelAnimationFrame(animationFrameIds[index]); - } -}; - -export const isPressReleased = (input: gamepad) => { - return input.index == 1 && input.isRelease; -} - -export const isDownPressed = (input: gamepad) => { - return input.index == 1 && input.value == -1; -} - -export const isUpPressed = (input: gamepad) => { - return input.index == 1 && input.value == 1; -} - -export const isLeftPressed = (input: gamepad) => { - return input.index == 0 && input.value == -1; -} - -export const isRightPressed = (input: gamepad) => { - return input.index == 0 && input.value == 1; -} diff --git a/client/src/views/EnterSessionId.tsx b/client/src/views/EnterSessionId.tsx deleted file mode 100644 index 122d81f..0000000 --- a/client/src/views/EnterSessionId.tsx +++ /dev/null @@ -1,109 +0,0 @@ -import React, { useState } from "react"; -import { useNavigate } from "react-router-dom"; -import axios from "axios"; - -const EnterSessionId: React.FC = () => { - const [sessionId, setSessionId] = useState(""); - const [playerName, setPlayerName] = useState(""); - const [isSessionValid, setIsSessionValid] = useState(false); - const [error, setError] = useState(null); - const navigate = useNavigate(); - - const handleSessionSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - if (sessionId) { - try { - const response = await axios.get( - `https://localhost:7144/Session/GetSessionById?sessionId=${sessionId}` - ); - console.log("Response data:", response.data); // Überprüfe die Antwortdaten - - // Überprüfe, ob die Session existiert - if (response.data) { - setIsSessionValid(true); // Session-ID ist gültig - setError(null); - } else { - setError("Invalid session ID. Please check the ID and try again."); - } - } catch (err) { - console.error("API call failed:", err); // Loggt Fehler zur Analyse - setError("Failed to fetch session data. Please try again later."); - } - } - }; - - const handlePlayerSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - if (playerName && sessionId) { - try { - await axios.post( - `https://localhost:7144/api/Player/JoinRoom?sessionId=${sessionId}`, - { playername: playerName } - ); - navigate(`/game/${sessionId}`); - } catch (err) { - setError("Failed to join the game. Please try again."); - } - } - }; - - return ( -
-
-
-
-

- Join Game -

-
- -
- - - {error &&

{error}

} -
- - {isSessionValid && ( -
- - - {error &&

{error}

} -
- )} -
-
-
- ); -}; - -export default EnterSessionId; diff --git a/client/src/views/Home.tsx b/client/src/views/Home.tsx index 1426f50..f934f3f 100644 --- a/client/src/views/Home.tsx +++ b/client/src/views/Home.tsx @@ -6,14 +6,6 @@ import backgroundMusic from "../assets/game.mp3"; import valuehero from "../assets/valuehero.png"; import valuehero2 from "../assets/valuehero2.png"; import AudioComponent from "../components/Audio"; -import { - addGamePadListener, - isDownPressed, - isLeftPressed, - isRightPressed, - isUpPressed, - removeGamePadListener, -} from "../utils/gamepad"; import { playSound } from "../utils/board"; const state: any = { @@ -82,37 +74,9 @@ const Home: React.FC = ({ }) => { window.addEventListener("keydown", handleKeyPress); - const handleGamepad = (input: gamepad) => { - if (input.type === "button" && input.pressed) { - handlePress(); - return; - } - - if (isDownPressed(input)) { - const newIndex = state.activeIndex > 0 ? state.activeIndex - 1 : 0; - setActiveIndex(newIndex); - } - - if (isUpPressed(input)) { - const newIndexD = state.activeIndex < 1 ? state.activeIndex + 1 : 1; - setActiveIndex(newIndexD); - } - - if (isRightPressed(input)) { - const newIndexR = state.gameMode == 0 ? state.gameMode + 1 : 0; - setGameMode(newIndexR); - } - - if (isLeftPressed(input)) { - const newIndexR = state.gameMode == 1 ? state.gameMode - 1 : 0; - setGameMode(newIndexR); - } - }; - const padIndex = addGamePadListener(handleGamepad); return () => { window.removeEventListener("keydown", handleKeyPress); - removeGamePadListener(handleGamepad, padIndex); }; }, []); diff --git a/service/src/PingPong/PingPong.db b/service/src/PingPong/PingPong.db deleted file mode 100644 index 609320f..0000000 Binary files a/service/src/PingPong/PingPong.db and /dev/null differ diff --git a/service/src/PingPong/appsettings.Development.json b/service/src/PingPong/appsettings.Development.json index 0c208ae..8fdb84a 100644 --- a/service/src/PingPong/appsettings.Development.json +++ b/service/src/PingPong/appsettings.Development.json @@ -4,5 +4,12 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "AllowedHosts": "*", + "SQLiteConfiguration": { + "ConnectionString": "Data Source=PingPong.db; Version=3;" + }, + "AppInformation":{ + "Version": "0.0.1" } }