Files
GdevelopMMOTestv1/Export/scenestack.js
T

3 lines
6.4 KiB
JavaScript

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._stack.length;++e)this._stack[e].onGameResolutionResized()}step(e){if(this._throwIfDisposed(),this._isNextLayoutLoading||this._stack.length===0)return!1;if(this.applyUpdateFromNetworkSyncDataIfAny())return h.info("Scene stack has been updated from network sync data, skipping step."),!0;const t=this._stack[this._stack.length-1];if(t.renderAndStep(e)){const s=t.getRequestedChange();if(s===r.SceneChangeRequest.STOP_GAME)return this._runtimeGame.getRenderer().stopGame(),!0;s===r.SceneChangeRequest.POP_SCENE?this.pop():s===r.SceneChangeRequest.PUSH_SCENE?this.push(t.getRequestedScene()):s===r.SceneChangeRequest.REPLACE_SCENE||s===r.SceneChangeRequest.CLEAR_SCENES?this.replace(t.getRequestedScene(),s===r.SceneChangeRequest.CLEAR_SCENES):l.error("Unrecognized change in scene stack: "+s)}return!0}renderWithoutStep(){this._throwIfDisposed();const e=this.getCurrentScene();return e?(e.render(),!0):!1}pop(e=1){this._throwIfDisposed();let a=!1;for(let t=0;t<e&&!(this._stack.length<=1);++t){a=!0;const s=this._stack.pop();if(!s)return;this._unloadSceneAndPossiblyResources({scene:s,newSceneName:null})}if(a){const t=this._stack[this._stack.length-1];t&&t.onResume()}}push(e,a){this._throwIfDisposed();const t=typeof e=="string"?e:e.sceneName,s=typeof e=="string"?void 0:e.getExcludedObjectNames,o=typeof e=="string"?!1:e.skipStoppingSoundsOnStartup,n=typeof e=="string"?!1:e.skipCreatingInstances,c=a||(typeof e=="string"?void 0:e.externalLayoutName),i=this._stack[this._stack.length-1];return i&&i.onPause(),this._runtimeGame.areSceneAssetsReady(t)?this._loadNewScene({sceneName:t,externalLayoutName:c,getExcludedObjectNames:s,skipStoppingSoundsOnStartup:o,skipCreatingInstances:n}):(this._isNextLayoutLoading=!0,this._runtimeGame.loadSceneAssets(t).then(()=>{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;o<this._stack.length;++o){const n=this._stack[o];s.push({name:n.getName(),networkId:n.getOrCreateNetworkId()})}return s}updateFromNetworkSyncData(e){this._sceneStackSyncDataToApply=e}applyUpdateFromNetworkSyncDataIfAny(e){this._throwIfDisposed();const a=this._sceneStackSyncDataToApply;let t=!1;if(!a)return t;this._sceneStackSyncDataToApply=null;const s=e&&e.getExcludedObjectNames,o=!!e&&!!e.preventSoundsStoppingOnStartup;if(e&&e.clearSceneStack){for(;this._stack.length!==0;){let n=this._stack.pop();n&&n.unloadScene()}for(let n=0;n<a.length;++n){const c=a[n],i=this.push({sceneName:c.name,getExcludedObjectNames:s,skipStoppingSoundsOnStartup:o});i&&(i.networkId=c.networkId)}return t=!0,t}for(let n=0;n<a.length;++n){const c=a[n],i=this._stack[n];if(!i){h.info(`Scene at position ${n} with name ${c.name} is missing from the stack, adding it.`);const u=this.push({sceneName:c.name,getExcludedObjectNames:s});u&&(u.networkId=c.networkId),t=!0;continue}if(i.getName()!==c.name){h.info(`Scene at position ${n} and name ${i.getName()} is not the same as the expected ${c.name}, 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(!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