Files
moon-gaming/games/New folder/runtimegame.js
T
2023-11-23 20:37:33 +00:00

3 lines
11 KiB
JavaScript

var gdjs;(function(a){const d=new a.Logger("Game manager"),h=(o,e,t)=>{if(o.startsWith("data:")||o.startsWith("blob:"))return o;const s=o.indexOf("?")===-1?"?":"&";return o+s+e+"="+t},l=o=>o.startsWith("https://project-resources.gdevelop.io/")||o.startsWith("https://project-resources-dev.gdevelop.io/");class c{constructor(e){this._runtimeGame=e}getFullUrl(e){const{gdevelopResourceToken:t}=this._runtimeGame._options;return!t||!l(e)?e:h(e,"gd_resource_token",encodeURIComponent(t))}checkIfCredentialsRequired(e){return this._runtimeGame._options.gdevelopResourceToken?!1:!!l(e)}}a.RuntimeGameResourcesLoader=c;class _{constructor(e,t){this._notifyScenesForGameResolutionResize=!1;this._paused=!1;this._hasJustResumed=!1;this._sessionMetricsInitialized=!1;this._disableMetrics=!1;this.loadAllAssetsAsync=async e=>{try{const t=new a.LoadingScreenRenderer(this.getRenderer(),this._imageManager,this._data.properties.loadingScreen),s=this._data.resources.resources.length;let i=0;const n=(r,u)=>{const g=Math.floor(100*(i+r)/s);t.setPercent(g),e&&e(g)};i+=await this._imageManager.loadTextures(n),i+=await this._soundManager.preloadAudio(n),i+=await this._fontManager.loadFonts(n),i+=await this._jsonManager.preloadJsons(n),i+=await this._model3DManager.loadModels(n),await this._bitmapFontManager.loadBitmapFontData(n),await t.unload(),await a.getAllAsynchronouslyLoadingLibraryPromise()}catch(t){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(t),t}};this._options=t||{},this._variables=new a.VariablesContainer(e.variables),this._data=e,this._resourcesLoader=new a.RuntimeGameResourcesLoader(this);const s=this._data.resources.resources;this._imageManager=new a.ImageManager(s,this._resourcesLoader),this._soundManager=new a.SoundManager(s,this._resourcesLoader),this._fontManager=new a.FontManager(s,this._resourcesLoader),this._jsonManager=new a.JsonManager(s,this._resourcesLoader),this._bitmapFontManager=new a.BitmapFontManager(s,this._resourcesLoader,this._imageManager),this._model3DManager=new a.Model3DManager(s,this._resourcesLoader),this._effectsManager=new a.EffectsManager,this._maxFPS=this._data.properties.maxFPS,this._minFPS=this._data.properties.minFPS,this._gameResolutionWidth=this._data.properties.windowWidth,this._gameResolutionHeight=this._data.properties.windowHeight,this._originalWidth=this._gameResolutionWidth,this._originalHeight=this._gameResolutionHeight,this._resizeMode=this._data.properties.sizeOnStartupMode,this._adaptGameResolutionAtRuntime=this._data.properties.adaptGameResolutionAtRuntime,this._scaleMode=e.properties.scaleMode||"linear",this._pixelsRounding=this._data.properties.pixelsRounding,this._antialiasingMode=this._data.properties.antialiasingMode,this._isAntialisingEnabledOnMobile=this._data.properties.antialisingEnabledOnMobile,this._renderer=new a.RuntimeGameRenderer(this,this._options.forceFullscreen||!1),this._watermark=new a.watermark.RuntimeWatermark(this,e.properties.authorUsernames,this._data.properties.watermark),this._sceneStack=new a.SceneStack(this),this._inputManager=new a.InputManager,this._injectExternalLayout=this._options.injectExternalLayout||"",this._debuggerClient=a.DebuggerClient?new a.DebuggerClient(this):null,this._isPreview=this._options.isPreview||!1,this._sessionId=null,this._playerId=null,this._embeddedResourcesMappings=new Map;for(const i of this._data.resources.resources)if(i.metadata)try{const n=JSON.parse(i.metadata);n?.embeddedResourcesMapping&&this._embeddedResourcesMappings.set(i.name,n.embeddedResourcesMapping)}catch{d.error("Some metadata of resources can not be successfully parsed.")}if(this._eventsBasedObjectDatas=new Map,this._data.eventsFunctionsExtensions)for(const i of this._data.eventsFunctionsExtensions)for(const n of i.eventsBasedObjects)this._eventsBasedObjectDatas.set(i.name+"::"+n.name,n);this.isUsingGDevelopDevelopmentEnvironment()&&d.info("This game will run on the development version of GDevelop APIs.")}setProjectData(e){this._data=e,this._imageManager.setResources(this._data.resources.resources),this._soundManager.setResources(this._data.resources.resources),this._fontManager.setResources(this._data.resources.resources),this._jsonManager.setResources(this._data.resources.resources),this._bitmapFontManager.setResources(this._data.resources.resources),this._model3DManager.setResources(this._data.resources.resources)}getAdditionalOptions(){return this._options}getRenderer(){return this._renderer}getVariables(){return this._variables}getSoundManager(){return this._soundManager}getImageManager(){return this._imageManager}getFontManager(){return this._fontManager}getBitmapFontManager(){return this._bitmapFontManager}getInputManager(){return this._inputManager}getJsonManager(){return this._jsonManager}getModel3DManager(){return this._model3DManager}getEffectsManager(){return this._effectsManager}getGameData(){return this._data}getEventsBasedObjectData(e){const t=this._eventsBasedObjectDatas.get(e);return t||(d.error('The game has no events-based object of the type "'+e+'"'),null)}getSceneData(e){let t=null;for(let s=0,i=this._data.layouts.length;s<i;++s){const n=this._data.layouts[s];if(e===void 0||n.name===e){t=n;break}}return t===null&&d.error('The game has no scene called "'+e+'"'),t}hasScene(e){let t=!1;for(let s=0,i=this._data.layouts.length;s<i;++s){const n=this._data.layouts[s];if(e===void 0||n.name==e){t=!0;break}}return t}getExternalLayoutData(e){let t=null;for(let s=0,i=this._data.externalLayouts.length;s<i;++s){const n=this._data.externalLayouts[s];if(n.name===e){t=n;break}}return t}getInitialObjectsData(){return this._data.objects||[]}getOriginalWidth(){return this._originalWidth}getOriginalHeight(){return this._originalHeight}getGameResolutionWidth(){return this._gameResolutionWidth}getGameResolutionHeight(){return this._gameResolutionHeight}setGameResolutionSize(e,t){if(this._gameResolutionWidth=e,this._gameResolutionHeight=t,this._adaptGameResolutionAtRuntime&&a.RuntimeGameRenderer&&a.RuntimeGameRenderer.getWindowInnerWidth&&a.RuntimeGameRenderer.getWindowInnerHeight){const s=a.RuntimeGameRenderer.getWindowInnerWidth(),i=a.RuntimeGameRenderer.getWindowInnerHeight();this._resizeMode==="adaptWidth"?this._gameResolutionWidth=this._gameResolutionHeight*s/i:this._resizeMode==="adaptHeight"&&(this._gameResolutionHeight=this._gameResolutionWidth*i/s)}this._renderer.updateRendererSize(),this._notifyScenesForGameResolutionResize=!0}setGameResolutionResizeMode(e){this._resizeMode=e,this._forceGameResolutionUpdate()}getGameResolutionResizeMode(){return this._resizeMode}setAdaptGameResolutionAtRuntime(e){this._adaptGameResolutionAtRuntime=e,this._forceGameResolutionUpdate()}getAdaptGameResolutionAtRuntime(){return this._adaptGameResolutionAtRuntime}getMinimalFramerate(){return this._minFPS}getScaleMode(){return this._scaleMode}getPixelsRounding(){return this._pixelsRounding}getAntialiasingMode(){return this._antialiasingMode}isAntialisingEnabledOnMobile(){return this._isAntialisingEnabledOnMobile}pause(e){this._paused!==e&&(this._paused=e,this._debuggerClient&&(this._paused?this._debuggerClient.sendGamePaused():this._debuggerClient.sendGameResumed()))}hasJustResumed(){return this._hasJustResumed}loadAllAssets(e,t){this.loadAllAssetsAsync(t).then(e)}startGameLoop(){try{if(!this.hasScene()){d.error("The game has no scene.");return}this._forceGameResolutionUpdate();const e=this._data.firstLayout;this._sceneStack.push(this.hasScene(e)?e:this.getSceneData().name,this._injectExternalLayout),this._watermark.displayAtStartup(),this._setupGameVisibilityEvents();let t=0;this._hasJustResumed=!1,this._renderer.startGameLoop(s=>{try{if(this._paused||(t+=s,this._maxFPS>0&&1e3/t>this._maxFPS+7))return!0;const i=t;return t=0,this._notifyScenesForGameResolutionResize&&(this._sceneStack.onGameResolutionResized(),this._notifyScenesForGameResolutionResize=!1),this._sceneStack.step(i)?(this.getInputManager().onFrameEnded(),this._hasJustResumed=!1,!0):!1}catch(i){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(i),i}}),setTimeout(()=>{this._setupSessionMetrics()},1e4)}catch(e){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(e),e}}enableMetrics(e){this._disableMetrics=!e,e&&this._setupSessionMetrics()}_setupGameVisibilityEvents(){typeof navigator!="undefined"&&typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&(this._hasJustResumed=!0)}),window.addEventListener("resume",()=>{this._hasJustResumed=!0},!1))}_setupSessionMetrics(){if(this._sessionMetricsInitialized||this._disableMetrics||this.isPreview()||typeof fetch=="undefined"||!this._data.properties.projectUuid)return;const e="https://api.gdevelop-app.com/analytics";this._playerId=this._makePlayerUuid();let t=0,s=0,i=Date.now();fetch(e+"/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({gameId:this._data.properties.projectUuid,playerId:this._playerId,game:{name:this._data.properties.name||"",packageName:this._data.properties.packageName||"",version:this._data.properties.version||"",location:window.location.href},platform:{isCordova:!!window.cordova,devicePlatform:typeof device!="undefined"&&device.platform||"",navigatorPlatform:typeof navigator!="undefined"?navigator.platform:"",hasTouch:typeof navigator!="undefined"?!!navigator.maxTouchPoints&&navigator.maxTouchPoints>2:!1}})}).then(r=>{if(!r.ok)throw console.error("Error while creating the session",r),new Error("Error while creating the session");return r}).then(r=>r.text()).then(r=>{this._sessionId=r}).catch(()=>{});const n=()=>{if(!this._sessionId)return;const r=Date.now();if(s+=r-i,i=r,s<5*1e3)return;const u=Math.floor(s/1e3)*1e3;t+=u,s-=u,navigator.sendBeacon(e+"/session-hit",JSON.stringify({gameId:this._data.properties.projectUuid,playerId:this._playerId,sessionId:this._sessionId,duration:Math.floor(t/1e3)}))};if(typeof navigator!="undefined"&&typeof document!="undefined"){document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"?i=Date.now():n()}),window.addEventListener("pagehide",n,!1),window.addEventListener("pause",n,!1),window.addEventListener("resume",()=>{i=Date.now()},!1);const r=typeof safari=="object"&&safari.pushNotification,u=/electron/i.test(navigator.userAgent);(r||u)&&window.addEventListener("beforeunload",()=>{n()})}this._sessionMetricsInitialized=!0,this._sessionId=this._sessionId}_makePlayerUuid(){try{const e="GDJS-internal-player-uuid",t=localStorage.getItem(e);if(t)return t;const s=a.makeUuid();return localStorage.setItem(e,s),s}catch{return a.makeUuid()}}getSessionId(){return this._sessionId}getPlayerId(){return this._playerId}onWindowInnerSizeChanged(){this._forceGameResolutionUpdate()}_forceGameResolutionUpdate(){this.setGameResolutionSize(this._gameResolutionWidth,this._gameResolutionHeight)}startCurrentSceneProfiler(e){const t=this._sceneStack.getCurrentScene();return t?(t.startProfiler(e),!0):!1}stopCurrentSceneProfiler(){const e=this._sceneStack.getCurrentScene();!e||e.stopProfiler()}wasFirstSceneLoaded(){return this._sceneStack.wasFirstSceneLoaded()}getSceneStack(){return this._sceneStack}isPreview(){return this._isPreview}isUsingGDevelopDevelopmentEnvironment(){return this._options.environment==="dev"}getExtensionProperty(e,t){for(let s of this._data.properties.extensionProperties)if(s.extension===e&&s.property===t)return s.value;return null}resolveEmbeddedResource(e,t){const s=this._embeddedResourcesMappings.get(e);return s&&s[t]?s[t]:t}}a.RuntimeGame=_})(gdjs||(gdjs={}));
//# sourceMappingURL=runtimegame.js.map