UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 2.38 kB
import{IndexedList as e}from"../../../core/indexed-list.js";import{Vec2 as o}from"../../../core/math/vec2.js";import{Component as s}from"../component.js";import{ComponentSystem as n}from"../system.js";import{ScreenComponent as t}from"./component.js";import{ScreenComponentData as r}from"./data.js";const i=["enabled"];class c extends n{constructor(s){super(s),this.id="screen",this.ComponentType=t,this.DataType=r,this.schema=i,this.windowResolution=new o,this._drawOrderSyncQueue=new e,this.app.graphicsDevice.on("resizecanvas",this._onResize,this),this.app.systems.on("update",this._onUpdate,this),this.on("beforeremove",this.onRemoveComponent,this)}initializeComponentData(e,s,n){void 0!==s.priority&&(e.priority=s.priority),void 0!==s.screenSpace&&(e.screenSpace=s.screenSpace),e.cull=e.screenSpace,void 0!==s.scaleMode&&(e.scaleMode=s.scaleMode),void 0!==s.scaleBlend&&(e.scaleBlend=s.scaleBlend),void 0!==s.resolution&&(s.resolution instanceof o?e._resolution.copy(s.resolution):e._resolution.set(s.resolution[0],s.resolution[1]),e.resolution=e._resolution),void 0!==s.referenceResolution&&(s.referenceResolution instanceof o?e._referenceResolution.copy(s.referenceResolution):e._referenceResolution.set(s.referenceResolution[0],s.referenceResolution[1]),e.referenceResolution=e._referenceResolution),e.syncDrawOrder(),super.initializeComponentData(e,s,n)}destroy(){super.destroy(),this.app.graphicsDevice.off("resizecanvas",this._onResize,this),this.app.systems.off("update",this._onUpdate,this)}_onUpdate(e){const o=this.store;for(const s in o)o[s].entity.screen.update&&o[s].entity.screen.update(e)}_onResize(e,o){this.windowResolution.x=e,this.windowResolution.y=o}cloneComponent(e,o){const s=e.screen;return this.addComponent(o,{enabled:s.enabled,screenSpace:s.screenSpace,scaleMode:s.scaleMode,resolution:s.resolution.clone(),referenceResolution:s.referenceResolution.clone()})}onRemoveComponent(e,o){o.onRemove()}processDrawOrderSyncQueue(){const e=this._drawOrderSyncQueue.list();for(let o=0;o<e.length;o++){const s=e[o];s.callback.call(s.scope)}this._drawOrderSyncQueue.clear()}queueDrawOrderSync(e,o,s){this._drawOrderSyncQueue.list().length||this.app.once("prerender",this.processDrawOrderSyncQueue,this),this._drawOrderSyncQueue.has(e)||this._drawOrderSyncQueue.push(e,{callback:o,scope:s})}}s._buildAccessors(t.prototype,i);export{c as ScreenComponentSystem};