Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): physics & game controls #31

Merged
merged 26 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5cd1334
refactor(api): initialize `graphql` code first
Neosoulink Jul 16, 2024
563c1af
feat: init `websocket` support
Neosoulink Jul 16, 2024
60ece0a
chore(deps): upgrade turbo to `2.0.9`
Neosoulink Jul 21, 2024
4bc387a
chore(configs): disable unused local ts rule
Neosoulink Jul 25, 2024
0a209eb
feat(web): base architecture
Neosoulink Jul 26, 2024
a233b38
fix: activate `husky`
Neosoulink Jul 26, 2024
7688697
feat: init base pieces logic
Neosoulink Jul 27, 2024
00ebd34
chore(config): use correct hook
Neosoulink Jul 28, 2024
09b4752
feat: implement pieces initializers
Neosoulink Jul 29, 2024
956a252
refactor: correct props naming
Neosoulink Aug 1, 2024
a229fec
refactor: make `PieceModel` independent from board
Neosoulink Aug 1, 2024
85bb5f5
refactor: re-organize pieces groups
Neosoulink Aug 1, 2024
6984dba
feat: add `movePiece` control
Neosoulink Aug 3, 2024
617acc0
refactor: re-use data `PieceModel` data
Neosoulink Aug 4, 2024
09ff14d
feat: handle piece dropping
Neosoulink Aug 4, 2024
1e17c60
refactor: use correct keys mapping
Neosoulink Aug 13, 2024
204bc9c
chore(conf): remove `pre-commit` git add step
Neosoulink Aug 14, 2024
abde6c5
feat(rapier-physics): base rapier physics integration
Neosoulink Aug 15, 2024
8ddb8b1
refactor(web): use group shape for offset
Neosoulink Aug 15, 2024
1f6f394
refactor: implement force bounding-box usage
Neosoulink Aug 19, 2024
232b0a5
feat(web): use `PhysicsProperties` to position the board
Neosoulink Aug 19, 2024
8a915ea
refactor(web): use correct pieces key mapping
Neosoulink Aug 19, 2024
288962c
refactor: implement physics debug
Neosoulink Aug 20, 2024
1b5ed07
refactor: improve board & pieces physics accessibility
Neosoulink Aug 21, 2024
8d413a9
refactor(web): handle piece drop from piece group
Neosoulink Aug 29, 2024
8d89ba7
chore(docs): list patch changelogs
Neosoulink Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mighty-penguins-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@chess-d/configs": patch
---

# Logs

## chore(configs): disable unused local **typescript** rules
41 changes: 41 additions & 0 deletions .changeset/shaggy-buses-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
"web": patch
---

# Logs

## refactor(web): handle piece drop from piece group

- Move the `dropPiece` handler to `PiecesGroupModel`
- Handle `PiecesGroupModel` count update
- Handle `PieceModel` deletion
- `PiecesGroupModel` update PieceModes
- Update `PiecesModel` composition on set coords
- Update physics rotation

## refactor(web): implement physics debug

- Move out of the core the `Physics` helper
- Register it in the dependency container
- Add debug module
- Implement physics debug
- Add new turbo env to the dev process
- use **vite** `import.meta.env?.DEV` env as debug mode checker

## feat(web): use `PhysicsProperties` to position the board

- Add `@chess-d/rapier-physics`
- Add `physicsBody` property to chess-board component

## feat(web): handle piece dropping

## refactor(web): make `PieceModel` independent from board

## feat(web): implement pieces initializers

## feat(web): set base web architecture

- Initialize world module
- Initialize game module
- Initialize chess board module
- initialize core module
13 changes: 13 additions & 0 deletions .changeset/tidy-dingos-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@chess-d/rapier-physics": minor
---

# Logs

## refactor: implement force bounding-box usage

- Use `Object3D.userData` to pass `useBoundingBox`, forcing **bounding-box** usage

## feat(rapier-physics): base rapier physics integration

- Use `ThreeJS` RapierPhysics addon as base.
11 changes: 11 additions & 0 deletions .changeset/wise-taxis-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"api": patch
---

# Logs

## Init base server resources

- Initialize `graphql` code first.
- Initialize `webSocket` support.
- Use `WS` library
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ pnpm-debug.log*
# Misc
.DS_Store
*.pem
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
{
"mode": "auto"
}
],
"cSpell.words": [
"timestep",
"tsyringe"
]
}
3 changes: 2 additions & 1 deletion apps/api/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
"deleteOutDir": true,
"plugins": ["@nestjs/graphql"]
}
}
12 changes: 10 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\""
},
"dependencies": {
"@apollo/server": "^4.10.4",
"@chess-d/api": "workspace:*",
"@nestjs/apollo": "^12.2.0",
"@nestjs/common": "^10.3.10",
"@nestjs/core": "^10.0.0",
"@nestjs/graphql": "^12.2.0",
"@nestjs/platform-express": "^10.3.10",
"@chess-d/api": "workspace:*",
"@nestjs/platform-ws": "^10.3.10",
"@nestjs/websockets": "^10.3.10",
"graphql": "^16.9.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"ws": "^8.18.0"
},
"devDependencies": {
"@chess-d/configs": "workspace:*",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.1.2",
"@nestjs/testing": "^10.3.10",
"@types/ws": "^8.5.11",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"tsconfig-paths": "^4.2.0"
Expand Down
22 changes: 0 additions & 22 deletions apps/api/src/app.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions apps/api/src/app.controller.ts

This file was deleted.

23 changes: 16 additions & 7 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { Module } from "@nestjs/common";
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
import { join } from "path";
import { GraphQLModule } from "@nestjs/graphql";

import { LinksModule } from "./links/links.module";

import { AppService } from "./app.service";
import { AppController } from "./app.controller";
import { ExperienceModule } from "./experience/experience.module";

@Module({
imports: [LinksModule],
controllers: [AppController],
providers: [AppService]
imports: [
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), "src/schema.gql"),
playground: false,
plugins: [ApolloServerPluginLandingPageLocalDefault()]
}),
ExperienceModule
],
controllers: [],
providers: []
})
export class AppModule {}
8 changes: 0 additions & 8 deletions apps/api/src/app.service.ts

This file was deleted.

10 changes: 10 additions & 0 deletions apps/api/src/experience/experience.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";

import { ExperienceService } from "./services/experience.service";
import { ExperienceResolver } from "./resolvers/experience.resolver";
import { ExperienceGateway } from "./gateways/experience.gateway";

@Module({
providers: [ExperienceResolver, ExperienceService, ExperienceGateway]
})
export class ExperienceModule {}
18 changes: 18 additions & 0 deletions apps/api/src/experience/gateways/experience.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from "@nestjs/testing";
import { ExperienceGateway } from "./experience.gateway";

describe("ExperienceGateway", () => {
let gateway: ExperienceGateway;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ExperienceGateway]
}).compile();

gateway = module.get<ExperienceGateway>(ExperienceGateway);
});

it("should be defined", () => {
expect(gateway).toBeDefined();
});
});
38 changes: 38 additions & 0 deletions apps/api/src/experience/gateways/experience.gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
MessageBody,
OnGatewayConnection,
OnGatewayDisconnect,
OnGatewayInit,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
WsResponse
} from "@nestjs/websockets";
import { Server, WebSocket } from "ws";

@WebSocketGateway(4000)
export class ExperienceGateway
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
{
@WebSocketServer()
server: Server;

afterInit() {
console.log(`WS: ${this.server.address().toString()}`);
}

handleConnection(client: WebSocket, ...args: any[]) {
console.log(`WS: New Client | ${client.url}`, args);
}

handleDisconnect(client: WebSocket) {
console.log(`WS: Client Disconnected | ${client.url}`);
}

@SubscribeMessage("events")
onEvent(@MessageBody() data: unknown): WsResponse<string> {
console.log(`WS: On Event | ${data}`);

return { event: "event", data: `data:${data}` };
}
}
19 changes: 19 additions & 0 deletions apps/api/src/experience/resolvers/experience.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Test, TestingModule } from "@nestjs/testing";
import { ExperienceResolver } from "./experience.resolver";
import { ExperienceService } from "./experience.service";

describe("ExperienceResolver", () => {
let resolver: ExperienceResolver;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ExperienceResolver, ExperienceService]
}).compile();

resolver = module.get<ExperienceResolver>(ExperienceResolver);
});

it("should be defined", () => {
expect(resolver).toBeDefined();
});
});
12 changes: 12 additions & 0 deletions apps/api/src/experience/resolvers/experience.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Query, Resolver } from "@nestjs/graphql";
import { ExperienceService } from "../services/experience.service";

@Resolver()
export class ExperienceResolver {
constructor(private readonly experienceService: ExperienceService) {}

@Query(() => String)
async log() {
return this.experienceService.log();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Test, TestingModule } from "@nestjs/testing";
import { LinksService } from "./links.service";
import { ExperienceService } from "./experience.service";

describe("LinksService", () => {
let service: LinksService;
describe("ExperienceService", () => {
let service: ExperienceService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [LinksService]
providers: [ExperienceService]
}).compile();

service = module.get<LinksService>(LinksService);
service = module.get<ExperienceService>(ExperienceService);
});

it("should be defined", () => {
Expand Down
8 changes: 8 additions & 0 deletions apps/api/src/experience/services/experience.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from "@nestjs/common";

@Injectable()
export class ExperienceService {
public async log() {
return "logged";
}
}
21 changes: 0 additions & 21 deletions apps/api/src/links/links.controller.spec.ts

This file was deleted.

Loading