78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
import { stat } from 'node:fs/promises'
|
|
import { build } from 'esbuild'
|
|
|
|
const bundled = await build({
|
|
bundle: true,
|
|
entryPoints: ['src/core/particleResources.ts'],
|
|
format: 'esm',
|
|
platform: 'node',
|
|
write: false,
|
|
})
|
|
const module = await import(
|
|
`data:text/javascript;base64,${Buffer.from(bundled.outputFiles[0].text).toString('base64')}`
|
|
)
|
|
|
|
const expectedNames = Array.from(
|
|
{ length: 15 },
|
|
(_, index) => `yanhua_${String(index + 1).padStart(2, '0')}.png`,
|
|
)
|
|
if (module.DEFAULT_SEQUENCE_FPS !== 15) {
|
|
throw new Error('默认序列帧播放帧率必须为 15 FPS')
|
|
}
|
|
if (JSON.stringify(module.DEFAULT_SEQUENCE_FRAME_NAMES) !== JSON.stringify(expectedNames)) {
|
|
throw new Error('默认序列帧顺序不正确')
|
|
}
|
|
|
|
const resource = {
|
|
imageMode: 'sequence',
|
|
sequenceFrames: [],
|
|
textureName: 'star',
|
|
textureFolder: '',
|
|
previewUrl: '/images/star.png',
|
|
}
|
|
if (!module.ensureDefaultSequenceFrames(resource)) {
|
|
throw new Error('序列帧模式应自动填充默认资源')
|
|
}
|
|
if (resource.sequenceFrames.length !== expectedNames.length) {
|
|
throw new Error('默认序列帧数量不正确')
|
|
}
|
|
if (resource.textureName !== 'yanhua' || resource.textureFolder !== '') {
|
|
throw new Error('默认序列帧资源名称或子文件夹不正确')
|
|
}
|
|
|
|
for (const [index, frame] of resource.sequenceFrames.entries()) {
|
|
const expectedName = expectedNames[index]
|
|
if (frame.name !== expectedName || !frame.previewUrl.endsWith(`/yanhua/${expectedName}`)) {
|
|
throw new Error(`默认序列帧路径错误: ${frame.name}`)
|
|
}
|
|
await stat(`public/images/frame-sequence/yanhua/${expectedName}`)
|
|
}
|
|
|
|
const existingFrames = [{ name: 'custom.png', previewUrl: '/custom.png', texture: null }]
|
|
const customResource = {
|
|
imageMode: 'sequence',
|
|
sequenceFrames: existingFrames,
|
|
textureName: 'custom',
|
|
textureFolder: 'custom/',
|
|
previewUrl: '/custom.png',
|
|
}
|
|
if (module.ensureDefaultSequenceFrames(customResource)) {
|
|
throw new Error('已有自定义序列帧时不应被默认资源覆盖')
|
|
}
|
|
if (customResource.sequenceFrames !== existingFrames) {
|
|
throw new Error('已有自定义序列帧引用不应变化')
|
|
}
|
|
|
|
const fixedResource = {
|
|
imageMode: 'fixed',
|
|
sequenceFrames: [],
|
|
textureName: 'star',
|
|
textureFolder: '',
|
|
previewUrl: '/images/star.png',
|
|
}
|
|
if (module.ensureDefaultSequenceFrames(fixedResource)) {
|
|
throw new Error('固定图片模式不应填充序列帧')
|
|
}
|
|
|
|
console.log('默认序列帧校验通过:15 FPS、yanhua 01-15 顺序、路径、资源名称、文件存在,且不会覆盖已有序列')
|