npm run format

This commit is contained in:
Dennis Postma 2024-12-25 02:06:58 +01:00
parent c35e27799e
commit b4989aac26
28 changed files with 252 additions and 243 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,84 +1,84 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { User } from './user'; import { User } from './user'
import { Zone } from './zone'; import { Zone } from './zone'
import { CharacterType } from './characterType'; import { CharacterType } from './characterType'
import { CharacterHair } from './characterHair'; import { CharacterHair } from './characterHair'
import { CharacterItem } from './characterItem'; import { CharacterItem } from './characterItem'
import { CharacterEquipment } from './characterEquipment'; import { CharacterEquipment } from './characterEquipment'
import { Chat } from './chat'; import { Chat } from './chat'
@Entity() @Entity()
export class Character { export class Character {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@ManyToOne(() => User) @ManyToOne(() => User)
user!: User; user!: User
@Property({ unique: true }) @Property({ unique: true })
name!: string; name!: string
@Property() @Property()
online = false; online = false
@Property() @Property()
role = 'player'; role = 'player'
@OneToMany(() => Chat, chat => chat.character) @OneToMany(() => Chat, (chat) => chat.character)
chats = new Collection<Chat>(this); chats = new Collection<Chat>(this)
// Position // Position
@ManyToOne(() => Zone) @ManyToOne(() => Zone)
zone!: Zone; zone!: Zone
@Property() @Property()
positionX = 0; positionX = 0
@Property() @Property()
positionY = 0; positionY = 0
@Property() @Property()
rotation = 0; rotation = 0
// Customization // Customization
@ManyToOne(() => CharacterType, { nullable: true }) @ManyToOne(() => CharacterType, { nullable: true })
characterType?: CharacterType; characterType?: CharacterType
@ManyToOne(() => CharacterHair, { nullable: true }) @ManyToOne(() => CharacterHair, { nullable: true })
characterHair?: CharacterHair; characterHair?: CharacterHair
// Inventory // Inventory
@OneToMany(() => CharacterItem, item => item.character) @OneToMany(() => CharacterItem, (item) => item.character)
items = new Collection<CharacterItem>(this); items = new Collection<CharacterItem>(this)
@OneToMany(() => CharacterEquipment, equipment => equipment.character) @OneToMany(() => CharacterEquipment, (equipment) => equipment.character)
equipment = new Collection<CharacterEquipment>(this); equipment = new Collection<CharacterEquipment>(this)
// Stats // Stats
@Property() @Property()
alignment = 50; alignment = 50
@Property() @Property()
hitpoints = 100; hitpoints = 100
@Property() @Property()
mana = 100; mana = 100
@Property() @Property()
level = 1; level = 1
@Property() @Property()
experience = 0; experience = 0
@Property() @Property()
strength = 10; strength = 10
@Property() @Property()
dexterity = 10; dexterity = 10
@Property() @Property()
intelligence = 10; intelligence = 10
@Property() @Property()
wisdom = 10; wisdom = 10
} }

View File

@ -1,19 +1,19 @@
import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core' import { Entity, Enum, ManyToOne, PrimaryKey } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { CharacterItem } from './characterItem'; import { CharacterItem } from './characterItem'
import { CharacterEquipmentSlotType } from '#utilities/enums'; import { CharacterEquipmentSlotType } from '#utilities/enums'
@Entity() @Entity()
export class CharacterEquipment { export class CharacterEquipment {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@Enum(() => CharacterEquipmentSlotType) @Enum(() => CharacterEquipmentSlotType)
slot!: CharacterEquipmentSlotType; slot!: CharacterEquipmentSlotType
@ManyToOne(() => Character) @ManyToOne(() => Character)
character!: Character; character!: Character
@ManyToOne(() => CharacterItem) @ManyToOne(() => CharacterItem)
characterItem!: CharacterItem; characterItem!: CharacterItem
} }

View File

@ -1,25 +1,25 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { Sprite } from './sprite'; import { Sprite } from './sprite'
import { CharacterGender } from '#utilities/enums'; import { CharacterGender } from '#utilities/enums'
@Entity() @Entity()
export class CharacterHair { export class CharacterHair {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@Property() @Property()
name!: string; name!: string
@Property() @Property()
gender: CharacterGender = CharacterGender.MALE; gender: CharacterGender = CharacterGender.MALE
@Property() @Property()
isSelectable = false; isSelectable = false
@ManyToOne(() => Sprite, { nullable: true }) @ManyToOne(() => Sprite, { nullable: true })
sprite?: Sprite; sprite?: Sprite
@OneToMany(() => Character, character => character.characterHair) @OneToMany(() => Character, (character) => character.characterHair)
characters = new Collection<Character>(this); characters = new Collection<Character>(this)
} }

View File

@ -1,22 +1,22 @@
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { Item } from './item'; import { Item } from './item'
import { CharacterEquipment } from './characterEquipment'; import { CharacterEquipment } from './characterEquipment'
@Entity() @Entity()
export class CharacterItem { export class CharacterItem {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@ManyToOne(() => Character) @ManyToOne(() => Character)
character!: Character; character!: Character
@ManyToOne(() => Item) @ManyToOne(() => Item)
item!: Item; item!: Item
@Property() @Property()
quantity!: number; quantity!: number
@OneToMany(() => CharacterEquipment, equipment => equipment.characterItem) @OneToMany(() => CharacterEquipment, (equipment) => equipment.characterItem)
characterEquipment = new Collection<CharacterEquipment>(this); characterEquipment = new Collection<CharacterEquipment>(this)
} }

View File

@ -1,34 +1,34 @@
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { Sprite } from './sprite'; import { Sprite } from './sprite'
import { CharacterGender, CharacterRace } from '#utilities/enums'; import { CharacterGender, CharacterRace } from '#utilities/enums'
@Entity() @Entity()
export class CharacterType { export class CharacterType {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@Property() @Property()
name!: string; name!: string
@Enum(() => CharacterGender) @Enum(() => CharacterGender)
gender!: CharacterGender; gender!: CharacterGender
@Enum(() => CharacterRace) @Enum(() => CharacterRace)
race!: CharacterRace; race!: CharacterRace
@Property() @Property()
isSelectable = false; isSelectable = false
@OneToMany(() => Character, character => character.characterType) @OneToMany(() => Character, (character) => character.characterType)
characters = new Collection<Character>(this); characters = new Collection<Character>(this)
@ManyToOne(() => Sprite, { nullable: true }) @ManyToOne(() => Sprite, { nullable: true })
sprite?: Sprite; sprite?: Sprite
@Property() @Property()
createdAt = new Date(); createdAt = new Date()
@Property() @Property()
updatedAt = new Date(); updatedAt = new Date()
} }

View File

@ -1,21 +1,21 @@
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { Zone } from './zone'; import { Zone } from './zone'
@Entity() @Entity()
export class Chat { export class Chat {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@ManyToOne(() => Character) @ManyToOne(() => Character)
character!: Character; character!: Character
@ManyToOne(() => Zone) @ManyToOne(() => Zone)
zone!: Zone; zone!: Zone
@Property() @Property()
message!: string; message!: string
@Property() @Property()
createdAt = new Date(); createdAt = new Date()
} }

View File

@ -1,37 +1,37 @@
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core' import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { Sprite } from './sprite'; import { Sprite } from './sprite'
import { CharacterItem } from './characterItem'; import { CharacterItem } from './characterItem'
import { ItemType, ItemRarity } from '#utilities/enums'; import { ItemType, ItemRarity } from '#utilities/enums'
@Entity() @Entity()
export class Item { export class Item {
@PrimaryKey() @PrimaryKey()
id!: string; id!: string
@Property() @Property()
name!: string; name!: string
@Property({ nullable: true }) @Property({ nullable: true })
description?: string; description?: string
@Enum(() => ItemType) @Enum(() => ItemType)
itemType!: ItemType; itemType!: ItemType
@Property() @Property()
stackable = false; stackable = false
@Enum(() => ItemRarity) @Enum(() => ItemRarity)
rarity: ItemRarity = ItemRarity.COMMON; rarity: ItemRarity = ItemRarity.COMMON
@ManyToOne(() => Sprite, { nullable: true }) @ManyToOne(() => Sprite, { nullable: true })
sprite?: Sprite; sprite?: Sprite
@Property() @Property()
createdAt = new Date(); createdAt = new Date()
@Property() @Property()
updatedAt = new Date(); updatedAt = new Date()
@OneToMany(() => CharacterItem, characterItem => characterItem.item) @OneToMany(() => CharacterItem, (characterItem) => characterItem.item)
characters = new Collection<CharacterItem>(this); characters = new Collection<CharacterItem>(this)
} }

View File

@ -1,17 +1,17 @@
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
import { User } from './user'; import { User } from './user'
@Entity() @Entity()
export class PasswordResetToken { export class PasswordResetToken {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@ManyToOne(() => User) @ManyToOne(() => User)
user!: User; user!: User
@Property({ unique: true }) @Property({ unique: true })
token!: string; token!: string
@Property() @Property()
createdAt = new Date(); createdAt = new Date()
} }

View File

@ -1,33 +1,33 @@
import { randomUUID } from 'node:crypto'; import { randomUUID } from 'node:crypto'
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { SpriteAction } from './spriteAction'; import { SpriteAction } from './spriteAction'
import { CharacterType } from './characterType'; import { CharacterType } from './characterType'
import { CharacterHair } from './characterHair'; import { CharacterHair } from './characterHair'
import { Item } from './item'; import { Item } from './item'
@Entity() @Entity()
export class Sprite { export class Sprite {
@PrimaryKey() @PrimaryKey()
id = randomUUID(); id = randomUUID()
@Property() @Property()
name!: string; name!: string
@Property() @Property()
createdAt = new Date(); createdAt = new Date()
@Property() @Property()
updatedAt = new Date(); updatedAt = new Date()
@OneToMany(() => SpriteAction, action => action.sprite) @OneToMany(() => SpriteAction, (action) => action.sprite)
spriteActions = new Collection<SpriteAction>(this); spriteActions = new Collection<SpriteAction>(this)
@OneToMany(() => CharacterType, type => type.sprite) @OneToMany(() => CharacterType, (type) => type.sprite)
characterTypes = new Collection<CharacterType>(this); characterTypes = new Collection<CharacterType>(this)
@OneToMany(() => CharacterHair, hair => hair.sprite) @OneToMany(() => CharacterHair, (hair) => hair.sprite)
characterHairs = new Collection<CharacterHair>(this); characterHairs = new Collection<CharacterHair>(this)
@OneToMany(() => Item, item => item.sprite) @OneToMany(() => Item, (item) => item.sprite)
items = new Collection<Item>(this); items = new Collection<Item>(this)
} }

View File

@ -1,39 +1,39 @@
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
import { Sprite } from './sprite'; import { Sprite } from './sprite'
@Entity() @Entity()
export class SpriteAction { export class SpriteAction {
@PrimaryKey() @PrimaryKey()
id = randomUUID(); id = randomUUID()
@ManyToOne(() => Sprite) @ManyToOne(() => Sprite)
sprite!: Sprite; sprite!: Sprite
@Property() @Property()
action!: string; action!: string
@Property({ type: 'json', nullable: true }) @Property({ type: 'json', nullable: true })
sprites?: any; sprites?: any
@Property() @Property()
originX = 0; originX = 0
@Property() @Property()
originY = 0; originY = 0
@Property() @Property()
isAnimated = false; isAnimated = false
@Property() @Property()
isLooping = false; isLooping = false
@Property() @Property()
frameWidth = 0; frameWidth = 0
@Property() @Property()
frameHeight = 0; frameHeight = 0
@Property() @Property()
frameRate = 0; frameRate = 0
} }

View File

@ -1,27 +1,27 @@
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { PasswordResetToken } from './passwordResetToken'; import { PasswordResetToken } from './passwordResetToken'
@Entity() @Entity()
export class User { export class User {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@Property({ unique: true }) @Property({ unique: true })
username!: string; username!: string
@Property({ unique: true }) @Property({ unique: true })
email!: string; email!: string
@Property() @Property()
password!: string; password!: string
@Property() @Property()
online = false; online = false
@OneToMany(() => Character, character => character.user) @OneToMany(() => Character, (character) => character.user)
characters = new Collection<Character>(this); characters = new Collection<Character>(this)
@OneToMany(() => PasswordResetToken, token => token.user) @OneToMany(() => PasswordResetToken, (token) => token.user)
passwordResetTokens = new Collection<PasswordResetToken>(this); passwordResetTokens = new Collection<PasswordResetToken>(this)
} }

View File

@ -1,19 +1,19 @@
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'; import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
@Entity() @Entity()
export class World { export class World {
@PrimaryKey() @PrimaryKey()
date = new Date(); date = new Date()
@Property() @Property()
isRainEnabled = false; isRainEnabled = false
@Property() @Property()
rainPercentage = 0; rainPercentage = 0
@Property() @Property()
isFogEnabled = false; isFogEnabled = false
@Property() @Property()
fogDensity = 0; fogDensity = 0
} }

View File

@ -1,15 +1,15 @@
import { Collection, Entity, OneToMany, PrimaryKey } from '@mikro-orm/core'; import { Collection, Entity, OneToMany, PrimaryKey } from '@mikro-orm/core'
import { Character } from './character'; import { Character } from './character'
import { Chat } from './chat'; import { Chat } from './chat'
@Entity() @Entity()
export class Zone { export class Zone {
@PrimaryKey() @PrimaryKey()
id!: number; id!: number
@OneToMany(() => Character, character => character.zone) @OneToMany(() => Character, (character) => character.zone)
characters = new Collection<Character>(this); characters = new Collection<Character>(this)
@OneToMany(() => Chat, chat => chat.zone) @OneToMany(() => Chat, (chat) => chat.zone)
chats = new Collection<Chat>(this); chats = new Collection<Chat>(this)
} }

View File

@ -40,13 +40,15 @@ async function generateAvatar(res: Response, options: AvatarOptions) {
if (characterHair?.spriteId) { if (characterHair?.spriteId) {
const hairSpritePath = getPublicPath('sprites', characterHair.spriteId, 'front.png') const hairSpritePath = getPublicPath('sprites', characterHair.spriteId, 'front.png')
if (fs.existsSync(hairSpritePath)) { if (fs.existsSync(hairSpritePath)) {
avatar = avatar.composite([{ avatar = avatar.composite([
{
input: hairSpritePath, input: hairSpritePath,
gravity: 'north', gravity: 'north'
// Top is originY in min @TODO finish me #287 // Top is originY in min @TODO finish me #287
// top: Math.round(Number(characterHair.sprite!.spriteActions.find((action) => action.action === 'front')?.originY ?? 0)), // top: Math.round(Number(characterHair.sprite!.spriteActions.find((action) => action.action === 'front')?.originY ?? 0)),
// left: 0 // left: 0
}]) }
])
} else { } else {
console.error(`Hair sprite file not found: ${hairSpritePath}`) console.error(`Hair sprite file not found: ${hairSpritePath}`)
} }

View File

@ -23,7 +23,7 @@ class CharacterRepository {
} }
} }
} }
}, }
} }
}) })
} catch (error: any) { } catch (error: any) {

View File

@ -1,8 +1,6 @@
import prisma from '#utilities/prisma' import prisma from '#utilities/prisma'
import { gameLogger } from '#utilities/logger' import { gameLogger } from '#utilities/logger'
class ZoneService { class ZoneService {}
}
export default ZoneService export default ZoneService

View File

@ -40,7 +40,7 @@ export default class SpriteCopyEvent {
data: { data: {
name: `${sourceSprite.name} (Copy)`, name: `${sourceSprite.name} (Copy)`,
spriteActions: { spriteActions: {
create: sourceSprite.spriteActions.map(action => ({ create: sourceSprite.spriteActions.map((action) => ({
action: action.action, action: action.action,
sprites: action.sprites as Prisma.InputJsonValue, sprites: action.sprites as Prisma.InputJsonValue,
originX: action.originX, originX: action.originX,

View File

@ -78,7 +78,8 @@ export default class SpriteUpdateEvent {
const parsedActions = this.validateSpriteActions(payload.spriteActions) const parsedActions = this.validateSpriteActions(payload.spriteActions)
// Process sprites // Process sprites
const processedActions = await Promise.all(parsedActions.map(async (action) => { const processedActions = await Promise.all(
parsedActions.map(async (action) => {
const spriteBuffers = await this.convertBase64ToBuffers(action.sprites) const spriteBuffers = await this.convertBase64ToBuffers(action.sprites)
const frameWidth = ISOMETRIC_CONFIG.tileWidth const frameWidth = ISOMETRIC_CONFIG.tileWidth
const frameHeight = await this.calculateOptimalHeight(spriteBuffers) const frameHeight = await this.calculateOptimalHeight(spriteBuffers)
@ -90,11 +91,15 @@ export default class SpriteUpdateEvent {
frameHeight, frameHeight,
buffersWithDimensions: processedFrames buffersWithDimensions: processedFrames
} }
})) })
)
await Promise.all([ await Promise.all([
this.updateDatabase(payload.id, payload.name, processedActions), this.updateDatabase(payload.id, payload.name, processedActions),
this.saveSpritesToDisk(payload.id, processedActions.filter(a => a.buffersWithDimensions.length > 0)) this.saveSpritesToDisk(
payload.id,
processedActions.filter((a) => a.buffersWithDimensions.length > 0)
)
]) ])
callback(true) callback(true)