import { PluginPureHook } from '@gedit/runtime-compiler'; import { Scene } from '@gedit/runtime-render'; import { prefixCreate, prefixPreload, prefixScene, local, global } from './common'; export function scene(hook: PluginPureHook, component: Scene, index: number): void { const { name, displayType } = component; hook.comment(`@type ${displayType}\n@name ${name}`); hook.print(`const ${prefixScene(index)} = `); hook.push(); hook.print('init() '); hook.push(); events(hook); hook.pop(false); hook.println(','); hook.println(`create: ${prefixCreate(index)},`); hook.println(`preload: ${prefixPreload(index)},`); hook.pop(); } export function events(hook: PluginPureHook): void { // game object added to scene /* hook.print(`this.events.on('addedtoscene', (${local.COMPONENT}) => `); hook.push(); hook.println(`${global.GAME_OBJECT_MAP}.set(${local.COMPONENT}.name, ${local.COMPONENT});`); hook.pop(false); hook.println(');'); */ // game object deleted from scene hook.print(`this.events.on('removedfromscene', (${local.COMPONENT}) => `); hook.push(); hook.println(`${global.GAME_OBJECT_MAP}.delete(${local.COMPONENT}.name);`); hook.pop(false); hook.println(');'); }