gdcore-tools 2.0.0-beta5 → 2.0.0-beta7
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.
- package/dist/Runtime/Cordova/config.xml +4 -0
- package/dist/Runtime/Cordova/package.json +12 -20
- package/dist/Runtime/CustomRuntimeObject.js +1 -1
- package/dist/Runtime/CustomRuntimeObject.js.map +2 -2
- package/dist/Runtime/CustomRuntimeObjectInstanceContainer.js +1 -1
- package/dist/Runtime/CustomRuntimeObjectInstanceContainer.js.map +2 -2
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/AmbientLight.js +1 -1
- package/dist/Runtime/Extensions/3D/AmbientLight.js.map +2 -2
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/DirectionalLight.js +1 -1
- package/dist/Runtime/Extensions/3D/DirectionalLight.js.map +2 -2
- package/dist/Runtime/Extensions/3D/ExponentialFog.js +1 -1
- package/dist/Runtime/Extensions/3D/ExponentialFog.js.map +2 -2
- package/dist/Runtime/Extensions/3D/HemisphereLight.js +1 -1
- package/dist/Runtime/Extensions/3D/HemisphereLight.js.map +2 -2
- package/dist/Runtime/Extensions/3D/JsExtension.js +419 -228
- package/dist/Runtime/Extensions/3D/LinearFog.js +1 -1
- package/dist/Runtime/Extensions/3D/LinearFog.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/AdMob/admobtools.js +1 -1
- package/dist/Runtime/Extensions/AdMob/admobtools.js.map +2 -2
- package/dist/Runtime/Extensions/AdvancedWindow/electron-advancedwindowtools.js +1 -1
- package/dist/Runtime/Extensions/AdvancedWindow/electron-advancedwindowtools.js.map +2 -2
- package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/BBText/JsExtension.js +45 -42
- package/dist/Runtime/Extensions/BBText/bbtextruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/BBText/bbtextruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/BitmapText/JsExtension.js +40 -49
- package/dist/Runtime/Extensions/BitmapText/bitmaptextruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/BitmapText/bitmaptextruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/Effects/JsExtension.js +2 -2
- package/dist/Runtime/Extensions/Effects/bevel-pixi-filter.js +1 -1
- package/dist/Runtime/Extensions/Effects/bevel-pixi-filter.js.map +2 -2
- package/dist/Runtime/Extensions/Effects/color-replace-pixi-filter.js +1 -1
- package/dist/Runtime/Extensions/Effects/color-replace-pixi-filter.js.map +2 -2
- package/dist/Runtime/Extensions/Effects/drop-shadow-pixi-filter.js +1 -1
- package/dist/Runtime/Extensions/Effects/drop-shadow-pixi-filter.js.map +2 -2
- package/dist/Runtime/Extensions/Effects/glow-pixi-filter.js +1 -1
- package/dist/Runtime/Extensions/Effects/glow-pixi-filter.js.map +2 -2
- package/dist/Runtime/Extensions/Effects/outline-pixi-filter.js +1 -1
- package/dist/Runtime/Extensions/Effects/outline-pixi-filter.js.map +2 -2
- package/dist/Runtime/Extensions/ExampleJsExtension/JsExtension.js +18 -21
- package/dist/Runtime/Extensions/Firebase/B_firebasetools/C_firebasetools.js +1 -1
- package/dist/Runtime/Extensions/Firebase/B_firebasetools/C_firebasetools.js.map +2 -2
- package/dist/Runtime/Extensions/JsExtensionTypes.d.ts +8 -2
- package/dist/Runtime/Extensions/Leaderboards/leaderboardstools.js +1 -1
- package/dist/Runtime/Extensions/Leaderboards/leaderboardstools.js.map +2 -2
- package/dist/Runtime/Extensions/Lighting/JsExtension.js +50 -38
- package/dist/Runtime/Extensions/Lighting/lightruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/Lighting/lightruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/JsExtension.js +112 -7
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayercomponents.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayercomponents.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayertools.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayertools.js.map +2 -2
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject.js +1 -1
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/JsExtension.js +127 -40
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PlayerAuthentication/playerauthenticationtools.js +1 -1
- package/dist/Runtime/Extensions/PlayerAuthentication/playerauthenticationtools.js.map +2 -2
- package/dist/Runtime/Extensions/PrimitiveDrawing/shapepainterruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PrimitiveDrawing/shapepainterruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/JsExtension.js +77 -36
- package/dist/Runtime/Extensions/Spine/spineruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/JsExtension.js +55 -56
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextObject/textruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TextObject/textruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TextObject/textruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextObject/textruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/JsExtension.js +511 -287
- package/dist/Runtime/Extensions/TileMap/TileMapRuntimeManager.js +1 -1
- package/dist/Runtime/Extensions/TileMap/TileMapRuntimeManager.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/collision/TransformedTileMap.js +1 -1
- package/dist/Runtime/Extensions/TileMap/collision/TransformedTileMap.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/helper/TileMapHelper.js +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/TileMapHelper.js.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/load/tiled/TiledTileMapLoader.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/model/TileMapModel.d.ts +12 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/model/TileMapModel.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/render/TileMapManager.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/render/TileMapPixiHelper.d.ts +1 -0
- package/dist/Runtime/Extensions/TileMap/helper/dts/render/TileMapPixiHelper.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/JsExtension.js +1 -0
- package/dist/Runtime/Extensions/Video/JsExtension.js +35 -44
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js.map +2 -2
- package/dist/Runtime/ResourceLoader.js +1 -1
- package/dist/Runtime/ResourceLoader.js.map +2 -2
- package/dist/Runtime/RuntimeInstanceContainer.js.map +2 -2
- package/dist/Runtime/SpriteAnimator.js +1 -1
- package/dist/Runtime/SpriteAnimator.js.map +2 -2
- package/dist/Runtime/debugger-client/InGameDebugger.js +1 -1
- package/dist/Runtime/debugger-client/InGameDebugger.js.map +2 -2
- package/dist/Runtime/debugger-client/abstract-debugger-client.js +1 -1
- package/dist/Runtime/debugger-client/abstract-debugger-client.js.map +2 -2
- package/dist/Runtime/debugger-client/hot-reloader.js +2 -1
- package/dist/Runtime/debugger-client/hot-reloader.js.map +2 -2
- package/dist/Runtime/debugger-client/minimal-debugger-client.js +2 -0
- package/dist/Runtime/debugger-client/minimal-debugger-client.js.map +7 -0
- package/dist/Runtime/debugger-client/websocket-debugger-client.js.map +2 -2
- package/dist/Runtime/debugger-client/window-message-debugger-client.js.map +2 -2
- package/dist/Runtime/events-tools/inputtools.js +1 -1
- package/dist/Runtime/events-tools/inputtools.js.map +2 -2
- package/dist/Runtime/events-tools/objecttools.js +1 -1
- package/dist/Runtime/events-tools/objecttools.js.map +2 -2
- package/dist/Runtime/gd.js +1 -1
- package/dist/Runtime/gd.js.map +2 -2
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
- package/dist/Runtime/inputmanager.js +1 -1
- package/dist/Runtime/inputmanager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/CustomRuntimeObject2DPixiRenderer.js +1 -1
- package/dist/Runtime/pixi-renderers/CustomRuntimeObject2DPixiRenderer.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-filters-tools.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-filters-tools.js.map +2 -2
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
- package/dist/Runtime/pixi-renderers/spriteruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/spriteruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimeobject.js +1 -1
- package/dist/Runtime/runtimeobject.js.map +2 -2
- package/dist/Runtime/runtimescene.js +1 -1
- package/dist/Runtime/runtimescene.js.map +2 -2
- package/dist/Runtime/scenestack.js +1 -1
- package/dist/Runtime/scenestack.js.map +2 -2
- package/dist/Runtime/spriteruntimeobject.js +1 -1
- package/dist/Runtime/spriteruntimeobject.js.map +2 -2
- package/dist/Runtime/types/project-data.d.ts +36 -8
- package/dist/Runtime/variablescontainer.js +1 -1
- package/dist/Runtime/variablescontainer.js.map +2 -2
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/gd.d.ts +149 -75
- package/package.json +3 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(
|
|
1
|
+
var gdjs;(function(g){const a=new g.Logger("Debugger client"),d={log:console.log,info:console.info,debug:console.debug,warn:console.warn,error:console.error},f=(c,e,n)=>{const t=[],r=[];return e==null&&(e=function(o,i){return t[0]===i?"[Circular ~]":"[Circular ~."+r.slice(0,t.indexOf(i)).join(".")+"]"}),function(o,i){if(t.length>0){const s=t.indexOf(this);if(~s?t.splice(s+1):t.push(this),~s?r.splice(s,1/0,o):r.push(o),n!=null&&s>n)return"[Max depth reached]";~t.indexOf(i)&&(i=e.call(this,o,i))}else t.push(i);return c==null?i:c.call(this,o,i)}},l=(c,e,n,t,r)=>JSON.stringify(c,f(e,r,n),t),p=(c,e)=>{if(e instanceof Error){const n={};return Object.getOwnPropertyNames(e).forEach(t=>{n[t]=e[t]}),n}return e},h=(c,e)=>{const n=e.getSceneStack().getAllSceneNames(),t=e.getSceneStack().getCurrentScene();return{type:"javascript-uncaught-exception",exception:c,platformInfo:e.getPlatformInfo(),playerId:e.getPlayerId(),sessionId:e.getSessionId(),isPreview:e.isPreview(),gdevelop:{previewContext:e.getAdditionalOptions().previewContext,isNativeMobileApp:e.getAdditionalOptions().nativeMobileApp,versionWithHash:e.getAdditionalOptions().gdevelopVersionWithHash,environment:e.getAdditionalOptions().environment},game:{gameId:g.projectData.properties.projectUuid,name:e.getGameData().properties.name||"",packageName:e.getGameData().properties.packageName||"",version:e.getGameData().properties.version||"",location:window.location.href,projectTemplateSlug:e.getAdditionalOptions().projectTemplateSlug,sourceGameId:e.getAdditionalOptions().sourceGameId},gameState:{sceneNames:n,isWebGLSupported:e.getRenderer().isWebGLSupported(),hasPixiRenderer:!!e.getRenderer().getPIXIRenderer(),hasThreeRenderer:!!e.getRenderer().getThreeRenderer(),resourcesTotalCount:e.getGameData().resources.resources.length,antialiasingMode:e.getAntialiasingMode(),isAntialisingEnabledOnMobile:e.isAntialisingEnabledOnMobile(),scriptFiles:e.getAdditionalOptions().scriptFiles,currentSceneTimeFromStart:t?t.getTimeManager().getTimeFromStart():null,gdjsKeys:Object.keys(g).slice(0,1e3)}}};class u{constructor(e){this._originalConsole=d;this._hasLoggedUncaughtException=!1;this._runtimegame=e,this._hotReloader=new g.HotReloader(e),this._inGameDebugger=new g.InGameDebugger(e);const n=(r,...o)=>{this.log("JavaScript",o.reduce((i,s)=>i+s,""),r,!1)};console.log=(...r)=>{d.log(...r),n("info",...r)},console.debug=(...r)=>{d.debug(...r),n("info",...r)},console.info=(...r)=>{d.info(...r),n("info",...r)},console.warn=(...r)=>{d.warn(...r),n("warning",...r)},console.error=(...r)=>{d.error(...r),n("error",...r)};const t=g.Logger.getLoggerOutput();g.Logger.setLoggerOutput({log:(r,o,i="info",s=!0)=>{t.log(r,o,i,s),this.log(r,o,i,s)}})}handleCommand(e){const n=this,t=this._runtimegame;!e||!e.command||(e.command==="play"?t.pause(!1):e.command==="pause"?(t.pause(!0),n.sendRuntimeGameDump()):e.command==="refresh"?n.sendRuntimeGameDump():e.command==="set"?n.set(e.path,e.newValue):e.command==="call"?n.call(e.path,e.args):e.command==="profiler.start"?(t.startCurrentSceneProfiler(function(r){n.sendProfilerOutput(r.getFramesAverageMeasures(),r.getStats()),n.sendProfilerStopped()}),n.sendProfilerStarted()):e.command==="profiler.stop"?t.stopCurrentSceneProfiler():e.command==="hotReload"?n._hotReloader.hotReload().then(r=>{n.sendHotReloaderLogs(r)}):a.info('Unknown command "'+e.command+'" received by the debugger.'))}static isErrorComingFromJavaScriptCode(e){return!e||!e.stack?!1:e.stack.includes("GDJSInlineCode")}async _reportCrash(e){const n=h(e,this._runtimegame);if(this._sendMessage(l({command:"game.crashed",payload:n},p)),!this._runtimegame.getAdditionalOptions().crashReportUploadLevel||this._runtimegame.getAdditionalOptions().crashReportUploadLevel==="none"||this._runtimegame.getAdditionalOptions().crashReportUploadLevel==="exclude-javascript-code-events"&&u.isErrorComingFromJavaScriptCode(e))return;const r=`${this._runtimegame.isUsingGDevelopDevelopmentEnvironment()?"https://api-dev.gdevelop.io":"https://api.gdevelop.io"}/analytics`;try{await fetch(`${r}/game-crash-report`,{body:l(n,p),method:"POST"})}catch(o){a.error("Error while sending the crash report:",o)}}onUncaughtException(e){a.error("Uncaught exception: "+e),this._inGameDebugger.setUncaughtException(e),this._hasLoggedUncaughtException||(this._hasLoggedUncaughtException=!0,this._reportCrash(e))}log(e,n,t,r){this._sendMessage(JSON.stringify({command:"console.log",payload:{message:n,type:t,group:e,internal:r,timestamp:performance.now()}}))}set(e,n){if(!e||!e.length)return a.warn("No path specified, set operation from debugger aborted"),!1;let t=this._runtimegame,r=0;for(;r<e.length-1;){const i=e[r];if(!t||!t[i])return a.error("Incorrect path specified. No "+i+" in ",t),!1;t=t[i],r++}const o=t[e[r]];return typeof o=="number"?n=parseFloat(n):typeof o=="string"&&(n=""+n),a.log("Updating",e,"to",n),t[e[r]]=n,!0}call(e,n){if(!e||!e.length)return a.warn("No path specified, call operation from debugger aborted"),!1;let t=this._runtimegame,r=0;for(;r<e.length-1;){const o=e[r];if(!t||!t[o])return a.error("Incorrect path specified. No "+o+" in ",t),!1;t=t[o],r++}return t[e[r]]?(a.log("Calling",e,"with",n),t[e[r]].apply(t,n),!0):(a.error("Unable to call",e),!1)}sendRuntimeGameDump(){const e=this,n={command:"dump",payload:this._runtimegame},t=Date.now(),r=[e._runtimegame.getGameData()],o=["_debuggerClient","_allInstancesList","_runtimeGame","_runtimeScene","_behaviorsTable","_animations","_animationFrame","linkedObjectsManager","_platformRBush","HSHG","_obstaclesHSHG","owner","_renderer","_gameRenderer","_imageManager","_rendererEffects","baseTexture","_baseTexture","_invalidTexture"],i=l(n,function(b,m){return r.indexOf(m)!==-1||o.indexOf(b)!==-1?"[Removed from the debugger]":m},18),s=Date.now()-t;a.log("RuntimeGame serialization took "+s+"ms"),s>500&&a.warn("Serialization took a long time: please check if there is a need to remove some objects from serialization"),this._sendMessage(i)}sendHotReloaderLogs(e){this._sendMessage(l({command:"hotReloader.logs",payload:e}))}sendProfilerStarted(){this._sendMessage(l({command:"profiler.started",payload:null}))}sendProfilerStopped(){this._sendMessage(l({command:"profiler.stopped",payload:null}))}sendGamePaused(){this._sendMessage(l({command:"game.paused",payload:null}))}sendGameResumed(){this._sendMessage(l({command:"game.resumed",payload:null}))}sendProfilerOutput(e,n){this._sendMessage(l({command:"profiler.output",payload:{framesAverageMeasures:e,stats:n}}))}}g.AbstractDebuggerClient=u})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=abstract-debugger-client.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../GDevelop/GDJS/Runtime/debugger-client/abstract-debugger-client.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n const logger = new gdjs.Logger('Debugger client');\n\n const originalConsole = {\n log: console.log,\n info: console.info,\n debug: console.debug,\n warn: console.warn,\n error: console.error,\n };\n\n /**\n * A function used to replace circular references with a new value.\n * @param key - The key corresponding to the value.\n * @param value - The value.\n * @returns The new value.\n */\n type DebuggerClientCycleReplacer = (key: string, value: any) => any;\n\n /**\n * Generates a JSON serializer that prevent circular references and stop if maxDepth is reached.\n * @param [replacer] - A function called for each property on the object or array being stringified, with the property key and its value, and that returns the new value. If not specified, values are not altered.\n * @param [cycleReplacer] - Function used to replace circular references with a new value.\n * @param [maxDepth] - The maximum depth, after which values are replaced by a string (\"[Max depth reached]\"). If not specified, there is no maximum depth.\n */\n const depthLimitedSerializer = (\n replacer?: DebuggerClientCycleReplacer,\n cycleReplacer?: DebuggerClientCycleReplacer,\n maxDepth?: number\n ): DebuggerClientCycleReplacer => {\n const stack: Array<string> = [],\n keys: Array<string> = [];\n if (cycleReplacer === undefined || cycleReplacer === null) {\n cycleReplacer = function (key, value) {\n if (stack[0] === value) {\n return '[Circular ~]';\n }\n return (\n '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']'\n );\n };\n }\n\n return function (key: string, value: any): any {\n if (stack.length > 0) {\n const thisPos = stack.indexOf(this);\n ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);\n ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);\n if (maxDepth != null && thisPos > maxDepth) {\n return '[Max depth reached]';\n } else {\n if (~stack.indexOf(value)) {\n value = (cycleReplacer as DebuggerClientCycleReplacer).call(\n this,\n key,\n value\n );\n }\n }\n } else {\n stack.push(value);\n }\n return replacer == null ? value : replacer.call(this, key, value);\n };\n };\n\n /**\n * This is an alternative to JSON.stringify that ensure that circular references\n * are replaced by a placeholder.\n *\n * @param obj - The object to serialize.\n * @param [replacer] - A function called for each property on the object or array being stringified, with the property key and its value, and that returns the new value. If not specified, values are not altered.\n * @param [maxDepth] - The maximum depth, after which values are replaced by a string (\"[Max depth reached]\"). If not specified, there is no maximum depth.\n * @param [spaces] - The number of spaces for indentation.\n * @param [cycleReplacer] - Function used to replace circular references with a new value.\n */\n const circularSafeStringify = (\n obj: any,\n replacer?: DebuggerClientCycleReplacer,\n maxDepth?: number,\n spaces?: number,\n cycleReplacer?: DebuggerClientCycleReplacer\n ) => {\n return JSON.stringify(\n obj,\n depthLimitedSerializer(replacer, cycleReplacer, maxDepth),\n spaces\n );\n };\n\n /**\n * The base class describing a debugger client, that can be used to inspect\n * a runtime game (dump its state) or alter it.\n */\n export abstract class AbstractDebuggerClient {\n _runtimegame: gdjs.RuntimeGame;\n _hotReloader: gdjs.HotReloader;\n _originalConsole = originalConsole;\n _inGameDebugger: gdjs.InGameDebugger;\n\n constructor(runtimeGame: RuntimeGame) {\n this._runtimegame = runtimeGame;\n this._hotReloader = new gdjs.HotReloader(runtimeGame);\n this._inGameDebugger = new gdjs.InGameDebugger(runtimeGame);\n\n const redirectJsLog = (\n type: 'info' | 'warning' | 'error',\n ...messages: any[]\n ) => {\n this.log(\n 'JavaScript',\n messages.reduce((accumulator, value) => accumulator + value, ''),\n type,\n false\n );\n };\n\n // Hook the console logging functions to log to the Debugger as well\n console.log = (...messages: any[]) => {\n originalConsole.log(...messages);\n redirectJsLog('info', ...messages);\n };\n\n console.debug = (...messages: any[]) => {\n originalConsole.debug(...messages);\n redirectJsLog('info', ...messages);\n };\n\n console.info = (...messages: any[]) => {\n originalConsole.info(...messages);\n redirectJsLog('info', ...messages);\n };\n\n console.warn = (...messages: any[]) => {\n originalConsole.warn(...messages);\n redirectJsLog('warning', ...messages);\n };\n\n console.error = (...messages: any[]) => {\n originalConsole.error(...messages);\n redirectJsLog('error', ...messages);\n };\n\n // Overwrite the default GDJS log outputs so that they\n // both go to the console (or wherever they were configured to go)\n // and sent to the remote debugger.\n const existingLoggerOutput = gdjs.Logger.getLoggerOutput();\n gdjs.Logger.setLoggerOutput({\n log: (\n group: string,\n message: string,\n type: 'info' | 'warning' | 'error' = 'info',\n internal = true\n ) => {\n existingLoggerOutput.log(group, message, type, internal);\n this.log(group, message, type, internal);\n },\n });\n }\n\n /**\n * Should be called by derived class to handle a command\n * received from the debugger server.\n *\n * @param data An object containing the command to do.\n */\n protected handleCommand(data: any) {\n const that = this;\n const runtimeGame = this._runtimegame;\n if (!data || !data.command) {\n // Not a command that's meant to be handled by the debugger, return silently to\n // avoid polluting the console.\n return;\n }\n\n if (data.command === 'play') {\n runtimeGame.pause(false);\n } else if (data.command === 'pause') {\n runtimeGame.pause(true);\n that.sendRuntimeGameDump();\n } else if (data.command === 'refresh') {\n that.sendRuntimeGameDump();\n } else if (data.command === 'set') {\n that.set(data.path, data.newValue);\n } else if (data.command === 'call') {\n that.call(data.path, data.args);\n } else if (data.command === 'profiler.start') {\n runtimeGame.startCurrentSceneProfiler(function (stoppedProfiler) {\n that.sendProfilerOutput(\n stoppedProfiler.getFramesAverageMeasures(),\n stoppedProfiler.getStats()\n );\n that.sendProfilerStopped();\n });\n that.sendProfilerStarted();\n } else if (data.command === 'profiler.stop') {\n runtimeGame.stopCurrentSceneProfiler();\n } else if (data.command === 'hotReload') {\n that._hotReloader.hotReload().then((logs) => {\n that.sendHotReloaderLogs(logs);\n });\n } else {\n logger.info(\n 'Unknown command \"' + data.command + '\" received by the debugger.'\n );\n }\n }\n\n /**\n * Should be re-implemented by derived class to send a stringified message object\n * to the debugger server.\n * @param message\n */\n protected abstract _sendMessage(message: string): void;\n\n onUncaughtException(exception: Error): void {\n logger.error('Uncaught exception: ' + exception);\n\n this._inGameDebugger.setUncaughtException(exception);\n }\n\n /**\n * Send a message (a log) to debugger server.\n */\n log(\n group: string,\n message: string,\n type: 'info' | 'warning' | 'error',\n internal: boolean\n ) {\n this._sendMessage(\n JSON.stringify({\n command: 'console.log',\n payload: {\n message,\n type,\n group,\n internal,\n timestamp: performance.now(),\n },\n })\n );\n }\n\n /**\n * Update a value, specified by a path starting from the {@link RuntimeGame} instance.\n * @param path - The path to the variable, starting from {@link RuntimeGame}.\n * @param newValue - The new value.\n * @return Was the operation successful?\n */\n set(path: string[], newValue: any): boolean {\n if (!path || !path.length) {\n logger.warn('No path specified, set operation from debugger aborted');\n return false;\n }\n let object = this._runtimegame;\n let currentIndex = 0;\n while (currentIndex < path.length - 1) {\n const key = path[currentIndex];\n if (!object || !object[key]) {\n logger.error('Incorrect path specified. No ' + key + ' in ', object);\n return false;\n }\n object = object[key];\n currentIndex++;\n }\n\n // Ensure the newValue is properly typed to avoid breaking anything in\n // the game engine.\n const currentValue = object[path[currentIndex]];\n if (typeof currentValue === 'number') {\n newValue = parseFloat(newValue);\n } else {\n if (typeof currentValue === 'string') {\n newValue = '' + newValue;\n }\n }\n logger.log('Updating', path, 'to', newValue);\n object[path[currentIndex]] = newValue;\n return true;\n }\n\n /**\n * Call a method, specified by a path starting from the {@link RuntimeGame} instance.\n * @param path - The path to the method, starting from {@link RuntimeGame}.\n * @param args - The arguments to pass the method.\n * @return Was the operation successful?\n */\n call(path: string[], args: any[]): boolean {\n if (!path || !path.length) {\n logger.warn('No path specified, call operation from debugger aborted');\n return false;\n }\n let object = this._runtimegame;\n let currentIndex = 0;\n while (currentIndex < path.length - 1) {\n const key = path[currentIndex];\n if (!object || !object[key]) {\n logger.error('Incorrect path specified. No ' + key + ' in ', object);\n return false;\n }\n object = object[key];\n currentIndex++;\n }\n if (!object[path[currentIndex]]) {\n logger.error('Unable to call', path);\n return false;\n }\n logger.log('Calling', path, 'with', args);\n object[path[currentIndex]].apply(object, args);\n return true;\n }\n\n /**\n * Dump all the relevant data from the {@link RuntimeGame} instance and send it to the server.\n */\n sendRuntimeGameDump(): void {\n const that = this;\n const message = { command: 'dump', payload: this._runtimegame };\n const serializationStartTime = Date.now();\n\n // Stringify the message, excluding some known data that are big and/or not\n // useful for the debugger.\n const excludedValues = [that._runtimegame.getGameData()];\n const excludedKeys = [\n // Exclude reference to the debugger\n '_debuggerClient',\n // Exclude some RuntimeScene fields:\n '_allInstancesList',\n // Exclude circular references to parent runtimeGame or runtimeScene:\n '_runtimeGame',\n '_runtimeScene',\n // Exclude some runtimeObject duplicated data:\n '_behaviorsTable',\n // Exclude some objects data:\n '_animations',\n '_animationFrame',\n // Exclude linked objects to avoid too much repetitions:\n 'linkedObjectsManager',\n // Could be improved by using private fields and excluding these (_)\n // Exclude some behaviors data:\n '_platformRBush',\n // PlatformBehavior\n 'HSHG',\n // Pathfinding\n '_obstaclesHSHG',\n // Pathfinding\n 'owner',\n // Avoid circular reference from behavior to parent runtimeObject\n // Exclude rendering related objects:\n '_renderer',\n '_gameRenderer',\n '_imageManager',\n '_rendererEffects',\n // Exclude PIXI textures:\n 'baseTexture',\n '_baseTexture',\n '_invalidTexture',\n ];\n const stringifiedMessage = circularSafeStringify(\n message,\n function (key, value) {\n if (\n excludedValues.indexOf(value) !== -1 ||\n excludedKeys.indexOf(key) !== -1\n ) {\n return '[Removed from the debugger]';\n }\n return value;\n },\n /* Limit maximum depth to prevent any crashes */\n 18\n );\n const serializationDuration = Date.now() - serializationStartTime;\n logger.log(\n 'RuntimeGame serialization took ' + serializationDuration + 'ms'\n );\n if (serializationDuration > 500) {\n logger.warn(\n 'Serialization took a long time: please check if there is a need to remove some objects from serialization'\n );\n }\n this._sendMessage(stringifiedMessage);\n }\n\n /**\n * Send logs from the hot reloader to the server.\n * @param logs The hot reloader logs.\n */\n sendHotReloaderLogs(logs: HotReloaderLog[]): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'hotReloader.logs',\n payload: logs,\n })\n );\n }\n\n /**\n * Callback called when profiling is starting.\n */\n sendProfilerStarted(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'profiler.started',\n payload: null,\n })\n );\n }\n\n /**\n * Callback called when profiling is ending.\n */\n sendProfilerStopped(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'profiler.stopped',\n payload: null,\n })\n );\n }\n\n /**\n * Callback called when the game is paused.\n */\n sendGamePaused(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'game.paused',\n payload: null,\n })\n );\n }\n\n /**\n * Callback called when the game is resumed.\n */\n sendGameResumed(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'game.resumed',\n payload: null,\n })\n );\n }\n\n /**\n * Send profiling results.\n * @param framesAverageMeasures The measures made for each frames.\n * @param stats Other measures done during the profiler run.\n */\n sendProfilerOutput(\n framesAverageMeasures: FrameMeasure,\n stats: ProfilerStats\n ): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'profiler.output',\n payload: {\n framesAverageMeasures: framesAverageMeasures,\n stats: stats,\n },\n })\n );\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,mBAEzB,EAAkB,CACtB,IAAK,QAAQ,IACb,KAAM,QAAQ,KACd,MAAO,QAAQ,MACf,KAAM,QAAQ,KACd,MAAO,QAAQ,OAiBX,EAAyB,CAC7B,EACA,EACA,IACgC,CAChC,KAAM,GAAuB,GAC3B,EAAsB,GACxB,MAAI,AAA+B,IAAkB,MACnD,GAAgB,SAAU,EAAK,EAAO,CACpC,MAAI,GAAM,KAAO,EACR,eAGP,eAAiB,EAAK,MAAM,EAAG,EAAM,QAAQ,IAAQ,KAAK,KAAO,MAKhE,SAAU,EAAa,EAAiB,CAC7C,GAAI,EAAM,OAAS,EAAG,CACpB,KAAM,GAAU,EAAM,QAAQ,MAG9B,GAFA,CAAC,EAAU,EAAM,OAAO,EAAU,GAAK,EAAM,KAAK,MAClD,CAAC,EAAU,EAAK,OAAO,EAAS,IAAU,GAAO,EAAK,KAAK,GACvD,GAAY,MAAQ,EAAU,EAChC,MAAO,sBAEP,AAAI,CAAC,EAAM,QAAQ,IACjB,GAAS,EAA8C,KACrD,KACA,EACA,QAKN,GAAM,KAAK,GAEb,MAAO,IAAY,KAAO,EAAQ,EAAS,KAAK,KAAM,EAAK,KAczD,EAAwB,CAC5B,EACA,EACA,EACA,EACA,IAEO,KAAK,UACV,EACA,EAAuB,EAAU,EAAe,GAChD,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n const logger = new gdjs.Logger('Debugger client');\n\n const originalConsole = {\n log: console.log,\n info: console.info,\n debug: console.debug,\n warn: console.warn,\n error: console.error,\n };\n\n /**\n * A function used to replace circular references with a new value.\n * @param key - The key corresponding to the value.\n * @param value - The value.\n * @returns The new value.\n */\n type DebuggerClientCycleReplacer = (key: string, value: any) => any;\n\n /**\n * Generates a JSON serializer that prevent circular references and stop if maxDepth is reached.\n * @param [replacer] - A function called for each property on the object or array being stringified, with the property key and its value, and that returns the new value. If not specified, values are not altered.\n * @param [cycleReplacer] - Function used to replace circular references with a new value.\n * @param [maxDepth] - The maximum depth, after which values are replaced by a string (\"[Max depth reached]\"). If not specified, there is no maximum depth.\n */\n const depthLimitedSerializer = (\n replacer?: DebuggerClientCycleReplacer,\n cycleReplacer?: DebuggerClientCycleReplacer,\n maxDepth?: number\n ): DebuggerClientCycleReplacer => {\n const stack: Array<string> = [],\n keys: Array<string> = [];\n if (cycleReplacer === undefined || cycleReplacer === null) {\n cycleReplacer = function (key, value) {\n if (stack[0] === value) {\n return '[Circular ~]';\n }\n return (\n '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']'\n );\n };\n }\n\n return function (key: string, value: any): any {\n if (stack.length > 0) {\n const thisPos = stack.indexOf(this);\n ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);\n ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);\n if (maxDepth != null && thisPos > maxDepth) {\n return '[Max depth reached]';\n } else {\n if (~stack.indexOf(value)) {\n value = (cycleReplacer as DebuggerClientCycleReplacer).call(\n this,\n key,\n value\n );\n }\n }\n } else {\n stack.push(value);\n }\n return replacer == null ? value : replacer.call(this, key, value);\n };\n };\n\n /**\n * This is an alternative to JSON.stringify that ensure that circular references\n * are replaced by a placeholder.\n *\n * @param obj - The object to serialize.\n * @param [replacer] - A function called for each property on the object or array being stringified, with the property key and its value, and that returns the new value. If not specified, values are not altered.\n * @param [maxDepth] - The maximum depth, after which values are replaced by a string (\"[Max depth reached]\"). If not specified, there is no maximum depth.\n * @param [spaces] - The number of spaces for indentation.\n * @param [cycleReplacer] - Function used to replace circular references with a new value.\n */\n const circularSafeStringify = (\n obj: any,\n replacer?: DebuggerClientCycleReplacer,\n maxDepth?: number,\n spaces?: number,\n cycleReplacer?: DebuggerClientCycleReplacer\n ) => {\n return JSON.stringify(\n obj,\n depthLimitedSerializer(replacer, cycleReplacer, maxDepth),\n spaces\n );\n };\n\n /** Replacer function for JSON.stringify to convert Error objects into plain objects that can be logged. */\n const errorReplacer = (_, value: any) => {\n if (value instanceof Error) {\n // See https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify\n const errorObject = {};\n Object.getOwnPropertyNames(value).forEach((prop) => {\n errorObject[prop] = value[prop];\n });\n\n return errorObject;\n }\n // Return the value unchanged if it's not an Error object.\n return value;\n };\n\n const buildGameCrashReport = (\n exception: Error,\n runtimeGame: gdjs.RuntimeGame\n ) => {\n const sceneNames = runtimeGame.getSceneStack().getAllSceneNames();\n const currentScene = runtimeGame.getSceneStack().getCurrentScene();\n return {\n type: 'javascript-uncaught-exception',\n exception,\n platformInfo: runtimeGame.getPlatformInfo(),\n playerId: runtimeGame.getPlayerId(),\n sessionId: runtimeGame.getSessionId(),\n isPreview: runtimeGame.isPreview(),\n gdevelop: {\n previewContext: runtimeGame.getAdditionalOptions().previewContext,\n isNativeMobileApp: runtimeGame.getAdditionalOptions().nativeMobileApp,\n versionWithHash: runtimeGame.getAdditionalOptions()\n .gdevelopVersionWithHash,\n environment: runtimeGame.getAdditionalOptions().environment,\n },\n game: {\n gameId: gdjs.projectData.properties.projectUuid,\n name: runtimeGame.getGameData().properties.name || '',\n packageName: runtimeGame.getGameData().properties.packageName || '',\n version: runtimeGame.getGameData().properties.version || '',\n location: window.location.href,\n projectTemplateSlug: runtimeGame.getAdditionalOptions()\n .projectTemplateSlug,\n sourceGameId: runtimeGame.getAdditionalOptions().sourceGameId,\n },\n gameState: {\n sceneNames,\n isWebGLSupported: runtimeGame.getRenderer().isWebGLSupported(),\n hasPixiRenderer: !!runtimeGame.getRenderer().getPIXIRenderer(),\n hasThreeRenderer: !!runtimeGame.getRenderer().getThreeRenderer(),\n resourcesTotalCount: runtimeGame.getGameData().resources.resources\n .length,\n antialiasingMode: runtimeGame.getAntialiasingMode(),\n isAntialisingEnabledOnMobile: runtimeGame.isAntialisingEnabledOnMobile(),\n scriptFiles: runtimeGame.getAdditionalOptions().scriptFiles,\n currentSceneTimeFromStart: currentScene\n ? currentScene.getTimeManager().getTimeFromStart()\n : null,\n gdjsKeys: Object.keys(gdjs).slice(0, 1000),\n },\n };\n };\n\n /**\n * The base class describing a debugger client, that can be used to inspect\n * a runtime game (dump its state) or alter it.\n */\n export abstract class AbstractDebuggerClient {\n _runtimegame: gdjs.RuntimeGame;\n _hotReloader: gdjs.HotReloader;\n _originalConsole = originalConsole;\n _inGameDebugger: gdjs.InGameDebugger;\n\n _hasLoggedUncaughtException = false;\n\n constructor(runtimeGame: RuntimeGame) {\n this._runtimegame = runtimeGame;\n this._hotReloader = new gdjs.HotReloader(runtimeGame);\n this._inGameDebugger = new gdjs.InGameDebugger(runtimeGame);\n\n const redirectJsLog = (\n type: 'info' | 'warning' | 'error',\n ...messages: any[]\n ) => {\n this.log(\n 'JavaScript',\n messages.reduce((accumulator, value) => accumulator + value, ''),\n type,\n false\n );\n };\n\n // Hook the console logging functions to log to the Debugger as well\n console.log = (...messages: any[]) => {\n originalConsole.log(...messages);\n redirectJsLog('info', ...messages);\n };\n\n console.debug = (...messages: any[]) => {\n originalConsole.debug(...messages);\n redirectJsLog('info', ...messages);\n };\n\n console.info = (...messages: any[]) => {\n originalConsole.info(...messages);\n redirectJsLog('info', ...messages);\n };\n\n console.warn = (...messages: any[]) => {\n originalConsole.warn(...messages);\n redirectJsLog('warning', ...messages);\n };\n\n console.error = (...messages: any[]) => {\n originalConsole.error(...messages);\n redirectJsLog('error', ...messages);\n };\n\n // Overwrite the default GDJS log outputs so that they\n // both go to the console (or wherever they were configured to go)\n // and sent to the remote debugger.\n const existingLoggerOutput = gdjs.Logger.getLoggerOutput();\n gdjs.Logger.setLoggerOutput({\n log: (\n group: string,\n message: string,\n type: 'info' | 'warning' | 'error' = 'info',\n internal = true\n ) => {\n existingLoggerOutput.log(group, message, type, internal);\n this.log(group, message, type, internal);\n },\n });\n }\n\n /**\n * Should be called by derived class to handle a command\n * received from the debugger server.\n *\n * @param data An object containing the command to do.\n */\n protected handleCommand(data: any) {\n const that = this;\n const runtimeGame = this._runtimegame;\n if (!data || !data.command) {\n // Not a command that's meant to be handled by the debugger, return silently to\n // avoid polluting the console.\n return;\n }\n\n if (data.command === 'play') {\n runtimeGame.pause(false);\n } else if (data.command === 'pause') {\n runtimeGame.pause(true);\n that.sendRuntimeGameDump();\n } else if (data.command === 'refresh') {\n that.sendRuntimeGameDump();\n } else if (data.command === 'set') {\n that.set(data.path, data.newValue);\n } else if (data.command === 'call') {\n that.call(data.path, data.args);\n } else if (data.command === 'profiler.start') {\n runtimeGame.startCurrentSceneProfiler(function (stoppedProfiler) {\n that.sendProfilerOutput(\n stoppedProfiler.getFramesAverageMeasures(),\n stoppedProfiler.getStats()\n );\n that.sendProfilerStopped();\n });\n that.sendProfilerStarted();\n } else if (data.command === 'profiler.stop') {\n runtimeGame.stopCurrentSceneProfiler();\n } else if (data.command === 'hotReload') {\n that._hotReloader.hotReload().then((logs) => {\n that.sendHotReloaderLogs(logs);\n });\n } else {\n logger.info(\n 'Unknown command \"' + data.command + '\" received by the debugger.'\n );\n }\n }\n\n /**\n * Should be re-implemented by derived class to send a stringified message object\n * to the debugger server.\n * @param message\n */\n protected abstract _sendMessage(message: string): void;\n\n static isErrorComingFromJavaScriptCode(exception: Error | null): boolean {\n if (!exception || !exception.stack) return false;\n\n return exception.stack.includes('GDJSInlineCode');\n }\n\n async _reportCrash(exception: Error) {\n const gameCrashReport = buildGameCrashReport(\n exception,\n this._runtimegame\n );\n\n // Let a debugger server know about the crash.\n this._sendMessage(\n circularSafeStringify(\n {\n command: 'game.crashed',\n payload: gameCrashReport,\n },\n errorReplacer\n )\n );\n\n // Send the report to the APIs, if allowed.\n if (\n !this._runtimegame.getAdditionalOptions().crashReportUploadLevel ||\n this._runtimegame.getAdditionalOptions().crashReportUploadLevel ===\n 'none' ||\n (this._runtimegame.getAdditionalOptions().crashReportUploadLevel ===\n 'exclude-javascript-code-events' &&\n AbstractDebuggerClient.isErrorComingFromJavaScriptCode(exception))\n ) {\n return;\n }\n\n const rootApi = this._runtimegame.isUsingGDevelopDevelopmentEnvironment()\n ? 'https://api-dev.gdevelop.io'\n : 'https://api.gdevelop.io';\n const baseUrl = `${rootApi}/analytics`;\n\n try {\n await fetch(`${baseUrl}/game-crash-report`, {\n body: circularSafeStringify(gameCrashReport, errorReplacer),\n method: 'POST',\n });\n } catch (error) {\n logger.error('Error while sending the crash report:', error);\n }\n }\n\n onUncaughtException(exception: Error): void {\n logger.error('Uncaught exception: ' + exception);\n\n this._inGameDebugger.setUncaughtException(exception);\n\n if (!this._hasLoggedUncaughtException) {\n // Only log an uncaught exception once, to avoid spamming the debugger server\n // in case of an exception at each frame.\n this._hasLoggedUncaughtException = true;\n\n this._reportCrash(exception);\n }\n }\n\n /**\n * Send a message (a log) to debugger server.\n */\n log(\n group: string,\n message: string,\n type: 'info' | 'warning' | 'error',\n internal: boolean\n ) {\n this._sendMessage(\n JSON.stringify({\n command: 'console.log',\n payload: {\n message,\n type,\n group,\n internal,\n timestamp: performance.now(),\n },\n })\n );\n }\n\n /**\n * Update a value, specified by a path starting from the {@link RuntimeGame} instance.\n * @param path - The path to the variable, starting from {@link RuntimeGame}.\n * @param newValue - The new value.\n * @return Was the operation successful?\n */\n set(path: string[], newValue: any): boolean {\n if (!path || !path.length) {\n logger.warn('No path specified, set operation from debugger aborted');\n return false;\n }\n let object = this._runtimegame;\n let currentIndex = 0;\n while (currentIndex < path.length - 1) {\n const key = path[currentIndex];\n if (!object || !object[key]) {\n logger.error('Incorrect path specified. No ' + key + ' in ', object);\n return false;\n }\n object = object[key];\n currentIndex++;\n }\n\n // Ensure the newValue is properly typed to avoid breaking anything in\n // the game engine.\n const currentValue = object[path[currentIndex]];\n if (typeof currentValue === 'number') {\n newValue = parseFloat(newValue);\n } else {\n if (typeof currentValue === 'string') {\n newValue = '' + newValue;\n }\n }\n logger.log('Updating', path, 'to', newValue);\n object[path[currentIndex]] = newValue;\n return true;\n }\n\n /**\n * Call a method, specified by a path starting from the {@link RuntimeGame} instance.\n * @param path - The path to the method, starting from {@link RuntimeGame}.\n * @param args - The arguments to pass the method.\n * @return Was the operation successful?\n */\n call(path: string[], args: any[]): boolean {\n if (!path || !path.length) {\n logger.warn('No path specified, call operation from debugger aborted');\n return false;\n }\n let object = this._runtimegame;\n let currentIndex = 0;\n while (currentIndex < path.length - 1) {\n const key = path[currentIndex];\n if (!object || !object[key]) {\n logger.error('Incorrect path specified. No ' + key + ' in ', object);\n return false;\n }\n object = object[key];\n currentIndex++;\n }\n if (!object[path[currentIndex]]) {\n logger.error('Unable to call', path);\n return false;\n }\n logger.log('Calling', path, 'with', args);\n object[path[currentIndex]].apply(object, args);\n return true;\n }\n\n /**\n * Dump all the relevant data from the {@link RuntimeGame} instance and send it to the server.\n */\n sendRuntimeGameDump(): void {\n const that = this;\n const message = { command: 'dump', payload: this._runtimegame };\n const serializationStartTime = Date.now();\n\n // Stringify the message, excluding some known data that are big and/or not\n // useful for the debugger.\n const excludedValues = [that._runtimegame.getGameData()];\n const excludedKeys = [\n // Exclude reference to the debugger\n '_debuggerClient',\n // Exclude some RuntimeScene fields:\n '_allInstancesList',\n // Exclude circular references to parent runtimeGame or runtimeScene:\n '_runtimeGame',\n '_runtimeScene',\n // Exclude some runtimeObject duplicated data:\n '_behaviorsTable',\n // Exclude some objects data:\n '_animations',\n '_animationFrame',\n // Exclude linked objects to avoid too much repetitions:\n 'linkedObjectsManager',\n // Could be improved by using private fields and excluding these (_)\n // Exclude some behaviors data:\n '_platformRBush',\n // PlatformBehavior\n 'HSHG',\n // Pathfinding\n '_obstaclesHSHG',\n // Pathfinding\n 'owner',\n // Avoid circular reference from behavior to parent runtimeObject\n // Exclude rendering related objects:\n '_renderer',\n '_gameRenderer',\n '_imageManager',\n '_rendererEffects',\n // Exclude PIXI textures:\n 'baseTexture',\n '_baseTexture',\n '_invalidTexture',\n ];\n const stringifiedMessage = circularSafeStringify(\n message,\n function (key, value) {\n if (\n excludedValues.indexOf(value) !== -1 ||\n excludedKeys.indexOf(key) !== -1\n ) {\n return '[Removed from the debugger]';\n }\n return value;\n },\n /* Limit maximum depth to prevent any crashes */\n 18\n );\n const serializationDuration = Date.now() - serializationStartTime;\n logger.log(\n 'RuntimeGame serialization took ' + serializationDuration + 'ms'\n );\n if (serializationDuration > 500) {\n logger.warn(\n 'Serialization took a long time: please check if there is a need to remove some objects from serialization'\n );\n }\n this._sendMessage(stringifiedMessage);\n }\n\n /**\n * Send logs from the hot reloader to the server.\n * @param logs The hot reloader logs.\n */\n sendHotReloaderLogs(logs: HotReloaderLog[]): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'hotReloader.logs',\n payload: logs,\n })\n );\n }\n\n /**\n * Callback called when profiling is starting.\n */\n sendProfilerStarted(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'profiler.started',\n payload: null,\n })\n );\n }\n\n /**\n * Callback called when profiling is ending.\n */\n sendProfilerStopped(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'profiler.stopped',\n payload: null,\n })\n );\n }\n\n /**\n * Callback called when the game is paused.\n */\n sendGamePaused(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'game.paused',\n payload: null,\n })\n );\n }\n\n /**\n * Callback called when the game is resumed.\n */\n sendGameResumed(): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'game.resumed',\n payload: null,\n })\n );\n }\n\n /**\n * Send profiling results.\n * @param framesAverageMeasures The measures made for each frames.\n * @param stats Other measures done during the profiler run.\n */\n sendProfilerOutput(\n framesAverageMeasures: FrameMeasure,\n stats: ProfilerStats\n ): void {\n this._sendMessage(\n circularSafeStringify({\n command: 'profiler.output',\n payload: {\n framesAverageMeasures: framesAverageMeasures,\n stats: stats,\n },\n })\n );\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
var gdjs;(function(d){const u=new d.Logger("Hot reloader");class m{constructor(o){this._reloadedScriptElement={};this._logs=[];this._alreadyLoadedScriptFiles={};this._runtimeGame=o}static groupByPersistentUuid(o){return o.reduce(function(e,r){return r.persistentUuid&&(e[r.persistentUuid]=r),e},{})}_canReloadScriptFile(o){function e(r,t){const i=r.indexOf(t);return i!==-1&&i===r.length-t.length}return!(e(o,".h")||this._alreadyLoadedScriptFiles[o]&&(e(o,"box2d.js")||e(o,"sha256.js")||e(o,"shopify-buy.umd.polyfilled.min.js")||e(o,"pixi-multistyle-text.umd.js")||e(o,"pixi-tilemap.umd.js")||e(o,"bondage.min.js")||e(o,"pixi-particles-pixi-renderer.min.js")||e(o,"pixi-tilemap.umd.js")||e(o,"pixi-tilemap-helper.js")||e(o,"pako/dist/pako.min")))}_reloadScript(o){function e(t,i){const a=t.indexOf(i);return a!==-1&&a===t.length-i.length}if(!this._canReloadScriptFile(o))return this._logs.push({kind:"info",message:"Not reloading "+o+" as it is blocked for hot-reloading."}),Promise.resolve();const r=document.getElementsByTagName("head")[0];return r?new Promise((t,i)=>{const a=this._reloadedScriptElement[o];if(a)r.removeChild(a);else{const n=r.getElementsByTagName("script");for(let h=0;h<n.length;++h){const l=n[h];e(l.src,o)&&r.removeChild(l)}}const s=document.createElement("script");s.src=o+"?timestamp="+Date.now(),s.onload=()=>{t()},s.onerror=n=>{i(n)},r.appendChild(s),this._reloadedScriptElement[o]=s}):Promise.reject(new Error("No head element found, are you in a navigator?"))}hotReload(){u.info("Hot reload started"),this._runtimeGame.pause(!0),this._logs=[];const o=d.projectData,e=d.runtimeGameOptions.scriptFiles;e.forEach(t=>{this._alreadyLoadedScriptFiles[t.path]=!0});const r={};for(let t in d.behaviorsTypes.items)r[t]=d.behaviorsTypes.items[t];return this._reloadScript("data.js").then(()=>{const t=d.projectData,i=d.runtimeGameOptions,a=i.scriptFiles,s=!!i.projectDataOnlyExport;return this.reloadScriptFiles(t,e,a,s).then(()=>{const n=this._computeChangedRuntimeBehaviors(r,d.behaviorsTypes.items);return this._hotReloadRuntimeGame(o,t,n,this._runtimeGame)}).catch(n=>{const h=n.target;h instanceof HTMLScriptElement?this._logs.push({kind:"fatal",message:"Unable to reload script:"+h.src}):this._logs.push({kind:"fatal",message:"Unexpected error happened while hot-reloading:"+n.message})}).then(()=>(u.info("Hot reload finished with logs:",this._logs),this._runtimeGame.pause(!1),this._logs))})}_computeChangedRuntimeBehaviors(o,e){const r=[];for(let t in o){const i=o[t],a=e[t];a?i!==a&&(this._logs.push({kind:"info",message:"Behavior with type "+t+" was changed, and will be re-instantiated in gdjs.RuntimeObjects using it."}),r.push({oldBehaviorConstructor:i,newBehaviorConstructor:a,behaviorTypeName:t})):this._logs.push({kind:"warning",message:"Behavior with type "+t+" was removed from the registered behaviors in gdjs."})}return r}reloadScriptFiles(o,e,r,t){const i=[];t||o.layouts.forEach((a,s)=>{i.push(this._reloadScript("code"+s+".js"))});for(let a=0;a<r.length;++a){const s=r[a],n=e.filter(h=>h.path===s.path)[0];n?s.hash!==n.hash&&(this._logs.push({kind:"info",message:"Reloading "+s.path+" because it was changed."}),i.push(this._reloadScript(s.path))):(this._logs.push({kind:"info",message:"Loading "+s.path+" as it was added to the list of scripts."}),i.push(this._reloadScript(s.path)))}for(let a=0;a<e.length;++a){const s=e[a];!r.filter(h=>h.path===s.path)[0]&&!t&&this._logs.push({kind:"warning",message:"Script file "+s.path+" was removed."})}return Promise.all(i)}async _hotReloadRuntimeGame(o,e,r,t){const i=t.getSceneStack(),a=i.getCurrentScene();if(!a){this._logs.push({kind:"error",message:"Can't hot-reload as no scene are opened."});return}t.setProjectData(e),await t.loadFirstAssetsAndStartBackgroundLoading(a.getName(),()=>{}),this._hotReloadVariablesContainer(o.variables,e.variables,t.getVariables()),i._stack.forEach(s=>{const n=o.layouts.filter(l=>l.name===s.getName())[0],h=e.layouts.filter(l=>l.name===s.getName())[0];n&&h?this._hotReloadRuntimeScene(n,h,r,s):this._logs.push({kind:"error",message:"Scene "+n.name+" was removed. A fresh preview should be launched."})}),e.externalLayouts.forEach(s=>{const n=o.externalLayouts.filter(h=>h.name===s.name)[0];n&&!m.deepEqual(n,s)&&i._stack.forEach(h=>{this._hotReloadRuntimeSceneInstances(n.instances,s.instances,h)})})}_hotReloadVariablesContainer(o,e,r){e.forEach(t=>{const i=t.name,a=o.find(n=>n.name===i),s=r.get(t.name);a?d.Variable.isPrimitive(t.type||"number")&&(a.value!==t.value||!d.Variable.isPrimitive(a.type||"number"))?(r.remove(i),r.add(i,new d.Variable(t))):d.Variable.isPrimitive(t.type||"number")||(t.type==="structure"?this._hotReloadStructureVariable(a.children,t.children,s):(r.remove(i),r.add(i,new d.Variable(t)))):r.add(i,new d.Variable(t))}),o.forEach(t=>{e.find(a=>a.name===t.name)||r.remove(t.name)})}_hotReloadStructureVariable(o,e,r){o?(o.forEach(t=>{const i=e.find(a=>a.name===t.name);i?d.Variable.isPrimitive(i.type||"number")&&(t.value!==i.value||!d.Variable.isPrimitive(t.type||"number"))?r.addChild(i.name,new d.Variable(i)):d.Variable.isPrimitive(i.type||"number")||(i.type==="structure"?this._hotReloadStructureVariable(t.children,i.children,r.getChild(i.name)):r.addChild(i.name,new d.Variable(i))):r.removeChild(t.name)}),e.forEach(t=>{o.find(a=>a.name===t.name)||r.addChild(t.name,new d.Variable(t))})):e.forEach(t=>{r.addChild(t.name,new d.Variable(t))})}_hotReloadRuntimeScene(o,e,r,t){t.setBackgroundColor(e.r,e.v,e.b),o.title!==e.title&&t.getGame().getRenderer().setWindowTitle(e.title),this._hotReloadVariablesContainer(o.variables,e.variables,t.getVariables()),this._hotReloadRuntimeSceneBehaviorsSharedData(o.behaviorsSharedData,e.behaviorsSharedData,t),this._reinstantiateRuntimeSceneRuntimeBehaviors(r,e.objects,t),this._hotReloadRuntimeSceneObjects(o.objects,e.objects,t),this._hotReloadRuntimeSceneInstances(o.instances,e.instances,t),this._hotReloadRuntimeSceneLayers(o.layers,e.layers,t),t.setEventsGeneratedCodeFunction(e)}_hotReloadRuntimeSceneBehaviorsSharedData(o,e,r){o.forEach(t=>{const i=t.name,a=e.filter(s=>s.name===i)[0];a?m.deepEqual(t,a)||r.setInitialSharedDataForBehavior(a.name,a):r.setInitialSharedDataForBehavior(t.name,null)}),e.forEach(t=>{const i=t.name;o.filter(s=>s.name===i)[0]||r.setInitialSharedDataForBehavior(t.name,t)})}_reinstantiateRuntimeSceneRuntimeBehaviors(o,e,r){e.forEach(t=>{const i=t.name,a=t.behaviors,s=r.getObjects(i);o.forEach(n=>{const h=n.behaviorTypeName;a.filter(l=>l.type===h).forEach(l=>{const f=l.name;this._logs.push({kind:"info",message:'Re-instantiating behavior named "'+f+'" for instances of object "'+i+'".'}),s.forEach(c=>{this._reinstantiateRuntimeObjectRuntimeBehavior(l,c)})})})})}_reinstantiateRuntimeObjectRuntimeBehavior(o,e){const r=o.name,t=e.getBehavior(r);if(!t)return;e.removeBehavior(r),e.addNewBehavior(o);const i=e.getBehavior(r);if(!i){this._logs.push({kind:"error",message:"Could not create behavior "+r+" (type: "+o.type+") for object "+e.getName()});return}for(let a in t)if(!!t.hasOwnProperty(a))if(a==="_behaviorData"){i[a]=i[a]||{};for(let s in t[a])i[a][s]=t[a][s]}else i[a]=t[a]}_hotReloadRuntimeSceneObjects(o,e,r){o.forEach(t=>{const i=t.name,a=e.filter(s=>s.name===i)[0];!a||t.type!==a.type?r.unregisterObject(i):r.isObjectRegistered(i)&&this._hotReloadRuntimeSceneObject(t,a,r)}),e.forEach(t=>{const i=t.name,a=o.filter(s=>s.name===i)[0];(!a||a.type!==t.type)&&!r.isObjectRegistered(i)&&r.registerObject(t)})}_hotReloadRuntimeSceneObject(o,e,r){let t=!0;if(!m.deepEqual(o,e)){this._logs.push({kind:"info",message:'Object "'+e.name+'" was modified and is hot-reloaded.'}),r.updateObject(e);const i=r.getObjects(e.name);i.forEach(a=>{t=a.updateFromObjectData(o,e)&&t}),i.forEach(a=>{this._hotReloadVariablesContainer(o.variables,e.variables,a.getVariables())}),this._hotReloadRuntimeObjectsBehaviors(o.behaviors,e.behaviors,i),this._hotReloadRuntimeObjectsEffects(o.effects,e.effects,i)}t||this._logs.push({kind:"error",message:'Object "'+e.name+'" could not be hot-reloaded. A fresh preview should be run.'})}_hotReloadRuntimeObjectsBehaviors(o,e,r){o.forEach(t=>{const i=t.name,a=e.filter(s=>s.name===i)[0];if(!a)r.forEach(s=>{s.hasBehavior(i)&&(s.removeBehavior(i)||this._logs.push({kind:"error",message:"Behavior "+i+" could not be removed from object"+s.getName()}))});else if(!m.deepEqual(t,a)){let s=!0;r.forEach(n=>{const h=n.getBehavior(a.name);h&&(s=this._hotReloadRuntimeBehavior(t,a,h)&&s)}),s||this._logs.push({kind:"error",message:a.name+" behavior could not be hot-reloaded."})}}),e.forEach(t=>{const i=t.name;if(!o.filter(s=>s.name===i)[0]){let s=!0;r.forEach(n=>{s=n.addNewBehavior(t)&&s}),s||this._logs.push({kind:"error",message:t.name+" behavior could not be added during hot-reload."})}})}_hotReloadRuntimeObjectsEffects(o,e,r){o.forEach(t=>{const i=t.name,a=e.filter(s=>s.name===i)[0];if(!a)r.forEach(s=>{s.hasEffect(i)&&(s.removeEffect(i)||this._logs.push({kind:"error",message:"Effect "+i+" could not be removed from object"+s.getName()}))});else if(!m.deepEqual(t,a)){let s=!0;r.forEach(n=>{t.effectType===a.effectType?s=n.updateAllEffectParameters(a)&&s:(n.removeEffect(t.name),n.addEffect(a))}),s||this._logs.push({kind:"error",message:a.name+" effect could not be hot-reloaded."})}}),e.forEach(t=>{const i=t.name;if(!o.filter(s=>s.name===i)[0]){let s=!0;r.forEach(n=>{s=n.addEffect(t)&&s}),s||this._logs.push({kind:"error",message:t.name+" effect could not be added during hot-reload."})}})}_hotReloadRuntimeBehavior(o,e,r){return r.updateFromBehaviorData(o,e)}_hotReloadRuntimeSceneLayers(o,e,r){o.forEach(t=>{const i=t.name,a=e.filter(s=>s.name===i)[0];if(!a)r.removeLayer(i);else if(r.hasLayer(i)){const s=r.getLayer(i);this._hotReloadRuntimeLayer(t,a,s)}}),e.forEach(t=>{const i=t.name;!o.filter(s=>s.name===i)[0]&&!r.hasLayer(i)&&r.addLayer(t)}),e.forEach((t,i)=>{r.setLayerIndex(t.name,i)})}_hotReloadRuntimeLayer(o,e,r){o.visibility!==e.visibility&&r.show(e.visibility),e.isLightingLayer&&((o.ambientLightColorR!==e.ambientLightColorR||o.ambientLightColorG!==e.ambientLightColorG||o.ambientLightColorB!==e.ambientLightColorB)&&r.setClearColor(e.ambientLightColorR,e.ambientLightColorG,e.ambientLightColorB),o.followBaseLayerCamera!==e.followBaseLayerCamera&&r.setFollowBaseLayerCamera(e.followBaseLayerCamera)),o.renderingType!==e.renderingType&&this._logs.push({kind:"error",message:`Could not change the rendering type (2D, 3D...) layer at runtime (for layer "${e.name}").`}),e.isLightingLayer!==o.isLightingLayer&&this._logs.push({kind:"error",message:`Could not add/remove a lighting layer at runtime (for layer "${e.name}").`}),this._hotReloadRuntimeLayerEffects(o.effects,e.effects,r)}_hotReloadRuntimeLayerEffects(o,e,r){o.forEach(t=>{const i=t.name,a=e.filter(s=>s.name===i)[0];a?r.hasEffect(i)&&(t.effectType!==a.effectType?(r.removeEffect(i),r.addEffect(a)):this._hotReloadRuntimeLayerEffect(t,a,r,i)):r.removeEffect(i)}),e.forEach(t=>{const i=t.name;!o.filter(s=>s.name===i)[0]&&!r.hasEffect(i)&&r.addEffect(t)})}_hotReloadRuntimeLayerEffect(o,e,r,t){for(let i in e.booleanParameters){const a=e.booleanParameters[i];a!==o.booleanParameters[i]&&r.setEffectBooleanParameter(t,i,a)}for(let i in e.doubleParameters){const a=e.doubleParameters[i];a!==o.doubleParameters[i]&&r.setEffectDoubleParameter(t,i,a)}for(let i in e.stringParameters){const a=e.stringParameters[i];a!==o.stringParameters[i]&&r.setEffectStringParameter(t,i,a)}}_hotReloadRuntimeSceneInstances(o,e,r){const t=r.getAdhocListOfAllInstances(),i=m.groupByPersistentUuid(o),a=m.groupByPersistentUuid(e),s=m.groupByPersistentUuid(t);for(let n in i){const h=i[n],l=a[n],f=s[n];h&&(!l||h.name!==l.name)?f&&f.deleteFromScene(r):h&&l&&f&&this._hotReloadRuntimeInstance(h,l,f)}for(let n in a){const h=i[n],l=a[n],f=s[n];l&&(!h||h.name!==l.name)&&!f&&r.createObjectsFrom([l],0,0,0,!0)}}_hotReloadRuntimeInstance(o,e,r){let t=!1;o.x!==e.x&&(r.setX(e.x),t=!0),o.y!==e.y&&(r.setY(e.y),t=!0),o.angle!==e.angle&&(r.setAngle(e.angle),t=!0),o.zOrder!==e.zOrder&&(r.setZOrder(e.zOrder),t=!0),o.layer!==e.layer&&(r.setLayer(e.layer),t=!0),d.Base3DHandler&&d.Base3DHandler.is3D(r)&&(o.z!==e.z&&e.z!==void 0&&(r.setZ(e.z),t=!0),o.rotationX!==e.rotationX&&e.rotationX!==void 0&&(r.setRotationX(e.rotationX),t=!0),o.rotationY!==e.rotationY&&e.rotationY!==void 0&&(r.setRotationY(e.rotationY),t=!0));let i=!1;e.customSize?o.customSize?(o.width!==e.width&&(r.setWidth(e.width),t=!0,i=!0),o.height!==e.height&&(r.setHeight(e.height),t=!0,i=!0)):(r.setWidth(e.width),r.setHeight(e.height),t=!0,i=!0):!e.customSize&&o.customSize&&(i=!0),d.Base3DHandler&&d.Base3DHandler.is3D(r)&&(o.depth!==e.depth&&e.depth!==void 0?(r.setDepth(e.depth),t=!0,i=!0):e.depth===void 0&&o.depth!==void 0&&(i=!0)),this._hotReloadVariablesContainer(o.initialVariables,e.initialVariables,r.getVariables());const a=e.numberProperties.some(n=>{const h=n.name,l=n.value,f=o.numberProperties.filter(c=>c.name===h)[0];return!f||f.value!==l}),s=e.stringProperties.some(n=>{const h=n.name,l=n.value,f=o.stringProperties.filter(c=>c.name===h)[0];return!f||f.value!==l});(a||s||i)&&(r.extraInitializationFromInitialInstance(e),t=!0),t&&r.notifyBehaviorsObjectHotReloaded()}static deepEqual(o,e){if(o===e)return!0;if(o&&e&&typeof o=="object"&&typeof e=="object"){if(o.constructor!==e.constructor)return!1;let r,t,i;if(Array.isArray(o)){if(r=o.length,r!=e.length)return!1;for(t=r;t--!=0;)if(!m.deepEqual(o[t],e[t]))return!1;return!0}if(o.valueOf!==Object.prototype.valueOf)return o.valueOf()===e.valueOf();if(o.toString!==Object.prototype.toString)return o.toString()===e.toString();if(i=Object.keys(o),r=i.length,r!==Object.keys(e).length)return!1;for(t=r;t--!=0;)if(!Object.prototype.hasOwnProperty.call(e,i[t]))return!1;for(t=r;t--!=0;){const a=i[t];if(!m.deepEqual(o[a],e[a]))return!1}return!0}return o!==o&&e!==e}}d.HotReloader=m})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(d){const y=new d.Logger("Hot reloader");class p{constructor(r){this._reloadedScriptElement={};this._logs=[];this._alreadyLoadedScriptFiles={};this._runtimeGame=r}static indexByPersistentUuid(r){return r.reduce(function(t,o){return o.persistentUuid&&t.set(o.persistentUuid,o),t},new Map)}static indexByName(r){return r.reduce(function(t,o){return o.name&&t.set(o.name,o),t},new Map)}_canReloadScriptFile(r){function t(o,e){const a=o.indexOf(e);return a!==-1&&a===o.length-e.length}return!(t(r,".h")||this._alreadyLoadedScriptFiles[r]&&(t(r,"box2d.js")||t(r,"sha256.js")||t(r,"shopify-buy.umd.polyfilled.min.js")||t(r,"pixi-multistyle-text.umd.js")||t(r,"pixi-tilemap.umd.js")||t(r,"bondage.min.js")||t(r,"pixi-particles-pixi-renderer.min.js")||t(r,"pixi-tilemap.umd.js")||t(r,"pixi-tilemap-helper.js")||t(r,"pako/dist/pako.min")))}_reloadScript(r){function t(e,a){const i=e.indexOf(a);return i!==-1&&i===e.length-a.length}if(!this._canReloadScriptFile(r))return this._logs.push({kind:"info",message:"Not reloading "+r+" as it is blocked for hot-reloading."}),Promise.resolve();const o=document.getElementsByTagName("head")[0];return o?new Promise((e,a)=>{const i=this._reloadedScriptElement[r];if(i)o.removeChild(i);else{const n=o.getElementsByTagName("script");for(let h=0;h<n.length;++h){const l=n[h];t(l.src,r)&&o.removeChild(l)}}const s=document.createElement("script");s.src=r+"?timestamp="+Date.now(),s.onload=()=>{e()},s.onerror=n=>{a(n)},o.appendChild(s),this._reloadedScriptElement[r]=s}):Promise.reject(new Error("No head element found, are you in a navigator?"))}hotReload(){y.info("Hot reload started"),this._runtimeGame.pause(!0),this._logs=[];const r=d.projectData,t=d.runtimeGameOptions.scriptFiles;t.forEach(e=>{this._alreadyLoadedScriptFiles[e.path]=!0});const o={};for(let e in d.behaviorsTypes.items)o[e]=d.behaviorsTypes.items[e];return this._reloadScript("data.js").then(()=>{const e=d.projectData,a=d.runtimeGameOptions,i=a.scriptFiles,s=!!a.projectDataOnlyExport;return this.reloadScriptFiles(e,t,i,s).then(()=>{const n=this._computeChangedRuntimeBehaviors(o,d.behaviorsTypes.items);return this._hotReloadRuntimeGame(r,e,n,this._runtimeGame)}).catch(n=>{const h=n.target;h instanceof HTMLScriptElement?this._logs.push({kind:"fatal",message:"Unable to reload script: "+h.src}):this._logs.push({kind:"fatal",message:"Unexpected error happened while hot-reloading: "+n.message})}).then(()=>(y.info("Hot reload finished with logs:",this._logs.map(n=>`
|
|
2
|
+
`+n.kind+": "+n.message)),this._runtimeGame.pause(!1),this._logs))})}_computeChangedRuntimeBehaviors(r,t){const o=[];for(let e in r){const a=r[e],i=t[e];i?a!==i&&(this._logs.push({kind:"info",message:"Behavior with type "+e+" was changed, and will be re-instantiated in gdjs.RuntimeObjects using it."}),o.push({oldBehaviorConstructor:a,newBehaviorConstructor:i,behaviorTypeName:e})):this._logs.push({kind:"warning",message:"Behavior with type "+e+" was removed from the registered behaviors in gdjs."})}return o}reloadScriptFiles(r,t,o,e){const a=[];e||r.layouts.forEach((i,s)=>{a.push(this._reloadScript("code"+s+".js"))});for(let i=0;i<o.length;++i){const s=o[i],n=t.filter(h=>h.path===s.path)[0];n?s.hash!==n.hash&&(this._logs.push({kind:"info",message:"Reloading "+s.path+" because it was changed."}),a.push(this._reloadScript(s.path))):(this._logs.push({kind:"info",message:"Loading "+s.path+" as it was added to the list of scripts."}),a.push(this._reloadScript(s.path)))}for(let i=0;i<t.length;++i){const s=t[i];!o.filter(h=>h.path===s.path)[0]&&!e&&this._logs.push({kind:"warning",message:"Script file "+s.path+" was removed."})}return Promise.all(a)}async _hotReloadRuntimeGame(r,t,o,e){const a=e.getSceneStack(),i=a.getCurrentScene();if(!i){this._logs.push({kind:"error",message:"Can't hot-reload as no scene are opened."});return}e.setProjectData(t),await e.loadFirstAssetsAndStartBackgroundLoading(i.getName(),()=>{}),this._hotReloadVariablesContainer(r.variables,t.variables,e.getVariables());for(const h of t.eventsFunctionsExtensions){const l=r.eventsFunctionsExtensions.find(u=>u.name===h.name),f=l?l.globalVariables:[],g=h.globalVariables;if(f.length>0||g.length>0){const u=e.getVariablesForExtension(h.name);u?this._hotReloadVariablesContainer(f,g,u):e._variablesByExtensionName.set(h.name,new d.VariablesContainer(g))}}const s=p.indexByName(r.layouts),n=p.indexByName(t.layouts);a._stack.forEach(h=>{const l=s.get(h.getName()),f=n.get(h.getName());if(l&&f){this._hotReloadRuntimeScene(r,t,l,f,o,h);for(const g of t.eventsFunctionsExtensions){const u=r.eventsFunctionsExtensions.find(m=>m.name===g.name),v=u?u.sceneVariables:[],c=g.sceneVariables;if(v.length>0||c.length>0){const m=h.getVariablesForExtension(g.name);m?this._hotReloadVariablesContainer(v,c,m):h._variablesByExtensionName.set(g.name,new d.VariablesContainer(c))}}}else this._logs.push({kind:"error",message:"Scene "+(l&&l.name)+" was removed. A fresh preview should be launched."})}),t.externalLayouts.forEach(h=>{const l=r.externalLayouts.filter(f=>f.name===h.name)[0];if(l&&!p.deepEqual(l,h)){const f=s.get(l.associatedLayout),g=n.get(h.associatedLayout);a._stack.forEach(u=>{this._hotReloadRuntimeSceneInstances(r,t,o,f?f.objects:[],g?g.objects:[],l.instances,h.instances,u)})}})}_hotReloadVariablesContainer(r,t,o){t.forEach(e=>{const a=e.name,i=r.find(n=>n.name===a),s=o.get(e.name);i?d.Variable.isPrimitive(e.type||"number")&&(i.value!==e.value||!d.Variable.isPrimitive(i.type||"number"))?(o.remove(a),o.add(a,new d.Variable(e))):d.Variable.isPrimitive(e.type||"number")||(e.type==="structure"?this._hotReloadStructureVariable(i.children,e.children,s):(o.remove(a),o.add(a,new d.Variable(e)))):o.add(a,new d.Variable(e))}),r.forEach(e=>{t.find(i=>i.name===e.name)||o.remove(e.name)}),o.rebuildIndexFrom(t)}_hotReloadStructureVariable(r,t,o){r?(r.forEach(e=>{const a=t.find(i=>i.name===e.name);a?d.Variable.isPrimitive(a.type||"number")&&(e.value!==a.value||!d.Variable.isPrimitive(e.type||"number"))?o.addChild(a.name,new d.Variable(a)):d.Variable.isPrimitive(a.type||"number")||(a.type==="structure"?this._hotReloadStructureVariable(e.children,a.children,o.getChild(a.name)):o.addChild(a.name,new d.Variable(a))):o.removeChild(e.name)}),t.forEach(e=>{r.find(i=>i.name===e.name)||o.addChild(e.name,new d.Variable(e))})):t.forEach(e=>{o.addChild(e.name,new d.Variable(e))})}_hotReloadRuntimeScene(r,t,o,e,a,i){i.setBackgroundColor(e.r,e.v,e.b),o.title!==e.title&&i.getGame().getRenderer().setWindowTitle(e.title),this._hotReloadVariablesContainer(o.variables,e.variables,i.getVariables()),this._hotReloadRuntimeSceneBehaviorsSharedData(o.behaviorsSharedData,e.behaviorsSharedData,i),this._hotReloadRuntimeInstanceContainer(r,t,o,e,a,i),i.setEventsGeneratedCodeFunction(e)}static resolveCustomObjectConfigurations(r,t){return t.map(o=>{const[e,a]=o.type.split("::"),i=r.eventsFunctionsExtensions.find(f=>f.name===e);if(!i)return o;const s=i&&i.eventsBasedObjects.find(f=>f.name===a);if(!s)return o;const n=o,h=n.childrenContent?s.objects.map(f=>({...f,...n.childrenContent[f.name]})):s.objects;return{...s,...o,objects:h,childrenContent:h}})}_hotReloadRuntimeInstanceContainer(r,t,o,e,a,i){const s=p.resolveCustomObjectConfigurations(r,o.objects),n=p.resolveCustomObjectConfigurations(t,e.objects);this._reinstantiateRuntimeSceneRuntimeBehaviors(a,n,i),this._hotReloadRuntimeSceneObjects(s,n,i),this._hotReloadRuntimeSceneInstances(r,t,a,s,n,o.instances,e.instances,i),this._hotReloadRuntimeSceneLayers(o.layers,e.layers,i)}_hotReloadRuntimeSceneBehaviorsSharedData(r,t,o){r.forEach(e=>{const a=e.name,i=t.filter(s=>s.name===a)[0];i?p.deepEqual(e,i)||o.setInitialSharedDataForBehavior(i.name,i):o.setInitialSharedDataForBehavior(e.name,null)}),t.forEach(e=>{const a=e.name;r.filter(s=>s.name===a)[0]||o.setInitialSharedDataForBehavior(e.name,e)})}_reinstantiateRuntimeSceneRuntimeBehaviors(r,t,o){t.forEach(e=>{const a=e.name,i=e.behaviors,s=o.getObjects(a);r.forEach(n=>{const h=n.behaviorTypeName;i.filter(l=>l.type===h).forEach(l=>{const f=l.name;this._logs.push({kind:"info",message:'Re-instantiating behavior named "'+f+'" for instances of object "'+a+'".'}),s.forEach(g=>{this._reinstantiateRuntimeObjectRuntimeBehavior(l,g)})})})})}_reinstantiateRuntimeObjectRuntimeBehavior(r,t){const o=r.name,e=t.getBehavior(o);if(!e)return;t.removeBehavior(o),t.addNewBehavior(r);const a=t.getBehavior(o);if(!a){this._logs.push({kind:"error",message:"Could not create behavior "+o+" (type: "+r.type+") for object "+t.getName()});return}for(let i in e)if(!!e.hasOwnProperty(i))if(i==="_behaviorData"){a[i]=a[i]||{};for(let s in e[i])a[i][s]=e[i][s]}else a[i]=e[i]}_hotReloadRuntimeSceneObjects(r,t,o){r.forEach(e=>{const a=e.name,i=t.filter(s=>s.name===a)[0];!i||e.type!==i.type?o.unregisterObject(a):o.isObjectRegistered(a)&&this._hotReloadRuntimeSceneObject(e,i,o)}),t.forEach(e=>{const a=e.name,i=r.filter(s=>s.name===a)[0];(!i||i.type!==e.type)&&!o.isObjectRegistered(a)&&o.registerObject(e)})}_hotReloadRuntimeSceneObject(r,t,o){let e=!0;if(!p.deepEqual(r,t)){this._logs.push({kind:"info",message:'Object "'+t.name+'" was modified and is hot-reloaded.'}),o.updateObject(t);const a=o.getObjects(t.name);a.forEach(i=>{e=i.updateFromObjectData(r,t)&&e}),this._hotReloadRuntimeObjectsBehaviors(r.behaviors,t.behaviors,a),this._hotReloadRuntimeObjectsEffects(r.effects,t.effects,a)}e||this._logs.push({kind:"error",message:'Object "'+t.name+'" could not be hot-reloaded. A fresh preview should be run.'})}_hotReloadRuntimeObjectsBehaviors(r,t,o){r.forEach(e=>{const a=e.name,i=t.filter(s=>s.name===a)[0];if(!i)o.forEach(s=>{s.hasBehavior(a)&&(s.removeBehavior(a)||this._logs.push({kind:"error",message:"Behavior "+a+" could not be removed from object"+s.getName()}))});else if(!p.deepEqual(e,i)){let s=!0;o.forEach(n=>{const h=n.getBehavior(i.name);h&&(s=this._hotReloadRuntimeBehavior(e,i,h)&&s)}),s||this._logs.push({kind:"error",message:i.name+" behavior could not be hot-reloaded."})}}),t.forEach(e=>{const a=e.name;if(!r.filter(s=>s.name===a)[0]){let s=!0;o.forEach(n=>{s=n.addNewBehavior(e)&&s}),s||this._logs.push({kind:"error",message:e.name+" behavior could not be added during hot-reload."})}})}_hotReloadRuntimeObjectsEffects(r,t,o){r.forEach(e=>{const a=e.name,i=t.filter(s=>s.name===a)[0];if(!i)o.forEach(s=>{s.hasEffect(a)&&(s.removeEffect(a)||this._logs.push({kind:"error",message:"Effect "+a+" could not be removed from object"+s.getName()}))});else if(!p.deepEqual(e,i)){let s=!0;o.forEach(n=>{e.effectType===i.effectType?s=n.updateAllEffectParameters(i)&&s:(n.removeEffect(e.name),n.addEffect(i))}),s||this._logs.push({kind:"error",message:i.name+" effect could not be hot-reloaded."})}}),t.forEach(e=>{const a=e.name;if(!r.filter(s=>s.name===a)[0]){let s=!0;o.forEach(n=>{s=n.addEffect(e)&&s}),s||this._logs.push({kind:"error",message:e.name+" effect could not be added during hot-reload."})}})}_hotReloadRuntimeBehavior(r,t,o){return o.updateFromBehaviorData(r,t)}_hotReloadRuntimeSceneLayers(r,t,o){r.forEach(e=>{const a=e.name,i=t.filter(s=>s.name===a)[0];if(!i)o.removeLayer(a);else if(o.hasLayer(a)){const s=o.getLayer(a);this._hotReloadRuntimeLayer(e,i,s)}}),t.forEach(e=>{const a=e.name;!r.filter(s=>s.name===a)[0]&&!o.hasLayer(a)&&o.addLayer(e)}),t.forEach((e,a)=>{o.setLayerIndex(e.name,a)})}_hotReloadRuntimeLayer(r,t,o){r.visibility!==t.visibility&&o.show(t.visibility),t.isLightingLayer&&((r.ambientLightColorR!==t.ambientLightColorR||r.ambientLightColorG!==t.ambientLightColorG||r.ambientLightColorB!==t.ambientLightColorB)&&o.setClearColor(t.ambientLightColorR,t.ambientLightColorG,t.ambientLightColorB),r.followBaseLayerCamera!==t.followBaseLayerCamera&&o.setFollowBaseLayerCamera(t.followBaseLayerCamera)),r.renderingType!==t.renderingType&&this._logs.push({kind:"error",message:`Could not change the rendering type (2D, 3D...) layer at runtime (for layer "${t.name}").`}),t.isLightingLayer!==r.isLightingLayer&&this._logs.push({kind:"error",message:`Could not add/remove a lighting layer at runtime (for layer "${t.name}").`}),this._hotReloadRuntimeLayerEffects(r.effects,t.effects,o)}_hotReloadRuntimeLayerEffects(r,t,o){r.forEach(e=>{const a=e.name,i=t.filter(s=>s.name===a)[0];i?o.hasEffect(a)&&(e.effectType!==i.effectType?(o.removeEffect(a),o.addEffect(i)):this._hotReloadRuntimeLayerEffect(e,i,o,a)):o.removeEffect(a)}),t.forEach(e=>{const a=e.name;!r.filter(s=>s.name===a)[0]&&!o.hasEffect(a)&&o.addEffect(e)})}_hotReloadRuntimeLayerEffect(r,t,o,e){for(let a in t.booleanParameters){const i=t.booleanParameters[a];i!==r.booleanParameters[a]&&o.setEffectBooleanParameter(e,a,i)}for(let a in t.doubleParameters){const i=t.doubleParameters[a];i!==r.doubleParameters[a]&&o.setEffectDoubleParameter(e,a,i)}for(let a in t.stringParameters){const i=t.stringParameters[a];i!==r.stringParameters[a]&&o.setEffectStringParameter(e,a,i)}}_hotReloadRuntimeSceneInstances(r,t,o,e,a,i,s,n){const h=n.getAdhocListOfAllInstances(),l=p.indexByPersistentUuid(i),f=p.indexByPersistentUuid(s),g=p.indexByPersistentUuid(h),u=p.indexByName(e),v=p.indexByName(a);for(const c of l.keys()){const m=l.get(c),b=f.get(c),R=g.get(c);m&&(!b||m.name!==b.name)&&R&&R.deleteFromScene(n)}for(const c of h){const m=u.get(c.getName()),b=v.get(c.getName());if(!c||!m||!b)continue;const R=l.get(c.persistentUuid),E=f.get(c.persistentUuid);if(R&&E)this._hotReloadRuntimeInstance(r,t,o,m,b,R,E,c);else if(this._hotReloadVariablesContainer(m.variables,b.variables,c.getVariables()),c instanceof d.CustomRuntimeObject){const _=c.getChildrenContainer(),C=m,B=b;this._hotReloadRuntimeInstanceContainer(r,t,C,B,o,_)}}for(const c of f.keys()){const m=l.get(c),b=f.get(c),R=g.get(c);b&&(!m||m.name!==b.name)&&!R&&n.createObjectsFrom([b],0,0,0,!0)}}_hotReloadRuntimeInstance(r,t,o,e,a,i,s,n){let h=!1;i.x!==s.x&&(n.setX(s.x),h=!0),i.y!==s.y&&(n.setY(s.y),h=!0),i.angle!==s.angle&&(n.setAngle(s.angle),h=!0),i.zOrder!==s.zOrder&&(n.setZOrder(s.zOrder),h=!0),i.layer!==s.layer&&(n.setLayer(s.layer),h=!0),d.Base3DHandler&&d.Base3DHandler.is3D(n)&&(i.z!==s.z&&s.z!==void 0&&(n.setZ(s.z),h=!0),i.rotationX!==s.rotationX&&s.rotationX!==void 0&&(n.setRotationX(s.rotationX),h=!0),i.rotationY!==s.rotationY&&s.rotationY!==void 0&&(n.setRotationY(s.rotationY),h=!0));let l=!1;if(s.customSize?i.customSize?(i.width!==s.width&&(n.setWidth(s.width),h=!0,l=!0),i.height!==s.height&&(n.setHeight(s.height),h=!0,l=!0)):(n.setWidth(s.width),n.setHeight(s.height),h=!0,l=!0):!s.customSize&&i.customSize&&(l=!0),d.Base3DHandler&&d.Base3DHandler.is3D(n)&&(i.depth!==s.depth&&s.depth!==void 0?(n.setDepth(s.depth),h=!0,l=!0):s.depth===void 0&&i.depth!==void 0&&(l=!0)),n instanceof d.CustomRuntimeObject){const u=n.getChildrenContainer(),v=e,c=a;this._hotReloadRuntimeInstanceContainer(r,t,v,c,o,u)}this._hotReloadVariablesContainer(this._mergeObjectVariablesData(e.variables,i.initialVariables),this._mergeObjectVariablesData(a.variables,s.initialVariables),n.getVariables());const f=s.numberProperties.some(u=>{const v=u.name,c=u.value,m=i.numberProperties.filter(b=>b.name===v)[0];return!m||m.value!==c}),g=s.stringProperties.some(u=>{const v=u.name,c=u.value,m=i.stringProperties.filter(b=>b.name===v)[0];return!m||m.value!==c});(f||g||l)&&(n.extraInitializationFromInitialInstance(s),h=!0),h&&n.notifyBehaviorsObjectHotReloaded()}_mergeObjectVariablesData(r,t){if(t.length===0)return r;const o=[...r];for(const e of t){const a=o.indexOf(i=>i.name===e.name);a>=0&&(o[a]=e)}return o}static deepEqual(r,t){if(r===t)return!0;if(r&&t&&typeof r=="object"&&typeof t=="object"){if(r.constructor!==t.constructor)return!1;let o,e,a;if(Array.isArray(r)){if(o=r.length,o!=t.length)return!1;for(e=o;e--!=0;)if(!p.deepEqual(r[e],t[e]))return!1;return!0}if(r.valueOf!==Object.prototype.valueOf)return r.valueOf()===t.valueOf();if(r.toString!==Object.prototype.toString)return r.toString()===t.toString();if(a=Object.keys(r),o=a.length,o!==Object.keys(t).length)return!1;for(e=o;e--!=0;)if(!Object.prototype.hasOwnProperty.call(t,a[e]))return!1;for(e=o;e--!=0;){const i=a[e];if(!p.deepEqual(r[i],t[i]))return!1}return!0}return r!==r&&t!==t}}d.HotReloader=p})(gdjs||(gdjs={}));
|
|
2
3
|
//# sourceMappingURL=hot-reloader.js.map
|