Files

3 lines
6.4 KiB
JavaScript
Raw Permalink Normal View History

2026-07-28 10:47:32 -04:00
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
//# sourceMappingURL=scenestack.js.map