Added README.md, started refactoring init. command
This commit is contained in:
parent
bf64a6df70
commit
2de2bec705
40
README.md
Normal file
40
README.md
Normal file
@ -0,0 +1,40 @@
|
||||
# Noxious game server
|
||||
|
||||
This is the server for the Noxious game.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository
|
||||
2. Install dependencies with `npm install`
|
||||
3. Copy the `.env.example` file to `.env` and fill in the required variables
|
||||
4. Run the server with `npm run dev`
|
||||
|
||||
## Commands
|
||||
|
||||
### `npm run dev`
|
||||
|
||||
Starts the server in development mode.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the server for production.
|
||||
|
||||
### `npm run format`
|
||||
|
||||
Formats the code using Prettier.
|
||||
|
||||
## MikroORM
|
||||
|
||||
MikroORM is used as the ORM for the server.
|
||||
|
||||
### Create init. migrations
|
||||
|
||||
Run `npx mikro-orm migration:create --initial` to create a new initial migration.
|
||||
|
||||
### Create migrations
|
||||
|
||||
Run `npx mikro-orm migration:create` to create a new migration.
|
||||
|
||||
### Apply migrations
|
||||
|
||||
Run `npx mikro-orm migration:up` to apply all pending migrations.
|
@ -1,6 +1,6 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20241225124810 extends Migration {
|
||||
export class Migration20241225180201 extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`create table \`map_object\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`tags\` json null, \`origin_x\` int not null default 0, \`origin_y\` int not null default 0, \`is_animated\` tinyint(1) not null default false, \`frame_rate\` int not null default 0, \`frame_width\` int not null default 0, \`frame_height\` int not null default 0, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`);
|
File diff suppressed because one or more lines are too long
@ -1,3 +1,4 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
import { BaseEntity } from '#application/bases/baseEntity'
|
||||
import { Zone } from './zone'
|
||||
@ -5,7 +6,7 @@ import { Zone } from './zone'
|
||||
@Entity()
|
||||
export class ZoneEffect extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id!: string
|
||||
id = randomUUID()
|
||||
|
||||
@ManyToOne(() => Zone)
|
||||
zone!: Zone
|
||||
|
@ -3,6 +3,16 @@ import { BaseRepository } from '#application/bases/baseRepository'
|
||||
import { CharacterHair } from '#entities/characterHair'
|
||||
|
||||
class CharacterHairRepository extends BaseRepository {
|
||||
async getFirst() {
|
||||
try {
|
||||
const repository = this.em.getRepository(CharacterHair)
|
||||
return await repository.findOne({ id: { $exists: true } })
|
||||
} catch (error: any) {
|
||||
appLogger.error(`Failed to get first character hair: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
try {
|
||||
const repository = this.em.getRepository(CharacterHair)
|
||||
|
@ -3,6 +3,16 @@ import { BaseRepository } from '#application/bases/baseRepository'
|
||||
import { CharacterType } from '#entities/characterType'
|
||||
|
||||
class CharacterTypeRepository extends BaseRepository {
|
||||
async getFirst() {
|
||||
try {
|
||||
const repository = this.em.getRepository(CharacterType)
|
||||
return await repository.findOne({ id: { $exists: true } })
|
||||
} catch (error: any) {
|
||||
appLogger.error(`Failed to get first character type: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
try {
|
||||
const repository = this.em.getRepository(CharacterType)
|
||||
|
@ -5,6 +5,16 @@ import { ZoneObject } from '#entities/zoneObject'
|
||||
import { Zone } from '#entities/zone'
|
||||
|
||||
class ZoneRepository extends BaseRepository {
|
||||
async getFirst(): Promise<Zone | null> {
|
||||
try {
|
||||
const repository = this.em.getRepository(Zone)
|
||||
return await repository.findOne({ id: { $exists: true } })
|
||||
} catch (error: any) {
|
||||
appLogger.error(`Failed to get first zone: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async getAll(): Promise<Zone[]> {
|
||||
try {
|
||||
const repository = this.em.getRepository(Zone)
|
||||
|
@ -38,7 +38,9 @@ export default class CharacterCreateEvent {
|
||||
}
|
||||
|
||||
const characterService = new CharacterService()
|
||||
const character: Character = await characterService.create(data.name, user_id)
|
||||
const character = await characterService.create(data.name, user_id)
|
||||
|
||||
if (!character) return this.socket.emit('notification', { message: 'Failed to create character. Please try again (later).' })
|
||||
|
||||
characters = [...characters, character]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user