Skip to content

Commit

Permalink
Use JSX for rendering in game debugger message
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Nov 30, 2023
1 parent e2c40ff commit 2cf4d7c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @jsx h

namespace gdjs {
/** A minimal utility to define DOM elements. */
function h<K extends keyof HTMLElementTagNameMap>(
Expand Down Expand Up @@ -123,48 +125,34 @@ namespace gdjs {
const errorIsInJs = isErrorComingFromJavaScriptCode(
this._uncaughtException
);
this._uncaughtExceptionElement = h(
'div',
{
style: styles.errorContainer,
},
h(
'button',
{
style: styles.closeButton,
onClick: () => this.setUncaughtException(null),
},
'×'
),
h(
'h2',
{
style: styles.errorTitle,
},
errorIsInJs
? 'An error happened in a JavaScript code event.'
: 'A crash or error happened in the game.'
),
h(
'p',
{
style: styles.errorMessage,
},
(errorIsInJs
? 'This error comes from a JavaScript code event. Verify your code to ensure no error is happening. You can use the Developer Tools (menu "View" > "Toggle Developer Tools"). Full error is: '
: "If you're using JavaScript, verify your code. Otherwise, this might be an issue with GDevelop - consider reporting a bug. Full error is: ") +
this._uncaughtException.message
),
h(
'pre',
{
style: styles.stacktrace,
},
this._uncaughtException.stack || '(No stracktrace).'
)
this._uncaughtExceptionElement = (
<div style={styles.errorContainer}>
<button
style={styles.closeButton}
onClick={() => this.setUncaughtException(null)}
>
×
</button>
<h2 style={styles.errorTitle}>
{errorIsInJs
? 'An error happened in a JavaScript code event.'
: 'A crash or error happened in the game.'}
</h2>
<p style={styles.errorMessage}>
{(errorIsInJs
? 'This error comes from a JavaScript code event. Verify your code to ensure no error is happening. You can use the Developer Tools (menu "View" > "Toggle Developer Tools"). Full error is: '
: "If you're using JavaScript, verify your code. Otherwise, this might be an issue with GDevelop - consider reporting a bug. Full error is: ") +
this._uncaughtException.message}
</p>
<pre style={styles.stacktrace}>
{this._uncaughtException.stack || '(No stracktrace).'}
</pre>
,
</div>
);

domElementContainer.appendChild(this._uncaughtExceptionElement);
if (this._uncaughtExceptionElement)
domElementContainer.appendChild(this._uncaughtExceptionElement);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GDJS/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('fs').promises;

/** @param {string} outPath */
const renameBuiltFile = (outPath) => {
return outPath.replace(/\.ts$/, '.js');
return outPath.replace(/\.tsx?$/, '.js');
};

const bundledOutPath =
Expand Down
4 changes: 2 additions & 2 deletions GDJS/scripts/lib/runtime-files-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const extensionsRuntimePath = path.join(gdevelopRootPath, 'Extensions');
const gdjsRuntimePath = path.join(gdjsRootPath, 'Runtime');

// The extensions to be included in the bundled Runtime (will be built with esbuild or copied).
const allowedExtensions = ['.js', '.ts', '.html', '.json', '.xml', '.map', '.wasm'];
const allowedExtensions = ['.js', '.ts', '.tsx', '.html', '.json', '.xml', '.map', '.wasm'];

// These extensions will be built with esbuild (the other will be copied).
const transformIncludedExtensions = ['.js', '.ts'];
const transformIncludedExtensions = ['.js', '.ts', '.tsx'];

// Among the files matching the previous extensions, these extensions won't be built with esbuild
// (they will be copied).
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
},
"baseUrl": "./",
"lib": ["DOM", "ES5", "ScriptHost", "ES2015.Iterable", "ES2015.Promise"],
"typeRoots": ["GDJS/node_modules/@types/"]
"typeRoots": ["GDJS/node_modules/@types/"],
// JSX syntax for lightweight rendering in the game engine:
"jsx": "react",
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment"
},
"include": [
"GDJS/Runtime/**/*",
Expand Down

0 comments on commit 2cf4d7c

Please sign in to comment.