Skip to content

Commit

Permalink
fix: working deno
Browse files Browse the repository at this point in the history
  • Loading branch information
morgan-cromell committed Nov 15, 2024
1 parent 1325442 commit 281da20
Show file tree
Hide file tree
Showing 128 changed files with 476 additions and 421 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"source.organizeImports": "explicit",
"source.sortMembers": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
Expand All @@ -21,5 +21,6 @@
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.updateImportsOnFileMove.enabled": "always",
"deno.enable": true,
"deno.lint": true,
"eslint.enable": false
}
5 changes: 4 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
"./packages/frontend"
],
"lint": {
"exclude": ["**/*.spec.ts"],
"rules": {
"exclude": ["no-unused-vars"]
"exclude": ["verbatim-module-syntax"]
}
},
"nodeModulesDir": "auto",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "npm:react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
Expand Down
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example-bots/node-arrows/src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from "node:process";
import { getBot, joinBoard, moveBotOnBoard, registerBot } from "./api/bot.js";
import {
couldNotJoinBoard,
Expand All @@ -6,7 +7,6 @@ import {
registrationSuccessful,
} from "./messages.js";
import { sleep } from "./utils.js";
import process from "node:process";

export const register = async (name, email, password, team) => {
const bot = await registerBot(name, email, password, team);
Expand All @@ -17,7 +17,7 @@ export const register = async (name, email, password, team) => {
}
};

const keypress = async () => {
const keypress = () => {
process.stdin.setRawMode(true);
return new Promise((resolve) =>
process.stdin.once("data", (data) => {
Expand Down Expand Up @@ -50,7 +50,7 @@ const keypress = async () => {
export const play = async (token, boardId) => {
gameStarted();
// Gets the provided logic
let bot = await getBot(token);
const bot = await getBot(token);

// Join board
let board = await joinBoard(token, boardId);
Expand Down
2 changes: 1 addition & 1 deletion example-bots/node/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const play = async (token, logic, boardId) => {
if (!logicFunction) {
invalidLogic();
}
let bot = await getBot(token);
const bot = await getBot(token);

// Join board
let board = await joinBoard(token, boardId);
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// "name": "@etimo/diamonds2-backend",
// "exports": "./mod.ts",
"name": "@etimo/diamonds2-backend",
"exports": "./mod.ts",
"tasks": {
"start": "deno run --watch -A src/main.ts",
"postinstall": "deno run -A npm:prisma generate",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,4 @@
"nodeId": "-2098992827"
}
}
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/controllers/boards.controller.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Param } from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { BoardDto, BoardMetadataDto } from "../models";
import { BoardsService } from "../services";
import { BoardDto, BoardMetadataDto } from "../models/index.ts";
import { BoardsService } from "../services/index.ts";

@ApiTags("Boards")
@Controller("api/boards")
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/controllers/bots.controller.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
BotRegistrationPublicDto,
JoinInputDto,
MoveInputDto,
} from "../models";
import { BoardsService, BotsService } from "../services";
import { NotFoundError } from "../errors";
} from "../models/index.ts";
import { BoardsService, BotsService } from "../services/index.ts";
import { NotFoundError } from "../errors/index.ts";

@ApiTags("Bots")
@Controller("api/bots")
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/controllers/highscores.controller.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Param } from "@nestjs/common";
import { ApiResponse, ApiTags } from "@nestjs/swagger";
import { HighscorePublicDto } from "../models";
import { HighscoresService } from "../services";
import { HighscorePublicDto } from "../models/index.ts";
import { HighscoresService } from "../services/index.ts";

@ApiTags("Highscores")
@Controller("api/highscores")
Expand All @@ -27,7 +27,7 @@ export class HighscoresController {
seasonId,
);
return highscores.map((highscore) =>
HighscorePublicDto.fromEntity(highscore),
HighscorePublicDto.fromEntity(highscore)
);
}
}
14 changes: 7 additions & 7 deletions packages/backend/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from "./boards.controller";
export * from "./bots.controller";
export * from "./highscores.controller";
export * from "./recordings.controller";
export * from "./seasons.controller";
export * from "./slack.controller";
export * from "./teams.controller";
export * from "./boards.controller.ts";
export * from "./bots.controller.ts";
export * from "./highscores.controller.ts";
export * from "./recordings.controller.ts";
export * from "./seasons.controller.ts";
export * from "./slack.controller.ts";
export * from "./teams.controller.ts";
4 changes: 2 additions & 2 deletions packages/backend/src/controllers/recordings.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Param } from "@nestjs/common";
import { ApiResponse, ApiTags } from "@nestjs/swagger";
import { RecordingListDto, RecordingPublicDto } from "../models";
import { RecordingsService } from "../services";
import { RecordingListDto, RecordingPublicDto } from "../models/index.ts";
import { RecordingsService } from "../services/index.ts";

@ApiTags("Recordings")
@Controller("api/recordings")
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/controllers/seasons.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Param } from "@nestjs/common";
import { ApiResponse, ApiTags } from "@nestjs/swagger";
import { BoardConfigDto, SeasonDto } from "../models";
import { BoardConfigService, SeasonsService } from "../services";
import { BoardConfigDto, SeasonDto } from "../models/index.ts";
import { BoardConfigService, SeasonsService } from "../services/index.ts";

@ApiTags("Seasons")
@Controller("api/seasons")
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/controllers/slack.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, HttpCode, Post, Req } from "@nestjs/common";
import { ApiResponse, ApiTags } from "@nestjs/swagger";
import { AuthorizationService, SlackService } from "../services";
import { AuthorizationService, SlackService } from "../services/index.ts";

@ApiTags("Slack")
@Controller("api/slack")
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/controllers/teams.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get } from "@nestjs/common";
import { ApiResponse, ApiTags } from "@nestjs/swagger";
import { TeamDto } from "../models";
import { TeamsService } from "../services";
import { TeamDto } from "../models/index.ts";
import { TeamsService } from "../services/index.ts";

@ApiTags("Teams")
@Controller("api/teams")
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./repositories";
export * from "./repositories/index.ts";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "../../services/prisma.service";
import { IBoardConfig, INewBoardConfig } from "../../types";
import { PrismaService } from "../../services/prisma.service.ts";
import { IBoardConfig, INewBoardConfig } from "../../types/index.ts";

@Injectable()
export class BoardConfigRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "../../services/prisma.service";
import { IBot, INewBot } from "../../types";
import { PrismaService } from "../../services/prisma.service.ts";
import { IBot, INewBot } from "../../types/index.ts";

@Injectable()
export class BotRegistrationsRepository {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/db/repositories/highscores.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "../../services/prisma.service";
import { IHighscore, INewHighscore } from "../../types";
import { PrismaService } from "../../services/prisma.service.ts";
import { IHighscore, INewHighscore } from "../../types/index.ts";

@Injectable()
export class HighscoresRepository {
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/src/db/repositories/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./boardConfig.repository";
export * from "./botRegistrations.repository";
export * from "./highscores.repository";
export * from "./recordings.repository";
export * from "./seasons.repository";
export * from "./teams.repository";
export * from "./boardConfig.repository.ts";
export * from "./botRegistrations.repository.ts";
export * from "./highscores.repository.ts";
export * from "./recordings.repository.ts";
export * from "./seasons.repository.ts";
export * from "./teams.repository.ts";
4 changes: 2 additions & 2 deletions packages/backend/src/db/repositories/recordings.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "../../services/prisma.service";
import { INewRecording, IRecording } from "../../types";
import { PrismaService } from "../../services/prisma.service.ts";
import { INewRecording, IRecording } from "../../types/index.ts";

@Injectable()
export class RecordingsRepository {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/db/repositories/seasons.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "../../services/prisma.service";
import { INewSeason, ISeason } from "../../types";
import { PrismaService } from "../../services/prisma.service.ts";
import { INewSeason, ISeason } from "../../types/index.ts";

@Injectable()
export class SeasonsRepository {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/db/repositories/teams.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "../../services/prisma.service";
import { INewTeam, ITeam } from "../../types";
import { PrismaService } from "../../services/prisma.service.ts";
import { INewTeam, ITeam } from "../../types/index.ts";

@Injectable()
export class TeamsRepository {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./bots-errors.enum";
export * from "./move-direction.enum";
export * from "./bots-errors.enum.ts";
export * from "./move-direction.enum.ts";
2 changes: 1 addition & 1 deletion packages/backend/src/errors/conflict.error.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiamondsBaseError } from "./base.error";
import { DiamondsBaseError } from "./base.error.ts";

export class ConflictError extends DiamondsBaseError {
constructor(message: string, errorTag?: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/errors/forbidden.error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiamondsBaseError } from "./base.error";
import { DiamondsBaseError } from "./base.error.ts";

export class ForbiddenError extends DiamondsBaseError {
constructor(message: string, errorTag?: string) {
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./base.error";
export * from "./conflict.error";
export * from "./forbidden.error";
export * from "./not-found.error";
export * from "./unauthorized.error";
export * from "./base.error.ts";
export * from "./conflict.error.ts";
export * from "./forbidden.error.ts";
export * from "./not-found.error.ts";
export * from "./unauthorized.error.ts";
4 changes: 2 additions & 2 deletions packages/backend/src/errors/not-found.error.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DiamondsBaseError } from "./base.error";
import { DiamondsBaseError } from "./base.error.ts";

export class NotFoundError extends DiamondsBaseError {
export class NotFoundError extends DiamondsBaseError {
constructor(message: string) {
super(message);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/errors/unauthorized.error.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiamondsBaseError } from "./base.error";
import { DiamondsBaseError } from "./base.error.ts";

export class UnauthorizedError extends DiamondsBaseError {
constructor(message: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/exceptions.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BotsErrors } from "./enums";
import { BotsErrors } from "./enums/index.ts";

export class ValidationException extends Error {
constructor(botErrors: BotsErrors) {
Expand Down
31 changes: 22 additions & 9 deletions packages/backend/src/gameengine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ The game engine is designed around some kind of mediator-like pattern.

## Game object providers

Game object providers react to events around the board itself, such as when a board is initialized and when objects are added or removed.
Game object providers react to events around the board itself, such as when a
board is initialized and when objects are added or removed.

All providers must inherit the abstract class `AbstractGameObjectProvider`.

Expand All @@ -20,30 +21,40 @@ Providers are mainly responsible for spawning/removing game objects.

Examples:

- When a board is initialized, generate a set of diamond game objects that can be collected.
- When a board is initialized, generate a set of diamond game objects that can
be collected.
- When diamonds are depleted, generate new ones.

## Game objects

Game objects are the actual objects placed on the board. Game objects have a position, they can be acted upon, they can collide, they can react to other game objects etc.
Game objects are the actual objects placed on the board. Game objects have a
position, they can be acted upon, they can collide, they can react to other game
objects etc.

All game objects perform actions using the assigned board as the mediator.

All game objects must inherit the abstract class `AbstractGameObject`.

Available events:

- _canGameObjectEnter_ - Another game object wants to move to the cell that this game object belongs to
- _onGameObjectEntered_ - Another game object moved to the cell of this game object
- _canGameObjectLeave_ - Another game object wants to leave the cell that this game object belongs to
- _canGameObjectEnter_ - Another game object wants to move to the cell that this
game object belongs to
- _onGameObjectEntered_ - Another game object moved to the cell of this game
object
- _canGameObjectLeave_ - Another game object wants to leave the cell that this
game object belongs to
- _onGameObjectLeft_ - Another game object left the cell of this game object
- _onGameObjectCallbackNotified_ - Callback for when a certain time has passed. Use to perform periodic activity. Requires telling the board to you notify you every X ms (`registerGameObjectForCallbackLoop(gameObject: AbstractGameObject, interval: number)`)
- _onGameObjectCallbackNotified_ - Callback for when a certain time has passed.
Use to perform periodic activity. Requires telling the board to you notify you
every X ms
(`registerGameObjectForCallbackLoop(gameObject: AbstractGameObject, interval: number)`)
- _onGameObjectRemoved_ - This game object was removed from the board
- _onEvent_ - Some kind of other event was published from a game object

### Available game objects

These are the game objects currently sort of implemented (not fully tested yet though :). They have a provider as well.
These are the game objects currently sort of implemented (not fully tested yet
though :). They have a provider as well.

- [Base](gameobjects/base/)
- [Bot](gameobjects/bot/)
Expand All @@ -54,7 +65,9 @@ These are the game objects currently sort of implemented (not fully tested yet t

## Boards

A board is created using a configuration and a set of game object providers ("Features"). This makes it easy to create different boards with different features activated.
A board is created using a configuration and a set of game object providers
("Features"). This makes it easy to create different boards with different
features activated.

```typescript
const providers = [
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/src/gameengine/board.spec.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Position } from "@etimo/diamonds2-types";
import { IBot } from "../types";
import { Board } from "./board";
import { BaseGameObject } from "./gameobjects/base/base";
import { BotGameObject } from "./gameobjects/bot/bot";
import { BotProvider } from "./gameobjects/bot/bot-provider";
import { DiamondProvider } from "./gameobjects/diamond/diamond-provider";
import { createTestBoard, createTestBot } from "./util";
import { IBot } from "../types/index.ts";
import { Board } from "./board.ts";
import { BaseGameObject } from "./gameobjects/base/base.ts";
import { BotGameObject } from "./gameobjects/bot/bot.ts";
import { BotProvider } from "./gameobjects/bot/bot-provider.ts";
import { DiamondProvider } from "./gameobjects/diamond/diamond-provider.ts";
import { createTestBoard, createTestBot } from "./util/index.ts";

let opponentPosition: Position;
let board: Board;
Expand Down
Loading

0 comments on commit 281da20

Please sign in to comment.