@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.63 kB
JavaScript
import{EventHandler as t}from"../../core/event-handler.js";import{AppBase as e}from"../app-base.js";import{ScriptAttributes as r}from"./script-attributes.js";import{ScriptType as o}from"./script-type.js";import{ScriptTypes as s}from"./script-types.js";import{Script as n}from"./script.js";const i=new Set(["system","entity","create","destroy","swap","move","data","scripts","_scripts","_scriptsIndex","_scriptsData","enabled","_oldState","onEnable","onDisable","onPostStateChange","_onSetEnabled","_checkState","_onBeforeRemove","_onInitializeAttributes","_onInitialize","_onPostInitialize","_onUpdate","_onPostUpdate","_callbacks","_callbackActive","has","get","on","off","fire","once","hasEvent"]);function a(){return i}function c(e,s){if(i.has(e))throw new Error(`Script name '${e}' is reserved, please rename the script`);const n=function(e){t.prototype.initEventHandler.call(this),o.prototype.initScriptType.call(this,e)};return(n.prototype=Object.create(o.prototype)).constructor=n,n.extend=o.extend,n.attributes=new r(n),m(n,e,s),n}const p={};function m(t,r,a){if("function"!=typeof t)throw new Error(`script class: '${t}' must be a constructor function (i.e. class).`);if(!(t.prototype instanceof n))throw new Error(`script class: '${o.__getScriptName(t)}' does not extend pc.Script.`);if(r=r||t.__name||o.__getScriptName(t),i.has(r))throw new Error(`script name: '${r}' is reserved, please change script name`);t.__name=r;(a?a.scripts:e.getApplication().scripts).add(t),s.push(t)}r.reservedNames.forEach(((t,e,r)=>{p[t]=1})),c.reservedAttributes=p;export{c as createScript,a as getReservedScriptNames,m as registerScript};