Moved some files

This commit is contained in:
martin 2023-07-07 22:19:17 +02:00
parent 45131efb37
commit 35295b9705
5 changed files with 68 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import React, {useEffect, useState} from "react";
import {AllDice} from "./dice";
import {GameAction} from "../websockets/actions";
import {GameAction} from "../utils/actions";
import GameBoard from "./gameBoard";
import {Character, Ghost, PacMan} from "../game/character";
import WebSocketService from "../websockets/WebSocketService";
@ -8,7 +8,7 @@ import {testMap} from "../game/map";
import {TileType} from "../game/tileType";
import Player, {State} from "../game/player";
import {Colour} from "../game/colour";
import PlayerStats from "../game/playerStats";
import PlayerStats from "../components/playerStats";
const wsService = new WebSocketService(import.meta.env.VITE_API);
@ -45,7 +45,7 @@ export const GameComponent: Component<{ player: Player }> = ({player}) => {
rollDice();
}
function doAction(message: MessageEvent<string>): void { // TODO move to Service
function doAction(message: MessageEvent<string>): void { // TODO move to actions.ts
const parsed: ActionMessage = JSON.parse(message.data);
switch (parsed.Action) {

View File

@ -1,5 +1,5 @@
import React from "react";
import Player, {State} from "./player";
import Player, {State} from "../game/player";
export interface PlayerStatsProps extends ComponentProps {
player: Player,

View File

@ -0,0 +1,62 @@
import Player from "../game/player";
import {Character, PacMan} from "../game/character";
import {testMap} from "../game/map";
import {TileType} from "../game/tileType";
export enum GameAction {
rollDice,
moveCharacter,
playerInfo,
ready,
}
function doAction(message: MessageEvent<string>): void { // TODO Jotai state management?
const parsed: ActionMessage = JSON.parse(message.data);
switch (parsed.Action) {
case GameAction.rollDice:
setDice(parsed.Data as number[]);
break;
case GameAction.moveCharacter:
setDice(parsed.Data?.dice as number[]);
updateCharacters(parsed);
removeEatenPellets(parsed);
break;
case GameAction.playerInfo:
const playerProps = parsed.Data as PlayerProps[];
console.log(playerProps);
setPlayers(playerProps.map(p => new Player(p)));
const pacMen = playerProps.filter(p => p.PacMan).map(p => new PacMan(p.PacMan!));
console.log(pacMen);
// TODO find spawn points
setCharacters([...pacMen, ...ghosts]);
break;
case GameAction.ready:
const isReady = parsed.Data.AllReady as boolean;
if (isReady) {
setCurrentPlayer(new Player(parsed.Data.Starter as PlayerProps));
}
setPlayers((parsed.Data.Players as PlayerProps[]).map(p => new Player(p)));
break;
}
}
function removeEatenPellets(parsed: ActionMessage): void {
const pellets = parsed.Data?.eatenPellets as Position[];
for (const pellet of pellets) {
testMap[pellet.y][pellet.x] = TileType.empty;
}
}
function updateCharacters(parsed: ActionMessage): void {
const updatedCharacters = parsed.Data?.characters as CharacterProps[] | undefined;
if (updatedCharacters) {
const newList: Character[] = [];
for (const character of updatedCharacters) {
newList.push(new Character(character));
}
setCharacters(newList);
}
}

View File

@ -1,6 +0,0 @@
export enum GameAction {
rollDice,
moveCharacter,
playerInfo,
ready,
}

View File

@ -44,6 +44,8 @@
<TypeScriptCompile Remove="ClientApp\src\components\gameCanvas.tsx" />
<TypeScriptCompile Remove="ClientApp\src\game\game.ts" />
<TypeScriptCompile Remove="ClientApp\src\App.test.tsx" />
<TypeScriptCompile Remove="ClientApp\src\game\playerStats.tsx" />
<TypeScriptCompile Remove="ClientApp\src\websockets\actions.ts" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">