Skip to content

Commit bc606ed

Browse files
authored
Add a console to the games debugger (#2770)
* When launching the Debugger to inspect a game, open the Console to see internal messages sent by the game, JavaScript code or the game engine. * This is an advanced feature that is useful to find issues in your game or to see if your game is displaying any internal error.
1 parent c705f89 commit bc606ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+946
-220
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
},
8181
{
8282
"type": "typescript",
83-
"tsconfig": "GDJS/tsconfig.json",
83+
"tsconfig": "tsconfig.json",
8484
"option": "watch",
8585
"problemMatcher": ["$tsc-watch"],
8686
"group": "test",

Extensions/AdMob/admobtools.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace gdjs {
22
declare var admob: any;
33

44
export namespace adMob {
5+
const logger = new gdjs.Logger('AdMob');
6+
57
export enum AdSizeType {
68
BANNER,
79
LARGE_BANNER,
@@ -127,13 +129,13 @@ namespace gdjs {
127129
() => {
128130
bannerShowing = true;
129131
bannerLoading = false;
130-
console.info('AdMob banner successfully shown.');
132+
logger.info('AdMob banner successfully shown.');
131133
},
132134
(error) => {
133135
bannerShowing = false;
134136
bannerLoading = false;
135137
bannerErrored = true;
136-
console.error('Error while showing an AdMob banner:', error);
138+
logger.error('Error while showing an AdMob banner:', error);
137139
}
138140
);
139141
};
@@ -190,14 +192,14 @@ namespace gdjs {
190192
})
191193
.then(
192194
() => {
193-
console.info('AdMob interstitial successfully loaded.');
195+
logger.info('AdMob interstitial successfully loaded.');
194196
if (displayWhenLoaded) showInterstitial();
195197
},
196198
(error) => {
197199
interstitialLoading = false;
198200
interstitialReady = false;
199201
interstitialErrored = true;
200-
console.error('Error while loading a interstitial:', error);
202+
logger.error('Error while loading a interstitial:', error);
201203
}
202204
);
203205
};
@@ -216,7 +218,7 @@ namespace gdjs {
216218
(error) => {
217219
interstitialShowing = false;
218220
interstitialErrored = true;
219-
console.error('Error while trying to show an interstitial:', error);
221+
logger.error('Error while trying to show an interstitial:', error);
220222
}
221223
);
222224
};
@@ -270,15 +272,15 @@ namespace gdjs {
270272
})
271273
.then(
272274
() => {
273-
console.info('AdMob reward video successfully loaded.');
275+
logger.info('AdMob reward video successfully loaded.');
274276

275277
if (displayWhenLoaded) showVideo();
276278
},
277279
(error) => {
278280
videoLoading = false;
279281
videoReady = false;
280282
videoErrored = true;
281-
console.error('Error while loading a reward video:', error);
283+
logger.error('Error while loading a reward video:', error);
282284
}
283285
);
284286
};
@@ -298,7 +300,7 @@ namespace gdjs {
298300
(error) => {
299301
videoShowing = false;
300302
videoErrored = true;
301-
console.error('Error while trying to show a reward video:', error);
303+
logger.error('Error while trying to show a reward video:', error);
302304
}
303305
);
304306
};

Extensions/DebuggerTools/JsExtension.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ module.exports = {
8383
.setIncludeFile('Extensions/DebuggerTools/debuggertools.js')
8484
.setFunctionName('gdjs.evtTools.debuggerTools.enableDebugDraw');
8585

86+
extension
87+
.addAction(
88+
'ConsoleLog',
89+
_('Log a message to the console'),
90+
_("Logs a message to the debugger's console."),
91+
_(
92+
'Log message _PARAM0_ of type _PARAM1_ to the console in group _PARAM2_'
93+
),
94+
_('Debugger Tools'),
95+
'res/actions/bug32.png',
96+
'res/actions/bug32.png'
97+
)
98+
.addParameter('string', 'Message to log', '', false)
99+
.addParameter(
100+
'stringWithSelector',
101+
'Message type',
102+
'["info", "warning", "error"]',
103+
true
104+
)
105+
.addParameter('string', 'Group of messages', '', true)
106+
.getCodeExtraInformation()
107+
.setIncludeFile('Extensions/DebuggerTools/debuggertools.js')
108+
.setFunctionName('gdjs.evtTools.debuggerTools.log');
109+
86110
return extension;
87111
},
88112
runExtensionSanityTests: function (

Extensions/DebuggerTools/debuggertools.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ namespace gdjs {
1313
runtimeScene.getGame().pause(true);
1414
};
1515

16+
/**
17+
* Logs a message to the console.
18+
* @param message - The message to log.
19+
* @param type - The type of log (info, warning or error).
20+
* @param group - The group of messages it belongs to.
21+
*/
22+
export const log = function (
23+
message: string,
24+
type: 'info' | 'warning' | 'error',
25+
group: string
26+
) {
27+
gdjs.log(group, message, type, false);
28+
};
29+
1630
/**
1731
* Enable or disable the debug draw.
1832
* @param runtimeScene - The current scene.

Extensions/DialogueTree/dialoguetools.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// @ts-nocheck - Weird usage of `this` in this file. Should be refactored.
22

33
namespace gdjs {
4+
const logger = new gdjs.Logger('Dialogue tree');
5+
46
gdjs.dialogueTree = {};
57
gdjs.dialogueTree.runner = new bondage.Runner();
68

@@ -21,7 +23,7 @@ namespace gdjs {
2123
gdjs.dialogueTree.startFrom(startDialogueNode);
2224
}
2325
} catch (e) {
24-
console.error(e);
26+
logger.error('Error while loading from scene variable: ', e);
2527
}
2628
};
2729

@@ -42,10 +44,7 @@ namespace gdjs {
4244
.getJsonManager()
4345
.loadJson(jsonResourceName, function (error, content) {
4446
if (error) {
45-
console.error(
46-
'An error happened while loading JSON resource:',
47-
error
48-
);
47+
logger.error('An error happened while loading JSON resource:', error);
4948
} else {
5049
if (!content) {
5150
return;
@@ -54,7 +53,7 @@ namespace gdjs {
5453
try {
5554
gdjs.dialogueTree.runner.load(gdjs.dialogueTree.yarnData);
5655
} catch (error) {
57-
console.error(
56+
logger.error(
5857
'An error happened while loading parsing the dialogue tree data:',
5958
error
6059
);
@@ -155,7 +154,7 @@ namespace gdjs {
155154
this.clipTextEnd >= this.dialogueText.length
156155
) {
157156
if (gdjs.dialogueTree.getVariable('debug')) {
158-
console.warn(
157+
logger.warn(
159158
'Scroll completed:',
160159
this.clipTextEnd,
161160
'/',
@@ -244,15 +243,15 @@ namespace gdjs {
244243
gdjs.dialogueTree.pauseScrolling = false;
245244
commandCalls.splice(index, 1);
246245
if (gdjs.dialogueTree.getVariable('debug')) {
247-
console.info('CMD:', call);
246+
logger.info('CMD:', call);
248247
}
249248
}, parseInt(call.params[1], 10));
250249
}
251250
if (call.cmd === command) {
252251
gdjs.dialogueTree.commandParameters = call.params;
253252
commandCalls.splice(index, 1);
254253
if (gdjs.dialogueTree.getVariable('debug')) {
255-
console.info('CMD:', call);
254+
logger.info('CMD:', call);
256255
}
257256
return true;
258257
}
@@ -366,7 +365,7 @@ namespace gdjs {
366365
this.dialogueData = this.dialogue.next().value;
367366
gdjs.dialogueTree.goToNextDialogueLine();
368367
} catch (error) {
369-
console.error(
368+
logger.error(
370369
`An error happened when trying to access the dialogue branch!`,
371370
error
372371
);
@@ -562,7 +561,7 @@ namespace gdjs {
562561
this.selectedOption = -1;
563562
this.selectedOptionUpdated = false;
564563
if (gdjs.dialogueTree.getVariable('debug')) {
565-
console.info('parsing:', this.dialogueData);
564+
logger.info('Parsing:', this.dialogueData);
566565
}
567566
if (!this.dialogueData) {
568567
gdjs.dialogueTree.stopRunningDialogue();
@@ -797,7 +796,7 @@ namespace gdjs {
797796
gdjs.dialogueTree.loadState = function (inputVariable: gdjs.Variable) {
798797
const loadedState = inputVariable.toJSObject();
799798
if (!loadedState) {
800-
console.error('Load state variable is empty:', inputVariable);
799+
logger.error('Load state variable is empty:', inputVariable);
801800
return;
802801
}
803802
try {
@@ -808,7 +807,7 @@ namespace gdjs {
808807
gdjs.dialogueTree.runner.variables.set(key, value);
809808
});
810809
} catch (e) {
811-
console.error('Failed to load state from variable:', inputVariable, e);
810+
logger.error('Failed to load state from variable:', inputVariable, e);
812811
}
813812
};
814813

Extensions/ExampleJsExtension/dummyeffect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//A simple PIXI filter doing some color changes
22
namespace gdjs {
3+
const logger = new gdjs.Logger('Dummy effect');
34
import PIXI = GlobalPIXIModule.PIXI;
45

56
const DummyPixiFilter = function () {
@@ -46,7 +47,7 @@ namespace gdjs {
4647
// `effectData.stringParameters.someImage`
4748
// `effectData.stringParameters.someColor`
4849
// `effectData.booleanParameters.someBoolean`
49-
console.info(
50+
logger.info(
5051
'The PIXI texture found for the Dummy Effect (not actually used):',
5152
(layer
5253
.getRuntimeScene()

Extensions/ExampleJsExtension/dummyruntimebehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
namespace gdjs {
2+
const logger = new gdjs.Logger('Dummy behavior');
3+
24
/**
35
* The DummyRuntimeBehavior changes a variable in the object that is owning
46
* it, at every tick before events are run, to set it to the string that was
@@ -20,7 +22,7 @@ namespace gdjs {
2022
this._textToSet = behaviorData.property1;
2123

2224
// You can also run arbitrary code at the creation of the behavior:
23-
console.log('DummyRuntimeBehavior was created for object:', owner);
25+
logger.log('DummyRuntimeBehavior was created for object:', owner);
2426
}
2527

2628
updateFromBehaviorData(oldBehaviorData, newBehaviorData): boolean {

Extensions/ExampleJsExtension/dummyruntimeobject.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
namespace gdjs {
2+
const logger = new gdjs.Logger('Dummy object');
3+
24
/**
35
* A dummy object doing showing a text on screen.
46
* @ignore
@@ -126,9 +128,9 @@ namespace gdjs {
126128
* A dummy method that can be called from events
127129
*/
128130
myMethod(number1: float, text1: string) {
129-
console.log('Congrats, this method was called on a DummyRuntimeObject');
130-
console.log('Here is the object:', this);
131-
console.log('Here are the arguments passed from events:', number1, text1);
131+
logger.log('Congrats, this method was called on a DummyRuntimeObject');
132+
logger.log('Here is the object:', this);
133+
logger.log('Here are the arguments passed from events:', number1, text1);
132134
}
133135
}
134136
gdjs.registerObject(

Extensions/ExampleJsExtension/dummywithshareddataruntimebehavior.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
namespace gdjs {
2+
const logger = new gdjs.Logger('Dummy behavior (with shared data)');
23
export class DummyWithSharedDataRuntimeBehavior extends gdjs.RuntimeBehavior {
34
_textToSet: string;
45

@@ -20,11 +21,11 @@ namespace gdjs {
2021
this._textToSet = (sharedData as any).sharedProperty1;
2122

2223
// You can also run arbitrary code at the creation of the behavior:
23-
console.log(
24+
logger.log(
2425
'DummyWithSharedDataRuntimeBehavior was created for object:',
2526
owner
2627
);
27-
console.log('The shared data are:', sharedData);
28+
logger.log('The shared data are:', sharedData);
2829
}
2930

3031
updateFromBehaviorData(oldBehaviorData, newBehaviorData): boolean {

Extensions/ExampleJsExtension/examplejsextensiontools.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
namespace gdjs {
2+
const logger = new gdjs.Logger('Example extension');
3+
24
export namespace evtTools {
35
/**
46
* This is an example of some functions that can be used through events.
@@ -24,15 +26,15 @@ namespace gdjs {
2426
* that will be called at this moment.
2527
*/
2628
gdjs.registerRuntimeSceneLoadedCallback(function (runtimeScene) {
27-
console.log('A gdjs.RuntimeScene was loaded:', runtimeScene);
29+
logger.log('A gdjs.RuntimeScene was loaded:', runtimeScene);
2830
});
2931

3032
/**
3133
* In **rare cases** you may want to run code at the end of a scene. You can define a callback
3234
* that will be called at this moment.
3335
*/
3436
gdjs.registerRuntimeSceneUnloadedCallback(function (runtimeScene) {
35-
console.log('A gdjs.RuntimeScene was unloaded:', runtimeScene);
37+
logger.log('A gdjs.RuntimeScene was unloaded:', runtimeScene);
3638
});
3739

3840
/**
@@ -42,15 +44,15 @@ namespace gdjs {
4244
runtimeScene,
4345
runtimeObject
4446
) {
45-
console.log(
47+
logger.log(
4648
'A gdjs.RuntimeObject was deleted from a gdjs.RuntimeScene:',
4749
runtimeScene,
4850
runtimeObject
4951
);
5052
});
5153

5254
// Finally, note that you can also simply run code here. Most of the time you shouldn't need it though.
53-
console.log(
55+
logger.log(
5456
'gdjs.exampleJsExtension was created, with myGlobalString containing:' +
5557
myGlobalString
5658
);

0 commit comments

Comments
 (0)