Updated db structure
This commit is contained in:
parent
b54b614a1b
commit
bc626c57ad
@ -19,4 +19,12 @@ model SpriteAction {
|
|||||||
frameWidth Int @default(0)
|
frameWidth Int @default(0)
|
||||||
frameHeight Int @default(0)
|
frameHeight Int @default(0)
|
||||||
frameSpeed Int @default(0)
|
frameSpeed Int @default(0)
|
||||||
|
images SpriteActionImage[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model SpriteActionImage {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
spriteActionId String
|
||||||
|
spriteAction SpriteAction @relation(fields: [spriteActionId], references: [id], onDelete: Cascade)
|
||||||
|
order Int
|
||||||
}
|
}
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
import { Server } from 'socket.io'
|
|
||||||
import { TSocket } from '../../../utilities/Types'
|
|
||||||
import path from 'path'
|
|
||||||
import fs from 'fs/promises'
|
|
||||||
import spriteRepository from '../../../repositories/SpriteRepository'
|
|
||||||
|
|
||||||
type Payload = {
|
|
||||||
id: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response = string[]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle game master sprite update event
|
|
||||||
* @param socket
|
|
||||||
* @param io
|
|
||||||
*/
|
|
||||||
export default function (socket: TSocket, io: Server) {
|
|
||||||
socket.on('gm:sprite:action:images', async (data: Payload, callback: (response: Response) => void) => {
|
|
||||||
if (socket.character?.role !== 'gm') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const sprite = await spriteRepository.getById(data.id)
|
|
||||||
if (!sprite) {
|
|
||||||
console.log(`---Sprite not found.`)
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const public_folder = path.join(process.cwd(), 'public', 'sprites')
|
|
||||||
const sprite_folder = path.join(public_folder, sprite.id)
|
|
||||||
|
|
||||||
const spriteActions = await fs.readdir(sprite_folder)
|
|
||||||
const urls = spriteActions.map((action: string) => {
|
|
||||||
return path.join(sprite_folder, action)
|
|
||||||
})
|
|
||||||
|
|
||||||
callback(urls)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
callback([])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user