Skip to content

Commit 31ef3fe

Browse files
authored
Add TypeScript type checking to JsExtension.js files (#6321)
1 parent 292b23e commit 31ef3fe

File tree

43 files changed

+2839
-2551
lines changed

Some content is hidden

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

43 files changed

+2839
-2551
lines changed

.semaphore/semaphore.yml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ blocks:
5656
- name: GDJS typing and documentation generation
5757
commands:
5858
- checkout
59+
- cache restore newIDE-app-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum newIDE/app/package-lock.json)
5960
- cache restore GDJS-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/package-lock.json)
6061
- cache restore GDJS-tests-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/tests/package-lock.json)
6162
- cd GDJS

.vscode/tasks.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"group": "build",
99
"label": "Start development server",
1010
"detail": "Starts the GDevelop development server.",
11+
"options": { "env": { "NODE_OPTIONS": "--max-old-space-size=8192" } },
1112
"problemMatcher": [
1213
{
1314
"owner": "cra",

Extensions/3D/JsExtension.js

+52-97
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// @flow
1+
//@ts-check
2+
/// <reference path="../JsExtensionTypes.d.ts" />
23
/**
34
* This is a declaration of an extension for GDevelop 5.
45
*
@@ -12,18 +13,9 @@
1213
* More information on https://github.com/4ian/GDevelop/blob/master/newIDE/README-extensions.md
1314
*/
1415

15-
/*::
16-
// Import types to allow Flow to do static type checking on this file.
17-
// Extensions declaration are typed using Flow (like the editor), but the files
18-
// for the game engine are checked with TypeScript annotations.
19-
import { type ObjectsRenderingService, type ObjectsEditorService } from '../JsExtensionTypes.flow.js'
20-
*/
21-
16+
/** @type {ExtensionModule} */
2217
module.exports = {
23-
createExtension: function (
24-
_ /*: (string) => string */,
25-
gd /*: libGDevelop */
26-
) {
18+
createExtension: function (_, gd) {
2719
const extension = new gd.PlatformExtension();
2820
extension
2921
.setExtensionInformation(
@@ -811,7 +803,6 @@ module.exports = {
811803
}
812804

813805
const Cube3DObject = new gd.ObjectJsImplementation();
814-
// $FlowExpectedError - ignore Flow warning as we're creating an object
815806
Cube3DObject.updateProperty = function (
816807
objectContent,
817808
propertyName,
@@ -860,7 +851,6 @@ module.exports = {
860851

861852
return false;
862853
};
863-
// $FlowExpectedError - ignore Flow warning as we're creating an object
864854
Cube3DObject.getProperties = function (objectContent) {
865855
const objectProperties = new gd.MapStringPropertyDescriptor();
866856

@@ -1100,7 +1090,6 @@ module.exports = {
11001090
})
11011091
);
11021092

1103-
// $FlowExpectedError
11041093
Cube3DObject.updateInitialInstanceProperty = function (
11051094
objectContent,
11061095
instance,
@@ -1112,7 +1101,6 @@ module.exports = {
11121101
return false;
11131102
};
11141103

1115-
// $FlowExpectedError
11161104
Cube3DObject.getInitialInstanceProperties = function (
11171105
content,
11181106
instance,
@@ -1665,7 +1653,7 @@ module.exports = {
16651653
'Change the camera rotation to look at an object. The camera top always face the screen.'
16661654
),
16671655
_('Change the camera rotation of _PARAM2_ to look at _PARAM1_'),
1668-
_("Layers and cameras"),
1656+
_('Layers and cameras'),
16691657
'res/conditions/3d_box.svg',
16701658
'res/conditions/3d_box.svg'
16711659
)
@@ -1943,11 +1931,7 @@ module.exports = {
19431931
const effect = extension
19441932
.addEffect('HueAndSaturation')
19451933
.setFullName(_('Hue and saturation'))
1946-
.setDescription(
1947-
_(
1948-
'Adjust hue and saturation.'
1949-
)
1950-
)
1934+
.setDescription(_('Adjust hue and saturation.'))
19511935
.markAsNotWorkingForObjects()
19521936
.markAsOnlyWorkingFor3D()
19531937
.addIncludeFile('Extensions/3D/HueAndSaturationEffect.js');
@@ -1967,11 +1951,7 @@ module.exports = {
19671951
const effect = extension
19681952
.addEffect('Exposure')
19691953
.setFullName(_('Exposure'))
1970-
.setDescription(
1971-
_(
1972-
'Adjust exposure.'
1973-
)
1974-
)
1954+
.setDescription(_('Adjust exposure.'))
19751955
.markAsNotWorkingForObjects()
19761956
.markAsOnlyWorkingFor3D()
19771957
.addIncludeFile('Extensions/3D/ExposureEffect.js');
@@ -1986,11 +1966,7 @@ module.exports = {
19861966
const effect = extension
19871967
.addEffect('Bloom')
19881968
.setFullName(_('Bloom'))
1989-
.setDescription(
1990-
_(
1991-
'Apply a bloom effect.'
1992-
)
1993-
)
1969+
.setDescription(_('Apply a bloom effect.'))
19941970
.markAsNotWorkingForObjects()
19951971
.markAsOnlyWorkingFor3D()
19961972
.addIncludeFile('Extensions/3D/BloomEffect.js');
@@ -2014,12 +1990,8 @@ module.exports = {
20141990
{
20151991
const effect = extension
20161992
.addEffect('BrightnessAndContrast')
2017-
.setFullName(_('Brightness and contrast'))
2018-
.setDescription(
2019-
_(
2020-
'Adjust brightness and contrast.'
2021-
)
2022-
)
1993+
.setFullName(_('Brightness and contrast.'))
1994+
.setDescription(_('Adjust brightness and contrast.'))
20231995
.markAsNotWorkingForObjects()
20241996
.markAsOnlyWorkingFor3D()
20251997
.addIncludeFile('Extensions/3D/BrightnessAndContrastEffect.js');
@@ -2050,68 +2022,47 @@ module.exports = {
20502022
* But it is recommended to create tests for the behaviors/objects properties you created
20512023
* to avoid mistakes.
20522024
*/
2053-
runExtensionSanityTests: function (
2054-
gd /*: libGDevelop */,
2055-
extension /*: gdPlatformExtension*/
2056-
) {
2025+
runExtensionSanityTests: function (gd, extension) {
20572026
return [];
20582027
},
20592028
/**
20602029
* Register editors for objects.
20612030
*
20622031
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change.
20632032
*/
2064-
registerEditorConfigurations: function (
2065-
objectsEditorService /*: ObjectsEditorService */
2066-
) {},
2033+
registerEditorConfigurations: function (objectsEditorService) {},
20672034
/**
20682035
* Register renderers for instance of objects on the scene editor.
20692036
*
20702037
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change.
20712038
*/
2072-
registerInstanceRenderers: function (
2073-
objectsRenderingService /*: ObjectsRenderingService */
2074-
) {
2039+
registerInstanceRenderers: function (objectsRenderingService) {
20752040
const RenderedInstance = objectsRenderingService.RenderedInstance;
20762041
const Rendered3DInstance = objectsRenderingService.Rendered3DInstance;
20772042
const PIXI = objectsRenderingService.PIXI;
20782043
const THREE = objectsRenderingService.THREE;
20792044
const THREE_ADDONS = objectsRenderingService.THREE_ADDONS;
20802045

20812046
const materialIndexToFaceIndex = {
2082-
// $FlowFixMe
20832047
0: 3,
2084-
// $FlowFixMe
20852048
1: 2,
2086-
// $FlowFixMe
20872049
2: 5,
2088-
// $FlowFixMe
20892050
3: 4,
2090-
// $FlowFixMe
20912051
4: 0,
2092-
// $FlowFixMe
20932052
5: 1,
20942053
};
20952054

20962055
const noRepeatTextureVertexIndexToUvMapping = {
2097-
// $FlowFixMe
20982056
0: [0, 0],
2099-
// $FlowFixMe
21002057
1: [1, 0],
2101-
// $FlowFixMe
21022058
2: [0, 1],
2103-
// $FlowFixMe
21042059
3: [1, 1],
21052060
};
21062061

21072062
const noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ = {
2108-
// $FlowFixMe
21092063
0: [0, 1],
2110-
// $FlowFixMe
21112064
1: [0, 0],
2112-
// $FlowFixMe
21132065
2: [1, 1],
2114-
// $FlowFixMe
21152066
3: [1, 0],
21162067
};
21172068

@@ -2157,6 +2108,11 @@ module.exports = {
21572108
};
21582109

21592110
class RenderedCube3DObject2DInstance extends RenderedInstance {
2111+
/** @type {number} */
2112+
_centerX = 0;
2113+
/** @type {number} */
2114+
_centerY = 0;
2115+
21602116
constructor(
21612117
project,
21622118
layout,
@@ -2173,10 +2129,9 @@ module.exports = {
21732129
pixiContainer,
21742130
pixiResourcesLoader
21752131
);
2176-
/**
2177-
* Name of the resource that is rendered.
2178-
* If no face is visible, this will be null.
2179-
*/
2132+
2133+
// Name of the resource that is rendered.
2134+
// If no face is visible, this will be null.
21802135
this._renderedResourceName = undefined;
21812136
const properties = associatedObjectConfiguration.getProperties();
21822137
this._defaultWidth = parseFloat(properties.get('width').getValue());
@@ -2206,12 +2161,9 @@ module.exports = {
22062161
}
22072162

22082163
static getThumbnail(project, resourcesLoader, objectConfiguration) {
2209-
const instance = this._instance;
2210-
2211-
const textureResourceName =
2212-
RenderedCube3DObject2DInstance._getResourceNameToDisplay(
2213-
objectConfiguration
2214-
);
2164+
const textureResourceName = RenderedCube3DObject2DInstance._getResourceNameToDisplay(
2165+
objectConfiguration
2166+
);
22152167
if (textureResourceName) {
22162168
return resourcesLoader.getResourceFullUrl(
22172169
project,
@@ -2223,20 +2175,18 @@ module.exports = {
22232175
}
22242176

22252177
updateTextureIfNeeded() {
2226-
const textureName =
2227-
RenderedCube3DObject2DInstance._getResourceNameToDisplay(
2228-
this._associatedObjectConfiguration
2229-
);
2178+
const textureName = RenderedCube3DObject2DInstance._getResourceNameToDisplay(
2179+
this._associatedObjectConfiguration
2180+
);
22302181
if (textureName === this._renderedResourceName) return;
22312182

22322183
this.updateTexture();
22332184
}
22342185

22352186
updateTexture() {
2236-
const textureName =
2237-
RenderedCube3DObject2DInstance._getResourceNameToDisplay(
2238-
this._associatedObjectConfiguration
2239-
);
2187+
const textureName = RenderedCube3DObject2DInstance._getResourceNameToDisplay(
2188+
this._associatedObjectConfiguration
2189+
);
22402190

22412191
if (!textureName) {
22422192
this._renderFallbackObject = true;
@@ -2494,10 +2444,9 @@ module.exports = {
24942444
continue;
24952445
}
24962446

2497-
const shouldRepeatTexture =
2498-
this._shouldRepeatTextureOnFace[
2499-
materialIndexToFaceIndex[materialIndex]
2500-
];
2447+
const shouldRepeatTexture = this._shouldRepeatTextureOnFace[
2448+
materialIndexToFaceIndex[materialIndex]
2449+
];
25012450

25022451
const shouldOrientateFacesTowardsY = this._facesOrientation === 'Y';
25032452

@@ -2532,13 +2481,16 @@ module.exports = {
25322481
}
25332482
} else {
25342483
if (shouldOrientateFacesTowardsY) {
2535-
[x, y] =
2536-
noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];
2484+
[x, y] = noRepeatTextureVertexIndexToUvMapping[
2485+
vertexIndex % 4
2486+
];
25372487
} else {
2538-
[x, y] =
2539-
noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[
2540-
vertexIndex % 4
2541-
];
2488+
[
2489+
x,
2490+
y,
2491+
] = noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[
2492+
vertexIndex % 4
2493+
];
25422494
}
25432495
}
25442496
break;
@@ -2568,13 +2520,16 @@ module.exports = {
25682520
}
25692521
} else {
25702522
if (shouldOrientateFacesTowardsY) {
2571-
[x, y] =
2572-
noRepeatTextureVertexIndexToUvMapping[vertexIndex % 4];
2523+
[x, y] = noRepeatTextureVertexIndexToUvMapping[
2524+
vertexIndex % 4
2525+
];
25732526
} else {
2574-
[x, y] =
2575-
noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[
2576-
vertexIndex % 4
2577-
];
2527+
[
2528+
x,
2529+
y,
2530+
] = noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ[
2531+
vertexIndex % 4
2532+
];
25782533
x = -x;
25792534
y = -y;
25802535
}
@@ -3111,7 +3066,7 @@ module.exports = {
31113066
);
31123067
threeObject.updateMatrixWorld(true);
31133068
const boundingBox = new THREE.Box3().setFromObject(threeObject);
3114-
3069+
31153070
const shouldKeepModelOrigin = !this._originPoint;
31163071
if (shouldKeepModelOrigin) {
31173072
// Keep the origin as part of the model.

Extensions/AdMob/JsExtension.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// @flow
1+
//@ts-check
2+
/// <reference path="../JsExtensionTypes.d.ts" />
23
/**
34
* This is a declaration of an extension for GDevelop 5.
45
*
@@ -12,18 +13,9 @@
1213
* More information on https://github.com/4ian/GDevelop/blob/master/newIDE/README-extensions.md
1314
*/
1415

15-
/*::
16-
// Import types to allow Flow to do static type checking on this file.
17-
// Extensions declaration are typed using Flow (like the editor), but the files
18-
// for the game engine are checked with TypeScript annotations.
19-
import { type ObjectsRenderingService, type ObjectsEditorService } from '../JsExtensionTypes.flow.js'
20-
*/
21-
16+
/** @type {ExtensionModule} */
2217
module.exports = {
23-
createExtension: function (
24-
_ /*: (string) => string */,
25-
gd /*: libGDevelop */
26-
) {
18+
createExtension: function (_, gd) {
2719
const extension = new gd.PlatformExtension();
2820
extension
2921
.setExtensionInformation(
@@ -789,10 +781,7 @@ module.exports = {
789781

790782
return extension;
791783
},
792-
runExtensionSanityTests: function (
793-
gd /*: libGDevelop */,
794-
extension /*: gdPlatformExtension*/
795-
) {
784+
runExtensionSanityTests: function (gd, extension) {
796785
return [];
797786
},
798787
};

0 commit comments

Comments
 (0)