From b786fe1e723b7cf905cdd7e525375dfe96241a21 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Mon, 21 Aug 2023 14:50:09 -0600 Subject: [PATCH] add default arguments to grid; add grid to server gl --- client/src/JumpStorm.ts | 8 ++++---- engine/config/constants.ts | 5 ++++- engine/structures/Grid.ts | 11 +++++++++-- server/bun.lockb | Bin 1650 -> 1270 bytes server/src/server.ts | 21 +++++++++++++-------- server/tsconfig.json | 14 +++++++++++++- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/client/src/JumpStorm.ts b/client/src/JumpStorm.ts index 008ba13..e094a6f 100644 --- a/client/src/JumpStorm.ts +++ b/client/src/JumpStorm.ts @@ -64,12 +64,12 @@ export class JumpStorm { const clientSocketMessageQueueProvider = new ClientSocketMessageQueueProvider(socket); const clientSocketMessagePublisher = new ClientSocketMessagePublisher( - socket, + socket ); const grid = new Grid( { width: Miscellaneous.WIDTH, height: Miscellaneous.HEIGHT }, - { width: 30, height: 30 }, + { width: 30, height: 30 } ); [ @@ -80,13 +80,13 @@ export class JumpStorm { new WallBounds(ctx.canvas.width), new NetworkUpdate( clientSocketMessageQueueProvider, - clientSocketMessagePublisher, + clientSocketMessagePublisher ), new Render(ctx), ].forEach((system) => this.game.addSystem(system)); [new Floor(160), new Player()].forEach((entity) => - this.game.addEntity(entity), + this.game.addEntity(entity) ); } diff --git a/engine/config/constants.ts b/engine/config/constants.ts index 3d536d3..b3c3f62 100644 --- a/engine/config/constants.ts +++ b/engine/config/constants.ts @@ -11,7 +11,7 @@ export namespace KeyConstants { }; export const ActionKeys: Map = Object.keys( - KeyActions, + KeyActions ).reduce((acc: Map, key) => { const action = KeyActions[key]; @@ -36,4 +36,7 @@ export namespace PhysicsConstants { export namespace Miscellaneous { export const WIDTH = 600; export const HEIGHT = 800; + + export const DEFAULT_GRID_WIDTH = 40; + export const DEFAULT_GRID_HEIGHT = 40; } diff --git a/engine/structures/Grid.ts b/engine/structures/Grid.ts index 836aaf4..6e8c0cb 100644 --- a/engine/structures/Grid.ts +++ b/engine/structures/Grid.ts @@ -1,5 +1,6 @@ import type { Coord2D, Dimension2D } from "../interfaces"; import type { BoxedEntry, RefreshingCollisionFinderBehavior } from "."; +import { Miscellaneous } from "../config/constants"; export class Grid implements RefreshingCollisionFinderBehavior { private cellEntities: Map; @@ -9,8 +10,14 @@ export class Grid implements RefreshingCollisionFinderBehavior { private topLeft: Coord2D; constructor( - gridDimension: Dimension2D, - cellDimension: Dimension2D, + gridDimension: Dimension2D = { + width: Miscellaneous.WIDTH, + height: Miscellaneous.HEIGHT, + }, + cellDimension: Dimension2D = { + width: Miscellaneous.DEFAULT_GRID_WIDTH, + height: Miscellaneous.DEFAULT_GRID_HEIGHT, + }, topLeft = { x: 0, y: 0 } ) { this.gridDimension = gridDimension; diff --git a/server/bun.lockb b/server/bun.lockb index 7f8b5ce2234046c9a802d015751d375ab8402e83..28b67ce2c2466108dc6314e3bd59d4aace865af0 100755 GIT binary patch delta 328 zcmeyw^Nn+Yo~F%_aPPl4-)AL%$P=vpR)1*Uk1$n{TXE-fKd#7h+pTyrjfDXWm?nnH z8&@$wI1CKMsYPX}MGOpFKmkq$h6Zm7AJ#^fqHWc0($97Xy;fpm;QAsC)XFwlkWpT7 z1ymbIH5l-(eEzSVfdOWm@MKFy>&XU;EP^l*kSY+HY4S|QlF6w|-jm<3222)VHsU$} zRdR)CawD^Y)W81_0Mft+BA7u00|N{5rr=!#vrKMQd^m zivi~|sL->?4a}mGpRnj~2|&Fb$1+)pRYAC=@uIj2O4%=S_NNiJcU2LLZP@s^zz4jxcz>Y|szpLBy*Qt34qOgU?k(2IAD9*DK}It$lvEa^ z7AF^F7L+8F=IMfYx%nxjIjOpdIhl#Y86_nJ#a8S VuZzOf1v@~mB)tl^{>ip1I{^ZQv#9_8 diff --git a/server/src/server.ts b/server/src/server.ts index d169f7d..18829e4 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1,21 +1,24 @@ -import { Game } from "../../engine/Game"; -import { Floor, Player } from "../../engine/entities"; +import { Game } from "@engine/Game"; +import { Floor, Player } from "@engine/entities"; import { WallBounds, Physics, Collision, MessageQueueProvider, MessagePublisher, -} from "../../engine/systems"; -import { Miscellaneous } from "../../engine/config"; +} from "@engine/systems"; +import { Grid } from "@engine/structures"; +import { Miscellaneous } from "@engine/config"; const TICK_RATE = 60 / 1000; const game = new Game(); -[new Physics(), new Collision(), new WallBounds(Miscellaneous.WIDTH)].forEach( - (system) => game.addSystem(system), -); +[ + new Physics(), + new Collision(new Grid()), + new WallBounds(Miscellaneous.WIDTH), +].forEach((system) => game.addSystem(system)); [new Floor(160), new Player()].forEach((entity) => game.addEntity(entity)); @@ -27,7 +30,7 @@ setInterval(() => { const server = Bun.serve({ port: 8080, - fetch(req, server) { + fetch: async (req, server): Promise => { const sessionId = Math.floor(Math.random() * 1e10).toString(); server.upgrade(req, { @@ -35,6 +38,8 @@ const server = Bun.serve({ "Set-Cookie": `SessionId=${sessionId}`, }, }); + + return "200 OK"; }, websocket: { open(ws) {}, diff --git a/server/tsconfig.json b/server/tsconfig.json index e39b364..8cc9ad3 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -21,6 +21,18 @@ // best practices "strict": true, "forceConsistentCasingInFileNames": true, - "skipLibCheck": true + "skipLibCheck": true, + + // engine path + "paths": { + "@engine/*": ["../engine/*"], + "@engine/components": ["../engine/components"], + "@engine/config": ["../engine/config"], + "@engine/entities": ["../engine/entities"], + "@engine/interfaces": ["../engine/interfaces"], + "@engine/structures": ["../engine/structures"], + "@engine/systems": ["../engine/systems"], + "@engine/utils": ["../engine/utils"], + } } }