Created base entities, extended normal entities with these

This commit is contained in:
2025-01-06 18:03:12 +01:00
parent be9ee97385
commit 24586855cb
42 changed files with 2006 additions and 1858 deletions

View File

@ -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<Chat>(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<CharacterItem>(this)
@OneToMany({ mappedBy: 'character' })
equipment = new Collection<CharacterEquipment>(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<Chat>) {
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<CharacterItem>) {
this.items = items
return this
}
getItems() {
return this.items
}
setEquipment(equipment: Collection<CharacterEquipment>) {
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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

71
src/entities/base/chat.ts Normal file
View File

@ -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
}
}

120
src/entities/base/item.ts Normal file
View File

@ -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
}
}

143
src/entities/base/map.ts Normal file
View File

@ -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<MapEffect>(this)
@OneToMany(() => MapEventTile, (tile) => tile.map, { orphanRemoval: true })
mapEventTiles = new Collection<MapEventTile>(this)
@OneToMany(() => PlacedMapObject, (placedMapObject) => placedMapObject.map, { orphanRemoval: true })
placedMapObjects = new Collection<PlacedMapObject>(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<MapEffect>) {
this.mapEffects = mapEffects
return this
}
getMapEffects() {
return this.mapEffects
}
setMapEventTiles(mapEventTiles: Collection<MapEventTile>) {
this.mapEventTiles = mapEventTiles
return this
}
getMapEventTiles() {
return this.mapEventTiles
}
setPlacedMapObjects(placedMapObjects: Collection<PlacedMapObject>) {
this.placedMapObjects = placedMapObjects
return this
}
getPlacedMapObjects() {
return this.placedMapObjects
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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<SpriteAction>(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<SpriteAction>) {
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
}
}

View File

@ -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
}
}

68
src/entities/base/tile.ts Normal file
View File

@ -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
}
}

97
src/entities/base/user.ts Normal file
View File

@ -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<Character>(this)
@OneToMany(() => PasswordResetToken, (token) => token.user)
passwordResetTokens = new Collection<PasswordResetToken>(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<Character>) {
this.characters = characters
return this
}
getCharacters() {
return this.characters
}
setPasswordResetTokens(passwordResetTokens: Collection<PasswordResetToken>) {
this.passwordResetTokens = passwordResetTokens
return this
}
getPasswordResetTokens() {
return this.passwordResetTokens
return this
}
}

View File

@ -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
}
}