1
- // @flow
1
+ //@ts -check
2
+ /// <reference path="../JsExtensionTypes.d.ts" />
2
3
/**
3
4
* This is a declaration of an extension for GDevelop 5.
4
5
*
12
13
* More information on https://github.com/4ian/GDevelop/blob/master/newIDE/README-extensions.md
13
14
*/
14
15
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 } */
22
17
module . exports = {
23
- createExtension : function (
24
- _ /*: (string) => string */ ,
25
- gd /*: libGDevelop */
26
- ) {
18
+ createExtension : function ( _ , gd ) {
27
19
const extension = new gd . PlatformExtension ( ) ;
28
20
extension
29
21
. setExtensionInformation (
@@ -811,7 +803,6 @@ module.exports = {
811
803
}
812
804
813
805
const Cube3DObject = new gd . ObjectJsImplementation ( ) ;
814
- // $FlowExpectedError - ignore Flow warning as we're creating an object
815
806
Cube3DObject . updateProperty = function (
816
807
objectContent ,
817
808
propertyName ,
@@ -860,7 +851,6 @@ module.exports = {
860
851
861
852
return false ;
862
853
} ;
863
- // $FlowExpectedError - ignore Flow warning as we're creating an object
864
854
Cube3DObject . getProperties = function ( objectContent ) {
865
855
const objectProperties = new gd . MapStringPropertyDescriptor ( ) ;
866
856
@@ -1100,7 +1090,6 @@ module.exports = {
1100
1090
} )
1101
1091
) ;
1102
1092
1103
- // $FlowExpectedError
1104
1093
Cube3DObject . updateInitialInstanceProperty = function (
1105
1094
objectContent ,
1106
1095
instance ,
@@ -1112,7 +1101,6 @@ module.exports = {
1112
1101
return false ;
1113
1102
} ;
1114
1103
1115
- // $FlowExpectedError
1116
1104
Cube3DObject . getInitialInstanceProperties = function (
1117
1105
content ,
1118
1106
instance ,
@@ -1665,7 +1653,7 @@ module.exports = {
1665
1653
'Change the camera rotation to look at an object. The camera top always face the screen.'
1666
1654
) ,
1667
1655
_ ( 'Change the camera rotation of _PARAM2_ to look at _PARAM1_' ) ,
1668
- _ ( " Layers and cameras" ) ,
1656
+ _ ( ' Layers and cameras' ) ,
1669
1657
'res/conditions/3d_box.svg' ,
1670
1658
'res/conditions/3d_box.svg'
1671
1659
)
@@ -1943,11 +1931,7 @@ module.exports = {
1943
1931
const effect = extension
1944
1932
. addEffect ( 'HueAndSaturation' )
1945
1933
. setFullName ( _ ( 'Hue and saturation' ) )
1946
- . setDescription (
1947
- _ (
1948
- 'Adjust hue and saturation.'
1949
- )
1950
- )
1934
+ . setDescription ( _ ( 'Adjust hue and saturation.' ) )
1951
1935
. markAsNotWorkingForObjects ( )
1952
1936
. markAsOnlyWorkingFor3D ( )
1953
1937
. addIncludeFile ( 'Extensions/3D/HueAndSaturationEffect.js' ) ;
@@ -1967,11 +1951,7 @@ module.exports = {
1967
1951
const effect = extension
1968
1952
. addEffect ( 'Exposure' )
1969
1953
. setFullName ( _ ( 'Exposure' ) )
1970
- . setDescription (
1971
- _ (
1972
- 'Adjust exposure.'
1973
- )
1974
- )
1954
+ . setDescription ( _ ( 'Adjust exposure.' ) )
1975
1955
. markAsNotWorkingForObjects ( )
1976
1956
. markAsOnlyWorkingFor3D ( )
1977
1957
. addIncludeFile ( 'Extensions/3D/ExposureEffect.js' ) ;
@@ -1986,11 +1966,7 @@ module.exports = {
1986
1966
const effect = extension
1987
1967
. addEffect ( 'Bloom' )
1988
1968
. setFullName ( _ ( 'Bloom' ) )
1989
- . setDescription (
1990
- _ (
1991
- 'Apply a bloom effect.'
1992
- )
1993
- )
1969
+ . setDescription ( _ ( 'Apply a bloom effect.' ) )
1994
1970
. markAsNotWorkingForObjects ( )
1995
1971
. markAsOnlyWorkingFor3D ( )
1996
1972
. addIncludeFile ( 'Extensions/3D/BloomEffect.js' ) ;
@@ -2014,12 +1990,8 @@ module.exports = {
2014
1990
{
2015
1991
const effect = extension
2016
1992
. 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.' ) )
2023
1995
. markAsNotWorkingForObjects ( )
2024
1996
. markAsOnlyWorkingFor3D ( )
2025
1997
. addIncludeFile ( 'Extensions/3D/BrightnessAndContrastEffect.js' ) ;
@@ -2050,68 +2022,47 @@ module.exports = {
2050
2022
* But it is recommended to create tests for the behaviors/objects properties you created
2051
2023
* to avoid mistakes.
2052
2024
*/
2053
- runExtensionSanityTests : function (
2054
- gd /*: libGDevelop */ ,
2055
- extension /*: gdPlatformExtension*/
2056
- ) {
2025
+ runExtensionSanityTests : function ( gd , extension ) {
2057
2026
return [ ] ;
2058
2027
} ,
2059
2028
/**
2060
2029
* Register editors for objects.
2061
2030
*
2062
2031
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change.
2063
2032
*/
2064
- registerEditorConfigurations : function (
2065
- objectsEditorService /*: ObjectsEditorService */
2066
- ) { } ,
2033
+ registerEditorConfigurations : function ( objectsEditorService ) { } ,
2067
2034
/**
2068
2035
* Register renderers for instance of objects on the scene editor.
2069
2036
*
2070
2037
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change.
2071
2038
*/
2072
- registerInstanceRenderers : function (
2073
- objectsRenderingService /*: ObjectsRenderingService */
2074
- ) {
2039
+ registerInstanceRenderers : function ( objectsRenderingService ) {
2075
2040
const RenderedInstance = objectsRenderingService . RenderedInstance ;
2076
2041
const Rendered3DInstance = objectsRenderingService . Rendered3DInstance ;
2077
2042
const PIXI = objectsRenderingService . PIXI ;
2078
2043
const THREE = objectsRenderingService . THREE ;
2079
2044
const THREE_ADDONS = objectsRenderingService . THREE_ADDONS ;
2080
2045
2081
2046
const materialIndexToFaceIndex = {
2082
- // $FlowFixMe
2083
2047
0 : 3 ,
2084
- // $FlowFixMe
2085
2048
1 : 2 ,
2086
- // $FlowFixMe
2087
2049
2 : 5 ,
2088
- // $FlowFixMe
2089
2050
3 : 4 ,
2090
- // $FlowFixMe
2091
2051
4 : 0 ,
2092
- // $FlowFixMe
2093
2052
5 : 1 ,
2094
2053
} ;
2095
2054
2096
2055
const noRepeatTextureVertexIndexToUvMapping = {
2097
- // $FlowFixMe
2098
2056
0 : [ 0 , 0 ] ,
2099
- // $FlowFixMe
2100
2057
1 : [ 1 , 0 ] ,
2101
- // $FlowFixMe
2102
2058
2 : [ 0 , 1 ] ,
2103
- // $FlowFixMe
2104
2059
3 : [ 1 , 1 ] ,
2105
2060
} ;
2106
2061
2107
2062
const noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ = {
2108
- // $FlowFixMe
2109
2063
0 : [ 0 , 1 ] ,
2110
- // $FlowFixMe
2111
2064
1 : [ 0 , 0 ] ,
2112
- // $FlowFixMe
2113
2065
2 : [ 1 , 1 ] ,
2114
- // $FlowFixMe
2115
2066
3 : [ 1 , 0 ] ,
2116
2067
} ;
2117
2068
@@ -2157,6 +2108,11 @@ module.exports = {
2157
2108
} ;
2158
2109
2159
2110
class RenderedCube3DObject2DInstance extends RenderedInstance {
2111
+ /** @type {number } */
2112
+ _centerX = 0 ;
2113
+ /** @type {number } */
2114
+ _centerY = 0 ;
2115
+
2160
2116
constructor (
2161
2117
project ,
2162
2118
layout ,
@@ -2173,10 +2129,9 @@ module.exports = {
2173
2129
pixiContainer ,
2174
2130
pixiResourcesLoader
2175
2131
) ;
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.
2180
2135
this . _renderedResourceName = undefined ;
2181
2136
const properties = associatedObjectConfiguration . getProperties ( ) ;
2182
2137
this . _defaultWidth = parseFloat ( properties . get ( 'width' ) . getValue ( ) ) ;
@@ -2206,12 +2161,9 @@ module.exports = {
2206
2161
}
2207
2162
2208
2163
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
+ ) ;
2215
2167
if ( textureResourceName ) {
2216
2168
return resourcesLoader . getResourceFullUrl (
2217
2169
project ,
@@ -2223,20 +2175,18 @@ module.exports = {
2223
2175
}
2224
2176
2225
2177
updateTextureIfNeeded ( ) {
2226
- const textureName =
2227
- RenderedCube3DObject2DInstance . _getResourceNameToDisplay (
2228
- this . _associatedObjectConfiguration
2229
- ) ;
2178
+ const textureName = RenderedCube3DObject2DInstance . _getResourceNameToDisplay (
2179
+ this . _associatedObjectConfiguration
2180
+ ) ;
2230
2181
if ( textureName === this . _renderedResourceName ) return ;
2231
2182
2232
2183
this . updateTexture ( ) ;
2233
2184
}
2234
2185
2235
2186
updateTexture ( ) {
2236
- const textureName =
2237
- RenderedCube3DObject2DInstance . _getResourceNameToDisplay (
2238
- this . _associatedObjectConfiguration
2239
- ) ;
2187
+ const textureName = RenderedCube3DObject2DInstance . _getResourceNameToDisplay (
2188
+ this . _associatedObjectConfiguration
2189
+ ) ;
2240
2190
2241
2191
if ( ! textureName ) {
2242
2192
this . _renderFallbackObject = true ;
@@ -2494,10 +2444,9 @@ module.exports = {
2494
2444
continue ;
2495
2445
}
2496
2446
2497
- const shouldRepeatTexture =
2498
- this . _shouldRepeatTextureOnFace [
2499
- materialIndexToFaceIndex [ materialIndex ]
2500
- ] ;
2447
+ const shouldRepeatTexture = this . _shouldRepeatTextureOnFace [
2448
+ materialIndexToFaceIndex [ materialIndex ]
2449
+ ] ;
2501
2450
2502
2451
const shouldOrientateFacesTowardsY = this . _facesOrientation === 'Y' ;
2503
2452
@@ -2532,13 +2481,16 @@ module.exports = {
2532
2481
}
2533
2482
} else {
2534
2483
if ( shouldOrientateFacesTowardsY ) {
2535
- [ x , y ] =
2536
- noRepeatTextureVertexIndexToUvMapping [ vertexIndex % 4 ] ;
2484
+ [ x , y ] = noRepeatTextureVertexIndexToUvMapping [
2485
+ vertexIndex % 4
2486
+ ] ;
2537
2487
} else {
2538
- [ x , y ] =
2539
- noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ [
2540
- vertexIndex % 4
2541
- ] ;
2488
+ [
2489
+ x ,
2490
+ y ,
2491
+ ] = noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ [
2492
+ vertexIndex % 4
2493
+ ] ;
2542
2494
}
2543
2495
}
2544
2496
break ;
@@ -2568,13 +2520,16 @@ module.exports = {
2568
2520
}
2569
2521
} else {
2570
2522
if ( shouldOrientateFacesTowardsY ) {
2571
- [ x , y ] =
2572
- noRepeatTextureVertexIndexToUvMapping [ vertexIndex % 4 ] ;
2523
+ [ x , y ] = noRepeatTextureVertexIndexToUvMapping [
2524
+ vertexIndex % 4
2525
+ ] ;
2573
2526
} else {
2574
- [ x , y ] =
2575
- noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ [
2576
- vertexIndex % 4
2577
- ] ;
2527
+ [
2528
+ x ,
2529
+ y ,
2530
+ ] = noRepeatTextureVertexIndexToUvMappingForLeftAndRightFacesTowardsZ [
2531
+ vertexIndex % 4
2532
+ ] ;
2578
2533
x = - x ;
2579
2534
y = - y ;
2580
2535
}
@@ -3111,7 +3066,7 @@ module.exports = {
3111
3066
) ;
3112
3067
threeObject . updateMatrixWorld ( true ) ;
3113
3068
const boundingBox = new THREE . Box3 ( ) . setFromObject ( threeObject ) ;
3114
-
3069
+
3115
3070
const shouldKeepModelOrigin = ! this . _originPoint ;
3116
3071
if ( shouldKeepModelOrigin ) {
3117
3072
// Keep the origin as part of the model.
0 commit comments