import { PluginPureHook } from '@gedit/runtime-compiler'; import { SpineGameObject } from '@gedit/runtime-render'; import { filterOrigin, transform } from './transform'; import { addGameObjectToMap, parseQuery, splitTexture, code } from '../common'; import { LocalComponent } from './utils'; import { attachCollisionBody } from './collision-body'; export interface SpineQueryParams { skeletonName: string; } export function spine(ctx: PluginPureHook, component: SpineGameObject): void { const { spine: data, name, displayType } = component; const { texture, params } = parseQuery(data.texture); if (texture && params.skeletonName) { const { key, child } = splitTexture(texture); const resourceKey = params.skeletonName === 'default' || !child ? key : `${key}.${params.skeletonName}`; ctx.comment(`@type ${displayType}\n@name ${name}`); const blk = new LocalComponent(ctx); blk.in(); ctx.println(`${code.create(component)}(0, 0, '${resourceKey}', '', false);`); addGameObjectToMap(ctx, component); attachCollisionBody(ctx, component); transform(ctx, component, true, filterOrigin); if (data.animationName) { ctx.println(` .setAnimation(0, '${data.animationName}', ${data.animationLoop}, true)`); } blk.out(); } }