@makefully/platypus 4.1.1 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{AnimatedSprite as t,Application as e,Assets as i,Circle as s,Container as n,CullerPlugin as o,Ellipse as r,Graphics as a,Matrix as h,NineSliceSprite as l,Point as c,Polygon as d,Rectangle as u,RenderTexture as p,RoundedRectangle as g,Sprite as f,Text as y,Texture as m,TextureSource as v,Ticker as w,TilingSprite as b,VERSION as x,extensions as _}from"pixi.js";import{Application as C,CaptionFactory as k,CaptionPlayer as E,Debugger as A,HtmlRenderer as S,UserData as M}from"springroll";import{default as T}from"@tweenjs/tween.js";import{Sound as U,sound as P}from"@pixi/sound";import{AtlasAttachmentLoader as O,SkeletonJson as L,Skin as z,Spine as B}from"@esotericsoftware/spine-pixi-v8";var I={m:{},d:(t,e)=>{for(var i in e)I.o(e,i)&&!I.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},u:t=>t+".platypus.mjs"};I.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),I.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),I.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;if("string"==typeof import.meta.url&&(t=import.meta.url),!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),I.p=t})(),I.b=new URL("./",import.meta.url);var D={};I.r(D),I.d(D,{AIChaser:()=>ci,AIPacer:()=>di,AudioMusic:()=>gi,AudioSFX:()=>vi,AudioVO:()=>bi,Camera:()=>Oi,CollisionBasic:()=>Vi,CollisionFilter:()=>Gi,CollisionGroup:()=>qi,CollisionTiles:()=>$i,ComponentSwitcher:()=>Ji,ControllerInput:()=>Qi,Counter:()=>Ki,EntityCamera:()=>ki,EntityContainer:()=>es,EntityController:()=>cs,HandlerCamera:()=>Oi,HandlerCollision:()=>xs,HandlerController:()=>Rs,HandlerLogic:()=>Hs,HandlerRender:()=>Vs,Interactive:()=>li,LevelBuilder:()=>qa,LogicAngularMovement:()=>$a,LogicAttachment:()=>Ja,LogicButton:()=>Qa,LogicCarrier:()=>Ka,LogicDestroyMe:()=>th,LogicDirectionalMovement:()=>nh,LogicDragDrop:()=>ah,LogicImpactLaunch:()=>hh,LogicPacingPlatform:()=>lh,LogicPortable:()=>ch,LogicPortal:()=>dh,LogicPushable:()=>ph,LogicRebounder:()=>gh,LogicRegionSpawner:()=>fh,LogicRotationalMovement:()=>yh,LogicSpawner:()=>mh,LogicStateMachine:()=>xh,LogicSwitch:()=>_h,LogicTeleportee:()=>Ch,LogicTeleporter:()=>kh,LogicTimer:()=>Eh,LogicWindUpRacer:()=>Ah,Motion:()=>Ph,Mover:()=>Ih,Node:()=>Dh,NodeMap:()=>jh,NodeResident:()=>Vh,Orientation:()=>Jh,RandomEvents:()=>el,RelativePosition:()=>il,RelayFamily:()=>sl,RelayGame:()=>ol,RelayLinker:()=>hl,RelayParent:()=>cl,RelaySelf:()=>ul,Render:()=>vl,RenderAnimator:()=>kl,RenderContainer:()=>yl,RenderDebug:()=>Tl,RenderDestroyMe:()=>Ul,RenderProgress:()=>Pl,RenderSpine:()=>Ll,RenderSprite:()=>Hl,RenderText:()=>Zl,RenderTiles:()=>ic,SceneChanger:()=>sc,TiledLoader:()=>Ra,Timeline:()=>rc,Tutorial:()=>lc,Tween:()=>fc,VoiceOver:()=>wc,XHR:()=>xc});const X={value:!1,writable:!0},R={},j=function(){this.contains=null,this.previous=null};let Y=null;const N={add:function(t,e,i,s,n,o){var r=t===Array,a=!r&&(t=>/^\s*class[\s{]/.test(t.toString()))(t),h=null;if(!e)return console.warn("Recycle: Must define a name for this cache."),null;if(R[e])return t!==R[e].ClassObject&&console.warn('Recycle: There is already a cache named "'+e+'" that is being used for another object type.'),R[e];if((h=R[e]={ClassObject:t,list:null,setUp:null,recycle:null,pop:r?function(){var t=this.list,e=null;return t?(this.list=t.previous,e=t.contains,t.previous=Y,Y=t,e):[]}:a?function(){var t=this.list,e=null;return t?(this.list=t.previous,e=t.contains,t.previous=Y,Y=t,e):new this.ClassObject}:function(){var t=this.list,e=null;return t?(this.list=t.previous,e=t.contains,t.previous=Y,Y=t,e):Object.create(this.ClassObject.prototype)},push:function(t){var e=Y;e?Y=e.previous:e=Object.create(j.prototype),e.previous=this.list,this.list=e,e.contains=t},getLength:function(){for(var t=0,e=this.list;e;)t+=1,e=e.previous;return t}}).setUp=i?function(){var t=this.pop();return i.apply(t,arguments),t}:r?function(){var t=this.pop(),e=0;for(e=0;e<arguments.length;e++)t[e]=arguments[e];return t}:h.pop,h.recycle=s?function(t,...e){s.apply(t,...e),this.push(t)}:r?function(t,e){var i=0;if(e>1)for(i=t.length,e-=1;i--;)this.recycle(t[i],e);t.length=0,this.push(t)}:h.push,o&&(h.setUp=function(t,...e){var i=t(...e);return void 0===i.recycled?Object.defineProperty(i,"recycled",X):i.recycled=!1,i}.bind(h,h.setUp.bind(h)),h.recycle=function(t,e,...i){e.recycled?console.warn("Recycle: WHOA! I have already been recycled!",e):(e.recycled=!0,t(e,...i))}.bind(h,h.recycle.bind(h)),r&&(h.recycle=function(t,e,...i){Array.isArray(e)||console.warn("Recycle: Adding a non-Array to the array cache!"),t(e,...i)}.bind(h,h.recycle.bind(h)))),n){const e=function(...t){this.holds>0?this.recyclePending=t:h.recycle(this,...t)},i=function(t){return t.holds=(t.holds||0)+1,t},s=function(t){if(t.holds=Math.max((t.holds||0)-1,0),0===t.holds){const{recyclePending:i}=t;null!=i&&(t.recyclePending=null,e.call(t,...i))}return t};Object.defineProperties(t,{recycleHold:{value:i},recycleRelease:{value:s},setUp:{value:h.setUp.bind(h)},recycle:{value:function(t,...i){e.call(t,...i)}}}),Object.defineProperties(t.prototype,{recycleHold:{value:function(){return i(this)}},recycleRelease:{value:function(){return s(this)}},recycle:{value:function(...t){e.call(this,...t)}}})}return h},cache:R},W=function(t){let e=arguments.length;if(t)if("string"==typeof t)for(e%2&&(this[e]=null,e-=1);e;)this[arguments[e-2]]=arguments[e-1],e-=2;else{const e=Object.keys(t);let i=e.length;for(;i--;)this[e[i]]=t[e[i]]}};N.add(W,"Data",W,function(){const t=Object.keys(this);let e=t.length;for(;e--;)delete this[t[e]]},!0);const H=W,V=N.add(Array,"Array",null,null,!1);function F(t,...e){for(let i=0;i<e.length;i++){const s=e[i];if(s&&s.length)for(let e=0;e<s.length;e++)-1===t.indexOf(s[e])&&t.push(s[e])}return t}function Z(t){const e=V.setUp(),i=t.length;for(let s=0;s<i;s++)e[s]=t[s];return e}function G(t,e){const i=t[e],s=t.length;if(e<0||e>=s)return null;for(let i=e+1;i<s;i++)t[i-1]=t[i];return t.length-=1,i}const q=function(t,e,i){return this.get(e)!==i&&(this.has(e)||t.push(e),this.set(e,i)),i},$=function(t,e){const i=t.indexOf(e),s=this.get(e);return i>=0&&(G(t,i),this.delete(e)),s},J=function(t){let e=t.length;for(;e--;)this.delete(t[e]);t.length=0},Q=function(t){const e={};let i=t.length;for(;i--;){const s=t[i];e[s]=this.get(s)}return e},K={get:{value:null},has:{value:null},keys:{value:null},set:{value:null},delete:{value:null},clear:{value:null},toJSON:{value:null}},tt=function(t){if(!this.map){const t=K,e=this.map=new Map,i=t.keys.value=V.setUp();t.get.value=e.get.bind(e),t.has.value=e.has.bind(e),t.set.value=q.bind(e,i),t.delete.value=$.bind(e,i),t.clear.value=J.bind(e,i),t.toJSON.value=Q.bind(e,i),Object.defineProperties(this,t)}if(t)if("string"==typeof t){let t=arguments.length;for(t%2&&(t-=1,this.set(arguments[t],null));t;)t-=2,this.set(arguments[t],arguments[t+1])}else if(t.keys){const e=t.keys;let i=e.length;for(;i--;)this.set(e[i],t.get(e[i]))}else{const e=Object.keys(t);let i=e.length;for(;i--;)this.set(e[i],t[e[i]])}};N.add(tt,"DataMap",tt,function(){this.clear()},!0);const et=tt,it=/^(?:\w+:\/{2}\w+(?:\.\w+)*\/?)?(?:[\/.]*?(?:[^?]+)?\/)?(?:([^\/?]+?)(?:\.(\w+|{\w+(?:,\w+)*}))?)(?:\?\S*)?$/,st=function(t){const e=t.src??t,i=e.match(it);return t.id&&platypus.debug.warn(`AssetManager: Use "alias" instead of "id" for asset identification. (${t.id})`),H.setUp("alias",t.alias??[t.id??(i?i[1]:e)],"src",e,"data",t.data??null)},nt=function(t,e=null,i=!1,s=0,n=0){this.callback=t,this.context=e,this.once=i,this.priority=s,this.order=n},{prototype:ot}=nt;ot.sortPriority=function(t){return this.priority-t.priority||this.order-t.order},N.add(nt,"EventHandler",nt,null,!0);const rt=nt,at=function(){this.dirty=!1,this.handlers=V.setUp(),this.orderIndex=0},{prototype:ht}=at;ht.add=function(t,e,i,s){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.callback===t&&s.context===e)return null}const n=rt.setUp(t,e,i,s,this.orderIndex++);return this.handlers.push(n),this.dirty=!0,n},ht.remove=function(t,e){const{handlers:i}=this;let s=i.length;for(;s--;){const n=i[s];n.callback!==t||void 0!==e&&n.context!==e||(n.recycle(),G(i,s))}},ht.trigger=function(t){this.dirty&&(this.handlers.sort((t,e)=>t.sortPriority(e)),this.dirty=!1);const e=Z(this.handlers),{length:i}=e;for(let t=0;t<i;t++)e[t].recycleHold();for(let s=0;s<i;s++){const{callback:i,context:n,once:o}=e[s];o&&this.remove(i),i.apply(n,t)}for(let t=0;t<i;t++)e[t].recycleRelease();return V.recycle(e),i},N.add(at,"EventHandlerList",at,function(){this.handlers.forEach(t=>t.recycle()),V.recycle(this.handlers),this.handlers=null,this.dirty=!1,this.orderIndex=0},!0);const lt=at,ct=function(t,e){return function(){t.apply(this,arguments),e.apply(this,arguments)}};class dt{constructor({debug:t}={}){if(this._listeners={},this._destroyed=!1,this.loopCheck=V.setUp(),t){const t=this.triggerEvent;this.triggerEvent=function(e,i){const s=i&&i.debug;let n=0;if(s||this.debug){const o="undefined"!=typeof performance&&performance.mark&&performance.measure?performance:null;for(let t=0;t<this.loopCheck.length;t++)if(this.loopCheck[t]===e){if(n+=1,n>5)throw"Endless loop detected for '"+e+"'.";platypus.debug.warn("Event '"+e+"' is nested inside another '"+e+"' event.")}this.loopCheck.push(e),o&&o.mark("a");const r=t.apply(this,arguments);return o&&(o.mark("b"),o.measure(this.type+":"+e,"a","b")),this.loopCheck.length=this.loopCheck.length-1,s&&(r?platypus.debug.log('Entity "'+this.type+'": Event "'+e+'" has '+r+" subscriber"+(r>1?"s":"")+".",i):platypus.debug.warn('Entity "'+this.type+'": Event "'+e+'" has no subscribers.',i)),r}return t.apply(this,arguments)}}}on(t,e,i=null,s=!1,n=-1){return this._destroyed?null:(this._listeners[t]=this._listeners[t]??lt.setUp()).add(e,i??this,s,-1===n?Number.MAX_SAFE_INTEGER:n)}off(t,e,i){if(!this._destroyed)if(void 0===t)this.getMessageIds().forEach(t=>this._listeners[t].recycle()),this._listeners={};else{const s=this._listeners[t];s&&(void 0===e?(s.recycle(),delete this._listeners[t]):(s.remove(e,i),s.handlers.length||(s.recycle(),delete this._listeners[t])))}}toString(){return"[Messenger Object]"}trigger(t,e,i){if("string"==typeof t)return this.triggerEvent.apply(this,arguments);if(Array.isArray(t)){const e=Z(arguments);let i=0;for(let s=0;s<t.length;s++)e[0]=t[s],i+=this.trigger.apply(this,e);return V.recycle(e),i}return t.event?void 0!==t.debug?this.triggerEvent(t.event,t.message??e,t.debug):this.triggerEvent(t.event,t.message??e):(platypus.debug.warn('Event incorrectly formatted: must be string, array, or object containing an "event" property.',t),0)}triggerEvent(t,...e){const{_listeners:i}=this;return!this._destroyed&&i.hasOwnProperty(t)&&i[t]?i[t].trigger(e):0}getMessageIds(){return Object.keys(this._listeners)}destroy(){V.recycle(this.loopCheck),this.loopCheck=null,this._destroyed=!0,this.getMessageIds().forEach(t=>this._listeners[t].recycle()),this._listeners=null}get destroyed(){return this._destroyed}static mixin(t){const e=dt.prototype,i=t.prototype,s=Object.getOwnPropertyNames(e);let n=s.length;for(;n--;){const t=s[n];"constructor"!==t&&(i[t]?i[t]=ct(i[t],e[t]):i[t]=e[t])}}static initialize(t){t._listeners={},t._destroyed=!1,t.loopCheck=V.setUp()}}const ut=dt;function pt(t,e){const i=V.setUp();let s=t.toString();if(e){const t=e.length;let n=s.indexOf(e);for(;n>=0;)i.push(s.substr(0,n)),s=s.substr(n+t),n=s.indexOf(e);i.push(s)}else{let t=s.length;const e=t-1;for(;t--;)i.push(s[e-t])}return i}const gt=function(t){const e=arguments.length;if(e)if(1===e&&"string"==typeof t)et.call(this),this.updateFromString(t);else{const t=function(t){const e=V.setUp();if("string"==typeof t[0])for(let i=0;i<t.length;i++)e.push(i%2?!!t[i]:t[i]);else if("object"==typeof t[0]){const i=t[0];if(i.keys&&i.get){const{keys:t}=i;let s=t.length;for(;s--;)e.push(t[s],!!i.get(t[s]))}else{const t=Object.keys(i);let s=t.length;for(;s--;)e.push(t[s],!!i[t[s]])}}return e}(arguments);et.apply(this,t),V.recycle(t)}else et.call(this)},ft=et.prototype,yt=gt.prototype=Object.create(ft);Object.defineProperty(yt,"constructor",{configurable:!0,writable:!0,value:gt}),Object.defineProperty(yt,"toString",{value:function(){const{keys:t}=this;let e=t.length,i=V.setUp();for(;e--;){const s=t[e];i.push(this.get(s)?s:`!${s}`)}const s=i.join(",");return V.recycle(i),s}}),Object.defineProperty(yt,"updateFromString",{value:function(t){const e=pt(t,",");let i=e.length;for(;i--;){const t=e[i];t&&("!"===t.substr(0,1)?this.set(t.substr(1),!1):this.set(t,!0))}return V.recycle(e),this}}),Object.defineProperty(yt,"update",{value:function(t){const{keys:e}=t;let i=e.length,s=!1;for(;i--;){const n=e[i],o=t.get(n);this.get(n)!==o&&(this.set(n,o),s=!0)}return s}}),Object.defineProperty(yt,"includes",{value:function(t){const{keys:e}=t;let i=e.length;for(;i--;){const s=e[i];if(this.get(s)!==t.get(s))return!1}return!0}}),Object.defineProperty(yt,"intersects",{value:function(t){const{keys:e}=t;let i=e.length;for(;i--;){const s=e[i];if(this.get(s)===t.get(s))return!0}return!1}}),N.add(gt,"StateMap",gt,function(){this.clear()},!0);const mt=gt;class vt{constructor(t,e,i){this.type=t,this.owner=e,this.id=i,this.publicMethods=H.setUp(),this.listener=H.setUp("events",V.setUp(),"messages",V.setUp())}initialize(){}toString(){return"[Component "+this.type+"]"}destroy(){if(this.listener){const t=this.publicMethods,e=Object.keys(t);let i=e.length;for(this._destroy&&this._destroy();i--;)this.removeMethod(e[i]);this.publicMethods.recycle(),this.removeEventListeners(),V.recycle(this.listener.events),V.recycle(this.listener.messages),this.listener.recycle(),this.listener=null}}removeEventListeners(t){if(t)for(let e=0;e<t.length;e++)this.removeEventListener(t[e]);else{const{listener:t,owner:e}=this,{events:i,messages:s}=t,{length:n}=i;for(let t=0;t<n;t++)e.off(i[t],s[t]);i.length=0,s.length=0}}addEventListener(t,e,i){const s=e.bind(this);return this.listener.events.push(t),this.listener.messages.push(s),this.owner.on(t,s,i),s}addEventListeners(t){const{owner:e}=this,{parent:i}=e,s=Object.keys(t).map(e=>{const i=this.addEventListener(e,t[e]);return()=>this.removeEventListener(e,i)});return e.state.get("loaded")&&i.triggerEvent?.("child-entity-updated",e),()=>{s.forEach(t=>t()),i.triggerEvent?.("child-entity-updated",e)}}addMethod(t,e){this.owner[t]?platypus.debug.warn(this.owner.type+': Entity already has a method called "'+t+'". Method not added.'):(this.owner[t]=e.bind(this),this.publicMethods[t]=e)}removeEventListener(t,e){const{listener:i,owner:s}=this,{events:n,messages:o}=i;for(let i=n.length-1;i>=0;i--)n[i]!==t||e&&o[i]!==e||(s.off(t,o[i]),G(n,i),G(o,i))}removeMethod(t){this.owner[t]?delete this.owner[t]:platypus.debug.warn(this.owner.type+': Entity does not have a method called "'+t+'".'),delete this.publicMethods[t]}static getAssetList(){return V.setUp()}}const wt=t=>("number"==typeof bt[t]?bt[t]+=1:bt[t]=0,`${t}-${bt[t]}`);let bt={};function xt(t={}){const{events:e,getAssetList:i,id:s,initialize:n,methods:o,properties:r,publicMethods:a,publicProperties:h}=t,l={[s]:class extends vt{constructor(t,i={},n){const{aliases:o,id:l=wt(s)}=i;if(super(s,t,l),r){const e=Object.keys(r),{length:s}=e;for(let n=0;n<s;n++){const s=e[n];this[s]=i[s]??t[s]??r[s]}}if(h){const e=Object.keys(h),{length:s}=e;for(let n=0;n<s;n++){const s=e[n];Object.defineProperty(this,s,{get:function(){return t[s]},set:function(e){t[s]=e},enumerable:!0}),this[s]=i[s]??t[s]??h[s]}}if(e){const t=Object.keys(e),{length:i}=t;for(let s=0;s<i;s++){const i=t[s];if(this.addEventListener(i,e[i]),o){const t=Object.keys(o),{length:s}=t;for(let n=0;n<s;n++){const s=t[n];o[s]===i&&this.addEventListener(s,e[i])}}}}if(a){const t=Object.keys(a),{length:e}=t;for(let i=0;i<e;i++){const e=t[i];let s=e;if(o){const t=Object.keys(o),{length:i}=t;for(let n=0;n<i;n++){const i=t[n];o[i]===e&&(s=i)}}this.addMethod(s,a[e])}}!this.initialize(i,n)&&n&&n()}}}[s],c=l.prototype;if(n&&(c.initialize=n),c.toJSON=function(){const t=function(i,s){const n=typeof i;let o=null,r=!1,a=!1;if(e||(e=!0,r=!0),"function"===n)a=!0;else if("object"===n&&null!==i)if(i.toJSON)o=s?Z(s):V.setUp(),o.push(i),t(i.toJSON(),o)||(a=!0);else if(Array.isArray(i)){let e=i.length;for(;e--;){const n=i[e];if(s&&s.indexOf(n)>=0){a=!0;break}if(o=s?Z(s):V.setUp(),o.push(n),!t(n,o)){a=!0;break}}}else{const e=Object.keys(i),{length:n}=e;for(let r=0;r<n;r++){const n=i[e[r]];if(s&&s.indexOf(n)>=0){a=!0;break}if(o=s?Z(s):V.setUp(),o.push(n),!t(n,o)){a=!0;break}}}return s&&V.recycle(s),r&&(e=!1),!a};let e=!1;return function(i,s){const n={type:this.type};if(r){const i=Object.keys(r),{length:o}=i;for(let a=0;a<o;a++){const o=i[a];r[o]!==this[o]&&(!s||e||t(this[o])||platypus.debug.warn('Component "'+this.type+'" includes a non-JSON property value for "'+o+'" (type "'+typeof this[o]+'"). You may want to create a custom `toJSON` method for this component.',this[o]),n[o]=this[o])}}if(h){const n=Object.keys(h),{length:o}=n;for(let r=0;r<o;r++){const o=n[r];h[o]!==this.owner[o]&&void 0===i[o]&&(!s||e||t(this.owner[o])||platypus.debug.warn('Component "'+this.type+'" includes a non-JSON public property value for "'+o+'" (type "'+typeof this.owner[o]+'"). You may want to create a custom `toJSON` method for this component.',this.owner[o]),i[o]=this.owner[o])}}return n}}(),o){const t=Object.keys(o),{length:e}=t;for(let i=0;i<e;i++){const e=t[i];"destroy"===e?c._destroy=o[e]:c[e]=o[e]}}if(a){const t=Object.keys(a),{length:e}=t;for(let i=0;i<e;i++){const e=t[i];c[e]=a[e]}}return i&&(l.getAssetList=i),l}const _t={},Ct=function(t){const{type:e}=t;return e?"function"==typeof e?e:platypus.components[e]?platypus.components[e]:void 0:t.id?xt(t):"function"==typeof t?t:null};class kt extends ut{constructor({components:t,properties:e={},id:i},{id:s,properties:n={}}={},o,r){super();const a=(t,e)=>new Promise(i=>this.addComponent(new t(this,e,i))),h=V.setUp(),l=V.setUp(),c=this.trigger;if(this.components=V.setUp(),this.type=i||"none",this.id=s??n.id,this.id){if(0===this.id.search(this.type+"-")){const t=parseInt(this.id.substring(this.id.search("-")+1),10);isNaN(t)||_t[this.type]&&!(_t[this.type]<=t)||(_t[this.type]=t+1)}}else _t[this.type]||(_t[this.type]=0),this.id=this.type+"-"+_t[this.type],_t[this.type]+=1;if(this.setProperty(e),this.setProperty(n),this.on("set-property",t=>{this.setProperty(t)}),this.state=mt.setUp(this.state),this.lastState=mt.setUp(),r&&(this.parent=r),this.trigger=this.triggerEvent=(...t)=>(l.push(c.bind(this,...t)),-1),t)for(let e=0;e<t.length;e++){const i=t[e];if(i)if(i.type){const t=Ct(i);t?h.push(a(t,i)):platypus.debug.warn('Entity "'+this.type+'": Component "'+i.type+'" is not defined.',i)}else i.id?h.push(a(xt(i))):"function"==typeof i?h.push(a(i)):platypus.debug.warn('Entity "'+this.type+'": Component must have an `id` or `type` value.',i)}this.loadingComponents=Promise.all(h).then(()=>{this.loadingComponents=null,delete this.trigger,delete this.triggerEvent;for(let t=0;t<l.length;t++)l[t]();V.recycle(l),this.triggerEvent("load"),o&&o(this)}),V.recycle(h)}toString(){return"[Entity "+this.type+"]"}toJSON(t){const{components:e,type:i}=this,s={id:this.id,state:this.state.toJSON()},n={properties:s};t?(n.id=i,n.components=[]):n.type=i;for(let i=0;i<e.length;i++){const o=e[i].toJSON(s);t&&o&&n.components.push(o)}return n}addComponent(t){return this.components.push(t),this.triggerEvent("component-added",t),t}removeComponent(t){if("string"==typeof t){for(let e=0;e<this.components.length;e++)if(this.components[e].type===t)return t=this.components[e],G(this.components,e),this.triggerEvent("component-removed",t),t.destroy(),t}else for(let e=0;e<this.components.length;e++)if(this.components[e]===t)return G(this.components,e),this.triggerEvent("component-removed",t),t.destroy(),t;return!1}getComponentById(t){return this.components.filter(({id:e})=>e===t)[0]??null}getComponentsByType(t){return this.components.filter(({type:e})=>e===t)}get(t){const e=t.split(".");let i=this;for(;e.length;){let t=e.shift();if(i=i[t]??i.getComponentById?.(t)??i.getEntityById?.(t),!i)return null}return i}setProperty(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];this[s]=t[s]}}destroy(){const t=this.components;if(!this._destroyed){for(;t.length;)t[0].destroy(),t.shift();V.recycle(t),this.components=null,this.state.recycle(),this.state=null,this.lastState.recycle(),this.lastState=null,super.destroy()}}static getAssetList({components:t=[],preload:e=[],properties:i={},type:s}={},n,o){if(s){const t=platypus.game.settings.entities[s];return t?kt.getAssetList({...t,preload:[...e,...t.preload??[]]},i,o):(platypus.debug.warn(`Entity "${s}": This entity is not defined.`),V.setUp())}return[...new Set([...e,...t.map(t=>Ct(t)?.getAssetList(t,i,n,o)??[]).flat()])]}}const Et=[{content:"Prevent empty captions error.",start:0,end:1}],At=class extends E{constructor(t={nullCaption:Et},e,i=null){super(t,new S(e)),i&&(this.getCaption=t=>new Promise((e,s)=>{i.read(t.media?.file??t.url,{onSuccess:i=>e((({tags:t},e)=>{const{SYLT:i}=t;if(i){const t=Array.isArray(i)?i:[i],s=t.filter(({data:t})=>"captions"===t.descriptor)[0]??t.filter(({data:t})=>"transcription"===t.contentType)[0]??t.filter(({data:t})=>"lyrics"===t.contentType)[0]??null;if(s)return k.createCaption(s.data.synchronisedText.map(({text:t,timeStamp:i},s,n)=>{const o=n[s+1];return{content:t,start:Math.max(i,.001),end:o?o.timeStamp:e}}))}return null})(i,1e3*t.duration|0)),onError:s})}))}async start(t,e,...i){if(this.getCaption&&void 0===this.captions[e])try{this.captions[e]=await this.getCaption(t)}catch(t){this.captions[e]=null,platypus.debug.warn(t.type,t.info)}super.start(this.captions[e]?e:t.url,...i)}},{Tween:St}=T;class Mt{constructor(){this.masterVolume=1,this.volume=1,this.playingAudio=V.setUp()}play(t,e){const i=("string"==typeof t?platypus.assetCache.get(platypus.assetCache.getFileId(t)):t).play(e);return i.initialVolume="number"==typeof e.initialVolume?e.initialVolume:i.volume,i.set("volume",i.volume*this.volume*this.masterVolume),this.playingAudio.push(i),i.on("end",()=>{const t=this.playingAudio.indexOf(i);G(this.playingAudio,t)}),i}stop(t){const e=this.playingAudio.indexOf(t);t.stop(),e>=0?G(this.playingAudio,e):platypus.debug.warn('SFXPlayer: Did not find "'+t.soundId+'"')}fade(t,e,i,s=()=>{}){const n=new St(t);n.to({initialVolume:e},i),n.onUpdate(()=>{t.set("volume",t.initialVolume*this.volume*this.masterVolume)}),n.onComplete(s),n.start()}setVolume(t){const e=this.playingAudio;this.volume=t;for(let t=0;t<e.length;t++){const i=e[t];i.set("volume",i.initialVolume*this.volume*this.masterVolume)}}setMasterVolume(t){this.masterVolume=t,this.setVolume(this.volume)}destroy(){V.recycle(this.playingAudio),this.playingAudio=null}}const Tt=class{constructor(t,{name:e,storageKeys:i=null}){const s=`${e}-data`,n=window.localStorage.getItem(s),o=t=>{const e=t?.data??t;if(e){const t=Object.keys(e),{length:i}=t;for(let s=0;s<i;s++){const i=t[s];this.map.has(i)?this.map.set(i,e[i]):this.addKey(i,e[i])}}};if(this.map=et.setUp(),this.storageKey=s,this.connected=!1,i)for(let t=0;t<i.length;t++)this.addKey(i[t],null);try{o(JSON.parse(n))}catch(t){}t.container.on("connected",async()=>{this.connected=!0;try{o(await M.read(this.storageKey))}catch(t){platypus.debug.warn("Storage: connected but received an error",t)}})}addKey(t,e){this.map.set(t,e),Object.defineProperty(this,t,{get:function(){return this.map.get(t)},set:function(e){this.map.set(t,e),this.save()},configurable:!0,enumerable:!0})}get(t){return this.map.has(t)||this.addKey(t,null),this[t]}async save(){const t=this.map.toJSON();if(this.connected)try{await M.write(this.storageKey,t)}catch(t){platypus.debug.warn("Storage: tried to save but received an error",t)}else window.localStorage.setItem(this.storageKey,JSON.stringify(t))}set(t,e){this.map.has(t)?this[t]=e:(this.addKey(t,e),this.save())}},Ut=class{constructor(t=60){const e=this.listeners=[],i=this.worker=new Worker(new URL(I.p+I.u(243),I.b),{type:"module"});this.deltaMS=1e3/t,this.elapsedMS=this.deltaMS,i.onmessage=({data:t})=>{this.elapsedMS=t.deltaTime,e.forEach(e=>e(t))},this.start()}add(t){this.listeners.push(t)}remove(t){const e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)}start(){this.worker.postMessage({begin:{delta:this.deltaMS}})}stop(){this.worker.postMessage({stop:!0})}get FPS(){return 1e3/this.elapsedMS}},Pt=function(t="",e=0,i=null,s=null,n=!0){"object"==typeof t?(this.event=t.event??"",this.message=t.message??i,this.time=(t.time??0)+e,this.entity=t.entity??s,this.interruptable=t.interruptable??n):(this.event=t,this.message=i,this.time=e,this.entity=s,this.interruptable=n)};Pt.prototype.toJSON=function(){return{event:this.event,message:this.message,time:this.time,entity:this.entity?.id??this.entity,interruptable:this.interruptable}},N.add(Pt,"TimeEvent",Pt,null,!0);const Ot=Pt,Lt=function(t=[],e=0){this.list||(this.list=V.setUp()),this.addEvents(t),this.time=e},zt=function(t,e){return t.time-e.time},Bt=Lt.prototype;Bt.clear=function(t){return this.getEvents(1/0,t)},Bt.addEvents=function(t,e=0){const{list:i}=this,s=V.setUp();return t.forEach(t=>{if("number"==typeof t)e+=t;else if(t instanceof Ot)i.push(t),s.push(t);else{const n=Ot.setUp(t,e);i.push(n),s.push(n)}}),i.sort(zt),s},Bt.getEvents=function(t,e){const i=V.setUp(),{list:s}=this;for(this.time=t;s.length&&s[0].time<=t;)(!e||e.indexOf(s[0])>=0)&&i.push(s.shift());return i},Bt.getDuration=function(){const{list:t}=this;return t.length?t[t.length-1].time:0},Bt.update=function(t){return this.getEvents(this.time+t)},Bt.toJSON=function(){return this.list.map(t=>t.toJSON())},N.add(Lt,"TimeEventList",Lt,function(){this.list.length=0},!0);const It=Lt,Dt=class extends ut{constructor(t,e){super(),this.game=t,this.assetCache=e,this.tagReader=t.options.modules?.jsmediatags??null,this._onSoundFinished=this._onSoundFinished.bind(this),this._updateSilence=this._updateSilence.bind(this),this._syncCaptionToSound=this._syncCaptionToSound.bind(this),this.preloadingNextSound="",this.paused=!1,this.voList=null,this._listCounter=0,this._currentVO=null,this._soundInstance=null,this._callback=null,this._cancelledCallback=null,this._timer=0,this._captions=null,this.masterVolume=1,this.volume=1,this.captionMute=!0,this.currentlyLoadingAudio=!1,this.interruptable=!0,this.playQueue=V.setUp()}get playing(){return null!==this._currentVO||this._timer>0}get currentVO(){return this._currentVO}set captions(t){this._captions=t,t&&(t.selfUpdate=!1,this.setCaptionMute(this.captionMute))}get captions(){return this._captions}get currentPosition(){return this.playing?this._soundInstance?this._soundInstance.position:this._currentVO?this._timer:this.voList[this._listCounter]-this._timer:0}get currentDuration(){return this.playing?this._soundInstance?this._soundInstance.duration:this._currentVO&&this._captions?this._captions.currentDuration:this.voList[this._listCounter]:0}getElapsed(){const{assetCache:t}=platypus;let e=0,i=0;if(!this.voList)return 0;for(let e=0;e<this._listCounter;++e){const s=this.voList[e];"string"==typeof s?i+=1e3*t.get(t.getFileId(s)).duration:"number"==typeof s&&(i+=s)}if(e=this._listCounter,e<this.voList.length){const t=this.voList[e];"string"==typeof t?this._soundInstance&&(i+=1e3*this._soundInstance._elapsed):"number"==typeof t&&(i+=t-this._timer)}return i}pause(){!this.paused&&this.playing&&(this.paused=!0,this._soundInstance&&this._soundInstance.pause(),this.game.off("tick",this._syncCaptionToSound),this.game.off("tick",this._updateSilence))}resume(){this.paused&&(this.paused=!1,this._soundInstance&&this._soundInstance.resume(),this._captions.activeCaption?this._soundInstance&&this.game.on("tick",this._syncCaptionToSound):this.game.on("tick",this._updateSilence))}play(t,e,i,s=!0){if(this.startingNewTrack)platypus.debug.warn("VOPlayer: Tried playing a new track while a new track was starting up.");else{if(this.currentlyLoadingAudio||!this.interruptable&&this.playing)return void this.playQueue.push(H.setUp("idOrList",t,"callback",e,"cancelledCallback",i,"interruptable",s));this.startingNewTrack=!0,this.stop(),this.startingNewTrack=!1,this.interruptable=s,this._listCounter=-1,"string"==typeof t?this.voList=V.setUp(0,t):(this.voList=Z(t),this.voList.unshift(0)),this._callback=e,this._cancelledCallback=!0===i?e:i,this._onSoundFinished()}}_onSoundFinished(t){if(this._listCounter>=0){const e=this._currentVO;this.trigger("end",e),"string"==typeof e?(this.voList[0]+=1e3*(t?.duration??0),this.unloadSound(e),G(this.voList,1),this._listCounter-=1):"function"==typeof this._currentVO?(G(this.voList,1),this._listCounter-=1):(this.voList[0]+=this.voList[1],G(this.voList,1),this._listCounter-=1)}else this._listCounter=0;if(this.game.off("tick",this._syncCaptionToSound),this.game.off("tick",this._updateSilence),this._captions&&this._captions.activeCaption&&this._soundInstance){const t=this._captions.activeCaption;t.lineIndex=t.lines.length}if(this._soundInstance=null,this._listCounter++,this._listCounter>=this.voList.length){const t=this._callback;this._captions&&this._captions.stop(),this._currentVO=null,this._cancelledCallback=null,this._callback=null,V.recycle(this.voList),this.voList=null,t&&t(),this.interruptable?this.clearQueue():this.checkQueue()}else this._currentVO=this.voList[this._listCounter],"string"==typeof this._currentVO?(this._playSound(),this.trigger("start",this._currentVO)):"function"==typeof this._currentVO?(this._currentVO(),this._onSoundFinished()):(this._timer=this._currentVO,this._currentVO=null,this.game.on("tick",this._updateSilence),this.trigger("start",null))}_updateSilence(t){this._timer-=t.delta,this._timer<=0&&this._onSoundFinished()}_syncCaptionToSound(t){if(!this._soundInstance)return;const{_soundInstance:e,audioEventQueue:i}=this,s=1e3*e._elapsed;s>0&&(this._captions.update(t.delta/1e3),i&&i.getEvents(s).forEach(t=>this.trigger(t)))}async _playSound(){const t=()=>{const t=platypus.assetCache.get(i);if(this._soundInstance=t.play({complete:this._onSoundFinished,volume:this.volume*this.masterVolume}),this.audioEventQueue=null,this.tagReader&&this.tagReader.read(t.media?.file??t.url,{onSuccess:({tags:t})=>{const{SYLT:e}=t;if(e){const t=(Array.isArray(e)?e:[e]).reduce((t,{data:e})=>(t.push(...e.synchronisedText.map(({text:t,timeStamp:i})=>({event:"lyric",time:i,message:{language:e.language,descriptor:e.descriptor,contentType:e.contentType,content:t},interruptable:!0}))),t),[]);this.audioEventQueue=this.audioEventQueue||It.setUp(),this.audioEventQueue.addEvents(t)}},onError:t=>platypus.debug.warn(t)}),this._captions&&(this._captions.start(t,i,0),this.game.on("tick",this._syncCaptionToSound)),this.playQueue.length&&this.interruptable)this.checkQueue();else for(let t=this._listCounter+1;t<this.voList.length;++t){const e=this.voList[t];if("string"==typeof e){const t=V.setUp({id:this._currentVO,src:this._currentVO});this.assetCache.load(t),V.recycle(t),this.preloadingNextSound&&this.unloadSound(this.preloadingNextSound),this.preloadingNextSound=e;break}}},e=this._currentVO,i=platypus.assetCache.getFileId(e),s=V.setUp({alias:[i],src:`${e}`});this.currentlyLoadingAudio=!0;try{await this.assetCache.load(s,null,()=>{this.currentlyLoadingAudio=!1,this.stoppedWhileLoading?(this.stoppedWhileLoading=!1,this.playQueue.length?t():(t(),this.stop())):e===this._currentVO?t():platypus.debug.warn("VOPlayer: Asset loading out of order.")})}catch(t){platypus.debug.warn("Unable to load voice-over.",t)}V.recycle(s)}checkQueue(){if(this.playQueue.length){const t=G(this.playQueue,0);this.play(t.idOrList,t.callback,t.cancelledCallback,t.interruptable),t.recycle()}}clearQueue(){for(;this.playQueue.length;)G(this.playQueue,0).recycle()}stop(t=!1){if(this.startingNewTrack||!this.interruptable&&!t||this.clearQueue(),this.currentlyLoadingAudio)return void(this.stoppedWhileLoading=!0);const e=this._cancelledCallback;if(this.paused=!1,this._soundInstance&&(this._soundInstance.stop(),this.unloadSound(this._currentVO),this._soundInstance=null),this._currentVO&&("string"==typeof this._currentVO?this.trigger("stop",this._currentVO):"function"!=typeof this._currentVO&&this.trigger("stop",null)),this._currentVO=null,this._captions&&this._captions.activeCaption&&this._captions.stop(),this.game.off("tick",this._syncCaptionToSound),this.game.off("tick",this._updateSilence),this.voList){for(let t=this._listCounter+1;t<this.voList.length;t++)"function"==typeof this.voList[t]&&this.voList[t]();this.voList=null}this._timer=0,this._callback=null,this._cancelledCallback=null,e&&e(),this.startingNewTrack||this.interruptable||t||this.checkQueue()}setVolume(t){this.volume=t,this._soundInstance&&(this._soundInstance.volume=this.volume*this.masterVolume)}setMasterVolume(t){this.masterVolume=t,this.setVolume(this.volume)}setCaptionMute(t){this.captionMute=t,this._captions&&(this._captions.renderer.renderTarget.style.display=t?"none":"block")}unloadSound(t){this.assetCache.delete(t)}destroy(){this.stop(),this.voList=null,this._currentVO=null,this._soundInstance=null,this._callback=null,this._cancelledCallback=null,this._captions=null}},Xt=(t,e,i)=>Math.floor(t*e/i),Rt=(t,e)=>{const i=65,s=e?.split?.("."),n=s?.length>=3,o=n?parseInt(s[0],10):(t.charCodeAt(0)||i)-i,r=n?parseInt(s[1],10):(t.charCodeAt(1)||i)-i,a=n?parseInt(s[2],10):(t.charCodeAt(2)||i)-i,h=Math.max(o,r,a,1);return`color: #ffffff; line-height: 1.5em; border-radius: 6px; background-color: rgb(${Xt(o,204,h)},${Xt(r,204,h)},${Xt(a,204,h)});`};P.disableAutoPause=!0;const jt=window.XMLHttpRequest,Yt=function(t,e){const i=function(){n-=1,n||e(t)},s=function(t,e,i){Yt(t[e],function(s){t[e]=s,i(s)})};let n=0;if(t){if(Array.isArray(t)){if(n=t.length,n)for(let e=0;e<t.length;e++)s(t,e,i);else e(t);return}if("object"==typeof t){if(t.src&&t.src.length>5&&".json"===t.src.substring(t.src.length-5).toLowerCase())Yt(t.src,function(i){t.src!==i&&(t=i),e(t)});else{const o=Object.keys(t),{length:r}=o;if(n+=r,n)for(let e=0;e<r;e++)s(t,o[e],i);else e(t)}return}if("string"==typeof t&&t.length>5&&".json"===t.substring(t.length-5).toLowerCase())return void function(t,e){const i=new jt;i.open("GET",t,!0),i.responseType="text",i.onload=function(){let s=null;if(200===i.status)try{s=JSON.parse(i.responseText)}catch(e){platypus.debug.warn(`Error parsing "${t}": ${e.message}`)}else platypus.debug.warn(`Error opening "${t}": ${i.description}`);e(s)},i.send()}(t,function(t){"object"==typeof t?Yt(t,e):e(t)})}e(t)};_.add(o);const Nt=class extends ut{constructor(t,i={},s){const{display:n={},modules:o={}}=i,r=async({dev:t=!1,display:i={}})=>{this.pixiApp=new e,await this.pixiApp.init({width:this.canvas.width,height:this.canvas.height,view:this.canvas,autoResize:!1,...i}),this.renderer=this.pixiApp.renderer,this.stage=this.pixiApp.stage,this.stage.sortableChildren=!0,t&&(window.__PIXI_DEVTOOLS__={app:window.__PIXI_APP__=this.pixiApp})},a=({disablePause:t=!1,features:e={sound:!0,vo:!0,music:!0,sfx:!0,soundVolume:!0,voVolume:!0,musicVolume:!0,sfxVolume:!0,captions:!0},name:s,storageKeys:n})=>new Promise(o=>{const r=this.springroll=new C({features:e}),a=r.state;t||a.pause.subscribe(t=>{t?this.paused||(this.ticker.remove(this.tickInstance),this.paused=!0,P.pauseAll()):this.paused&&(this.ticker.add(this.tickInstance),this.paused=!1,P.resumeAll())}),a.soundVolume.subscribe(t=>{this.musicPlayer.setMasterVolume(t),this.voPlayer.setMasterVolume(t),this.sfxPlayer.setMasterVolume(t)}),a.musicVolume.subscribe(t=>this.musicPlayer.setVolume(t)),a.voVolume.subscribe(t=>this.voPlayer.setVolume(t)),a.sfxVolume.subscribe(t=>this.sfxPlayer.setVolume(t)),a.captionsMuted.subscribe(t=>this.voPlayer.setCaptionMute(t)),a.ready.subscribe(o),this.storage=new Tt(r,{name:s,storageKeys:n}),i?.beforeReady&&i.beforeReady(this)}),h=async function(t){const e=window.devicePixelRatio||1,h=i.workerTick?new Ut:w.shared,l=[];if(platypus.game=this,i.dev&&(t.debug=!0),this.settings=t,l.push(r(i),a(i)),o["box2d3-wasm"]&&l.push((async()=>{this.box2d=await o["box2d3-wasm"]()})()),await Promise.all(l),(t.captions||o.jsmediatags)&&(this.voPlayer.captions=new At(t.captions,document.getElementById("captions")||(()=>{const t=document.createElement("div"),{canvas:e}=this;return t.setAttribute("id","captions"),e.parentNode.insertBefore(t,e),t})(),o.jsmediatags)),n.aspectRatio){const t=n.aspectRatio.split("-"),i=t[0].split(":"),s=t[t.length-1].split(":"),o=i[0]/i[1],r=s[0]/s[1],a=Math.min(o,r),h=Math.max(o,r),l=this.canvas;this.resizeObserver=new ResizeObserver(t=>t.forEach(({contentRect:t})=>{const{height:i,width:s}=t,n=this.renderer,o=s/a|0,r=i*h|0;let c=i*e,d=s*e,u=!1;i>o?(l.style.height=o+"px",l.style.top=((i-o)/2|0)+"px",l.style.width="",l.style.left="",c=o*e,u=!0):s>r?(l.style.width=r+"px",l.style.left=((s-r)/2|0)+"px",l.style.height="",l.style.top="",d=r*e,u=!0):i===o&&s===r||(l.style.height="",l.style.top="",l.style.width="",l.style.left="",u=!0),u&&(n.resize(d,c),n.render(this.stage))}))}else this.resizeObserver=new ResizeObserver(t=>t.forEach(({contentRect:t})=>{const{height:i,width:s}=t,n=this.renderer;n.resize(s*e,i*e),n.render(this.stage)}));this.resizeObserver.observe(this.canvas.parentElement),s&&s(this),t.hideHello||function(t){const{options:e={}}=t,{version:i="(?)"}=e,s=document.getElementsByName("author")?.[0]?.getAttribute("content")??"",n=s?`by ${s}`:"",o=`${e.name??t.name??document.title??""}${i?` ${i}`:""}`,r=V.setUp(),{springroll:a,supports:h}=platypus;var l;a&&r.push("SpringRoll "+a.version),r.push("Pixi.js "+x),h.firefox||h.chrome?(console.log(`%c ${o} %c ${n}`,Rt(o,o.substr(o.lastIndexOf(" ")-o.length+1)),"line-height: 1.5em;"),r.push(`Platypus ${platypus.version}`),console.log(`Using %c ${r.join(" %c %c ")} %c `,...(l=r,l.reduce((t,e)=>(t.push(Rt(e,e.substr(e.lastIndexOf(" ")-e.length+1)),"line-height: 1.5em;"),t),[])))):console.log(`--- "${o}" ${n} - Using ${r.join(", ")}, and Platypus ${platypus.version} ---`),V.recycle(r)}(this),platypus.debug.general("Game config loaded.",t),window.getEntityById=this.getEntityById.bind(this),window.getEntitiesByType=this.getEntitiesByType.bind(this),window.getVisibleSprites=(t=this.stage,e=[])=>{if(!t.texture&&t.visible){for(let i=0;i<t.children.length;i++)window.getVisibleSprites(t.children[i],e);return e}return t.visible?(e.push(t),e):e},this.ticker=h,this.tickInstance=this.tick.bind(this,h,{delta:0,deltaMS:0,deltaTime:0,elapsed:0}),h.add(this.tickInstance),this.paused=!1,t.debug&&function(t,e){const i=document.createElement("div");let s=0;i.id="framerate",i.classList.add("platypus-debugging"),i.innerHTML="FPS: 00.000",e.parentNode.insertBefore(i,e),t.add(()=>{s+=t.deltaMS,s>=1e3&&(i.innerHTML="FPS: "+t.FPS.toFixed(3),s=0)})}(h,this.canvas)};let l=null;super(),t?(this.options=i,i.canvasId&&(l=window.document.getElementById(i.canvasId)),l||(l=window.document.createElement("canvas"),window.document.body.appendChild(l),i.canvasId&&l.setAttribute("id",i.canvasId)),l.classList.add("platypus-canvas"),l.width=l.offsetWidth,l.height=l.offsetHeight,l.ondragstart=function(){return!1},this.canvas=l,this.voPlayer=new Dt(this,platypus.assetCache),this.voPlayer.trackSound=platypus.supports.iOS,this.sfxPlayer=new Mt,this.musicPlayer=new Mt,this.layers=V.setUp(),this.sceneLayers=V.setUp(),this.loading=V.setUp(),this.loadingQueue=V.setUp(),"string"==typeof t?Yt(t,h.bind(this)):h.call(this,t)):platypus.debug.warn("No game definition is supplied. Game not created.")}tick(t,e,{deltaTime:i}){const s=this.loading;if(e.delta=e.deltaMS=t.deltaMS,e.deltaTime=i,e.elapsed+=t.deltaMS,s.length){for(let t=0;t<s.length;t++)s[t]();s.length=0}T.update(),this.triggerEvent("tick",e),this.triggerOnChildren("tick",e),this.renderer.render(this.stage)}triggerOnChildren(...t){const e=this.layers;for(let i=0;i<e.length;i++)e[i].trigger(...t)}load(t,e,i,s){this.loadingQueue.push(t),this.loading.push(()=>{const n=Array.isArray(t)?Z(t):V.setUp(t),o=V.setUp(),r=V.setUp(),a=t=>{const e=t?t.type||t:null;let i=null;if(!e)return platypus.debug.warn("Game: A layer id or layer definition must be provided to load a layer."),null;if("string"==typeof e){if(!this.settings.entities[e])return platypus.debug.warn('Game: A layer with the id "'+e+'" has not been defined in the game settings.'),null;i=this.settings.entities[e]}else i=t;return i},h=(t,e,i,s,n,o)=>new Promise(r=>{const a=H.setUp(n);if(a.stage=this.stage,a.parent=this,s){const n=H.setUp("count",1,"release",()=>{n.count-=1,n.count||(n.recycle(),r())}),h=new kt(s,{properties:a},e=>{t[i]=e,n.release()});h.unloadLayer=()=>{const t=()=>{s-=1,0===s&&window.setTimeout(()=>{h.triggerEvent("layer-unloaded"),platypus.debug.log("Layer unloaded: "+h.id),G(this.layers,this.layers.indexOf(h)),h.destroy(),platypus.assetCache.unload(e[i]),V.recycle(e[i])},1)};let s=1;h.triggerEvent("unload-layer",()=>{s+=1},t),platypus.debug.log("Layer unloading: "+h.id),t()},h.triggerEvent("layer-loaded",o,n)}}),l=s?"string"==typeof s?function(t,e){t.progress=e,this.triggerOnChildren("load-progress",t)}.bind(this,H.setUp("id",s,"progress",0)):s:null;for(let t=0;t<n.length;t++){const e=n[t],i=a(e),s=e&&e.type&&e.properties||null;n[t]={...i,preload:[...i?.preload??[],...e?.preload??[]]},r[t]=s}!function(t,e,i,s,n,o){const r=V.setUp();for(let n=0;n<t.length;n++){const o=H.setUp(e[n]),a=s[n]=kt.getAssetList(t[n],o,i);for(let t=0;t<a.length;t++)r.push(a[t]);o.recycle()}platypus.assetCache.load(r,n,o)}(n,r,e,o,l,async()=>{await Promise.all([new Promise(e=>{const i=this.loadingQueue,s=i.indexOf(t);if(0===s)for(i.shift(),e();"function"==typeof i[0];){const t=i[0];i.shift(),t()}else i[s]=e}),...n.map((t,i,s)=>h(s,o,i,t,r[i],e))]);for(let t=0;t<n.length;t++){const s=n[t];this.layers.push(s),i&&this.sceneLayers.push(s),platypus.debug.log("Layer live: "+s.id),s.triggerEvent("layer-live",e)}})})}loadScene(t,e,i="scene"){const s=this.sceneLayers;let n=t;if("string"==typeof n&&(n=this.settings.scenes&&this.settings.scenes[n]),n){for(n.layers&&(n=n.layers);s.length;)this.unload(s[0]);this.load(n,e,!0,i)}else platypus.debug.warn('Game: "'+t+'" is an invalid scene.')}unload(t){let e=t,i=0;if("string"==typeof e)for(let t=0;t<this.layers.length;t++)if(this.layers[t].type===e){e=this.layers[t];break}i=this.sceneLayers.indexOf(e),i>=0&&G(this.sceneLayers,i),e.unloadLayer()}getEntityById(t){for(let e=0;e<this.layers.length;e++){if(this.layers[e].id===t)return this.layers[e];if(this.layers[e].getEntityById){const i=this.layers[e].getEntityById(t);if(i)return i}}return null}getEntitiesByType(t){const e=V.setUp();for(let i=0;i<this.layers.length;i++)if(this.layers[i].type===t&&e.push(this.layers[i]),this.layers[i].getEntitiesByType){const s=this.layers[i].getEntitiesByType(t);F(e,s),V.recycle(s)}return e}destroy(){const t=this.layers;this.resizeObserver.disconnect();for(let e=0;e<t.length;e++)t[e].destroy();t.recycle()}};function Wt(t,{local:e=!0,scale:i=1}){if(e){const{registration:{x:e,y:s}}=t;return{x:e*i,y:s*i}}{const{x:e,y:s}=t;return{x:e*i,y:s*i}}}const Ht=function(){const t=function(t,e,i){this.matrix?(this.matrix[0]=0,this.matrix[1]=0,this.matrix[2]=0):this.matrix=V.setUp(0,0,0),this.set(t,e,i)},e=t.prototype;Object.defineProperty(e,"x",{get:function(){return this.matrix[0]},set:function(t){this.matrix[0]=t}}),Object.defineProperty(e,"y",{get:function(){return this.matrix[1]},set:function(t){this.matrix[1]=t}}),Object.defineProperty(e,"z",{get:function(){return this.matrix[2]},set:function(t){this.matrix[2]=t}}),e.toString=function(){return"["+this.matrix.join(",")+"]"},e.set=function(t,e,i){return t&&t.matrix?this.setVector(t,e):t&&"number"==typeof t.x&&"number"==typeof t.y?this.setXYZ(t.x,t.y,t.z):t&&Array.isArray(t)?this.setArray(t,e):this.setXYZ(t,e,i)},e.setXYZ=function(t,e,i){const{matrix:s}=this;return s[0]=t||0,s[1]=e||0,s[2]=i||0,this},e.setVector=function(t,e){return this.setArray(t.matrix,e)},e.setArray=function(t,e){const{matrix:i}=this;let s=e||t.length;for(;s--;)i[s]=t[s];return this},e.equals=function(t,e,i){const{matrix:s}=this;if(t&&Array.isArray(t)){let i=e||t.length;for(;i--;)if(s[i]!==t[i])return!1;return!0}if(t&&t.matrix){const i=t.matrix;let n=e||i.length;for(;n--;)if(s[n]!==i[n])return!1;return!0}return!("number"!=typeof t||s[0]!==t||"number"==typeof e&&s[1]!==e||"number"==typeof i&&s[2]!==i)},e.magnitude=function(t){return Math.sqrt(this.magnitudeSquared(t))},e.magnitudeSquared=function(t){const{matrix:e}=this;let i=0;t=t||e.length;for(let s=0;s<t;s++)i+=e[s]**2;return i},e.getAngle=function(){const t=this.magnitude(2);let e=0;return 0!==t&&(e=Math.acos(this.x/t),this.y<0&&(e=2*Math.PI-e)),e},e.getUnit=function(){return t.setUp(this).normalize()},e.getInverse=function(){return t.setUp(this).multiply(-1)},e.normalize=function(){const t=this.magnitude();return 0===t?this:this.multiply(1/t)},e.cross=function(){const t=function(t,e,i,s){return t*s-e*i};return function({x:e,y:i,z:s}){const{x:n,y:o,z:r}=this;return this.x=t(o,r,i,s),this.y=-t(n,r,e,s),this.z=t(n,o,e,i),this}}(),e.getCrossProduct=function(e){return t.setUp(this).cross(e)};const i=new t(1,0,0),s=new t(0,1,0),n=new t(0,0,1);return e.rotate=function(t,e=n){const{x:o,y:r,z:a}="x"===e?i:"y"===e?s:e,h=Math.cos(t),l=Math.sin(t),c=1-h,d=V.setUp(V.setUp(h+o*o*c,o*r*c-a*l,o*a*c+r*l),V.setUp(r*o*c+a*l,h+r*r*c,r*a*c-o*l),V.setUp(a*o*c-r*l,a*r*c+o*l,h+a*a*c));return this.multiply(d),V.recycle(d,2),this},e.rotateAbout=function(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,o=this.y-t.y;return this.x=t.x+(n*i-o*s),this.y=t.y+(n*s+o*i),this},e.multiply=function(t,e){const i=this.matrix;if(Array.isArray(t)){const e=Z(i);2===t.length?(i[0]=e[0]*t[0][0]+e[1]*t[0][1],i[1]=e[0]*t[1][0]+e[1]*t[1][1]):t.length>=3&&(i[0]=e[0]*t[0][0]+e[1]*t[0][1]+e[2]*t[0][2],i[1]=e[0]*t[1][0]+e[1]*t[1][1]+e[2]*t[1][2],i[2]=e[0]*t[2][0]+e[1]*t[2][1]+e[2]*t[2][2]),V.recycle(e)}else{const s=e||i.length;for(let e=0;e<s;e++)i[e]*=t}return this},e.add=function(e,i,s){let n=e,o=0;Array.isArray(n)?o=i||this.matrix.length:n instanceof t?(n=n.matrix,o=i||this.matrix.length):(n=[e||0,i||0,s||0],o=this.matrix.length);for(let t=0;t<o;t++)this.matrix[t]+=n[t];return this},e.addVector=function(t,e){return this.add(t,e)},e.subtractVector=function(t,e){const i=t.getInverse();return this.add(i,e),i.recycle(),this},e.perpendicular=function(t){const e=this.matrix,i=!0===t?-1:1,s=-this.matrix[1];return e[1]=e[0],e[0]=s,t&&(e[1]*=i,e[0]*=i),this},e.scale=function(t,e){return this.multiply(t,e)},e.dot=function({matrix:t},e){const{matrix:i}=this;let s=0,n=e||i.length;for(;n--;)s+=i[n]*(t[n]||0);return s},e.angleTo=function(t){const e=this.getUnit(),i=t.getUnit();let s=0;return e.magnitude()&&i.magnitude()?s=Math.acos(e.dot(i)):(platypus.debug.warn("Vector: Attempted to find the angle of a zero-length vector."),s=NaN),e.recycle(),i.recycle(),s},e.signedAngleTo=function(t,e){const i=this.getUnit(),s=t.getUnit(),n=i.getCrossProduct(s);let o=0;return o=0===n.magnitude()?i.x===s.x&&i.y===s.y&&i.z===s.z?0:Math.PI:n.dot(e)<0?-Math.acos(i.dot(s)):Math.acos(i.dot(s)),i.recycle(),s.recycle(),n.recycle(),o},e.scalarProjection=function(e){if("number"==typeof e)return this.magnitude(2)*Math.cos(e);{const i=t.setUp(e).normalize(),s=this.dot(i);return i.recycle(),s}},e.copy=function(){return t.setUp(this)},t.assign=function(){const e=function(t,e,i,s){let n=null,o=!1;void 0!==e[t]&&(n=e[t],delete e[t],o=!0),Object.defineProperty(e,t,{get:function(){return i.matrix[s]},set:function(t){i.matrix[s]=t},enumerable:!0}),o&&(e[t]=n)};return function(i,s){if(i&&s){if(!i[s]){i[s]=t.setUp();for(let t=2;t<arguments.length;t++)arguments[t]!==s&&e(arguments[t],i,i[s],t-2);return null}return i[s]}return null}}(),N.add(t,"Vector",t,function(){this.matrix.length=0},!0),t}(),Vt=(t,e)=>t.x*e.x+t.y*e.y,Ft=t=>Math.max(0,Math.min(1,t)),Zt=t=>t.list?{...t,list:t.list.map(t=>Zt(t)),a:t.b,b:t.a}:{...t,a:t.b,b:t.a},Gt=({a:t,b:e,distance:i,list:s,intersects:n=!1})=>{const{radius:o}=t;if(o>=i)return{a:e,b:e,distance:0,intersects:!0};{const r=i-o,a=r/i;if(s){const t=s.map(({a:t,b:e})=>({a:{x:e.x+(t.x-e.x)*a,y:e.y+(t.y-e.y)*a},b:e}));return{a:t[0],b:e,distance:r,list:t,intersects:n}}return{a:{x:e.x+(t.x-e.x)*a,y:e.y+(t.y-e.y)*a},b:e,distance:r,intersects:n}}},qt=({a:t,b:e,distance:i,list:s,intersects:n=!1})=>{const{radius:o}=e;if(o>=i)return{a:t,b:t,distance:0,intersects:!0};{const r=i-o,a=r/i;if(s){const e=s.map(({a:t,b:e})=>({a:t,b:{x:t.x+(e.x-t.x)*a,y:t.y+(e.y-t.y)*a}}));return{a:t,b:e[0],distance:r,list:e,intersects:n}}return{a:t,b:{x:t.x+(e.x-t.x)*a,y:t.y+(e.y-t.y)*a},distance:r,intersects:n}}},$t=t=>Gt(qt(t)),Jt=(t,e,i)=>{const s=[];let n=1/0;return e.forEach(e=>{const o=i(t,e);o.distance<n?(s.length=0,s.push(o),n=o.distance):o.distance===n&&s.push(o)}),{a:s[0].a,b:s[0].b,list:s,distance:n}},Qt=(t,e)=>({a:t,b:e,distance:Math.hypot(e.x-t.x,e.y-t.y)}),Kt=(t,{a:e,b:i})=>{const s={x:i.x-e.x,y:i.y-e.y},n=Vt(s,s);if(0===n)return Qt(t,e);{const i=Ft(Vt({x:t.x-e.x,y:t.y-e.y},s)/n);return Qt(t,{x:e.x+s.x*i,y:e.y+s.y*i})}},te=(t,e)=>qt(Kt(t,e)),ee=(t,e)=>qt(Qt(t,e)),ie=(t,e)=>Jt(t,e,Kt),se=(t,e)=>({...Jt(t,e,Kt),intersects:e.isPointInside(t)}),ne=(t,e)=>qt(se(t,e)),oe=(t,e)=>Zt(Kt(e,t)),re=(t,e)=>{const{a:i,b:s}=t,n={x:s.x-i.x,y:s.y-i.y},o=Vt(n,n);if(0===o)return Kt(i,e);{const{a:r,b:a}=e,h={x:a.x-r.x,y:a.y-r.y},l=Vt(h,h);if(0===l)return oe(t,s);{const t={x:i.x-r.x,y:i.y-r.y},e=Vt(h,t),s=Vt(n,t),a=Vt(n,h),c=o*l-a*a,d=Math.abs(c)>0?Ft((a*e-s*l)/c):0,u=Ft((a*d+e)/l),p=0===u?Ft(-s/o):1===u?Ft((a-s)/o):d;return Qt({x:i.x+n.x*p,y:i.y+n.y*p},{x:r.x+h.x*u,y:r.y+h.y*u})}}},ae=(t,e)=>qt(re(t,e)),he=(t,e)=>Jt(t,e,re),le=(t,e)=>Zt(te(e,t)),ce=(t,e)=>Zt(ae(e,t)),de=(t,e)=>Gt(ae(t,e)),ue=(t,e)=>Zt(fe(e,t)),pe=(t,e)=>Gt(he(t,e)),ge=(t,e)=>$t(he(t,e)),fe=(t,e)=>Gt(te(t,e)),ye=(t,e)=>Gt(se(t,e)),me=(t,e)=>pe(t.toCapsule(),e),ve=(t,e)=>Zt(he(e,t)),we=(t,e)=>Jt(t,e,ve),be=(t,e)=>Zt(se(e,t)),xe=(t,e)=>qt(ve(t,e)),_e=(t,e)=>qt(be(t,e)),Ce=(t,e)=>xe(t,e.toCapsule()),ke=(t,e)=>qt(we(t,e)),Ee=(t,e)=>$t(ve(t,e)),Ae=(t,e)=>Gt(we(t,e)),Se={capsule:{point:le,segment:ce,capsule:de,circle:ue,ellipse:(t,e)=>de(t,e.toCapsule()),polygon:pe,polyline:pe,rectangle:pe,roundedRectangle:ge},circle:{point:(t,e)=>Zt(ee(e,t)),segment:(t,e)=>Gt(Kt(t,e)),capsule:fe,circle:(t,e)=>Gt(ee(t,e)),ellipse:(t,e)=>fe(t,e.toCapsule()),polygon:ye,polyline:(t,e)=>Gt(ie(t,e)),rectangle:ye,roundedRectangle:(t,e)=>$t(se(t,e))},ellipse:{point:(t,e)=>le(t.toCapsule(),e),segment:(t,e)=>ce(t.toCapsule(),e),capsule:(t,e)=>de(t.toCapsule(),e),circle:(t,e)=>ue(t.toCapsule(),e),ellipse:(t,e)=>de(t.toCapsule(),e.toCapsule()),polygon:me,polyline:me,rectangle:me,roundedRectangle:(t,e)=>ge(t.toCapsule(),e)},polygon:{point:be,segment:ve,capsule:xe,circle:_e,ellipse:Ce,polygon:we,polyline:we,rectangle:we,roundedRectangle:ke},polyline:{point:(t,e)=>Zt(ie(e,t)),segment:ve,capsule:xe,circle:(t,e)=>qt(Zt(ie(e,t))),ellipse:Ce,polygon:we,polyline:we,rectangle:we,roundedRectangle:ke},point:{point:Qt,segment:Kt,capsule:te,circle:ee,ellipse:(t,e)=>te(t,e.toCapsule()),polygon:se,polyline:ie,rectangle:se,roundedRectangle:ne},rectangle:{point:be,segment:ve,capsule:xe,circle:_e,ellipse:Ce,polygon:we,polyline:we,rectangle:we,roundedRectangle:ke},roundedRectangle:{point:(t,e)=>Zt(ne(e,t)),segment:(t,e)=>Gt(ve(t,e)),capsule:Ee,circle:(t,e)=>qt(Zt(qt(se(e,t)))),ellipse:(t,e)=>Ee(t,e.toCapsule()),polygon:Ae,polyline:Ae,rectangle:Ae,roundedRectangle:(t,e)=>$t(we(t,e))},segment:{point:oe,segment:re,capsule:ae,circle:(t,e)=>qt(oe(t,e)),ellipse:(t,e)=>ae(t,e.toCapsule()),polygon:he,polyline:he,rectangle:he,roundedRectangle:(t,e)=>qt(he(t,e))}},Me={circle:(t,e)=>{const{radius:i}=t,{scale:n=1}=e,{x:o,y:r}=Wt(t,e);return new s(o,r,i*n)},ellipse:(t,e)=>{const{halfHeight:i,halfWidth:s}=t,{scale:n=1}=e,{x:o,y:a}=Wt(t,e);return new r(o,a,s*n,i*n)},point:(t,e)=>{const{x:i,y:s}=Wt(t,e);return new c(i,s)},polygon:(t,{local:e=!0,scale:i=1})=>new d(t.toArray1D(e).map(t=>t*i)),rectangle:(t,e)=>{const{height:i,width:s}=t,{scale:n=1}=e,{x:o,y:r}=Wt(t,e);return new u(o,r,s*n,i*n)},roundedRectangle:(t,e)=>{const{height:i,radius:s,width:n}=t,{scale:o=1}=e,{x:r,y:a}=Wt(t,e);return new g(r,a,n*o,i*o,s*o)}};function Te(t,e={}){const{type:i}=t,s=Me[i];return s?s(t,e):(platypus.debug.warn(`Unable to cast shape of type "${i}" to Pixi Shape.`,t),null)}const Ue=(t,{fill:e,stroke:i})=>("number"==typeof e&&t.fill(e),"number"==typeof i&&t.stroke(i),t),Pe=({graphics:t})=>t??new a,Oe={circle:(t,e)=>{const i=Pe(e),{radius:s}=t,{scale:n=1}=e,{x:o,y:r}=Wt(t,e);return i.circle(o,r,s*n),Ue(i,e)},ellipse:(t,e)=>{const i=Pe(e),{halfHeight:s,halfWidth:n}=t,{scale:o=1}=e,{x:r,y:a}=Wt(t,e);return i.ellipse(r,a,n*o,s*o),Ue(i,e)},point:(t,e)=>{const i=Pe(e),{scale:s=1}=e,{x:n,y:o}=Wt(t,e);return i.circle(n,o,s),Ue(i,e)},polygon:(t,e)=>{const i=Pe(e);return i.poly(t.points.map(t=>Wt(t,e)),!0),Ue(i,e)},polyline:(t,e)=>{const i=Pe(e);return i.poly(t.points.map(t=>Wt(t,e)),!1),Ue(i,e)},rectangle:(t,e)=>{const i=Pe(e),{height:s,width:n}=t,{scale:o=1}=e,{x:r,y:a}=Wt(t,e);return i.rect(r,a,n*o,s*o),Ue(i,e)},roundedRectangle:(t,e)=>{const i=Pe(e),{height:s,radius:n,width:o}=t,{scale:r=1}=e,{x:a,y:h}=Wt(t,e);return i.filletRect(a,h,o*r,s*r,-n*r),Ue(i,e)}};function Le(t,e={}){const{type:i}=t,s=Oe[i];return s?s(t,e):(platypus.debug.warn(`Unable to cast shape of type "${i}" to Pixi Graphics.`,t),null)}const ze=t=>{const{b2DefaultShapeDef:e}=platypus.game.box2d;if(t instanceof e)return t;{const{density:i=1,enableContactEvents:s=!1,enableHitEvents:n=!1,enablePreSolveEvents:o=!1,enableSensorEvents:r=!1,filter:a,invokeContactCreation:h=!1,isSensor:l=!1,material:c,updateBodyMass:d=!0}=t,u=new e;return a&&(u.filter.categoryBits=a.categoryBits??0,u.filter.groupIndex=a.groupIndex??0,u.filter.maskBits=a.maskBits??65535),c&&(u.material.customColor=c.customColor??0,u.material.friction=c.friction??.5,u.material.restitution=c.restitution??.2,u.material.rollingResistance=c.rollingResistance??0,u.material.tangentSpeed=c.tangentSpeed??0,u.material.userMaterialId=c.userMaterialId??0),u.density=i,u.enableContactEvents=s,u.enableHitEvents=n,u.enablePreSolveEvents=o,u.enableSensorEvents=r,u.invokeContactCreation=h,u.isSensor=l,u.updateBodyMass=d,u}},Be=(t,e)=>{const{bodyId:i,scale:s=1,shapeDefinition:n}=e,{b2Capsule:o,b2CreateCapsuleShape:r}=platypus.game.box2d,{radius:a,a:h,b:l}=t,{x:c,y:d}=Wt(h,e),{x:u,y:p}=Wt(l,e),g=new o;return g.radius=a*s,g.center1.Set(c,d),g.center2.Set(u,p),r(i,ze(n),g)},Ie=(t,e)=>{const i=new platypus.game.box2d.b2Vec2,{x:s,y:n}=Wt(t,e);return i.x=s,i.y=n,i},De=(t,e)=>{const{chain:i=!1,shapeDefinition:s}=e;if(i)return Xe(t,{...e,shapeDefinition:{...s,isLoop:!0}});{const{bodyId:i,local:s=!0,radius:n=0,scale:o=1,shapeDefinition:r}=e,{b2CreatePolygonShape:a,b2ComputeHull:h,b2MakePolygon:l}=platypus.game.box2d;return t.split(3,8).map(({points:t})=>a(i,ze(r),l(h(t.map(t=>Ie(t,{local:s,scale:o})),t.length),n)))}},Xe=({points:t},{bodyId:e,local:i=!0,scale:s=1,shapeDefinition:n})=>{const{b2CreateChain:o}=platypus.game.box2d;return o(e,(t=>{const{b2DefaultChainDef:e}=platypus.game.box2d;if(t instanceof e)return t;{const{enableSensorEvents:i=!1,filter:s,isLoop:n=!1,materials:o,points:r}=t,a=new e;return s&&(a.filter.categoryBits=s.categoryBits??0,a.filter.groupIndex=s.groupIndex??0,a.filter.maskBits=s.maskBits??65535),a.SetMaterials(o),a.SetPoints(r),a.enableSensorEvents=i,a.isLoop=n,a}})({...n,points:t.map(t=>Ie(t,{local:i,scale:s}))}))},Re={capsule:Be,circle:(t,e)=>{const{radius:i}=t,{bodyId:s,scale:n=1,shapeDefinition:o}=e,{b2Circle:r,b2CreateCircleShape:a}=platypus.game.box2d,{x:h,y:l}=Wt(t,e),c=new r;return c.radius=i*n,c.center.Set(h,l),a(s,ze(o),c)},ellipse:(t,...e)=>Be(t.toCapsule(),...e),point:Ie,polygon:De,polyline:Xe,rectangle:De,roundedRectangle:De,segment:({a:t,b:e},i)=>{const s=new platypus.game.box2d.b2Segment,{x:n,y:o}=Wt(t,i),{x:r,y:a}=Wt(e,i);return s.point1.x=n,s.point1.y=o,s.point2.x=r,s.point2.y=a,s}};function je(t,e={}){const{type:i}=t,s=Re[i];return s?s(t,e):(platypus.debug.warn(`Unable to cast shape of type "${i}" to Box2D.`,t),null)}const Ye=2*Math.PI;class Ne{constructor(t){this.type="point",this.registration=new Ht,this.initialize(t)}get rotation(){return this.revolutions*Ye%Ye}set rotation(t){this.revolutions=t/Ye}get x(){return this.registration.x}set x(t){this.moveX(t)}get y(){return this.registration.y}set y(t){this.moveY(t)}initialize({revolutions:t,rotation:e=0,x:i=0,y:s=0}){this.moveX(i),this.moveY(s),this.revolutions=t??e/Ye}toBox2D(...t){return je(this,...t)}toJSON(t,...e){return JSON.stringify(this.toObject(t),...e)}toObject(t){const{type:e}=this;return{type:e,...Wt(this,t)}}toPixiShape(...t){return Te(this,...t)}toPixiGraphics(...t){return Le(this,...t)}move({x:t,y:e}){this.moveX(t),this.moveY(e)}moveX(t){this.registration.x=t}moveY(t){this.registration.y=t}shift({x:t,y:e}){this.shiftX(t),this.shiftY(e)}shiftX(t){this.moveX(this.x+t)}shiftY(t){this.moveY(this.y+t)}checkVisibility(t){const e=t.reduce((t,e)=>{const{segments:i}=e;return i?t.push(...i):t.push(e),t},[]);return e.filter(t=>{const i=t.a&&t.b?{x:(t.a.x+t.b.x)/2,y:(t.a.y+t.b.y)/2}:t;return!e.some(e=>t!==e&&e.intersects?.({a:this,b:i}))})}getClosestPoints(t,e){let i=null;if(e?.x??e?.y){const s=t.duplicate();s.shift(e),i=Se[s.type]?.[this.type]?.(s,this)??null}else i=Se[t.type]?.[this.type]?.(t,this)??null;return i||platypus.debug.warn(`No closest point support for "${Se[t.type]?this.type:t.type}" shapes.`),i}duplicate(){return new Ne(this)}getRadians(){return this.revolutions*Ye}getDegrees(){return 360*this.revolutions}getSinCos(){const{rotation:t}=this;return{sin:Math.sin(t),cos:Math.cos(t)}}toArray(t=!1){if(t){const{registration:{x:t,y:e}}=this;return[t,e]}{const{x:t,y:e}=this;return[t,e]}}static validateDefinition({x:t,y:e}={}){return"number"==typeof t&&"number"==typeof e&&!isNaN(t)&&!isNaN(e)}}class We extends Ne{constructor(...t){super(...t),this.type="circle"}initialize(t){super.initialize(t),this.radius=t.radius??0}duplicate(){return new We(this)}isPointInside({x:t,y:e},i=1e-6){const{registration:s}=this,n=t-s.x,o=e-s.y;return n*n+o*o<=(this.radius+i)**2}toObject(t){const{radius:e,type:i}=this,{scale:s=1}=t;return{radius:e*s,type:i,...Wt(this,t)}}static validateDefinition({radius:t}={}){return"number"==typeof t&&t>0}}const He=1e-10;class Ve extends Ne{constructor(...t){super(...t),this.type="segment",this._points=null,this._revolutions=0}get a(){return this.points[0]}get b(){return this.points[this.points.length-1]}get points(){if(!this._points){const{revolutions:t,x:e,y:i}=this;if(t%1){const{cos:t,sin:s}=this.getSinCos();this._points=this._vectors.map(({x:n,y:o})=>new Ne({x:e+n*t-o*s,y:i+n*s+o*t}))}else this._points=this._vectors.map(({x:t,y:s})=>new Ne({x:e+t,y:i+s}))}return this._points}get revolutions(){return this._revolutions}set revolutions(t){this._revolutions!==t&&(this._points=null,this._revolutions=t)}get vectors(){return this._vectors}initialize(t){const{a:e,b:i,points:s,revolutions:n=0,x:o=0,y:r=0}=t;if(super.initialize(t),n%1){const{cos:t,sin:n}=this.getSinCos();this._vectors=(s??[e,i]).map(e=>Array.isArray(e)?new Ht(e[0]*t+e[1]*n-o,-e[0]*n+e[1]*t-r):new Ht(e.x*t+e.y*n-o,-e.x*n+e.y*t-r))}else this._vectors=(s??[e,i]).map(t=>Array.isArray(t)?new Ht(t[0]-o,t[1]-r):new Ht(t.x-o,t.y-r))}getLength(){const{a:t,b:e}=this;return Math.hypot(e.x-t.x,e.y-t.y)}intersects({a:t,b:e}){const i=(t,e,i)=>(i.y-t.y)*(e.x-t.x)>(e.y-t.y)*(i.x-t.x),{a:s,b:n}=this;return i(s,t,e)!==i(n,t,e)&&i(s,n,t)!==i(s,n,e)}getIntersection(t,{intersectsLine:e=!1,segmentIsLine:i=!1}){const{a:s,b:n}=this,{a:o,b:r}=t,a=s.x-n.x,h=s.y-n.y,l=o.x-r.x,c=o.y-r.y,d=a*c-h*l;if(Math.abs(d)<He)return null;{const u=(t,e,i)=>(t.x-e.x)*i.x+(t.y-e.y)*i.y,p=s.x*n.y-s.y*n.x,g=o.x*r.y-o.y*r.x,f=new Ne({x:(p*l-a*g)/d,y:(p*c-h*g)/d});if(!e){const t=this.getVector(),e=u(f,s,t),i=Math.min(0,u(n,s,t)),o=Math.max(0,u(n,s,t));if(t.recycle(),e<i-He||e>o+He)return null}if(!i){const e=t.getVector(),i=u(f,o,e),s=Math.min(0,u(r,o,e)),n=Math.max(0,u(r,o,e));if(e.recycle(),i<s-He||i>n+He)return null}return f}}getVector(){const{a:t,b:e}=this;return Ht.setUp(e.x-t.x,e.y-t.y)}duplicate(){return new Ve(this)}moveX(t){super.moveX(t),this._points=null}moveY(t){super.moveY(t),this._points=null}reflect(t){const{a:e,b:i}=this,s=Ht.setUp(i.x-e.x,i.y-e.y),n=Ht.setUp(t.x-e.x,t.y-e.y),o=(s.x*n.x+s.y*n.y)/(s.x*s.x+s.y*s.y),r=Ht.setUp(e.x+o*s.x,e.y+o*s.y),a=new Ne({x:2*r.x-t.x,y:2*r.y-t.y});return s.recycle(),n.recycle(),r.recycle(),a}isCollinear(t,{epsilon:e=1e-10}={}){const{a:i,b:s}=this,{a:n,b:o}=t,r=(t,e,i)=>(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y),a=r(n,o,i),h=r(n,o,s);return Math.abs(a)<e&&Math.abs(h)<e}bisect(t,e){const{a:i,b:s}=this,{a:n,b:o}=t,r=t.getVector(),a=(t,e,i)=>(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y),h=a(n,o,i),l=a(n,o,s);if(Math.abs(h)<He&&Math.abs(l)<He){const t=t=>(t.x-n.x)*r.x+(t.y-n.y)*r.y,e=t(i),a=t(s),h=t(n),l=t(o),c=Math.min(h,l),d=Math.max(h,l),u=Math.min(e,a),p=Math.max(e,a);if(p<c)return[this,null];if(u>d)return[null,this];if(u>=c&&p<=d)return[null,null];{const t=r.x*r.x+r.y*r.y;return[e<c?new Ve({a:i,b:{x:n.x+c/t*r.x,y:n.y+c/t*r.y}}):null,a>d?new Ve({a:{x:n.x+d/t*r.x,y:n.y+d/t*r.y},b:s}):null]}}if(h>-1e-10&&l>-1e-10)return[this,null];if(h<He&&l<He)return[null,this];{const n=this.getIntersection(t,e);if(n){const t=new Ve({a:i,b:n}),e=new Ve({a:n,b:s});return h>0?[t,e]:[e,t]}return h>0?[this,null]:[null,this]}}toArray(t=!1){return t?this.vectors.map(({x:t,y:e})=>new Ht(t,e)):this.points.map(({x:t,y:e})=>new Ne({x:t,y:e}))}toArray1D(t=!1){return t?this.vectors.reduce((t,{x:e,y:i})=>(t.push(e,i),t),[]):this.points.reduce((t,{x:e,y:i})=>(t.push(e,i),t),[])}toArray2D(t=!1){return t?this.vectors.map(({x:t,y:e})=>[t,e]):this.points.map(({x:t,y:e})=>[t,e])}toObject(t){const{a:e,b:i,type:s}=this;return{a:adjustedXY(e,t),b:adjustedXY(i,t),type:s}}static validateDefinition({a:t,b:e,points:i}={}){const s=i??[t,e];if(2!==s.length)return!1;{const t=Array.isArray(s[0])?{x:s[0][0],y:s[0][1]}:s[0],e=Array.isArray(s[1])?{x:s[1][0],y:s[1][1]}:s[1];return Ne.validateDefinition(t)&&Ne.validateDefinition(e)&&(t.x!==e.x||t.y!==e.y)}}}class Fe extends Ve{constructor(...t){super(...t),this.type="polyline",this._segments=null}get loop(){return this._loop}set loop(t){const e=!!t;e!==this._loop&&(this._loop=e,this._segments=null)}get segments(){if(!this._segments){const{points:t}=this,e=[];for(let i=0;i<t.length-1;i++)e.push(new Ve({a:t[i],b:t[i+1]}));this.loop&&e.push(new Ve({a:t[t.length-1],b:t[0]})),this._segments=e}return this._segments}initialize(t){super.initialize(t),this._loop=t.loop??!1}forEach(t){this.segments.forEach(t)}getLength(){return this.segments.reduce((t,e)=>t+e.getLength(),0)}duplicate(){return new Fe(this)}toObject(t){const{points:e,type:i}=this;return{points:e.map(e=>adjustedXY(e,t)),type:i}}static validateDefinition({points:t}={}){const{length:e=0}=t??[];if(e<2)return!1;for(let i=0;i<e;i++){const e=t[i];if(!Ne.validateDefinition(Array.isArray(e)?{x:e[0],y:e[1]}:e))return!1}return!0}}class Ze extends Fe{constructor(...t){super(...t),this.type="polygon"}get loop(){return!0}set loop(t){if(!t)throw new Error("Polygon shapes are comprised of a loop of segments.")}initialize(t){super.initialize(t),this._loop=!0}isPointInside({x:t,y:e}){const{points:i}=this;let s=!1;for(let n=0,o=i.length-1;n<i.length;o=n++){const r=i[n],a=i[o];r.y>e!=a.y>e&&t<(a.x-r.x)*(e-r.y)/(a.y-r.y)+r.x&&(s=!s)}return s}duplicate(){return new Ze(this)}decompose(){const t=platypus.game.options.modules?.["poly-decomp"],e=this.toArray2D(!0);return t?.isSimple(e)?t.quickDecomp(e).map(t=>new Ze({points:t})):null}split(t=3,e=8){const i=t+e-2,s=[],n=this.decompose()??[this];let o=0;return n.forEach(t=>{const n=[...t.points];let{length:r}=n;for(;r>e;){const t=(r>=i?e:Math.ceil(r/2))-2,a=n.splice((o-1)*t,o?t:1/0);a.push(n[n.length-1],n[0]),s.push(new Ze({points:a})),o=1-o,r=n.length}s.push(new Ze({points:n}))}),s}static validateDefinition(t={}){const{points:e}=t,{length:i=0}=e??[];return!(i<3)&&Fe.validateDefinition(t)}}const Ge=1e-4;class qe extends Ze{constructor(...t){super(...t),this.type="rectangle"}get halfHeight(){return this.height/2}set halfHeight(t){this.height=2*t}get halfWidth(){return this.width/2}set halfWidth(t){this.width=2*t}initialize(t){const{anchor:{x:e,y:i}={x:0,y:0},height:s,width:n,x:o=0,y:r=0}=t,a=o-e*n,h=r-i*s,l=o+(1-e)*n,c=r+(1-i)*s;this.width=n,this.height=s,super.initialize({...t,points:[{x:a,y:h},{x:l,y:h},{x:l,y:c},{x:a,y:c}]})}duplicate(){return new qe(this)}static validateDefinition({height:t,width:e,points:i}={}){return"number"==typeof t&&t>0&&"number"==typeof e&&e>0&&(!i||4===i.length&&(({x:t,y:e},{x:i,y:s},{x:n,y:o},{x:r,y:a})=>{const h=t=>t*t,l=(t+i+n+r)/4,c=(e+s+o+a)/4,d=h(l-t)+h(c-e),u=h(l-i)+h(c-s),p=h(l-n)+h(c-o),g=h(l-r)+h(c-a);return Math.abs(d-u)<Ge&&Math.abs(d-p)<Ge&&Math.abs(d-g)<Ge})(...i))}}const $e={x:{axis:"x",alt:"y",length:"width",breadth:"height"},y:{axis:"y",alt:"x",length:"height",breadth:"width"}};class Je extends Ve{constructor(...t){super(...t),this.type="capsule"}initialize(t){if(t.points||t.a&&t.b||!t.width||!t.height)super.initialize(t),this.radius=t.radius??0;else{const{alt:e,axis:i,breadth:s,length:n}=$e[t.width>t.height?"x":"y"],o=t[s]/2,r=(t[n]-2*o)/2;super.initialize({...t,a:{[i]:-r,[e]:0},b:{[i]:r,[e]:0}}),this.radius=o}}duplicate(){return new Je(this)}toObject(t){const{a:e,b:i,radius:s,type:n}=this,{scale:o=1}=t;return{a:Wt(e,t),b:Wt(i,t),radius:s*o,type:n}}static validateDefinition(t){return qe.validateDefinition(t)||We.validateDefinition(t)&&Ve.validateDefinition(t)}}class Qe extends Ve{constructor(...t){super(...t),this.type="ellipse"}get halfHeight(){return this.height/2}set halfHeight(t){this.height=2*t}get halfWidth(){return this.width/2}set halfWidth(t){this.width=2*t}initialize(t){const{a:e,b:i,height:s,points:n,width:o}=t;if(n||e&&i)super.initialize(t);else{const e=o/2,i=s/2;if(o>s){const s=Math.sqrt(e*e-i*i);super.initialize({...t,a:{x:-s,y:0},b:{x:s,y:0}})}else{const s=Math.sqrt(i*i-e*e);super.initialize({...t,a:{x:0,y:-s},b:{x:0,y:s}})}}this.height=s,this.width=o,Object.defineProperties(this,{constantSumOfDistances:{get(){return Math.max(this.width,this.height)}}})}toCapsule(){const{a:t,b:e,constantSumOfDistances:i,width:s,height:n}=this,o=s>n?n/2:s/2,r=(i-o-o)/this.getLength();return new Je({a:{x:t.x*r,y:t.y*r},b:{x:e.x*r,y:e.y*r},radius:o})}duplicate(){return new Qe(this)}toObject(t){const{a:e,b:i,height:s,radius:n,type:o,width:r}=this,{scale:a=1}=t;return{a:Wt(e,t),b:Wt(i,t),height:s*a,radius:n*a,type:o,width:r*a}}static validateDefinition(t){return qe.validateDefinition(t)}}class Ke extends qe{constructor(...t){super(...t),this.type="roundedRectangle"}initialize(t){super.initialize(t),this.radius=t.radius}duplicate(){return new Ke(this)}toObject(t){const{radius:e}=this,{scale:i}=t;return{...super.toObject(t),radius:e*i}}static validateDefinition(t){return We.validateDefinition(t)&&qe.validateDefinition(t)}}const ti={capsule:Je,circle:We,ellipse:Qe,polygon:Ze,polyline:Fe,rectangle:qe,roundedRectangle:Ke,segment:Ve,point:Ne};function ei(t,e=["roundedRectangle","rectangle","capsule","ellipse","segment","polygon","polyline","circle","point"]){const{type:i}=t;if(i&&e.indexOf(i)>=0){const e=ti[i];if(e?.validateDefinition(t))return new e(t)}else{const{length:i}=e;for(let s=0;s<i;s++){const i=ti[e[s]];if(i?.validateDefinition(t))return new i(t)}}return platypus.debug.warn("Unable to create a shape matching provided data.",t),null}const ii=["circle","capsule","segment","polygon","segment"],si={circle:(t,{scale:e=1}={})=>{const{radius:i,center:{x:s,y:n}}=platypus.game.box2d.b2Shape_GetCircle(t);return{radius:i*e,type:"circle",x:s*e,y:n*e}},capsule:(t,{scale:e=1}={})=>{const{radius:i,center1:{x:s,y:n},center2:{x:o,y:r}}=platypus.game.box2d.b2Shape_GetCapsule(t);return{a:{x:s*e,y:n*e},b:{x:o*e,y:r*e},radius:i*e,type:"capsule"}},segment:(t,{scale:e=1}={})=>{const{point1:{x:i,y:s},point2:{x:n,y:o}}=platypus.game.box2d.b2Shape_GetSegment(t);return{a:{x:i*e,y:s*e},b:{x:n*e,y:o*e},type:"segment"}},polygon:(t,{scale:e=1}={})=>{const i=platypus.game.box2d.b2Shape_GetPolygon(t),{count:s,radius:n}=i,o=[];for(let t=0;t<s;t++){const{x:s,y:n}=i.GetVertex(t);o.push({x:s*e,y:n*e})}return{points:o,radius:n*e,type:"polygon"}}};function ni(t,e){const{b2Shape_GetType:i}=platypus.game.box2d,s=ii[i(t).value];return s?ei(si[s](t,e)):(platypus.debug.warn(`Unable to cast shape of type "${s}" from Box2D.`,s),null)}function oi(){return platypus.debug.warn("Unable to cast from Pixi Graphics."),null}const ri={circle:(t,{scale:e=1})=>{const{radius:i,type:s,x:n,y:o}=t;return{radius:i*e,type:s,x:n*e,y:o*e}},ellipse:(t,{scale:e=1})=>{const{halfHeight:i,halfWidth:s,type:n,x:o,y:r}=t;return{height:2*i*e,type:n,width:2*s*e,x:o*e,y:r*e}},point:(t,{scale:e=1})=>{const{x:i,y:s}=t;return{type:"point",x:i*e,y:s*e}},polygon:(t,{scale:e=1})=>{const{closePath:i,points:s}=t;return{type:i?"polygon":"polyline",points:s.map(({x:t,y:i})=>({x:t*e,y:i*e}))}},rectangle:(t,{scale:e=1})=>{const{height:i,type:s,width:n,x:o,y:r}=t;return{height:i*e,type:s,width:n*e,x:o*e,y:r*e}},roundedRectangle:(t,{scale:e=1})=>{const{height:i,radius:s,type:n,width:o,x:r,y:a}=t;return{height:i*e,radius:s*e,type:n,width:o*e,x:r*e,y:a*e}}};function ai(t,e){const{type:i}=t,s="string"==typeof i?ri[i]:ri.point;return s?ei(s(t,e)):(platypus.debug.warn(`Unable to cast shape of type "${i}" from Box2D.`,t),null)}const hi={},li=xt({id:"Interactive",properties:{container:null,hitArea:null,hover:!1,relativeToSelf:!1,trackCameraUpdates:!1},publicProperties:{buttonMode:!1},initialize:function(){this.pressed=null,this.hitArea&&(this.container.hitArea=this.setHitArea(this.hitArea)),this.buttonMode&&platypus.debug.warn('Interactive: "buttonMode" is deprecated. Set "cursor" to "pointer" on the entity instead.'),this.dragOver=!1},events:{"dispatch-event":function(t){this.sprite.dispatchEvent(this.sprite,t.event,t.data)},"camera-update":function(){this.dragOver&&this.dragOver()},"input-on":function(){this.removeInputListeners||this.addInputs()},"input-off":function(){this.removeInputListeners&&(this.pressed&&this.handlePressUp(this.pressed),this.removeInputListeners())},pointerdown:function(t){null===this.pressed&&(this.pressed=H.setUp(t))},pointermove:function(t){this.pressed?.pixiEvent?.pointerId===t.pixiEvent.pointerId&&(this.owner.triggerEvent("pressmove",t),this.pressed.recycle(),this.pressed=H.setUp(t))},pointerup:function(t){this.handlePressUp(t)},pointerupoutside:function(t){this.handlePressUp(t)},pointercancel:function(t){this.handlePressUp(t)},"set-hit-area":function(t){this.container.hitArea=this.setHitArea(t)}},methods:{addInputs(){const t=this.container,e=V.setUp(),i=(i,s)=>{t.addListener(i,s),e.push(()=>{t.removeListener(i,s)})},s=(t,e,i)=>{const{container:s}=t;if(s&&i.data.originalEvent){s.getBounds();const{owner:n,relativeToSelf:o}=t,r=n.worldCamera?.viewport??n.parent.worldCamera.viewport,a=o?s.worldTransform:s.parent.worldTransform,h=H.setUp("event",i.data.originalEvent,"pixiEvent",i,"x",i.data.global.x/a.a+r.left,"y",i.data.global.y/a.d+r.top,"entity",n);n.trigger(e,h),h.recycle()}};if(t.eventMode="static",i("pointerdown",t=>{s(this,"pointerdown",t),t.currentTarget.mouseTarget=!0}),i("pointerup",t=>{s(this,"pointerup",t),t.currentTarget.mouseTarget=!1,t.currentTarget.removeDisplayObject&&t.currentTarget.removeDisplayObject()}),i("pointerupoutside",t=>{s(this,"pointerupoutside",t),t.currentTarget.mouseTarget=!1,t.currentTarget.removeDisplayObject&&t.currentTarget.removeDisplayObject()}),i("pointercancel",t=>{s(this,"pointercancel",t),t.currentTarget.mouseTarget=!1,t.currentTarget.removeDisplayObject&&t.currentTarget.removeDisplayObject()}),i("pointermove",t=>{s(this,"pointermove",t),t.currentTarget.mouseTarget=!0}),i("pointertap",t=>{s(this,"pointertap",t)}),this.hover&&(i("pointerover",t=>{s(this,"pointerover",t)}),i("pointerout",t=>{s(this,"pointerout",t)})),this.trackCameraUpdates){const t=t=>{n&&(n=t)};let n=null;this.dragOver=()=>{n&&s(this,"pointermove",n)},i("pointerover",t=>n=t),i("pointerdown",t),i("pointermove",t),i("pointerout",()=>n=null),e.push(()=>{n=null,this.dragOver=null})}this.removeInputListeners=()=>{for(let t=0;t<e.length;t++)e[t]();V.recycle(e),t.eventMode="auto",this.removeInputListeners=null}},setHitArea(t){if(t){let e="",i=null;try{e=JSON.stringify(t),i=hi[e]}catch(t){}return i||(i=Te(ei(Array.isArray(t)?{type:"polygon",points:t}:t)),e&&(hi[e]=i)),i}return null},handlePressUp(t){this.pressed?.pixiEvent?.pointerId===t.pixiEvent.pointerId&&(this.owner.triggerEvent("pressup",t),this.pressed.recycle(),this.pressed=null)},toJSON:()=>null,destroy(){const{container:t,removeInputListeners:e}=this;e&&e(),t.mouseTarget&&t.parent&&(t.visible=!1,t.removeDisplayObject=()=>{t.parent&&t.parent.removeChild(t),this.container=null})}}}),ci=xt({id:"AIChaser",properties:{accelerate:!1,chasing:!0},publicProperties:{speed:.3},initialize:function(){this.target=this.owner.target||null,this.offset=Ht.setUp(0,0),this.state=this.owner.state,this.state.set("chasing",!1)},events:{load:function(){this.owner.addMover?this.direction=this.owner.addMover({vector:[this.speed,0,0],event:"chase",accelerator:this.accelerate}).vector:platypus.debug.warn('The "AIChaser" component requires a "Mover" component to function correctly.')},"handle-ai":function(){let t=!1;if(this.target&&this.chasing){const e=Ht.setUp(this.offset).add(this.target.position).subtractVector(this.owner.position);e.magnitude(2)&&(t=!0,this.direction.setVector(e).normalize().multiply(this.speed)),e.recycle()}t!==this.state.get("chasing")&&(this.state.set("chasing",t),this.owner.triggerEvent("chase",t))},"set-target":function(t){this.target=t,this.offset.x=0,this.offset.y=0},"set-target-offset":function(t){this.offset.x=t.x,this.offset.y=t.y},"start-chasing":function(t){t&&(this.target=t),this.chasing=!0},"stop-chasing":function(){this.chasing=!1}},methods:{destroy:function(){this.target=null,this.offset.recycle(),this.state=null}}}),di=xt({id:"AIPacer",properties:{movement:"both",direction:null},initialize:function(){this.lastDirection="",this.currentDirection=this.direction||("horizontal"===this.movement?"left":"up")},events:{"handle-ai":function(){this.currentDirection!==this.lastDirection&&(this.lastDirection=this.currentDirection,this.owner.triggerEvent("stop"),this.owner.triggerEvent("go-"+this.currentDirection))},"turn-around":function(t){"both"!==this.movement&&"horizontal"!==this.movement||(t.x>0?this.currentDirection="left":t.x<0&&(this.currentDirection="right")),"both"!==this.movement&&"vertical"!==this.movement||(t.y>0?this.currentDirection="up":t.y<0&&(this.currentDirection="down"))}}}),ui=t=>-1===t.indexOf(".mp3")?`${t}.mp3`:t,pi={},gi=xt({id:"AudioMusic",properties:{tracks:null,fade:1e3},initialize:function(){this.player=platypus.game.musicPlayer,this.changeMusicTracks(this.tracks)},events:{"change-music-tracks":function(t){this.changeMusicTracks(t)}},methods:{changeMusicTracks(t){const{player:e}=this,i=Object.keys(pi),{fade:s}=this;if(t){const n=Object.keys(t),{length:o}=n;for(let r=0;r<o;r++){const o=n[r],a=i.indexOf(o),h=t[o];if(!1!==h.autoStart){let t=pi[o],n=h.fade??s;a>=0?G(i,a):t=pi[o]=this.player.play(h.sound||h,{loop:1/0,volume:n?0:"number"==typeof h.volume?h.volume:1}),n&&e.fade(t,"number"==typeof h.volume?h.volume:1,n)}}}i.forEach(t=>{const i=pi[t];e.fade(i,0,s,()=>{e.stop(i)}),delete pi[t]})}},getAssetList:function(t,e,i){const s=V.setUp(),n=t?.tracks??e?.tracks??i?.tracks;if(n){const t=Object.keys(n),{length:e}=t;for(let i=0;i<e;i++){const e=n[t[i]],o=ui(e.sound??e);-1===s.indexOf(o)&&s.push(o)}}return s}}),fi=t=>-1===t.indexOf(".mp3")?`${t}.mp3`:t,yi={interrupt:0,delay:0,start:0,loop:0,volume:1,pan:0,muted:!1,speed:1,playthrough:!1},mi=function(t){let e="",i=null;return"string"==typeof t?(e=t,i={}):(e=t.sound,i={...t},delete i.sound),e=platypus.assetCache.getFileId(e),function(t){const s=platypus.assetCache.get(e),n=H.setUp({...yi,...i,...t});if(s){if(n.volume*=this.volume,n.loop&&"number"==typeof n.loop&&(n.loop>1&&(n.loopCount=n.loop),n.loop=n.loop>1||n.loop<0),n.pan&&(s.panFilter?s.panFilter.pan=n.pan:s.panFilter=new U.filters.StereoFilter(n.pan)),s.panFilter||this.autoPanFilter){const t=[];s.panFilter&&t.push(s.panFilter),this.autoPanFilter&&t.push(this.autoPanFilter),s.filters=t}if(n.audio=this.player.play(s,n),n.speed&&(n.audio.speed=n.speed),n.playthrough&&!n.loop?n.audio.playthrough=!0:n.audio.playthrough=!1,n.loopCount){let t=-1;n.audio.on("progress",e=>{e<t&&(console.log("LOOPED?",n.loopCount--),1===n.loopCount&&n.audio.set("loop",!1)),t=e})}if(n.audio.on("end",()=>{n.audio&&!this.owner.destroyed&&this.activeAudioClips&&(this.removeClip(n.audio),this.owner.triggerEvent("clip-complete")),n.recycle()}),n.audio.soundId=e,this.activeAudioClips.push(n.audio),"playFailed"===n.audio.playState){const t=function(i){i.id===e&&(n.audio.play(n),U.off("fileload",t))};U.on("fileload",t)}}else platypus.debug.warn(`The sound "${e}" is not a loaded asset.`)}},vi=xt({id:"AudioSFX",properties:{audioMap:null,autoPan:!1,forcePlayThrough:!0,eventBased:!0,stateBased:!1},initialize:function(){const t=this.audioMap;if(this.activeAudioClips=V.setUp(),this.state=this.owner.state,this.stateChange=!1,this.player=platypus.game.sfxPlayer,this.volume=1,t){const e=Object.keys(t),{length:i}=e;this.stateBased&&(this.checkStates=V.setUp());for(let s=0;s<i;s++){const i=e[s],n=t[i],o=mi(n);this.eventBased&&this.addEventListener(i,o),this.stateBased&&this.addStateCheck(i,n.sound??n,o)}}if(this.autoPan){const t={minimum:this.autoPan.minimum||0,maximum:this.autoPan.maximum||1,range:this.autoPan.range||-1,buffer:this.autoPan.buffer||0};let e=0;this.volume=t.maximum,this.autoPanFilter=new U.filters.StereoFilter(e),this.addEventListener("camera-update",function(i){const s=this.owner.x-i.viewport.x,n=Math.abs(s),o=s/n,r=-1===t.range?i.viewport.width:t.range;let a=0,h=1;n<=t.buffer?(a=0,h=t.maximum):n>t.buffer+r?(a=o,h=Math.max(t.minimum,Math.min(t.maximum,(t.buffer+2*r-n)/r))):(a=o*(n-t.buffer)/r,h=t.maximum),a!==e&&(this.autoPanFilter.pan=a,e=a),h!==this.volume&&this.owner.triggerEvent("set-volume",h)})}this.paused=!1},events:{"handle-render":function(){const t=this.state;if(!this.paused&&this.stateBased&&this.stateChange){const e=this.checkStates;let i=e.length;for(;i--;)e[i].check(t);this.stateChange=!1}},"state-changed":function(){this.stateChange=!0},"toggle-mute":function(t){this.handleClip(t,function(t){t&&(t.unmuted?(t.volume=t.unmuted,delete t.unmuted):(t.unmuted=t.volume,t.volume=0))})},"stop-audio":function(t){t?"string"==typeof t?this.stopAudio(t):this.stopAudio(t.audioId||!1,t.playthrough||!1):this.stopAudio()},"mute-audio":function(t){this.handleClip(t,function(t){t&&(t.unmuted=t.volume,t.volume=0)})},"unmute-audio":function(t){this.handleClip(t,function(t){t&&(t.volume=t.unmuted,delete t.unmuted)})},"pause-audio":function(t){this.handleClip(t,function(t){t&&t.pause()})},"unpause-audio":function(t){this.handleClip(t,function(t){t&&t.unpause()})},"set-pan":function(t,e=""){const i=e=>{e&&(e.pan=t)};e?this.handleClip(e,i):this.getAllClips(i)},"set-volume":function(t,e=""){const i=e=>{e&&(e.volume=t*this.player.volume)};e?this.handleClip(e,i):(this.volume=t,this.getAllClips(i))},"set-speed":function(t,e=""){const i=function(e){e&&(e.speed=t)};e?this.handleClip(e,i):this.getAllClips(i)}},methods:{handleClip:function(t,e){"string"==typeof t?this.getClipById(t,e):this.getAllClips(e)},getClipById:function(t,e=()=>{}){const i=this.activeAudioClips;for(let s=0;s<i.length;s++)if(i[s].soundId===t)return e(i[s]),i[s];return e(null),null},getAllClips:function(t=()=>{}){const e=this.activeAudioClips;for(let i=0;i<e.length;i++)t(e[i]);return e},stopAudio:function(t,e){const i=this.activeAudioClips;let s=i.length;if(t)for(;s--;)i[s].soundId===t&&((i[s].playthrough??e)||(this.player.stop(i[s]),G(i,s)));else{for(;s--;)(i[s].playthrough??e)||this.player.stop(i[s]);i.length=0}},removeClip:function(t){const e=this.activeAudioClips.indexOf(t);e>=0&&G(this.activeAudioClips,e)},addStateCheck:function(t,e,i){const s=mt.setUp(t),n=H.setUp("states",s,"playing",!1);n.check=t=>{const s=t.includes(n.states);s!==n.playing&&(s?i.call(this):this.stopAudio(e,this.forcePlaythrough),n.playing=s)},this.checkStates.push(n)},destroy:function(){const t=this.checkStates;if(this.stopAudio(),V.recycle(this.activeAudioClips),this.activeAudioClips=null,this.state=null,t){let e=t.length;for(;e--;){const i=t[e];i.states.recycle(),i.recycle()}V.recycle(t),this.checkStates=null}}},getAssetList:function(t,e,i){const s=V.setUp(),n=t?.audioMap??e?.audioMap??i?.audioMap;if(n){const t=Object.keys(n),{length:e}=t;for(let i=0;i<e;i++){const e=n[t[i]],o=fi(e.sound??e);-1===s.indexOf(o)&&s.push(o)}}return s}}),wi=t=>-1===t.indexOf(".mp3")?`${t}.mp3`:t,bi=xt({id:"AudioVO",properties:{audioMap:null,interrupt:!0,preloadAudio:"events"},initialize:function(){const t=this.audioMap;if(this.eventList=It.setUp(),this.playingAudio=0,this.stopping=!1,this.player=platypus.game.voPlayer,t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,this.playSound.bind(this,t[i]))}}this.paused=!1},events:{"handle-render":function(){!this.paused&&this.eventList&&this.checkTimeEvents(!1)},"play-voice-over":function(t){this.playSound(t)},"stop-audio":function(){this.player.stop(),this.player.voList=[]}},methods:{checkTimeEvents:function(t,e){const{eventList:i,owner:s}=this;if(i){const n=t?1/0:this.player.getElapsed(),o=i.getEvents(n);o.forEach(i=>{t&&!e&&i.interruptable||s.trigger(i),i.recycle()}),V.recycle(o)}},destroy:function(){this.playingAudio>0&&(this.stopping=!0,this.player.stop(!0),this.player.voList=[]),this.eventList&&(this.eventList.recycle(),this.eventList=null)},playSound:function(t,e){if(!this.stopping){const{owner:i,player:s}=this,n=t=>{this.playingAudio-=1,i.destroyed||(this.checkTimeEvents(!0,t),o.recycle(),this.eventList===o&&(this.eventList=null),i.triggerEvent("sequence-complete")),V.recycle(r)},o=It.setUp();let r=null;"string"==typeof t?r=V.setUp(t):Array.isArray(t)?r=this.setupEventList(t,o):(t.events&&o.addEvents(t.events),r=Array.isArray(t.sound)?this.setupEventList(t.sound,o):V.setUp(t.sound)),e&&e.events&&o.addEvents(e.events),s.play(r,n.bind(this,!0),n.bind(this,!1),this.interrupt),this.eventList=o,this.playingAudio+=1}},setupEventList(t,e){const{owner:i,player:s}=this,n=V.setUp();for(let o=0;o<t.length;o++)if(t[o].sound){const r=t[o].events;let a=null;r&&n.push(()=>a=e.addEvents(r,s.getElapsed())),n.push(t[o].sound),r&&n.push(()=>e.clear(a).forEach(t=>{i.trigger(t),t.recycle()}))}else n.push(t[o]);return n}},getAssetList:function(t,e,i){const s=t?.preloadAudio??e?.preloadAudio??i?.preloadAudio,n=t?.audioMap??e?.audioMap??i?.audioMap;if(n&&"none"!==s){const t={all:()=>!0,events:t=>{if(!Array.isArray(t))return!!t&&(e(t?.sound)||t?.events?.length>0);for(let i=0;i<t.length;i++)if(e(t[i]))return!0}},e=t[s]??t.events,i=t=>"string"==typeof t?{[wi(t)]:!0}:Array.isArray(t)?t.reduce((t,e)=>({...t,...i(e)}),{}):t.sound?i(t.sound):{};return Object.keys(Object.keys(n).reduce((t,s)=>{const o=n[s];return e(o)?{...t,...i(o)}:t},{}))}return[]}}),xi=function(t,e,i,s){t instanceof xi?this.set(t):(this.empty=!0,this.setAll(t,e,i,s))},_i=xi.prototype;_i.setAll=function(t,e,i,s){return this.empty=!1,this.x=t,this.y=e,this.resize(i,s),this},_i.setBounds=function(t,e,i,s){return this.empty=!1,this.left=t,this.top=e,this.right=i,this.bottom=s,this.width=i-t,this.height=s-e,this.halfWidth=this.width/2,this.halfHeight=this.height/2,this.x=t+this.halfWidth,this.y=e+this.halfHeight,this},_i.set=function(t){return this.empty=t.empty,this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this.halfWidth=t.halfWidth,this.halfHeight=t.halfHeight,this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this},_i.toString=function(){return"[AABB: "+this.width+"x"+this.height+" ("+this.x+", "+this.y+")]"},_i.reset=function(){return this.empty=!0,this},_i.resize=function(t=0,e=0){return this.setWidth(t),this.setHeight(e),this},_i.include=function(t){return this.empty?this.set(t):(this.left>t.left&&this.setLeft(t.left),this.right<t.right&&this.setRight(t.right),this.top>t.top&&this.setTop(t.top),this.bottom<t.bottom&&this.setBottom(t.bottom)),this},_i.includeVector=function(...t){return t.forEach(({x:t,y:e})=>{this.empty?(this.empty=!1,this.x=t,this.y=e,this.resize()):(this.left>t&&this.setLeft(t),this.right<t&&this.setRight(t),this.top>e&&this.setTop(e),this.bottom<e&&this.setBottom(e))}),this},_i.move=function(t,e){return this.moveX(t),this.moveY(e),this},_i.moveX=function(t){return this.x=t,this.left=t-this.halfWidth,this.right=t+this.halfWidth,this},_i.moveY=function(t){return this.y=t,this.top=t-this.halfHeight,this.bottom=t+this.halfHeight,this},_i.moveXBy=function(t){return this.moveX(this.x+t)},_i.moveYBy=function(t){return this.moveY(this.y+t)},_i.setWidth=function(t){const e=t/2;return this.width=t,this.halfWidth=e,"number"==typeof this.x?(this.left=this.x-e,this.right=this.x+e):this.empty=!0,this},_i.setHeight=function(t){const e=t/2;return this.height=t,this.halfHeight=e,"number"==typeof this.y?(this.top=this.y-e,this.bottom=this.y+e):this.empty=!0,this},_i.setLeft=function(t){const e=this.right-t,i=e/2;return this.left=t,this.width=e,this.halfWidth=i,this.x=t+i,this},_i.setRight=function(t){const e=t-this.left,i=e/2;return this.right=t,this.width=e,this.halfWidth=i,this.x=this.left+i,this},_i.setTop=function(t){const e=this.bottom-t,i=e/2;return this.top=t,this.height=e,this.halfHeight=i,this.y=t+i,this},_i.setBottom=function(t){const e=t-this.top,i=e/2;return this.bottom=t,this.height=e,this.halfHeight=i,this.y=this.top+i,this},_i.equals=function(t){return!this.empty&&!t.empty&&this.left===t.left&&this.top===t.top&&this.right===t.right&&this.bottom===t.bottom},_i.contains=function(t){return t.top>=this.top&&t.bottom<=this.bottom&&t.left>=this.left&&t.right<=this.right},_i.containsVector=function(t){return this.containsPoint(t.x,t.y)},_i.containsPoint=function(t,e){return e>=this.top&&e<=this.bottom&&t>=this.left&&t<=this.right},_i.collides=function(t){return t.bottom>this.top&&t.top<this.bottom&&t.right>this.left&&t.left<this.right},_i.collidesPoint=function(t,e){return e>this.top&&e<this.bottom&&t>this.left&&t<this.right},_i.intersects=function(t){return t.bottom>=this.top&&t.top<=this.bottom&&t.right>=this.left&&t.left<=this.right},_i.getIntersection=function(t){return this.intersects(t)?xi.setUp().setBounds(Math.max(this.left,t.left),Math.max(this.top,t.top),Math.min(this.right,t.right),Math.min(this.bottom,t.bottom)):xi.setUp()},_i.getIntersectionArea=function(t){return this.intersects(t)?(Math.min(this.bottom,t.bottom)-Math.max(this.top,t.top))*(Math.min(this.right,t.right)-Math.max(this.left,t.left)):0},N.add(xi,"AABB",xi,null,!0);const Ci=xi,ki=xt({id:"EntityCamera",properties:{camera:{},mode:"forward",pause:!1},publicProperties:{cameraBounds:null,cameraFocus:1,cameraOffset:null,cameraOffsetX:0,cameraOffsetY:0,cameraSize:null,cameraWidth:0,cameraHeight:0,x:0,y:0},initialize:function(){const{cameraOffsetX:t,cameraOffsetY:e,cameraHeight:i,cameraWidth:s,x:n,y:o}=this;this.pauseGame=this.pause&&this.camera.time?{time:this.camera.time}:null,Ht.assign(this.owner,"cameraOffset","cameraOffsetX","cameraOffsetY"),Ht.assign(this.owner,"cameraSize","cameraWidth","cameraHeight"),this.cameraBounds=Ci.setUp(n+t,o+e,s,i),this.cameraWidth||(this.cameraWidth=this.owner.width||100),this.cameraHeight||(this.cameraHeight=this.owner.height||100),this.camera=H.setUp("entity",this.owner,"mode",this.camera.mode||this.mode,"top",this.camera.top,"left",this.camera.left,"offsetX",this.camera.offsetX,"offsetY",this.camera.offsetY,"width",this.camera.width,"height",this.camera.height,"time",this.camera.time)},events:{"handle-movement":function(){const{cameraBounds:t,cameraOffsetX:e,cameraOffsetY:i,cameraHeight:s,cameraWidth:n,x:o,y:r}=this;t.setAll(o+e,r+i,n,s)},"follow-me":function(t){let e=null;e=t?H.setUp("entity",this.owner,"mode",t.mode||this.camera.mode,"top",t.top||this.camera.top,"left",t.left||this.camera.left,"offsetX",t.offsetX||this.camera.offsetX,"offsetY",t.offsetY||this.camera.offsetY,"width",t.width||this.camera.width,"height",t.height||this.camera.height,"time",t.time||this.camera.time):H.setUp(this.camera),this.pauseGame&&(this.owner.parent.triggerEvent("pause-logic",this.pauseGame),this.owner.parent.triggerEvent("pause-render",this.pauseGame)),this.owner.parent.triggerEvent("follow",e),e.recycle()}},methods:{destroy:function(){this.camera.recycle()}}}),Ei=window.devicePixelRatio||1,Ai=["static","mouse-pan","following"],Si={pan:1,locked:2,forward:2,bounding:2,"anchor-bound":2},Mi=(t="static")=>{if(Ai.indexOf(t)>=0)return t;if("number"==typeof Si[t]){const e=Ai[Si[t]];return platypus.debug.warn(`"${t} has been deprecated. Use "${e}" instead.`),e}return platypus.debug.warn(`"${t} is not a valid mode. Available modes include "${Ai.join('", "')}".`),"static"},Ti=function(){return!1},Ui=function(t){return t.clientX?t.clientX:t.touches&&t.touches[0]&&t.touches[0].clientX?t.touches[0].clientX:0},Pi=function(t){return t.clientY?t.clientY:t.touches&&t.touches[0]&&t.touches[0].clientY?t.touches[0].clientY:0},Oi=xt({id:"HandlerCamera",properties:{width:0,height:0,mode:"static",overflow:!1,stretch:!1,threshold:1,rotate:!1,x:0,y:0},publicProperties:{canvas:null,transitionX:400,transitionY:600,transitionAngle:600,worldCamera:null,z:0},initialize:function(t){const e=Ci.setUp(this.x,this.y,this.width,this.height),i=H.setUp("viewport",e,"orientation",t.orientation||0);this.viewport=Ci.setUp(0,0,0,0),this.worldCamera=i,this.worldDimensions=Ci.setUp(),this.unbounded=!0,this.worldIsLoaded=!1,this.mode=Mi(this.mode),this.cameras=[],this.xMagnitude=0,this.yMagnitude=0,this.xWaveLength=0,this.yWaveLength=0,this.xShakeTime=0,this.yShakeTime=0,this.shakeTime=0,this.shakeIncrementor=0,this.direction=!0,this.stationary=!1,this.viewportUpdate=!1,this.owner.container?this.parentContainer=this.owner.container:this.owner.stage?(this.canvas=this.canvas||platypus.game.canvas,this.parentContainer=this.owner.stage,this.owner.width=this.canvas.width,this.owner.height=this.canvas.height):platypus.debug.warn("Camera: There appears to be no Container on this entity for the camera to display."),this.container=new n,this.container.zIndex=this.z,this.container.visible=!1,this.parentContainer.addChild(this.container),this.movedCamera=!1},events:{load:function(){this.resize()},"render-world":function(t){this.world=t.world,this.container.addChild(this.world)},"child-entity-added":function(t){if(this.viewportUpdate=!0,this.worldIsLoaded){const e=H.setUp("viewport",Ci.setUp(this.worldCamera.viewport),"world",this.worldDimensions);t.triggerEvent("camera-loaded",e),e.viewport.recycle(),e.recycle()}"number"==typeof t.cameraFocus&&this.addCamera(t)},"child-entity-updated":function(t){if(this.viewportUpdate=!0,this.worldIsLoaded){const{container:e,owner:i,stationary:s,windowPerWorldUnitHeight:n,windowPerWorldUnitWidth:o,world:r,worldCamera:a}=this,{viewport:h}=a,l=H.setUp("viewport",Ci.setUp(h),"scaleX",o,"scaleY",n,"orientation",a.orientation,"stationary",s,"world",this.worldDimensions);t.triggerEvent("camera-update",l),l.viewport.recycle(),l.recycle()}"number"==typeof t.cameraFocus?this.addCamera(t):this.removeCamera(t)},"child-entity-removed":function(t){this.viewportUpdate=!0,this.removeCamera(t)},"world-loaded":function(t){const{owner:e}=this;if(this.worldDimensions.set(t.world),this.unbounded=!!t.level.infinite,this.worldIsLoaded=!0,t.camera&&this.follow(t.camera),e.triggerEventOnChildren){const t=H.setUp("viewport",Ci.setUp(this.worldCamera.viewport),"world",this.worldDimensions);e.triggerEventOnChildren("camera-loaded",t),t.viewport.recycle(),t.recycle()}this.updateMovementMethods()},pointerdown:function(t){if("mouse-pan"===this.state){const{viewport:e}=this.worldCamera;this.mouseVector||(this.mouseVector=Ht.setUp(),this.mouseWorldOrigin=Ht.setUp()),this.mouse=this.mouseVector,this.mouse.x=Ui(t.event),this.mouse.y=Pi(t.event),this.mouseWorldOrigin.x=e.x,this.mouseWorldOrigin.y=e.y,t.pixiEvent.stopPropagation()}},pressmove:function(t){this.mouse&&this.move(this.mouseWorldOrigin.x+(this.mouse.x-Ui(t.event))*Ei/this.world.worldTransform.a,this.mouseWorldOrigin.y+(this.mouse.y-Pi(t.event))*Ei/this.world.worldTransform.d)&&(this.viewportUpdate=!0,this.movedCamera=!0,t.pixiEvent.stopPropagation())},pressup:function(t){this.mouse&&(this.mouse=null,this.movedCamera&&(this.movedCamera=!1,t.pixiEvent.stopPropagation()))},tick:function({delta:t}){if("following"===this.mode&&this.lockedFollow(this.cameras,t)&&(this.viewportUpdate=!0),this.canvas&&(this.owner.width=this.canvas.width,this.owner.height=this.canvas.height),this.owner.width===this.lastWidth&&this.owner.height===this.lastHeight||(this.resize(),this.lastWidth=this.owner.width,this.lastHeight=this.owner.height),this.shakeIncrementor<this.shakeTime){const e=this.worldCamera.viewport;this.viewportUpdate=!0,this.shakeIncrementor+=t,this.shakeIncrementor=Math.min(this.shakeIncrementor,this.shakeTime),this.shakeIncrementor<this.xShakeTime&&e.moveX(e.x+Math.sin(this.shakeIncrementor/this.xWaveLength*(2*Math.PI))*this.xMagnitude),this.shakeIncrementor<this.yShakeTime&&e.moveY(e.y+Math.sin(this.shakeIncrementor/this.yWaveLength*(2*Math.PI))*this.yMagnitude)}this.updateViewport(),this.container.zIndex!==this.z&&(this.container.zIndex=this.z)},"resize-camera":function(t={},e=!1){const{width:i,height:s,time:n,ease:o}=t,r=e||t.forceUpdate;if(n){const t=new T.Tween(this);t.to({width:i,height:s},n),o&&t.easing(o),t.onUpdate(()=>{this.resize()}).start()}else i&&s&&(this.width=t.width,this.height=t.height),this.canvas&&(this.owner.width=this.canvas.width,this.owner.height=this.canvas.height),this.resize();r&&(this.updateViewport(),this.owner.triggerEvent("render-update"))},relocate:function(t){if(t.time){const e=this.worldCamera.viewport,i=Ht.setUp(e.x,e.y),s=new T.Tween(i);s.to({x:t.x,y:t.y},t.time),t.ease&&s.easing(t.ease),s.onUpdate(()=>this.viewportUpdate|=!this.owner.destroyed&&this.move(i.x,i.y)).onStop(()=>i.recycle()).start()}else this.move(t.x,t.y)&&(this.viewportUpdate=!0)},follow:function(t){this.follow(t)},shake:function(t={}){const e=t.xMagnitude||0,i=t.yMagnitude||0,s=t.xFrequency||0,n=t.yFrequency||0,o=t.time||0;this.viewportUpdate=!0,this.shakeIncrementor=0,this.xMagnitude=e,this.yMagnitude=i,0===s?(this.xWaveLength=1,this.xShakeTime=0):(this.xWaveLength=1e3/s,this.xShakeTime=Math.ceil(o/this.xWaveLength)*this.xWaveLength),0===n?(this.yWaveLength=1,this.yShakeTime=0):(this.yWaveLength=1e3/n,this.yShakeTime=Math.ceil(o/this.yWaveLength)*this.yWaveLength),this.shakeTime=Math.max(this.xShakeTime,this.yShakeTime)}},methods:{follow:function({begin:t=0,entity:e,mode:i,orientation:s=0,time:n=0,x:o,y:r}={}){(t||n)&&platypus.debug.warn('"begin" and "time" syntax has been deprecated. Use the "Timeline" component to set up transitional timings instead.'),this.mode=Mi(i),"following"===this.mode?this.addCamera(e):"number"==typeof o&&"number"==typeof r&&(this.move(o,r,s),this.viewportUpdate=!0)},addCamera(t){const e=-1===this.cameras.indexOf(t);return e&&("number"!=typeof t.cameraFocus&&t.addComponent(new ki(t,{})),this.cameras.push(t),this.mode="following"),e},removeCamera(t){const e=this.cameras.indexOf(t),i=e>=0;return i&&(this.cameras.splice(e,1),0===this.cameras.length&&(this.mode="static")),i},move:function(t,e,i){const s=this.moveX(t),n=this.moveY(e),o=this.rotate&&this.reorient(i||0);return s||n||o},moveX:Ti,moveY:Ti,reorient:function(t){const{worldCamera:e}=this;return Math.abs(e.orientation-t)>1e-4&&(e.orientation=t,!0)},lockedFollow(t){const{worldCamera:{viewport:e},worldDimensions:{top:i,bottom:s,left:n,right:o,height:r,width:a,x:h,y:l},unbounded:c}=this,d=t.reduce((t,{cameraFocus:e})=>t+e,0),u=d<1,p=t.filter(({cameraFocus:t})=>t>0),g=t=>[({focus:e,result:i},{cameraFocus:s,cameraBounds:n})=>(s>e&&(s=e),{focus:s<=e?e-s:0,result:i+s*n[t]}),{focus:d,result:u?e[t]*(1-d):0}],{result:f}=p.sort(({cameraBounds:{top:t}},{cameraBounds:{top:e}})=>t-e).reduce(...g("top")),{result:y}=p.sort(({cameraBounds:{bottom:t}},{cameraBounds:{bottom:e}})=>e-t).reduce(...g("bottom")),{result:m}=p.sort(({cameraBounds:{left:t}},{cameraBounds:{left:e}})=>t-e).reduce(...g("left")),{result:v}=p.sort(({cameraBounds:{right:t}},{cameraBounds:{right:e}})=>e-t).reduce(...g("right")),w=Ci.setUp(e);return e.setBounds(m,f,v,y),this.width!==e.width||this.height!==e.height?(this.width=e.width,this.height=e.height,this.matchAspectRatio(),this.resize()):this.matchAspectRatio(),c||(a&&(a<e.width?e.moveX(h):n>e.left?e.moveX(n+e.halfWidth):o<e.right&&e.moveX(o-e.halfWidth)),r&&(r<e.height?e.moveY(l):i>e.top?e.moveY(i+e.halfHeight):s<e.bottom&&e.moveY(s-e.halfHeight))),w.equals(e)?(w.recycle(),!1):(w.recycle(),!0)},matchAspectRatio(){const{height:t,owner:e,width:i,worldCamera:s}=this,{viewport:n}=s,o=i/t,r=e.width/e.height;r>o?n.resize(t*r,t):n.resize(i,i/r)},clampAspectRatio(){const{height:t,owner:e,viewport:i,width:s}=this,n=s/t;e.width/e.height>n?i.resize(i.height*n,i.height):i.resize(i.width,i.width/n)},resize:function(){const{container:t,height:e,owner:i,viewport:s,width:n,worldCamera:o}=this,r=n/e,a=i.width/i.height,{viewport:h}=o;s.setAll(i.width/2,i.height/2,i.width,i.height),a>r?h.resize(e*a,e):h.resize(n,n/a),this.worldPerWindowUnitWidth=h.width/s.width,this.worldPerWindowUnitHeight=h.height/s.height,this.windowPerWorldUnitWidth=s.width/h.width,this.windowPerWorldUnitHeight=s.height/h.height,t.updateTransform({x:s.x-s.halfWidth,y:s.y-s.halfHeight}),this.viewportUpdate=!0,this.updateMovementMethods()},updateMovementMethods:function(){const t=function(){const{worldDimensions:t}=this;return this.worldCamera.viewport.moveX(t.width/2+t.left),this.moveX=Ti,!0},e=function(){const{worldDimensions:t}=this;return this.worldCamera.viewport.moveY(t.height/2+t.top),this.moveY=Ti,!0},i=function(t){const{worldDimensions:e,worldCamera:i}=this,{viewport:s}=i,{left:n,width:o}=e;return Math.abs(s.x-t)>this.threshold&&(t+s.halfWidth>o+n?s.moveX(o-s.halfWidth+n):t<s.halfWidth+n?s.moveX(s.halfWidth+n):s.moveX(t),!0)},s=function(t){const{worldDimensions:e,worldCamera:i}=this,{viewport:s}=i,{height:n,top:o}=e;return Math.abs(s.y-t)>this.threshold&&(t+s.halfHeight>n+o?s.moveY(n-s.halfHeight+o):t<s.halfHeight+o?s.moveY(s.halfHeight+o):s.moveY(t),!0)},n=function(t){const{threshold:e,worldCamera:i}=this,{viewport:s}=i;return Math.abs(s.x-t)>e&&(s.moveX(t),!0)},o=function(t){const{threshold:e,worldCamera:i}=this,{viewport:s}=i;return Math.abs(s.y-t)>e&&(s.moveY(t),!0)};return function(){const{threshold:r,unbounded:a,worldCamera:h,worldDimensions:l}=this,{viewport:c}=h,{height:d,width:u}=l;a||!u?this.moveX=n:u<c.width?this.moveX=t:this.moveX=i,a||!d?this.moveY=o:d<c.height?this.moveY=e:this.moveY=s,this.threshold=-1,this.moveX(c.x),this.moveY(c.y),this.threshold=r}}(),updateViewport:function(){const{container:t,owner:e,stationary:i,viewportUpdate:s,windowPerWorldUnitHeight:n,windowPerWorldUnitWidth:o,world:r,worldCamera:a}=this,{viewport:h}=a,l=H.setUp("viewport",Ci.setUp(h),"scaleX",o,"scaleY",n,"orientation",a.orientation,"stationary",!s&&!i,"world",this.worldDimensions);s?(this.viewportUpdate=!1,this.stationary=!1,r.x=-h.x,r.y=-h.y,t.x=h.halfWidth*l.scaleX,t.y=h.halfHeight*l.scaleY,t.scale.x=l.scaleX,t.scale.y=l.scaleY,t.rotation=l.orientation,t.visible=!0,e.triggerEvent("camera-update",l),e.triggerEventOnChildren&&e.triggerEventOnChildren("camera-update",l)):i||(this.stationary=!0,e.triggerEvent("camera-update",l),e.triggerEventOnChildren&&e.triggerEventOnChildren("camera-update",l)),l.viewport.recycle(),l.recycle()},destroy:function(){this.parentContainer.removeChild(this.container),this.parentContainer=null,this.container=null,this.mouseVector&&(this.mouseVector.recycle(),this.mouseWorldOrigin.recycle()),this.viewport.recycle(),this.worldCamera.viewport.recycle(),this.worldCamera.recycle(),this.worldDimensions.recycle()}},publicMethods:{isOnCanvas:function(t){const{canvas:e}=this;return!t||!(t.x+t.width<0||t.x>e.width||t.y+t.height<0||t.y>e.height)},windowToWorld:function(t,e,i){const{worldPerWindowUnitHeight:s,worldPerWindowUnitWidth:n,viewport:o,worldCamera:{viewport:r}}=this,a=i||Ht.setUp();return a.x=t.x*n,a.y=t.y*s,!1!==e&&(a.x-=o.left*n-r.left,a.y-=o.top*s-r.top),a},worldToWindow:function(t,e,i){const{windowPerWorldUnitHeight:s,windowPerWorldUnitWidth:n,viewport:o,worldCamera:{viewport:r}}=this,a=i||Ht.setUp();return a.x=t.x*n,a.y=t.y*s,!1!==e&&(a.x-=r.left*n-o.left,a.y-=r.top*s-o.top),a}}}),Li=function(t,e){const i=e.aABB,s=i.halfHeight,n=i.halfWidth,o=Math.abs(t.x-e.x),r=Math.abs(t.y-e.y),a=t.radius;return o<n||r<s||o<n+a&&r<s+a&&(o-n)**2+(r-s)**2<a**2},zi=function(t){return this.aABB.collides(t.aABB)&&("rectangle"===t.type&&Li(this,t)||"circle"===t.type&&(this.x-t.x)**2+(this.y-t.y)**2<=(this.radius+t.radius)**2)},Bi=function(){return!1},Ii=function(t){return this.aABB.collides(t.aABB)&&("rectangle"===t.type||"circle"===t.type&&Li(t,this))},Di=function(t,e,i){const{x:s,y:n}=t??e,{offsetX:o,offsetY:r,radius:a=0,type:h="rectangle"}=e,l=2*a,c="circle"===h?l:e.width??l,d="circle"===h?l:e.height??l,u=e.regX??c/2,p=e.regY??d/2;this.initialized||(this.initialized=!0,Ht.assign(this,"offset","offsetX","offsetY"),Ht.assign(this,"position","x","y"),Ht.assign(this,"size","width","height"),this.aABB=Ci.setUp()),this.owner=t,this.collisionType=i,this.jumpThrough=e.jumpThrough?Ht.setUp(e.jumpThrough.x,e.jumpThrough.y):null,this.type=h,this.subType="",this.collides="circle"===h?zi:"rectangle"===h?Ii:Bi,this.size.setXYZ(c,d),this.radius=a,this.offset.setXYZ(o??c/2-u,r??d/2-p),this.position.setXYZ(s,n).add(this.offset),this.aABB.setAll(this.x,this.y,c,d)},Xi=Di.prototype;Xi.updateAll=function(t){this.owner=t.owner,this.collisionType=t.collisionType,this.type=t.type,this.subType=t.subType,this.offset.x=t.offset.x,this.offset.y=t.offset.y,this.position.x=t.position.x,this.position.y=t.position.y,this.size.x=t.size.x,this.size.y=t.size.y,this.radius=t.radius,this.aABB.setAll(this.x,this.y,this.width,this.height),"circle"===this.type?this.collides=zi:"rectangle"===this.type?this.collides=Ii:this.collides=Bi},Xi.update=function(t,e){const i=t+this.offsetX,s=e+this.offsetY;this.position.setXYZ(i,s),this.aABB.move(i,s)},Xi.moveX=function(t){this.x=t,this.aABB.moveX(t)},Xi.moveY=function(t){this.y=t,this.aABB.moveY(t)},Xi.moveXY=function(t,e){this.x=t,this.y=e,this.aABB.move(t,e)},Xi.getAABB=function(){return this.aABB},Xi.setXWithEntityX=function(t){this.x=t+this.offsetX,this.aABB.moveX(this.x)},Xi.setYWithEntityY=function(t){this.y=t+this.offsetY,this.aABB.moveY(this.y)},Xi.multiply=function(t){const e=this.position,i=this.owner.position;e.subtractVector(i),e.multiply(t),this.offset.multiply(t),this.size.multiply(t),e.addVector(i),this.width=Math.abs(this.width),this.height=Math.abs(this.height),this.aABB.setAll(this.x,this.y,this.width,this.height)},Xi.containsPoint=function(t,e){return this.aABB.containsPoint(t,e)&&("rectangle"===this.type||"circle"===this.type&&(this.x-t)**2+(this.y-e)**2<=this.radius**2)},Xi.toJSON=function(){const t={type:this.type},e=this.size.width,i=this.size.height;return e/2!==this.regX&&(t.regX=this.regX),i/2!==this.regY&&(t.regY=this.regY),this.offset.x!==e/2-this.regX&&(t.offsetX=this.offset.x),this.offset.y!==i/2-this.regY&&(t.offsetY=this.offset.y),"circle"===this.type?t.radius=this.radius:(t.width=e,t.height=i),t},N.add(Di,"CollisionShape",Di,function(){this.jumpThrough&&this.jumpThrough.recycle(),this.jumpThrough=null},!0);const Ri=Di,ji=function(){const t=function(t,e,i,s){s.myType===e&&s.hitType===i&&this.owner.triggerEvent(t,s)},e=function(t,e,i,s){if(s.myType===e&&s.hitType===i)for(let e=0;e<t.length;e++)this.owner.triggerEvent(t[e],s)},i=function(t,e,i,s){let n=s.x,o=s.y;!s.entity||n||o||(n=s.entity.x-this.owner.x,o=s.entity.y-this.owner.y),s.myType===e&&s.hitType===i&&(o>0&&t.bottom?this.owner.trigger(t.bottom,s):o<0&&t.top&&this.owner.trigger(t.top,s),n>0&&t.right?this.owner.trigger(t.right,s):n<0&&t.left&&this.owner.trigger(t.left,s),t.all&&this.owner.trigger(t.all,s))};return function(s,n,o){return"string"==typeof n?t.bind(s,n,s.collisionType,o):Array.isArray(n)?e.bind(s,n,s.collisionType,o):i.bind(s,n,s.collisionType,o)}}(),Yi=function(){const t=function(t,e,i){if(i){const t=e.get(i);return t?t.getAABB():null}{const{keys:i}=e;let s=i.length;for(t.reset();s--;)t.include(e.get(i[s]).getAABB());return t}},e=function(t,e){const i=t.get(e);return i?i.getPreviousAABB():null},i=function(t,e){const i=t.get(e);return i?i.getShapes():null},s=function(t,e){const i=t.get(e);return i?i.getPrevShapes():null},n=function(t,e,i){const s=t.keys;let n=s.length;for(;n--;)t.get(s[n]).prepareCollision(e,i)},o=function(){const t=function(t,e,i){let s=e.stuck;if(s){const n=t.magnitude();e.thatShape.owner&&Math.abs(s)>1&&(s*=.05),(!n||n>Math.abs(s))&&(e.vector.x&&(t.x=s,t.y=0),e.vector.y&&(t.x=0,t.y=s),i.stuckWith&&i.stuckWith.recycle(),i.stuckWith=Ht.setUp(e.thatShape.x,e.thatShape.y))}},e={position:null,unstick:null};return function(i,s){const n=s.xData[0],o=s.yData[0],r=e;let a=null;n&&(a=Ht.setUp(0,0,0),t(a,n,this)),o&&(a=a??Ht.setUp(0,0,0),t(a,o,this)),r.position=i,r.unstick=a,this.triggerEvent("relocate-entity",r),a&&a.recycle()}}(),r=function(t,e){const{keys:i}=t;let s=i.length;for(;s--;)t.get(i[s]).movePreviousX(e)},a=function(){return this.collisionTypes},h=function(){return this.solidCollisionMap},l=function(){return this.getAABB()},c=function(){return this.getPreviousAABB()},d=function(){return this.getShapes()},u=function(){return this.getPrevShapes()},p=function(t,e){this.prepareCollision(t,e)},g=function(t){this.movePreviousX(t)};return function(f,y){let m=y.collisionFunctions;m||(m=y.collisionFunctions=et.setUp(),y.aabb=Ci.setUp(),y.getAABB=t.bind(y,y.aabb,m),y.getPreviousAABB=e.bind(y,m),y.getShapes=i.bind(y,m),y.getPrevShapes=s.bind(y,m),y.prepareCollision=n.bind(y,m),y.relocateEntity=o.bind(y),y.movePreviousX=r.bind(y,m),y.getCollisionTypes=a.bind(y),y.getSolidCollisions=h.bind(y)),m.set(f.collisionType,H.setUp("getAABB",l.bind(f),"getPreviousAABB",c.bind(f),"getShapes",d.bind(f),"getPrevShapes",u.bind(f),"prepareCollision",p.bind(f),"movePreviousX",g.bind(f)))}}(),Ni=function(t,e,i,s,n){let o=t.length;for(;o--;){const r=t[o];r.updateAll(e[o]),r.update(s,n),i.include(r.aABB)}this.updateShapes=Wi},Wi=function(t,e,i,s,n){let o=t.length;for(;o--;){const e=t[o];e.update(s,n),i.include(e.aABB)}},Hi=function(t){return!0===t?{x:0,y:-1}:t?{x:t.x||0,y:t.y||0}:null},Vi=xt({id:"CollisionBasic",properties:{collisionType:"none",shapeType:"rectangle",ignoreOrientation:!1,regX:null,regY:null,width:0,height:0,radius:0,softCollisions:null,solidCollisions:null,margin:0,shapes:null},publicProperties:{collisionDirty:!1,immobile:!1,bullet:!1,jumpThrough:!1},initialize:function(t){const{height:e,margin:i=0,owner:s,radius:n,regX:o=this.width/2,regY:r=this.height/2,width:a}=this,h=i.left??i,l=i.right??i,c=i.top??i,d=i.bottom??i;let u=null;if(Ht.assign(this.owner,"position","x","y","z"),Ht.assign(this.owner,"previousPosition","previousX","previousY","previousZ"),this.owner.previousX=this.owner.previousX||this.owner.x,this.owner.previousY=this.owner.previousY||this.owner.y,this.aabb=Ci.setUp(),this.prevAABB=Ci.setUp(),this.shapes)u=this.shapes;else if("circle"===this.shapeType){const t=n||((a||0)+(e||0))/4;u=[{regX:(isNaN(o)?t:o)-(l-h)/2,regY:(isNaN(r)?t:r)-(d-c)/2,radius:t,type:this.shapeType}]}else u=[{regX:(isNaN(o)?(a||0)/2:o)+h,regY:(isNaN(r)?(e||0)/2:r)+c,points:t.points,width:(a||0)+h+l,height:(e||0)+c+d,type:this.shapeType}];this.owner.collisionTypes=this.owner.collisionTypes||V.setUp(),this.owner.collisionTypes.push(this.collisionType),this.shapes=V.setUp(),this.prevShapes=V.setUp(),this.entities=null;for(let t=0;t<u.length;t++){const e=u[t],i={...e,jumpThrough:Hi(void 0===e.jumpThrough?this.jumpThrough:e.jumpThrough)};this.shapes.push(Ri.setUp(this.owner,i,this.collisionType)),this.prevShapes.push(Ri.setUp(this.owner,i,this.collisionType)),this.prevAABB.include(this.prevShapes[t].aABB),this.aabb.include(this.shapes[t].aABB)}this.updateShapes=Wi,Yi(this,this.owner),s.softCollisionMap=s.softCollisionMap??et.setUp(),s.solidCollisionMap=s.solidCollisionMap??et.setUp();{const t=this.softCollisions,e=t?Object.keys(t):V.setUp(),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];t[i]&&this.addEventListener(`hit-by-${i}`,ji(this,t[i],"soft"))}s.softCollisionMap.set(this.collisionType,e)}{const t=this.solidCollisions,e=t?Object.keys(t):V.setUp(),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];t[i]&&this.addEventListener(`hit-by-${i}`,ji(this,t[i],"solid"))}s.solidCollisionMap.set(this.collisionType,e)}this.active=!0,this.stuck=!1},events:{"collide-on":function(t){const{collisionType:e,owner:i}=this,{collisionTypes:s}=i;this.active||"string"==typeof t&&t!==e||(i.parent.triggerEvent("remove-collision-entity",i),-1===s.indexOf(e)&&s.push(e),i.parent.triggerEvent("add-collision-entity",i),this.active=!0,this.collisionDirty=!0)},"collide-off":function(t){const{collisionType:e,owner:i}=this,{collisionTypes:s,parent:n}=i;if(this.active&&("string"!=typeof t||t===e)){n.triggerEvent("remove-collision-entity",i);const t=s.indexOf(e);t>=0&&G(s,t),this.active=!1,s.length&&n.triggerEvent("add-collision-entity",i)}},"relocate-entity":function(t,e){const{aabb:i,owner:s,shapes:n}=this,o=t.unstick,r=o?.magnitude()??0,a=t.position??t;let h=n.length,l=0,c=0;for(this.move&&(this.move.recycle(),this.move=null),t.relative||e?s.position.setVector(s.previousPosition).add(a):s.position.setVector(a),this.stuck&&(r>0?s.position.add(o):this.stuck=!1),l=s.x,c=s.y,i.reset(),h=n.length;h--;){const t=n[h];t.update(l,c),i.include(t.aABB)}s.previousPosition.setVector(s.position),r>0&&(this.stuck||(this.stuck=!0),this.move=s.stuckWith.copy().add(-l,-c).normalize())},"handle-logic":function(){this.move&&this.owner.position.add(this.move)},"orientation-updated":function(t){if(!this.ignoreOrientation){for(let e=0;e<this.shapes.length;e++)this.shapes[e].multiply(t);this.updateShapes=Ni,this.collisionDirty=!0}}},methods:{getAABB:function(){return this.aabb},getPreviousAABB:function(){return this.prevAABB},getShapes:function(){return this.shapes},getPrevShapes:function(){return this.prevShapes},prepareCollision:function(t,e){const i=this.shapes,s=this.prevShapes,n=this.aabb;this.owner.x=t,this.owner.y=e,this.prevShapes=i,this.shapes=s,this.prevAABB.set(n),n.reset(),this.updateShapes(s,i,n,t,e),this.collisionDirty&&(this.collisionDirty=!1)},movePreviousX:function(t){this.prevAABB.moveX(t);for(let e=0;e<this.prevShapes.length;e++)this.prevShapes[e].setXWithEntityX(t)},destroy:function(){const{collisionType:t,owner:e}=this,{collisionFunctions:i,collisionTypes:s,parent:n,softCollisionMap:o,solidCollisionMap:r}=e;let a=s?s.indexOf(t):-1;for(n.triggerEvent("remove-collision-entity",e),this.aabb.recycle(),delete this.aabb,this.prevAABB.recycle(),delete this.prevAABB,a>=0&&G(s,a),s&&(r.has(t)&&V.recycle(r.delete(t)),o.has(t)&&V.recycle(o.delete(t)),i.delete(t).recycle()),a=this.shapes.length;a--;)this.shapes[a].recycle(),this.prevShapes[a].recycle();V.recycle(this.shapes),V.recycle(this.prevShapes),this.shapes=null,this.prevShapes=null,this.entities=null,s&&(s.length?n.triggerEvent("add-collision-entity",e):(i.recycle(),e.collisionFunctions=null,r.recycle(),e.solidCollisionMap=null,o.recycle(),e.softCollisionMap=null,e.aabb.recycle(),e.aabb=null,V.recycle(s),e.collisionTypes=null))}}}),Fi=function(t,e,i){this.state.get(t)&&this.trigger(e,i)},Zi=function(t,e,i){this.state.get(t)||this.trigger(e,i)},Gi=xt({id:"CollisionFilter",properties:{collisions:{},state:""},initialize:function(){const t=this.collisions;if(t){const{state:e,owner:i}=this,s="!"===e[0],n=s?e.substring[1]:e,o=s?Zi:Fi,r=Object.keys(t),{length:a}=r;for(let e=0;e<a;e++){const s=r[e];this.addEventListener(s,o.bind(i,n,t[s]))}}}}),qi=xt({id:"CollisionGroup",initialize:function(){this.solidEntities=V.setUp(),this.collisionTypes=V.setUp(),this.shapes=V.setUp(),this.prevShapes=V.setUp(),this.terrain=null,this.aabb=Ci.setUp(this.owner.x,this.owner.y),this.prevAABB=Ci.setUp(this.owner.x,this.owner.y),this.filteredAABB=Ci.setUp(),Ht.assign(this.owner,"position","x","y","z"),Ht.assign(this.owner,"previousPosition","previousX","previousY","previousZ"),this.owner.previousX=this.owner.previousX||this.owner.x,this.owner.previousY=this.owner.previousY||this.owner.y,this.collisionGroup=this.owner.collisionGroup={getAllEntities:function(){let t=0;for(let e=0;e<this.solidEntities.length;e++){const i=this.solidEntities[e];i!==this.owner&&i.collisionGroup?t+=i.collisionGroup.getAllEntities():t+=1}return t}.bind(this),getSize:function(){return this.solidEntities.length}.bind(this),getCollisionTypes:function(){return this.getCollisionTypes()}.bind(this),getSolidCollisions:function(){return this.getSolidCollisions()}.bind(this),getAABB:function(t){return this.getAABB(t)}.bind(this),getPreviousAABB:function(t){return this.getPreviousAABB(t)}.bind(this),getShapes:function(t){return this.getShapes(t)}.bind(this),getPrevShapes:function(t){return this.getPrevShapes(t)}.bind(this),prepareCollision:function(t,e){return this.prepareCollision(t,e)}.bind(this),relocateEntity:function(t,e){return this.relocateEntity(t,e)}.bind(this),movePreviousX:function(t){return this.movePreviousX(t)}.bind(this),getSolidEntities:function(){return this.solidEntities}.bind(this),jumpThrough:!1}},events:{"child-entity-added":function(t){this.addCollisionEntity(t)},"add-collision-entity":function(t){this.addCollisionEntity(t)},"child-entity-removed":function(t){this.removeCollisionEntity(t)},"remove-collision-entity":function(t){this.removeCollisionEntity(t)},"relocate-entity":function(){this.owner.previousPosition.setVector(this.owner.position),this.updateAABB()}},methods:{addCollisionEntity:function(t){const{collisionTypes:e}=t;if(e){let i=e.length;for(;i--;)t.solidCollisionMap.get(e[i]).length&&!t.immobile&&-1===this.solidEntities.indexOf(t)&&(this.solidEntities[this.solidEntities.length]=t);this.updateAABB()}},removeCollisionEntity:function(t){const{collisionTypes:e}=t;if(e){let i=e.length;for(;i--;)if(t.solidCollisionMap.get(e[i]).length){const e=this.solidEntities.indexOf(t);e>=0&&G(this.solidEntities,e)}this.updateAABB()}},getCollisionTypes:function(){const{collisionTypes:t,owner:e,solidEntities:i}=this;let s=i.length;for(t.length=0;s--;){const n=i[s];n!==e&&n.collisionGroup&&(n=n.collisionGroup),F(t,n.getCollisionTypes())}return t},getSolidCollisions:function(){const{owner:t,solidEntities:e}=this,i=et.setUp();for(let s=0;s<e.length;s++){const n=e[s],{collisionGroup:o}=n,r=n!==t&&o,a=(r?o:n).getSolidCollisions(),h=a.keys;let l=h.length;for(;l--;){const t=h[l],e=i.get(t)||i.set(t,V.setUp()),s=a.get(t);F(e,s),r&&s.recycle()}r&&a.recycle()}return i},getAABB:function(t){if(t){const{filteredAABB:e,owner:i,solidEntities:s}=this;let n=s.length;for(e.reset();n--;){const o=s[n],{collisionGroup:r}=o,a=(o!==i&&r?r:o).getAABB(t);a&&e.include(a)}return e}return this.aabb},getPreviousAABB:function(t){if(t){const{filteredAABB:e,owner:i,solidEntities:s}=this;let n=s.length;for(e.reset();n--;){const o=s[n],{collisionGroup:r}=o,a=(o!==i&&r?r:o).getPreviousAABB(t);a&&e.include(a)}return e}return this.prevAABB},updateAABB:function(){const{aabb:t,owner:e,solidEntities:i}=this;let s=i.length;for(t.reset();s--;){const n=i[s];t.include(n!==e&&n.getCollisionGroupAABB?n.getCollisionGroupAABB():n.getAABB())}},getShapes:function(t){const{owner:e,shapes:i,solidEntities:s}=this;i.length=0;for(let n=0;n<s.length;n++){const o=s[n],{collisionGroup:r}=o,a=(o!==e&&r?r:o).getShapes(t);a&&F(i,a)}return i},getPrevShapes:function(t){const{owner:e,prevShapes:i,solidEntities:s}=this;i.length=0;for(let n=0;n<s.length;n++){const o=s[n],{collisionGroup:r}=o,a=(o!==e&&r?r:o).getPrevShapes(t);a&&F(i,a)}return i},prepareCollision:function(t,e){const{owner:i,solidEntities:s}=this;for(let n=0;n<s.length;n++){const o=s[n],r=i.previousX-o.previousX,a=i.previousY-o.previousY;o.saveDX=o.x-o.previousX,o.saveDY=o.y-o.previousY,o.saveOX=r,o.saveOY=a,o!==i&&o.collisionGroup?o.collisionGroup.prepareCollision(t-r,e-a):o.prepareCollision(t-r,e-a)}},movePreviousX:function(t){const{owner:e,solidEntities:i}=this;for(let s=0;s<i.length;s++){const n=i[s],o=n.saveOX;n!==e&&n.collisionGroup?n.collisionGroup.movePreviousX(t-o):n.movePreviousX(t-o)}},relocateEntity:function(t,e){const{owner:i,solidEntities:s}=this,{xData:n,yData:o}=e;let r=n.length,a=o.length;for(i.saveDX-=t.x-i.previousX,i.saveDY-=t.y-i.previousY;r--;)if(n[r].thisShape.owner===i){i.saveDX=0;break}for(;a--;)if(o[a].thisShape.owner===i){i.saveDY=0;break}for(let n=0;n<s.length;n++){const o=s[n],{collisionGroup:r}=o,a=o!==i&&r?r:o,h=Ht.setUp(t.x-o.saveOX,t.y-o.saveOY,a.z);a.relocateEntity(h,e),h.recycle(),o.x+=o.saveDX,o.y+=o.saveDY,o!==i&&(o.x+=i.saveDX,o.y+=i.saveDY)}},destroy:function(){V.recycle(this.solidEntities),V.recycle(this.collisionTypes),V.recycle(this.shapes),V.recycle(this.prevShapes),this.aabb.recycle(),this.prevAABB.recycle(),this.filteredAABB.recycle()}},publicMethods:{getCollisionGroupAABB:function(){return this.getAABB()},getWorldEntities:function(){return this.owner.parent.getWorldEntities()},getWorldTerrain:function(){return this.owner.parent.getWorldTerrain()}}}),$i=function(){const t=536870912,e=2147483648,i=1073741824,s=268435455,n=function(){return this.collisionType},o=function(t){return this.collisionTypeMap[t&s]||this.collisionType},r=function(e){return 0===e?e:e^i^t},a=function(i){return 0===i?i:i^e^t},h=function(t){return 0===t?t:t^e},l=function(t){return 0===t?t:t^i},c=function(s){return 0===s?s:t&s?s^i^t:s^e^t},d=function(t){return 0===t?t:t^e^i},u=function(s){return 0===s?s:t&s?s^e^t:s^i^t},p=function(t,e,i,s,n){const o=V.setUp();for(let r=0;r<n;r++){o[r]=V.setUp();for(let n=0;n<s;n++)o[r][n]=t[e+n][i+r]}return o},g={diagonal:function(t,e,i,s,n){const o=p(t,e,i,s,n),a=r;for(let r=0;r<s;r++)for(let s=0;s<n;s++)t[e+r][i+s]=a(o[r][s]);return V.recycle(o,2),t},"diagonal-inverse":function(t,e,i,s,n){const o=p(t,e,i,s,n),r=a;for(let a=0;a<s;a++)for(let h=0;h<n;h++)t[e+s-a-1][i+n-h-1]=r(o[a][h]);return V.recycle(o,2),t},horizontal:function(t,e,i,s,n){const o=p(t,e,i,s,n),r=h;for(let a=0;a<n;a++)for(let n=0;n<s;n++)t[e+s-n-1][i+a]=r(o[a][n]);return V.recycle(o,2),t},vertical:function(t,e,i,s,n){const o=p(t,e,i,s,n),r=l;for(let a=0;a<n;a++)for(let h=0;h<s;h++)t[e+h][i+n-a-1]=r(o[a][h]);return V.recycle(o,2),t},"rotate-90":function(t,e,i,s,n){const o=p(t,e,i,s,n),r=c;for(let a=0;a<n;a++)for(let h=0;h<s;h++)t[e+n-a-1][i+h]=r(o[a][h]);return V.recycle(o,2),t},"rotate-180":function(t,e,i,s,n){const o=p(t,e,i,s,n),r=d;for(let a=0;a<n;a++)for(let h=0;h<s;h++)t[e+s-h-1][i+n-a-1]=r(o[a][h]);return V.recycle(o,2),t},"rotate-270":function(t,e,i,s,n){const o=p(t,e,i,s,n),r=u;for(let a=0;a<n;a++)for(let n=0;n<s;n++)t[e+a][i+s-n-1]=r(o[a][n]);return V.recycle(o,2),t},translate:function(t,e,i,s,n,o,r){const a=function(t,e,i,s,n){const o=V.setUp();for(let r=0;r<n;r++){o[r]=V.setUp();for(let n=0;n<s;n++)o[r][n]=t[e+n][i+r],t[e+n][i+r]=-1}return o}(t,e,i,s,n);for(let h=0;h<n;h++)for(let n=0;n<s;n++)t[e+n+o][i+h+r]=a[h][n];return V.recycle(a,2),t}};return xt({id:"CollisionTiles",properties:{collisionTypeMap:null,collisionType:"tiles",top:0,left:0},publicProperties:{collisionMap:[],tileWidth:10,tileHeight:10},initialize:function(){this.tileOffsetLeft=this.tileWidth/2+this.left,this.tileOffsetTop=this.tileHeight/2+this.top,this.columns=this.collisionMap[0].length,this.rows=this.collisionMap[0][0].length,this.shapeDefinition=H.setUp("x",0,"y",0,"type","rectangle","width",this.tileWidth,"height",this.tileHeight),this.storedTiles=V.setUp(),this.serveTiles=V.setUp(),this.storedTileIndex=0,this.aabb=Ci.setUp(),this.aabb.setBounds(this.left,this.top,this.tileWidth*this.columns+this.left,this.tileHeight*this.rows+this.top),this.collisionTypeMap?this.getType=o:this.getType=n},events:{transform:function(t){this.transform(t)},translate:function(t){this.translate(t)},"add-collision-tiles":function(t){const e=t.collisionMap[0],i=t.collisionTypeMap;let s=0;if(e&&this.collisionMap.push(e),i)for(s in i)this.collisionTypeMap[s]&&console.warn("Overwriting existing typeMap."),this.collisionTypeMap[s]=i[s]}},methods:{getShape:function(t,e,i){const{storedTileIndex:s,storedTiles:n}=this;let o=null;return s===n.length?(o=Ri.setUp(null,this.shapeDefinition,i),n.push(o)):(o=n[s],o.collisionType=i),o.update(t*this.tileWidth+this.tileOffsetLeft,e*this.tileHeight+this.tileOffsetTop),this.storedTileIndex+=1,o},addShape:function(n,o,r,a,h,l){const c=this.collisionMap[r][a][h],d=c&s;if(c&&this.getType(d)===l)if(268435456&c){const s=t&c,r=i&c;s&&e&c?o.left>=(a+1)*this.tileWidth+this.left&&n.push(this.getShape(a,h,l)):s?o.right<=a*this.tileWidth+this.left&&n.push(this.getShape(a,h,l)):r?o.top>=(h+1)*this.tileHeight+this.top&&n.push(this.getShape(a,h,l)):o.bottom<=h*this.tileHeight+this.top&&n.push(this.getShape(a,h,l))}else n.push(this.getShape(a,h,l));return n},destroy:function(){const t=this.storedTiles;let e=t.length;for(this.shapeDefinition.recycle(),this.shapeDefinition=null;e--;)t[e].recycle();V.recycle(t),this.storedTiles=null,V.recycle(this.serveTiles),this.serveTiles=null,this.aabb.recycle(),this.aabb=null}},publicMethods:{getAABB:function(){return this.aabb},isTile:function(t,e){let i=0;if(t<0||e<0||t>=this.columns||e>=this.rows)return!1;for(i=0;i<this.collisionMap.length;i++)if(-1!==this.collisionMap[i][t][e])return!0;return!1},getTileShapes:function(t,e,i){const s=i||"tiles",n=this.left,o=this.top,r=this.tileHeight,a=this.tileWidth,h=Math.max(Math.floor((t.left-n)/a),0),l=Math.max(Math.floor((t.top-o)/r),0),c=Math.min(Math.ceil((t.right-n)/a),this.columns),d=Math.min(Math.ceil((t.bottom-o)/r),this.rows),u=this.serveTiles;u.length=0,this.storedTileIndex=0;for(let t=0;t<this.collisionMap.length;t++)for(let i=h;i<c;i++)for(let n=l;n<d;n++)this.addShape(u,e,t,i,n,s);return u},transform:function(t={}){const{layers:e=[0],left:i=0,top:s=0,width:n=this.rows,height:o=this.columns,type:r="horizontal"}=t;let a=0;if(g[r]){for(a=0;a<this.collisionMap.length;a++)e.includes(a)&&g[r](this.collisionMap[a],i,s,n,o);return this.collisionMap}return null},translate:function(t={}){const{layers:e=[0],left:i=0,top:s=0,width:n=this.rows,height:o=this.columns,dx:r=0,dy:a=0}=t;let h=0;for(h=0;h<this.collisionMap.length;h++)e&&!e.includes(h)||g.translate(this.collisionMap[h],i,s,n,o,r,a);return this.collisionMap},getCollisionMatrix:function(t,e,i,s,n){return p(this.collisionMap[t],e,i,s,n)},setCollisionMatrix:function(t,e,i,s,n,o){return function(t,e,i,s,n,o){for(let r=0;r<o;r++)for(let o=0;o<n;o++)t[i+o][s+r]=e[r][o];return t}(this.collisionMap[e],t,i,s,n,o)}}})}(),Ji=xt({id:"ComponentSwitcher",properties:{componentMap:null},initialize:function(){const{componentMap:t}=this,e=this.switches=V.setUp();if(t){const i=Object.keys(t),{length:s}=i;for(let t=0;t<s;t++){const s=i[t];this.addEventListener(s,t=>{e.push(t)})}}},events:{"prepare-logic":function(){if(this.switches.length){for(let t=0;t<this.switches.length;t++)this.switchComponents(this.componentMap[this.switches[t]]);this.switches.length=0}}},methods:{switchComponents:function(t){const e=this.owner,i=e.components,s=t.remove,n=t.add;if(s)if(Array.isArray(s))for(let t=0;t<s.length;t++)for(let n=i.length-1;n>-1;n--)i[n].type===s[t]&&e.removeComponent(i[n]);else for(let t=i.length-1;t>-1;t--)i[t].type===s&&e.removeComponent(i[t]);if(n)if(Array.isArray(n))for(let t=0;t<n.length;t++)e.addComponent(new platypus.components[n[t].type](e,n[t]));else e.addComponent(new platypus.components[n.type](e,n));e.parent.triggerEvent("child-entity-updated",e),e.triggerEvent("add-remove-component-complete")},destroy:function(){V.recycle(this.switches)}},getAssetList:function(t,e,i){const s=t?.componentMap??e?.componentMap??i?.componentMap,n=V.setUp();if(s){const t=Object.keys(s),{length:o}=t;for(let s=0;s<o;s++){const o=map[t[s]].add;for(let t=0;t<o.length;t++){const s=platypus.components[o[t].type];if(s){const r=s.getAssetList(o[t],e,i);F(n,r),V.recycle(r)}}}}return n}}),Qi=xt({id:"ControllerInput",properties:{code:null,controllerType:"button"},initialize(){const{code:t,controllerType:e,owner:i}=this,s=()=>platypus.game.triggerOnChildren("controller-input-up",{code:t??i.type,entity:i}),n=()=>platypus.game.triggerOnChildren("controller-input-down",{code:t??i.type,entity:i});{const t=this.addEventListener("pointerdown",n),e=this.addEventListener("pointerup",s),i=this.addEventListener("pointerupoutside",s),o=this.addEventListener("pointercancel",s);this.unattachControls=()=>{this.removeEventListener("pointerdown",t),this.removeEventListener("pointerup",e),this.removeEventListener("pointerupoutside",i),this.removeEventListener("pointercancel",o)}}}}),Ki=xt({id:"Counter",properties:{persistentStorage:!1},publicProperties:{count:0,progress:0,total:0},initialize:function(){if(this.lastTotal=-1,this.lastCount=-1,this.message=H.setUp("text",""),this.persistentStorage){const t=this.storage=platypus.game.storage;!0===this.persistentStorage&&(this.persistentStorage=this.owner.type),this.count=t.get(this.persistentStorage)||0}},events:{"handle-logic":function(){const t=this.message;let e=!1;this.total!==this.lastTotal&&(this.lastTotal=this.total,e=!0),this.count!==this.lastCount&&(this.lastCount=this.count,this.persistentStorage&&this.storage.set(this.persistentStorage,this.count),e=!0),e&&(this.total?t.text=String(this.count)+"/"+String(this.total):t.text=String(this.count),this.owner.triggerEvent("update-content",t),this.total&&(this.progress=this.count/this.total))},"change-total":function(t){this.total=t},"change-count":function(t){this.count=t},"increment-count":function(){this.count+=1},"decrement-count":function(){this.count-=1}},methods:{destroy:function(){this.message.recycle()}}}),ts=xt({id:"EntityContainer",properties:{childEvents:[]},initialize:function(t,e){const i=this.owner,s=t.entities&&i.entities?t.entities.concat(i.entities):t.entities??i.entities??null,n=this.childEvents;ut.initialize(this),this.newAdds=V.setUp(),this._childEvents={},i.entities=this.entities=V.setUp(),this.childEvents=V.setUp();for(let t=0;t<n.length;t++)this.addNewPublicEvent(n[t]);return this.addNewPrivateEvent("peer-entity-added"),this.addNewPrivateEvent("peer-entity-removed"),!!s&&(Promise.all(s.map(t=>new Promise(e=>this.addEntity(t,e)))).then(e),!0)},events:{"add-entity":function(t,e){this.addEntity(t,e)},"remove-entity":function(t){this.removeEntity(t)},"child-entity-updated":function(t){this.updateChildEventListeners(t)},"handle-logic":function(){const t=this.newAdds,e=t.length;if(e){const i=V.setUp();let s=0;for(let s=0;s<e;s++){const e=t[s];!e.destroyed&&e.loadingComponents||i.push(s)}for(s=i.length;s--;)G(t,i[s]);V.recycle(i)}}},methods:{addNewPublicEvent:function(t){this.addNewPrivateEvent(t);for(let e=0;e<this.childEvents.length;e++)if(this.childEvents[e]===t)return!1;return this.childEvents.push(t),this.addEventListener(t,function(t){return function(e,i){this.triggerOnChildren(t,e,i)}}(t)),!0},addNewPrivateEvent(t){if(this._childEvents[t])return!1;this._childEvents[t]=!0;for(let e=0;e<this.entities.length;e++){const i=this.entities[e]._listeners[t];if(i){const{handlers:s}=i;for(let i=0;i<s.length;i++)this.addChildEventListener(this.entities[e],t,s[i])}}return!0},updateChildEventListeners:function(t){this.removeChildEventListeners(t),this.addChildEventListeners(t)},addChildEventListeners(t){const{_listeners:e}=t,i=Object.keys(e),{length:s}=i;for(let n=0;n<s;n++){const s=i[n],o=e[s];if(o){const{handlers:e}=o;for(let i=0;i<e.length;i++)this.addChildEventListener(t,s,e[i])}}},removeChildEventListeners:function(t){if(t.containerListener?.events){const{events:e,handlers:i}=t.containerListener,{length:s}=e;for(let t=0;t<s;t++)this.off(e[t],i[t].callback,i[t].context);V.recycle(e),V.recycle(i),t.containerListener.recycle(),t.containerListener=null}},addChildEventListener:function(t,e,i){t.containerListener||(t.containerListener=H.setUp("events",V.setUp(),"handlers",V.setUp()));const s=this.on(e,i.callback,i.context,i.once,i.priority);s&&(t.containerListener.events.push(e),t.containerListener.handlers.push(s))},removeChildEventListener:function(t,e,i){const{events:s,handlers:n}=t.containerListener;let o=s.length;for(;o--;)s[o]!==e||i&&n[o].callback!==i||(this.off(e,n[o].callback,n[o].context),G(s,o),G(n,o))},destroy:function(){const t=Z(this.entities);let e=t.length;for(;e--;){const i=t[e];this.removeChildEventListeners(i),i.destroy()}V.recycle(t),V.recycle(this.entities),this.owner.entities=null,V.recycle(this.childEvents),this.childEvents=null,V.recycle(this.newAdds),this.newAdds=null}},publicMethods:{getEntityById:function(t){const e=this.entities.filter(e=>e.id===t)[0]??this.newAdds.filter(e=>e.id===t)[0];if(e)return e;for(let e=0;e<this.entities.length;e++){const i=this.entities[e].getEntityById?.(t);if(i)return i}return null},getEntitiesByType:function(t){const e=V.setUp();for(let i=0;i<this.entities.length;i++)if(this.entities[i].type===t&&e.push(this.entities[i]),this.entities[i].getEntitiesByType){const s=this.entities[i].getEntitiesByType(t);F(e,s),V.recycle(s)}return e},addEntity(t,e){const{owner:i}=this,s=t=>{const{owner:i,entities:s}=this;let n=s.length;for(t.triggerEvent("adopted",t);n--&&t.triggerEvent("peer-entity-added",s[n]););this.triggerEventOnChildren("peer-entity-added",t),this.addChildEventListeners(t),s.push(t),i.triggerEvent("child-entity-added",t),e&&e(t)};let n=null;if(t instanceof kt)n=t,n.parent=i,s(n);else{if("string"==typeof t){const e=platypus.game.settings.entities[t];if(!e)throw new Error(`EntityContainer: There is no entity defined for type "${t}".`);n=new kt(e,{},s,i)}else if(t.id)n=new kt(t,{},s,i);else{const e=platypus.game.settings.entities[t.type];if(!e)throw new Error(`EntityContainer: There is no entity defined for type "${t.type}".`);n=new kt(e,t,s,i)}this.owner.triggerEvent("entity-created",n)}return this.newAdds.push(n),n},removeEntity:function(t){const e=this.entities.indexOf(t);return e>=0&&(this.removeChildEventListeners(t),G(this.entities,e),this.triggerEventOnChildren("peer-entity-removed",t),this.owner.triggerEvent("child-entity-removed",t),t.destroy(),t.parent=null,t)},triggerEventOnChildren:function(t,e,i){return this.destroyed?0:(this._childEvents[t]||this.addNewPrivateEvent(t),this.triggerEvent(t,e,i))},triggerOnChildren:function(t){return this.destroyed?0:(this._childEvents[t]||this.addNewPrivateEvent(t),this.trigger.apply(this,arguments))}},getAssetList:function(t,e,i,s){const n=V.setUp(),o=V.setUp();t.entities&&F(o,t.entities),e&&e.entities?F(o,e.entities):i&&i.entities&&F(o,i.entities);for(let t=0;t<o.length;t++){const e=kt.getAssetList(o[t],null,s);F(n,e),V.recycle(e)}return V.recycle(o),n}});ut.mixin(ts);const es=ts,is=function(t,e,i){this.event=t,this.trigger=i,this.active=!1,this.wasActive=!1,this.valid=!0,this.wasValid=!0,this.states=mt.setUp(e),this.inputs=V.setUp(),this.stateSummary=H.setUp("pressed",!1,"released",!1,"triggered",!1)},ss=function(t){return t},ns=is.prototype;ns.update=function(t){const e=this.stateSummary;return this.valid=t.includes(this.states),this.active=this.inputs.some(ss),e.pressed=this.valid&&this.active,e.released=this.wasActive&&(!this.valid&&this.wasValid||this.valid&&!this.active),e.triggered=this.valid&&this.active&&!this.wasActive,this.wasValid=this.valid,this.wasActive=this.active,e.pressed||e.released||e.triggered},ns.resolve=function(){this.trigger(this.event,this.stateSummary)},N.add(is,"ActionState",is,function(){this.states.recycle(),this.stateSummary.recycle(),V.recycle(this.inputs)},!0);const os=is,rs=[null,null,null,null,["east","south","west","north"],null,null,null,["east","southeast","south","southwest","west","northwest","north","northeast"],null,null,null,null,null,null,null,["east","east-southeast","southeast","south-southeast","south","south-southwest","southwest","west-southwest","west","west-northwest","northwest","north-northwest","north","north-northeast","northeast","east-northeast"]],as=["left-button","middle-button","right-button"],hs=function(t,e){this.paused||this.owner.trigger(t,e)},ls=function(t,e,i){!this.paused&&i[t]&&this.owner.trigger(e,i)},cs=xt({id:"EntityController",properties:{controlMap:{},joystick:null,stateMaps:{}},publicProperties:{paused:!1},initialize:function(t){const e=this.stateMaps;if(this.actions=et.setUp(),e){const t=Object.keys(e),{length:i}=t;for(let s=0;s<i;s++){const i=t[s],n=mt.setUp(i);this.addMap(e[i],i,n),n.recycle()}}this.addMap(this.controlMap,"default"),t.joystick&&(this.joystick=H.setUp("directions",t.joystick.directions||4,"handleEdge",t.joystick.handleEdge||!1,"innerRadius",t.joystick.innerRadius||0,"outerRadius",t.joystick.outerRadius||1/0))},events:{"handle-controller":function(){const t=this.actions,e=t.keys,i=V.setUp(),s=this.owner.state;let n=e.length,o=0;for(;n--;){const o=t.get(e[n]);o.update(s)&&i.push(o)}for(o=i.length;o--;)i[o].resolve();V.recycle(i)},pointerdown:function(t){"mouse"===t.pixiEvent.data.pointerType&&this.owner.triggerEvent("mouse:"+as[t.event.button||0]+":down",t.event),this.joystick&&(this.owner.triggerEvent("joystick:down",t.event),this.handleJoy(t))},pressup:function(t){const e=this.owner;"mouse"===t.pixiEvent.data.pointerType&&e.triggerEvent("mouse:"+as[t.event.button||0]+":up",t.event),this.joystick&&(e.triggerEvent("joystick:up",t.event),e.triggerEvent("stop"))},pressmove:function(t){this.joystick&&this.handleJoy(t)},"pause-controls":function(){this.paused=!0},"unpause-controls":function(){this.paused=!1}},methods:{handleJoy:function(t){const e=this.joystick,i=function(t,e){const i=e.x-t.x,s=e.y-t.y;return Math.sqrt(i*i+s*s)}(owner,t);if(!(i>e.outerRadius||i<e.innerRadius||this.paused)){const s=this.owner,n=Math.PI/(e.directions/2),o=function(t,e,i){const s=e.x-t.x,n=e.y-t.y,o=2*Math.PI;let r=0;return i?(r=Math.acos(s/i),n<0&&(r=o-r),r):r}(s,t,i),r=rs[e.directions][Math.floor((o+n/2)%(2*Math.PI)/n)];if(e.handleEdge){const i=Math.PI/e.directions,n=rs[2*e.directions][Math.floor((o+i/2)%(2*Math.PI)/i)];n!==r&&s.triggerEvent(n.replace(r,"").replace("-",""),t)}s.triggerEvent("stop"),s.triggerEvent(r,t),s.triggerEvent("joystick-orientation",o)}},addController:function(){const t=function(t){this.inputs[t]=!1},e=function(t){this.inputs[t]=!0};return function(i,s,n,o,r){const a=this.actions,h=`${s}-${n}-${r||"all"}`;let l=a.get(h);l||(l=r?a.set(h,os.setUp(n,o,ls.bind(this,r))):a.set(h,os.setUp(n,o,hs.bind(this)))),this.addEventListener(i+":up",t.bind(l,l.inputs.length)),this.addEventListener(i+":down",e.bind(l,l.inputs.length)),l.inputs.push(!1)}}(),addMap:function(t,e,i){const s=Object.keys(t),{length:n}=s;for(let o=0;o<n;o++){const n=s[o],r=t[n];if("string"==typeof r)this.addController(n,e,r,i);else if(Array.isArray(r))for(let t=0;t<r.length;t++)this.addController(n,e,r[t],i);else{const t=Object.keys(r),{length:s}=t;for(let o=0;o<s;o++){const s=t[o],a=r[s];if("string"==typeof a)this.addController(n,e,a,i,s);else for(let t=0;t<a.length;t++)this.addController(n,e,a[t],i,s)}}}},destroy:function(){const t=this.actions,e=t.keys;let i=e.length;for(;i--;)t.get(e[i]).recycle();t.recycle(),this.joystick&&this.joystick.recycle()}}}),ds=function(t){this.vector||(this.vector=Ht.setUp()),t instanceof ds?this.copy(t):this.set.apply(this,arguments)},us=ds.prototype;us.set=function(t,e,i,s,n,o,r,a,h){this.occurred=t||!1,this.direction=e||null,this.position=i||null,this.deltaMovement=s||null,this.aABB=n||null,this.thisShape=o||null,this.thatShape=r||null,this.vector.set(a),this.stuck=h||0},us.copy=function(t){this.occurred=t.occurred,this.direction=t.direction,this.position=t.position,this.deltaMovement=t.deltaMovement,this.aABB=t.aABB,this.thisShape=t.thisShape,this.thatShape=t.thatShape,this.vector.setVector(t.vector),this.stuck=t.stuck},N.add(ds,"CollisionData",ds,null,!0);const ps=ds,gs=function(){this.xData||this.yData?this.reset():(this.xData=V.setUp(),this.yData=V.setUp(),this.xDeltaMovement=1/0,this.yDeltaMovement=1/0)},fs=gs.prototype;fs.tryToAddX=function(t){return!(t.deltaMovement>this.xDeltaMovement||(t.deltaMovement<this.xDeltaMovement&&this.resetX(t.deltaMovement),this.xData.push(t),0))},fs.tryToAddY=function(t){return!(t.deltaMovement>this.yDeltaMovement||(t.deltaMovement<this.yDeltaMovement&&this.resetY(t.deltaMovement),this.yData.push(t),0))},fs.reset=function(){this.resetX(1/0),this.resetY(1/0)},fs.resetX=function(t){const{xData:e}=this;let i=e.length;for(;i--;)e[i].recycle();e.length=0,this.xDeltaMovement=t},fs.resetY=function(t){const{yData:e}=this;let i=e.length;for(;i--;)e[i].recycle();e.length=0,this.yDeltaMovement=t},N.add(gs,"CollisionDataContainer",gs,null,!0);const ys=gs,ms=function(t,e){return t<<16|65535&e},vs={entity:null,target:null,type:null,x:0,y:0,hitType:null,myType:null},ws=function(t,e){return t.collisionGroup.getAllEntities()-e.collisionGroup.getAllEntities()},bs=1e-6,xs=xt({id:"HandlerCollision",properties:{gridBits:8},initialize:function(){this.againstGrid=H.setUp(),this.solidEntitiesLive=V.setUp(),this.softEntitiesLive=V.setUp(),this.allEntitiesLive=V.setUp(),this.groupsLive=V.setUp(),this.nonColliders=V.setUp(),this.terrains=[],this.owner.previousX=this.owner.previousX||this.owner.x,this.owner.previousY=this.owner.previousY||this.owner.y,this.relocationMessage=H.setUp("position",Ht.setUp(),"relative",!1)},events:{"child-entity-added":function(t){t.collideOff||this.addCollisionEntity(t)},"add-collision-entity":function(t){this.addCollisionEntity(t)},"child-entity-removed":function(t){this.removeCollisionEntity(t)},"remove-collision-entity":function(t){this.removeCollisionEntity(t)},"child-entity-updated":function(t){this.removeCollisionEntity(t),this.addCollisionEntity(t)},"check-collision-group":function(t){this.checkCamera(t.camera,t.entities),this.checkGroupCollisions(),this.checkSolidCollisions(),this.resolveNonCollisions(),this.checkSoftCollisions(t)}},methods:{mapDown(t){const e=Ci.setUp(),i=this.gridBits;return e.setBounds(t.left>>i,t.top>>i,t.right>>i,t.bottom>>i)},getAgainstGrid(t,e,i){const s=this.mapDown(e),n=H.setUp(),o=this.againstGrid;if(t&&e.equals(t.againstAABB))return this.getEntityAgainstGrid(t,i);for(let t=s.left;t<=s.right;t++)for(let e=s.top;e<=s.bottom;e++){const s=o[ms(t,e)];s&&this.mergeAGCell(s,n,i)}return s.recycle(),n},getEntityAgainstGrid:function(t,e){const i=t.againstGrid,s=H.setUp();let n=i.length;for(;n--;)this.mergeAGCell(i[n],s,e);return s},mergeAGCell:function(t,e,i){let s=i.length;for(;s--;){const n=i[s],o=t.get(n);if(o?.length){const t=e[n];t?F(t,o):e[n]=F(V.setUp(),o)}}},removeAgainst(t){const{collisionTypes:e,againstGrid:i}=t,s=e.length;let n=i.length;for(;n--;){const o=i[n];let r=s;for(;r--;){const i=o.get(e[r]);if(i){const e=i.indexOf(t);e>=0&&G(i,e)}}}i.length=0},updateAgainst(t){const{againstAABB:e,againstGrid:i,collisionTypes:s}=t,n=this.mapDown(t.getAABB()),{againstGrid:o}=this;if(!n.equals(e)){e.set(n),this.removeAgainst(t);for(let e=n.left;e<=n.right;e++)for(let r=n.top;r<=n.bottom;r++){const n=ms(e,r);let a=o[n],h=s.length;for(a||(a=o[n]=et.setUp());h--;){const e=s[h];(a.get(e)??a.set(e,V.setUp())).push(t)}i.push(a)}}n.recycle()},addCollisionEntity:function(t){t.getTileShapes?this.terrains.push(t):t.collisionTypes&&!t.againstGrid&&(t.againstGrid=V.setUp(),t.againstAABB=Ci.setUp(),this.updateAgainst(t))},removeCollisionEntity:function(t){if(t.getTileShapes){const e=this.terrains.indexOf(t);-1!==e&&this.terrains.splice(e,1)}t.againstGrid&&(this.removeAgainst(t),V.recycle(t.againstGrid),t.againstGrid=null,t.againstAABB.recycle(),t.againstAABB=null)},checkCamera:function(t,e){const{allEntitiesLive:i,solidEntitiesLive:s,softEntitiesLive:n,nonColliders:o,groupsLive:r}=this;let a=e.length;for(i.length=0,s.length=0,n.length=0,o.length=0,r.length=0;a--;){const t=e[a],{collisionTypes:h,immobile:l}=t;if(!l&&h?.length){let e=!1,a=h.length;if(i.push(t),t!==this.owner){let i=h.length;for(;i--;)if(t.solidCollisionMap.get(h[i]).length){s.push(t),e=!0;break}}for(;a--;)if(t.softCollisionMap.get(h[a]).length){n.push(t);break}e||o.push(t),t.collisionGroup&&r.push(t)}}r.sort(ws)},resolveNonCollisions:function(){const t=this.relocationMessage,e=this.nonColliders;let i=e.length;for(t.relative=!1;i--;){const s=e[i];s.position.x===s.previousPosition.x&&s.position.y===s.previousPosition.y||(t.position.setVector(s.position),s.triggerEvent("relocate-entity",t),this.updateAgainst(s))}},checkGroupCollisions:function(){const t=function(t,e,i,s,n,o,r,a){const h=vs;h.entity=e,h.target=t,h.myType=i,h.type=s,h.x=n,h.y=o,h.direction=a,h.hitType=r,t.triggerEvent("hit-by-"+s,h),e&&(h.entity=t,h.target=e,h.type=i,h.myType=s,h.x=-n,h.y=-o,h.direction=a.getInverse(),h.hitType=r,e.triggerEvent("hit-by-"+i,h),h.direction.recycle())};return function(){const e=this.groupsLive;let i=e.length;for(;i--;){const s=e[i];if(s.collisionGroup.getSize()>1){const e=this.checkSolidEntityCollision(s,s.collisionGroup),{xData:i,yData:n}=e;let o=i.length,r=n.length;for(;o--;){const e=i[o];t(e.thisShape.owner,e.thatShape.owner,e.thisShape.collisionType,e.thatShape.collisionType,e.direction,0,"solid",e.vector)}for(;r--;){const e=n[r];t(e.thisShape.owner,e.thatShape.owner,e.thisShape.collisionType,e.thatShape.collisionType,0,e.direction,"solid",e.vector)}e.recycle()}}}}(),checkSolidCollisions:function(){const t=function(t,e,i,s,n,o,r,a){const h=vs;h.entity=e,h.target=t,h.myType=i,h.type=s,h.x=n,h.y=o,h.direction=a,h.hitType=r,t.triggerEvent("hit-by-"+s,h),e&&(h.entity=t,h.target=e,h.type=i,h.myType=s,h.x=-n,h.y=-o,h.direction=a.getInverse(),h.hitType=r,e.triggerEvent("hit-by-"+i,h),h.direction.recycle())};return function(){const e=this.solidEntitiesLive;let i=e.length;for(;i--;){const s=e[i],n=this.checkSolidEntityCollision(s,s),{xData:o,yData:r}=n;let a=o.length,h=r.length;for(;a--;){const e=o[a];t(e.thisShape.owner,e.thatShape.owner,e.thisShape.collisionType,e.thatShape.collisionType,e.direction,0,"solid",e.vector)}for(;h--;){const e=r[h];t(e.thisShape.owner,e.thatShape.owner,e.thisShape.collisionType,e.thatShape.collisionType,0,e.direction,"solid",e.vector)}n.recycle()}}}(),checkSolidEntityCollision:function(t,e){const{bullet:i,collisionDirty:s,previousX:n,previousY:o,x:r,y:a}=t,h=ys.setUp(),l=r-n,c=a-o,d=e.getCollisionTypes(),u=e.getSolidEntities?.()??!1;let p=Ht.setUp(t.position);if(l||c||s){if(i){let i=1/0,s=1/0,n=d.length;for(;n--;){const t=e.getAABB(d[n]);i=Math.min(i,t.width),s=Math.min(s,t.height)}{const n=Math.min(Math.ceil(Math.max(Math.abs(l)/i,Math.abs(c)/s)),100),o=l/n,r=c/n;let a=n;for(;a--;){if(e.prepareCollision(t.previousX+o,t.previousY+r),p=this.processCollisionStep(t,e,u,h,p.setVector(t.position),o,r,d),p.x===t.previousX&&p.y===t.previousY){e.relocateEntity(p,h);break}e.relocateEntity(p,h)}}}else e.prepareCollision(n+l,o+c),p=this.processCollisionStep(t,e,u,h,p,l,c,d),e.relocateEntity(p,h);if((p.x!==n||p.y!==o)&&(this.updateAgainst(t),t!==e)){const t=e.getSolidEntities();for(let e=0;e<t.length;e++)this.updateAgainst(t[e])}}return p.recycle(),h},processCollisionStep:function(){const t=Ci.setUp(),e=function(t){const e=t.jumpThrough;if(e){const i=t.owner,s=Ht.setUp(e.x*(i.scaleX||1),e.y*(i.scaleY||1));return i.rotation&&s.rotate(i.rotation*Math.PI/180),s}return null},i=function(t,i,s){const n=t.collisionTypes;if(!n)return!0;let o=n.length;for(;o--;){const r=t.getShapes(n[o]);if(!r)continue;let a=r.length;for(;a--;){const t=r[a],n=e(t);if(n){const t=Math.abs(n.x),e=Math.abs(n.y)>=t?n.y<-bs&&i.bottom>s.top||n.y>bs&&i.top<s.bottom:n.x<-bs&&i.right>s.left||n.x>bs&&i.left<s.right;if(n.recycle(),e)return e}}}return!1},s=function(t,e,s,n,o,r){if(s===t)return!1;if(i(s,e,n))return!1;if(i(t,n,e))return!1;if(o){let t=o.length;for(;t--;)if(s===o[t])return!1}return r.collides(n)};return function(e,i,n,o,r,a,h,l){const c=V.setUp(),d=this.terrains,u=i.getSolidCollisions(),p=t;let g=l.length,f=!1;for(;g--;){const t=c[g]=V.setUp(),o=l[g],r=i.getPreviousAABB(o),a=i.getAABB(o),h=u.get(o);let y=null,m=h.length;for(p.set(a),p.include(r),y=this.getAgainstGrid(e,p,h);m--;){const i=h[m],o=y[i];if(o){let a=o.length;for(;a--;){const h=o[a],l=h.getAABB(i);if(s(e,r,h,l,n,p)){const e=h.getShapes(i);let s=e.length;for(;s--;)t.push(e[s]);f=!0}}V.recycle(o)}else if(d.length){let e=0;for(e=0;e<d.length;e++){const s=d[e].getTileShapes(p,r,i);let n=s.length;for(;n--;)t.push(s[n]),f=!0}}}y.recycle()}return f&&(r=this.resolveCollisionPosition(e,i,r,c,o,l,a,h)),V.recycle(c,2),r}}(),resolveCollisionPosition:function(t,e,i,s,n,o,r,a){if(0!==r){let i=o.length;for(;i--;){const r=this.findMinAxisMovement(t,e,o[i],"x",s[i]);r.occurred&&n.tryToAddX(r)||r.recycle()}}{const e=n.xData[0];i.x=e?t.previousX+e.deltaMovement*e.direction:t.x}if(e.movePreviousX(i.x),0!==a){let i=o.length;for(;i--;){const r=this.findMinAxisMovement(t,e,o[i],"y",s[i]);r.occurred&&n.tryToAddY(r)||r.recycle()}}{const e=n.yData[0];i.y=e?t.previousY+e.deltaMovement*e.direction:t.y}return i},findMinAxisMovement:function(t,e,i,s,n){const o=e.getShapes(i),r=e.getPrevShapes(i);let a=ps.setUp(),h=o.length;for(;h--;){const t=this.findMinShapeMovementCollision(r[h],o[h],s,n);t.occurred&&(!a.occurred||t.deltaMovement<a.deltaMovement)?(a.recycle(),a=t):t.recycle()}return a},findMinShapeMovementCollision:function(){const t={position:0,contactVector:Ht.setUp()},e=(t,e)=>Math.sqrt(e**2-t**2),i=function(t,e,i){const s=t-e;return s-s/Math.abs(s)*i},s=function(t,s,n,o,r){const a=s.aABB,h=a.halfWidth,{x:l,y:c}=t;if(c>=a.top&&c<=a.bottom)return h+t.radius;{const d=i(c,s.y,a.halfHeight),u=h+e(d,t.radius);return n===t?(r.x=-i(l-o*u,s.x,h)/2,r.y=-d):(r.x=i(l,s.x-o*u,h)/2,r.y=d),r.normalize(),u}},n=function(t,s,n,o,r){const a=s.aABB,h=a.halfHeight,{x:l,y:c}=t;if(l>=a.left&&l<=a.right)return h+t.radius;{const d=i(l,s.x,a.halfWidth),u=h+e(d,t.radius);return n===t?(r.x=-d,r.y=-i(c-o*u,s.y,h)/2):(r.x=d,r.y=i(c,s.y-o*u,h)/2),r.normalize(),u}},o={x:{rectangle:{rectangle:function(e,i,s){const n=t;return n.position=s.x-e*(s.aABB.halfWidth+i.aABB.halfWidth),n.contactVector.setXYZ(e,0),n},circle:function(e,i,n){const o=t;return o.position=n.x-e*s(n,i,i,e,o.contactVector.setXYZ(e,0)),o}},circle:{rectangle:function(e,i,n){const o=t;return o.position=n.x-e*s(i,n,i,e,o.contactVector.setXYZ(e,0)),o},circle:function(i,s,n){const o=n.y-s.y,r=n.x-i*e(o,s.radius+n.radius),a=t;return a.contactVector.setXYZ(n.x-r,o).normalize(),a.position=r,a}}},y:{rectangle:{rectangle:function(e,i,s){const n=t;return n.position=s.y-e*(s.aABB.halfHeight+i.aABB.halfHeight),n.contactVector.setXYZ(0,e),n},circle:function(e,i,s){const o=t;return o.position=s.y-e*n(s,i,i,e,o.contactVector.setXYZ(0,e)),o}},circle:{rectangle:function(e,i,s){const o=t;return o.position=s.y-e*n(i,s,i,e,o.contactVector.setXYZ(0,e)),o},circle:function(i,s,n){const o=n.x-s.x,r=n.y-i*e(o,s.radius+n.radius),a=t;return a.contactVector.setXYZ(o,n.y-r).normalize(),a.position=r,a}}}};return function(t,e,i,s){const n=t[i],r=e[i],a=n<r?1:-1,h=ps.setUp();let l=r;if(n!==r){const c=o[i][t.type];let d=s.length;for("x"===i?t.moveX(r):"y"===i&&t.moveY(r);d--;){const i=s[d];if(t.collides(i)){const s=c[i.type](a,t,i),o=s.position;a>0?o<l&&(l=o<n?n:o,h.set(!0,a,l,Math.abs(l-n),i.aABB,e,i,s.contactVector,0)):o>l&&(l=o>n?n:o,h.set(!0,a,l,Math.abs(l-n),i.aABB,e,i,s.contactVector,0))}}}return h}}(),checkSoftCollisions(){const t=this.softEntitiesLive;let e=t.length;for(;e--;){const i=t[e];this.checkEntityForSoftCollisions(i,t=>{i.triggerEvent("hit-by-"+t.type,t)})}},checkEntityForSoftCollisions:function(t,e){const i=vs,s=this.terrains;let n=t.collisionTypes.length;for(i.x=0,i.y=0;n--;){const o=t.collisionTypes[n],r=t.softCollisionMap.get(o),a=this.getEntityAgainstGrid(t,r);let h=r.length;for(;h--;){const n=r[h],l=a[n];if(l){let s=l.length;for(;s--;){const r=l[s];if(r!==t&&t.getAABB(o).collides(r.getAABB(n))){const s=t.getShapes(o),a=r.getShapes(n);let h=!1,l=s.length;for(;l--;){let c=a.length;for(;c--;)if(s[l].collides(a[c])){i.entity=r,i.target=t,i.type=n,i.myType=o,i.shape=a[c],i.hitType="soft",e(i),h=!0;break}if(h)break}}}V.recycle(l)}if(s.length){let r=0;for(r=0;r<s.length;r++){const a=t.getAABB(o),h=s[r].getTileShapes(a,a,n);let l=h.length;for(;l--;)i.entity=s[r],i.target=t,i.type=n,i.myType=o,i.shape=h[l],i.hitType="soft",e(i)}}}a.recycle()}},checkShapeForCollisions:function(t,e,i){const s=this.getAgainstGrid(null,t.getAABB(),e),n=vs;let o=e.length;for(n.x=0,n.y=0;o--;){const r=e[o],a=s[r];if(a){let e=a.length;for(;e--;){const s=a[e];if(t.getAABB().collides(s.getAABB(r))){const e=s.getShapes(r);let o=e.length;for(;o--;)if(t.collides(e[o])){n.entity=s,n.target=null,n.type=r,n.myType="",n.shape=e[o],n.hitType="soft",i(n);break}}}V.recycle(a)}}s.recycle()},checkPointForCollisions:function(t,e,i,s){const n=this.gridBits,o=this.againstGrid[function(t,e,i){return ms(t>>i,e>>i)}(t,e,n)],r=vs;let a=i.length;if(r.x=0,r.y=0,o)for(;a--;){const n=i[a],h=o.get(n);if(h){let i=h.length;for(;i--;){const o=h[i];if(o.getAABB(n).containsPoint(t,e)){const i=o.getShapes(n);let a=i.length;for(;a--;)if(i[a].containsPoint(t,e)){r.entity=o,r.target=null,r.type=n,r.myType="",r.shape=i[a],r.hitType="soft",s(r);break}}}}}},destroy:function(){const t=this.againstGrid,e=Object.keys(t),{length:i}=e;V.recycle(this.groupsLive),V.recycle(this.nonColliders),V.recycle(this.allEntitiesLive),V.recycle(this.softEntitiesLive),V.recycle(this.solidEntitiesLive),this.relocationMessage.position.recycle(),this.relocationMessage.recycle();for(let s=0;s<i;s++){const i=t[e[s]],n=i.keys;let o=n.length;for(;o--;)V.recycle(i.get(n[o]));i.recycle()}t.recycle(),this.againstGrid=null}},publicMethods:{getWorldEntities:function(){return this.allEntitiesLive},getWorldTerrain:function(){return this.terrains},getEntityCollisions:function(t){const e=V.setUp();return this.checkEntityForSoftCollisions(t,t=>e.push(H.setUp(t))),e},getShapeCollisions:function(t,e){const i=V.setUp();return this.checkShapeForCollisions(t,e,t=>i.push(H.setUp(t))),i},getPointCollisions:function(t,e,i){const s=V.setUp();return this.checkPointForCollisions(t,e,i,t=>s.push(H.setUp(t))),s}}}),_s=function(t,e,i,s,n="",o=.1){this.source=t,this.deadzone=o,this.axes=this.axes||V.setUp();for(let e=0;e<t.axes.length>>1;e++)this.axes.push(Es(Ht.setUp(t.axes[2*e],t.axes[2*e+1]),o));this.buttons=this.buttons||V.setUp();for(let e=0;e<t.buttons.length;e++)this.buttons.push(t.buttons[e].value);this.id=n||`${t.id} - ${t.index}`,this.onDown=e,this.onUp=i,this.onChange=s},Cs={duration:500,startDelay:0,strongMagnitude:1,weakMagnitude:1},ks={a0:"LeftStick",a1:"RightStick",b0:"AButton",b1:"BButton",b2:"XButton",b3:"YButton",b4:"LeftBumper",b5:"RightBumper",b6:"LeftTrigger",b7:"RightTrigger",b8:"BackButton",b9:"StartButton",b10:"LeftStickButton",b11:"RightStickButton",b12:"UpDPad",b13:"DownDPad",b14:"LeftDPad",b15:"RightDPad"},Es=function(t,e){const i=t.magnitude();if(i>1)t.x*=1/i,t.y*=1/i;else if(i<e)t.x=0,t.y=0;else{const i=1-e;t.x=(t.x-e)/i,t.y=(t.y-e)/i}return t},As=_s.prototype;As.dualRumble=function(t=500,e=0,i=1,s=1){Cs.duration=t,Cs.startDelay=e,Cs.strongMagnitude=i,Cs.weakMagnitude=s,this.source.vibrationActuator.playEffect("dual-rumble",Cs)},As.update=function(t){const e=this.axes,i=this.buttons,s=this.onDown,n=this.onUp,o=this.onChange;for(let i=0;i<e.length;i++){const s=e[i],n=Es(Ht.setUp(t.axes[2*i],t.axes[2*i+1]),this.deadzone);if(!n.equals(s,2)){const t=H.setUp("code",ks[`a${i}`],"direction",s,"gamepad",this,"id",this.id);s.set(n),o(t),t.recycle()}n.recycle()}for(let e=0;e<t.buttons.length;e++){const r=t.buttons[e],a=r.value,h=i[e];if(a!==h){const t=H.setUp("code",ks[`b${e}`],"button",r,"gamepad",this,"id",this.id);i[e]=a,0===h?(s(t),o(t)):0===a?(o(t),n(t)):o(t),t.recycle()}}},N.add(_s,"Gamepad",_s,function(){for(let t=0;t<this.axes.length;t++)this.axes[t].recycle();this.axes.length=0,this.buttons.length=0,this.onDown=null,this.onUp=null,this.onChange=null},!0);const Ss=_s,Ms=function(t){if(Ds){const t=[...window.navigator.getGamepads()],e=this.gamepads;for(let i=0;i<t.length;i++){const s=t[i];if(s){const t=e[s.index];t?t.update(s):e[s.index]=Ss.setUp(s,Ts.bind(this,"gamepad"),Us.bind(this,"gamepad"),Ps.bind(this,"gamepad"))}}}this.triggerOnAll("handle-controller",t)},Ts=function(t,e){this.triggerControlAction(e.code,"down",e),Os(t),this.upOnBlur&&this.upsToBlur.push(e.code)},Us=function(t,e){if(this.triggerControlAction(e.code,"up",e),Os(t),this.upOnBlur){const t=this.upsToBlur.indexOf(e.code);t>=0&&this.upsToBlur.splice(t,1)}},Ps=function(t,e){this.triggerControlAction(e.code,"change",e),Os(t)},Os=t=>{if(t!==Ls[0]){const e=Ls.indexOf(t);e>0&&G(Ls,e),Ls.unshift(t);for(let t=0;t<zs.length;t++)zs[t](Ls)}},Ls=[],zs=[],Bs={},Is={};let Ds=!1,Xs=!1;window.addEventListener("gamepadconnected",()=>{Ds=!0,Os("gamepad")}),window.addEventListener("touchstart",()=>{Os("touch")}),window.addEventListener("mousedown",()=>{Os("mouse")});const Rs=xt({id:"HandlerController",properties:{useHandleLogic:!1,upOnBlur:!0,enableDefaultEvents:"none"},publicProperties:{inputPrecedence:Ls},initialize:function(){const{enableDefaultEvents:t}=this;if(this.upsToBlur=[],platypus.game.settings.debug||"all"===t)this.callbackKeyDown=Ts.bind(this,"keyboard"),this.callbackKeyUp=Us.bind(this,"keyboard");else{const e=Array.isArray(t)?e=>-1===t.indexOf(e.code)?e.preventDefault():null:t=>t.preventDefault();this.callbackKeyDown=t=>{Ts.call(this,"keyboard",t),e(t)},this.callbackKeyUp=t=>{Us.call(this,"keyboard",t),e(t)}}window.addEventListener("keydown",this.callbackKeyDown,!0),window.addEventListener("keyup",this.callbackKeyUp,!0),this.addEventListener("controller-input-down",t=>this.triggerControlAction(t.code,"down",t)),this.addEventListener("controller-input-up",t=>this.triggerControlAction(t.code,"up",t)),this.useHandleLogic?this.addEventListener("handle-logic",Ms):this.addEventListener("tick",Ms),this.gamepads=V.setUp(),this.notifier=t=>{this.triggerOnAll("input-precedence-updated",t)},zs.push(this.notifier),Xs||(Xs=!0,platypus.game.on("tick",function(){const t=Object.keys(Bs),{length:e}=t;for(let i=0;i<e;i++){const e=t[i];0===Bs[e]?this.triggerOnChildren("invalid-input",e):this.triggerOnChildren("valid-input",e),delete Bs[e]}}.bind(platypus.game)),window.addEventListener("blur",()=>{platypus.game.triggerOnChildren("blur-control")}))},events:{"blur-control":function(t){this.upOnBlur&&(this.upsToBlur.forEach(e=>this.triggerControlAction(e,"up",t)),this.upsToBlur.length=0)},"invalid-input":function(t){this.owner.triggerEventOnChildren("invalid-input",t)},"valid-input":function(t){this.owner.triggerEventOnChildren("valid-input",t)}},methods:{destroy:function(){window.removeEventListener("keydown",this.callbackKeyDown),window.removeEventListener("keyup",this.callbackKeyUp);for(let t=0;t<this.gamepads.length;t++)this.gamepads[t]&&this.gamepads[t].recycle();V.recycle(this.gamepads),G(zs,zs.indexOf(this.notifier))},triggerControlAction:function(t,e,...i){const s=`${t}:${e}`;Is[t]=(Is[t]||0)+this.triggerOnAll(s,...i),"up"===e&&(Bs[t]=(Bs[t]||0)+Is[t],Is[t]=0)},triggerOnAll:function(t,...e){const i=this.owner;let s=i.triggerEvent(t,...e);return i.triggerEventOnChildren&&(s+=i.triggerEventOnChildren(t,...e)),s}}}),js=function(t,e){let i=t.length;for(e.length=0;i--;)e.push(t[i])},Ys=function(t,e){return t.alwaysOn||t.aabb&&e.collides(t.getAABB())||void 0===t.x||e.containsPoint(t.x,t.y)},Ns=function(t,e,i){let s=t.length;for(e.length=0;s--;){const n=t[s];Ys(n,i)&&e.push(n)}},Ws=function(t){return"handle-logic"===t||"handle-post-collision-logic"===t||"prepare-logic"===t||"state-changed"===t||"handle-movement"===t},Hs=xt({id:"HandlerLogic",properties:{alwaysOn:!1},publicProperties:{buffer:-1,stepLength:5,maxStepsPerTick:100,timeMultiplier:1},initialize:function(){this.entities=V.setUp(),this.activeEntities=V.setUp(),this.removals=V.setUp(),this.inLogicLoop=!1,this.alwaysOn?(this.updateList=js,this.camera=null):(this.updateList=Ns,this.camera=Ci.setUp()),this.paused=0,this.leftoverTime=0,this.message={delta:this.stepLength,tick:null,camera:this.camera,entities:this.activeEntities}},events:{"child-entity-updated":function(t){const e=this.entities.indexOf(t),i=t.getMessageIds().some(Ws);i&&e<0?(this.entities.push(t),!this.inLogicLoop||this.camera&&!Ys(t,this.camera)||this.activeEntities.push(t)):!i&&e>=0&&(G(this.entities,e),this.inLogicLoop&&this.removals.push(t))},"child-entity-added":function(t){t.getMessageIds().some(Ws)&&(this.entities.push(t),!this.inLogicLoop||this.camera&&!Ys(t,this.camera)||this.activeEntities.push(t))},"child-entity-removed":function(t){const e=this.entities.indexOf(t);e>=0&&(G(this.entities,e),this.inLogicLoop&&this.removals.push(t))},"pause-logic":function(t){t&&t.time?this.paused=t.time:this.paused=-1,this.owner.triggerEventOnChildren&&this.owner.triggerEventOnChildren("logic-paused")},"unpause-logic":function(){this.paused=0,this.owner.triggerEventOnChildren&&this.owner.triggerEventOnChildren("logic-unpaused")},"camera-update":function(t){const e=this.camera;if(e){const i=-1===this.buffer?t.viewport.width/10:this.buffer,s=t.viewport;e.setBounds(s.left-i,s.top-i,s.right+i,s.bottom+i)}},tick:function(t){const{activeEntities:e,message:i,removals:s}=this,n=this.stepLength*this.timeMultiplier;let o=0;for(this.leftoverTime+=t.delta*this.timeMultiplier,o=Math.floor(this.leftoverTime/n)||1,i.gameDelta=this.stepLength,i.delta=n,this.leftoverTime=Math.max(this.leftoverTime-o*n,0),i.tick=t,this.updateList(this.entities,e,this.camera),o=Math.min(o,this.maxStepsPerTick);o--;)if(this.paused>0&&(this.paused-=n,this.paused<0&&(this.paused=0)),!this.paused){let t=0;for(this.inLogicLoop=!0,this.owner.triggerEvent("handle-logic",i),this.owner.triggerEventOnChildren&&this.owner.triggerEventOnChildren("handle-ai",i),t=e.length;t--;){const s=e[t];s.triggerEvent("prepare-logic",i),s.triggerEvent("handle-logic",i),s.triggerEvent("handle-movement",i)}if(this.inLogicLoop=!1,s.length){let t=s.length;for(;t--;){let i=e.indexOf(s[t]);i>=0&&G(e,i)}s.length=0}if(t=e.length,this.owner.triggerEvent("check-collision-group",i))for(;t--;){const s=e[t];s.triggerEvent("handle-post-collision-logic",i),s.lastState?.update(s.state)&&s.triggerEvent("state-changed",s.state)}else for(;t--;){const i=e[t];i.lastState?.update(i.state)&&i.triggerEvent("state-changed",i.state)}}}},methods:{destroy:function(){V.recycle(this.entities),this.entities=null,V.recycle(this.activeEntities),this.activeEntities=null,V.recycle(this.removals),this.removals=null}}}),Vs=xt({id:"HandlerRender",properties:{interactive:!1},publicProperties:{worldContainer:null,timeMultiplier:1},initialize:function(){let t=null;this.worldContainer=this.worldContainer||new n,this.worldContainer.sortableChildren=!0,this.worldContainer.label="",this.interactive&&(t=H.setUp("container",this.worldContainer,"hitArea",this.interactive.hitArea,"hover",this.interactive.hover,"relativeToSelf",!0),this.owner.addComponent(new li(this.owner,t)),t.recycle()),this.renderMessage=H.setUp("delta",0,"container",this.worldContainer,"tick",null)},events:{load:function(){this.owner.triggerEvent("render-world",{world:this.worldContainer}),this.owner.triggerEvent("input-on")},"child-entity-added":function(t){t.triggerEvent("handle-render-load",this.renderMessage)},"pause-render":function(t){t&&t.time?this.paused=t.time:this.paused=-1,this.owner.triggerEventOnChildren&&this.owner.triggerEventOnChildren("render-paused")},"unpause-render":function(){this.paused=0,this.owner.triggerEventOnChildren&&this.owner.triggerEventOnChildren("render-unpaused")},tick:function(t){this.paused>0&&(this.paused-=t.delta,this.paused<=0&&(this.paused=0)),this.paused||this.renderUpdate(t)},"render-update":function(t){this.renderUpdate(t)},"set-parent-render-container":function(t,e){this.setParentRenderContainer(t,e)}},methods:{renderUpdate:function(t){const e=this.renderMessage;e.gameDelta=t&&t.delta||0,e.delta=e.gameDelta*this.timeMultiplier,e.tick=t,this.owner.triggerEvent("handle-render",e),this.owner.triggerEventOnChildren&&this.owner.triggerEventOnChildren("handle-render",e)},setParentRenderContainer:function(t,e){platypus.debug.warn("HandlerRender: No longer required to call 'setParentRenderContainer' on layer - just call 'addToParentContainer' on entity."),t.addToParentContainer(e)},destroy:function(){this.worldContainer=null,this.renderMessage.recycle(),this.renderMessage=null}}});function Fs(t){let e=t.length;for(;--e>=0;)t[e]=0}const Zs=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),Gs=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),qs=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),$s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Js=new Array(576);Fs(Js);const Qs=new Array(60);Fs(Qs);const Ks=new Array(512);Fs(Ks);const tn=new Array(256);Fs(tn);const en=new Array(29);Fs(en);const sn=new Array(30);function nn(t,e,i,s,n){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=s,this.max_length=n,this.has_stree=t&&t.length}let on,rn,an;function hn(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}Fs(sn);const ln=t=>t<256?Ks[t]:Ks[256+(t>>>7)],cn=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},dn=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<<t.bi_valid&65535,cn(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=i)},un=(t,e,i)=>{dn(t,i[2*e],i[2*e+1])},pn=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},gn=(t,e,i)=>{const s=new Array(16);let n,o,r=0;for(n=1;n<=15;n++)r=r+i[n-1]<<1,s[n]=r;for(o=0;o<=e;o++){let e=t[2*o+1];0!==e&&(t[2*o]=pn(s[e]++,e))}},fn=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},yn=t=>{t.bi_valid>8?cn(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},mn=(t,e,i,s)=>{const n=2*e,o=2*i;return t[n]<t[o]||t[n]===t[o]&&s[e]<=s[i]},vn=(t,e,i)=>{const s=t.heap[i];let n=i<<1;for(;n<=t.heap_len&&(n<t.heap_len&&mn(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!mn(e,s,t.heap[n],t.depth));)t.heap[i]=t.heap[n],i=n,n<<=1;t.heap[i]=s},wn=(t,e,i)=>{let s,n,o,r,a=0;if(0!==t.sym_next)do{s=255&t.pending_buf[t.sym_buf+a++],s+=(255&t.pending_buf[t.sym_buf+a++])<<8,n=t.pending_buf[t.sym_buf+a++],0===s?un(t,n,e):(o=tn[n],un(t,o+256+1,e),r=Zs[o],0!==r&&(n-=en[o],dn(t,n,r)),s--,o=ln(s),un(t,o,i),r=Gs[o],0!==r&&(s-=sn[o],dn(t,s,r)))}while(a<t.sym_next);un(t,256,e)},bn=(t,e)=>{const i=e.dyn_tree,s=e.stat_desc.static_tree,n=e.stat_desc.has_stree,o=e.stat_desc.elems;let r,a,h,l=-1;for(t.heap_len=0,t.heap_max=573,r=0;r<o;r++)0!==i[2*r]?(t.heap[++t.heap_len]=l=r,t.depth[r]=0):i[2*r+1]=0;for(;t.heap_len<2;)h=t.heap[++t.heap_len]=l<2?++l:0,i[2*h]=1,t.depth[h]=0,t.opt_len--,n&&(t.static_len-=s[2*h+1]);for(e.max_code=l,r=t.heap_len>>1;r>=1;r--)vn(t,i,r);h=o;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],vn(t,i,1),a=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=a,i[2*h]=i[2*r]+i[2*a],t.depth[h]=(t.depth[r]>=t.depth[a]?t.depth[r]:t.depth[a])+1,i[2*r+1]=i[2*a+1]=h,t.heap[1]=h++,vn(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,s=e.max_code,n=e.stat_desc.static_tree,o=e.stat_desc.has_stree,r=e.stat_desc.extra_bits,a=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,d,u,p,g,f=0;for(u=0;u<=15;u++)t.bl_count[u]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)c=t.heap[l],u=i[2*i[2*c+1]+1]+1,u>h&&(u=h,f++),i[2*c+1]=u,c>s||(t.bl_count[u]++,p=0,c>=a&&(p=r[c-a]),g=i[2*c],t.opt_len+=g*(u+p),o&&(t.static_len+=g*(n[2*c+1]+p)));if(0!==f){do{for(u=h-1;0===t.bl_count[u];)u--;t.bl_count[u]--,t.bl_count[u+1]+=2,t.bl_count[h]--,f-=2}while(f>0);for(u=h;0!==u;u--)for(c=t.bl_count[u];0!==c;)d=t.heap[--l],d>s||(i[2*d+1]!==u&&(t.opt_len+=(u-i[2*d+1])*i[2*d],i[2*d+1]=u),c--)}})(t,e),gn(i,l,t.bl_count)},xn=(t,e,i)=>{let s,n,o=-1,r=e[1],a=0,h=7,l=4;for(0===r&&(h=138,l=3),e[2*(i+1)+1]=65535,s=0;s<=i;s++)n=r,r=e[2*(s+1)+1],++a<h&&n===r||(a<l?t.bl_tree[2*n]+=a:0!==n?(n!==o&&t.bl_tree[2*n]++,t.bl_tree[32]++):a<=10?t.bl_tree[34]++:t.bl_tree[36]++,a=0,o=n,0===r?(h=138,l=3):n===r?(h=6,l=3):(h=7,l=4))},_n=(t,e,i)=>{let s,n,o=-1,r=e[1],a=0,h=7,l=4;for(0===r&&(h=138,l=3),s=0;s<=i;s++)if(n=r,r=e[2*(s+1)+1],!(++a<h&&n===r)){if(a<l)do{un(t,n,t.bl_tree)}while(0!==--a);else 0!==n?(n!==o&&(un(t,n,t.bl_tree),a--),un(t,16,t.bl_tree),dn(t,a-3,2)):a<=10?(un(t,17,t.bl_tree),dn(t,a-3,3)):(un(t,18,t.bl_tree),dn(t,a-11,7));a=0,o=n,0===r?(h=138,l=3):n===r?(h=6,l=3):(h=7,l=4)}};let Cn=!1;const kn=(t,e,i,s)=>{dn(t,0+(s?1:0),3),yn(t),cn(t,i),cn(t,~i),i&&t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i};var En={_tr_init:t=>{Cn||((()=>{let t,e,i,s,n;const o=new Array(16);for(i=0,s=0;s<28;s++)for(en[s]=i,t=0;t<1<<Zs[s];t++)tn[i++]=s;for(tn[i-1]=s,n=0,s=0;s<16;s++)for(sn[s]=n,t=0;t<1<<Gs[s];t++)Ks[n++]=s;for(n>>=7;s<30;s++)for(sn[s]=n<<7,t=0;t<1<<Gs[s]-7;t++)Ks[256+n++]=s;for(e=0;e<=15;e++)o[e]=0;for(t=0;t<=143;)Js[2*t+1]=8,t++,o[8]++;for(;t<=255;)Js[2*t+1]=9,t++,o[9]++;for(;t<=279;)Js[2*t+1]=7,t++,o[7]++;for(;t<=287;)Js[2*t+1]=8,t++,o[8]++;for(gn(Js,287,o),t=0;t<30;t++)Qs[2*t+1]=5,Qs[2*t]=pn(t,5);on=new nn(Js,Zs,257,286,15),rn=new nn(Qs,Gs,0,30,15),an=new nn(new Array(0),qs,0,19,7)})(),Cn=!0),t.l_desc=new hn(t.dyn_ltree,on),t.d_desc=new hn(t.dyn_dtree,rn),t.bl_desc=new hn(t.bl_tree,an),t.bi_buf=0,t.bi_valid=0,fn(t)},_tr_stored_block:kn,_tr_flush_block:(t,e,i,s)=>{let n,o,r=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),bn(t,t.l_desc),bn(t,t.d_desc),r=(t=>{let e;for(xn(t,t.dyn_ltree,t.l_desc.max_code),xn(t,t.dyn_dtree,t.d_desc.max_code),bn(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*$s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),n=t.opt_len+3+7>>>3,o=t.static_len+3+7>>>3,o<=n&&(n=o)):n=o=i+5,i+4<=n&&-1!==e?kn(t,e,i,s):4===t.strategy||o===n?(dn(t,2+(s?1:0),3),wn(t,Js,Qs)):(dn(t,4+(s?1:0),3),((t,e,i,s)=>{let n;for(dn(t,e-257,5),dn(t,i-1,5),dn(t,s-4,4),n=0;n<s;n++)dn(t,t.bl_tree[2*$s[n]+1],3);_n(t,t.dyn_ltree,e-1),_n(t,t.dyn_dtree,i-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,r+1),wn(t,t.dyn_ltree,t.dyn_dtree)),fn(t),s&&yn(t)},_tr_tally:(t,e,i)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=i,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(tn[i]+256+1)]++,t.dyn_dtree[2*ln(e)]++),t.sym_next===t.sym_end),_tr_align:t=>{dn(t,2,3),un(t,256,Js),(t=>{16===t.bi_valid?(cn(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},An=(t,e,i,s)=>{let n=65535&t,o=t>>>16&65535,r=0;for(;0!==i;){r=i>2e3?2e3:i,i-=r;do{n=n+e[s++]|0,o=o+n|0}while(--r);n%=65521,o%=65521}return n|o<<16};const Sn=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var s=0;s<8;s++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Mn=(t,e,i,s)=>{const n=Sn,o=s+i;t^=-1;for(let i=s;i<o;i++)t=t>>>8^n[255&(t^e[i])];return-1^t},Tn={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Un={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Pn,_tr_stored_block:On,_tr_flush_block:Ln,_tr_tally:zn,_tr_align:Bn}=En,{Z_NO_FLUSH:In,Z_PARTIAL_FLUSH:Dn,Z_FULL_FLUSH:Xn,Z_FINISH:Rn,Z_BLOCK:jn,Z_OK:Yn,Z_STREAM_END:Nn,Z_STREAM_ERROR:Wn,Z_DATA_ERROR:Hn,Z_BUF_ERROR:Vn,Z_DEFAULT_COMPRESSION:Fn,Z_FILTERED:Zn,Z_HUFFMAN_ONLY:Gn,Z_RLE:qn,Z_FIXED:$n,Z_DEFAULT_STRATEGY:Jn,Z_UNKNOWN:Qn,Z_DEFLATED:Kn}=Un,to=258,eo=262,io=42,so=113,no=666,oo=(t,e)=>(t.msg=Tn[e],e),ro=t=>2*t-(t>4?9:0),ao=t=>{let e=t.length;for(;--e>=0;)t[e]=0},ho=t=>{let e,i,s,n=t.w_size;e=t.hash_size,s=e;do{i=t.head[--s],t.head[s]=i>=n?i-n:0}while(--e);e=n,s=e;do{i=t.prev[--s],t.prev[s]=i>=n?i-n:0}while(--e)};let lo=(t,e,i)=>(e<<t.hash_shift^i)&t.hash_mask;const co=t=>{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},uo=(t,e)=>{Ln(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,co(t.strm)},po=(t,e)=>{t.pending_buf[t.pending++]=e},go=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},fo=(t,e,i,s)=>{let n=t.avail_in;return n>s&&(n=s),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),i),1===t.state.wrap?t.adler=An(t.adler,e,n,i):2===t.state.wrap&&(t.adler=Mn(t.adler,e,n,i)),t.next_in+=n,t.total_in+=n,n)},yo=(t,e)=>{let i,s,n=t.max_chain_length,o=t.strstart,r=t.prev_length,a=t.nice_match;const h=t.strstart>t.w_size-eo?t.strstart-(t.w_size-eo):0,l=t.window,c=t.w_mask,d=t.prev,u=t.strstart+to;let p=l[o+r-1],g=l[o+r];t.prev_length>=t.good_match&&(n>>=2),a>t.lookahead&&(a=t.lookahead);do{if(i=e,l[i+r]===g&&l[i+r-1]===p&&l[i]===l[o]&&l[++i]===l[o+1]){o+=2,i++;do{}while(l[++o]===l[++i]&&l[++o]===l[++i]&&l[++o]===l[++i]&&l[++o]===l[++i]&&l[++o]===l[++i]&&l[++o]===l[++i]&&l[++o]===l[++i]&&l[++o]===l[++i]&&o<u);if(s=to-(u-o),o=u-to,s>r){if(t.match_start=e,r=s,s>=a)break;p=l[o+r-1],g=l[o+r]}}}while((e=d[e&c])>h&&0!==--n);return r<=t.lookahead?r:t.lookahead},mo=t=>{const e=t.w_size;let i,s,n;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-eo)&&(t.window.set(t.window.subarray(e,e+e-s),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),ho(t),s+=e),0===t.strm.avail_in)break;if(i=fo(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=i,t.lookahead+t.insert>=3)for(n=t.strstart-t.insert,t.ins_h=t.window[n],t.ins_h=lo(t,t.ins_h,t.window[n+1]);t.insert&&(t.ins_h=lo(t,t.ins_h,t.window[n+3-1]),t.prev[n&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=n,n++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<eo&&0!==t.strm.avail_in)},vo=(t,e)=>{let i,s,n,o=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,r=0,a=t.strm.avail_in;do{if(i=65535,n=t.bi_valid+42>>3,t.strm.avail_out<n)break;if(n=t.strm.avail_out-n,s=t.strstart-t.block_start,i>s+t.strm.avail_in&&(i=s+t.strm.avail_in),i>n&&(i=n),i<o&&(0===i&&e!==Rn||e===In||i!==s+t.strm.avail_in))break;r=e===Rn&&i===s+t.strm.avail_in?1:0,On(t,0,0,r),t.pending_buf[t.pending-4]=i,t.pending_buf[t.pending-3]=i>>8,t.pending_buf[t.pending-2]=~i,t.pending_buf[t.pending-1]=~i>>8,co(t.strm),s&&(s>i&&(s=i),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+s),t.strm.next_out),t.strm.next_out+=s,t.strm.avail_out-=s,t.strm.total_out+=s,t.block_start+=s,i-=s),i&&(fo(t.strm,t.strm.output,t.strm.next_out,i),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i)}while(0===r);return a-=t.strm.avail_in,a&&(a>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=a&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-a,t.strm.next_in),t.strstart),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),r?4:e!==In&&e!==Rn&&0===t.strm.avail_in&&t.strstart===t.block_start?2:(n=t.window_size-t.strstart,t.strm.avail_in>n&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,n+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),n>t.strm.avail_in&&(n=t.strm.avail_in),n&&(fo(t.strm,t.window,t.strstart,n),t.strstart+=n,t.insert+=n>t.w_size-t.insert?t.w_size-t.insert:n),t.high_water<t.strstart&&(t.high_water=t.strstart),n=t.bi_valid+42>>3,n=t.pending_buf_size-n>65535?65535:t.pending_buf_size-n,o=n>t.w_size?t.w_size:n,s=t.strstart-t.block_start,(s>=o||(s||e===Rn)&&e!==In&&0===t.strm.avail_in&&s<=n)&&(i=s>n?n:s,r=e===Rn&&0===t.strm.avail_in&&i===s?1:0,On(t,t.block_start,i,r),t.block_start+=i,co(t.strm)),r?3:1)},wo=(t,e)=>{let i,s;for(;;){if(t.lookahead<eo){if(mo(t),t.lookahead<eo&&e===In)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=lo(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-eo&&(t.match_length=yo(t,i)),t.match_length>=3)if(s=zn(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=lo(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!==--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=lo(t,t.ins_h,t.window[t.strstart+1]);else s=zn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(s&&(uo(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Rn?(uo(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(uo(t,!1),0===t.strm.avail_out)?1:2},bo=(t,e)=>{let i,s,n;for(;;){if(t.lookahead<eo){if(mo(t),t.lookahead<eo&&e===In)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=lo(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length<t.max_lazy_match&&t.strstart-i<=t.w_size-eo&&(t.match_length=yo(t,i),t.match_length<=5&&(t.strategy===Zn||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,s=zn(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=lo(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!==--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,s&&(uo(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(s=zn(t,0,t.window[t.strstart-1]),s&&uo(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(s=zn(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Rn?(uo(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(uo(t,!1),0===t.strm.avail_out)?1:2};function xo(t,e,i,s,n){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=s,this.func=n}const _o=[new xo(0,0,0,0,vo),new xo(4,4,8,4,wo),new xo(4,5,16,8,wo),new xo(4,6,32,32,wo),new xo(4,4,16,16,bo),new xo(8,16,32,32,bo),new xo(8,16,128,128,bo),new xo(8,32,128,256,bo),new xo(32,128,258,1024,bo),new xo(32,258,258,4096,bo)];function Co(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Kn,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),ao(this.dyn_ltree),ao(this.dyn_dtree),ao(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),ao(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),ao(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const ko=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.status!==io&&57!==e.status&&69!==e.status&&73!==e.status&&91!==e.status&&103!==e.status&&e.status!==so&&e.status!==no?1:0},Eo=t=>{if(ko(t))return oo(t,Wn);t.total_in=t.total_out=0,t.data_type=Qn;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=2===e.wrap?57:e.wrap?io:so,t.adler=2===e.wrap?0:1,e.last_flush=-2,Pn(e),Yn},Ao=t=>{const e=Eo(t);var i;return e===Yn&&((i=t.state).window_size=2*i.w_size,ao(i.head),i.max_lazy_match=_o[i.level].max_lazy,i.good_match=_o[i.level].good_length,i.nice_match=_o[i.level].nice_length,i.max_chain_length=_o[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e},So=(t,e,i,s,n,o)=>{if(!t)return Wn;let r=1;if(e===Fn&&(e=6),s<0?(r=0,s=-s):s>15&&(r=2,s-=16),n<1||n>9||i!==Kn||s<8||s>15||e<0||e>9||o<0||o>$n||8===s&&1!==r)return oo(t,Wn);8===s&&(s=9);const a=new Co;return t.state=a,a.strm=t,a.status=io,a.wrap=r,a.gzhead=null,a.w_bits=s,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=n+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+3-1)/3),a.window=new Uint8Array(2*a.w_size),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<n+6,a.pending_buf_size=4*a.lit_bufsize,a.pending_buf=new Uint8Array(a.pending_buf_size),a.sym_buf=a.lit_bufsize,a.sym_end=3*(a.lit_bufsize-1),a.level=e,a.strategy=o,a.method=i,Ao(t)};var Mo=So,To=(t,e)=>ko(t)||2!==t.state.wrap?Wn:(t.state.gzhead=e,Yn),Uo=(t,e)=>{if(ko(t)||e>jn||e<0)return t?oo(t,Wn):Wn;const i=t.state;if(!t.output||0!==t.avail_in&&!t.input||i.status===no&&e!==Rn)return oo(t,0===t.avail_out?Vn:Wn);const s=i.last_flush;if(i.last_flush=e,0!==i.pending){if(co(t),0===t.avail_out)return i.last_flush=-1,Yn}else if(0===t.avail_in&&ro(e)<=ro(s)&&e!==Rn)return oo(t,Vn);if(i.status===no&&0!==t.avail_in)return oo(t,Vn);if(i.status===io&&0===i.wrap&&(i.status=so),i.status===io){let e=Kn+(i.w_bits-8<<4)<<8,s=-1;if(s=i.strategy>=Gn||i.level<2?0:i.level<6?1:6===i.level?2:3,e|=s<<6,0!==i.strstart&&(e|=32),e+=31-e%31,go(i,e),0!==i.strstart&&(go(i,t.adler>>>16),go(i,65535&t.adler)),t.adler=1,i.status=so,co(t),0!==i.pending)return i.last_flush=-1,Yn}if(57===i.status)if(t.adler=0,po(i,31),po(i,139),po(i,8),i.gzhead)po(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),po(i,255&i.gzhead.time),po(i,i.gzhead.time>>8&255),po(i,i.gzhead.time>>16&255),po(i,i.gzhead.time>>24&255),po(i,9===i.level?2:i.strategy>=Gn||i.level<2?4:0),po(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(po(i,255&i.gzhead.extra.length),po(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=Mn(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69;else if(po(i,0),po(i,0),po(i,0),po(i,0),po(i,0),po(i,9===i.level?2:i.strategy>=Gn||i.level<2?4:0),po(i,3),i.status=so,co(t),0!==i.pending)return i.last_flush=-1,Yn;if(69===i.status){if(i.gzhead.extra){let e=i.pending,s=(65535&i.gzhead.extra.length)-i.gzindex;for(;i.pending+s>i.pending_buf_size;){let n=i.pending_buf_size-i.pending;if(i.pending_buf.set(i.gzhead.extra.subarray(i.gzindex,i.gzindex+n),i.pending),i.pending=i.pending_buf_size,i.gzhead.hcrc&&i.pending>e&&(t.adler=Mn(t.adler,i.pending_buf,i.pending-e,e)),i.gzindex+=n,co(t),0!==i.pending)return i.last_flush=-1,Yn;e=0,s-=n}let n=new Uint8Array(i.gzhead.extra);i.pending_buf.set(n.subarray(i.gzindex,i.gzindex+s),i.pending),i.pending+=s,i.gzhead.hcrc&&i.pending>e&&(t.adler=Mn(t.adler,i.pending_buf,i.pending-e,e)),i.gzindex=0}i.status=73}if(73===i.status){if(i.gzhead.name){let e,s=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>s&&(t.adler=Mn(t.adler,i.pending_buf,i.pending-s,s)),co(t),0!==i.pending)return i.last_flush=-1,Yn;s=0}e=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0,po(i,e)}while(0!==e);i.gzhead.hcrc&&i.pending>s&&(t.adler=Mn(t.adler,i.pending_buf,i.pending-s,s)),i.gzindex=0}i.status=91}if(91===i.status){if(i.gzhead.comment){let e,s=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>s&&(t.adler=Mn(t.adler,i.pending_buf,i.pending-s,s)),co(t),0!==i.pending)return i.last_flush=-1,Yn;s=0}e=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0,po(i,e)}while(0!==e);i.gzhead.hcrc&&i.pending>s&&(t.adler=Mn(t.adler,i.pending_buf,i.pending-s,s))}i.status=103}if(103===i.status){if(i.gzhead.hcrc){if(i.pending+2>i.pending_buf_size&&(co(t),0!==i.pending))return i.last_flush=-1,Yn;po(i,255&t.adler),po(i,t.adler>>8&255),t.adler=0}if(i.status=so,co(t),0!==i.pending)return i.last_flush=-1,Yn}if(0!==t.avail_in||0!==i.lookahead||e!==In&&i.status!==no){let s=0===i.level?vo(i,e):i.strategy===Gn?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(mo(t),0===t.lookahead)){if(e===In)return 1;break}if(t.match_length=0,i=zn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(uo(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Rn?(uo(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(uo(t,!1),0===t.strm.avail_out)?1:2})(i,e):i.strategy===qn?((t,e)=>{let i,s,n,o;const r=t.window;for(;;){if(t.lookahead<=to){if(mo(t),t.lookahead<=to&&e===In)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,s=r[n],s===r[++n]&&s===r[++n]&&s===r[++n])){o=t.strstart+to;do{}while(s===r[++n]&&s===r[++n]&&s===r[++n]&&s===r[++n]&&s===r[++n]&&s===r[++n]&&s===r[++n]&&s===r[++n]&&n<o);t.match_length=to-(o-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=zn(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=zn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(uo(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Rn?(uo(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(uo(t,!1),0===t.strm.avail_out)?1:2})(i,e):_o[i.level].func(i,e);if(3!==s&&4!==s||(i.status=no),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),Yn;if(2===s&&(e===Dn?Bn(i):e!==jn&&(On(i,0,0,!1),e===Xn&&(ao(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),co(t),0===t.avail_out))return i.last_flush=-1,Yn}return e!==Rn?Yn:i.wrap<=0?Nn:(2===i.wrap?(po(i,255&t.adler),po(i,t.adler>>8&255),po(i,t.adler>>16&255),po(i,t.adler>>24&255),po(i,255&t.total_in),po(i,t.total_in>>8&255),po(i,t.total_in>>16&255),po(i,t.total_in>>24&255)):(go(i,t.adler>>>16),go(i,65535&t.adler)),co(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?Yn:Nn)},Po=t=>{if(ko(t))return Wn;const e=t.state.status;return t.state=null,e===so?oo(t,Hn):Yn},Oo=(t,e)=>{let i=e.length;if(ko(t))return Wn;const s=t.state,n=s.wrap;if(2===n||1===n&&s.status!==io||s.lookahead)return Wn;if(1===n&&(t.adler=An(t.adler,e,i,0)),s.wrap=0,i>=s.w_size){0===n&&(ao(s.head),s.strstart=0,s.block_start=0,s.insert=0);let t=new Uint8Array(s.w_size);t.set(e.subarray(i-s.w_size,i),0),e=t,i=s.w_size}const o=t.avail_in,r=t.next_in,a=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,mo(s);s.lookahead>=3;){let t=s.strstart,e=s.lookahead-2;do{s.ins_h=lo(s,s.ins_h,s.window[t+3-1]),s.prev[t&s.w_mask]=s.head[s.ins_h],s.head[s.ins_h]=t,t++}while(--e);s.strstart=t,s.lookahead=2,mo(s)}return s.strstart+=s.lookahead,s.block_start=s.strstart,s.insert=s.lookahead,s.lookahead=0,s.match_length=s.prev_length=2,s.match_available=0,t.next_in=r,t.input=a,t.avail_in=o,s.wrap=n,Yn};const Lo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var zo=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Lo(i,e)&&(t[e]=i[e])}}return t},Bo=t=>{let e=0;for(let i=0,s=t.length;i<s;i++)e+=t[i].length;const i=new Uint8Array(e);for(let e=0,s=0,n=t.length;e<n;e++){let n=t[e];i.set(n,s),s+=n.length}return i};let Io=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){Io=!1}const Do=new Uint8Array(256);for(let t=0;t<256;t++)Do[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Do[254]=Do[254]=1;var Xo=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,s,n,o,r=t.length,a=0;for(n=0;n<r;n++)i=t.charCodeAt(n),55296==(64512&i)&&n+1<r&&(s=t.charCodeAt(n+1),56320==(64512&s)&&(i=65536+(i-55296<<10)+(s-56320),n++)),a+=i<128?1:i<2048?2:i<65536?3:4;for(e=new Uint8Array(a),o=0,n=0;o<a;n++)i=t.charCodeAt(n),55296==(64512&i)&&n+1<r&&(s=t.charCodeAt(n+1),56320==(64512&s)&&(i=65536+(i-55296<<10)+(s-56320),n++)),i<128?e[o++]=i:i<2048?(e[o++]=192|i>>>6,e[o++]=128|63&i):i<65536?(e[o++]=224|i>>>12,e[o++]=128|i>>>6&63,e[o++]=128|63&i):(e[o++]=240|i>>>18,e[o++]=128|i>>>12&63,e[o++]=128|i>>>6&63,e[o++]=128|63&i);return e},Ro=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let s,n;const o=new Array(2*i);for(n=0,s=0;s<i;){let e=t[s++];if(e<128){o[n++]=e;continue}let r=Do[e];if(r>4)o[n++]=65533,s+=r-1;else{for(e&=2===r?31:3===r?15:7;r>1&&s<i;)e=e<<6|63&t[s++],r--;r>1?o[n++]=65533:e<65536?o[n++]=e:(e-=65536,o[n++]=55296|e>>10&1023,o[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Io)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let s=0;s<e;s++)i+=String.fromCharCode(t[s]);return i})(o,n)},jo=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Do[t[i]]>e?i:e},Yo=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const No=Object.prototype.toString,{Z_NO_FLUSH:Wo,Z_SYNC_FLUSH:Ho,Z_FULL_FLUSH:Vo,Z_FINISH:Fo,Z_OK:Zo,Z_STREAM_END:Go,Z_DEFAULT_COMPRESSION:qo,Z_DEFAULT_STRATEGY:$o,Z_DEFLATED:Jo}=Un;function Qo(t){this.options=zo({level:qo,method:Jo,chunkSize:16384,windowBits:15,memLevel:8,strategy:$o},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Yo,this.strm.avail_out=0;let i=Mo(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==Zo)throw new Error(Tn[i]);if(e.header&&To(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Xo(e.dictionary):"[object ArrayBuffer]"===No.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=Oo(this.strm,t),i!==Zo)throw new Error(Tn[i]);this._dict_set=!0}}function Ko(t,e){const i=new Qo(e);if(i.push(t,!0),i.err)throw i.msg||Tn[i.err];return i.result}Qo.prototype.push=function(t,e){const i=this.strm,s=this.options.chunkSize;let n,o;if(this.ended)return!1;for(o=e===~~e?e:!0===e?Fo:Wo,"string"==typeof t?i.input=Xo(t):"[object ArrayBuffer]"===No.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(s),i.next_out=0,i.avail_out=s),(o===Ho||o===Vo)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(n=Uo(i,o),n===Go)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=Po(this.strm),this.onEnd(n),this.ended=!0,n===Zo;if(0!==i.avail_out){if(o>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},Qo.prototype.onData=function(t){this.chunks.push(t)},Qo.prototype.onEnd=function(t){t===Zo&&(this.result=Bo(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var tr={Deflate:Qo,deflate:Ko,deflateRaw:function(t,e){return(e=e||{}).raw=!0,Ko(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,Ko(t,e)},constants:Un};const er=16209;var ir=function(t,e){let i,s,n,o,r,a,h,l,c,d,u,p,g,f,y,m,v,w,b,x,_,C,k,E;const A=t.state;i=t.next_in,k=t.input,s=i+(t.avail_in-5),n=t.next_out,E=t.output,o=n-(e-t.avail_out),r=n+(t.avail_out-257),a=A.dmax,h=A.wsize,l=A.whave,c=A.wnext,d=A.window,u=A.hold,p=A.bits,g=A.lencode,f=A.distcode,y=(1<<A.lenbits)-1,m=(1<<A.distbits)-1;t:do{p<15&&(u+=k[i++]<<p,p+=8,u+=k[i++]<<p,p+=8),v=g[u&y];e:for(;;){if(w=v>>>24,u>>>=w,p-=w,w=v>>>16&255,0===w)E[n++]=65535&v;else{if(!(16&w)){if(64&w){if(32&w){A.mode=16191;break t}t.msg="invalid literal/length code",A.mode=er;break t}v=g[(65535&v)+(u&(1<<w)-1)];continue e}for(b=65535&v,w&=15,w&&(p<w&&(u+=k[i++]<<p,p+=8),b+=u&(1<<w)-1,u>>>=w,p-=w),p<15&&(u+=k[i++]<<p,p+=8,u+=k[i++]<<p,p+=8),v=f[u&m];;){if(w=v>>>24,u>>>=w,p-=w,w=v>>>16&255,16&w){if(x=65535&v,w&=15,p<w&&(u+=k[i++]<<p,p+=8,p<w&&(u+=k[i++]<<p,p+=8)),x+=u&(1<<w)-1,x>a){t.msg="invalid distance too far back",A.mode=er;break t}if(u>>>=w,p-=w,w=n-o,x>w){if(w=x-w,w>l&&A.sane){t.msg="invalid distance too far back",A.mode=er;break t}if(_=0,C=d,0===c){if(_+=h-w,w<b){b-=w;do{E[n++]=d[_++]}while(--w);_=n-x,C=E}}else if(c<w){if(_+=h+c-w,w-=c,w<b){b-=w;do{E[n++]=d[_++]}while(--w);if(_=0,c<b){w=c,b-=w;do{E[n++]=d[_++]}while(--w);_=n-x,C=E}}}else if(_+=c-w,w<b){b-=w;do{E[n++]=d[_++]}while(--w);_=n-x,C=E}for(;b>2;)E[n++]=C[_++],E[n++]=C[_++],E[n++]=C[_++],b-=3;b&&(E[n++]=C[_++],b>1&&(E[n++]=C[_++]))}else{_=n-x;do{E[n++]=E[_++],E[n++]=E[_++],E[n++]=E[_++],b-=3}while(b>2);b&&(E[n++]=E[_++],b>1&&(E[n++]=E[_++]))}break}if(64&w){t.msg="invalid distance code",A.mode=er;break t}v=f[(65535&v)+(u&(1<<w)-1)]}}break}}while(i<s&&n<r);b=p>>3,i-=b,p-=b<<3,u&=(1<<p)-1,t.next_in=i,t.next_out=n,t.avail_in=i<s?s-i+5:5-(i-s),t.avail_out=n<r?r-n+257:257-(n-r),A.hold=u,A.bits=p};const sr=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),nr=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),or=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),rr=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var ar=(t,e,i,s,n,o,r,a)=>{const h=a.bits;let l,c,d,u,p,g,f=0,y=0,m=0,v=0,w=0,b=0,x=0,_=0,C=0,k=0,E=null;const A=new Uint16Array(16),S=new Uint16Array(16);let M,T,U,P=null;for(f=0;f<=15;f++)A[f]=0;for(y=0;y<s;y++)A[e[i+y]]++;for(w=h,v=15;v>=1&&0===A[v];v--);if(w>v&&(w=v),0===v)return n[o++]=20971520,n[o++]=20971520,a.bits=1,0;for(m=1;m<v&&0===A[m];m++);for(w<m&&(w=m),_=1,f=1;f<=15;f++)if(_<<=1,_-=A[f],_<0)return-1;if(_>0&&(0===t||1!==v))return-1;for(S[1]=0,f=1;f<15;f++)S[f+1]=S[f]+A[f];for(y=0;y<s;y++)0!==e[i+y]&&(r[S[e[i+y]]++]=y);if(0===t?(E=P=r,g=20):1===t?(E=sr,P=nr,g=257):(E=or,P=rr,g=0),k=0,y=0,f=m,p=o,b=w,x=0,d=-1,C=1<<w,u=C-1,1===t&&C>852||2===t&&C>592)return 1;for(;;){M=f-x,r[y]+1<g?(T=0,U=r[y]):r[y]>=g?(T=P[r[y]-g],U=E[r[y]-g]):(T=96,U=0),l=1<<f-x,c=1<<b,m=c;do{c-=l,n[p+(k>>x)+c]=M<<24|T<<16|U}while(0!==c);for(l=1<<f-1;k&l;)l>>=1;if(0!==l?(k&=l-1,k+=l):k=0,y++,0===--A[f]){if(f===v)break;f=e[i+r[y]]}if(f>w&&(k&u)!==d){for(0===x&&(x=w),p+=m,b=f-x,_=1<<b;b+x<v&&(_-=A[b+x],!(_<=0));)b++,_<<=1;if(C+=1<<b,1===t&&C>852||2===t&&C>592)return 1;d=k&u,n[d]=w<<24|b<<16|p-o}}return 0!==k&&(n[p+k]=f-x<<24|64<<16),a.bits=w,0};const{Z_FINISH:hr,Z_BLOCK:lr,Z_TREES:cr,Z_OK:dr,Z_STREAM_END:ur,Z_NEED_DICT:pr,Z_STREAM_ERROR:gr,Z_DATA_ERROR:fr,Z_MEM_ERROR:yr,Z_BUF_ERROR:mr,Z_DEFLATED:vr}=Un,wr=16180,br=16190,xr=16191,_r=16192,Cr=16194,kr=16199,Er=16200,Ar=16206,Sr=16209,Mr=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Tr(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Ur=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.mode<wr||e.mode>16211?1:0},Pr=t=>{if(Ur(t))return gr;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=wr,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,dr},Or=t=>{if(Ur(t))return gr;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,Pr(t)},Lr=(t,e)=>{let i;if(Ur(t))return gr;const s=t.state;return e<0?(i=0,e=-e):(i=5+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?gr:(null!==s.window&&s.wbits!==e&&(s.window=null),s.wrap=i,s.wbits=e,Or(t))},zr=(t,e)=>{if(!t)return gr;const i=new Tr;t.state=i,i.strm=t,i.window=null,i.mode=wr;const s=Lr(t,e);return s!==dr&&(t.state=null),s};let Br,Ir,Dr=!0;const Xr=t=>{if(Dr){Br=new Int32Array(512),Ir=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(ar(1,t.lens,0,288,Br,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;ar(2,t.lens,0,32,Ir,0,t.work,{bits:5}),Dr=!1}t.lencode=Br,t.lenbits=9,t.distcode=Ir,t.distbits=5},Rr=(t,e,i,s)=>{let n;const o=t.state;return null===o.window&&(o.wsize=1<<o.wbits,o.wnext=0,o.whave=0,o.window=new Uint8Array(o.wsize)),s>=o.wsize?(o.window.set(e.subarray(i-o.wsize,i),0),o.wnext=0,o.whave=o.wsize):(n=o.wsize-o.wnext,n>s&&(n=s),o.window.set(e.subarray(i-s,i-s+n),o.wnext),(s-=n)?(o.window.set(e.subarray(i-s,i),0),o.wnext=s,o.whave=o.wsize):(o.wnext+=n,o.wnext===o.wsize&&(o.wnext=0),o.whave<o.wsize&&(o.whave+=n))),0};var jr=Or,Yr=zr,Nr=(t,e)=>{let i,s,n,o,r,a,h,l,c,d,u,p,g,f,y,m,v,w,b,x,_,C,k=0;const E=new Uint8Array(4);let A,S;const M=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Ur(t)||!t.output||!t.input&&0!==t.avail_in)return gr;i=t.state,i.mode===xr&&(i.mode=_r),r=t.next_out,n=t.output,h=t.avail_out,o=t.next_in,s=t.input,a=t.avail_in,l=i.hold,c=i.bits,d=a,u=h,C=dr;t:for(;;)switch(i.mode){case wr:if(0===i.wrap){i.mode=_r;break}for(;c<16;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(2&i.wrap&&35615===l){0===i.wbits&&(i.wbits=15),i.check=0,E[0]=255&l,E[1]=l>>>8&255,i.check=Mn(i.check,E,2,0),l=0,c=0,i.mode=16181;break}if(i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Sr;break}if((15&l)!==vr){t.msg="unknown compression method",i.mode=Sr;break}if(l>>>=4,c-=4,_=8+(15&l),0===i.wbits&&(i.wbits=_),_>15||_>i.wbits){t.msg="invalid window size",i.mode=Sr;break}i.dmax=1<<i.wbits,i.flags=0,t.adler=i.check=1,i.mode=512&l?16189:xr,l=0,c=0;break;case 16181:for(;c<16;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(i.flags=l,(255&i.flags)!==vr){t.msg="unknown compression method",i.mode=Sr;break}if(57344&i.flags){t.msg="unknown header flags set",i.mode=Sr;break}i.head&&(i.head.text=l>>8&1),512&i.flags&&4&i.wrap&&(E[0]=255&l,E[1]=l>>>8&255,i.check=Mn(i.check,E,2,0)),l=0,c=0,i.mode=16182;case 16182:for(;c<32;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}i.head&&(i.head.time=l),512&i.flags&&4&i.wrap&&(E[0]=255&l,E[1]=l>>>8&255,E[2]=l>>>16&255,E[3]=l>>>24&255,i.check=Mn(i.check,E,4,0)),l=0,c=0,i.mode=16183;case 16183:for(;c<16;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}i.head&&(i.head.xflags=255&l,i.head.os=l>>8),512&i.flags&&4&i.wrap&&(E[0]=255&l,E[1]=l>>>8&255,i.check=Mn(i.check,E,2,0)),l=0,c=0,i.mode=16184;case 16184:if(1024&i.flags){for(;c<16;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}i.length=l,i.head&&(i.head.extra_len=l),512&i.flags&&4&i.wrap&&(E[0]=255&l,E[1]=l>>>8&255,i.check=Mn(i.check,E,2,0)),l=0,c=0}else i.head&&(i.head.extra=null);i.mode=16185;case 16185:if(1024&i.flags&&(p=i.length,p>a&&(p=a),p&&(i.head&&(_=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(s.subarray(o,o+p),_)),512&i.flags&&4&i.wrap&&(i.check=Mn(i.check,s,p,o)),a-=p,o+=p,i.length-=p),i.length))break t;i.length=0,i.mode=16186;case 16186:if(2048&i.flags){if(0===a)break t;p=0;do{_=s[o+p++],i.head&&_&&i.length<65536&&(i.head.name+=String.fromCharCode(_))}while(_&&p<a);if(512&i.flags&&4&i.wrap&&(i.check=Mn(i.check,s,p,o)),a-=p,o+=p,_)break t}else i.head&&(i.head.name=null);i.length=0,i.mode=16187;case 16187:if(4096&i.flags){if(0===a)break t;p=0;do{_=s[o+p++],i.head&&_&&i.length<65536&&(i.head.comment+=String.fromCharCode(_))}while(_&&p<a);if(512&i.flags&&4&i.wrap&&(i.check=Mn(i.check,s,p,o)),a-=p,o+=p,_)break t}else i.head&&(i.head.comment=null);i.mode=16188;case 16188:if(512&i.flags){for(;c<16;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(4&i.wrap&&l!==(65535&i.check)){t.msg="header crc mismatch",i.mode=Sr;break}l=0,c=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xr;break;case 16189:for(;c<32;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}t.adler=i.check=Mr(l),l=0,c=0,i.mode=br;case br:if(0===i.havedict)return t.next_out=r,t.avail_out=h,t.next_in=o,t.avail_in=a,i.hold=l,i.bits=c,pr;t.adler=i.check=1,i.mode=xr;case xr:if(e===lr||e===cr)break t;case _r:if(i.last){l>>>=7&c,c-=7&c,i.mode=Ar;break}for(;c<3;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}switch(i.last=1&l,l>>>=1,c-=1,3&l){case 0:i.mode=16193;break;case 1:if(Xr(i),i.mode=kr,e===cr){l>>>=2,c-=2;break t}break;case 2:i.mode=16196;break;case 3:t.msg="invalid block type",i.mode=Sr}l>>>=2,c-=2;break;case 16193:for(l>>>=7&c,c-=7&c;c<32;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if((65535&l)!=(l>>>16^65535)){t.msg="invalid stored block lengths",i.mode=Sr;break}if(i.length=65535&l,l=0,c=0,i.mode=Cr,e===cr)break t;case Cr:i.mode=16195;case 16195:if(p=i.length,p){if(p>a&&(p=a),p>h&&(p=h),0===p)break t;n.set(s.subarray(o,o+p),r),a-=p,o+=p,h-=p,r+=p,i.length-=p;break}i.mode=xr;break;case 16196:for(;c<14;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(i.nlen=257+(31&l),l>>>=5,c-=5,i.ndist=1+(31&l),l>>>=5,c-=5,i.ncode=4+(15&l),l>>>=4,c-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Sr;break}i.have=0,i.mode=16197;case 16197:for(;i.have<i.ncode;){for(;c<3;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}i.lens[M[i.have++]]=7&l,l>>>=3,c-=3}for(;i.have<19;)i.lens[M[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,A={bits:i.lenbits},C=ar(0,i.lens,0,19,i.lencode,0,i.work,A),i.lenbits=A.bits,C){t.msg="invalid code lengths set",i.mode=Sr;break}i.have=0,i.mode=16198;case 16198:for(;i.have<i.nlen+i.ndist;){for(;k=i.lencode[l&(1<<i.lenbits)-1],y=k>>>24,m=k>>>16&255,v=65535&k,!(y<=c);){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(v<16)l>>>=y,c-=y,i.lens[i.have++]=v;else{if(16===v){for(S=y+2;c<S;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(l>>>=y,c-=y,0===i.have){t.msg="invalid bit length repeat",i.mode=Sr;break}_=i.lens[i.have-1],p=3+(3&l),l>>>=2,c-=2}else if(17===v){for(S=y+3;c<S;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}l>>>=y,c-=y,_=0,p=3+(7&l),l>>>=3,c-=3}else{for(S=y+7;c<S;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}l>>>=y,c-=y,_=0,p=11+(127&l),l>>>=7,c-=7}if(i.have+p>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Sr;break}for(;p--;)i.lens[i.have++]=_}}if(i.mode===Sr)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Sr;break}if(i.lenbits=9,A={bits:i.lenbits},C=ar(1,i.lens,0,i.nlen,i.lencode,0,i.work,A),i.lenbits=A.bits,C){t.msg="invalid literal/lengths set",i.mode=Sr;break}if(i.distbits=6,i.distcode=i.distdyn,A={bits:i.distbits},C=ar(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,A),i.distbits=A.bits,C){t.msg="invalid distances set",i.mode=Sr;break}if(i.mode=kr,e===cr)break t;case kr:i.mode=Er;case Er:if(a>=6&&h>=258){t.next_out=r,t.avail_out=h,t.next_in=o,t.avail_in=a,i.hold=l,i.bits=c,ir(t,u),r=t.next_out,n=t.output,h=t.avail_out,o=t.next_in,s=t.input,a=t.avail_in,l=i.hold,c=i.bits,i.mode===xr&&(i.back=-1);break}for(i.back=0;k=i.lencode[l&(1<<i.lenbits)-1],y=k>>>24,m=k>>>16&255,v=65535&k,!(y<=c);){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(m&&!(240&m)){for(w=y,b=m,x=v;k=i.lencode[x+((l&(1<<w+b)-1)>>w)],y=k>>>24,m=k>>>16&255,v=65535&k,!(w+y<=c);){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}l>>>=w,c-=w,i.back+=w}if(l>>>=y,c-=y,i.back+=y,i.length=v,0===m){i.mode=16205;break}if(32&m){i.back=-1,i.mode=xr;break}if(64&m){t.msg="invalid literal/length code",i.mode=Sr;break}i.extra=15&m,i.mode=16201;case 16201:if(i.extra){for(S=i.extra;c<S;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}i.length+=l&(1<<i.extra)-1,l>>>=i.extra,c-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=16202;case 16202:for(;k=i.distcode[l&(1<<i.distbits)-1],y=k>>>24,m=k>>>16&255,v=65535&k,!(y<=c);){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(!(240&m)){for(w=y,b=m,x=v;k=i.distcode[x+((l&(1<<w+b)-1)>>w)],y=k>>>24,m=k>>>16&255,v=65535&k,!(w+y<=c);){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}l>>>=w,c-=w,i.back+=w}if(l>>>=y,c-=y,i.back+=y,64&m){t.msg="invalid distance code",i.mode=Sr;break}i.offset=v,i.extra=15&m,i.mode=16203;case 16203:if(i.extra){for(S=i.extra;c<S;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}i.offset+=l&(1<<i.extra)-1,l>>>=i.extra,c-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Sr;break}i.mode=16204;case 16204:if(0===h)break t;if(p=u-h,i.offset>p){if(p=i.offset-p,p>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Sr;break}p>i.wnext?(p-=i.wnext,g=i.wsize-p):g=i.wnext-p,p>i.length&&(p=i.length),f=i.window}else f=n,g=r-i.offset,p=i.length;p>h&&(p=h),h-=p,i.length-=p;do{n[r++]=f[g++]}while(--p);0===i.length&&(i.mode=Er);break;case 16205:if(0===h)break t;n[r++]=i.length,h--,i.mode=Er;break;case Ar:if(i.wrap){for(;c<32;){if(0===a)break t;a--,l|=s[o++]<<c,c+=8}if(u-=h,t.total_out+=u,i.total+=u,4&i.wrap&&u&&(t.adler=i.check=i.flags?Mn(i.check,n,u,r-u):An(i.check,n,u,r-u)),u=h,4&i.wrap&&(i.flags?l:Mr(l))!==i.check){t.msg="incorrect data check",i.mode=Sr;break}l=0,c=0}i.mode=16207;case 16207:if(i.wrap&&i.flags){for(;c<32;){if(0===a)break t;a--,l+=s[o++]<<c,c+=8}if(4&i.wrap&&l!==(4294967295&i.total)){t.msg="incorrect length check",i.mode=Sr;break}l=0,c=0}i.mode=16208;case 16208:C=ur;break t;case Sr:C=fr;break t;case 16210:return yr;default:return gr}return t.next_out=r,t.avail_out=h,t.next_in=o,t.avail_in=a,i.hold=l,i.bits=c,(i.wsize||u!==t.avail_out&&i.mode<Sr&&(i.mode<Ar||e!==hr))&&Rr(t,t.output,t.next_out,u-t.avail_out),d-=t.avail_in,u-=t.avail_out,t.total_in+=d,t.total_out+=u,i.total+=u,4&i.wrap&&u&&(t.adler=i.check=i.flags?Mn(i.check,n,u,t.next_out-u):An(i.check,n,u,t.next_out-u)),t.data_type=i.bits+(i.last?64:0)+(i.mode===xr?128:0)+(i.mode===kr||i.mode===Cr?256:0),(0===d&&0===u||e===hr)&&C===dr&&(C=mr),C},Wr=t=>{if(Ur(t))return gr;let e=t.state;return e.window&&(e.window=null),t.state=null,dr},Hr=(t,e)=>{if(Ur(t))return gr;const i=t.state;return 2&i.wrap?(i.head=e,e.done=!1,dr):gr},Vr=(t,e)=>{const i=e.length;let s,n,o;return Ur(t)?gr:(s=t.state,0!==s.wrap&&s.mode!==br?gr:s.mode===br&&(n=1,n=An(n,e,i,0),n!==s.check)?fr:(o=Rr(t,e,i,i),o?(s.mode=16210,yr):(s.havedict=1,dr)))},Fr=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Zr=Object.prototype.toString,{Z_NO_FLUSH:Gr,Z_FINISH:qr,Z_OK:$r,Z_STREAM_END:Jr,Z_NEED_DICT:Qr,Z_STREAM_ERROR:Kr,Z_DATA_ERROR:ta,Z_MEM_ERROR:ea}=Un;function ia(t){this.options=zo({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(15&e.windowBits||(e.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Yo,this.strm.avail_out=0;let i=Yr(this.strm,e.windowBits);if(i!==$r)throw new Error(Tn[i]);if(this.header=new Fr,Hr(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xo(e.dictionary):"[object ArrayBuffer]"===Zr.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Vr(this.strm,e.dictionary),i!==$r)))throw new Error(Tn[i])}function sa(t,e){const i=new ia(e);if(i.push(t),i.err)throw i.msg||Tn[i.err];return i.result}ia.prototype.push=function(t,e){const i=this.strm,s=this.options.chunkSize,n=this.options.dictionary;let o,r,a;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qr:Gr,"[object ArrayBuffer]"===Zr.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(s),i.next_out=0,i.avail_out=s),o=Nr(i,r),o===Qr&&n&&(o=Vr(i,n),o===$r?o=Nr(i,r):o===ta&&(o=Qr));i.avail_in>0&&o===Jr&&i.state.wrap>0&&0!==t[i.next_in];)jr(i),o=Nr(i,r);switch(o){case Kr:case ta:case Qr:case ea:return this.onEnd(o),this.ended=!0,!1}if(a=i.avail_out,i.next_out&&(0===i.avail_out||o===Jr))if("string"===this.options.to){let t=jo(i.output,i.next_out),e=i.next_out-t,n=Ro(i.output,t);i.next_out=e,i.avail_out=s-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(n)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(o!==$r||0!==a){if(o===Jr)return o=Wr(this.strm),this.onEnd(o),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},ia.prototype.onData=function(t){this.chunks.push(t)},ia.prototype.onEnd=function(t){t===$r&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Bo(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var na={Inflate:ia,inflate:sa,inflateRaw:function(t,e){return(e=e||{}).raw=!0,sa(t,e)},ungzip:sa,constants:Un};const{Deflate:oa,deflate:ra,deflateRaw:aa,gzip:ha}=tr,{Inflate:la,inflate:ca,inflateRaw:da,ungzip:ua}=na;var pa=ca;const ga=function(){this.ids=this.ids||V.setUp(),this.entities=this.entities||et.setUp(),this.currentId=0,this.count=1},fa=ga.prototype;fa.attemptRecycle=function(){this.count-=1,0===this.count&&this.recycle()},fa.linkObject=function(t){this.currentId=t,this.count+=1},fa.linkEntity=function(t){const e=t.tiledId,i=this.ids;let s=i.length;for(;s--;){const e=i[s];let n=!1;e.onEntity===t.tiledId&&(e.onEntity=t,n=!0),e.toEntity===t.tiledId&&(e.toEntity=t,n=!0),n&&"object"==typeof e.onEntity&&"object"==typeof e.toEntity&&(e.onEntity[e.property]=e.toEntity,e.recycle(),G(i,s))}return this.entities[e]=t,this.attemptRecycle(),t},fa.getEntity=function(t,e){return this.entities[t]||(this.ids.push(H.setUp("onEntity",this.currentId,"toEntity",t,"property",e)),null)},N.add(ga,"EntityLinker",ga,function(){const t=this.entities,e=Object.keys(t),i=this.ids;for(let i=0;i<e.length;i++)delete t[e[i]];for(let t=0;t<i.length;t++)i[t].recycle();i.length=0},!0);const ya=ga,ma=/^(?:(\w+:)\/{2}(\w+(?:\.\w+)*\/?))?([\/.]*?(?:[^?]+)?\/)?(?:(([^\/?]+)\.(\w+))|([^\/?]+))(?:\?((?:(?:[^&]*?[\/=])?(?:((?:(?:[^\/?&=]+)\.(\w+)))\S*?)|\S+))?)?$/,va={top:-1,bottom:1,left:-1,right:1,center:0,middle:0},wa=268435455,ba=(t,e)=>t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24)>>>0,xa=(t,e)=>t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24)>>>0,_a=function(t){return"base64"===t.encoding&&(t.data=((t,e)=>{const i=[],s="zlib"===e,n=window.atob(t.replace(/\\/g,"")),o=s?pa(n):n,r=s?xa:ba;let a=4;for(;a<=o.length;)i.push(r(o,a-4)),a+=4;return i})(t.data,t.compression),t.encoding="csv"),t},Ca=function(t){const e=t.match(ma);return e[5]??e[7]},ka=function(t){let e=1;for(;e<t;)e*=10;return e},Ea={x:1,y:1,id:-1},Aa=(...t)=>{const e=Sa(...t);return e&&e.value},Sa=(t,e)=>{if(t){if(Array.isArray(t)){let i=t.length;for(;i--;)if(t[i].name===e)return t[i];return null}return platypus.debug.warn("This Tiled map version is deprecated."),{name:e,type:typeof t[e],value:t[e]}}return null},Ma=(t,e,i)=>{if(t)if(Array.isArray(t)){let s=t.length;for(;s--;)if(t[s].name===e)return t[s].type=typeof i,void(t[s].value=i);t.push({name:e,type:typeof i,value:i})}else t[e]=i},Ta=function(t){const e=!!(536870912&t),i=!!(1073741824&t),s=!!(2147483648&t);return Ea.id=wa&t,Ea.x=s?-1:1,Ea.y=i?-1:1,Ea.rotation=e?90:0,Ea},Ua=t=>{const{height:e=0,rotation:i=0,width:s=0,x:n=0,y:o=0}=t,r=s/2,a=e/2,h=i/180*Math.PI,l=Ht.setUp(r,a).rotate(h),c=Ht.setUp(n,o).addVector(l),d={...t,x:c.x,y:c.y};return l.recycle(),c.recycle(),d},Pa=(t,{rotation:e=0,x:i=1,y:s=1},n=0,o=0)=>{const r=Ht.setUp(t.x,t.y).add(-n/2,-o/2);return e?(r.rotate(e/180*Math.PI),r.x*=-i,r.y*=s):(r.x*=i,r.y*=s),r.add(n/2,o/2),{...t,rotation:t.rotation+e,flipX:i,flipY:s,x:r.x,y:r.y}},Oa=function(t,e,i){const s={},n={gid:-1,transform:null,properties:s,type:""};let o=t.gid||-1,r=null;if(-1!==o&&(n.transform=Ta(o),o=n.gid=Ea.id),e){let t=null;for(let i=0;i<e.length&&!(e[i].firstgid>o);i++)t=e[i];if(t?.tiles){const e=t.tiles,i=o-t.firstgid;for(let t=0;t<e.length;t++){const s=e[t];if(s.id===i){r=s.properties||null,n.type=s.type||"";break}}}}return n.type=t.type||n.type,n.type?(n.transform?(s.scaleX=n.transform.x,s.scaleY=n.transform.y):(s.scaleX=1,s.scaleY=1),t.name&&(s.name=t.name),i&&i.linkObject(n.properties.tiledId=t.id),La(r,n.properties,i),La(t.properties,n.properties,i),n):null},La=function(t,e,i){if(t&&e)if(Array.isArray(t))for(let s=0;s<t.length;s++)Ma(e,t[s].name,Ba(t[s],i));else{const i=Object.keys(t),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];Ma(e,s,za(t[s]))}}return e},za=function(t){if("string"==typeof t){const e=parseFloat(t)??parseInt(t);if(0===e||e)return e;if("true"===t)return!0;if("false"===t)return!1;if(t.length>1&&("{"===t[0]&&"}"===t[t.length-1]||"["===t[0]&&"]"===t[t.length-1]))try{return JSON.parse(t)}catch(t){}}return t},Ba=function({name:t,value:e,type:i},s){switch(i){case"color":return`#${e.substring(3)}${e.substring(1,3)}`;case"object":return s&&0!==e?s.getEntity(e,t):null;case"string":if(e.length>1&&("{"===e[0]&&"}"===e[e.length-1]||"["===e[0]&&"]"===e[e.length-1]))try{return JSON.parse(e)}catch(t){}}return e},Ia={"render-layer":{id:"render-layer",components:[{type:"RenderTiles",spriteSheet:"import",imageMap:"import",entityCache:!0}]},"collision-layer":{id:"collision-layer",components:[{type:"CollisionTiles",collisionMap:"import"}]},"image-layer":{id:"image-layer",components:[{type:"RenderTiles",spriteSheet:"import",imageMap:"import"}]}},Da=function(t){const e=platypus.game.settings.tilesets[Ca(t.source)],i=Object.keys(e),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];t[s]=e[s]}return delete t.source,t},Xa=function(t){for(let e=0;e<t.length;e++)t[e].source&&(t[e]=Da(t[e]));return t},Ra=xt({id:"TiledLoader",properties:{offsetMap:!1,showCollisionTiles:!1,images:null,layerIncrement:1e3,separateTiles:!1,spriteSheet:null,backgroundLoad:!0},publicProperties:{level:null,entityModifier:t=>t,entityPositionX:"center",entityPositionY:"bottom",manuallyLoad:!1,tileWidth:null,tileHeight:null},initialize:function(){this.assetCache=platypus.assetCache,this.layerZ=0,this.followEntity=!1,this.lazyLoads=V.setUp()},events:{"layer-loaded":function(t,e){this.manuallyLoad||(e.count+=1,this.loadLevel({level:this.level||t.level,persistentData:t},e.release))},"load-level":function(t,e){this.loadLevel(t,e)}},methods:{createLayer:function(t,e,i,s,n,o,r,a,h,l,c,d){const u=_a(e),{offsetx:p=0,offsety:g=0,properties:f,tileheight:y=o,tilewidth:m=n}=u,{data:v,height:w,width:b}=f?(({data:t,height:e,properties:i,width:s})=>{const n=Aa(i,"height"),o=Aa(i,"width"),r=o?parseInt(o,10):s,a=n?parseInt(n,10):e,h=r!==s||a!==e?[]:t;if(0===h.length)for(let i=0;i<r;i++)for(let n=0;n<a;n++)h[i+n*r]=i<s&&n<e?t[i+n*s]:0;return{width:r,height:a,data:h}})(u):u,x=i+p,_=s+g,C=JSON.parse(JSON.stringify(platypus.game.settings.entities[t]??Ia[t])),k=C.properties=C.properties??{},{components:E}=C,A={},S=[],M=[],T=[],U={images:u.image?[u.image]:h,frames:M,animations:A},P=function(t,e,i){const{image:s,tiles:n}=i;if(s){const{columns:s=i.imagewidth/(i.tilewidth+i.spacing)+(2*i.margin-i.spacing)|0,imageheight:n,margin:o=0,spacing:r=0,tileheight:a,tilewidth:h}=i,l=h/2,c=a/2,d=h+r,u=a+r,p=n/u+(2*o-r)|0;for(let i=0;i<p;i++)for(let n=0;n<s;n++)t.push([o+n*d,o+i*u,h,a,e,l,c]);e+=1}else if(n)for(let i=0;i<n.length;i++){const{imageheight:s,imagewidth:o}=n[i];t.push([0,0,s,o,e,s/2,o/2]),e+=1}return e};let O=0,L=null,z=!1,B=!1;if(d.linkObject(k.tiledId=u.id),f&&La(f,k,d),k.width=m*b,k.height=y*w,k.columns=b,k.rows=w,k.tileWidth=m,k.tileHeight=y,k.scaleX=1,k.scaleY=1,k.layerZ=this.layerZ,k.left=k.x||x,k.top=k.y||_,k.z=k.z||this.layerZ,r.length){let t=0;for(let e=0;e<r.length;e++)t=P(M,t,r[e]);L=r[r.length-1];{const t=L.firstgid+L.tilecount;for(let e=-1;e<t;e++)A["tile"+e]=e}}for(let t=0;t<b;t++){S[t]=[],T[t]=[];for(let e=0;e<w;e++)if(O=+v[t+e*b]-1,T[t][e]="tile"+O,O+=1,S[t][e]=O,a){const i=Ta(O);if(a.has(i.id)){const{objectgroup:s,properties:h}=a.get(i.id);if(s&&!k.ignoreTileCollision){const a=x+n*t,h=_+o*e;this.setUpEntities(s.objects.map(t=>Ua(t)).map(t=>Pa(t,i,n,o)),s,a,h,r,c,d)}h&&Aa(h,"hide")&&(T[t][e]="tile-1")}}}for(let t=0;t<E.length;t++)"RenderTiles"===E[t].type&&(z=E[t]),"CollisionTiles"===E[t].type&&(B=E[t]),"import"===E[t].spriteSheet?E[t].spriteSheet=U:E[t].spriteSheet&&("string"==typeof E[t].spriteSheet&&platypus.game.settings.spriteSheets[E[t].spriteSheet]&&(E[t].spriteSheet=platypus.game.settings.spriteSheets[E[t].spriteSheet]),E[t].spriteSheet.animations||(E[t].spriteSheet.animations=A)),"import"===E[t].collisionMap&&(E[t].collisionMap=[S]),"import"===E[t].imageMap&&(E[t].imageMap=T);if(this.separateTiles||l?.tileHeight!==y||l?.tileWidth!==m||l?.columns!==b||l?.rows!==w){const t={};return this.spriteSheet&&("string"==typeof this.spriteSheet?t.spriteSheet=platypus.game.settings.spriteSheets[this.spriteSheet]:t.spriteSheet=this.spriteSheet,t.spriteSheet.animations||(t.spriteSheet.animations=A)),d.linkEntity(this.owner.addEntity(new kt(C,{properties:t},this.updateLoadingProgress.bind(this,c),this.owner)))}return l.triggerEvent("add-tiles",z),l.triggerEvent("add-collision-tiles",B),this.updateLoadingProgress(c),l},convertImageLayer:function(t){const{image:e,name:i,properties:s}=t,n=this.assetCache.get(i),o=n?i:Ca(e),r=n??this.assetCache.get(o)??null,a=Aa(s,"repeat"),h=Aa(s,"repeat-x"),l=+(Aa(s,"repeat-y")??a??1),c=+(h??a??1),d=c*l,u=r?.height??1,p=r?.width??1,g={...t,data:Array(d).fill(1),image:r?o:e,height:l,type:"tilelayer",width:c,tileheight:u,tilewidth:p,properties:s};return r||platypus.debug.warn(`Component TiledLoader: Cannot find the "${i}" sprite sheet. Add it to the list of assets in config.json and give it the id "${i}".`),g.tileset={columns:1,image:g.image,imageheight:u,imagewidth:p,margin:0,name:i,spacing:0,tilecount:1,tileheight:u,tilewidth:p,type:"tileset"},g},loadLevel:function(t,e){const{assetCache:i,offsetMap:s,owner:n}=this,o=ya.setUp(),r=this.images?Z(this.images):V.setUp(),a="string"==typeof t.level?platypus.game.settings.levels[t.level]:t.level,h=a.layers,l=H.setUp("count",0,"progress",0,"total",0),c=et.setUp(),d=Xa(a.tilesets),u=this.tileWidth=a.tilewidth,p=this.tileHeight=a.tileheight,g=a.height*p,f=a.width*u,y=s?ka(f):0,m=s?ka(g):0;let v=null;if(function(t,e){for(let i=0;i<e.length;i++){const s=e[i],n=s.tiles;if(n)for(let e=0;e<n.length;e++){const i=n[e];t.set(i.id+s.firstgid,i)}}}(c,d),a.properties&&(o.linkObject(n.tiledId=0),La(a.properties,n,o),o.linkEntity(n)),0===r.length){const t=({image:t})=>{const e=Ca(t);i.get(e)?r.push(e):(platypus.debug.warn('Component TiledLoader: Cannot find the "'+e+'" sprite sheet. Add it to the list of assets in config.json and give it the id "'+e+'".'),r.push(t))};for(let e=0;e<d.length;e++){const i=d[e];i.image?t(i):i.tiles.forEach(t)}}l.total=h.length,this.finishedLoading=()=>{const{lazyLoads:t}=this,i=H.setUp("level",null,"world",Ci.setUp(),"tile",Ci.setUp(),"camera",null,t),s=t=>{const e=t.aabb,i=t.entityLinker;e.recycle(),t.aabb=null,t.entityLinker=null,i.linkEntity(n.addEntity(t))};i.level=a,i.camera=this.followEntity,i.width=f,i.height=g,i.world.setBounds(y,m,y+f,m+g),i.tile.setBounds(0,0,u,p),n.triggerEvent("world-loaded",i),i.world.recycle(),i.tile.recycle(),i.recycle(),t.length?(this.addEventListener("camera-update",e=>{const i=Ci.setUp(e.viewport);let n=t.length;for(i.resize(1.5*i.width,1.5*i.height);n--;){const e=t[n],o=e.aabb;if(i.intersects(o)){s(e);for(let e=n+1;e<t.length;e++)t[e-1]=t[e];t.length-=1}}}),this.backgroundLoad&&this.addEventListener("tick",function(){t.length&&s(t.pop())})):n.removeComponent(this),e&&e()};for(let t=0;t<h.length;t++){const e=h[t];switch(e.type){case"imagelayer":v=this.convertImageLayer(e),v=this.createLayer(Aa(v.properties,"entity")||"image-layer",v,y,m,v.tilewidth,v.tileheight,[v.tileset],null,r,v,l,o);break;case"objectgroup":this.setUpEntities(e.objects.map(t=>Ua(t)),e,y,m,d,l,o),v=null,this.updateLoadingProgress(l);break;case"tilelayer":v=this.setupLayer(e,v,y,m,u,p,d,c,r,l,o);break;default:platypus.debug.warn('Component TiledLoader: Platypus does not support Tiled layers of type "'+e.type+'". This layer will not be loaded.'),this.updateLoadingProgress(l)}this.layerZ+=this.layerIncrement}c.recycle()},setUpEntities:function(){const t=function(t){return H.setUp("x",-t.x,"y",-t.y)},e=function(t){return H.setUp("x",t.x,"y",t.y)},i=function(t){return H.setUp("x",-t.x,"y",t.y)},s=function(t){return H.setUp("x",t.x,"y",-t.y)},n=function(n,o,r){const a=V.setUp(),h=o?r?t:i:r?s:e;if(o^r){let t=n.length;for(;t--;)a.push(h(n[t]));a.unshift(a.pop())}else for(let t=0;t<n.length;t++)a.push(h(n[t]));return a},o=function(t,e,i,s,o){const r={type:t,points:n(e,i,s)};if(o){const t=[];let e=0;for(e=0;e<o.length;e++)t.push(n(o[e],i,s));r.decomposedPolygon=t}return r};return function(t,e,i,s,n,r,a){const{offsetx:h=0,offsety:l=0,properties:c}=e,d=i+h,u=s+l,p=t.length;r.total+=p,t.forEach(t=>{const e=Oa(t,n,a);if(e){const i=Aa(c,"entityPositionX")??this.entityPositionX,s=Aa(c,"entityPositionY")??this.entityPositionY,{flipX:n=1,flipY:h=1,height:l,point:p,polygon:g,polyline:f,rotation:y,width:m,x:v,y:w}=t,b=y/180*Math.PI,x=Ht.setUp(m/2*va[i]*n,l/2*va[s]*h).rotate(b),_=Ht.setUp(d+v,u+w).addVector(x),{type:C,properties:k}=e,E={properties:k},A=platypus.game.settings.entities[C],S=A?.properties??null,M=(p?(S?.height??0)*(1+va[s]):l)/2,T=(p?(S?.width??0)*(1+va[i]):m)/2,U=Ht.setUp(x).add(T,M),P=(t,e)=>{e.shapes||(e.shapes=[]),t.regX=U.x,t.regY=U.y,e.shapes.push(t)},O=({ellipse:t,height:e,width:i},s)=>{t?P(i===e?{type:"circle",radius:i/2}:{type:"ellipse",width:i,height:e},s):i&&e&&P({type:"rectangle",width:i,height:e},s)};if(E[A?"type":"id"]=C,g||f){const t=g??f;let e=1/0,i=-1/0,s=1/0,r=-1/0;for(let n=0;n<t.length;n++)t[n].x>i&&(i=t[n].x),t[n].x<e&&(e=t[n].x),t[n].y>r&&(r=t[n].y),t[n].y<s&&(s=t[n].y);k.width=i-e,k.height=r-s,k.x=_.x,k.y=_.y,g?P(o("polygon",t,-1===n,-1===h,k.decomposedPolygon),k):f&&P(o("polyline",t,-1===n,-1===h,null),k),y&&(k.rotation=y)}else p||(k.width=m,k.height=l),k.x=_.x,k.y=_.y,k.rotation=t.rotation,k.regX=U.x,k.regY=U.y,O(t,k);S&&(k.scaleX*=S.scaleX||1,k.scaleY*=S.scaleY||1),k.scaleX*=n,k.scaleY*=h,k.layerZ=this.layerZ,k.z?k.z+=this.layerZ:S&&"number"==typeof S.z?k.z=this.layerZ+S.z:k.z=this.layerZ;{const t=this.entityModifier(E);if(t)if(k.lazyLoad||S&&S.lazyLoad){const{height:e=1,regX:i=0,regY:s=0,width:n=1,x:o=0,y:h=0}=k;t.aabb=Ci.setUp(o+n/2-i,h+e/2-s,n,e),t.entityLinker=a,this.lazyLoads.push(t),this.updateLoadingProgress(r)}else{const e=this.owner.addEntity(t,this.updateLoadingProgress.bind(this,r));a.linkEntity(e),e&&e.camera&&(this.followEntity={entity:e,mode:e.camera})}else this.updateLoadingProgress(r)}}else this.updateLoadingProgress(r)})}}(),setupLayer:function(t,e,i,s,n,o,r,a,h,l,c){const d=Aa(t.properties,"entity")??"render-layer",u=platypus.game.settings.entities[d]??Ia[d];let p=!1;if(u){let t=u.components.length;for(;t--;)if("RenderTiles"===u.components[t].type){p=!0;break}}return p?this.createLayer(d,t,i,s,n,o,r,a,h,e,l,c):(this.createLayer(d,t,i,s,n,o,r,a,h,e,l,c),null)},updateLoadingProgress:function(t){t.count+=1,t.progress=t.count/t.total,this.owner.triggerEvent("level-loading-progress",t),t.count===t.total&&(t.recycle(),this.finishedLoading())},destroy:function(){V.recycle(this.lazyLoads),this.lazyLoads=null}},getAssetList:function(t,e,i,s){const n=t?.spriteSheet??e?.spriteSheet??i?.spriteSheet,o=t?.images??e?.images??i?.images,r=function(t,e){const i=(t,e,i)=>{const s=e.objects;for(let e=0;e<s.length;e++){const n=Oa(s[e],i);if(n){const e=kt.getAssetList(n);F(t,e),V.recycle(e)}}},s="string"==typeof t?platypus.game.settings.levels[t]:t,n=V.setUp();if(s)if(s.tilesets&&(s.tilesets=Xa(s.tilesets)),s.assets)F(n,s.assets);else if(s.layers){for(let t=0;t<s.layers.length;t++){const e=s.layers[t];if("objectgroup"===e.type)i(n,e,s.tilesets);else if("imagelayer"===e.type){const t=Aa(e.properties,"entity");if(t){const i=H.setUp("type",t,"properties",La(e.properties,{})),s=kt.getAssetList(i);F(n,s),V.recycle(s),i.recycle()}else F(n,[e.image])}else{const o=Aa(s.layers[t].properties,"entity"),r=V.setUp();_a(e),F(r,e.data);for(let t=0;t<r.length;t++){const e=wa&r[t];for(let t=0;t<s.tilesets.length;t++){const{tiles:o,firstgid:r}=s.tilesets[t];if(o)for(let t=0;t<o.length;t++){const s=o[t];s.id+r===e&&s.objectgroup&&i(n,s.objectgroup)}}}if(o){const t=H.setUp("type",o),e=kt.getAssetList(t);F(n,e),V.recycle(e),t.recycle()}}}if(!e){const t=s.tilesets,e=V.setUp();for(let i=0;i<t.length;i++){const s=t[i];if(s.image)e.push(s.image);else{const t=s.tiles;for(let i=0;i<t.length;i++){const s=t[i];s.image&&e.push(s.image)}}}F(n,e),V.recycle(e)}s.assets=Z(n)}return n}(s?.level??t?.level??e?.level??i?.level,n);return n&&F(r,"string"==typeof n?platypus.game.settings.spriteSheets[n].images:n.images),o&&F(r,o),r}}),ja=(t,e)=>t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24)>>>0,Ya=(t,e)=>t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24)>>>0,Na=function(t){return"base64"===t.encoding&&(t.data=((t,e)=>{const i=[],s="zlib"===e,n=window.atob(t.replace(/\\/g,"")),o=s?pa(n):n,r=s?Ya:ja;let a=4;for(;a<=o.length;)i.push(r(o,a-4)),a+=4;return i})(t.data,t.compression),t.encoding="csv"),t},Wa=function(t,e,i,s,n,o){const r=Z(t);if("horizontal"===o){for(let t=n-1;t>=0;t--)for(let n=t*s,o=0;n<(t+1)*s;n++,o++)r.splice((t+1)*e+o,0,i[n]);return r}return"vertical"===o?t.concat(i):null},Ha=function(t,e,i,s){const n=Z(t);for(let t=0;t<e.length;t++){const o={...e[t]};"horizontal"===s?o.x+=i:"vertical"===s&&(o.y+=i),n.push(o)}return n},Va=function(t,e,i){t.tilewidth||t.tileheight?t.tilewidth===e.tilewidth&&t.tileheight===e.tileheight||platypus.debug.warn("Component LevelBuilder: Your map has segments with different tile sizes. All tile sizes must match. Segment: "+e):(t.tilewidth=e.tilewidth,t.tileheight=e.tileheight),"horizontal"===i?0===t.height?t.height=e.height:t.height!==e.height&&platypus.debug.warn("Component LevelBuilder: You are trying to merge segments with different heights. All segments need to have the same height. Level: "+t+" Segment: "+e):"vertical"===i&&(0===t.width?t.width=e.width:t.width!==e.width&&platypus.debug.warn("Component LevelBuilder: You are trying to merge segments with different widths. All segments need to have the same width. Level: "+t+" Segment: "+e));for(let s=0;s<e.layers.length;s++)if(t.layers[s])t.layers[s].type===e.layers[s].type?t.layers[s].data&&e.layers[s].data?(Na(e.layers[s]),"horizontal"===i?(t.layers[s].data=Wa(t.layers[s].data,t.width,e.layers[s].data,e.width,t.height,i),t.layers[s].width+=e.width):"vertical"===i&&(t.layers[s].data=Wa(t.layers[s].data,t.height,e.layers[s].data,e.height,t.width,i),t.layers[s].height+=e.height)):t.layers[s].objects&&e.layers[s].objects&&("horizontal"===i?t.layers[s].objects=Ha(t.layers[s].objects,e.layers[s].objects,t.width*t.tilewidth,i):"vertical"===i&&(t.layers[s].objects=Ha(t.layers[s].objects,e.layers[s].objects,t.height*t.tileheight,i))):platypus.debug.warn("Component LevelBuilder: The layers in your level segments do not match. Level: "+t+" Segment: "+e);else{Na(e.layers[s]);const n=t.layers[s]={...e.layers[s]};n.objects&&("horizontal"===i?n.objects=Ha([],n.objects,t.width*t.tilewidth,i):"vertical"===i&&(n.objects=Ha([],n.objects,t.height*t.tileheight,i)))}"horizontal"===i?t.width+=e.width:"vertical"===i&&(t.height+=e.height);{const i=Object.keys(e),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];t[s]||(t[s]=e[s])}}},Fa=function(t){const e=platypus.game.settings.levels,i={height:0,width:0,layers:[]};for(let s=0;s<t.length;s++){const n={height:0,width:0,layers:[]};for(let i=0;i<t[s].length;i++)if("string"==typeof t[s][i]){const o=t[s][i],r=o.indexOf(":");let a=e[o];if(!a&&r>=0){const t=o.substring(r+1);a=e[o.substring(0,r)],"mirror"===t&&(a=e[o]=Za(a))}Va(n,a,"horizontal")}else Va(n,t[s][i],"horizontal");Va(i,n,"vertical")}return i},Za=function(t){const e={layers:[]},i=t.width*t.tilewidth;for(let s=0;s<t.layers.length;s++){Na(t.layers[s]);const n=t.layers[s],o=e.layers[s]={...n};if(n.data){const e=n.data,i=t.width;o.data=e.map((t,s)=>{const n=e[i*(s/i|0)+i-1-s%i];return n?2147483648^n:0})}if(n.objects){const t=n.objects,e=o.objects=[];for(let s=0;s<t.length;s++){const n=t[s],o=e[s]={...n};o.x=i-n.x-(n.width||0),n.rotation&&(o.rotation=-n.rotation),n.polygon&&(o.polygon=Ga(n.polygon)),n.polyline&&(o.polyline=Ga(n.polyline))}}}{const i=Object.keys(t),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];e[s]||(e[s]=t[s])}}return e},Ga=function(t){const e=[];let i=t.length;for(;i--;)e.push({x:-t[i].x,y:t[i].y});return e.unshift(e.pop()),e},qa=xt({id:"LevelBuilder",properties:{useUniques:!0,levelTemplate:null,levelPieces:null},publicProperties:{},initialize:function(){this.levelMessage={level:null,persistentData:null}},events:{"layer-loaded":function(t){const e=t?.levelPieces??this.levelPieces;if(this.levelMessage.persistentData=t,this.levelTemplate=t?.levelTemplate??this.levelTemplate,this.useUniques=t?.useUniques??this.useUniques,this.levelPieces={},e){const t=Object.keys(e),{length:i}=t;for(let s=0;s<i;s++){const i=t[s];if("string"==typeof e[i])this.levelPieces[i]=e[i];else{if(!Array.isArray(e[i]))throw"Level Builder: Level pieces of incorrect type: "+e[i];this.levelPieces[i]=[...e[i]]}}}if(this.levelTemplate)if(this.levelTemplate){this.levelMessage.level=[];for(let t=0;t<this.levelTemplate.length;t++){const e=this.levelTemplate[t];if("string"==typeof e)this.levelMessage.level[t]=this.getLevelPiece(e);else{if(!e.length)throw"Level Builder: Template row is neither a string or array. What is it?";this.levelMessage.level[t]=[];for(let i=0;i<e.length;i++)this.levelMessage.level[t][i]=this.getLevelPiece(e[i])}}}else platypus.debug.warn("Level Builder: Template is not defined");else platypus.debug.warn("Level Builder: There is no level template.");this.levelMessage.level&&(this.levelMessage.level=Fa(this.levelMessage.level),this.owner.triggerEvent("created-level",this.levelMessage),this.owner.triggerEvent("load-level",this.levelMessage))}},methods:{getLevelPiece:function(t){const e=this.levelPieces[t]??t;if(e){if("string"==typeof e)return this.useUniques&&(this.levelPieces[t]=null),e;if(e.length){const i=Math.floor(Math.random()*e.length);return this.useUniques?G(this.levelPieces[t],i):e[i]}throw new Error(`Level Builder: There are no MORE level pieces of type: ${t}`)}throw new Error(`Level Builder: There are no level pieces of type: ${t}`)},destroy:function(){this.levelMessage.level=null,this.levelMessage.persistentData=null,this.levelMessage=null}},publicMethods:{mergeLevels:function(t){return Fa(t)}},getAssetList:function(t,e,i,s){const n=V.setUp(),o=t?.levelPieces??e?.levelPieces??i?.levelPieces??s?.levelPieces;if(o){const t=Object.keys(o),{length:s}=t;for(let r=0;r<s;r++){const s=t[r];if(Array.isArray(o[s]))for(let t=0;t<o[s].length;t++){const r=Ra.getAssetList({level:o[s][t]},e,i);F(n,r),V.recycle(r)}else{const t=Ra.getAssetList({level:o[s]},e,i);F(n,t),V.recycle(t)}}}return n}}),$a=xt({id:"LogicAngularMovement",properties:{maxVelocity:3,acceleration:.01,visualOffset:0,startAngle:0},publicProperties:{},initialize:function(){this.angle=this.startAngle,this.v=V.setUp(0,0),this.moving=!1,this.piOverTwo=Math.PI/2,this.owner.rotation=this.owner.rotation||this.visualOffset},events:{"handle-logic":function({delta:t}){const{PI:e,sin:i,cos:s,min:n,max:o}=Math;if(this.moving){let r=0;this.v[0]+=this.acceleration*s(this.angle)*t,this.v[1]+=this.acceleration*i(this.angle)*t,0===this.v[0]?r=this.v[1]>0?this.piOverTwo:this.v[1]<0?-this.piOverTwo:this.angle:(r=Math.atan(this.v[1]/this.v[0]),this.v[0]<0&&(r=e+r)),this.v[0]>=0?this.v[0]=n(this.v[0],this.maxVelocity*s(r)):this.v[0]=o(this.v[0],this.maxVelocity*s(r)),this.v[1]>=0?this.v[1]=n(this.v[1],this.maxVelocity*i(r)):this.v[1]=o(this.v[1],this.maxVelocity*i(r)),this.owner.x+=this.v[0],this.owner.y+=this.v[1],this.owner.rotation=r*(180/e)+this.visualOffset}},"set-angle":function(t){this.angle=t},move:function(){this.moving=!0},stop:function(){this.moving=!1,this.v[0]=0,this.v[1]=0},"set-max-velocity":function(t){this.maxVelocity=t}},methods:{destroy:function(){this.v.recycle()}}}),Ja=xt({id:"LogicAttachment",properties:{attachState:"attached",attachment:"",updateProperties:null,events:null,startAttached:!1,offsetX:0,offsetY:0,offsetZ:.01},initialize:function(){const t=this.events;if(this.state=this.owner.state,this.state.set(this.attachState,this.startAttached),this.attachmentPosition={x:0,y:0,z:0,dx:0,dy:0},this.attachmentProperties={type:this.attachment,properties:this.attachmentPosition},null===this.updateProperties&&(this.updateProperties=["x","y","z"]),this.attachment=null,this.isAttached=this.startAttached,t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s],n=t[i];this.addEventListener(i,(...t)=>{const{attachment:e}=this;e&&e.trigger.call(e,n,...t)})}}},events:{"handle-logic":function(){const{attachmentPosition:t,owner:e,state:i,updateProperties:s}=this;if(!e.destroyed){if(this.isAttached)if(this.attachment||(s.forEach(i=>t[i]=e[i]),this.attachment=this.owner.parent.addEntity(this.attachmentProperties)),this.attachment.destroyed)e.parent.removeEntity(this.attachment),this.attachment=null,this.isAttached=!1;else{s.forEach(t=>this.attachment[t]=e[t]);let{offsetX:t,offsetY:n}=this;this.attachment.x=e.x,i.get("left")?(t*=-1,this.attachment.rotation=180):i.get("right")&&(this.attachment.rotation=0),this.attachment.x+=t,this.attachment.y=e.y,i.get("top")?(n*=-1,this.attachment.rotation=90):i.get("bottom")&&(this.attachment.rotation=-90),this.attachment.y+=n,this.attachment.z=e.z,this.attachment.z+=this.offsetZ}else this.attachment&&(this.owner.parent.removeEntity(this.attachment),this.attachment=null);i.set(this.attachState,this.isAttached)}},attach:function(t){this.isAttached=!t||!1!==t.pressed},detach:function(){this.isAttached=!1},"change-attachment-offset":function(t){void 0!==t.x?this.offsetX=t.x:void 0!==t.y?this.offsetY=t.y:void 0!==t.z&&(this.offsetZ=t.z)}},methods:{destroy:function(){this.state.set(this.attachState,!1),this.attachment&&(this.owner.parent.removeEntity(this.attachment),this.attachment=null),this.isAttached=!1,this.state=null}},getAssetList:function(t,e,i){const s=t?.attachment??e?.attachment??i?.attachment;return s?kt.getAssetList({type:s}):V.setUp()}}),Qa=xt({id:"LogicButton",properties:{onPress:"",onRelease:"",onCancel:"",onHover:"",useOnce:!1,disabled:!1,toggle:!1,pressed:!1,validState:"!disabled",validParentState:"",baton:!1},publicProperties:{bottom:null,left:null,right:null,top:null},initialize:function(){const{state:t}=this.owner;this.aabb=Ci.setUp(),this.lastBottom=null,this.lastLeft=null,this.lastRight=null,this.lastTop=null,this.state=t,t.set("disabled",this.disabled),t.set("released",!this.pressed),t.set("pressed",this.pressed),t.set("highlighted",!1),this.validParentState=mt.setUp(this.validParentState),this.validState=mt.setUp(this.validState),this.baton&&(this.validParentState.set("baton",!1),this.owner.parent.state.set("baton",!1),this.batonIsMine=!1),this.owner.container.cursor=this.disabled?null:"pointer",this.cancelled=!1,this.readyToToggle=!1},events:{"handle-logic":function(){const{bottom:t,left:e,right:i,top:s}=this;this.lastBottom===t&&this.lastLeft===e&&this.lastRight===i&&this.lastTop===s||(this.updatePosition(this.aabb),this.lastBottom=t,this.lastLeft=e,this.lastRight=i,this.lastTop=s)},"camera-update":function(t){this.aabb.set(t.viewport),this.updatePosition(this.aabb)},pointerdown:function(t){this.checkStateValidity()&&(this.toggle?this.readyToToggle=!0:(this.baton&&(this.batonIsMine=!0,this.owner.parent.state.set("baton",!0)),this.onPress&&this.owner.trigger(this.onPress),this.updateStateAndTrigger("pressed"),t&&t.pixiEvent&&t.pixiEvent.stopPropagation&&t.pixiEvent.stopPropagation()))},pressup:function(t){const{state:e}=this;this.baton&&this.batonIsMine&&(this.batonIsMine=!1,this.owner.parent.state.set("baton",!1)),this.checkStateValidity()&&(this.cancelled?(this.onCancel&&this.owner.trigger(this.onCancel),this.updateStateAndTrigger("cancelled")):this.toggle?this.readyToToggle&&(e.get("pressed")?this.updateStateAndTrigger("released"):this.updateStateAndTrigger("pressed")):(this.onRelease&&this.owner.trigger(this.onRelease),this.updateStateAndTrigger("released")),t&&t.pixiEvent&&t.pixiEvent.stopPropagation&&t.pixiEvent.stopPropagation(),!this.cancelled&&this.useOnce&&this.removeEventListener&&(this.removeEventListener("pointerdown"),this.removeEventListener("pressup"),this.state.set("disabled",!0),this.owner.container.cursor=null)),this.cancelled=!1,this.readyToToggle=!1},pointerover:function(){this.onHover&&this.owner.trigger(this.onHover),this.state.get("pressed")&&(this.cancelled=!1)},pointerout:function(){this.state.get("pressed")&&(this.cancelled=!0)},disable:function(){this.state.set("disabled",!0),this.owner.container.cursor=null},enable:function(){this.state.set("disabled",!1),this.owner.container.cursor="pointer"},"toggle-disabled":function(){const t=this.state.get("disabled");this.owner.container.cursor=t?"pointer":null,this.state.set("disabled",!t)},highlight:function(){this.state.set("highlighted",!0)},unhighlight:function(){this.state.set("highlighted",!1)},"toggle-highlight":function(){const{state:t}=this;t.set("highlighted",!t.get("highlighted"))}},methods:{checkStateValidity(){const{owner:t,validParentState:e,validState:i}=this;return t.state.includes(i)&&t.parent.state.includes(e)},updatePosition(t){const{bottom:e,left:i,owner:s,right:n,top:o}=this;"number"==typeof i?s.x=t.left+i:"number"==typeof n&&(s.x=t.right-n),"number"==typeof o?s.y=t.top+o:"number"==typeof e&&(s.y=t.bottom-e)},updateStateAndTrigger(t){const{owner:e,state:i}=this,s=i.get("pressed"),n=i.get("released");let o=!1;if(n&&"pressed"===t?(i.set("pressed",!0),i.set("released",!1),o=!0):!s||"released"!==t&&"cancelled"!==t||(i.set("pressed",!1),i.set("released",!0),o=!0),o){const i=H.setUp("released",s,"pressed",n,"triggered",n,"entity",e);e.triggerEvent(t,i),i.recycle()}},destroy:function(){this.baton&&this.batonIsMine&&(this.batonIsMine=!1,this.owner.parent.state.set("baton",!1)),this.aabb.recycle(),this.aabb=null,this.owner.container.cursor=null,this.state=null}}}),Ka=xt({id:"LogicCarrier",initialize:function(){},events:{load:function(){this.owner.triggerEvent("add-collision-entity",this.owner)||(this.owner.addComponent(new platypus.components.CollisionGroup(this.owner,{})),this.owner.triggerEvent("add-collision-entity",this.owner))},"carry-me":function(t){this.owner.triggerEvent("add-collision-entity",t.entity)},"release-me":function(t){this.owner.triggerEvent("remove-collision-entity",t.entity)}}}),th=xt({id:"LogicDestroyMe",properties:{delay:0,destroyed:!1},initialize:function(){},events:{"prepare-logic":function({delta:t}){this.destroyed&&!this.owner.state.get("paused")&&(this.delay-=t,this.delay<=0&&this.owner.parent.removeEntity(this.owner))},"destroy-me":function(){this.destroyed=!0}}}),eh=function(t){return function(e){this[t]=!e||!1!==e.pressed}},ih=function(){},sh={x:function(t,e){t!==e&&(t>180&&e<=180||t<=180&&e>180)&&this.owner.triggerEvent("transform","vertical")},y:function(t,e){t!==e&&(t>90&&t<=270&&(e<=90||e>270)||(t<=90||t>270)&&e>90&&e<=270)&&this.owner.triggerEvent("transform","horizontal")},z:function(t,e){t!==e&&this.owner.triggerEvent("replace-transform","rotate-"+t)}},nh=xt({id:"LogicDirectionalMovement",properties:{axis:"y",speed:.3},initialize:function(){const t=this.state=this.owner.state;"number"==typeof this.speed&&(this.speed=[this.speed,0,0]),this.initialVector=Ht.setUp(this.speed),this.reorient=sh[this.axis],this.reorient||(this.reorient=ih),this.moving=t.set("moving",!1),this.left=t.set("left",!1),this.right=t.set("right",!1),this.up=t.set("up",!1),this.down=t.set("down",!1),this.upLeft=!1,this.upRight=!1,this.downLeft=!1,this.downRight=!1,this.heading=0,this.owner.heading=this.owner.heading||0,this.headingsMap={up:270,north:270,down:90,south:90,left:180,west:180,right:0,east:0,"up-left":225,northwest:225,"up-right":315,northeast:315,"down-left":135,southwest:135,"down-right":45,southeast:45}},events:{"component-added":function(t){if(t===this){if(!this.owner.addMover)return void platypus.debug.warn('The "LogicDirectionalMovement" component requires a "Mover" component to function correctly.');this.direction=this.owner.addMover({velocity:this.speed,drag:0,friction:0,stopOnCollision:!1,orient:!1,aliases:{moving:"control-velocity"}}).velocity,this.owner.heading!==this.heading&&(this.direction.setVector(this.initialVector).rotate(this.owner.heading/180*Math.PI),this.heading=this.owner.heading),this.owner.triggerEvent("moving",this.moving)}},"handle-logic":function(){const t=this.state,e=this.upLeft||this.up&&this.left,i=this.downLeft||this.down&&this.left,s=this.downRight||this.down&&this.right,n=this.upRight||this.up&&this.right;let o=this.up||this.upLeft||this.upRight,r=this.left||this.upLeft||this.downLeft,a=this.down||this.downLeft||this.downRight,h=this.right||this.upRight||this.downRight;if(r&&h||o&&a)this.moving=!1;else if(e)this.moving=!0,this.heading=225;else if(n)this.moving=!0,this.heading=315;else if(i)this.moving=!0,this.heading=135;else if(s)this.moving=!0,this.heading=45;else if(r)this.moving=!0,this.heading=180;else if(h)this.moving=!0,this.heading=0;else if(o)this.moving=!0,this.heading=270;else if(a)this.moving=!0,this.heading=90;else switch(this.moving=!1,this.heading){case 270:o=!0;break;case 90:a=!0;break;case 180:r=!0;break;case 225:o=!0,r=!0;break;case 315:o=!0,h=!0;break;case 135:a=!0,r=!0;break;case 45:a=!0,h=!0;break;default:h=!0}this.owner.heading!==this.heading&&(this.direction.setVector(this.initialVector).rotate(this.heading/180*Math.PI),this.reorient(this.heading,this.owner.heading),this.owner.heading=this.heading),t.get("moving")!==this.moving&&(this.owner.triggerEvent("moving",this.moving),t.set("moving",this.moving)),t.set("up",o),t.set("right",h),t.set("down",a),t.set("left",r)},"go-down":eh("down"),"go-south":eh("down"),"go-down-left":eh("downLeft"),"go-southwest":eh("downLeft"),"go-left":eh("left"),"go-west":eh("left"),"go-up-left":eh("upLeft"),"go-northwest":eh("upLeft"),"go-up":eh("up"),"go-north":eh("up"),"go-up-right":eh("upRight"),"go-northeast":eh("upRight"),"go-right":eh("right"),"go-east":eh("right"),"go-down-right":eh("downRight"),"go-southeast":eh("downRight"),stop:function(t){t&&!1===t.pressed||(this.left=!1,this.right=!1,this.up=!1,this.down=!1,this.upLeft=!1,this.upRight=!1,this.downLeft=!1,this.downRight=!1)},face:function(t){this.heading=this.headingsMap[t]||0},accelerate:function(t){this.initialVector.normalize().multiply(t),this.direction.normalize().multiply(t)}},methods:{destroy:function(){this.initialVector.recycle(),this.state=null}}}),oh=new u(-2e3,-2e3,4e3,4e3),rh=[],ah=xt({id:"LogicDragDrop",properties:{stickiness:0,dragDisabled:!1},publicProperties:{stayInViewport:!1,stickyClick:void 0},initialize:function(){this.aabb=this.owner.parent.worldCamera.viewport,this.cameraScaleX=1,this.cameraScaleY=1,this.nextX=this.owner.x,this.nextY=this.owner.y,this.grabOffsetX=0,this.grabOffsetY=0,this.state=this.owner.state,this.state.set("dragging",!1),this.dragId=null,this.originalContainer=null,this.dragContainer=new n,this.dragContainer.zIndex=1/0,void 0===this.stickyClick&&(this.stickyClick=!platypus.supports.mobile),this.releaseStick=!1},events:{"camera-update":function({scaleX:t,scaleY:e}){this.cameraScaleX=t,this.cameraScaleY=e,this.checkCamera()},"prepare-logic":function(){this.checkCamera()},"handle-logic":function(){let t=!1;if(this.state.get("dragging")){const{dragContainer:e,nextX:i,nextY:s,owner:n}=this;n.triggerEvent("dragging",{dragContainer:e,entity:n,x:i,y:s,pointer:{x:i+this.grabOffsetX,y:s+this.grabOffsetY},preventDefault:()=>{t=!0}}),t||(n.x=i,n.y=s)}},pointerdown:function(t){if(!this.dragDisabled){if(this.sticking)this.sticking=null,this.nextX=t.x-this.grabOffsetX,this.nextY=t.y-this.grabOffsetY,this.stayInViewport&&this.checkCamera(),this.releaseStick=!0;else{const{owner:e}=this;if(null===this.dragId){const{dragContainer:i}=this;let s=!1;if(this.dragId=t.event.pointerId,e.triggerEvent("drag-start",{dragContainer:i,entity:e,preventDefault:()=>{s=!0}}),s)this.dragId=null;else{const{state:s}=this,{x:n,y:o}=e;this.nextX=n,this.nextY=o,this.grabOffsetX=(0|t.x)-n,this.grabOffsetY=(0|t.y)-o,s.set("dragging",!0),e.dragMode=!0,this.sticking=this.stickyClick?{x:n,y:o}:null,this.claimPointer(),this.checkCamera(),this.originalContainer=e.container.parent,i.addChild(e.container),e.parent.stage.addChild(i),rh.push(this)}}}t.pixiEvent.stopPropagation()}},pressup:function(t){if(this.releaseStick)return this.release(),void(this.releaseStick=!1);this.state.get("dragging")&&(null===this.dragId||this.sticking||this.release(),t.pixiEvent.stopPropagation())},"input-off":function(){this.state.get("dragging")&&null!==this.dragId&&this.release()},pointermove:function(t){this.state.get("dragging")&&this.sticking&&(this.nextX=t.x-this.grabOffsetX,this.nextY=t.y-this.grabOffsetY,this.stayInViewport&&this.checkCamera(),t.event.preventDefault(),t.pixiEvent.stopPropagation())},pressmove:function(t){if(this.state.get("dragging")&&null!==this.dragId){const{stickiness:e,sticking:i}=this;this.nextX=t.x-this.grabOffsetX,this.nextY=t.y-this.grabOffsetY,this.stayInViewport&&this.checkCamera(),i&&(this.nextX-i.x)**2+(this.nextY-i.y)**2>e**2&&(this.sticking=null),t.event.preventDefault(),t.pixiEvent.stopPropagation()}},"disable-drag":function(t){this.dragDisabled="boolean"==typeof t?t:!this.dragDisabled,this.dragDisabled&&this.state.get("dragging")&&this.release()}},methods:{checkCamera(){const{state:t,stayInViewport:e}=this,i=t?.get("dragging");if(i||e){const{aabb:t}=this;if(t.containsPoint(i?this.nextX+this.grabOffsetX:this.owner.x,i?this.nextY+this.grabOffsetY:this.owner.y)){const{cameraScaleX:e,cameraScaleY:i,dragContainer:s}=this;s.scale.x=e,s.scale.y=i,s.x=-t.left*e,s.y=-t.top*i}else this.stayInViewport?i?(this.nextX=Math.min(t.right,Math.max(t.left,this.nextX+this.grabOffsetX))-this.grabOffsetX,this.nextY=Math.min(t.bottom,Math.max(t.top,this.nextY+this.grabOffsetY))-this.grabOffsetY):(this.owner.x=Math.min(t.right,Math.max(t.left,this.owner.x)),this.owner.y=Math.min(t.bottom,Math.max(t.top,this.owner.y))):this.release()}},claimPointer(){this.lastHitArea=this.owner.container.hitArea,this.owner.container.hitArea=oh},releasePointer(){this.owner.container.hitArea=this.lastHitArea},releaseContainer(){const{originalContainer:t,owner:e}=this,i=rh.indexOf(this);i>=0&&rh.splice(i,1),t&&(e.parent.stage.removeChild(this.dragContainer),t.addChild(e.container),this.originalContainer=null)},release(){const{dragContainer:t,owner:e,state:i}=this,s=e.x,n=e.y;let o=!1;this.sticking=null,this.dragId=null,i.set("dragging",!1),e.dragMode=!1,this.releasePointer(),this.releaseContainer(),e.triggerEvent("drop",{dragContainer:t,entity:e,x:s,y:n,preventDefault:()=>{o=!0}}),o||(e.x=s,e.y=n,e.triggerEvent("drop-complete"))},destroy(){this.state.get("dragging")&&(this.dragId=null,this.releaseContainer(),this.state.set("dragging",!1)),this.owner.dragMode=!1,this.state=null}}}),hh=xt({id:"LogicImpactLaunch",properties:{accelerationX:-.3,accelerationY:-.8,flipX:!0,flipY:!1,state:"stunned"},initialize:function(t){this.stunState=t.state||"stunned",this.flipX=this.flipX?-1:1,this.flipY=this.flipY?-1:1,this.justJumped=!1,this.stunned=!1,this.state=this.owner.state,this.state.set("impact",!1),this.state.set(this.stunState,!1)},events:{"component-added":function(t){if(t===this){if(!this.owner.addMover)return void platypus.debug.warn('The "LogicDirectionalMovement" component requires a "Mover" component to function correctly.');this.direction=this.owner.addMover({velocity:[0,0,0],orient:!1}).velocity,this.vector=Ht.setUp()}},"handle-logic":function(){this.state.set("impact",this.justJumped),this.state.set(this.stunState,this.stunned),this.justJumped&&(this.direction.setVector(this.vector),this.justJumped=!1,this.stunned=!0)},"impact-launch":function({entity:t,x:e,y:i}){if(!this.stunned){const{owner:s,vector:n}=this,o=t?t.x-s.x:e,r=t?t.y-s.y:i;this.justJumped=!0,o>=0?n.x=this.accelerationX:o<0&&(n.x=this.accelerationX*this.flipX),r>=0?n.y=this.accelerationY:r<0&&(n.y=this.accelerationY*this.flipY)}},"hit-solid":function(t){this.stunned&&t.y>0&&(this.direction.x=0,this.direction.y=0,this.stunned=!1)}},methods:{destroy:function(){this.vector.recycle(),this.state=null}}}),lh=xt({id:"LogicPacingPlatform",initialize:function(t){this.ang=this.owner.angle||t.angle||0,this.dist=this.owner.distance||t.distance||128,this.dX=this.dist*Math.cos(this.ang),this.dY=this.dist*Math.sin(this.ang),this.period=this.owner.period||t.period||4e3,this.time=0,this.startPos=this.owner.startPos||t.startPos||0,this.offset=0,this.originX=this.owner.x,this.originY=this.owner.y},events:{"handle-logic":function({delta:t}){const{period:e}=this;this.time+=t,this.time>e&&(this.time=this.time%e),this.offset=this.time/e*(2*Math.PI),this.owner.x=this.originX+Math.sin(this.offset+this.startPos)*this.dX,this.owner.y=this.originY+Math.sin(this.offset+this.startPos)*this.dY}}}),ch=xt({id:"LogicPortable",properties:{portableDirections:{down:!0}},initialize:function(){this.carrier=this.lastCarrier=null,this.message={entity:this.owner}},events:{"handle-logic":function(){const{message:t}=this;this.carrierConnected?(this.carrier!==this.lastCarrier&&(this.lastCarrier&&this.lastCarrier.triggerEvent("release-me",t),this.carrier.triggerEvent("carry-me",t)),this.carrierConnected=!1):this.carrier&&(this.carrier.triggerEvent("release-me",t),this.carrier=null),this.lastCarrier=this.carrier},"hit-solid":function(t){t.y>0?this.updateCarrier(t.entity,"down"):t.y<0?this.updateCarrier(t.entity,"up"):t.x<0?this.updateCarrier(t.entity,"left"):t.x>0&&this.updateCarrier(t.entity,"right")},"force-release":function(){this.carrier&&this.carrier.triggerEvent("release-me",this.message),this.carrier=null,this.lastCarrier=this.carrier,this.carrierConnected=!1}},methods:{updateCarrier:function(t,e){this.portableDirections[e]&&t&&(t!==this.carrier&&(this.carrier=t),this.carrierConnected=!0)}}}),dh=xt({id:"LogicPortal",initialize:function(t){const e=t.entrants||t.entrant||"no one",i=this.owner.state;if(this.destination=this.owner.destination||t.destination,this.used=!1,this.ready=!1,this.wasReady=!1,this.entrants=et.setUp(),Array.isArray(e))for(let t=0;t<e.length;t++)this.entrants.set(e[t],!1);else this.entrants.set(e,!1);this.state=i,i.set("occupied",!1),i.set("ready",!0)},events:{"handle-logic":function(){const{entrants:t,state:e}=this,i=t.keys;let s=i.length,n=!1,o=!0;for(!this.used&&this.activated?(this.owner.triggerEvent("port-"+this.destination),this.used=!0):this.ready&&!this.wasReady?(this.owner.triggerEvent("portal-waiting"),this.wasReady=!0):this.wasReady&&!this.ready&&(this.owner.triggerEvent("portal-not-waiting"),this.wasReady=!1);s--;)t[i[s]]?(n=!0,t.set(i[s],!1)):o=!1;e.set("occupied",n),e.set("ready",o),this.ready=!1},"occupied-portal":function(t){const e=this.entrants,i=e.keys;let s=i.length;for(e.set(t.entity.type,!0);s--;)if(!e.get(i[s]))return;this.ready=!0},"activate-portal":function(){this.activated=!0}},methods:{destroy:function(){this.state=null,this.entrants.recycle(),this.entrants=null}}}),uh=function(t,e){return t/Math.abs(t)*e},ph=xt({id:"LogicPushable",initialize:function(t){this.yPush=t.push||t.yPush||0,this.xPush=t.push||t.xPush||.1,t.roll?(this.radius=t.radius||this.owner.radius||(this.owner.width||this.owner.height||2)/2,this.owner.orientation=this.owner.orientation||0):this.radius=0,this.currentPushX=0,this.currentPushY=0,this.lastX=this.owner.x,this.lastY=this.owner.y,this.pushers=V.setUp()},events:{"handle-logic":function({delta:t}){this.currentPushY&&(this.owner.y+=uh(this.currentPushY,this.yPush*t),this.currentPushY=0),this.currentPushX&&(this.owner.x+=uh(this.currentPushX,this.xPush*t),this.currentPushX=0),this.lastX===this.owner.x&&this.lastY===this.owner.y||(this.radius&&(this.owner.orientation+=(this.owner.x+this.owner.y-this.lastX-this.lastY)/this.radius),this.lastX=this.owner.x,this.lastY=this.owner.y);for(let t=0;t<this.pushers.length;t++)this.pushers[t].triggerEvent("pushed",this.owner);this.pushers.length=0},"push-entity":function(t){const e=t.x||0,i=t.y||0;this.currentPushX-=e,this.currentPushY-=i,(this.yPush&&i||this.xPush&&e)&&this.pushers.push(t.entity)},"hit-solid":function(t){return t.y>0&&this.vY>0||t.y<0&&this.vY<0?this.vY=0:(t.x<0&&this.vX<0||t.x>0&&this.vX>0)&&(this.vX=0),!0}},methods:{destroy:function(){V.recycle(this.pushers)}}}),gh=xt({id:"LogicRebounder",initialize:function(t){Ht.assign(this.owner,"velocity","dx","dy","dz"),this.owner.mass=this.owner.mass||t.mass||1,this.elasticity=t.elasticity||.8,this.v=Ht.setUp(0,0,0),this.incidentVector=Ht.setUp(0,0,0),this.staticCollisionOccurred=!1,this.nonStaticCollisionOccurred=!1,this.hitThisTick=V.setUp(),this.otherV=Ht.setUp(0,0,0),this.otherVelocityData=V.setUp()},events:{"handle-logic":function(){this.hitThisTick.length=0;for(let t=0;t<this.otherVelocityData.length;t++)this.otherVelocityData[t].velocity.recycle();this.otherVelocityData.length=0},"hit-static":function({direction:t,entity:e}){let i=0;for(let t=0;t<this.hitThisTick.length;t++)if(e===this.hitThisTick[t])return;this.hitThisTick.push(e),this.v.setVector(this.owner.velocity),this.incidentVector.setVector(t),i=this.v.scalarProjection(this.incidentVector),isNaN(i)||(this.incidentVector.scale(i*(1+this.elasticity)),this.v.subtractVector(this.incidentVector)),this.owner.velocity.setVector(this.v)},"hit-non-static":function({direction:t,entity:e}){let i=!1,s=0,n=0,o=0;if(!(this.hitThisTick.indexOf(e)>=0)){this.hitThisTick.push(e);for(let t=0;t<this.otherVelocityData.length;t++)if(e===this.otherVelocityData[t].entity){this.otherV.setVector(this.otherVelocityData[t].velocity),i=!0;break}i||(this.otherV.setVector(e.velocity),e.triggerEvent("share-velocity",this.owner)),this.v.setVector(this.owner.velocity),this.incidentVector.setVector(t),s=this.v.scalarProjection(this.incidentVector),s=isNaN(s)?0:s,n=this.otherV.scalarProjection(this.incidentVector),n=isNaN(n)?0:n,o=(s*(this.owner.mass-e.mass)+2*e.mass*n)/(this.owner.mass+e.mass),this.incidentVector.scale(o-s),this.owner.velocity.setVector(this.incidentVector)}},"share-velocity":function(t){this.otherVelocityData.push({entity:t,velocity:Ht.setUp(t.velocity)})}},methods:{destroy:function(){this.v.recycle(),this.incidentVector.recycle(),this.otherV.recycle(),V.recycle(this.hitThisTick),V.recycle(this.otherVelocityData)}}}),fh=xt({id:"LogicRegionSpawner",initialize:function(t){if(this.spawnPosition={x:0,y:0},this.spawnProperties={type:t.spawn,properties:this.spawnPosition},this.regions=null,this.usedRegions=null,this.regionWidth=0,this.regionHeight=0,t.regions){const e=t.regions.width||this.owner.width,i=t.regions.height||this.owner.height,s=Math.round(this.owner.width/e),n=Math.round(this.owner.height/i);this.regions=V.setUp(),this.usedRegions=V.setUp(),this.regionWidth=e,this.regionHeight=i;for(let t=0;t<s;t++)for(let s=0;s<n;s++){const n=Math.min(e,this.owner.width-t*e),o=Math.min(i,this.owner.height-s*i);this.regions.push({x:t*e,y:s*i,width:n,height:o})}}this.interval=this.owner.interval||t.interval||1e3,this.time=0},events:{"handle-logic":function({delta:t}){if(this.time+=t,this.time>this.interval){let t=this.regions,e=null;this.time-=this.interval,t?(t.length||(this.regions=this.usedRegions,this.usedRegions=t,t=this.regions),e=t[Math.floor(t.length*Math.random())],this.spawnPosition.x=this.owner.x-(this.owner.regX||0)+(e.x+Math.random()*e.width),this.spawnPosition.y=this.owner.y-(this.owner.regY||0)+(e.y+Math.random()*e.height)):(this.spawnPosition.x=this.owner.x-(this.owner.regX||0)+Math.random()*this.owner.width,this.spawnPosition.y=this.owner.y-(this.owner.regY||0)+Math.random()*this.owner.height),this.owner.parent.addEntity(this.spawnProperties)}}},methods:{destroy:function(){this.regions&&(V.recycle(this.regions),V.recycle(this.usedRegions))}},getAssetList:function(t,e,i){const s=t?.spawn??e?.spawn??i?.spawn;return s?kt.getAssetList({type:s}):V.setUp()}}),yh=function(){const t=Math.cos,e=Math.sin;return xt({id:"LogicRotationalMovement",properties:{speed:.3,angle:0,degree:1},initialize:function(){const t=this.owner.state;this.magnitude=0,this.state=t,t.set("moving",!1),t.set("turningRight",!1),t.set("turningLeft",!1),this.owner.orientation=0,this.moving=!1,this.turningRight=!1,this.turningLeft=!1},events:{"handle-logic":function(i){const s=this.state;var n,o;this.turningRight&&(this.angle+=this.degree*i.delta/15),this.turningLeft&&(this.angle-=this.degree*i.delta/15),this.moving&&(this.owner.x+=(n=this.magnitude,o=this.angle,n*t(o)*i.delta),this.owner.y+=function(t,i){return t*e(i)}(this.magnitude,this.angle)*i.delta),s.set("moving",this.moving),s.set("turningLeft",this.turningLeft),s.set("turningRight",this.turningRight),this.owner.orientation!==this.angle*Math.PI/180&&(this.owner.orientation=this.angle*Math.PI/180,this.owner.triggerEvent("orientation-updated"))},rotate:function(t){this.angle+=t},"turn-right":function(t){this.turningRight=!t||t.pressed},"turn-left":function(t){this.turningLeft=!t||t.pressed},"go-forward":function(t){!t||t.pressed?(this.moving=!0,this.magnitude=this.speed):this.moving=!1},"go-backward":function(t){!t||t.pressed?(this.moving=!0,this.magnitude=-this.speed):this.moving=!1},stop:function(t){t&&!t.pressed||(this.moving=!1,this.turningLeft=!1,this.turningRight=!1)},"stop-moving":function(t){t&&!t.pressed||(this.moving=!1)},"stop-turning":function(t){t&&!t.pressed||(this.turningLeft=!1,this.turningRight=!1)}},methods:{destroy:function(){this.state=null}}})}(),mh=xt({id:"LogicSpawner",initialize:function(t){const e=this.owner.spawneeClass||t.spawneeClass;if(this.state=this.owner.state,this.stateName=t.state||"spawning",this.originalZ=platypus.game.settings.entities[e]&&platypus.game.settings.entities[e].properties&&platypus.game.settings.entities[e].properties.z||0,this.speed=t.speed||this.owner.speed||0,this.state.set(this.stateName,!1),this.spawneeProperties={x:0,y:0,z:0,dx:0,dy:0,spawner:this.owner},t.passOnProperties)for(let e=0;e<t.passOnProperties.length;e++){const i=t.passOnProperties[e];this.owner[i]&&(this.spawneeProperties[i]=this.owner[i])}this.propertiesContainer={type:e,properties:this.spawneeProperties},this.offsetX=this.owner.offsetX||t.offsetX||0,this.offsetY=this.owner.offsetY||t.offsetY||0,this.firing=!1},events:{"handle-logic":function(){const t=this.state;if(this.firing){let e=0;this.spawneeProperties.x=this.owner.x,this.spawneeProperties.y=this.owner.y,this.spawneeProperties.z=this.owner.z+this.originalZ,e=this.offsetX,t.get("left")&&(e*=-1),this.spawneeProperties.x+=e,e=this.offsetY,t.get("top")&&(e*=-1),this.spawneeProperties.y+=e,this.speed?(t.get("top")?this.spawneeProperties.dy=-this.speed:t.get("bottom")?this.spawneeProperties.dy=this.speed:delete this.spawneeProperties.dy,t.get("left")?this.spawneeProperties.dx=-this.speed:t.get("right")?this.spawneeProperties.dx=this.speed:delete this.spawneeProperties.dx):(delete this.spawneeProperties.dx,delete this.spawneeProperties.dy),this.parent.addEntity(this.propertiesContainer)}t.set(this.stateName,this.firing),this.firing=!1},spawn:function(t){this.firing=!t||!1!==t.pressed,this.parent=this.owner.parent}},methods:{destroy:function(){this.state=null}},getAssetList:function(t,e,i){const s=t?.spawneeClass??e?.spawneeClass??i?.spawneeClass;return s?kt.getAssetList({type:s}):V.setUp()}}),vh=function(t){if(!t||"object"!=typeof t||Array.isArray(t)||t.event)return t;{const e=et.setUp(),i=Object.keys(t),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];e.set(s,vh(t[s]))}return e}},wh=function({title:t,state:e,last:i,checks:s,changed:n,self:o,queue:r,appendDetails:a}){const h=s.keys,l=s.message??0===s.message??!1===s.message;if(n){if("string"==typeof s){if(a){const t=mt.setUp(e);o.triggerEvent(s,{entity:o,state:t}),t.recycle()}else o.triggerEvent(s);return}if(Array.isArray(s)){for(let h=0;h<s.length;h++)wh({title:t,state:e,last:i,checks:s[h],changed:n,self:o,queue:r,appendDetails:a});return}if(s.event&&(l||s.delay)){if(s.delay)r.push(s);else if(a){const t=mt.setUp(e);o.trigger(s.event,{...s.message??{},entity:o,state:t}),t.recycle()}else o.trigger(s.event,s.message);return}if(s.get){const h=s.get("true");h&&wh({title:t,state:e,last:i,checks:h,changed:n,self:o,queue:r,appendDetails:a})}}if(h){let t=h.length;for(;t--;){const l=h[t];"true"!==l&&bh({title:l,state:e,last:i,checks:s.get(l),changed:n,self:o,queue:r,appendDetails:a})}}},bh=function({title:t,state:e,last:i,checks:s,changed:n,self:o,queue:r,appendDetails:a}){let h=n,l=!1;if("!"===t.charAt(0)){const s=t.substring(1),n=e.get(s);l=!1===n,"outputs"!==t&&i.get(s)!==n&&(h=!0)}else{const s=e.get(t);l=!0===s,"outputs"!==t&&i.get(t)!==s&&(h=!0)}(l||"outputs"===t)&&wh({title:t,state:e,last:i,checks:s,changed:h,self:o,queue:r,appendDetails:a})},xh=xt({id:"LogicStateMachine",properties:{appendDetails:!1,inputs:null,outputs:null},initialize:function(t){const e=this.inputs,i=t["sustained-inputs"],s=this.owner.state;if(this.state=s,e){const t=V.setUp(),i=Object.keys(e),{length:n}=i;for(let o=0;o<n;o++){const n=i[o],r=mt.setUp(e[n]),a=r.keys;let h=a.length;for(t.push(r),this.addEventListener(n,()=>{s.update(r)});h--;)s.has(a[h])||s.set(a[h],!1)}this.stateObjects=t}if(this.sustainedState=mt.setUp(),i){const t=Object.keys(i),{length:e}=t,{sustainedState:n}=this;for(let o=0;o<e;o++){const e=t[o],r=i[e];this.addEventListener(e,()=>{n.set(r,!0)}),n.set(i[e],!1),s.set(i[e],!1)}}this.snapshot=mt.setUp(),this.last=mt.setUp(),this.queueTimes=V.setUp(),this.queue=V.setUp(),this.outputs=vh(this.outputs)},events:{"handle-logic":function(t){const{state:e,sustainedState:i}=this,s=i.keys;let n=s.length;for(;n--;){const t=s[n];e.set(t,i.get(t)),i.set(t,!1)}for(n=this.queue.length;n--;)this.queueTimes[n]-=t.delta,this.queueTimes[n]<=0&&(this.owner.trigger(this.queue[n].event,this.queue[n].message),G(this.queueTimes,n),G(this.queue,n))},"update-state":function(t){this.state.update(t)},"state-changed":function(t){const e=this.snapshot;if(this.outputs){const i=V.setUp();e.update(t),bh({title:"outputs",state:e,last:this.last,checks:this.outputs,changed:!1,self:this.owner,queue:i,appendDetails:this.appendDetails});let s=i.length;for(;s--;)this.queue.push(i[s]),this.queueTimes.push(i[s].delay);V.recycle(i),this.last.update(e)}}},methods:{destroy:function(){const t=this.stateObjects;if(V.recycle(this.queueTimes),V.recycle(this.queue),t){let e=t.length;for(;e--;)t[e].recycle();V.recycle(t),this.stateObjects=null}this.sustainedState.recycle(),this.snapshot.recycle(),this.last.recycle(),this.state=null,this.inputs=null}}}),_h=xt({id:"LogicSwitch",initialize:function(t){this.state=this.owner.state,this.pressed=!1,this.wasPressed=this.pressed,this.sticky=t.sticky||!1,this.state.set("pressed",!1),this.initialPress=!0},events:{"handle-logic":function(){this.sticky?this.pressed&&!this.wasPressed&&(this.state.set("pressed",!0),this.wasPressed=!0,this.owner.triggerEvent("switch-on")):(this.pressed!==this.wasPressed&&(this.pressed?(this.state.set("pressed",!0),this.owner.triggerEvent("switch-on")):(this.state.set("pressed",!1),this.owner.triggerEvent("switch-off"))),this.wasPressed=this.pressed,this.pressed=!1)},"switch-pressed":function(){this.pressed=!0,this.initialPress&&(this.owner.triggerEvent("initial-press"),this.initialPress=!1)}},methods:{destroy:function(){this.state=null}}}),Ch=xt({id:"LogicTeleportee",initialize:function(){this.teleportDestination=Ht.setUp(),this.teleportNow=!1,this.DestinationSet=!1,this.message={position:this.teleportDestination}},events:{"handle-logic":function(){this.teleportNow&&(this.owner.triggerEvent("relocate-entity",this.message),this.teleportNow=!1,this.owner.triggerEvent("teleport-complete"))},teleport:function(){this.destinationSet&&(this.teleportNow=!0)},"set-destination":function(t){this.setDestination(t)},"hit-telepoint":function(t){this.setDestination(t.entity)}},methods:{setDestination:function(t){this.teleportDestination.setXYZ(t.x,t.y,this.owner.z),this.destinationSet=!0},destroy:function(){this.teleportDestination.recycle()}}}),kh=xt({id:"LogicTeleporter",initialize:function(t){this.destination=null,this.linkId=this.owner.teleportId||t.teleportId,this.facing=this.owner.facing||t.facing||!1,this.facing&&this.owner.state.set("facing-"+this.facing,!0)},events:{"peer-entity-added":function(t){this.destination||t.linkId!==this.linkId||(this.destination=t)},"teleport-entity":function(t){switch(this.facing){case"up":t.y<0&&t.entity.triggerEvent("teleport",this.destination);break;case"right":t.x>0&&t.entity.triggerEvent("teleport",this.destination);break;case"down":t.y>0&&t.entity.triggerEvent("teleport",this.destination);break;case"left":t.x<0&&t.entity.triggerEvent("teleport",this.destination);break;default:t.entity.triggerEvent("teleport",this.destination)}}},methods:{destroy:function(){this.destination=null}}}),Eh=xt({id:"LogicTimer",properties:{time:0,alarmTime:0,isInterval:!1,alarmMessage:"",updateMessage:"",isOn:!0,isIncrementing:!0,maxTime:36e5,resetOnStop:!1},initialize:function(){this.prevTime=this.time},events:{"handle-logic":function(t){this.isOn&&(this.prevTime=this.time,this.isIncrementing?this.time+=t.delta:this.time-=t.delta,Math.abs(this.time)>this.maxTime&&(this.time>0?this.time=this.maxTime:this.time<0&&(this.time=-this.maxTime),this.triggerEvent("stop-timer")),0!==this.alarmTime&&(this.isInterval?this.isIncrementing?Math.floor(this.time/this.alarmTime)>Math.floor(this.prevTime/this.alarmTime)&&this.owner.trigger(this.alarmMessage):Math.floor(this.time/this.alarmTime)<Math.floor(this.prevTime/this.alarmTime)&&this.owner.trigger(this.alarmMessage):this.isIncrementing?this.time>this.alarmTime&&this.prevTime<this.alarmTime&&this.owner.trigger(this.alarmMessage):this.time<this.alarmTime&&this.prevTime>this.alarmTime&&this.owner.trigger(this.alarmMessage))),this.owner.trigger(this.updateMessage,{time:this.time})},"set-timer":function(t){this.time=t.time},"start-timer":function(){this.isOn=!0},"stop-timer":function(){this.isOn=!1,this.resetOnStop&&(this.time=0)}}}),Ah=xt({id:"LogicWindUpRacer",properties:{speed:.3,raceTime:5e3,windTime:500},initialize:function(){const{state:t}=this.owner;this.windProgress=0,this.winding=!1,this.racing=!1,this.blocked=!1,this.right=!1,this.left=!1,this.state=t,t.set("windingUp",!1),t.set("racing",!1),t.set("blocked",!1)},events:{"handle-logic":function(t){const{state:e}=this;this.racing?!this.blocked&&this.right&&e.get("right")?(this.owner.x+=this.speed*t.delta,this.owner.triggerEvent("racing")):!this.blocked&&this.left&&e.get("left")?(this.owner.x-=this.speed*t.delta,this.owner.triggerEvent("racing")):(this.racing=!1,this.owner.triggerEvent("stopped-racing")):this.winding?((this.right&&e.get("right")||this.left&&e.get("left"))&&(this.windProgress+=t.delta),this.owner.triggerEvent("winding",this.windProgress/this.windTime)):this.windProgress&&(this.windProgress>=this.windTime&&(this.racing=!0),this.windProgress=0,this.owner.triggerEvent("stopped-winding")),e.set("windingUp",this.winding),e.set("racing",this.racing),e.set("blocked",this.blocked),this.blocked=!1},"stop-racing":function(){this.racing=!1,this.owner.triggerEvent("stopped-racing")},"wind-up":function(t){this.winding=!t||!1!==t.pressed,this.right=this.state.get("right"),this.left=this.state.get("left")},"hit-solid":function(t){t.x&&this.racing&&(this.right&&t.x>0||this.left&&t.x<0)&&(this.blocked=!0,this.owner.triggerEvent("blocked",t))}},methods:{destroy:function(){this.state.set("windingUp",!1),this.state.set("racing",!1),this.state.set("blocked",!1),this.state=null}}}),Sh=function(){return!0},Mh=function(t,e){return t.get(e)},Th=function(t,e,i){const s=t(),n=e();if(this.activeVelocity){if(this.enact&&!n&&(this.ready=!1),this.ready&&this.enact&&s)this.ready=!1,this.velocity.setVector(this.instant),i&&this.owner.triggerEvent(i);else if(this.ready||this.enact&&s){if(n)return null}else this.ready=!0,this.decay();return this.velocity}return null},Uh=function(t,e){return this.activeVelocity&&t()?(this.activeAcceleration&&this.move(e),this.velocity):null},Ph=xt({id:"Motion",properties:{orient:!0,acceleration:0,activeAcceleration:!0,activeVelocity:!0,maxMagnitude:1/0,controlState:"",instant:!1,instantState:"",instantSuccess:"",instantDecay:null,velocity:0,stopOnCollision:!0,drag:-1,friction:-1},initialize:function(t){this.acceleration||(this.activeAcceleration=!1),this.acceleration=Ht.setUp(this.acceleration),this.velocity=Ht.setUp(this.velocity),this.triggered=!1,this.ready=!0,"number"==typeof this.instantDecay?this.capMagnitude=this.velocity.magnitude()*this.instantDecay:this.capMagnitude=-1,function(t,e){const i=t.owner.state,s=e.controlState?Mh.bind(null,i,e.controlState):Sh,n=e.instantState?Mh.bind(null,i,e.instantState):Sh;t.instant||e.instantState?(t.instant=!0,t.update=Th.bind(t,n,s,e.instantSuccess)):t.update=Uh.bind(t,s)}(this,t),this.instant&&(this.enact=!1,this.instant=Ht.setUp(this.velocity),this.velocity.setXYZ(0,0,0)),this.orient&&(this.owner.triggerEvent("orient-vector",this.velocity),this.owner.triggerEvent("orient-vector",this.acceleration))},events:{"control-velocity":function(t){this.activeVelocity=t&&!1!==t.pressed},"stop-velocity":function(){this.activeVelocity=!1},"start-velocity":function(){this.activeVelocity=!0},"control-acceleration":function(t){this.activeAcceleration=t&&!1!==t.pressed},"stop-acceleration":function(){this.activeAcceleration=!1},"start-acceleration":function(){this.activeAcceleration=!0},"instant-motion":function(t){this.enact=t&&!1!==t.triggered},"instant-begin":function(){this.enact=!0},"instant-end":function(){this.enact=!1},"set-motion":function(t){t.acceleration&&this.acceleration.set(t.acceleration),t.velocity&&(this.velocity.set(t.velocity),"number"==typeof this.instantDecay?this.capMagnitude=this.velocity.magnitude()*this.instantDecay:this.capMagnitude=-1),"number"==typeof t.maxMagnitude&&(this.maxMagnitude=t.maxMagnitude)}},methods:{move:function(t){const e=Ht.setUp(this.acceleration).multiply(t);return this.velocity.add(e),e.recycle(),this.velocity.magnitude()>this.maxMagnitude&&this.velocity.normalize().multiply(this.maxMagnitude),this.velocity},decay:function(){this.capMagnitude>=0&&this.velocity.magnitude()>this.capMagnitude&&this.velocity.normalize().multiply(this.capMagnitude)},destroy:function(){this.orient&&(this.owner.triggerEvent("remove-vector",this.acceleration),this.owner.triggerEvent("remove-vector",this.velocity)),this.acceleration.recycle(),this.velocity.recycle(),this.instant&&this.instant.recycle()}}}),Oh=Ht.setUp(),Lh=function(t,e,i,s){return t&&e!==i?e<i?Math.min(e+t*s,i):Math.max(e-t*s,i):e},zh=function(t,e){const i=this.maxMagnitudeInterim=Lh(this.maxMagnitudeDelta,this.maxMagnitudeInterim,this.maxMagnitude,e);t.magnitude()>i&&t.normalize().multiply(i)},Bh=function(t,e){const i=this.maxMagnitude,s=this.maxMagnitudeDelta,n=this.maxMagnitudeInterim;n.up=Lh(s,n.up,i.up,e),n.right=Lh(s,n.right,i.right,e),n.down=Lh(s,n.down,i.down,e),n.left=Lh(s,n.left,i.left,e),t.x>0?t.x>n.right&&(t.x=n.right):t.x<0&&t.x<-n.left&&(t.x=-n.left),t.y>0?t.y>n.down&&(t.y=n.down):t.y<0&&t.y<-n.up&&(t.y=-n.up)},Ih=xt({id:"Mover",properties:{ground:[0,1]},publicProperties:{movers:[],gravity:0,jump:0,speed:0,drag:.01,friction:.06,maxMagnitude:1/0,maxMagnitudeDelta:0,reorientVelocities:!0},initialize:function(){const t=this.maxMagnitude,{state:e}=this;let i=1/0;Ht.assign(this.owner,"position","x","y","z"),Ht.assign(this.owner,"velocity","dx","dy","dz"),this.position=this.owner.position,this.velocity=this.owner.velocity,this.lastVelocity=Ht.setUp(this.velocity),this.collision=null,this.pause=!1,this.moversCopy=this.movers,this.movers=V.setUp(),this.velocityChanges=V.setUp(),this.velocityDirections=V.setUp(),this.ground=Ht.setUp(this.ground),this.state=e,e.set("grounded",!1),Object.defineProperty(this.owner,"maxMagnitude",{get:function(){return i},set:function(t){"number"==typeof t?(this.clamp=zh,i=t,this.maxMagnitudeDelta||(this.maxMagnitudeInterim=t)):(this.clamp=Bh,"number"==typeof i&&(i={up:i,right:i,down:i,left:i}),"number"==typeof t.up&&(i.up=t.up),"number"==typeof t.right&&(i.right=t.right),"number"==typeof t.down&&(i.down=t.down),"number"==typeof t.left&&(i.left=t.left),"number"==typeof this.maxMagnitudeInterim?this.maxMagnitudeDelta?this.maxMagnitudeInterim={up:this.maxMagnitudeInterim,right:this.maxMagnitudeInterim,down:this.maxMagnitudeInterim,left:this.maxMagnitudeInterim}:this.maxMagnitudeInterim={up:i.up,right:i.right,down:i.down,left:i.left}:this.maxMagnitudeDelta||(this.maxMagnitudeInterim.up=i.up,this.maxMagnitudeInterim.right=i.right,this.maxMagnitudeInterim.down=i.down,this.maxMagnitudeInterim.left=i.left))}.bind(this)}),this.maxMagnitudeInterim=0,this.maxMagnitude=t},events:{"component-added":function(t){"Motion"===t.type&&this.movers.push(t)},"component-removed":function(t){if("Motion"===t.type){let e=this.movers.indexOf(t);e>=0&&G(this.movers,e)}},load:function(){const t=this.moversCopy;delete this.moversCopy;for(let e=0;e<t.length;e++)this.addMover(t[e]);this.externalForces=this.addMover({velocity:[0,0,0],orient:!1}).velocity,this.speed&&(isNaN(this.speed)||(this.speed=[this.speed,0,0]),this.speed=this.addMover({velocity:this.speed,controlState:"moving"}).velocity),this.gravity&&(isNaN(this.gravity)||(this.gravity=[0,this.gravity,0]),this.gravity=this.addMover({acceleration:this.gravity,orient:!1,aliases:{gravitate:"control-acceleration"}}).acceleration),this.jump&&(isNaN(this.jump)||(this.jump=[0,this.jump,0]),this.jump=this.addMover({velocity:this.jump,instant:!0,controlState:"grounded",state:"jumping",instantSuccess:"just-jumped",instantDecay:.2,aliases:{jump:"instant-motion"}}).instant)},"handle-movement":function({delta:t}){const{movers:e,position:i,state:s,velocity:n}=this,o=Ht.setUp();let r=e.length;if(!s.get("paused")&&!this.paused){for(n.equals(this.lastVelocity,2)||this.externalForces.addVector(n).subtractVector(this.lastVelocity),n.setXYZ(0,0,0);r--;){const i=e[r].update(t);i&&(this.grounded?-1!==e[r].friction?i.multiply(1-e[r].friction):i.multiply(1-this.friction):-1!==e[r].drag?i.multiply(1-e[r].drag):i.multiply(1-this.drag),n.add(i))}this.clamp(n,t),this.lastVelocity.setVector(n),o.set(n).multiply(t),i.add(o),o.recycle(),s.set("grounded",this.grounded),this.grounded=!1}},"hit-solid":function({direction:t,entity:e}){const i=e?.velocity,s=this.velocityChanges,n=this.velocityDirections,o=s.length;let r=!0,a=0;if(t.dot(this.ground)>0&&(this.grounded=!0),a=this.velocity.scalarProjection(t),a>0){if(i){const e=Math.max(i.scalarProjection(t),0);a=e<a?e:0}else a=0;for(;o--;)if(a<s[o]&&n[o].dot(t)>0){s[o]=a,n[o].setVector(t),r=!1;break}r&&(s.push(a),n.push(Ht.setUp(t)))}},"handle-post-collision-logic":function(){const t=this.velocityChanges,e=t.length;if(e){const i=this.movers,s=this.velocityDirections,n=Oh,o=i.filter(({stopOnCollision:t})=>t);for(;e--;){let i=o.length;const r=s[e],a=t[e]/i;for(;i--;){const t=o[i];n.setVector(r).normalize().multiply(a-t.velocity.scalarProjection(r)),t.velocity.add(n)}r.recycle()}t.length=0,s.length=0,V.recycle(o)}},"set-mover":function(t){"number"==typeof t.maxMagnitudeDelta&&(this.maxMagnitudeDelta=t.maxMagnitudeDelta),t.maxMagnitude&&(this.maxMagnitude=t.maxMagnitude)},"pause-movement":function(){this.paused=!0},"unpause-movement":function(){this.paused=!1},"orientation-updated":function(t){this.reorientVelocities||this.lastVelocity.multiply(t)}},methods:{destroy:function(){const t=this.maxMagnitude;for(let t=this.movers.length-1;t>=0;t--)this.removeMover(this.movers[t]);V.recycle(this.movers),this.ground.recycle(),this.lastVelocity.recycle(),V.recycle(this.velocityChanges),V.recycle(this.velocityDirections),delete this.owner.maxMagnitude,this.owner.maxMagnitude=t,this.state=null}},publicMethods:{addMover:function(t){return this.owner.addComponent(new platypus.components.Motion(this.owner,t))},removeMover:function(t){this.owner.removeComponent(t)}}}),Dh=xt({id:"Node",properties:{neighborProperties:null},publicProperties:{neighbors:null,nodeId:"",x:0,y:0,z:0},initialize:function(){const t=this.owner;if(this.nodeId=this.nodeId||t.id||String(Math.random()),"string"!=typeof this.nodeId&&this.nodeId.length&&(this.nodeId=this.nodeId.join("|")),t.nodeId=this.nodeId,t.isNode=!0,this.map=t.map=t.map||t.parent||null,this.contains=t.contains=V.setUp(),this.edgesContain=t.edgesContain=V.setUp(),Ht.assign(t,"position","x","y","z"),this.neighbors||(this.neighbors={}),this.neighborProperties){const e=this.neighborProperties;for(let i=0;i<e.length;i++){const s=e[i],n=t[s];n&&(this.neighbors[s]=n),Object.defineProperty(t,s,{get:()=>this.neighbors[s],set:t=>{if(t!==this.neighbors[s]){this.neighbors[s]=t;for(let t=0;t<this.contains.length;t++)this.contains[t].triggerEvent("set-directions")}}})}}},events:{"add-neighbors":function(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];this.neighbors[s]=t[s]}for(let t=0;t<this.contains.length;t++)this.contains[t].triggerEvent("set-directions")},"remove-neighbor":function(t){const e=t.nodeId??t,i=Object.keys(this.neighbors);for(let t=0;t<i.length;t++){const s=i[t];s!==e&&s.nodeId!==e||delete this.neighbors[t]}}},methods:{toJSON(t){const e=this.neighborProperties;return e.forEach(e=>{const i=this.neighbors[e];i&&(t[e]=i.id)}),t.nodeId=this.nodeId,{type:"Node",neighborProperties:e}},destroy(){V.recycle(this.contains),this.contains=this.owner.contains=null,V.recycle(this.edgesContain),this.edgesContain=this.owner.edgesContain=null}},publicMethods:{joinNode(t,e,i=!1){this.neighbors[e]=t;for(let t=0;t<this.contains.length;t++)this.contains[t].triggerEvent("set-directions");i&&t.joinNode(this.owner,"boolean"==typeof i?e:i)},getNode:function(t){const e=this.neighbors[t];if(!this.map&&this.owner.map&&(this.map=this.owner.map),e){const i=e.destroyed?e.id:e;if(i.isNode)return i;if("string"==typeof i){const e=this.map.getNode(i);if(e)return this.neighbors[t]=e,e}else if(i.length){const e=this.map.getNode(i.join("|"));if(e)return this.neighbors[t]=e,e}}return null},addToNode:function(t){for(let e=0;e<this.contains.length;e++)if(this.contains[e]===t)return!1;return this.contains.push(t),t},removeFromNode:function(t){for(let e=0;e<this.contains.length;e++)if(this.contains[e]===t)return G(this.contains,e);return!1},addToEdge:function(t){for(let e=0;e<this.edgesContain.length;e++)if(this.edgesContain[e]===t)return!1;return this.edgesContain.push(t),t},removeFromEdge:function(t){for(let e=0;e<this.edgesContain.length;e++)if(this.edgesContain[e]===t)return G(this.edgesContain,e);return!1}}}),Xh=function(t,e){t.id?"string"==typeof t.id?this.id=t.id:Array.isArray(t.id)?this.id=t.id.join("|"):this.id=String(Math.random()):this.id=String(Math.random()),this.isNode=!0,this.map=e,this.contains=V.setUp(),this.type=t.type||"",this.position||Ht.assign(this,"position","x","y","z"),this.x=t.x||0,this.y=t.y||0,this.z=t.z||0,this.neighbors=t.neighbors||{}},Rh=Xh.prototype;Rh.getNode=function(t){const e=this.neighbors[t];if(e){if(e.isNode)return e;if("string"==typeof e){const i=this.map.getNode(e);if(i)return this.neighbors[t]=i,i}else if(Array.isArray(e)){const i=this.map.getNode(e.join("|"));if(i)return this.neighbors[t]=i,i}return null}return null},Rh.addToNode=function(t){for(let e=0;e<this.contains.length;e++)if(this.contains[e]===t)return!1;return this.contains.push(t),t},Rh.removeFromNode=function(t){for(let e=0;e<this.contains.length;e++)if(this.contains[e]===t)return G(this.contains,e);return!1},N.add(Xh,"Node",Xh,function(){V.recycle(this.contains)},!0);const jh=xt({id:"NodeMap",publicProperties:{map:[]},initialize:function(){const t=this.map;this.map=V.setUp(),this.nodes={},this.residentsAwaitingNode=V.setUp();for(let e=0;e<t.length;e++)this.addNode(Xh.setUp(t[e],this))},events:{"add-node":function(t){let e=null;t.isNode?(e=t,t.map=this):e=Xh.setUp(t,this),this.addNode(e);for(let t=this.residentsAwaitingNode.length-1;t>=0;t--){const i=this.residentsAwaitingNode[t];e.id===i.nodeId&&(G(this.residentsAwaitingNode,t),i.node=this.getNode(i.nodeId))}},"child-entity-added":function(t){t.isNode?this.owner.triggerEvent("add-node",t):t.nodeId&&(t.node=this.getNode(t.nodeId),t.node||this.residentsAwaitingNode.push(t))},"child-entity-removed":function(t){t.isNode&&this.owner.triggerEvent("remove-node",t)},"remove-node":function(t){this.removeNode(t)}},methods:{addNode:function(t){this.map.push(t),this.nodes[t.id]=t},removeNode:function(t){const e=this.map.indexOf(t);e>=0?(this.map.splice(e,1),delete this.nodes[t.id]):platypus.debug.warn(`NodeMap: "${t.id}" is not mapped, so it cannot be removed.`)},destroy:function(){for(let t=0;t<this.map.length;t++)this.map[t]instanceof kt||this.map[t].recycle();V.recycle(this.map),V.recycle(this.residentsAwaitingNode)}},publicMethods:{getNode:function(...t){let e=t.join("|");if(1===t.length){if(t[0].isNode)return t[0].destroyed?this.nodes[t[0].id]:t[0];Array.isArray(t[0])&&(e=t[0].join("|"))}return this.nodes[e]??null},getClosestNode:function(t,e,i){const s=Ht.setUp(t),n=Ht.setUp(),o=e||this.map;let r=null,a=1/0;for(let t=0;t<o.length;t++){const e=n.setVector(s).subtractVector(o[t].position).magnitude();if(e<a){if(i?.indexOf(o[t])>=0)break;a=e,r=o[t]}}return s.recycle(),n.recycle(),r}}}),Yh=function(t,e,i){return function(){const s=e.getNode(t);return!!this.isPassable(s)&&(this.destinationNodes.length=0,this.destinationNodes.push(s),this.node?this.onEdge(s):this.distance=0,this.progress=0,this.setState("going-"+i),!0)}},Nh=function(t,e){const i=e.x-t.x,s=e.y-t.y,n=e.z-t.z;return Math.sqrt(i*i+s*s+n*n)},Wh=function(t,e,i,s){if(t.rotation&&e.rotation)return((t.rotation+180)%360*(1-s)+(e.rotation+180)%360*s+180)%360;{const s=e.x-t.x,n=e.y-t.y;let o=0;return i?(o=Math.acos(s/i),n<0&&(o=2*Math.PI-o),180*o/Math.PI):o}},Hh=function(t,e,i,s){return e*(1-t)+i*t+s},Vh=xt({id:"NodeResident",properties:{algorithm:Nh,node:null,offset:{},snapToNodes:!1,updateOrientation:!1},publicProperties:{friendlyNodes:null,friendlyEntities:null,nodeId:"",speed:0},initialize:function(){const t=this.offset,e=this.node;this.neighbors={},this.distance=0,this.progress=0,this.offset={x:t.x||0,y:t.y||0,z:t.z||0},this.destinationNodes=V.setUp(),this.state=this.owner.state,this.state.set("moving",!1),this.state.set("on-node",!1),this.currentState="",Object.defineProperty(this.owner,"node",{get:()=>this.node,set:t=>{t?this.getOnNode(t):this.getOffNode()}}),this.owner.node=e},events:{"set-algorithm":function(t){this.algorithm=t||Nh},"handle-logic":function(t){let e=0,i=0;if(!this.owner.node){const t=V.setUp(this.owner.x,this.owner.y);this.owner.node=this.owner.parent.getClosestNode(t),V.recycle(t),this.owner.triggerEvent("in-location",this.owner)}if(this.followEntity){const t=this.followEntity.node||this.followEntity;t&&t.isNode&&t!==this.node?(this.lag=0,this.state.set("moving",this.gotoNode()),this.followDistance&&(i=this.lag)):this.followEntity=null}else i=this.speed*t.delta;if(this.blocked&&(this.blocked=!1,this.goingToNode&&this.owner.triggerEvent("goto-closest-node",this.goingToNode)),this.destinationNodes.length){if(this.state.set("moving",0!==this.speed),this.node)this.onEdge(this.destinationNodes[0]);else if(!this.lastNode&&(this.owner.node=this.destinationNodes[0],this.destinationNodes.shift(),!this.destinationNodes.length))return void this.state.set("moving",!1);if(this.snapToNodes){for(let t=0;t<this.destinationNodes.length;t++)this.owner.node=this.destinationNodes[t];this.destinationNodes.length=0}else for(;this.destinationNodes.length&&i;)if(this.progress+i>=this.distance){const t=this.destinationNodes[0];i-=this.distance-this.progress,this.progress=0,this.destinationNodes.shift(),this.owner.node=t,this.destinationNodes.length&&i&&this.onEdge(this.destinationNodes[0])}else this.progress+=i,e=this.progress/this.distance,this.owner.x=Hh(e,this.lastNode.x,this.destinationNodes[0].x,this.offset.x),this.owner.y=Hh(e,this.lastNode.y,this.destinationNodes[0].y,this.offset.y),this.owner.z=Hh(e,this.lastNode.z,this.destinationNodes[0].z,this.offset.z),this.updateOrientation&&(this.owner.rotation=Wh(this.lastNode,this.destinationNodes[0],this.distance,e)),i=0}else this.state.set("moving",!1)},"goto-node":function(t){this.gotoNode(t)},follow:function(t){t.entity?(this.followDistance=t.distance,this.followEntity=t.entity):(this.followDistance=0,this.followEntity=t)},"goto-closest-node":function(){const t=(t,e)=>e.indexOf(t)>=0,e=(t,e)=>t.type===e,i=(t,e)=>t.type===e.type;return function(s){const n=this.node??this.lastNode,o="string"==typeof s?e:"string"==typeof s.type?i:t,r=s.steps??0;if(this.goingToNode=s,n&&s&&!o(n,s)){const t=V.setUp(),e=this.traverseNode({depth:20,origin:n,position:n,test:o,destination:s,nodes:t,shortestPath:1/0,distance:0,found:!1,algorithm:this.algorithm,blocked:!1});e.distance-=this.progress,e.found?this.followEntity&&this.followDistance?e.distance+(this.followEntity.progress||0)>this.followDistance?(this.lag=e.distance+(this.followEntity.progress||0)-this.followDistance,this.setPath(e,r)):this.lag=0:this.setPath(e,r):e.blocked&&(this.blocked=!0),V.recycle(t)}}}(),"set-directions":function(){const t=this.node,e=t.neighbors,i=Object.keys(e),{length:s}=i;this.owner.triggerEvent("remove-directions");for(let n=0;n<s;n++){const s=i[n],o=e[s],r=t.map.getNode(o),a=this.neighbors[s]=Yh(o,t.map,n);if(this.addEventListener(s,a),r){const t=r.contains;for(let e=0;e<t.length;e++)t[e].triggerEvent("next-to-"+this.owner.type,this.owner),this.owner.triggerEvent("next-to-"+t[e].type,t[e])}}},"remove-directions":function(){const t=this.neighbors,e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.removeEventListener(i,t[i]),delete t[i]}}},methods:{gotoNode(t){const e=this.node??this.lastNode;let i=!1;if(!t&&this.followEntity&&(t=this.followEntity.node??this.followEntity.lastNode??this.followEntity),e&&t&&this.node!==t){const s=V.setUp(),n=this.traverseNode({depth:20,origin:e,position:e,test:(t,e)=>t===e,destination:t,nodes:s,shortestPath:1/0,distance:0,found:!1,algorithm:this.algorithm,blocked:!1});n.distance-=this.progress,n.found?this.followEntity&&this.followDistance?n.distance+(this.followEntity.progress||0)>this.followDistance?(this.lag=n.distance+(this.followEntity.progress||0)-this.followDistance,this.setPath(n),i=!0):this.lag=0:(this.setPath(n),i=!0):n.blocked&&(this.blocked=!0),V.recycle(s)}return i},getOnNode(t){const e=t.contains;this.getOffNode(),this.node=t,this.node?.removeFromEdge&&this.node.removeFromEdge(this.owner),this.lastNode?.removeFromEdge&&this.lastNode.removeFromEdge(this.owner),this.node.addToNode(this.owner),this.setState("on-node"),this.owner.x=this.node.x+this.offset.x,this.owner.y=this.node.y+this.offset.y,this.owner.z=this.node.z+this.offset.z,this.updateOrientation&&this.node.rotation&&(this.owner.rotation=this.node.rotation),this.owner.triggerEvent("set-directions"),this.friendlyNodes&&this.friendlyNodes[t.type]&&this.owner.trigger(this.friendlyNodes[t.type],t);for(let t=0;t<e.length;t++)this.owner!==e[t]&&(e[t].triggerEvent("with-"+this.owner.type,this.owner),this.owner.triggerEvent("with-"+e[t].type,e[t]));this.owner.triggerEvent("on-node",t)},getOffNode:function(){this.node&&(this.node.removeFromNode(this.owner),this.owner.triggerEvent("left-node",this.node),this.owner.triggerEvent("remove-directions")),this.lastNode=this.node,this.node=null},isPassable:function(t){return t&&this.node!==t&&(!this.friendlyNodes||void 0!==this.friendlyNodes[t.type])&&(!t.contains.length||function(t,e){if(null!==e){let i=!1;for(let s=0;s<t.length;s++){for(let n=0;n<e.length;n++)t[s].type===e[n]&&(i=!0);if(!i)return!1;i=!1}}return!0}(t.contains,this.friendlyEntities))},traverseNode:function(t){const{position:e,test:i}=t;if(0===t.depth||t.distance>t.shortestPath)return t;if(i(e,t.destination))return t.found=!0,t.shortestPath=t.distance,t;if(t.nodes.includes(e,1))return t;{const s=t.algorithm||Nh,n=e.map,o=e.neighbors,r=Object.keys(o),{length:a}=r,h={shortestPath:1/0,found:!1,blocked:!1};let l=!0,c=!1;for(let d=0;d<a;d++){const a=r[d],u=n.getNode(o[a]);if(c=!0,this.isPassable(u)){const n=[...t.nodes,u],o=this.traverseNode({depth:t.depth-1,origin:t.origin,position:u,destination:t.destination,test:i,algorithm:s,nodes:n,shortestPath:t.shortestPath,distance:t.distance+s(e,u),gateway:t.gateway||a,found:!1,blocked:!1});o.found&&h.shortestPath>o.shortestPath&&(h=o),l=!1}}return h.blocked=c&&l,h}},setPath:function(t,e){t.nodes[0]===this.node&&t.nodes.shift(),V.recycle(this.destinationNodes),this.destinationNodes=Z(t.nodes),e&&(this.destinationNodes.length=Math.min(e,this.destinationNodes.length))},setState:function(t){"on-node"===t?this.state.set("on-node",!0):(this.state.set("on-node",!1),this.currentState&&this.state.set(this.currentState,!1),this.currentState=t,this.state.set(t,!0))},onEdge:function(t){this.distance=Nh(this.node,t),this.updateOrientation&&(this.owner.rotation=Wh(this.node,t,this.distance,this.progress/this.distance)),this.node.addToEdge&&this.node.addToEdge(this.owner),t.addToEdge&&t.addToEdge(this.owner),this.owner.node=null},destroy:function(){V.recycle(this.destinationNodes),this.destinationNodes=null,this.state=null}}}),Fh=Ht.setUp(0,0,1),Zh=Ht.setUp(1,0,0),Gh={identity:[[1,0,0],[0,1,0],[0,0,1]],horizontal:[[-1,0,0],[0,1,0],[0,0,-1]],vertical:[[1,0,0],[0,-1,0],[0,0,-1]],diagonal:[[0,1,0],[1,0,0],[0,0,-1]],"diagonal-inverse":[[0,-1,0],[-1,0,0],[0,0,-1]],"rotate-90":[[0,-1,0],[1,0,0],[0,0,1]],"rotate-180":[[-1,0,0],[0,-1,0],[0,0,1]],"rotate-270":[[0,1,0],[-1,0,0],[0,0,1]]},qh=function(){const t=function(t,e,i){let s=0;for(let n=0;n<t.length;n++)s+=t[n]*i[n][e];return s};return function(e,i,s){const n=V.setUp();for(let s=0;s<e.length;s++)for(let o=0;o<e[0].length;o++)n.push(t(e[s],o,i));for(let t=0;t<e.length;t++)for(let i=0;i<e[0].length;i++)s[t][i]=n.shift();V.recycle(n)}}(),$h=function(t){for(let e=0;e<3;e++)for(let i=0;i<3;i++)t[e][i]=e===i?1:0;return t},Jh=xt({id:"Orientation",publicProperties:{scaleX:1,scaleY:1,rotation:0,orientation:0,orientationMatrix:null},initialize(){this.loadedOrientationMatrix=this.orientationMatrix,this.matrix=V.setUp(V.setUp(1,0,0),V.setUp(0,1,0),V.setUp(0,0,1)),this.matrixTween=V.setUp(V.setUp(1,0,0),V.setUp(0,1,0),V.setUp(0,0,1)),this.relocationMessage=H.setUp("position",null),this.vectors=V.setUp(),this.inverses=V.setUp(),this.tweens=V.setUp(),this.orientationVector=function(t,e){const i=Ht.setUp(1,0,0),s=t.owner,n=V.setUp(V.setUp(1,0,0),V.setUp(0,1,0),V.setUp(0,0,1));return Object.defineProperty(s,"orientationMatrix",{get:function(){return qh(t.matrixTween,t.matrix,$h(n)),n},enumerable:!0}),delete s.orientation,Object.defineProperty(s,"orientation",{get:function(){return i.signedAngleTo(Zh,Fh)},set:function(t){i.setVector(Zh).rotate(t)},enumerable:!0}),Object.defineProperty(s,"rotation",{get:function(){return s.orientation/Math.PI*180},set:function(t){s.orientation=t*Math.PI/180},enumerable:!0}),e&&("number"!=typeof e?i.set(e):i.rotate(e)),i}(this,this.orientation),this.owner.triggerEvent("orient-vector",this.orientationVector),this.owner.state.set("reorienting",!1)},events:{load:function(){this.loadedOrientationMatrix?this.transform(this.loadedOrientationMatrix):(this.scaleX&&this.scaleX<0&&(this.scaleX=-this.scaleX,this.transform("horizontal")),this.scaleY&&this.scaleY<0&&(this.scaleY=-this.scaleY,this.transform("vertical")),this.rotation&&((this.rotation+270)%360==0?(this.rotation=0,this.transform("rotate-90")):(this.rotation+180)%360==0?(this.rotation=0,this.transform("rotate-180")):(this.rotation+90)%360==0&&(this.rotation=0,this.transform("rotate-270")))),delete this.loadedOrientationMatrix},"handle-logic":function({delta:t}){const e=this.owner.state;let i=this.tweens.length;if(i){const s=V.setUp();for(e.set("reorienting",!0),$h(this.matrixTween);i--;)this.updateTween(this.tweens[i],t)&&s.push(G(this.tweens,i));for(i=this.vectors.length;i--;)this.updateVector(this.vectors[i],this.inverses[i]);for(i=s.length;i--;){const t=s[i];if(this.transform(t.endMatrix),t.anchor){const e=this.relocationMessage;t.offset.multiply(t.endMatrix).addVector(t.anchor),e.position=t.offset,this.owner.triggerEvent("relocate-entity",e),t.recycleOffset&&t.offset.recycle()}t.onFinished(t.endMatrix),t.recycle()}V.recycle(s)}else e.get("reorienting")&&($h(this.matrixTween),e.set("reorienting",!1))},"complete-tweens":function(){for(let t=0;t<this.tweens.length;t++)this.tweens[t].time=this.tweens[t].endTime},"drop-tweens":function(){let t=this.tweens.length;for(;t--;)this.tweens[t].offset&&this.tweens[t].offset.recycle();for(this.tweens.length=0,t=this.vectors.length;t--;)this.updateVector(this.vectors[t],this.inverses[t])},"orient-vector":function(t){const e=t.aligned||!1;t.vector&&(t=t.vector),-1===this.vectors.indexOf(t)&&(e||t.multiply(this.matrix),this.vectors.push(t),this.inverses.push(Ht.setUp()))},"remove-vector":function(t){const e=this.vectors.indexOf(t);e>=0&&(G(this.vectors,e),G(this.inverses,e).recycle())},"tween-transform":function(t){this.tweenTransform(t)},transform:function(t){this.transform(t)},"prepend-transform":function(t){this.transform(t)},"append-transform":function(t){this.transform(t,!0)},"replace-transform":function(t){Array.isArray(t)?this.replace(t):"string"==typeof t&&Gh[t]&&this.replace(Gh[t])}},methods:{transform:function(t,e){Array.isArray(t)?this.multiply(t,e):"string"==typeof t&&Gh[t]&&this.multiply(Gh[t],e)},multiply:function(t,e){e?qh(this.matrix,t,this.matrix):qh(t,this.matrix,this.matrix);for(let e=0;e<this.vectors.length;e++)this.vectors[e].multiply(t),this.inverses[e].multiply(t);this.owner.triggerEvent("orientation-updated",t)},replace:function(){const t=function(t,e,i,s){return t*s-e*i};return function(e){const i=function(e){const i=V.setUp(V.setUp(),V.setUp(),V.setUp()),s=1/function(t){let e=0;for(let i=0;i<3;i++)e+=t[i][0]*t[(i+1)%3][1]*t[(i+2)%3][2],e-=t[i][2]*t[(i+1)%3][1]*t[(i+2)%3][0];return e}(e);return i[0].push(t(e[1][1],e[1][2],e[2][1],e[2][2])*s),i[0].push(t(e[0][2],e[0][1],e[2][2],e[2][1])*s),i[0].push(t(e[0][1],e[0][2],e[1][1],e[1][2])*s),i[1].push(t(e[1][2],e[1][0],e[2][2],e[2][0])*s),i[1].push(t(e[0][0],e[0][2],e[2][0],e[2][2])*s),i[1].push(t(e[0][2],e[0][0],e[1][2],e[1][0])*s),i[2].push(t(e[1][0],e[1][1],e[2][0],e[2][1])*s),i[2].push(t(e[0][1],e[0][0],e[2][1],e[2][0])*s),i[2].push(t(e[0][0],e[0][1],e[1][0],e[1][1])*s),i}(this.matrix);this.multiply(i),this.multiply(e),V.recycle(i,2)}}(),updateTween:function(){const t=function(t,e,i){return t*(1-i)+e*i};return function(e,i){const s=e.endMatrix;let n=0,o=1,r=0,a=0,h=1,l=1,c=null,d=0;if(e.beforeTick(e.time)&&(e.time+=i),e.time>=e.endTime)return!0;if(n=e.tween(e.time/e.endTime),e.angle?(d=n*e.angle,o=h=Math.cos(d),r=Math.sin(d),a=-r):(o=t(o,s[0][0],n),r=t(r,s[1][0],n),a=t(a,s[0][1],n),h=t(h,s[1][1],n),l=t(l,s[2][2],n)),c=V.setUp(V.setUp(o,a,0),V.setUp(r,h,0),V.setUp(0,0,l)),qh(this.matrixTween,c,this.matrixTween),e.anchor){const t=Ht.setUp(e.offset).multiply(1-n),i=Ht.setUp(e.offset).multiply(n);this.owner.triggerEvent("relocate-entity",{position:t.add(i).multiply(c).addVector(e.anchor)}),t.recycle(),i.recycle()}return e.afterTick(n,c),V.recycle(c,2),!1}}(),updateVector:function(t,e){e.setVector(t.add(e)),t.multiply(this.matrixTween),e.subtractVector(t)},destroy:function(){V.recycle(this.vectors),this.vectors=null,V.recycle(this.inverses),this.inverses=null,V.recycle(this.tweens),this.tweens=null,this.orientationVector.recycle(),this.orientationVector=null,V.recycle(this.orientationMatrix,2),V.recycle(this.matrix,2),this.matrix=null,V.recycle(this.matrixTween,2),this.matrixTween=null,this.relocationMessage.recycle(),this.relocationMessage=null}},publicMethods:{tweenTransform:function(){const t=function(){},e=function(){return!0},i=function(t){return t};return function(s){const n=s.matrix??Gh[s.transform],o=H.setUp("transform",s.transform,"anchor",s.anchor,"endTime",s.time||0,"time",0,"tween",s.tween||i,"onFinished",s.onFinished||t,"beforeTick",s.beforeTick||e,"afterTick",s.afterTick||t);let r=s.angle||0;if(o.endMatrix=n,!r&&0===s.transform.indexOf("rotate"))switch(s.transform){case"rotate-90":r=Math.PI/2;break;case"rotate-180":r=Math.PI;break;case"rotate-270":r=-Math.PI/2;break;default:{const t=pt(s.transform,"-");r=t[1]/180*Math.PI,V.recycle(t);break}}o.angle=r,s.anchor&&(o.offset=s.offset,o.offset||(o.offset=this.owner.position.copy().subtractVector(s.anchor,2),o.recycleOffset=!0)),this.tweens.push(o)}}()}}),Qh=function(){const t=function(t){let e=0;if(t)for(this.contents=[],e=0;e<t.length;e++)this.contents.push(t[e]);else this.contents=[];this.availableIndexes=[],this.refill()},e=t.prototype;return e.refill=function(){let t=0;for(t=0;t<this.contents.length;t++)this.availableIndexes.push(t)},e.add=function(t){this.contents.push(t),this.availableIndexes.push(this.contents.length-1)},e.remove=function(t,e){let i=-1,s=-1;do{if(i=this.contents.indexOf(t),-1!==i){this.contents.splice(i,1),s=this.availableIndexes.indexOf(i),this.availableIndexes.splice(s,1);for(let t=0;t<this.availableIndexes;t++)this.availableIndexes[t]>i&&(this.availableIndexes[t]-=1)}}while(-1!==i&&e)},e.get=function(){let t=0;return 0===this.availableIndexes.length&&this.refill(),t=this.availableIndexes.splice(Math.floor(Math.random()*this.availableIndexes.length),1)[0],this.contents[t]},e.getMultiple=function(t){const e=[];let i=0;for(i=0;i<t;i++)e.push(this.get());return e},N.add(t,"RandomSet",t,null,!0),t}(),Kh=function(t){return function(e,i){this.owner.trigger(t.get(),e,i)}},tl=function(t){return function(e,i){this.owner.trigger(t[Math.floor(Math.random()*t.length)],e,i)}},el=xt({id:"RandomEvents",properties:{events:null,trueRandom:!1},initialize:function(){const t=this.events;if(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.trueRandom?this.addEventListener(i,tl(t[i])):this.addEventListener(i,Kh(Qh.setUp(t[i])))}}}}),il=xt({id:"RelativePosition",properties:{cameraSizes:null},publicProperties:{bottom:null,left:null,right:null,top:null,scaleX:1,scaleY:1,x:0,y:0},initialize:function(){this.aabb=Ci.setUp(),this.lastBottom=null,this.lastLeft=null,this.lastRight=null,this.lastTop=null,this.cameraSizesIndex=-1},events:{"handle-logic":function(){const{bottom:t,left:e,right:i,top:s}=this;this.lastBottom===t&&this.lastLeft===e&&this.lastRight===i&&this.lastTop===s||(this.updatePosition(this.aabb),this.lastBottom=t,this.lastLeft=e,this.lastRight=i,this.lastTop=s)},"camera-update":function(t){this.aabb.set(t.viewport),this.cameraSizes&&this.checkCamera(this.aabb),this.updatePosition(this.aabb)}},methods:{checkCamera:function(t){const e=this.cameraSizes,i=t.width/t.height;for(let t=0;t<e.length;t++)if(i>e[t].minRatio){t!==this.cameraSizesIndex&&(this.updateProperties(e[t]),this.cameraSizesIndex=t);break}},updateProperties:function(t){this.right="number"==typeof t.right?t.right:null,this.left="number"==typeof t.left?t.left:null,this.top="number"==typeof t.top?t.top:null,this.bottom="number"==typeof t.bottom?t.bottom:null,"number"==typeof t.x&&(this.x=t.x),"number"==typeof t.y&&(this.y=t.y),"number"==typeof t.scaleX&&(this.scaleX=t.scaleX),"number"==typeof t.scaleY&&(this.scaleY=t.scaleY)},updatePosition:function(t){const{bottom:e,left:i,owner:s,right:n,top:o}=this;"number"==typeof i?s.x=t.left+i:"number"==typeof n&&(s.x=t.right-n),"number"==typeof o?s.y=t.top+o:"number"==typeof e&&(s.y=t.bottom-e)},destroy:function(){this.aabb.recycle(),this.aabb=null}}}),sl=xt({id:"RelayFamily",properties:{events:null},initialize:function(){const t=this.events;if(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,this.broadcast.bind(this,null,t[i]))}}this.owner.familyLinks=V.setUp(this.owner)},events:{"link-family":function(t){const e=this.owner.familyLinks,i=F(F(V.setUp(),t),e);for(let t=0;t<i.length;t++)i[t].familyLinks=i;this.broadcast(t,"family-members-added",e),this.broadcast(e,"family-members-added",t),V.recycle(e)},"entity-created":function(t){t.triggerEvent("link-family",this.owner.familyLinks)||(t.addComponent(new platypus.components.RelayFamily(t,{})),t.triggerEvent("link-family",this.owner.familyLinks))}},methods:{broadcast:function(t,...e){const i=t||this.owner.familyLinks;for(let t=0;t<i.length;t++)i[t].trigger.apply(i[t],e)},destroy:function(){const{familyLinks:t}=this.owner,e=t.indexOf(this.owner);e>=0&&G(t,e),this.broadcast(t,"family-member-removed",this.owner),this.events=null}}}),nl=function(){platypus.game.triggerOnChildren.apply(platypus.game,arguments)},ol=xt({id:"RelayGame",properties:{events:null},initialize:function(){const t=this.events;if(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,nl.bind(this,t[i]))}}}}),rl={},al=function(...t){const e=this.channel;for(let i=0;i<e.length;i++)e[i].trigger(...t)},hl=xt({id:"RelayLinker",properties:{linkId:"linked",events:null},initialize:function(){const{events:t,linkId:e}=this;if(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,al.bind(this,t[i]))}}this.owner.linkId||(this.owner.linkId=e),this.channel=rl[e]=rl[e]??[]},events:{load:function(){this.channel.push(this.owner)}},methods:{destroy:function(){const t=this.channel.indexOf(this.owner);t>=0?G(this.channel,t):platypus.debug.warn("RelayLinker: Component destroyed, but entity not found on channel."),this.events=null}}}),ll=function(){const{parent:t}=this.owner;t&&t.trigger.apply(t,arguments)},cl=xt({id:"RelayParent",properties:{events:null},initialize:function(){const t=this.events;if(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,ll.bind(this,t[i]))}}}}),dl=function(){const{owner:t}=this;t.trigger.apply(t,arguments)},ul=xt({id:"RelaySelf",properties:{events:null},initialize:function(){const t=this.events;if(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,dl.bind(this,t[i]))}}}}),pl=new h,gl=function(t,e){return t*t+e*e},fl=function(t,e){const i=e.indexOf("("),s=e.substring(0,i);let n=e.substring(i+1,e.indexOf(")"));if(n.length){let e=0,i=!1;for("["===n[0]&&(n=n.substring(1,n.length-1),i=!0),n=pt(n,","),e=n.length;e--;)n[e]=+n[e];i?t[s](n):(t[s].apply(t,n),V.recycle(n))}else t[s]()},yl=xt({id:"RenderContainer",properties:{mask:null,interactive:!1,interpolation:0,rotate:"rotation",mirror:!1,flip:!1,visible:!0,cache:!1,cullable:!0,ignoreOpacity:!1,localMask:!1},publicProperties:{dragMode:!1,renderParent:!0,rotation:0,scaleX:1,scaleY:1,skewX:0,skewY:0,tint:null,x:0,y:0,z:0},initialize:function(){const{owner:t}=this,e=this.container=t.container=new n,i=this.tint;if(e.sortableChildren=!0,e.cullable=this.cullable,e.label=t.id,!0===this.rotate&&(this.rotate="rotation",platypus.debug.warn('RenderContainer: Boolean values for the "rotate" property has been deprecated. Use "rotation", "orientationMatrix", or "" to specify the source of rotation for the render container. This property defaults to "rotation".')),this.parentContainer=null,this.wasVisible=this.visible,this.lastX=t.x,this.lastY=t.y,this.interpolation){const t=()=>{this.updateSprite(!0,this.owner.x,this.owner.y)},e=()=>{const e=this.owner,h=gl(this.lastX-e.x,this.lastY-e.y);if(!s||h<1.5)s=0,a=t,a();else{const t=Math.min(s/i,n/h),a=1-t;s=Math.max(0,s-5),o=this.lastX,r=this.lastY,n=h,this.updateSprite(!0,e.x*a+o*t,e.y*a+r*t)}},i=this.interpolation;let s=0,n=0,o=0,r=0,a=t;this.addEventListener("handle-render",function(t){t.tick.timeShift?(o=this.lastX,r=this.lastY,n=gl(this.lastX-this.owner.x,this.lastY-this.owner.y),s=n>1.5?i:0,a=e):a()})}else this.addEventListener("handle-render",function(){this.updateSprite(!0,this.owner.x,this.owner.y)});if(this.interpolate=H.setUp("x",0,"y",0),this.interpolationTime=0,Object.defineProperty(t,"tint",{get:function(){return e.tint}.bind(this),set:function(t){e.tint=t}.bind(this)}),null!==i&&(this.tint=i),this.interactive){const i=H.setUp("container",e,"hitArea",this.interactive.hitArea,"hover",this.interactive.hover);t.addComponent(new li(t,i)),i.recycle()}this.cache&&(this.updateSprite(!1,t.x,t.y),this.owner.cacheRender=this.container),this.mask&&this.localMask&&this.setMask(this.mask),this.renderParent&&this.addToParentContainer(this.renderParent)},events:{cache:function(){const t=this.owner;this.updateSprite(!1,t.x,t.y),t.cacheRender=this.container,this.cache=!0,t.parent.triggerEventOnChildren?t.parent.triggerEventOnChildren("cache-sprite",t):platypus.debug.warn("Unable to cache sprite for "+t.type)},"handle-render-load":function(){this.owner.triggerEvent("input-on")},"hide-sprite":function(){this.visible=!1},"show-sprite":function(){this.visible=!0},"set-mask":function(t){this.setMask(t)}},methods:{updateSprite:function(t,e,i){const{container:s,dragMode:n,owner:o,scaleX:r,scaleY:a,skewX:h,skewY:l,visible:c}=this,d=pl,u="rotation"===this.rotate&&this.rotation||0;let p=1,g=1;if(s.zIndex!==o.z&&(s.zIndex=o.z),this.ignoreOpacity||!o.opacity&&0!==o.opacity||(s.alpha=o.opacity),this.mirror||this.flip){const t=this.rotation%360;this.mirror&&t>90&&t<270&&(p=-1),this.flip&&t<180&&(g=-1)}if("orientationMatrix"===this.rotate){const t=this.owner.orientationMatrix;d.a=t[0][0],d.b=t[1][0],d.tx=e+t[0][2],d.c=t[0][1],d.d=t[1][1],d.ty=i+t[1][2],s.transform.setFromMatrix(d)}else s.updateTransform({x:e,y:i,scaleX:r*p,scaleY:a*g,rotation:u?u/180*Math.PI:0,skewX:h,skewY:l});this.lastX=e,this.lastY=i,this.wasVisible=c,s.visible=c||n},setMask:function(t){let e=null;this.mask&&(this.localMask?this.container.removeChild(this.mask):this.parentContainer&&this.parentContainer.removeChild(this.mask)),t?(t.isMask||t instanceof a?e=t:(e=new a,"string"==typeof t?function(t,e){const i=pt(e,".");for(let e=0;e<i.length;e++)fl(t,i[e]);V.recycle(i)}(e,t):t.radius?e.circle(t.x||0,t.y||0,t.radius):t instanceof Ci?e.rect(t.left,t.top,t.width,t.height):t.width&&t.height&&e.rect(t.x||0,t.y||0,t.width,t.height),e.fill(0,1)),e.isMask=!0,this.mask=this.container.mask=e,this.mask.z=0,this.localMask?this.container.addChild(this.mask):this.parentContainer&&this.parentContainer.addChild(this.mask)):this.mask=this.container.mask=null},destroy:function(){this.parentContainer&&!this.container.mouseTarget?(this.parentContainer.removeChild(this.container),this.parentContainer=null):this.cache||this.container.destroy(),this.container=null,this.interpolate.recycle(),this.interpolate=null}},publicMethods:{removeFromParentContainer:function(){this.parentContainer&&(this.mask&&!this.localMask&&this.setMask(),this.parentContainer.removeChild(this.container))},addToParentContainer:function(t){if(this.removeFromParentContainer(),!this.cache){const{parent:e,x:i,y:s}=this.owner;let n=!0===t?e.worldContainer:t?.container??t??e.worldContainer;if("string"==typeof t){const i=e.getEntityById(t);n=i?.container,n||(platypus.debug.warn(`Trying to add to non-existent entity "${t}", added to World container instead.`),n=e.worldContainer)}n instanceof kt?n.on("load",()=>this.addToParentContainer(n)):(this.parentContainer=n,this.parentContainer.addChild(this.container),this.updateSprite(!0,i,s),this.mask&&!this.localMask&&this.setMask(this.mask))}}}}),ml={Sprite:f,TilingSprite:b,AnimatedSprite:t,NineSliceSprite:l},vl=xt({id:"Render",properties:{matchEntity:!1,offsetX:0,offsetY:0,offsetZ:0,options:null,image:null,images:null,spriteType:"Sprite",localRotation:0,localScaleX:1,localScaleY:1},initialize(){const{image:t,images:e,localRotation:i,localScaleX:s,localScaleY:n,offsetX:o,offsetY:r,offsetZ:a,options:h,owner:l,spriteType:c}=this,d=this.sprite=new ml["Sprite"===c&&e&&!e?"AnimatedSprite":c]({...t?{texture:platypus.assetCache.get(t)}:{textures:e.map(t=>platypus.assetCache.get(t))},...h??{}}),u=this.matchEntity?{originalWidth:l.width,originalHeight:l.height}:null;if(d.x=o,d.y=r,d.zIndex=a,d.rotation=i/180*Math.PI,d.scale.x=s,d.scale.y=n,l.container)this.addToContainer();else{const{interactive:t,mask:e,mirror:i,flip:s,visible:n,cache:o,ignoreOpacity:r,scaleX:a,scaleY:h,skewX:c,skewY:d}=l;l.addComponent(new yl(this.owner,{interactive:t,mask:e,mirror:i,flip:s,visible:n,cache:o,ignoreOpacity:r,scaleX:a,scaleY:h,skewX:c,skewY:d},()=>this.addToContainer()))}u&&("NineSliceSprite"===c?(d.x=o-l.width/2,d.y=r-l.height/2,d.width=l.width,d.height=l.height,this.addEventListener("handle-render",t=>{d.x=o-l.width/2,d.y=r-l.height/2,d.width=l.width,d.height=l.height})):this.addEventListener("handle-render",t=>{d.scale.x=s*l.width/u.originalWidth,d.scale.y=n*l.height/u.originalHeight})),d.update&&this.addEventListener("handle-render",t=>{d.update&&d.update(t.delta)})},methods:{addToContainer:function(){this.owner.container.addChild(this.sprite)},destroy:function(){this.owner.container.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null}},getAssetList(t,e,i){const s=t?.image??e?.image??i?.image;return(s?[s]:t?.images??e?.images??i?.images??[]).map(t=>({alias:[t],src:t}))}}),wl=function(t,e){if("default"===t)return()=>e;{const i=mt.setUp(t);return t=>!!t.includes(i)&&e}},bl=function(t,e,i){this.component.playAnimation(t,e,i)},xl=function(t){this.component.stopAnimation(t)},_l=function(t,e,i){this.owner.triggerEvent("play-animation",t,e,i)},Cl=function(t){this.owner.triggerEvent("stop-animation",t)},kl=xt({id:"RenderAnimator",properties:{animationStates:null,animationEvents:null,component:null,forcePlayThrough:!1,restart:!0,loop:!1},initialize:function(){const t=function(t,e,i){this.override=t,this.owner.triggerEvent("play-animation",t,e,i)},e=function(t,e,i){this.override=t,this.playAnimation(t,e,i)};return function(){const i=this.animationEvents,s=this.animationStates;if(this.override=!1,i){const s=Object.keys(i),{length:n}=s,o=this.component,r=o?e:t;for(let t=0;t<n;t++){const e=s[t];this.addEventListener(e,r.bind(o??this,i[e],this.loop,this.restart))}}if(this.followThroughs={},this.checkStates=V.setUp(),this.state=this.owner.state,this.stateChange=!0,this.lastState=-1,s){const t=Object.keys(s),{length:e}=t;for(let i=0;i<e;i++){const e=t[i],n=s[e],o=n.length-1,r="!"===n[o],a=r?n.substring(0,o):n;this.followThroughs[a]=r,this.checkStates.push(wl(e,a))}}this.waitingAnimation=!1,this.waitingState=0,this.playWaiting=!1,this.animationFinished=!1,this.component?(this.playAnimation=bl,this.stopAnimation=xl):(this.playAnimation=_l,this.stopAnimation=Cl)}}(),events:{"state-changed":function(){this.stateChange=!0},"animation-ended":function(t){t===this.currentAnimation&&(this.override&&t===this.override&&(this.stateChange=!0,this.override=!1),this.waitingAnimation?(this.currentAnimation=this.waitingAnimation,this.waitingAnimation=!1,this.lastState=this.waitingState,this.animationFinished=!1,this.playAnimation(this.currentAnimation)):this.animationFinished=!0)},"update-animation":function(t){if(this.stateChange&&!this.override){this.state.has("visible")&&(this.visible=this.state.get("visible"));for(let e=0;e<this.checkStates.length;e++){const i=this.checkStates[e](this.state);if(i){this.currentAnimation!==i?!this.followThroughs[this.currentAnimation]&&(!this.forcePlaythrough||this.animationFinished||this.lastState>=+e)?(this.currentAnimation=i,this.lastState=+e,this.animationFinished=!1,t?this.playAnimation(this.currentAnimation):this.stopAnimation(this.currentAnimation)):(this.waitingAnimation=i,this.waitingState=+e):this.waitingAnimation&&!this.followThroughs[this.currentAnimation]&&(this.waitingAnimation=!1);break}}this.stateChange=!1}}},methods:{toJSON:function(){return null},destroy:function(){V.recycle(this.checkStates),this.checkStates=null,this.followThroughs=null,this.state=null}}}),El={},Al=function(t){let e=t.charCodeAt(0)||0,i=t.charCodeAt(1)||0,s=t.charCodeAt(2)||0,n=0,o=0;return n=Math.min(e,i,s),e-=n,i-=n,s-=n,o=Math.max(e,i,s,1),e=204*e/o|0,i=204*i/o|0,s=204*s/o|0,(e<<8)+(i<<4)+s},Sl=function({radius:t,color:e,left:i,top:s,width:n,height:o,z:r,outline:h,points:l}){const c=new a;if(t){const e=n?i+n/2:i+t,r=o?s+o/2:s+t;c.circle(e,r,t)}else l?c.poly(l):n&&o&&c.rect(i,s,n,o);return c.z=r,c.fill(e,.1),h&&c.stroke({width:h,color:e}),c},Ml=function(t){return"string"==typeof t?parseInt(t.replace("#",""),16):t},Tl=xt({id:"RenderDebug",properties:{aabbColor:16746751,collisionColor:0,groupColor:65280,renderColor:255,width:100,height:100,offsetZ:1e4},initialize:function(){this.container=new n,this.container.cullable=!0,this.parentContainer=this.owner.parent.worldContainer,this.parentContainer.addChild(this.container),this.shapes=V.setUp(),this.isOutdated=!0,this.aabbColor=Ml(this.aabbColor),this.collisionColor=this.collisionColor?Ml(this.collisionColor):0,this.groupColor=Ml(this.groupColor),this.renderColor=Ml(this.renderColor)},events:{load:function(){platypus.game.settings.debug||this.owner.removeComponent(this)},"handle-render":function(){if(this.isOutdated&&(this.updateSprites(),this.isOutdated=!1),this.owner.getCollisionGroupAABB){const t=this.owner.getCollisionGroupAABB(),e=-.5;this.groupShape||(this.groupShape=Sl({color:this.groupColor,left:e,top:e,width:1,height:1,z:this.offsetZ}),this.container.addChild(this.groupShape)),this.groupShape.scaleX=t.width,this.groupShape.scaleY=t.height,this.groupShape.x=t.x-this.owner.x,this.groupShape.y=t.y-this.owner.y}this.update()},"orientation-updated":function(){this.isOutdated=!0},"collide-on":function(){this.isOutdated=!0},"collide-off":function(){this.isOutdated=!0}},methods:{addShape(t){const e=Sl({z:this.offsetZ,...t});this.shapes.push(e),this.container.addChild(e),this.offsetZ-=1e-4},update(){const{container:t,owner:e}=this;t.zIndex!==e.z+1e-6&&(t.zIndex=e.z+1e-6),t.updateTransform({x:e.x,y:e.y})},updateSprites:function(){const{owner:t}=this;for(let t=0;t<this.shapes.length;t++)this.container.removeChild(this.shapes[t]);if(this.shapes.length=0,t.getAABB)for(let e=0;e<t.collisionTypes.length;e++){const i=t.collisionTypes[e],s=t.getAABB(i),n=2,o=t.getShapes(i),r=this.initialWidth=s.width,a=this.initialHeight=s.height;let h=this.collisionColor||El[i];h||(h=El[i]=Al(i)),this.addShape({color:this.aabbColor,left:s.left-t.x,top:s.top-t.y,width:r,height:a});for(let e=0;e<o.length;e++){const i=o[e],s=i.aABB;this.addShape({color:h,left:s.left-t.x,top:s.top-t.y,width:s.width,height:s.height,radius:"circle"===i.type?i.radius:0,outline:n})}}else{const{height:t=1,width:e=1}=this;this.addShape({color:this.renderColor,left:-e/2,top:-t/2,width:e,height:t})}this.addShape({color:0,left:-1,outline:1,top:-1,radius:1})},destroy:function(){for(let t=0;t<this.shapes.length;t++)this.container.removeChild(this.shapes[t]);V.recycle(this.shapes),this.parentContainer.removeChild(this.container),this.container=null}}}),Ul=xt({id:"RenderDestroyMe",properties:{animationId:"",animationIds:null},initialize:function(t){this.animationId?this.animationIds=V.setUp(t.animationId):this.animationIds&&(this.animationIds=Z(this.animationIds))},events:{"animation-ended":function(t){(!this.animationIds||this.animationIds.indexOf(t)>=0)&&this.owner.parent.removeEntity(this.owner)}},methods:{destroy:function(){this.animationIds&&(V.recycle(this.animationIds),this.animationIds=null)}}}),Pl=xt({id:"RenderProgress",properties:{backgroundColor:0,color:16777215,mirror:!1,flip:!1,width:100,height:20,regX:0,regY:0},publicProperties:{x:0,y:0,z:0},initialize:function(){const t=new a,e=new a,i=new n;this.parentContainer=null,this.background=t,this.progress=e,this.container=i,"string"==typeof this.backgroundColor&&(this.backgroundColor=+this.backgroundColor.replace("#","0x")),"string"==typeof this.color&&(this.color=+this.color.replace("#","0x")),t.f(this.backgroundColor).rect(-this.regX,-this.regY,this.width,this.height),e.f(this.color).rect(-this.regX,-this.regY,this.width,this.height),e.scale=new c(1e-4,1),i.addChild(t),i.addChild(e)},events:{"handle-render-load":function(t){!this.parentContainer&&t&&t.container&&(this.parentContainer=t.container,this.parentContainer.addChild(this.container))},"handle-render":function(t){this.container&&(this.parentContainer||(t&&t.container?(this.parentContainer=t.container,this.parentContainer.addChild(this.container)):(platypus.debug.warn('No PIXI Stage, removing ProgressRender component from "'+this.owner.type+'".'),this.owner.removeComponent(this))),this.container.x=this.x,this.container.y=this.y,this.container.z=this.z)},"update-progress":function(t){isNaN(t)?"number"==typeof t.fraction?this.progress.scale.x=t.fraction:"number"==typeof t.total&&"number"==typeof t.progress&&(this.progress.scale.x=t.progress/t.total):this.progress.scale.x=t}},methods:{destroy:function(){this.parentContainer&&(this.parentContainer.removeChild(this.container),this.parentContainer=null),this.container=null}}}),Ol=function(t,e){if("default"===t)return()=>e;{const i=mt.setUp(t);return t=>t.includes(i)?e:null}},Ll=xt({id:"RenderSpine",properties:{animationStates:null,animationEvents:null,animationMap:null,skinMap:null,localScaleX:1,localScaleY:1,mask:null,interactive:!1,mixTimes:0,offsetX:0,offsetY:0,offsetZ:0,atlas:"",skeleton:null,mirror:!1,flip:!1,visible:!0,eventBased:!1,preMultipliedAlpha:!0,stateBased:!0},publicProperties:{dragMode:!1,scaleX:1,scaleY:1,skewX:0,skewY:0,x:0,y:0,z:0},initialize:function(){if(B){const i=platypus.assetCache.get(this.skeleton),s=platypus.assetCache.get(this.atlas),n=new L(new O(s)).readSkeletonData(i),o=this.spine=new B(n),r=(t=this.animationMap,e=i.animations,t||Object.keys(e).reduce((t,e)=>(t[e]=e,t),{}));let a="";if(o.state.addListener({event:(t,e)=>{const i=e.data.name;this.playAnimation(i)&&this.spine.update(1e-6),this.owner.trigger(i,e.data)},complete:t=>{const e=t.animation.name;if(this.playSequence){const t=this.playIndex===this.playSequence.length-1;if(this.playIndex+=1,this.playIndex<this.playSequence.length||this.loopSequence)return this.playIndex=this.playIndex%this.playSequence.length,this.innerPlayAnimation(this.playSequence[this.playIndex],!1),void(t&&this.owner.triggerEvent("animation-looped"))}this.owner.triggerEvent("animation-ended",e)}}),o.autoUpdate=!1,this.stateBased=r&&this.stateBased,this.eventBased=r&&this.eventBased,r){const t=H.setUp("animationEvents",this.eventBased?this.animationEvents||r:null,"animationStates",this.stateBased?this.animationStates||r:null,"forcePlayThrough",this.forcePlayThrough,"component",this);this.owner.addComponent(new kl(this.owner,t)),t.recycle(),a=r.default||""}if(this.mixTimes&&this.setMixTimes(this.mixTimes),this.currentAnimations=V.setUp(),a&&this.playAnimation(a),this.playSequence=null,this.playIndex=0,o.x=this.offsetX,o.y=this.offsetY,o.zIndex=this.offsetZ,o.scale.x=this.localScaleX,o.scale.y=this.localScaleY,this.skinMap){const t=this.skinMap;if(this.currentSkin=null,this.eventBased){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];this.addEventListener(i,()=>this.switchSkin(t[i]))}}if(this.stateBased){const e=Object.keys(t),{length:i}=e;this.state=this.owner.state,this.stateChange=!0,this.checkStates=V.setUp(),this.skins=V.setUp();for(let s=0;s<i;s++){const i=e[s];this.checkStates.push(Ol(i,t[i])),this.skins.push(i)}this.addEventListener("state-changed",()=>{this.stateChange=!0}),this.addEventListener("handle-render",()=>{if(this.stateChange){for(let t=0;t<this.checkStates.length;t++){const e=this.checkStates[t](this.state);if(null!==e){this.switchSkin(e);break}}this.stateChange=!1}});for(let t=0;t<this.checkStates.length;t++){const e=this.checkStates[t](this.state);if(null!==e){this.switchSkin(e);break}}}}if(this.owner.container)this.addToContainer();else{const t=H.setUp("interactive",this.interactive,"mask",this.mask,"mirror",this.mirror,"flip",this.flip,"visible",this.visible,"cache",this.cache,"ignoreOpacity",this.ignoreOpacity,"scaleX",this.scaleX,"scaleY",this.scaleY,"skewX",this.skewX,"skewY",this.skewY);this.owner.addComponent(new yl(this.owner,t,()=>this.addToContainer())),t.recycle()}}else platypus.debug.error("RenderSpine requires `PIXI.spine` to function.");var t,e},events:{"handle-render":function(t){this.spine&&!this.paused&&(this.owner.triggerEvent("update-animation",!0),this.spine.update(t.delta/1e3))},"set-mix-times":function(t){this.setMixTimes(t)},hide:function(){this.visible=!1},show:function(){this.visible=!0},"stop-animation":function(t){this.stopAnimation(t)},"play-animation":function(t,e){this.playAnimation(t,e)},"pause-animation":function(){this.paused=!0},"unpause-animation":function(){this.paused=!1},"switch-skin":function(t){this.switchSkin(t)},"tint-slots":function(t,e){let i=null,s=0;for(s=0;s<t.length;s++)i=this.spine.skeleton.findSlot(t[s]),i&&i.color.setFromString(e)},"tint-attachment":function(t,e,i){let s=null,n=null;s=this.spine.skeleton.findSlot(t),s?(n=this.spine.skeleton.getAttachment(t,e),n?n.color.setFromString(i):console.warn("Cannot tint attachment, doesn't exist")):console.warn("Cannot tint attachment, slot doesn't exist")},"apply-spine-physics":function(t){t.translate&&this.spine.skeleton.physicsTranslate(t.translate.x,t.translate.y),t.rotate&&this.spine.skeleton.physicsTranslate(t.rotate.x,t.rotate.y,t.rotate.degrees)}},methods:{switchSkin:function(t){const e=this.spine.skeleton.data,i=new z("custom");let s=0,n=null;for("string"==typeof t&&(t=[t]),s=0;s<t.length;s++)n=e.findSkin(t[s]),n?i.addSkin(n):console.warn("Cannot find skin: "+t[s]);this.spine.skeleton.setSkin(i),this.spine.skeleton.setSlotsToSetupPose()},addToContainer:function(){this.owner.container.cullable=!1,this.owner.container.addChild(this.spine)},playAnimation:function(t,e=!0){return Array.isArray(t)?t!==this.playSequence?(this.playSequence=t,this.playIndex=0,this.loopSequence=e,this.innerPlayAnimation(t[0],!1)):0:(this.playSequence=null,this.playIndex=0,this.innerPlayAnimation(t,e))},innerPlayAnimation:function(t,e){const{currentAnimations:i,spine:s}=this,{state:n,skeleton:o}=s,{data:r}=o;let a=0,h=t;for(;h;){const t=h.indexOf(";"),s=t>=0?h.substring(0,t):h;h=t>=0?h.substring(t+1):"","_"===s?(i[a]=s,n.setEmptyAnimation(a)):s&&r.findAnimation(s)&&(i[a]=s,n.setAnimation(a,s,e)),a+=1}return a},stopAnimation:function(t){const{currentAnimations:e,spine:i}=this,{state:s,skeleton:n}=i,{data:o}=n;let r=0,a=t;for(;a;){const t=a.indexOf(";"),i=t>=0?a.substring(0,t):a;a=t>=0?a.substring(t+1):"","_"===i?(e[r]=i,s.setEmptyAnimation(r)):i&&o.findAnimation(i)&&(e[r]=i,s.setAnimation(r,i,!1)),r+=1}return r},setMixTimes:function(t){const{spine:e}=this,{animations:i}=e.skeleton.data,{data:s}=e.state;if("number"==typeof t){let e=i.length;for(;e--;){let n=i.length;for(;n--;)e!==n&&s.setMix(i[e].name,i[n].name,t)}}else{const e=Object.keys(t),{length:i}=e;for(let n=0;n<i;n++){const i=e[n],o=i.indexOf(":");o>=0&&s.setMix(i.substring(0,o),i.substring(o+1),t[i])}}this.mixTimes=s.animationToMixTime},destroy:function(){this.owner.container.removeChild(this.spine),this.spine.destroy(),this.spine=null,this.mixTimes=null}},getAssetList:(t,e,i)=>[{alias:[t?.atlas??e?.atlas??i?.atlas],src:t?.atlas??e?.atlas??i?.atlas},{alias:[t?.skeleton??e?.skeleton??i?.skeleton],src:t?.skeleton??e?.skeleton??i?.skeleton}]}),zl={},Bl={},Il=function(){},Dl=m.EMPTY,Xl=/[\[\]{},-]/g,Rl=function(t){const e=platypus.assetCache,i=V.setUp();for(let s=0;s<t.length;s++){const n=t[s];if("string"==typeof n){if(!Bl[n]){const t=e.get(n);if(!t){platypus.debug.warn(`PIXIAnimation: "${n}" is not a loaded asset.`);break}Bl[n]=t.source}i.push(Bl[n])}else i.push(new v(n))}return i},jl=function(t,e){const i=V.setUp();for(let s=0;s<t;s++)i.push(e[s]??Dl);return H.setUp("id","default","frames",i,"next","default","speed",1)},Yl=function(t,e){const i=H.setUp(),s=Object.keys(t),{length:n}=s;for(let o=0;o<n;o++){const n=s[o],r=t[n],a=Z(r.frames);let h=a.length;for(;h--;)a[h]=e[a[h]]||Dl;i[n]=H.setUp("id",n,"frames",a,"next",r.next,"speed",r.speed)}return i.default||(i.default=jl(e.length,e)),i},Nl=class extends n{constructor(e,i){const s=function(t){if(t.id)return t.id;for(let e=0;e<t.images.length;e++)if("string"!=typeof t.images[e])return"";return t.id=JSON.stringify(t).replace(Xl,""),t.id}(e),n=(e.framerate||60)/60;let o=s?zl[s]:null;super(),s?o?(o.viable+=1,this.cacheId=s):(o=zl[s]=function(t,e){const{frames:i,images:s}=t,n=Rl(s),o=i.map(t=>new m({source:n[t[4]],frame:new u(t[0],t[1],t[2],t[3]),rotate:0,defaultAnchor:new c((t[5]||0)/t[2],(t[6]||0)/t[3])})),r=Yl(t.animations,o);return V.recycle(n),H.setUp("textures",o,"animations",r,"viable",1,"cacheId",e)}(e,s),this.cacheId=s):o=function(t={}){const{frames:e,images:i}=t,s=Rl(i),n=e.map(t=>new m({source:s[t[4]],frame:new u(t[0],t[1],t[2],t[3]),rotate:0,defaultAnchor:new c((t[5]||0)/t[2],(t[6]||0)/t[3])})),o=Yl(t.animations,n);return o.default||(o.default=jl(n.length,n)),V.recycle(s),H.setUp("textures",n,"animations",o)}(e),this._animations={};{const e=this._animations,{animations:i}=o,s=Object.keys(i),{length:r}=s;for(let o=0;o<r;o++){const r=s[o],a=i[r];if(1===a.frames.length)e[r]=new f(a.frames[0]);else{const i=e[r]=new t(a.frames);i.animationSpeed=n*a.speed,i.onComplete=i.onLoop=()=>{this.onComplete&&this.onComplete(r),a.next&&this.gotoAndPlay(a.next)},i.updateAnchor=!0}}}this._animation=null,this.animationSpeed=n,this.currentAnimation=null,this.playing=!1,this._visible=!0,this._updating=!1,this.update=Il,this.gotoAndPlay(i)}get visible(){return this._visible}set visible(t){this._visible=t}get paused(){return!this.playing}set paused(t){(t&&this.playing||!t&&!this.playing)&&(this.playing=!t)}stop(){this.paused=!0}play(){this.paused=!1}gotoAndStop(t){this.stop(),this._animation&&this._animation.stop&&this._animation.stop(),this._animation=this._animations[t],this._animation||(this._animation=this._animations.default),this.removeChildren(),this.addChild(this._animation)}gotoAndPlay(t,e=!0,i=!0){(this.currentAnimation!==t||i)&&(this._animation&&this._animation.stop&&this._animation.stop(),this._animation=this._animations[t],this.currentAnimation=t,this._animation||(this._animation=this._animations.default,this.currentAnimation="default"),this.removeChildren(),this.addChild(this._animation)),this._animation.loop=e,this._animation.play&&this._animation.play(),this.play()}has(t){return!!this._animations[t]}destroy(){if(this.stop(),this._animation?.stop&&this._animation.stop(),super.destroy(),this.cacheId){const t=zl[this.cacheId];if(t.viable-=1,t.viable<=0){V.recycle(t.textures);const e=t.animations,i=Object.keys(e),{length:s}=i;for(let t=0;t<s;t++){const s=i[t];V.recycle(e[s].frames)}delete zl[this.cacheId]}}}static get EmptySpriteSheet(){return{framerate:60,frames:[],images:[],animations:{},recycleSpriteSheet:function(){}}}static formatSpriteSheet(t){const e=/([\w-\.]+)\.(\w+)$/,i=t=>t.map(t=>(t.src??t).substring(0,128)).join(","),s=function(t,e){const{animations:s,id:r,images:a,framerate:h=60,frames:l}=t,{animations:c,id:d,images:u,framerate:p=60,frames:g}=e,f=a.map(t=>o(t)),y=u.length,m=g.length;if(e.id=d?`${d};${r??i(a)}`:r??i(a),u.push(...f),Array.isArray(l))!function(t,e,i){for(let s=0;s<t.length;s++){const n=t[s];e.push(V.setUp(n[0],n[1],n[2],n[3],n[4]+i,n[5],n[6]))}}(l,g,y);else{const t=Rl(f);!function(t,e,i,s){const{width:n,height:o,regX:r=0,regY:a=0}=t;for(let t=0;t<s.length;t++){const h=s[t],l=h.realWidth-n,c=h.realHeight-o;for(let s=0;s<=c;s+=o)for(let h=0;h<=l;h+=n)e.push([h,s,n,o,t+i,r,a])}}(l,g,y,t),V.recycle(t)}return function(t={},e,i,s,o){const r=Object.keys(t),{length:a}=r;for(let h=0;h<a;h++){const a=r[h];e[a]&&(V.recycle(e[a].frames),e[a].recycle(),platypus.debug.log('PIXIAnimation "'+o+'": Overwriting duplicate animation for "'+a+'".')),e[a]=n(a,t[a],i,s)}}(s,c,h/p,m,e.id),V.recycle(f),e},n=function(t,e,i,s){const n=V.setUp();if("number"==typeof e)return n.push(e+s),H.setUp("frames",n,"next",t,"speed",i);if(Array.isArray(e)){const o=e[0]??0,r=(e[1]??o)+1+s;for(let t=o+s;t<r;t++)n.push(t);return H.setUp("frames",n,"next",e[2]||t,"speed",(e[3]||1)*i)}for(let t=0;t<e.frames.length;t++)n.push(e.frames[t]+s);return H.setUp("frames",n,"next",e.next||t,"speed",(e.speed||1)*i)},o=function(t){if("string"==typeof t){const i=t.match(e);if(i)return i[1]}return t},r=function(){const t=this.animations,e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s];V.recycle(t[i].frames),t[i].recycle()}V.recycle(this.frames,2),this.frames=null,V.recycle(this.images),this.images=null,this.recycle()};let a=Nl.EmptySpriteSheet,h=t;if("string"==typeof h&&(h=platypus.game.settings.spriteSheets[t]),h){if(a=H.setUp("animations",H.setUp(),"framerate",60,"frames",V.setUp(),"id","","images",V.setUp(),"recycleSpriteSheet",r),Array.isArray(h))return function(t,e){let i=t.length;for(;i--;){let n=t[i];"string"==typeof n&&(n=platypus.game.settings.spriteSheets[n]),n&&s(n,e)}return e}(h,a);if(h)return s(h,a)}return a}},Wl=Nl,Hl=xt({id:"RenderSprite",properties:{animationStates:null,animationEvents:null,spriteSheet:null,animationMap:null,mask:null,interactive:!1,offsetX:0,offsetY:0,offsetZ:0,restart:!0,mirror:!1,flip:!1,visible:!0,eventBased:!1,stateBased:!0,cache:!1,forcePlayThrough:!1,ignoreOpacity:!1,scale:1,scaleX:1,scaleY:1,localRotation:0,localScaleX:1,localScaleY:1,skew:0,skewX:0,skewY:0},initialize:function(){const t=Wl.formatSpriteSheet(this.spriteSheet),e=function(t,e){return t||(Array.isArray(e.frames)&&1===e.frames.length?null:Object.keys(e.animations).reduce((t,e)=>(t[e]=e,t),{}))}(this.animationMap,t),i=e?.default??"";if(t===Wl.EmptySpriteSheet&&platypus.debug.warn('Entity "'+this.owner.type+'": RenderSprite sprite sheet not defined.'),this.stateBased=e&&this.stateBased,this.eventBased=e&&this.eventBased,e){const t=H.setUp("animationEvents",this.eventBased?this.animationEvents||e:null,"animationStates",this.stateBased?this.animationStates||e:null,"forcePlayThrough",this.forcePlayThrough,"restart",this.restart,"component",this);this.owner.addComponent(new kl(this.owner,t)),t.recycle()}if(this.sprite=new Wl(t,i),this.sprite.onComplete=t=>{this.owner.triggerEvent("animation-ended",t)},this.sprite.x=this.offsetX,this.sprite.y=this.offsetY,this.sprite.zIndex=this.offsetZ,this.sprite.rotation=this.localRotation/180*Math.PI,this.sprite.scale.x=this.localScaleX,this.sprite.scale.y=this.localScaleY,this.owner.container)this.addToContainer();else{const t=H.setUp("interactive",this.interactive,"mask",this.mask,"mirror",this.mirror,"flip",this.flip,"visible",this.visible,"cache",this.cache,"ignoreOpacity",this.ignoreOpacity,"scaleX",this.scaleX,"scaleY",this.scaleY,"skewX",this.skewX,"skewY",this.skewY);this.owner.addComponent(new yl(this.owner,t,()=>this.addToContainer())),t.recycle()}t.recycleSpriteSheet()},events:{"handle-render":function(t){this.sprite&&(this.owner.triggerEvent("update-animation",!0),this.sprite.update(t.delta))},"stop-animation":function(t){this.stopAnimation(t)},"play-animation":function(t,e,i){this.playAnimation(t,e,i)}},methods:{addToContainer:function(){this.owner.container.addChild(this.sprite)},playAnimation:function(t,e,i){const{sprite:s}=this;t&&s.has(t)?s.gotoAndPlay(t,e,i):s.play()},stopAnimation:function(t){const{sprite:e}=this;t&&e.has(t)?e.gotoAndStop(t):e.stop()},destroy:function(){this.owner.container.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null}},getAssetList:function(){const t=function(e,i){if(e){if("string"==typeof e)return t(i[e],i);if(e.images)return Z(e.images)}return V.setUp()};return function(e,i,s){const n=platypus.game.settings.spriteSheets,o=e?.spriteSheet??i?.spriteSheet??s?.spriteSheet;if(Array.isArray(o)){const e=V.setUp();let i=o.length;for(;i--;){const s=t(o[i],n);F(e,s),V.recycle(s)}return e}return t(o,n)}}()}),Vl=.5,Fl={horizontal:{left:0,middle:Vl,center:Vl,right:1},vertical:{top:0,middle:Vl,center:Vl,bottom:1}},Zl=xt({id:"RenderText",properties:{offsetX:0,offsetY:0,offsetZ:0,text:"",style:null},initialize:function(t){const{offsetX:e,offsetY:i,offsetZ:s,owner:n,style:o={},text:r=""}=this,a=Fl.horizontal[o?.align]??Vl,h=Fl.vertical[o?.verticalAlign]??Vl,l=this.sprite=new y({text:r,style:o});l.anchor.x=a,l.anchor.y=h,l.x=e,l.y=i,l.zIndex=s,n.container?this.addToContainer():n.addComponent(new yl(n,t,()=>this.addToContainer()))},events:{"set-text":function(t){const{sprite:e}=this;"string"==typeof t?e.text=t:(t.style&&Object.keys(t.style).forEach(i=>e.style[i]=t.style[i]),"string"==typeof t.text&&(e.text=t.text))}},methods:{addToContainer:function(){this.owner.container.addChild(this.sprite)},destroy:function(){this.owner.container.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null}}}),Gl=function(){return null},ql=Ci.setUp(),$l=function(t,e){return t.z-e.z},Jl=function(t){let e=1;for(;e<t;)e*=2;return e},Ql=(t,e)=>{const i=Object.keys(e).map(i=>{const s=t.addEventListener(i,e[i]);return()=>t.removeEventListener(i,s)});return()=>{i.forEach(t=>t())}},Kl=function(t,e,i){this.id=e,this.instances=V.setUp(),this.index=0,this.tileSpriteSheet=t,this.getNext=this.initializeAndGetNext,this.uninitializedTiles=i,i.push(this)},tc={getNext:Gl,destroy:Gl},ec=Kl.prototype;ec.initializeAndGetNext=function(){return this.initialize(),this.index+=1,this.instances[0]},ec.initialize=function(){const t=+this.id.substring(4),e="tile"+(268435455&t),i=new f((this.tileSpriteSheet._animations[e]||this.tileSpriteSheet._animations.default).texture);!function(t,e){if(2147483648&t&&(e.scale.x=-1),1073741824&t&&(e.scale.y=-1),536870912&t){const t=e.scale.x;e.scale.x=e.scale.y,e.scale.y=-t,e.rotation=Math.PI/2}}(t,i),i.template=this,this.instances.push(i),G(this.uninitializedTiles,this.uninitializedTiles.indexOf(this)),delete this.getNext},ec.getNext=function(){let t=this.instances[this.index];if(!t){const e=this.instances[0];t=this.instances[this.index]=new f(e.texture),t.scale=e.scale,t.rotation=e.rotation,t.anchor=e.anchor||e._animation.anchor}return this.index+=1,t},ec.clear=function(){this.index=0},ec.destroy=function(){for(let t=0;t<this.instances.length;t++)this.instances[t].destroy();V.recycle(this.instances),this.recycle()},N.add(Kl,"Template",Kl,null,!0);const ic=xt({id:"RenderTiles",properties:{buffer:0,cacheAll:!1,entityCache:!1,imageMap:[],maximumBuffer:2048,refreshBuffer:0,scaleX:1,scaleY:1,spriteSheet:null,tileCache:!0,tileHeight:10,tileWidth:10,top:0,left:0},initialize:function(t){const e=this.imageMap,i=this.addEventListener("handle-render",function(){this.uninitializedTiles.length?this.uninitializedTiles[0].initialize():(this.removeEventListener("handle-render",i),this.owner.parent.triggerEvent("child-entity-updated",this.owner))});this.doMap=null,this.cachedDisplayObjects=null,this.populate=this.populateTiles,this.tiles={},this.renderer=platypus.game.renderer,this.tilesSprite=null,this.cacheTexture=null,this.mapContainer=null,this.laxCam=Ci.setUp(),this.worldWidth=this.tileWidth,this.worldHeight=this.tileHeight,this.cache=Ci.setUp(),this.cachePixels=Ci.setUp(),this.uninitializedTiles=V.setUp(),this.spriteSheet=Wl.formatSpriteSheet(this.spriteSheet),this.tileSpriteSheet=new Wl(this.spriteSheet),this.tileContainer=new n,this.mapContainer=new n,this.mapContainer.addChild(this.tileContainer),this.updateCache=!1,this.imageMap=V.setUp(this.createMap(e)),this.tilesWidth=this.imageMap[0].length,this.tilesHeight=this.imageMap[0][0].length,this.layerWidth=this.tilesWidth*this.tileWidth,this.layerHeight=this.tilesHeight*this.tileHeight,this.edgeBleed=1,this.edgesBleed=2,this.cacheWidth=Math.min(Jl(this.layerWidth+this.edgesBleed),this.maximumBuffer),this.cacheHeight=Math.min(Jl(this.layerHeight+this.edgesBleed),this.maximumBuffer),this.owner.container||this.owner.addComponent(new yl(this.owner,t)),this.container=this.owner.container,this.tileCache?this.layerWidth<=this.cacheWidth&&this.layerHeight<=this.cacheHeight?this.teardown=this.setupSingleCache():this.cacheAll||this.layerWidth<=2*this.cacheWidth&&this.layerHeight<=this.cacheHeight||this.layerWidth<=this.cacheWidth&&this.layerHeight<=2*this.cacheHeight?this.teardown=this.setupFullCache():this.teardown=this.setupPanningCache():this.teardown=this.setupNoCache()},events:{"cache-sprite":function(t){this.cacheSprite(t)},"refresh-cache":function(){this.updateCache=!0},"peer-entity-added":function(t){this.cacheSprite(t)},"peer-entity-removed":function(t){this.uncacheSprite(t)},"add-tiles":function(t){const e=t.imageMap;e&&(this.imageMap.push(this.createMap(e)),this.updateCache=!0)},"change-tile":function(t,e,i,s){const n=this.imageMap;n&&(this.updateTile(t,n[s||0],e,i),!this.cache.empty&&e>=this.cache.left&&e<=this.cache.right&&i>=this.cache.top&&i<=this.cache.bottom&&(this.updateCache=!0))},"camera-loaded":function(t){this.worldWidth=t.world.width,this.worldHeight=t.world.height,this.buffer&&!this.cacheAll&&this.updateBufferRegion(t.viewport)},"force-render":function(){if(this.cacheAll)this.populateTiles(this.cache,null),this.renderCache(this.cache,this.cacheTexture,this.mapContainer,this.mapContainerWrapper);else if(this.cacheTexture){const{viewport:t}=this.owner.parent.worldCamera,{cache:e,cachePixels:i}=this,s=ql,n=this.cacheTilesWidth-1,o=this.cacheTilesHeight-1,r=n/2,a=o/2;this.convertCamera(t),i.empty=!0,s.setAll(Math.round((this.laxCam.x-this.left)/this.tileWidth-r)+r,Math.round((this.laxCam.y-this.top)/this.tileHeight-a)+a,n,o),s.left<0?s.moveX(s.halfWidth):s.right>this.tilesWidth-1&&s.moveX(this.tilesWidth-1-s.halfWidth),s.top<0?s.moveY(s.halfHeight):s.bottom>this.tilesHeight-1&&s.moveY(this.tilesHeight-1-s.halfHeight),this.tilesSpriteCache.texture=this.cacheTexture,this.cacheTexture=this.cacheTexture.alternate,this.tilesSprite.texture=this.cacheTexture,this.populateTiles(s,e),this.renderCache(s,this.cacheTexture,this.mapContainer,this.mapContainerWrapper,this.tilesSpriteCache),e.set(s),i.setAll((e.x+.5)*this.tileWidth+this.left,(e.y+.5)*this.tileHeight+this.top,(e.width+1)*this.tileWidth,(e.height+1)*this.tileHeight),this.tilesSprite.x=t.left-this.laxCam.left+e.left*this.tileWidth+this.left,this.tilesSprite.y=t.top-this.laxCam.top+e.top*this.tileHeight+this.top}}},methods:{setupSingleCache(){const{container:t,mapContainer:e,owner:i}=this,{z:s}=i,o=p.create({width:this.cacheWidth,height:this.cacheHeight}),r=new f(o);return this.mapContainerWrapper=new n,this.mapContainerWrapper.addChild(e),this.cacheAll=!0,this.edgeBleed=0,this.edgesBleed=0,this.updateRegion(0),this.render=this.renderCache,this.cacheTexture=o,this.tilesSprite=r,r.scale.x=this.scaleX,r.scale.y=this.scaleY,r.z=s,this.cache.setBounds(0,0,this.tilesWidth-1,this.tilesHeight-1),this.populateTiles(this.cache,null),this.renderCache(this.cache,o,this.mapContainer,this.mapContainerWrapper),t.addChild(r),Ql(this,{"camera-update":function(t){const{laxCam:e,left:i,top:s}=this,{viewport:n}=t;this.convertCamera(n),this.tilesSprite.x=n.left-e.left+this.cache.left*this.tileWidth+i,this.tilesSprite.y=n.top-e.top+this.cache.top*this.tileHeight+s},"handle-render":function(){this.updateCache&&(this.updateCache=!1,this.populateTiles(this.cache,null),this.renderCache(this.cache,this.cacheTexture,this.mapContainer,this.mapContainerWrapper))}})},setupFullCache(){const{container:t,mapContainer:e,owner:i}=this,{z:s}=i;return this.mapContainerWrapper=new n,this.mapContainerWrapper.addChild(e),this.cacheAll=!0,this.cacheWidth=Math.min(Jl(this.layerWidth+2),this.maximumBuffer),this.cacheHeight=Math.min(Jl(this.layerHeight+2),this.maximumBuffer),this.updateRegion(2),this.tileContainer.x=-1,this.tileContainer.y=-1,this.render=this.renderCacheWithExtrusion,this.cacheGrid=this.createGrid(t),this.updateCache=!0,Ql(this,{"camera-update":function(t){const{cacheClipHeight:e,cacheClipWidth:i,cacheGrid:s,cachePixels:n,laxCam:o,left:r,top:a}=this,{viewport:h}=t;this.convertCamera(h);for(let t=0;t<s.length;t++)for(let l=0;l<s[t].length;l++){n.setAll((t+.5)*i+r,(l+.5)*e+a,i,e);const c=s[t][l],d=n.intersects(o);c.visible&&!d?c.visible=!1:!c.visible&&d&&(c.visible=!0),c.visible&&d&&(c.x=h.left-o.left+t*i+r,c.y=h.top-o.top+l*e+a)}},"handle-render":function(){if(this.updateCache){const{cache:t,cacheGrid:e,cacheTilesHeight:i,cacheTilesWidth:s,tilesHeight:n,tilesWidth:o}=this,r=n-1,a=o-1;this.updateCache=!1;for(let n=0;n<e.length;n++)for(let o=0;o<e[n].length;o++)t.setBounds(n*s,o*i,Math.min((n+1)*s,a),Math.min((o+1)*i,r)),this.populateTiles(t,null),this.renderCacheWithExtrusion(t,e[n][o].texture,this.mapContainer,this.mapContainerWrapper)}}})},setupPanningCache(){const{container:t,mapContainer:e,owner:i}=this,{z:s}=i;return this.mapContainerWrapper=new n,this.mapContainerWrapper.addChild(e),this.updateRegion(0),this.render=this.renderCache,this.cacheAll=!1,this.cacheTexture=p.create({width:this.cacheWidth,height:this.cacheHeight}),this.tilesSprite=new f(this.cacheTexture),this.tilesSprite.scale.x=this.scaleX,this.tilesSprite.scale.y=this.scaleY,this.tilesSprite.z=s,this.cacheTexture.alternate=p.create({width:this.cacheWidth,height:this.cacheHeight}),this.tilesSpriteCache=new f(this.cacheTexture.alternate),this.cacheTexture.alternate.alternate=this.cacheTexture,t.addChild(this.tilesSprite),Ql(this,{"camera-update":function(t){const{buffer:e,cache:i,cachePixels:s,laxCam:n,refreshBuffer:o}=this,{viewport:r}=t,a=e&&(r.width!==n.width||r.height!==n.height),h=ql;if(this.convertCamera(r),(s.empty||!s.contains(n))&&this.imageMap.length>0){a&&this.updateBufferRegion(n);const t=this.cacheTilesWidth-1,e=this.cacheTilesHeight-1,o=t/2,r=e/2;h.setAll(Math.round((n.x-this.left)/this.tileWidth-o)+o,Math.round((n.y-this.top)/this.tileHeight-r)+r,t,e),h.left<0?h.moveX(h.halfWidth):h.right>this.tilesWidth-1&&h.moveX(this.tilesWidth-1-h.halfWidth),h.top<0?h.moveY(h.halfHeight):h.bottom>this.tilesHeight-1&&h.moveY(this.tilesHeight-1-h.halfHeight),this.tilesSpriteCache.texture=this.cacheTexture,this.cacheTexture=this.cacheTexture.alternate,this.tilesSprite.texture=this.cacheTexture,this.populateTiles(h,i),this.renderCache(h,this.cacheTexture,this.mapContainer,this.mapContainerWrapper,this.tilesSpriteCache,i),i.set(h),s.setAll((i.x+.5)*this.tileWidth+this.left,(i.y+.5)*this.tileHeight+this.top,(i.width+1)*this.tileWidth,(i.height+1)*this.tileHeight)}this.tilesSprite.x=r.left-n.left+i.left*this.tileWidth+this.left,this.tilesSprite.y=r.top-n.top+i.top*this.tileHeight+this.top},"handle-render":function(){this.updateCache&&!this.cache.empty&&(this.updateCache=!1,this.populateTiles(this.cache,null),this.renderCacheClear(this.cache,this.cacheTexture,this.mapContainer,this.mapContainerWrapper),this.tilesSpriteCache.texture=this.cacheTexture,this.cachePixels.setAll((this.cache.x+.5)*this.tileWidth+this.left,(this.cache.y+.5)*this.tileHeight+this.top,(this.cache.width+1)*this.tileWidth,(this.cache.height+1)*this.tileHeight))}})},setupNoCache(){const{container:t,left:e,mapContainer:i,owner:s,scaleX:n,scaleY:o,top:r}=this,{z:a}=s;return this.updateRegion(0),i.scale.x=n,i.scale.y=o,i.x=e,i.y=r,i.z=a,t.addChild(i),this.buffer=0,this.cacheAll=!1,Ql(this,{"camera-update":function(t){const{buffer:e,cache:i,cachePixels:s,laxCam:n}=this,{viewport:o}=t,r=e&&(o.width!==n.width||o.height!==n.height),a=ql;if(this.convertCamera(o),(s.empty||!s.contains(n))&&this.imageMap.length>0){r&&this.updateBufferRegion(n);const t=this.cacheTilesWidth-1,e=this.cacheTilesHeight-1,o=t/2,h=e/2;a.setAll(Math.round((n.x-this.left)/this.tileWidth-o)+o,Math.round((n.y-this.top)/this.tileHeight-h)+h,t,e),a.left<0?a.moveX(a.halfWidth):a.right>this.tilesWidth-1&&a.moveX(this.tilesWidth-1-a.halfWidth),a.top<0?a.moveY(a.halfHeight):a.bottom>this.tilesHeight-1&&a.moveY(this.tilesHeight-1-a.halfHeight),this.populateTiles(a,null),i.set(a),s.setAll((i.x+.5)*this.tileWidth+this.left,(i.y+.5)*this.tileHeight+this.top,(i.width+1)*this.tileWidth,(i.height+1)*this.tileHeight)}},"handle-render":function(){this.updateCache&&(this.updateCache=!1,this.cachePixels.empty=!0)}})},cacheSprite:function(t){const e=t.cacheRender;if(this.entityCache&&e){const{x:i,y:s,width:n,height:o}=e.getBounds(e.transformMatrix),r=i-this.left,a=s-this.top,h=Math.max(0,Math.floor(a/this.tileHeight)),l=Math.min(this.tilesHeight,Math.ceil((a+o)/this.tileHeight)),c=Math.max(0,Math.floor(r/this.tileWidth)),d=Math.min(this.tilesWidth,Math.ceil((r+n)/this.tileWidth));this.doMap||(this.doMap=V.setUp(),this.cachedDisplayObjects=V.setUp(),this.populate=this.populateTilesAndEntities),this.cachedDisplayObjects.push(e);for(let t=c;t<d;t++){this.doMap[t]||(this.doMap[t]=V.setUp());for(let i=h;i<l;i++)this.doMap[t][i]||(this.doMap[t][i]=V.setUp()),this.doMap[t][i].push(e)}t.removeFromParentContainer(),this.updateCache=!0}},uncacheSprite:function(t){const e=t.cacheRender;if(this.entityCache&&e){const{x:t,y:i,width:s,height:n}=e.getBounds(e.transformMatrix),o=this.cachedDisplayObjects.indexOf(e),r=t-this.left,a=i-this.top,h=Math.max(0,Math.floor(a/this.tileHeight)),l=Math.min(this.tilesHeight,Math.ceil((a+n)/this.tileHeight)),c=Math.max(0,Math.floor(r/this.tileWidth)),d=Math.min(this.tilesWidth,Math.ceil((r+s)/this.tileWidth));o>=0&&this.cachedDisplayObjects.splice(o,1);for(let t=c;t<d;t++)for(let i=h;i<l;i++)if(this.doMap?.[t]?.[i]){const s=this.doMap[t][i].indexOf(e);s>=0&&this.doMap[t][i].splice(s,1)}this.updateCache=!0}},convertCamera:function(t){const e=this.worldWidth/this.scaleX,i=e-t.width,s=this.worldHeight/this.scaleY,n=s-t.height,o=this.laxCam;e!==this.layerWidth&&i?o.moveX((t.left-this.left)*(this.layerWidth-t.width)/i+t.halfWidth+this.left):o.moveX(t.x),s!==this.layerHeight&&n?o.moveY((t.top-this.top)*(this.layerHeight-t.height)/n+t.halfHeight+this.top):o.moveY(t.y),t.width===o.width&&t.height===o.height||o.resize(t.width,t.height)},createTile:function(t){return"tile-1"===t?tc:Kl.setUp(this.tileSpriteSheet,t,this.uninitializedTiles)},createMap:function(t){if("string"!=typeof t[0][0])return t;{const e=V.setUp();for(let i=0;i<t.length;i++){e[i]=V.setUp();for(let s=0;s<t[i].length;s++)this.updateTile(t[i][s],e,i,s)}return e}},updateTile:function(t,e,i,s){const n=t.id??t,{tiles:o}=this,r=o[n];e[i][s]=r||null===r?r:o[n]=this.createTile(n)},createGrid:function(t){const{edgeBleed:e,edgesBleed:i}=this,s=this.cacheHeight,n=this.cacheWidth,o=this.cacheTilesHeight,r=this.cacheTilesWidth,a=this.scaleX,h=this.scaleY,l=this.tileHeight,c=this.tileWidth,d=this.tilesHeight,g=this.tilesWidth,y=V.setUp();let m=null,v=this.owner.z;for(let w=0;w<g;w+=r){const r=V.setUp();y.push(r);for(let y=0;y<d;y+=o){const o=Math.min(Jl((g-w)*c+i),n),b=Math.min(Jl((d-y)*l+i),s),x=p.create({width:o,height:b});x.frame=new u(e,e,((o-i)/c|0)*c+e,((b-i)/l|0)*l+e),m=new f(x),m.z=v,m.scale.x=a,m.scale.y=h,r.push(m),t.addChild(m),v-=1e-6}}return y},updateRegion:function(t){const{edgesBleed:e}=this,i=this.tileWidth*this.scaleX,s=this.tileHeight*this.scaleY,n=Math.min(this.tilesWidth,(this.cacheWidth-e)/i|0),o=Math.min(this.tilesHeight,(this.cacheHeight-e)/s|0);n||platypus.debug.warn('"'+this.owner.type+'" RenderTiles: The tiles are '+i+"px wide which is larger than "+(this.cacheWidth-e)+"px (maximum cache size of "+this.cacheWidth+"px minus a 2px edge bleed). Increase the maximum cache size or reduce tile size."),o||platypus.debug.warn('"'+this.owner.type+'" RenderTiles: The tiles are '+s+"px high which is larger than "+(this.cacheHeight-e)+"px (maximum cache size of "+this.cacheHeight+"px minus a 2px edge bleed). Increase the maximum cache size or reduce tile size."),this.cacheTilesWidth=n,this.cacheTilesHeight=o,this.cacheClipWidth=n*i,this.cacheClipHeight=o*s,this.tileCache&&(this.mapContainer.mask=(new a).rect(0,0,this.cacheClipWidth+t,this.cacheClipHeight+t).fill(0))},updateBufferRegion:function(t){const e=this.tileWidth*this.scaleX,i=this.tileHeight*this.scaleY;this.cacheTilesWidth=Math.min(this.tilesWidth,Math.ceil((t.width+2*this.buffer)/e),this.cacheWidth/e|0),this.cacheTilesHeight=Math.min(this.tilesHeight,Math.ceil((t.height+2*this.buffer)/i),this.cacheHeight/i|0),this.cacheClipWidth=this.cacheTilesWidth*e,this.cacheClipHeight=this.cacheTilesHeight*i,this.mapContainer.mask=(new a).rect(0,0,this.cacheClipWidth,this.cacheClipHeight).fill(0)},populateTiles:function(t,e){const i=V.setUp();this.tileContainer.removeChildren();for(let s=t.left;s<=t.right;s++)for(let n=t.top;n<=t.bottom;n++)if(!e||e.empty||n>e.bottom||n<e.top||s>e.right||s<e.left)for(let t=0;t<this.imageMap.length;t++){const e=this.imageMap[t][s][n].getNext();e&&(e.template&&i.push(e.template),e.x=(s+.5)*this.tileWidth,e.y=(n+.5)*this.tileHeight,this.tileContainer.addChild(e))}for(let t=0;t<i.length;t++)i[t].clear();V.recycle(i)},populateTilesAndEntities:function(t,e){const i=V.setUp(),s=V.setUp();this.tileContainer.removeChildren();for(let n=t.left;n<=t.right;n++)for(let o=t.top;o<=t.bottom;o++)if(!e||e.empty||o>e.bottom||o<e.top||n>e.right||n<e.left){for(let t=0;t<this.imageMap.length;t++){const e=this.imageMap[t][n][o].getNext();e&&(e.template&&s.push(e.template),e.x=(n+.5)*this.tileWidth,e.y=(o+.5)*this.tileHeight,this.tileContainer.addChild(e))}if(this.doMap[n]&&this.doMap[n][o]){const t=this.doMap[n][o];for(let e=0;e<t.length;e++)t[e].drawn||(t[e].drawn=!0,i.push(t[e]))}}if(this.mapContainer.removeChildren(),this.mapContainer.addChild(this.tileContainer),i.length){i.sort($l);for(let t=0;t<i.length;t++){const e=i[t];delete e.drawn,this.mapContainer.addChild(e),e.mask&&this.mapContainer.addChild(e.mask)}}for(let t=0;t<s.length;t++)s[t].clear();V.recycle(s),V.recycle(i)},renderCache:function(t,e,i,s,n,o){const{renderer:r}=this;n&&o&&!o.empty&&(n.x=o.left*this.tileWidth,n.y=o.top*this.tileHeight,i.addChild(n)),i.x=-t.left*this.tileWidth,i.y=-t.top*this.tileHeight,r.render({container:s,target:e}),e.requiresUpdate=!0},renderCacheClear:function(t,e,i,s){const{renderer:n}=this;i.x=-t.left*this.tileWidth,i.y=-t.top*this.tileHeight,n.render({container:s,target:e,clear:!0}),e.requiresUpdate=!0},renderCacheWithExtrusion:function(t,e,i,s){const n=new a,{renderer:o}=this,r={container:s,target:e};n.rect(.5,.5,this.cacheClipWidth+1,this.cacheClipHeight+1),n.stroke({width:1,color:0}),s.mask=n,i.x=-t.left*this.tileWidth,i.y=-t.top*this.tileHeight+1,o.render(r),i.x=-t.left*this.tileWidth+1,i.y=-t.top*this.tileHeight,o.render(r),i.x=-t.left*this.tileWidth+2,i.y=-t.top*this.tileHeight+1,o.render(r),i.x=-t.left*this.tileWidth+1,i.y=-t.top*this.tileHeight+2,o.render(r),s.mask=null,i.x=-t.left*this.tileWidth+1,i.y=-t.top*this.tileHeight+1,o.render(r),e.requiresUpdate=!0},toJSON:function(){const t=this.imageMap[0],e=[];let i=t.length;for(;i--;){let s=t[i].length;for(e[i]=[];s--;)e[i][s]=t[i][s].id}return{type:"RenderTiles",buffer:this.buffer,cacheAll:this.cacheAll,entityCache:this.entityCache,imageMap:e,maximumBuffer:this.maximumBuffer,scaleX:this.scaleX,scaleY:this.scaleY,spriteSheet:this.spriteSheet,tileCache:this.tileCache,tileHeight:this.tileHeight,tileWidth:this.tileWidth,top:this.top,left:this.left}},destroy:function(){const t=this.cacheGrid,e=this.doMap,i=this.imageMap,s=Object.keys(this.tiles),{length:n}=s;if(t){for(let e=0;e<t.length;e++)for(let i=0;i<t[e].length;i++)t[e][i].texture.destroy(!0),this.container.removeChild(t[e][i]);V.recycle(t,2),delete this.cacheGrid}else this.tilesSprite?(this.tilesSprite.texture.alternate&&this.tilesSprite.texture.alternate.destroy(!0),this.tilesSprite.texture.destroy(!0),this.container.removeChild(this.tilesSprite)):this.container.removeChild(this.mapContainer);V.recycle(i,2);for(let t=0;t<n;t++)this.tiles[s[t]].destroy();if(this.tiles=null,this.container=null,this.tilesSprite=null,this.spriteSheet.recycleSpriteSheet(),e){for(let t=0;t<this.cachedDisplayObjects.length;t++)this.cachedDisplayObjects[t].destroy();V.recycle(this.cachedDisplayObjects);for(let t=0;t<e.length;t++)if(e[t]){for(let i=0;i<e[t].length;i++)e[t][i]&&V.recycle(e[t][i]);V.recycle(e[t])}V.recycle(e)}this.laxCam.recycle(),this.cache.recycle(),this.cachePixels.recycle(),V.recycle(this.uninitializedTiles),this.teardown?.()}},publicMethods:{getMapDimensions:function(){return{tilesWidth:this.tilesWidth,tilesHeight:this.tilesHeight,layerWidth:this.layerWidth,layerHeight:this.layerHeight}},getTileAt:function(t,e,i){return this.imageMap[i][t][e]},getRootTileIndex:function(t){let e=t;return"string"==typeof t&&(e=+t.slice(4)),536870911&e},getTileVariants:function(t){const e=2147483648,i=1073741824,s=536870912;let n=this.getRootTileIndex(t);return[n,n+e,n+i,n+s,n+e+i,n+e+s,n+i+s,n+e+i+s]}},getAssetList:function(){const t=function(e,i){if(e){if("string"==typeof e)return t(i[e],i);if(e.images)return Z(e.images)}return V.setUp()};return function(e,i,s){const n=platypus.game.settings.spriteSheets,o=e?.spriteSheet??i?.spriteSheet??s?.spriteSheet;if(o){if("string"==typeof o&&"import"!==o)return t(o,n);if(Array.isArray(o)){const e=V.setUp();let i=o.length;for(;i--;){const s=t(o[i],n);F(e,s),V.recycle(s)}return e}if(o.images)return Z(o.images)}return V.setUp()}}()}),sc=xt({id:"SceneChanger",properties:{loadLayers:null,scene:"",unloadLayers:null,persistentData:null},initialize:function(){this.persistentData=H.setUp(this.persistentData)},events:{"new-scene":function(t){const e=t&&t.loadLayers||this.loadLayers,i=t&&t.scene||this.scene,s=t&&t.unloadLayers||this.unloadLayers,n=t&&t.persistentData||this.persistentData;if(s&&s.length)for(let t=0;t<s.length;t++)platypus.game.unload(s[t]);e&&e.length&&platypus.game.load(e,n),i&&platypus.game.loadScene(i,n)},"set-scene":function(t){this.scene=t},"set-persistent-scene-data":function(t){const e=this.persistentData,i=Object.keys(t),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];e[s]=t[s]}}},methods:{destroy:function(){}}}),nc=function(){this.active--},oc=function(){this.active++},rc=xt({id:"Timeline",properties:{executionFlow:"parallel",timelines:{}},initialize:function(){const t=Object.keys(this.timelines),{length:e}=t;this.timelineInstances=V.setUp();for(let i=0;i<e;i++){const e=t[i];this.addTimeline(e,this.timelines[e])}},events:{"handle-logic":function(t){const{executionFlow:e,owner:i,timelineInstances:s}=this,n=t.delta;let o=s.length,r=!1;for(;o--;){const t=s[o];t.remove?(G(s,o),t.timeline.recycle(),t.recycle(),r=!0):t.active&&(0===t.timeline.list.length?(G(s,o),t.timeline.recycle(),t.recycle(),r=!0):this.progressTimeline(t,n))}if(s.length){if(r&&"serial"===e){const t=s[0];t.active||t.play()}i.triggerEvent("timeline-progress",s)}},"pause-timelines":function(){this.timelineInstances.forEach(t=>{t.active&&t.pause()})},"play-timelines":function(){const{executionFlow:t,timelineInstances:e}=this;if("serial"===t){if(e.length){const t=e[0];t.active||t.play()}}else e.forEach(t=>{t.active||t.play()})},"stop-active-timelines":function(){const t=this.timelineInstances;let e=t.length;for(;e--;)t[e].active&&(t[e].remove=!0)},"stop-all-timelines":function(){const t=this.timelineInstances;let e=t.length;for(;e--;)t[e].remove=!0},"add-timeline":function(t,e){this.addTimeline(t,e)},"start-timeline":function(t){this.startTimeline(t)}},methods:{addTimeline:function(t,e){this.addEventListener(t,()=>this.startTimeline(e))},createTimeStampedTimeline:function(t,e=1){const i=It.setUp(t);return H.setUp("timeline",i,"time",0,"total",i.getDuration(),"active",1,"pause",nc,"play",oc,"remove",!1)},startTimeline(t){const{executionFlow:e,timelineInstances:i}=this;switch(e){case"serial":return i.push(this.createTimeStampedTimeline(t),i.some(({active:t})=>t)?0:1),!0;case"exclusive":return i.forEach(t=>t.remove=!0),i.push(this.createTimeStampedTimeline(t)),!0;case"tentative":return!i.some(({active:t})=>t)&&(i.push(this.createTimeStampedTimeline(t)),!0);default:return i.push(this.createTimeStampedTimeline(t)),!0}},progressTimeline(t,e){const i=t.timeline;t.time+=e,i.getEvents(t.time).forEach(e=>{const{event:i,entity:s}=e;if("function"==typeof i)i(this.owner,t);else{let t=this.owner;s&&(t="string"==typeof s?this.owner.getEntityById?this.owner.getEntityById(s):this.owner.parent.getEntityById(s):s,t||(platypus.debug.warn("No entity of that id"),t=this.owner)),t.trigger(e)}e.recycle()})},destroy:function(){const t=this.timelineInstances;let e=t.length;for(;e--;){const i=t[e];i.timeline.recycle(),i.recycle()}V.recycle(t),this.timelineInstances=null}},publicMethods:{wait(t){return new Promise((e,i)=>{this.startTimeline([t,e])||i()})}}}),ac=function(t){t.type in this.watchedEntities&&this.watchedEntities[t.type].push(t)},hc=function(t){const e=this.watchedEntities[t.type];for(let i=e.length-1;i>=0;i--)if(e[i]===t){e.splice(i,1);break}},lc=xt({id:"Tutorial",properties:{tutorialDefs:[]},initialize:function(){this.playing=null,this.theQueue=[],this.watchedEntities={},this.tutorials=[];for(let t=0;t<this.tutorialDefs.length;t++){const e=this.tutorialDefs[t];if(e.events){const t={events:Z(e.events),originalEvents:Z(e.events),priority:e.priority||0,queue:e.queue||!1,timesToReplay:"number"==typeof e.timesToReplay?e.timesToReplay:1/0,replayDelay:e.replayDelay||null,replayDelayTimer:e.replayDelay||null,level:e.level,requirements:{}},i=Object.keys(e.requirements),{length:s}=i;for(let n=0;n<s;n++){const s=i[n];t.requirements[s]=Z(e.requirements[s]),this.watchedEntities[s]||(this.watchedEntities[s]=[])}this.tutorials.push(t)}else platypus.debug.warn("Tutorial definition lacks events.")}},events:{"child-entity-added":ac,"peer-entity-added":ac,"child-entity-removed":hc,"peer-entity-removed":hc,"handle-logic":function(t){const e=t.delta;let i=null,s=-1;for(let t=0;t<this.tutorials.length;t++){const n=this.tutorials[t];let o=!1;if(this.playing||0!==this.theQueue.length?(!this.playing&&this.theQueue.length>0&&n.priority>this.theQueue[0].priority||this.playing&&this.playing.priority<n.priority||n.queue)&&(o=!0):o=!0,o&&this.checkRequirements(n.requirements)){if(n.replayDelay&&n.replayDelayTimer>0&&(n.replayDelayTimer-=e,n.replayDelayTimer>0))continue;(!i||i.priority<n.priority)&&(i=n,s=t)}}if(i){const t=this.tutorials.splice(s,1)[0];this.playing?t.priority>this.playing.priority?(this.owner.triggerEvent("stop-audio"),this.play(t)):this.queue(t):this.theQueue.length>0?t.priority>this.theQueue[0].priority?this.play(t):(this.play(this.theQueue.splice(0,1)[0]),this.queue(t)):this.play(t)}else!this.playing&&this.theQueue.length>0&&this.play(this.theQueue.splice(0,1)[0])},"sequence-complete":function(){this.playing.timesToReplay>=0&&this.tutorials.push(this.playing),this.playing=null}},methods:{play:function(t){this.playing=t,0===this.playing.events.length&&(this.playing.events=Z(this.playing.originalEvents)),this.owner.triggerEvent(this.playing.events.splice(Math.floor(Math.random()*this.playing.events.length),1)[0]),t.timesToReplay-=1,t.replayDelayTimer=t.replayDelay},queue:function(t){let e=!1;for(let i=0;i<this.theQueue.length;i++)if(this.theQueue[i].priority<t.priority){this.theQueue.splice(i,0,t),e=!0;break}e||this.theQueue.push(t)},checkRequirements:function(t){const e=Object.keys(t),{length:i}=e;for(let s=0;s<i;s++){const i=e[s],n=t[i];let o=!0;for(let t=this.watchedEntities[i].length-1;t>=0;t--){const e=this.watchedEntities[i][t];o=!0;for(let t=0;t<n.length;t++)if(!e.state.get(n[t])){o=!1;break}if(o)break}if(!o)return!1}return!0},destroy:function(){this.watchedEntities=null,this.theQueue=null,this.playing=null,this.tutorials=null}}}),cc=T.Easing,dc=T.Group,uc=T.Interpolation,pc=T.Tween,gc=function(){const t={},e=Object.keys(cc),{length:i}=e;for(let s=0;s<i;s++){const i=e[s],n=Object.keys(cc[i]),{length:o}=n;for(let e=0;e<o;e++){const s=n[e];t[i+"."+s]=cc[i][s]}}return t}(),fc=xt({id:"Tween",properties:{events:null},initialize:function(){const t=this.events;this.group=new dc,this.time=0,this.paused=!1,t&&Object.keys(t).forEach(e=>this.addEventListener(e,i=>{const s=t[e],n=Array.isArray(s);typeof i==typeof s&&Array.isArray(i)===n?n?this.runTween([...s,...i]):this.runTween({...s,...i}):this.runTween(s)}))},events:{tween:function(t){this.runTween(t)},"handle-logic":function(t){this.paused||(this.time+=t.delta,this.group.update(this.time))},"stop-tween":function(){this.group.removeAll()},"pause-tween":function(){this.paused=!0},"unpause-tween":function(){this.paused=!1}},methods:{createTween:function(t,e){const i=this.owner,s=t.target?"string"==typeof t.target?i.get(t.target)??i.parent.get(t.target):t.target:i;if(s){if(t.to&&t.time){const n=new pc(s,this.group);if(n.to(t.to,t.time),t.onUpdate&&n.onUpdate("function"!=typeof t.onUpdate?(...e)=>i.trigger(t.onUpdate,...e):t.onUpdate),t.onStart&&n.onStart("function"!=typeof t.onStart?(...e)=>i.trigger(t.onStart,...e):t.onStart),t.onStop&&n.onStop("function"!=typeof t.onStop?(...e)=>i.trigger(t.onStop,...e):t.onStop),t.onComplete&&n.onComplete(()=>{n.stop(),t.onComplete&&("function"!=typeof t.onComplete?i.trigger(t.onComplete):t.onComplete())}),t.onRepeat&&n.onRepeat("function"!=typeof t.onRepeat?(...e)=>i.trigger(t.onRepeat,...e):t.onRepeat),t.chain&&(e?"string"==typeof t.chain?this.events[t.chain]?n.chain(this.createTweens(this.events[t.chain])):platypus.debug.warn(`Component Tween: ignoring chain on tween since there is no tween event trigger "${t.chain}".`):n.chain(t.chain):platypus.debug.warn("Component Tween: ignoring `chain` on tween since it is part of an array of tweens.")),t.repeat&&n.repeat(t.repeat),t.yoyo&&n.yoyo(!0),t.delay&&n.delay(t.delay),void 0!==t.repeatDelay&&n.repeatDelay(t.repeatDelay),t.interpolation&&("function"==typeof t.interpolation?n.interpolation(t.interpolation):uc[t.interpolation]?n.interpolation(uc[t.interpolation]):platypus.debug.warn('Component Tween: "'+t.interpolation+'" is not a valid interpolation value; must be "Linear", "Bezier", or "CatmullRom".')),t.easing)if("function"==typeof t.easing)n.easing(t.easing);else if(gc[t.easing])n.easing(gc[t.easing]);else{const e='", or "',i='", "';platypus.debug.warn(`Component Tween: "${t.easing}" is not a valid easing value; must be ${Object.keys(gc).reduce((t,s,n)=>`${0===n?e:i}${s}${t}`,'".').substring(3)}`)}return n}return platypus.debug.warn("Component Tween: Both `time` and `to` must be specified to create tween."),null}return platypus.debug.warn("Component Tween: Could not find entity as specified by `target` - "+t.target),null},createTweens:function(t){if(Array.isArray(t)){let e=t.length,i=null;for(;e--;){const s=this.createTween(t[e],!i);i&&s.chain(i),i=s}return i}return this.createTween(t,!0)},destroy:function(){this.group.removeAll()},runTween:function(t){const e=this.createTweens(t);e?e.start(this.time):platypus.debug.warn("Component Tween: Unable to run requested tween.",t)}}}),yc=function(t,e){return" "===e?t+"default":t+e},mc=function(t,e=[],i,s){const n="string"==typeof t?t:"string"==typeof t.sound?t.sound:"",o=n?{}:t.sound,r={sound:n,events:[...t.events??[]],...o},a=t.voice,h=t.mouthCues??platypus.game.settings.mouthCues?.[r.sound]??platypus.game.settings.mouthCues?.[r.sound.substring(r.sound.lastIndexOf("/")+1)];if(a){let t=null,e=0;a+=" ";for(let n=0;n<a.length;n++){const o=a[n];o!==t&&(t=o,r.events.push({time:e,event:yc(i,o)})),e+=s}}else if(h)if("number"==typeof h[0]){const t=h.length/2|0;for(let e=0;e<t;e++){const t=2*e;r.events.push({time:1e3*h[t],event:yc(i,h[t+1])})}}else for(let t=0;t<h.length;t++){const e=h[t];r.events.push({time:1e3*e.start,event:yc(i,e.value)})}return r},vc=function(t,e,i,s){return e[" "]||(e[" "]=e.default),Array.isArray(t)?t.map(t=>"number"==typeof t||"function"==typeof t?t:mc(t,e,i,s)):mc(t,e,i,s)},wc=xt({id:"VoiceOver",properties:{aliases:null,animationMap:{default:"default"},renderComponent:"RenderSprite",frameLength:100,messagePrefix:"",voiceOverMap:null,generatedVoiceOverMaps:null,acceptInput:null,animation:null,flip:null,hidden:null,interactive:null,mask:null,mirror:null,offsetZ:null,regX:null,regY:null,restart:null,scaleX:null,scaleY:null,spriteSheet:null,stateBased:null},initialize:function(t,e){const{aliases:i,acceptInput:s,animation:n,animationMap:o,flip:r,hidden:a,interactive:h,mask:l,messagePrefix:c,mirror:d,offsetZ:u,owner:p,regX:g,regY:f,renderComponent:y,restart:m,scaleX:v,scaleY:w,spriteSheet:b,stateBased:x,voiceOverMap:_={}}=this,C=Object.keys(o),{length:k}=C,E=(t,e)=>new Promise(i=>{p.addComponent(new t(p,e,i))}),A=Object.keys(_),{length:S}=A,M={audioMap:{},aliases:i},T={acceptInput:s,aliases:i,animation:n,animationMap:{},eventBased:!0,flip:r,hidden:a,interactive:h,mask:l,mirror:d,offsetZ:u,regX:g,regY:f,restart:m,scaleX:v,scaleY:w,spriteSheet:b,stateBased:x};this.message=c?`${c}-`:"",this.relayLipSyncEvents=({descriptor:t,content:e})=>{"lipsync"===t&&this.owner.triggerEvent(yc(this.message,e))},platypus.game.voPlayer.on("lyric",this.relayLipSyncEvents);for(let t=0;t<k;t++){const e=C[t];T.animationMap[yc(this.message,e)]=o[e]}if(T.animationMap.default=this.animationMap.default,this.generatedVoiceOverMaps){const t=(t,e,i)=>{if(!this.voiceOverMap[t]){const s=i.initialDelay||0,n=i.endEventTime||99999,o=i.onEndEvent||"";this.voiceOverMap[t]=[s,{sound:{sound:e,events:[{event:o,time:n}]}}]}};for(let e=0;e<this.generatedVoiceOverMaps.length;e++){const i=this.generatedVoiceOverMaps[e],s=i.eventPrefix||"vo-",n=i.audio;if(Array.isArray(n))for(let e=0;e<n.length;e++){const o=n[e];t(`${s}${o}`,o,i)}else Object.keys(n).forEach(e=>t(`${s}${e}`,n[e],i))}}for(let t=0;t<S;t++){const e=A[t];M.audioMap[e]=vc(_[e],o,this.message,this.frameLength)}return Promise.all([E("string"==typeof this.renderComponent?platypus.components[this.renderComponent]:this.renderComponent,T),E(bi,M)]).then(e),!0},methods:{destroy(){platypus.game.voPlayer.off("lipsync",this.relayLipSyncEvents)}},events:{"play-voice-over-with-lip-sync":function(t){this.owner.triggerEvent("play-voice-over",vc(t,this.animationMap,this.message,this.frameLength))}},getAssetList:function(t,e,i){const s=t?.spriteSheet??e?.spriteSheet??i?.spriteSheet,n=t?.voiceOverMap??e?.voiceOverMap??i?.voiceOverMap,o=bi.getAssetList({audioMap:n});return"string"==typeof s?[...Z(platypus.game.settings.spriteSheets[s].images),...o]:s?[...Z(s.images),...o]:o}}),bc=window.XMLHttpRequest,xc=xt({id:"XHR",properties:{method:"GET",path:"",responseType:"text",withCredentials:!1},initialize:function(t){this.setProperties(t)},events:{request:function(t){if(this.setProperties(t),"GET"===this.method)this.get();else{if("POST"!==this.method)throw"Method must be GET or POST";this.post()}}},methods:{setProperties:function(t={}){this.method=t.method??this.method??"GET",this.path=t.path??this.path??null,this.responseType=t.responseType??this.responseType??"text",this.withCredentials=t.withCredentials??this.withCredentials??!1,this.data=t.data?new URLSearchParams(t.data).toString():"",this.onload=t.onload??this.onload??(()=>{200===this.status&&this.owner.triggerEvent("response",this.responseText)})},get:function(){const t=new bc,e=this.data?`${this.path}?${this.data}`:this.path;t.open(this.method,e,!0),t.withCredentials=this.withCredentials,t.responseType=this.responseType,t.onload=this.onload,t.send()},post:function(){const t=new bc;t.open(this.method,this.path,!0),t.withCredentials=this.withCredentials,t.responseType=this.responseType,t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),t.onload=this.onload,t.send(this.data)}}}),_c=I.g.platypus={createComponentClass:xt,components:D},Cc=navigator.userAgent.toLowerCase(),kc=Cc.search("edge")>-1,Ec=Cc.search("ipod")>-1,Ac=Cc.search("iphone")>-1,Sc=Cc.search("ipad")>-1||Cc.search("mac")>-1&&navigator.maxTouchPoints>2&&!Ac,Mc=Cc.search("android")>-1,Tc=Cc.search("silk")>-1,Uc=Ec||Ac||Sc,Pc=Uc||Mc||Tc,Oc=Pc?(()=>{const t=document.createElement("ul"),e=document.createElement("button");let i=!0;return t.style.display="none",t.id="platypus-logging",t.classList.add("platypus-debugging"),document.body.appendChild(t),e.style.display="none",e.id="toggle-platypus-debugging",e.innerText="log",e.addEventListener("click",()=>{"none"===t.style.display?(t.style.display="block",e.innerText="X"):(t.style.display="none",e.innerText="log")}),document.body.appendChild(e),(s,...n)=>{const o=document.createElement("li");o.classList.add(s),n.forEach(t=>{const e=document.createElement("span");e.innerText=t,o.appendChild(e)}),t.appendChild(o),i&&(i=!1,e.style.display="block")}})():()=>{},Lc=function(t,...e){_c.game?.settings?.debug&&(A.log(t,...e),Oc(t,...e))};_c.supports={touch:"undefined"!==window.ontouchstart,edge:kc,iPod:Ec,iPhone:Ac,iPad:Sc,safari:Cc.search("safari")>-1&&!kc,ie:Cc.search("msie")>-1||Cc.search("trident")>-1,firefox:Cc.search("firefox")>-1,android:Mc,chrome:Cc.search("chrome")>-1&&!kc,silk:Tc,iOS:Uc,mobile:Pc,desktop:!Pc},_c.debug={general:Lc.bind(null,"log"),log:Lc.bind(null,"log"),warn:Lc.bind(null,"warn"),debug:Lc.bind(null,"debug"),error:Lc.bind(null,"error")},_c.assetCache=new class{constructor(){this.assets=et.setUp(),this.counts=H.setUp()}delete(t){const e=this.assets;if(e.has(t)){const i=this.counts;if(i[t]-=1,0===i[t]){const i=e.get(t);i&&i.src&&(i.src=""),e.delete(t)}return!i[t]}return!1}get(t){return this.assets.get(t)}getFileId(t){const e=t.match(it);return e?e[1]:t}has(t){return this.assets.has(t)}set(t,e,i=1){const s=this.assets,n=this.counts;s.has(t)?n[t]+=i:(s.set(t,e),n[t]=i)}async load(t,e,s){const n=this.counts,o=V.setUp(),r=H.setUp();(platypus.game?.options?.images??platypus.game?.options?.audio)&&platypus.debug.warn("AssetManager: Default asset folders are no longer specified via game options. Include pathing in asset imports."),i.setPreferences({preferCreateImageBitmap:!1,preferWorker:!1});for(let e=0;e<t.length;e++){const i=st(t[e]),s=i.alias?.[0]??i.id??i.src??i;this.has(s)?n[s]+=1:r.hasOwnProperty(s)?r[s]+=1:(r[s]=1,o.push(i))}if(o.length){o.forEach(t=>i.add(t));const t=o.map(t=>t.alias[0]),n=await i.load(t,e);t.forEach(t=>{const e=n[t];this.set(t,e,r[t])}),s&&s()}else setTimeout(()=>{e&&e(1),s&&s()},1);V.recycle(o)}unload(t){let e=t.length;for(;e--;)this.delete(t[e].alias?.[0]??t[e].id??t[e])}},_c.version="4.1.5",_c.Game=Nt;const zc=_c;export{Ci as AABB,os as ActionState,C as Application,Je as Capsule,We as Circle,ps as CollisionData,ys as CollisionDataContainer,Ri as CollisionShape,vt as Component,H as Data,et as DataMap,Qe as Ellipse,kt as Entity,Nt as Game,ut as Messenger,Wl as PIXIAnimation,Ne as Point,Ze as Polygon,Fe as Polyline,Qh as RandomSet,qe as Rectangle,Ke as RoundedRectangle,Ve as Segment,mt as StateMap,Ht as Vector,V as arrayCache,D as components,xt as createComponentClass,zc as default,Z as greenSlice,G as greenSplice,pt as greenSplit,N as recycle,ni as shapeFromBox2D,ei as shapeFromObject,oi as shapeFromPixiGraphics,ai as shapeFromPixiShape,je as shapeToBox2D,Le as shapeToPixiGraphics,Te as shapeToPixiShape,F as union};