var gdjs;(function(r){const l=new r.Logger("Scene stack"),h=new r.Logger("Scene stack - Debug");r.Logger.getDefaultConsoleLoggerOutput().discardGroup("Scene stack - Debug");class d{constructor(e){this._stack=[];this._wasFirstSceneLoaded=!1;this._isNextLayoutLoading=!1;this._sceneStackSyncDataToApply=null;this._wasDisposed=!1;if(!e)throw"SceneStack must be constructed with a gdjs.RuntimeGame.";this._runtimeGame=e}onGameResolutionResized(){for(let e=0;e{this._loadNewScene({sceneName:t,externalLayoutName:c,getExcludedObjectNames:s,skipStoppingSoundsOnStartup:o,skipCreatingInstances:n}),this._isNextLayoutLoading=!1}),null)}_loadNewScene(e){this._throwIfDisposed();const a=new r.RuntimeScene(this._runtimeGame);if(a.loadFromScene(this._runtimeGame.getSceneAndExtensionsData(e.sceneName),{excludedObjectNames:e.getExcludedObjectNames?e.getExcludedObjectNames(a):void 0,skipStoppingSoundsOnStartup:e.skipStoppingSoundsOnStartup,skipCreatingInstances:e.skipCreatingInstances}),this._wasFirstSceneLoaded=!0,e.externalLayoutName){const t=this._runtimeGame.getExternalLayoutData(e.externalLayoutName);t&&a.createObjectsFrom(t.instances,0,0,0,!0)}return this._stack.push(a),a}replace(e,a){const t=a||typeof e=="string"?!1:e.clear,s=typeof e=="string"?e:e.sceneName;if(this._throwIfDisposed(),t)for(;this._stack.length!==0;){let o=this._stack.pop();o&&this._unloadSceneAndPossiblyResources({scene:o,newSceneName:s})}else if(this._stack.length!==0){let o=this._stack.pop();o&&this._unloadSceneAndPossiblyResources({scene:o,newSceneName:s})}return this.push(e)}getCurrentScene(){return this._throwIfDisposed(),this._stack.length===0?null:this._stack[this._stack.length-1]}wasFirstSceneLoaded(){return this._wasFirstSceneLoaded}getAllScenes(){return this._throwIfDisposed(),this._stack}getAllSceneNames(){return this._throwIfDisposed(),this._stack.map(e=>e.getName())}getNetworkSyncData(e){const a=e.playerNumber,t=e.isHost;if(a!==void 0&&!t)return null;const s=[];for(let o=0;on+1&&(h.info(`Unloading ${this._stack.length-(n+1)} scenes after position ${n}.`),this.pop(this._stack.length-(n+1)));const u=this.replace({sceneName:c.name,clear:!1,getExcludedObjectNames:s});u&&(u.networkId=c.networkId),t=!0;continue}if(!i.networkId&&c.networkId&&c.name===i.getName()){h.info(`Scene at position ${n} and name ${i.getName()} has no networkId, let's assume it's the right one and reconcile it with the id ${c.networkId}.`),i.networkId=c.networkId;continue}if(i.networkId!==c.networkId){h.info(`Scene at position ${n} and name ${i.getName()} has a different networkId ${i.networkId} than the expected ${c.networkId}, replacing it.`),this._stack.length>n+1&&(h.info(`Unloading ${this._stack.length-(n+1)} scenes after position ${n}.`),this.pop(this._stack.length-(n+1)));const u=this.replace({sceneName:c.name,clear:!1,getExcludedObjectNames:s});u&&(u.networkId=c.networkId),t=!0;continue}}if(this._stack.length>a.length){const n=this._stack.length-a.length;this.pop(n),t=!0}return t}dispose(){for(;this._stack.length>0;){const e=this._stack.pop();e&&this._unloadSceneAndPossiblyResources({scene:e,newSceneName:null})}this._wasDisposed=!0}_unloadSceneAndPossiblyResources({scene:e,newSceneName:a}){const t=e.getName(),s=e.getResourcesUnloading(),n=(s==="inherit"?this._runtimeGame.getSceneResourcesUnloading():s)==="at-scene-exit"&&a!==e.getName()&&this._stack.every(c=>c.getName()!==t);e.unloadScene(),n&&this._runtimeGame.getResourceLoader().unloadSceneResources({unloadedSceneName:t,newSceneName:a})}_throwIfDisposed(){if(this._wasDisposed)throw"The scene stack has been disposed and should not be used anymore."}}r.SceneStack=d})(gdjs||(gdjs={})); //# sourceMappingURL=scenestack.js.map