36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
import { build } from 'esbuild'
|
|
|
|
const bundled = await build({
|
|
bundle: true,
|
|
entryPoints: ['src/core/loopFrameBaker.ts'],
|
|
format: 'esm',
|
|
platform: 'node',
|
|
treeShaking: true,
|
|
write: false,
|
|
})
|
|
const source = bundled.outputFiles[0].text
|
|
const moduleUrl = `data:text/javascript;base64,${Buffer.from(source).toString('base64')}`
|
|
const { closeLoopFrameSeam } = await import(moduleUrl)
|
|
|
|
const first = [{
|
|
boneName: 'p_0', spawnId: 7, x: 12, y: -4, rotation: 30,
|
|
scaleX: 1.2, scaleY: 0.8, alpha: 0.75, colorHex: 0xffcc00,
|
|
resourceId: 1, imageFrameIndex: 2, imageVisible: true, active: true,
|
|
trailState: {
|
|
bones: [{ boneName: 'trail_0', x: 1, y: 2, rotation: 3 }],
|
|
activeBoneCount: 1, width: 5, alpha: 0.5, colorHex: 0xffffff, resourceId: 1,
|
|
},
|
|
}]
|
|
const frames = [first, [{ ...first[0], spawnId: 99, x: 200, y: 300 }]]
|
|
|
|
closeLoopFrameSeam(frames)
|
|
|
|
if (JSON.stringify(frames[0]) !== JSON.stringify(frames[1])) {
|
|
throw new Error('循环尾帧没有与首帧保持完全一致')
|
|
}
|
|
if (frames[0] === frames[1] || frames[0][0] === frames[1][0] || frames[0][0].trailState === frames[1][0].trailState) {
|
|
throw new Error('循环闭合帧必须是深拷贝,不能共享可变状态')
|
|
}
|
|
|
|
console.log('循环持续:首尾粒子身份、变换、生命周期表现及拖尾状态完全一致')
|