diff --git a/lol.js b/lol.js new file mode 100644 index 0000000..425e00f --- /dev/null +++ b/lol.js @@ -0,0 +1,47 @@ +const fs = require('fs/promises'); +const path = require('path'); + +function toPascalCase(str) { + return str.charAt(0).toUpperCase() + str.slice(1); +} + +async function transformEntities() { + const entitiesDir = './src/entities'; + const baseDir = './src/entities/base'; + + // Create base directory if it doesn't exist + await fs.mkdir(baseDir, { recursive: true }); + + // Get all .ts files in entities directory + const files = await fs.readdir(entitiesDir); + const tsFiles = files.filter(file => file.endsWith('.ts') && file !== 'index.ts'); + + for (const file of tsFiles) { + const filePath = path.join(entitiesDir, file); + let content = await fs.readFile(filePath, 'utf-8'); + + // Get proper Pascal Case class name + const className = toPascalCase(path.basename(file, '.ts')); + + // Create base class content + let baseContent = content + .replace(/@Entity\(\)/, '') // Remove @Entity decorator + .replace(/export class (\w+)/, `export class Base${className}`); // Add Base prefix with proper Pascal Case + + // Create derived class content + const derivedContent = `import { Entity } from '@mikro-orm/core' +import { Base${className} } from '#entities/base/${file}' + +@Entity() +export class ${className} extends Base${className} {} +`; + + // Write base class + await fs.writeFile(path.join(baseDir, file), baseContent); + + // Write derived class + await fs.writeFile(filePath, derivedContent); + } +} + +transformEntities().catch(console.error); diff --git a/migrations/Migration20250105033941.ts b/migrations/Migration20250106170204.ts similarity index 99% rename from migrations/Migration20250105033941.ts rename to migrations/Migration20250106170204.ts index d22c686..1937fb2 100644 --- a/migrations/Migration20250105033941.ts +++ b/migrations/Migration20250106170204.ts @@ -1,6 +1,6 @@ import { Migration } from '@mikro-orm/migrations'; -export class Migration20250105033941 extends Migration { +export class Migration20250106170204 extends Migration { override async up(): Promise { this.addSql(`create table \`map\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`width\` int not null default 10, \`height\` int not null default 10, \`tiles\` json null, \`pvp\` tinyint(1) not null default false, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); diff --git a/mikro-orm.config.ts b/mikro-orm.config.ts index 5bc1e12..2d9fda9 100644 --- a/mikro-orm.config.ts +++ b/mikro-orm.config.ts @@ -8,8 +8,8 @@ import serverConfig from './src/application/config' export default defineConfig({ extensions: [Migrator], metadataProvider: TsMorphMetadataProvider, - entities: ['./src/entities/**/*.js'], - entitiesTs: ['./src/entities/**/*.ts'], + entities: ['./src/entities/*.js'], + entitiesTs: ['./src/entities/*.ts'], driver: MySqlDriver, host: serverConfig.DB_HOST, port: serverConfig.DB_PORT, diff --git a/src/entities/base/character.ts b/src/entities/base/character.ts new file mode 100644 index 0000000..f710ab1 --- /dev/null +++ b/src/entities/base/character.ts @@ -0,0 +1,296 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { CharacterEquipment } from '#entities/characterEquipment' +import { CharacterHair } from '#entities/characterHair' +import { CharacterItem } from '#entities/characterItem' +import { CharacterType } from '#entities/characterType' +import { Chat } from '#entities/chat' +import { Map } from '#entities/map' +import { User } from '#entities/user' + + +export class BaseCharacter extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + user!: User + + @Property({ unique: true }) + name!: string + + @Property() + online = false + + @Property() + role = 'player' + + @OneToMany(() => Chat, (chat) => chat.character) + chats = new Collection(this) + + // Position - @TODO: Update to spawn point when current map is not found + @ManyToOne() + map!: Map + + @Property() + positionX = 0 + + @Property() + positionY = 0 + + @Property() + rotation = 0 + + // Customization + @ManyToOne({ deleteRule: 'set null' }) + characterType?: CharacterType | null | undefined + + @ManyToOne({ deleteRule: 'set null' }) + characterHair?: CharacterHair | null | undefined + + // Inventory + @OneToMany({ mappedBy: 'character' }) + items = new Collection(this) + + @OneToMany({ mappedBy: 'character' }) + equipment = new Collection(this) + + // Stats + @Property() + alignment = 50 + + @Property() + hitpoints = 100 + + @Property() + mana = 100 + + @Property() + level = 1 + + @Property() + experience = 0 + + @Property() + strength = 10 + + @Property() + dexterity = 10 + + @Property() + intelligence = 10 + + @Property() + wisdom = 10 + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setUser(user: User) { + this.user = user + return this + } + + getUser() { + return this.user + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setOnline(online: boolean) { + this.online = online + return this + } + + getOnline() { + return this.online + } + + setRole(role: string) { + this.role = role + return this + } + + getRole() { + return this.role + } + + setChats(chats: Collection) { + this.chats = chats + return this + } + + getChats() { + return this.chats + } + + setMap(map: Map) { + this.map = map + return this + } + + getMap() { + return this.map + } + + setPositionX(positionX: number) { + this.positionX = positionX + return this + } + + getPositionX() { + return this.positionX + } + + setPositionY(positionY: number) { + this.positionY = positionY + return this + } + + getPositionY() { + return this.positionY + } + + setRotation(rotation: number) { + this.rotation = rotation + return this + } + + getRotation() { + return this.rotation + } + + setCharacterType(characterType: CharacterType | null | undefined) { + this.characterType = characterType + return this + } + + getCharacterType() { + return this.characterType + } + + setCharacterHair(characterHair: CharacterHair | null | undefined) { + this.characterHair = characterHair + return this + } + + getCharacterHair() { + return this.characterHair + } + + setItems(items: Collection) { + this.items = items + return this + } + + getItems() { + return this.items + } + + setEquipment(equipment: Collection) { + this.equipment = equipment + return this + } + + getEquipment() { + return this.equipment + } + + setAlignment(alignment: number) { + this.alignment = alignment + return this + } + + getAlignment() { + return this.alignment + } + + setHitpoints(hitpoints: number) { + this.hitpoints = hitpoints + return this + } + + getHitpoints() { + return this.hitpoints + } + + setMana(mana: number) { + this.mana = mana + return this + } + + getMana() { + return this.mana + } + + setLevel(level: number) { + this.level = level + return this + } + + getLevel() { + return this.level + } + + setExperience(experience: number) { + this.experience = experience + return this + } + + getExperience() { + return this.experience + } + + setStrength(strength: number) { + this.strength = strength + return this + } + + getStrength() { + return this.strength + } + + setDexterity(dexterity: number) { + this.dexterity = dexterity + return this + } + + getDexterity() { + return this.dexterity + } + + setIntelligence(intelligence: number) { + this.intelligence = intelligence + return this + } + + getIntelligence() { + return this.intelligence + } + + setWisdom(wisdom: number) { + this.wisdom = wisdom + return this + } + + getWisdom() { + return this.wisdom + } +} diff --git a/src/entities/base/characterEquipment.ts b/src/entities/base/characterEquipment.ts new file mode 100644 index 0000000..34cd6e7 --- /dev/null +++ b/src/entities/base/characterEquipment.ts @@ -0,0 +1,60 @@ +import { randomUUID } from 'node:crypto' + +import { Enum, ManyToOne, PrimaryKey } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { CharacterEquipmentSlotType } from '#application/enums' +import { UUID } from '#application/types' +import { Character } from '#entities/character' +import { CharacterItem } from '#entities/characterItem' + +export class BaseCharacterEquipment extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Enum(() => CharacterEquipmentSlotType) + slot!: CharacterEquipmentSlotType + + @ManyToOne({ deleteRule: 'cascade' }) + character!: Character + + @ManyToOne({ deleteRule: 'cascade' }) + characterItem!: CharacterItem + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setSlot(slot: CharacterEquipmentSlotType) { + this.slot = slot + return this + } + + getSlot() { + return this.slot + } + + setCharacter(character: Character) { + this.character = character + return this + } + + getCharacter() { + return this.character + } + + setCharacterItem(characterItem: CharacterItem) { + this.characterItem = characterItem + return this + } + + getCharacterItem() { + return this.characterItem + } +} diff --git a/src/entities/base/characterHair.ts b/src/entities/base/characterHair.ts new file mode 100644 index 0000000..fb5bf3f --- /dev/null +++ b/src/entities/base/characterHair.ts @@ -0,0 +1,72 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { CharacterGender } from '#application/enums' +import { UUID } from '#application/types' +import { Character } from '#entities/character' +import { Sprite } from '#entities/sprite' + +export class BaseCharacterHair extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @Property() + gender: CharacterGender = CharacterGender.MALE + + @Property() + isSelectable = false + + @ManyToOne() + sprite?: Sprite + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setGender(gender: CharacterGender) { + this.gender = gender + return this + } + + getGender() { + return this.gender + } + + setIsSelectable(isSelectable: boolean) { + this.isSelectable = isSelectable + return this + } + + getIsSelectable() { + return this.isSelectable + } + + setSprite(sprite: Sprite) { + this.sprite = sprite + return this + } + + getSprite() { + return this.sprite + } +} diff --git a/src/entities/base/characterItem.ts b/src/entities/base/characterItem.ts new file mode 100644 index 0000000..ba0c0e9 --- /dev/null +++ b/src/entities/base/characterItem.ts @@ -0,0 +1,60 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Character } from '#entities/character' +import { CharacterEquipment } from '#entities/characterEquipment' +import { Item } from '#entities/item' + + +export class BaseCharacterItem extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + character!: Character + + @ManyToOne({ deleteRule: 'cascade' }) + item!: Item + + @Property() + quantity!: number + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setCharacter(character: Character) { + this.character = character + return this + } + + getCharacter() { + return this.character + } + + setItem(item: Item) { + this.item = item + return this + } + + getItem() { + return this.item + } + + setQuantity(quantity: number) { + this.quantity = quantity + return this + } + + getQuantity() { + return this.quantity + } +} diff --git a/src/entities/base/characterType.ts b/src/entities/base/characterType.ts new file mode 100644 index 0000000..e10d94d --- /dev/null +++ b/src/entities/base/characterType.ts @@ -0,0 +1,108 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { CharacterGender, CharacterRace } from '#application/enums' +import { UUID } from '#application/types' +import { Character } from '#entities/character' +import { Sprite } from '#entities/sprite' + +export class BaseCharacterType extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @Enum(() => CharacterGender) + gender!: CharacterGender + + @Enum(() => CharacterRace) + race!: CharacterRace + + @Property() + isSelectable = false + + @ManyToOne() + sprite?: Sprite + + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setGender(gender: CharacterGender) { + this.gender = gender + return this + } + + getGender() { + return this.gender + } + + setRace(race: CharacterRace) { + this.race = race + return this + } + + getRace() { + return this.race + } + + setIsSelectable(isSelectable: boolean) { + this.isSelectable = isSelectable + return this + } + + getIsSelectable() { + return this.isSelectable + } + + setSprite(sprite: Sprite) { + this.sprite = sprite + return this + } + + getSprite() { + return this.sprite + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } +} diff --git a/src/entities/base/chat.ts b/src/entities/base/chat.ts new file mode 100644 index 0000000..4522b1c --- /dev/null +++ b/src/entities/base/chat.ts @@ -0,0 +1,71 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Character } from '#entities/character' +import { Map } from '#entities/map' + + +export class BaseChat extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + character!: Character + + @ManyToOne({ deleteRule: 'cascade' }) + map!: Map + + @Property() + message!: string + + @Property() + createdAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setCharacter(character: Character) { + this.character = character + return this + } + + getCharacter() { + return this.character + } + + setMap(map: Map) { + this.map = map + return this + } + + getMap() { + return this.map + } + + setMessage(message: string) { + this.message = message + return this + } + + getMessage() { + return this.message + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } +} diff --git a/src/entities/base/item.ts b/src/entities/base/item.ts new file mode 100644 index 0000000..d039cab --- /dev/null +++ b/src/entities/base/item.ts @@ -0,0 +1,120 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { ItemType, ItemRarity } from '#application/enums' +import { UUID } from '#application/types' +import { CharacterItem } from '#entities/characterItem' +import { Sprite } from '#entities/sprite' + +export class BaseItem extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @Property() + description: string = '' + + @Enum(() => ItemType) + itemType!: ItemType + + @Property() + stackable = false + + @Enum(() => ItemRarity) + rarity: ItemRarity = ItemRarity.COMMON + + @ManyToOne(() => Sprite) + sprite?: Sprite + + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setDescription(description: string) { + this.description = description + return this + } + + getDescription() { + return this.description + } + + setItemType(itemType: ItemType) { + this.itemType = itemType + return this + } + + getItemType() { + return this.itemType + } + + setStackable(stackable: boolean) { + this.stackable = stackable + return this + } + + getStackable() { + return this.stackable + } + + setRarity(rarity: ItemRarity) { + this.rarity = rarity + return this + } + + getRarity() { + return this.rarity + } + + setSprite(sprite: Sprite) { + this.sprite = sprite + return this + } + + getSprite() { + return this.sprite + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } +} diff --git a/src/entities/base/map.ts b/src/entities/base/map.ts new file mode 100644 index 0000000..c4eb07a --- /dev/null +++ b/src/entities/base/map.ts @@ -0,0 +1,143 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { MapEffect } from '#entities/mapEffect' +import { MapEventTile } from '#entities/mapEventTile' +import { PlacedMapObject } from '#entities/placedMapObject' + +export class BaseMap extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @Property() + width = 10 + + @Property() + height = 10 + + @Property({ type: 'json', nullable: true }) + tiles?: any + + @Property() + pvp = false + + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + + @OneToMany(() => MapEffect, (effect) => effect.map, { orphanRemoval: true }) + mapEffects = new Collection(this) + + @OneToMany(() => MapEventTile, (tile) => tile.map, { orphanRemoval: true }) + mapEventTiles = new Collection(this) + + @OneToMany(() => PlacedMapObject, (placedMapObject) => placedMapObject.map, { orphanRemoval: true }) + placedMapObjects = new Collection(this) + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setWidth(width: number) { + this.width = width + return this + } + + getWidth() { + return this.width + } + + setHeight(height: number) { + this.height = height + return this + } + + getHeight() { + return this.height + } + + setTiles(tiles: any) { + this.tiles = tiles + return this + } + + getTiles() { + return this.tiles + } + + setPvp(pvp: boolean) { + this.pvp = pvp + return this + } + + getPvp() { + return this.pvp + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } + + setMapEffects(mapEffects: Collection) { + this.mapEffects = mapEffects + return this + } + + getMapEffects() { + return this.mapEffects + } + + setMapEventTiles(mapEventTiles: Collection) { + this.mapEventTiles = mapEventTiles + return this + } + + getMapEventTiles() { + return this.mapEventTiles + } + + setPlacedMapObjects(placedMapObjects: Collection) { + this.placedMapObjects = placedMapObjects + return this + } + + getPlacedMapObjects() { + return this.placedMapObjects + } +} diff --git a/src/entities/base/mapEffect.ts b/src/entities/base/mapEffect.ts new file mode 100644 index 0000000..82f5335 --- /dev/null +++ b/src/entities/base/mapEffect.ts @@ -0,0 +1,58 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Map } from '#entities/map' + +export class BaseMapEffect extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + map!: Map + + @Property() + effect!: string + + @Property() + strength!: number + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setMap(map: Map) { + this.map = map + return this + } + + getMap() { + return this.map + } + + setEffect(effect: string) { + this.effect = effect + return this + } + + getEffect() { + return this.effect + } + + setStrength(strength: number) { + this.strength = strength + return this + } + + getStrength() { + return this.strength + } +} diff --git a/src/entities/base/mapEventTile.ts b/src/entities/base/mapEventTile.ts new file mode 100644 index 0000000..a95bca6 --- /dev/null +++ b/src/entities/base/mapEventTile.ts @@ -0,0 +1,84 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { MapEventTileType } from '#application/enums' +import { UUID } from '#application/types' +import { Map } from '#entities/map' +import { MapEventTileTeleport } from '#entities/mapEventTileTeleport' + +export class BaseMapEventTile extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + map!: Map + + @Enum(() => MapEventTileType) + type!: MapEventTileType + + @Property() + positionX!: number + + @Property() + positionY!: number + + @OneToOne(() => MapEventTileTeleport, (teleport) => teleport.mapEventTile, { eager: true }) + teleport?: MapEventTileTeleport + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setMap(map: Map) { + this.map = map + return this + } + + getMap() { + return this.map + } + + setType(type: MapEventTileType) { + this.type = type + return this + } + + getType() { + return this.type + } + + setPositionX(positionX: number) { + this.positionX = positionX + return this + } + + getPositionX() { + return this.positionX + } + + setPositionY(positionY: number) { + this.positionY = positionY + return this + } + + getPositionY() { + return this.positionY + } + + setTeleport(teleport: MapEventTileTeleport) { + this.teleport = teleport + return this + } + + getTeleport() { + return this.teleport + } +} diff --git a/src/entities/base/mapEventTileTeleport.ts b/src/entities/base/mapEventTileTeleport.ts new file mode 100644 index 0000000..a921637 --- /dev/null +++ b/src/entities/base/mapEventTileTeleport.ts @@ -0,0 +1,83 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Map } from '#entities/map' +import { MapEventTile } from '#entities/mapEventTile' + + +export class BaseMapEventTileTeleport extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @OneToOne({ deleteRule: 'cascade' }) + mapEventTile!: MapEventTile + + @ManyToOne({ deleteRule: 'cascade', eager: true }) + toMap!: Map + + @Property() + toRotation!: number + + @Property() + toPositionX!: number + + @Property() + toPositionY!: number + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setMapEventTile(mapEventTile: MapEventTile) { + this.mapEventTile = mapEventTile + return this + } + + getMapEventTile() { + return this.mapEventTile + } + + setToMap(toMap: Map) { + this.toMap = toMap + return this + } + + getToMap() { + return this.toMap + } + + setToRotation(toRotation: number) { + this.toRotation = toRotation + return this + } + + getToRotation() { + return this.toRotation + } + + setToPositionX(toPositionX: number) { + this.toPositionX = toPositionX + return this + } + + getToPositionX() { + return this.toPositionX + } + + setToPositionY(toPositionY: number) { + this.toPositionY = toPositionY + return this + } + + getToPositionY() { + return this.toPositionY + } +} diff --git a/src/entities/base/mapObject.ts b/src/entities/base/mapObject.ts new file mode 100644 index 0000000..a3fb7ae --- /dev/null +++ b/src/entities/base/mapObject.ts @@ -0,0 +1,140 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' + +export class BaseMapObject extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @Property({ type: 'json', nullable: true }) + tags?: any + + @Property({ type: 'decimal', precision: 10, scale: 2 }) + originX = 0 + + @Property({ type: 'decimal', precision: 10, scale: 2 }) + originY = 0 + + @Property() + isAnimated = false + + @Property() + frameRate = 0 + + @Property() + frameWidth = 0 + + @Property() + frameHeight = 0 + + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setTags(tags: any) { + this.tags = tags + return this + } + + getTags() { + return this.tags + } + + setOriginX(originX: number) { + this.originX = originX + return this + } + + getOriginX() { + return this.originX + } + + setOriginY(originY: number) { + this.originY = originY + return this + } + + getOriginY() { + return this.originY + } + + setIsAnimated(isAnimated: boolean) { + this.isAnimated = isAnimated + return this + } + + getIsAnimated() { + return this.isAnimated + } + + setFrameRate(frameRate: number) { + this.frameRate = frameRate + return this + } + + getFrameRate() { + return this.frameRate + } + + setFrameWidth(frameWidth: number) { + this.frameWidth = frameWidth + return this + } + + getFrameWidth() { + return this.frameWidth + } + + setFrameHeight(frameHeight: number) { + this.frameHeight = frameHeight + return this + } + + getFrameHeight() { + return this.frameHeight + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } +} diff --git a/src/entities/base/passwordResetToken.ts b/src/entities/base/passwordResetToken.ts new file mode 100644 index 0000000..13ffed6 --- /dev/null +++ b/src/entities/base/passwordResetToken.ts @@ -0,0 +1,58 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { User } from '#entities/user' + +export class BasePasswordResetToken extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + user!: User + + @Property({ unique: true }) + token!: string + + @Property() + createdAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setUser(user: User) { + this.user = user + return this + } + + getUser() { + return this.user + } + + setToken(token: string) { + this.token = token + return this + } + + getToken() { + return this.token + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } +} diff --git a/src/entities/base/placedMapObject.ts b/src/entities/base/placedMapObject.ts new file mode 100644 index 0000000..8d91b13 --- /dev/null +++ b/src/entities/base/placedMapObject.ts @@ -0,0 +1,97 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Map } from '#entities/map' +import { MapObject } from '#entities/mapObject' + +//@TODO : Rename mapObject + +export class BasePlacedMapObject extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + map!: Map + + @ManyToOne({ deleteRule: 'cascade', eager: true }) + mapObject!: MapObject + + @Property() + depth = 0 + + @Property() + isRotated = false + + @Property() + positionX = 0 + + @Property() + positionY = 0 + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setMap(map: Map) { + this.map = map + return this + } + + getMap() { + return this.map + } + + setMapObject(mapObject: MapObject) { + this.mapObject = mapObject + return this + } + + getMapObject() { + return this.mapObject + } + + setDepth(depth: number) { + this.depth = depth + return this + } + + getDepth() { + return this.depth + } + + setIsRotated(isRotated: boolean) { + this.isRotated = isRotated + return this + } + + getIsRotated() { + return this.isRotated + } + + setPositionX(positionX: number) { + this.positionX = positionX + return this + } + + getPositionX() { + return this.positionX + } + + setPositionY(positionY: number) { + this.positionY = positionY + return this + } + + getPositionY() { + return this.positionY + } +} diff --git a/src/entities/base/sprite.ts b/src/entities/base/sprite.ts new file mode 100644 index 0000000..d60cc18 --- /dev/null +++ b/src/entities/base/sprite.ts @@ -0,0 +1,70 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { SpriteAction } from '#entities/spriteAction' + +export class BaseSprite extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @OneToMany(() => SpriteAction, (action) => action.sprite) + spriteActions = new Collection(this) + + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setSpriteActions(spriteActions: Collection) { + this.spriteActions = spriteActions + return this + } + + getSpriteActions() { + return this.spriteActions + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } +} diff --git a/src/entities/base/spriteAction.ts b/src/entities/base/spriteAction.ts new file mode 100644 index 0000000..06bdc08 --- /dev/null +++ b/src/entities/base/spriteAction.ts @@ -0,0 +1,142 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' + + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Sprite } from '#entities/sprite' + +export class BaseSpriteAction extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @ManyToOne({ deleteRule: 'cascade' }) + sprite!: Sprite + + @Property() + action!: string + + @Property({ type: 'json', nullable: true }) + sprites?: string[] + + @Property() + originX = 0 + + @Property() + originY = 0 + + @Property() + isAnimated = false + + @Property() + isLooping = false + + @Property() + frameWidth = 0 + + @Property() + frameHeight = 0 + + @Property() + frameRate = 0 + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setSprite(sprite: Sprite) { + this.sprite = sprite + return this + } + + getSprite() { + return this.sprite + } + + setAction(action: string) { + this.action = action + return this + } + + getAction() { + return this.action + } + + setSprites(sprites: string[]) { + this.sprites = sprites + return this + } + + getSprites() { + return this.sprites + } + + setOriginX(originX: number) { + this.originX = originX + return this + } + + getOriginX() { + return this.originX + } + + setOriginY(originY: number) { + this.originY = originY + return this + } + + getOriginY() { + return this.originY + } + + setIsAnimated(isAnimated: boolean) { + this.isAnimated = isAnimated + return this + } + + getIsAnimated() { + return this.isAnimated + } + + setIsLooping(isLooping: boolean) { + this.isLooping = isLooping + return this + } + + getIsLooping() { + return this.isLooping + } + + setFrameWidth(frameWidth: number) { + this.frameWidth = frameWidth + return this + } + + getFrameWidth() { + return this.frameWidth + } + + setFrameHeight(frameHeight: number) { + this.frameHeight = frameHeight + return this + } + + getFrameHeight() { + return this.frameHeight + } + + setFrameRate(frameRate: number) { + this.frameRate = frameRate + return this + } + + getFrameRate() { + return this.frameRate + } +} diff --git a/src/entities/base/tile.ts b/src/entities/base/tile.ts new file mode 100644 index 0000000..0679157 --- /dev/null +++ b/src/entities/base/tile.ts @@ -0,0 +1,68 @@ +import { randomUUID } from 'node:crypto' + +import { Entity, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' + +export class BaseTile extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property() + name!: string + + @Property({ type: 'json', nullable: true }) + tags?: any + + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setName(name: string) { + this.name = name + return this + } + + getName() { + return this.name + } + + setTags(tags: any) { + this.tags = tags + return this + } + + getTags() { + return this.tags + } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } +} diff --git a/src/entities/base/user.ts b/src/entities/base/user.ts new file mode 100644 index 0000000..99240f3 --- /dev/null +++ b/src/entities/base/user.ts @@ -0,0 +1,97 @@ +import { randomUUID } from 'node:crypto' + +import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' +import bcrypt from 'bcryptjs' + +import { BaseEntity } from '#application/base/baseEntity' +import { UUID } from '#application/types' +import { Character } from '#entities/character' +import { PasswordResetToken } from '#entities/passwordResetToken' + + +export class BaseUser extends BaseEntity { + @PrimaryKey() + id = randomUUID() + + @Property({ unique: true }) + username!: string + + @Property({ unique: true }) + email!: string + + @Property() + password!: string + + @Property() + online = false + + @OneToMany(() => Character, (character) => character.user) + characters = new Collection(this) + + @OneToMany(() => PasswordResetToken, (token) => token.user) + passwordResetTokens = new Collection(this) + + setId(id: UUID) { + this.id = id + return this + } + + getId() { + return this.id + } + + setUsername(username: string) { + this.username = username + return this + } + + getUsername() { + return this.username + } + + setEmail(email: string) { + this.email = email + return this + } + + getEmail() { + return this.email + } + + setPassword(password: string) { + this.password = bcrypt.hashSync(password, 10) + return this + } + + getPassword() { + return this.password + } + + setOnline(online: boolean) { + this.online = online + return this + } + + getOnline() { + return this.online + } + + setCharacters(characters: Collection) { + this.characters = characters + return this + } + + getCharacters() { + return this.characters + } + + setPasswordResetTokens(passwordResetTokens: Collection) { + this.passwordResetTokens = passwordResetTokens + return this + } + + getPasswordResetTokens() { + return this.passwordResetTokens + return this + } +} diff --git a/src/entities/base/world.ts b/src/entities/base/world.ts new file mode 100644 index 0000000..50658d1 --- /dev/null +++ b/src/entities/base/world.ts @@ -0,0 +1,65 @@ +import { Entity, PrimaryKey, Property } from '@mikro-orm/core' + +import { BaseEntity } from '#application/base/baseEntity' + +export class BaseWorld extends BaseEntity { + @PrimaryKey() + date = new Date() + + @Property() + isRainEnabled = false + + @Property() + rainPercentage = 0 + + @Property() + isFogEnabled = false + + @Property() + fogDensity = 0 + + setDate(date: Date) { + this.date = date + return this + } + + getDate() { + return this.date + } + + setIsRainEnabled(isRainEnabled: boolean) { + this.isRainEnabled = isRainEnabled + return this + } + + getIsRainEnabled() { + return this.isRainEnabled + } + + setRainPercentage(rainPercentage: number) { + this.rainPercentage = rainPercentage + return this + } + + getRainPercentage() { + return this.rainPercentage + } + + setIsFogEnabled(isFogEnabled: boolean) { + this.isFogEnabled = isFogEnabled + return this + } + + getIsFogEnabled() { + return this.isFogEnabled + } + + setFogDensity(fogDensity: number) { + this.fogDensity = fogDensity + return this + } + + getFogDensity() { + return this.fogDensity + } +} diff --git a/src/entities/character.ts b/src/entities/character.ts index 054b632..ecb2266 100644 --- a/src/entities/character.ts +++ b/src/entities/character.ts @@ -1,297 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { CharacterEquipment } from './characterEquipment' -import { CharacterHair } from './characterHair' -import { CharacterItem } from './characterItem' -import { CharacterType } from './characterType' -import { Chat } from './chat' -import { Map } from './map' -import { User } from './user' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseCharacter } from '#entities/base/character' @Entity() -export class Character extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - user!: User - - @Property({ unique: true }) - name!: string - - @Property() - online = false - - @Property() - role = 'player' - - @OneToMany(() => Chat, (chat) => chat.character) - chats = new Collection(this) - - // Position - @TODO: Update to spawn point when current map is not found - @ManyToOne() - map!: Map - - @Property() - positionX = 0 - - @Property() - positionY = 0 - - @Property() - rotation = 0 - - // Customization - @ManyToOne({ deleteRule: 'set null' }) - characterType?: CharacterType | null | undefined - - @ManyToOne({ deleteRule: 'set null' }) - characterHair?: CharacterHair | null | undefined - - // Inventory - @OneToMany({ mappedBy: 'character' }) - items = new Collection(this) - - @OneToMany({ mappedBy: 'character' }) - equipment = new Collection(this) - - // Stats - @Property() - alignment = 50 - - @Property() - hitpoints = 100 - - @Property() - mana = 100 - - @Property() - level = 1 - - @Property() - experience = 0 - - @Property() - strength = 10 - - @Property() - dexterity = 10 - - @Property() - intelligence = 10 - - @Property() - wisdom = 10 - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setUser(user: User) { - this.user = user - return this - } - - getUser() { - return this.user - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setOnline(online: boolean) { - this.online = online - return this - } - - getOnline() { - return this.online - } - - setRole(role: string) { - this.role = role - return this - } - - getRole() { - return this.role - } - - setChats(chats: Collection) { - this.chats = chats - return this - } - - getChats() { - return this.chats - } - - setMap(map: Map) { - this.map = map - return this - } - - getMap() { - return this.map - } - - setPositionX(positionX: number) { - this.positionX = positionX - return this - } - - getPositionX() { - return this.positionX - } - - setPositionY(positionY: number) { - this.positionY = positionY - return this - } - - getPositionY() { - return this.positionY - } - - setRotation(rotation: number) { - this.rotation = rotation - return this - } - - getRotation() { - return this.rotation - } - - setCharacterType(characterType: CharacterType | null | undefined) { - this.characterType = characterType - return this - } - - getCharacterType() { - return this.characterType - } - - setCharacterHair(characterHair: CharacterHair | null | undefined) { - this.characterHair = characterHair - return this - } - - getCharacterHair() { - return this.characterHair - } - - setItems(items: Collection) { - this.items = items - return this - } - - getItems() { - return this.items - } - - setEquipment(equipment: Collection) { - this.equipment = equipment - return this - } - - getEquipment() { - return this.equipment - } - - setAlignment(alignment: number) { - this.alignment = alignment - return this - } - - getAlignment() { - return this.alignment - } - - setHitpoints(hitpoints: number) { - this.hitpoints = hitpoints - return this - } - - getHitpoints() { - return this.hitpoints - } - - setMana(mana: number) { - this.mana = mana - return this - } - - getMana() { - return this.mana - } - - setLevel(level: number) { - this.level = level - return this - } - - getLevel() { - return this.level - } - - setExperience(experience: number) { - this.experience = experience - return this - } - - getExperience() { - return this.experience - } - - setStrength(strength: number) { - this.strength = strength - return this - } - - getStrength() { - return this.strength - } - - setDexterity(dexterity: number) { - this.dexterity = dexterity - return this - } - - getDexterity() { - return this.dexterity - } - - setIntelligence(intelligence: number) { - this.intelligence = intelligence - return this - } - - getIntelligence() { - return this.intelligence - } - - setWisdom(wisdom: number) { - this.wisdom = wisdom - return this - } - - getWisdom() { - return this.wisdom - } -} +export class Character extends BaseCharacter {} diff --git a/src/entities/characterEquipment.ts b/src/entities/characterEquipment.ts index 5bb18ad..bc93994 100644 --- a/src/entities/characterEquipment.ts +++ b/src/entities/characterEquipment.ts @@ -1,61 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, Enum, ManyToOne, PrimaryKey } from '@mikro-orm/core' - -import { Character } from './character' -import { CharacterItem } from './characterItem' - -import { BaseEntity } from '#application/base/baseEntity' -import { CharacterEquipmentSlotType } from '#application/enums' -import { UUID } from '#application/types' +import { BaseCharacterEquipment } from '#entities/base/characterEquipment' @Entity() -export class CharacterEquipment extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Enum(() => CharacterEquipmentSlotType) - slot!: CharacterEquipmentSlotType - - @ManyToOne({ deleteRule: 'cascade' }) - character!: Character - - @ManyToOne({ deleteRule: 'cascade' }) - characterItem!: CharacterItem - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setSlot(slot: CharacterEquipmentSlotType) { - this.slot = slot - return this - } - - getSlot() { - return this.slot - } - - setCharacter(character: Character) { - this.character = character - return this - } - - getCharacter() { - return this.character - } - - setCharacterItem(characterItem: CharacterItem) { - this.characterItem = characterItem - return this - } - - getCharacterItem() { - return this.characterItem - } -} +export class CharacterEquipment extends BaseCharacterEquipment {} diff --git a/src/entities/characterHair.ts b/src/entities/characterHair.ts index 5c371c1..e177819 100644 --- a/src/entities/characterHair.ts +++ b/src/entities/characterHair.ts @@ -1,73 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { Character } from './character' -import { Sprite } from './sprite' - -import { BaseEntity } from '#application/base/baseEntity' -import { CharacterGender } from '#application/enums' -import { UUID } from '#application/types' +import { BaseCharacterHair } from '#entities/base/characterHair' @Entity() -export class CharacterHair extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @Property() - gender: CharacterGender = CharacterGender.MALE - - @Property() - isSelectable = false - - @ManyToOne() - sprite?: Sprite - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setGender(gender: CharacterGender) { - this.gender = gender - return this - } - - getGender() { - return this.gender - } - - setIsSelectable(isSelectable: boolean) { - this.isSelectable = isSelectable - return this - } - - getIsSelectable() { - return this.isSelectable - } - - setSprite(sprite: Sprite) { - this.sprite = sprite - return this - } - - getSprite() { - return this.sprite - } -} +export class CharacterHair extends BaseCharacterHair {} diff --git a/src/entities/characterItem.ts b/src/entities/characterItem.ts index 437a943..8548117 100644 --- a/src/entities/characterItem.ts +++ b/src/entities/characterItem.ts @@ -1,61 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { Character } from './character' -import { CharacterEquipment } from './characterEquipment' -import { Item } from './item' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseCharacterItem } from '#entities/base/characterItem' @Entity() -export class CharacterItem extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - character!: Character - - @ManyToOne({ deleteRule: 'cascade' }) - item!: Item - - @Property() - quantity!: number - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setCharacter(character: Character) { - this.character = character - return this - } - - getCharacter() { - return this.character - } - - setItem(item: Item) { - this.item = item - return this - } - - getItem() { - return this.item - } - - setQuantity(quantity: number) { - this.quantity = quantity - return this - } - - getQuantity() { - return this.quantity - } -} +export class CharacterItem extends BaseCharacterItem {} diff --git a/src/entities/characterType.ts b/src/entities/characterType.ts index 15b7ac2..0884ed1 100644 --- a/src/entities/characterType.ts +++ b/src/entities/characterType.ts @@ -1,109 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { Character } from './character' -import { Sprite } from './sprite' - -import { BaseEntity } from '#application/base/baseEntity' -import { CharacterGender, CharacterRace } from '#application/enums' -import { UUID } from '#application/types' +import { BaseCharacterType } from '#entities/base/characterType' @Entity() -export class CharacterType extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @Enum(() => CharacterGender) - gender!: CharacterGender - - @Enum(() => CharacterRace) - race!: CharacterRace - - @Property() - isSelectable = false - - @ManyToOne() - sprite?: Sprite - - @Property() - createdAt = new Date() - - @Property() - updatedAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setGender(gender: CharacterGender) { - this.gender = gender - return this - } - - getGender() { - return this.gender - } - - setRace(race: CharacterRace) { - this.race = race - return this - } - - getRace() { - return this.race - } - - setIsSelectable(isSelectable: boolean) { - this.isSelectable = isSelectable - return this - } - - getIsSelectable() { - return this.isSelectable - } - - setSprite(sprite: Sprite) { - this.sprite = sprite - return this - } - - getSprite() { - return this.sprite - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } - - setUpdatedAt(updatedAt: Date) { - this.updatedAt = updatedAt - return this - } - - getUpdatedAt() { - return this.updatedAt - } -} +export class CharacterType extends BaseCharacterType {} diff --git a/src/entities/chat.ts b/src/entities/chat.ts index 7417640..161f2ae 100644 --- a/src/entities/chat.ts +++ b/src/entities/chat.ts @@ -1,72 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' - -import { Character } from './character' -import { Map } from './map' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseChat } from '#entities/base/chat' @Entity() -export class Chat extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - character!: Character - - @ManyToOne({ deleteRule: 'cascade' }) - map!: Map - - @Property() - message!: string - - @Property() - createdAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setCharacter(character: Character) { - this.character = character - return this - } - - getCharacter() { - return this.character - } - - setMap(map: Map) { - this.map = map - return this - } - - getMap() { - return this.map - } - - setMessage(message: string) { - this.message = message - return this - } - - getMessage() { - return this.message - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } -} +export class Chat extends BaseChat {} diff --git a/src/entities/item.ts b/src/entities/item.ts index 1ec5aac..3f5a0f2 100644 --- a/src/entities/item.ts +++ b/src/entities/item.ts @@ -1,121 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { CharacterItem } from './characterItem' -import { Sprite } from './sprite' - -import { BaseEntity } from '#application/base/baseEntity' -import { ItemType, ItemRarity } from '#application/enums' -import { UUID } from '#application/types' +import { BaseItem } from '#entities/base/item' @Entity() -export class Item extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @Property() - description: string = '' - - @Enum(() => ItemType) - itemType!: ItemType - - @Property() - stackable = false - - @Enum(() => ItemRarity) - rarity: ItemRarity = ItemRarity.COMMON - - @ManyToOne(() => Sprite) - sprite?: Sprite - - @Property() - createdAt = new Date() - - @Property() - updatedAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setDescription(description: string) { - this.description = description - return this - } - - getDescription() { - return this.description - } - - setItemType(itemType: ItemType) { - this.itemType = itemType - return this - } - - getItemType() { - return this.itemType - } - - setStackable(stackable: boolean) { - this.stackable = stackable - return this - } - - getStackable() { - return this.stackable - } - - setRarity(rarity: ItemRarity) { - this.rarity = rarity - return this - } - - getRarity() { - return this.rarity - } - - setSprite(sprite: Sprite) { - this.sprite = sprite - return this - } - - getSprite() { - return this.sprite - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } - - setUpdatedAt(updatedAt: Date) { - this.updatedAt = updatedAt - return this - } - - getUpdatedAt() { - return this.updatedAt - } -} +export class Item extends BaseItem {} diff --git a/src/entities/map.ts b/src/entities/map.ts index 4608c3b..aba9d82 100644 --- a/src/entities/map.ts +++ b/src/entities/map.ts @@ -1,145 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { MapEffect } from './mapEffect' -import { MapEventTile } from './mapEventTile' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' -import { PlacedMapObject } from '#entities/placedMapObject' +import { BaseMap } from '#entities/base/map' @Entity() -export class Map extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @Property() - width = 10 - - @Property() - height = 10 - - @Property({ type: 'json', nullable: true }) - tiles?: any - - @Property() - pvp = false - - @Property() - createdAt = new Date() - - @Property() - updatedAt = new Date() - - @OneToMany(() => MapEffect, (effect) => effect.map, { orphanRemoval: true }) - mapEffects = new Collection(this) - - @OneToMany(() => MapEventTile, (tile) => tile.map, { orphanRemoval: true }) - mapEventTiles = new Collection(this) - - @OneToMany(() => PlacedMapObject, (placedMapObject) => placedMapObject.map, { orphanRemoval: true }) - placedMapObjects = new Collection(this) - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setWidth(width: number) { - this.width = width - return this - } - - getWidth() { - return this.width - } - - setHeight(height: number) { - this.height = height - return this - } - - getHeight() { - return this.height - } - - setTiles(tiles: any) { - this.tiles = tiles - return this - } - - getTiles() { - return this.tiles - } - - setPvp(pvp: boolean) { - this.pvp = pvp - return this - } - - getPvp() { - return this.pvp - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } - - setUpdatedAt(updatedAt: Date) { - this.updatedAt = updatedAt - return this - } - - getUpdatedAt() { - return this.updatedAt - } - - setMapEffects(mapEffects: Collection) { - this.mapEffects = mapEffects - return this - } - - getMapEffects() { - return this.mapEffects - } - - setMapEventTiles(mapEventTiles: Collection) { - this.mapEventTiles = mapEventTiles - return this - } - - getMapEventTiles() { - return this.mapEventTiles - } - - setPlacedMapObjects(placedMapObjects: Collection) { - this.placedMapObjects = placedMapObjects - return this - } - - getPlacedMapObjects() { - return this.placedMapObjects - } -} +export class Map extends BaseMap {} diff --git a/src/entities/mapEffect.ts b/src/entities/mapEffect.ts index 73ad517..0843fcb 100644 --- a/src/entities/mapEffect.ts +++ b/src/entities/mapEffect.ts @@ -1,59 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' - -import { Map } from './map' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseMapEffect } from '#entities/base/mapEffect' @Entity() -export class MapEffect extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - map!: Map - - @Property() - effect!: string - - @Property() - strength!: number - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setMap(map: Map) { - this.map = map - return this - } - - getMap() { - return this.map - } - - setEffect(effect: string) { - this.effect = effect - return this - } - - getEffect() { - return this.effect - } - - setStrength(strength: number) { - this.strength = strength - return this - } - - getStrength() { - return this.strength - } -} +export class MapEffect extends BaseMapEffect {} diff --git a/src/entities/mapEventTile.ts b/src/entities/mapEventTile.ts index 100b1b6..a758db4 100644 --- a/src/entities/mapEventTile.ts +++ b/src/entities/mapEventTile.ts @@ -1,85 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core' - -import { Map } from './map' -import { MapEventTileTeleport } from './mapEventTileTeleport' - -import { BaseEntity } from '#application/base/baseEntity' -import { MapEventTileType } from '#application/enums' -import { UUID } from '#application/types' +import { BaseMapEventTile } from '#entities/base/mapEventTile' @Entity() -export class MapEventTile extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - map!: Map - - @Enum(() => MapEventTileType) - type!: MapEventTileType - - @Property() - positionX!: number - - @Property() - positionY!: number - - @OneToOne(() => MapEventTileTeleport, (teleport) => teleport.mapEventTile, { eager: true }) - teleport?: MapEventTileTeleport - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setMap(map: Map) { - this.map = map - return this - } - - getMap() { - return this.map - } - - setType(type: MapEventTileType) { - this.type = type - return this - } - - getType() { - return this.type - } - - setPositionX(positionX: number) { - this.positionX = positionX - return this - } - - getPositionX() { - return this.positionX - } - - setPositionY(positionY: number) { - this.positionY = positionY - return this - } - - getPositionY() { - return this.positionY - } - - setTeleport(teleport: MapEventTileTeleport) { - this.teleport = teleport - return this - } - - getTeleport() { - return this.teleport - } -} +export class MapEventTile extends BaseMapEventTile {} diff --git a/src/entities/mapEventTileTeleport.ts b/src/entities/mapEventTileTeleport.ts index 7cfbf8d..ce9b2e1 100644 --- a/src/entities/mapEventTileTeleport.ts +++ b/src/entities/mapEventTileTeleport.ts @@ -1,84 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core' - -import { Map } from './map' -import { MapEventTile } from './mapEventTile' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseMapEventTileTeleport } from '#entities/base/mapEventTileTeleport' @Entity() -export class MapEventTileTeleport extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @OneToOne({ deleteRule: 'cascade' }) - mapEventTile!: MapEventTile - - @ManyToOne({ deleteRule: 'cascade', eager: true }) - toMap!: Map - - @Property() - toRotation!: number - - @Property() - toPositionX!: number - - @Property() - toPositionY!: number - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setMapEventTile(mapEventTile: MapEventTile) { - this.mapEventTile = mapEventTile - return this - } - - getMapEventTile() { - return this.mapEventTile - } - - setToMap(toMap: Map) { - this.toMap = toMap - return this - } - - getToMap() { - return this.toMap - } - - setToRotation(toRotation: number) { - this.toRotation = toRotation - return this - } - - getToRotation() { - return this.toRotation - } - - setToPositionX(toPositionX: number) { - this.toPositionX = toPositionX - return this - } - - getToPositionX() { - return this.toPositionX - } - - setToPositionY(toPositionY: number) { - this.toPositionY = toPositionY - return this - } - - getToPositionY() { - return this.toPositionY - } -} +export class MapEventTileTeleport extends BaseMapEventTileTeleport {} diff --git a/src/entities/mapObject.ts b/src/entities/mapObject.ts index 3debba2..4110afd 100644 --- a/src/entities/mapObject.ts +++ b/src/entities/mapObject.ts @@ -1,141 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, PrimaryKey, Property } from '@mikro-orm/core' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseMapObject } from '#entities/base/mapObject' @Entity() -export class MapObject extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @Property({ type: 'json', nullable: true }) - tags?: any - - @Property({ type: 'decimal', precision: 10, scale: 2 }) - originX = 0 - - @Property({ type: 'decimal', precision: 10, scale: 2 }) - originY = 0 - - @Property() - isAnimated = false - - @Property() - frameRate = 0 - - @Property() - frameWidth = 0 - - @Property() - frameHeight = 0 - - @Property() - createdAt = new Date() - - @Property() - updatedAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setTags(tags: any) { - this.tags = tags - return this - } - - getTags() { - return this.tags - } - - setOriginX(originX: number) { - this.originX = originX - return this - } - - getOriginX() { - return this.originX - } - - setOriginY(originY: number) { - this.originY = originY - return this - } - - getOriginY() { - return this.originY - } - - setIsAnimated(isAnimated: boolean) { - this.isAnimated = isAnimated - return this - } - - getIsAnimated() { - return this.isAnimated - } - - setFrameRate(frameRate: number) { - this.frameRate = frameRate - return this - } - - getFrameRate() { - return this.frameRate - } - - setFrameWidth(frameWidth: number) { - this.frameWidth = frameWidth - return this - } - - getFrameWidth() { - return this.frameWidth - } - - setFrameHeight(frameHeight: number) { - this.frameHeight = frameHeight - return this - } - - getFrameHeight() { - return this.frameHeight - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } - - setUpdatedAt(updatedAt: Date) { - this.updatedAt = updatedAt - return this - } - - getUpdatedAt() { - return this.updatedAt - } -} +export class MapObject extends BaseMapObject {} diff --git a/src/entities/passwordResetToken.ts b/src/entities/passwordResetToken.ts index 774faca..a493cd8 100644 --- a/src/entities/passwordResetToken.ts +++ b/src/entities/passwordResetToken.ts @@ -1,59 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' - -import { User } from './user' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BasePasswordResetToken } from '#entities/base/passwordResetToken' @Entity() -export class PasswordResetToken extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - user!: User - - @Property({ unique: true }) - token!: string - - @Property() - createdAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setUser(user: User) { - this.user = user - return this - } - - getUser() { - return this.user - } - - setToken(token: string) { - this.token = token - return this - } - - getToken() { - return this.token - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } -} +export class PasswordResetToken extends BasePasswordResetToken {} diff --git a/src/entities/placedMapObject.ts b/src/entities/placedMapObject.ts index 4fa0cef..af6e1eb 100644 --- a/src/entities/placedMapObject.ts +++ b/src/entities/placedMapObject.ts @@ -1,97 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' +import { BasePlacedMapObject } from '#entities/base/placedMapObject' -import { Map } from './map' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' -import { MapObject } from '#entities/mapObject' - -//@TODO : Rename mapObject @Entity() -export class PlacedMapObject extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - map!: Map - - @ManyToOne({ deleteRule: 'cascade', eager: true }) - mapObject!: MapObject - - @Property() - depth = 0 - - @Property() - isRotated = false - - @Property() - positionX = 0 - - @Property() - positionY = 0 - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setMap(map: Map) { - this.map = map - return this - } - - getMap() { - return this.map - } - - setMapObject(mapObject: MapObject) { - this.mapObject = mapObject - return this - } - - getMapObject() { - return this.mapObject - } - - setDepth(depth: number) { - this.depth = depth - return this - } - - getDepth() { - return this.depth - } - - setIsRotated(isRotated: boolean) { - this.isRotated = isRotated - return this - } - - getIsRotated() { - return this.isRotated - } - - setPositionX(positionX: number) { - this.positionX = positionX - return this - } - - getPositionX() { - return this.positionX - } - - setPositionY(positionY: number) { - this.positionY = positionY - return this - } - - getPositionY() { - return this.positionY - } -} +export class PlacedMapObject extends BasePlacedMapObject {} diff --git a/src/entities/sprite.ts b/src/entities/sprite.ts index 5e2ca67..7b1ab3a 100644 --- a/src/entities/sprite.ts +++ b/src/entities/sprite.ts @@ -1,71 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' - -import { SpriteAction } from './spriteAction' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseSprite } from '#entities/base/sprite' @Entity() -export class Sprite extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @OneToMany(() => SpriteAction, (action) => action.sprite) - spriteActions = new Collection(this) - - @Property() - createdAt = new Date() - - @Property() - updatedAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setSpriteActions(spriteActions: Collection) { - this.spriteActions = spriteActions - return this - } - - getSpriteActions() { - return this.spriteActions - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } - - setUpdatedAt(updatedAt: Date) { - this.updatedAt = updatedAt - return this - } - - getUpdatedAt() { - return this.updatedAt - } -} +export class Sprite extends BaseSprite {} diff --git a/src/entities/spriteAction.ts b/src/entities/spriteAction.ts index cd7c7fb..d615344 100644 --- a/src/entities/spriteAction.ts +++ b/src/entities/spriteAction.ts @@ -1,143 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' - -import { Sprite } from './sprite' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseSpriteAction } from '#entities/base/spriteAction' @Entity() -export class SpriteAction extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @ManyToOne({ deleteRule: 'cascade' }) - sprite!: Sprite - - @Property() - action!: string - - @Property({ type: 'json', nullable: true }) - sprites?: string[] - - @Property() - originX = 0 - - @Property() - originY = 0 - - @Property() - isAnimated = false - - @Property() - isLooping = false - - @Property() - frameWidth = 0 - - @Property() - frameHeight = 0 - - @Property() - frameRate = 0 - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setSprite(sprite: Sprite) { - this.sprite = sprite - return this - } - - getSprite() { - return this.sprite - } - - setAction(action: string) { - this.action = action - return this - } - - getAction() { - return this.action - } - - setSprites(sprites: string[]) { - this.sprites = sprites - return this - } - - getSprites() { - return this.sprites - } - - setOriginX(originX: number) { - this.originX = originX - return this - } - - getOriginX() { - return this.originX - } - - setOriginY(originY: number) { - this.originY = originY - return this - } - - getOriginY() { - return this.originY - } - - setIsAnimated(isAnimated: boolean) { - this.isAnimated = isAnimated - return this - } - - getIsAnimated() { - return this.isAnimated - } - - setIsLooping(isLooping: boolean) { - this.isLooping = isLooping - return this - } - - getIsLooping() { - return this.isLooping - } - - setFrameWidth(frameWidth: number) { - this.frameWidth = frameWidth - return this - } - - getFrameWidth() { - return this.frameWidth - } - - setFrameHeight(frameHeight: number) { - this.frameHeight = frameHeight - return this - } - - getFrameHeight() { - return this.frameHeight - } - - setFrameRate(frameRate: number) { - this.frameRate = frameRate - return this - } - - getFrameRate() { - return this.frameRate - } -} +export class SpriteAction extends BaseSpriteAction {} diff --git a/src/entities/tile.ts b/src/entities/tile.ts index e48853a..9330748 100644 --- a/src/entities/tile.ts +++ b/src/entities/tile.ts @@ -1,69 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Entity, PrimaryKey, Property } from '@mikro-orm/core' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseTile } from '#entities/base/tile' @Entity() -export class Tile extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property() - name!: string - - @Property({ type: 'json', nullable: true }) - tags?: any - - @Property() - createdAt = new Date() - - @Property() - updatedAt = new Date() - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setName(name: string) { - this.name = name - return this - } - - getName() { - return this.name - } - - setTags(tags: any) { - this.tags = tags - return this - } - - getTags() { - return this.tags - } - - setCreatedAt(createdAt: Date) { - this.createdAt = createdAt - return this - } - - getCreatedAt() { - return this.createdAt - } - - setUpdatedAt(updatedAt: Date) { - this.updatedAt = updatedAt - return this - } - - getUpdatedAt() { - return this.updatedAt - } -} +export class Tile extends BaseTile {} diff --git a/src/entities/user.ts b/src/entities/user.ts index 0da3691..d71995c 100644 --- a/src/entities/user.ts +++ b/src/entities/user.ts @@ -1,98 +1,6 @@ -import { randomUUID } from 'node:crypto' +import { Entity } from '@mikro-orm/core' -import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' -import bcrypt from 'bcryptjs' - -import { Character } from './character' -import { PasswordResetToken } from './passwordResetToken' - -import { BaseEntity } from '#application/base/baseEntity' -import { UUID } from '#application/types' +import { BaseUser } from '#entities/base/user' @Entity() -export class User extends BaseEntity { - @PrimaryKey() - id = randomUUID() - - @Property({ unique: true }) - username!: string - - @Property({ unique: true }) - email!: string - - @Property() - password!: string - - @Property() - online = false - - @OneToMany(() => Character, (character) => character.user) - characters = new Collection(this) - - @OneToMany(() => PasswordResetToken, (token) => token.user) - passwordResetTokens = new Collection(this) - - setId(id: UUID) { - this.id = id - return this - } - - getId() { - return this.id - } - - setUsername(username: string) { - this.username = username - return this - } - - getUsername() { - return this.username - } - - setEmail(email: string) { - this.email = email - return this - } - - getEmail() { - return this.email - } - - setPassword(password: string) { - this.password = bcrypt.hashSync(password, 10) - return this - } - - getPassword() { - return this.password - } - - setOnline(online: boolean) { - this.online = online - return this - } - - getOnline() { - return this.online - } - - setCharacters(characters: Collection) { - this.characters = characters - return this - } - - getCharacters() { - return this.characters - } - - setPasswordResetTokens(passwordResetTokens: Collection) { - this.passwordResetTokens = passwordResetTokens - return this - } - - getPasswordResetTokens() { - return this.passwordResetTokens - return this - } -} +export class User extends BaseUser {} diff --git a/src/entities/world.ts b/src/entities/world.ts index 33f38ee..a936e44 100644 --- a/src/entities/world.ts +++ b/src/entities/world.ts @@ -1,66 +1,6 @@ -import { Entity, PrimaryKey, Property } from '@mikro-orm/core' +import { Entity } from '@mikro-orm/core' -import { BaseEntity } from '#application/base/baseEntity' +import { BaseWorld } from '#entities/base/world' @Entity() -export class World extends BaseEntity { - @PrimaryKey() - date = new Date() - - @Property() - isRainEnabled = false - - @Property() - rainPercentage = 0 - - @Property() - isFogEnabled = false - - @Property() - fogDensity = 0 - - setDate(date: Date) { - this.date = date - return this - } - - getDate() { - return this.date - } - - setIsRainEnabled(isRainEnabled: boolean) { - this.isRainEnabled = isRainEnabled - return this - } - - getIsRainEnabled() { - return this.isRainEnabled - } - - setRainPercentage(rainPercentage: number) { - this.rainPercentage = rainPercentage - return this - } - - getRainPercentage() { - return this.rainPercentage - } - - setIsFogEnabled(isFogEnabled: boolean) { - this.isFogEnabled = isFogEnabled - return this - } - - getIsFogEnabled() { - return this.isFogEnabled - } - - setFogDensity(fogDensity: number) { - this.fogDensity = fogDensity - return this - } - - getFogDensity() { - return this.fogDensity - } -} +export class World extends BaseWorld {} diff --git a/src/services/teleportService.ts b/src/services/teleportService.ts index 6e2686b..1a64982 100644 --- a/src/services/teleportService.ts +++ b/src/services/teleportService.ts @@ -56,7 +56,13 @@ class TeleportService { } // Update character position and map - await mapCharacter.getCharacter().setPositionX(options.targetX).setPositionY(options.targetY).setRotation(options.rotation ?? 0).setMap(targetMap.getMap()).save() + await mapCharacter + .getCharacter() + .setPositionX(options.targetX) + .setPositionY(options.targetY) + .setRotation(options.rotation ?? 0) + .setMap(targetMap.getMap()) + .save() // Join new map socket.join(options.targetMapId)