forked from noxious/server
127 lines
2.0 KiB
TypeScript
127 lines
2.0 KiB
TypeScript
import { randomUUID } from 'node:crypto'
|
|
|
|
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
|
|
|
import type { UUID } from '@/application/types'
|
|
import type { Sprite } from '@/entities/sprite'
|
|
|
|
import { BaseEntity } from '@/application/base/baseEntity'
|
|
|
|
export interface SpriteImage {
|
|
url: string
|
|
offset: {
|
|
x: number
|
|
y: number
|
|
}
|
|
}
|
|
|
|
export class BaseSpriteAction extends BaseEntity {
|
|
@PrimaryKey()
|
|
id = randomUUID()
|
|
|
|
@ManyToOne({ deleteRule: 'cascade' })
|
|
sprite!: Sprite
|
|
|
|
@Property()
|
|
action!: string
|
|
|
|
@Property({ type: 'json', nullable: true })
|
|
sprites?: SpriteImage[]
|
|
|
|
@Property({ type: 'decimal', precision: 5, scale: 2 })
|
|
originX = 0.0
|
|
|
|
@Property({ type: 'decimal', precision: 5, scale: 2 })
|
|
originY = 0.0
|
|
|
|
@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: SpriteImage[]) {
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|