diff --git a/Extensions/3D/A_RuntimeObject3D.ts b/Extensions/3D/A_RuntimeObject3D.ts index d2adee49d0b4..7e7c36387921 100644 --- a/Extensions/3D/A_RuntimeObject3D.ts +++ b/Extensions/3D/A_RuntimeObject3D.ts @@ -4,14 +4,21 @@ namespace gdjs { type Object3DNetworkSyncDataType = { // z is position on the Z axis, different from zo, which is Z order - z: number; - d: number; - rx: number; - ry: number; + z?: number; + + d?: number; + depth?: number; + + rx?: number; + rotationX?: number; + // no need for rz, as it is the angle from gdjs.RuntimeObject - flipX: boolean; - flipY: boolean; - flipZ: boolean; + ry?: number; + rotationY?: number; + + flipX?: boolean; + flipY?: boolean; + flipZ?: boolean; }; /** @category Objects > 3D Objects */ @@ -123,12 +130,14 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): Object3DNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), z: this.getZ(), - d: this.getDepth(), - rx: this.getRotationX(), - ry: this.getRotationY(), + [getKey('d', 'depth')]: this.getDepth(), + [getKey('rx', 'rotationX')]: this.getRotationX(), + [getKey('ry', 'rotationY')]: this.getRotationY(), flipX: this.isFlippedX(), flipY: this.isFlippedY(), flipZ: this.isFlippedZ(), diff --git a/Extensions/3D/AmbientLight.ts b/Extensions/3D/AmbientLight.ts index 438ff6761641..d50e6b0d9653 100644 --- a/Extensions/3D/AmbientLight.ts +++ b/Extensions/3D/AmbientLight.ts @@ -1,7 +1,10 @@ namespace gdjs { interface AmbientLightFilterNetworkSyncData { - i: number; - c: number; + i?: number; + intensity?: number; + + c?: number; + color?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::AmbientLight', @@ -88,15 +91,19 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): AmbientLightFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): AmbientLightFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - i: this.light.intensity, - c: this.light.color.getHex(), - }; + [getKey('i', 'intensity')]: this.light.intensity, + [getKey('c', 'color')]: this.light.color.getHex(), + } as AmbientLightFilterNetworkSyncData; } updateFromNetworkSyncData(data: AmbientLightFilterNetworkSyncData) { - this.light.intensity = data.i; - this.light.color.setHex(data.c); + if (data.i !== undefined) this.light.intensity = data.i; + if (data.c !== undefined) this.light.color.setHex(data.c); } })(); } diff --git a/Extensions/3D/BloomEffect.ts b/Extensions/3D/BloomEffect.ts index 821dbecd052c..2afce0076c5b 100644 --- a/Extensions/3D/BloomEffect.ts +++ b/Extensions/3D/BloomEffect.ts @@ -1,8 +1,13 @@ namespace gdjs { interface BloomFilterNetworkSyncData { - s: number; - r: number; - t: number; + s?: number; + strength?: number; + + r?: number; + radius?: number; + + t?: number; + threshold?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::Bloom', @@ -87,17 +92,21 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): BloomFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): BloomFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - s: this.shaderPass.strength, - r: this.shaderPass.radius, - t: this.shaderPass.threshold, - }; + [getKey('s', 'strength')]: this.shaderPass.strength, + [getKey('r', 'radius')]: this.shaderPass.radius, + [getKey('t', 'threshold')]: this.shaderPass.threshold, + } as BloomFilterNetworkSyncData; } updateFromNetworkSyncData(data: BloomFilterNetworkSyncData) { - this.shaderPass.strength = data.s; - this.shaderPass.radius = data.r; - this.shaderPass.threshold = data.t; + if (data.s !== undefined) this.shaderPass.strength = data.s; + if (data.r !== undefined) this.shaderPass.radius = data.r; + if (data.t !== undefined) this.shaderPass.threshold = data.t; } })(); } diff --git a/Extensions/3D/BrightnessAndContrastEffect.ts b/Extensions/3D/BrightnessAndContrastEffect.ts index 2034650f6311..57958d3bdb02 100644 --- a/Extensions/3D/BrightnessAndContrastEffect.ts +++ b/Extensions/3D/BrightnessAndContrastEffect.ts @@ -1,7 +1,10 @@ namespace gdjs { interface BrightnessAndContrastFilterNetworkSyncData { - b: number; - c: number; + b?: number; + brightness?: number; + + c?: number; + contrast?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::BrightnessAndContrast', @@ -77,17 +80,25 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): BrightnessAndContrastFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): BrightnessAndContrastFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - b: this.shaderPass.uniforms.brightness.value, - c: this.shaderPass.uniforms.contrast.value, - }; + [getKey('b', 'brightness')]: + this.shaderPass.uniforms.brightness.value, + [getKey('c', 'contrast')]: + this.shaderPass.uniforms.contrast.value, + } as BrightnessAndContrastFilterNetworkSyncData; } updateFromNetworkSyncData( data: BrightnessAndContrastFilterNetworkSyncData ) { - this.shaderPass.uniforms.brightness.value = data.b; - this.shaderPass.uniforms.contrast.value = data.c; + if (data.b !== undefined) + this.shaderPass.uniforms.brightness.value = data.b; + if (data.c !== undefined) + this.shaderPass.uniforms.contrast.value = data.c; } })(); } diff --git a/Extensions/3D/Cube3DRuntimeObject.ts b/Extensions/3D/Cube3DRuntimeObject.ts index 762405645dd9..d2ed9d219148 100644 --- a/Extensions/3D/Cube3DRuntimeObject.ts +++ b/Extensions/3D/Cube3DRuntimeObject.ts @@ -44,13 +44,25 @@ namespace gdjs { }; type Cube3DObjectNetworkSyncDataType = { - fo: 'Y' | 'Z'; - bfu: 'X' | 'Y'; - vfb: integer; - trfb: integer; - frn: [string, string, string, string, string, string]; - mt: number; - tint: string; + fo?: 'Y' | 'Z'; + facesOrientation?: 'Y' | 'Z'; + + bfu?: 'X' | 'Y'; + backFaceUpThroughWhichAxisRotation?: 'X' | 'Y'; + + vfb?: integer; + visibleFacesBitmask?: integer; + + trfb?: integer; + textureRepeatFacesBitmask?: integer; + + frn?: [string, string, string, string, string, string]; + faceResourceNames?: [string, string, string, string, string, string]; + + mt?: number; + materialType?: number; + + tint?: string; }; type Cube3DObjectNetworkSyncData = Object3DNetworkSyncData & @@ -460,14 +472,18 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): Cube3DObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - mt: this._materialType, - fo: this._facesOrientation, - bfu: this._backFaceUpThroughWhichAxisRotation, - vfb: this._visibleFacesBitmask, - trfb: this._textureRepeatFacesBitmask, - frn: this._faceResourceNames, + [getKey('mt', 'materialType')]: this._materialType, + [getKey('fo', 'facesOrientation')]: this._facesOrientation, + [getKey('bfu', 'backFaceUpThroughWhichAxisRotation')]: + this._backFaceUpThroughWhichAxisRotation, + [getKey('vfb', 'visibleFacesBitmask')]: this._visibleFacesBitmask, + [getKey('trfb', 'textureRepeatFacesBitmask')]: + this._textureRepeatFacesBitmask, + [getKey('frn', 'faceResourceNames')]: this._faceResourceNames, tint: this._tint, }; } @@ -510,13 +526,12 @@ namespace gdjs { } } if (networkSyncData.frn !== undefined) { + const frn = networkSyncData.frn; // If one element is different, update all the faces. if ( - !this._faceResourceNames.every( - (value, index) => value === networkSyncData.frn[index] - ) + !this._faceResourceNames.every((value, index) => value === frn[index]) ) { - this._faceResourceNames = networkSyncData.frn; + this._faceResourceNames = frn; // Update all faces. (Could optimize to only update the changed ones) for (let i = 0; i < this._faceResourceNames.length; i++) { this._renderer.updateFace(i); diff --git a/Extensions/3D/CustomRuntimeObject3D.ts b/Extensions/3D/CustomRuntimeObject3D.ts index 51271a63e015..1dc9d9a5f38e 100644 --- a/Extensions/3D/CustomRuntimeObject3D.ts +++ b/Extensions/3D/CustomRuntimeObject3D.ts @@ -1,11 +1,21 @@ namespace gdjs { type CustomObject3DNetworkSyncDataType = { - z: float; - d: float; - rx: float; - ry: float; - ifz: boolean; - ccz: float; + z?: float; + + d?: float; + depth?: float; + + rx?: float; + rotationX?: float; + + ry?: float; + rotationY?: float; + + ifz?: boolean; + isFlippedZ?: boolean; + + ccz?: float; + customCenterZ?: float; }; type CustomObject3DNetworkSyncData = CustomObjectNetworkSyncData & @@ -88,14 +98,16 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): CustomObject3DNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), z: this.getZ(), - d: this.getDepth(), - rx: this.getRotationX(), - ry: this.getRotationY(), - ifz: this.isFlippedZ(), - ccz: this._customCenterZ, + [getKey('d', 'depth')]: this.getDepth(), + [getKey('rx', 'rotationX')]: this.getRotationX(), + [getKey('ry', 'rotationY')]: this.getRotationY(), + [getKey('ifz', 'isFlippedZ')]: this.isFlippedZ(), + [getKey('ccz', 'customCenterZ')]: this._customCenterZ, }; } diff --git a/Extensions/3D/DirectionalLight.ts b/Extensions/3D/DirectionalLight.ts index b9a5350873a7..a790d014bff9 100644 --- a/Extensions/3D/DirectionalLight.ts +++ b/Extensions/3D/DirectionalLight.ts @@ -1,10 +1,19 @@ namespace gdjs { interface DirectionalLightFilterNetworkSyncData { - i: number; - c: number; - e: number; - r: number; - t: string; + i?: number; + intensity?: number; + + c?: number; + color?: number; + + e?: number; + elevation?: number; + + r?: number; + rotation?: number; + + t?: string; + top?: string; } const shadowHelper = false; gdjs.PixiFiltersTools.registerFilterCreator( @@ -258,21 +267,27 @@ namespace gdjs { this._light.castShadow = value; } } - getNetworkSyncData(): DirectionalLightFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): DirectionalLightFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - i: this._light.intensity, - c: this._light.color.getHex(), - e: this._elevation, - r: this._rotation, - t: this._top, - }; + [getKey('i', 'intensity')]: this._light.intensity, + [getKey('c', 'color')]: this._light.color.getHex(), + [getKey('e', 'elevation')]: this._elevation, + [getKey('r', 'rotation')]: this._rotation, + [getKey('t', 'top')]: this._top, + } as DirectionalLightFilterNetworkSyncData; } - updateFromNetworkSyncData(syncData: any): void { - this._light.intensity = syncData.i; - this._light.color.setHex(syncData.c); - this._elevation = syncData.e; - this._rotation = syncData.r; - this._top = syncData.t; + updateFromNetworkSyncData( + syncData: DirectionalLightFilterNetworkSyncData + ): void { + if (syncData.i !== undefined) this._light.intensity = syncData.i; + if (syncData.c !== undefined) this._light.color.setHex(syncData.c); + if (syncData.e !== undefined) this._elevation = syncData.e; + if (syncData.r !== undefined) this._rotation = syncData.r; + if (syncData.t !== undefined) this._top = syncData.t; } })(); } diff --git a/Extensions/3D/ExponentialFog.ts b/Extensions/3D/ExponentialFog.ts index dc39b12e0f19..26cf87cef152 100644 --- a/Extensions/3D/ExponentialFog.ts +++ b/Extensions/3D/ExponentialFog.ts @@ -1,7 +1,10 @@ namespace gdjs { interface ExponentialFogFilterNetworkSyncData { - d: number; - c: number; + d?: number; + density?: number; + + c?: number; + color?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::ExponentialFog', @@ -87,17 +90,21 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): ExponentialFogFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): ExponentialFogFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - d: this.fog.density, - c: this.fog.color.getHex(), - }; + [getKey('d', 'density')]: this.fog.density, + [getKey('c', 'color')]: this.fog.color.getHex(), + } as ExponentialFogFilterNetworkSyncData; } updateFromNetworkSyncData( syncData: ExponentialFogFilterNetworkSyncData ): void { - this.fog.density = syncData.d; - this.fog.color.setHex(syncData.c); + if (syncData.d !== undefined) this.fog.density = syncData.d; + if (syncData.c !== undefined) this.fog.color.setHex(syncData.c); } })(); } diff --git a/Extensions/3D/ExposureEffect.ts b/Extensions/3D/ExposureEffect.ts index 59a7aee4b0c1..a816df9563aa 100644 --- a/Extensions/3D/ExposureEffect.ts +++ b/Extensions/3D/ExposureEffect.ts @@ -1,6 +1,7 @@ namespace gdjs { interface ExposureFilterNetworkSyncData { - e: number; + e?: number; + exposure?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::Exposure', @@ -70,13 +71,21 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): ExposureFilterNetworkSyncData { - return { e: this.shaderPass.uniforms.exposure.value }; + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): ExposureFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; + return { + [getKey('e', 'exposure')]: + this.shaderPass.uniforms.exposure.value, + } as ExposureFilterNetworkSyncData; } updateFromNetworkSyncData( syncData: ExposureFilterNetworkSyncData ): void { - this.shaderPass.uniforms.exposure.value = syncData.e; + if (syncData.e !== undefined) + this.shaderPass.uniforms.exposure.value = syncData.e; } })(); } diff --git a/Extensions/3D/HemisphereLight.ts b/Extensions/3D/HemisphereLight.ts index 3a35aa4c2bcb..b5ee975c67d5 100644 --- a/Extensions/3D/HemisphereLight.ts +++ b/Extensions/3D/HemisphereLight.ts @@ -1,11 +1,22 @@ namespace gdjs { interface HemisphereLightFilterNetworkSyncData { - i: number; - sc: number; - gc: number; - e: number; - r: number; - t: string; + i?: number; + intensity?: number; + + sc?: number; + skyColor?: number; + + gc?: number; + groundColor?: number; + + e?: number; + elevation?: number; + + r?: number; + rotation?: number; + + t?: string; + top?: string; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::HemisphereLight', @@ -144,25 +155,31 @@ namespace gdjs { ); } } - getNetworkSyncData(): HemisphereLightFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): HemisphereLightFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - i: this._light.intensity, - sc: this._light.color.getHex(), - gc: this._light.groundColor.getHex(), - e: this._elevation, - r: this._rotation, - t: this._top, - }; + [getKey('i', 'intensity')]: this._light.intensity, + [getKey('sc', 'skyColor')]: this._light.color.getHex(), + [getKey('gc', 'groundColor')]: this._light.groundColor.getHex(), + [getKey('e', 'elevation')]: this._elevation, + [getKey('r', 'rotation')]: this._rotation, + [getKey('t', 'top')]: this._top, + } as HemisphereLightFilterNetworkSyncData; } updateFromNetworkSyncData( syncData: HemisphereLightFilterNetworkSyncData ): void { - this._light.intensity = syncData.i; - this._light.color.setHex(syncData.sc); - this._light.groundColor.setHex(syncData.gc); - this._elevation = syncData.e; - this._rotation = syncData.r; - this._top = syncData.t; + if (syncData.i !== undefined) this._light.intensity = syncData.i; + if (syncData.sc !== undefined) + this._light.color.setHex(syncData.sc); + if (syncData.gc !== undefined) + this._light.groundColor.setHex(syncData.gc); + if (syncData.e !== undefined) this._elevation = syncData.e; + if (syncData.r !== undefined) this._rotation = syncData.r; + if (syncData.t !== undefined) this._top = syncData.t; this.updateRotation(); } })(); diff --git a/Extensions/3D/HueAndSaturationEffect.ts b/Extensions/3D/HueAndSaturationEffect.ts index d84104c8c6ca..8629948f840a 100644 --- a/Extensions/3D/HueAndSaturationEffect.ts +++ b/Extensions/3D/HueAndSaturationEffect.ts @@ -1,7 +1,10 @@ namespace gdjs { interface HueAndSaturationFilterExtra { - h: number; - s: number; + h?: number; + hue?: number; + + s?: number; + saturation?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::HueAndSaturation', @@ -77,17 +80,24 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): HueAndSaturationFilterExtra { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): HueAndSaturationFilterExtra { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - h: this.shaderPass.uniforms.hue.value, - s: this.shaderPass.uniforms.saturation.value, - }; + [getKey('h', 'hue')]: this.shaderPass.uniforms.hue.value, + [getKey('s', 'saturation')]: + this.shaderPass.uniforms.saturation.value, + } as HueAndSaturationFilterExtra; } updateFromNetworkSyncData( syncData: HueAndSaturationFilterExtra ): void { - this.shaderPass.uniforms.hue.value = syncData.h; - this.shaderPass.uniforms.saturation.value = syncData.s; + if (syncData.h !== undefined) + this.shaderPass.uniforms.hue.value = syncData.h; + if (syncData.s !== undefined) + this.shaderPass.uniforms.saturation.value = syncData.s; } })(); } diff --git a/Extensions/3D/LinearFog.ts b/Extensions/3D/LinearFog.ts index bf821fe05e31..9fe9d46e20ad 100644 --- a/Extensions/3D/LinearFog.ts +++ b/Extensions/3D/LinearFog.ts @@ -1,8 +1,13 @@ namespace gdjs { interface LinearFogFilterNetworkSyncData { - n: number; - f: number; - c: number; + n?: number; + near?: number; + + f?: number; + far?: number; + + c?: number; + color?: number; } gdjs.PixiFiltersTools.registerFilterCreator( 'Scene3D::LinearFog', @@ -92,19 +97,23 @@ namespace gdjs { return 0; } updateBooleanParameter(parameterName: string, value: boolean): void {} - getNetworkSyncData(): LinearFogFilterNetworkSyncData { + getNetworkSyncData( + syncOptions: GetNetworkSyncDataOptions + ): LinearFogFilterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { - n: this.fog.near, - f: this.fog.far, - c: this.fog.color.getHex(), - }; + [getKey('n', 'near')]: this.fog.near, + [getKey('f', 'far')]: this.fog.far, + [getKey('c', 'color')]: this.fog.color.getHex(), + } as LinearFogFilterNetworkSyncData; } updateFromNetworkSyncData( data: LinearFogFilterNetworkSyncData ): void { - this.fog.near = data.n; - this.fog.far = data.f; - this.fog.color.setHex(data.c); + if (data.n !== undefined) this.fog.near = data.n; + if (data.f !== undefined) this.fog.far = data.f; + if (data.c !== undefined) this.fog.color.setHex(data.c); } })(); } diff --git a/Extensions/3D/Model3DRuntimeObject.ts b/Extensions/3D/Model3DRuntimeObject.ts index d894716973df..e292204dc23f 100644 --- a/Extensions/3D/Model3DRuntimeObject.ts +++ b/Extensions/3D/Model3DRuntimeObject.ts @@ -2,15 +2,31 @@ namespace gdjs { type Model3DAnimation = { name: string; source: string; loop: boolean }; type Model3DObjectNetworkSyncDataType = { - mt: number; - op: LocationPoint | null; - cp: LocationPoint | null; - anis: Model3DAnimation[]; - ai: integer; - ass: float; - aet: float; - ap: boolean; - cfd: float; + mt?: number; + materialType?: number; + + op?: LocationPoint | null; + originPoint?: LocationPoint | null; + + cp?: LocationPoint | null; + centerPoint?: LocationPoint | null; + + anis?: Model3DAnimation[]; + + ai?: integer; + animationIndex?: integer; + + ass?: float; + animationSpeedScale?: float; + + aet?: float; + animationElapsedTime?: float; + + ap?: boolean; + animationPaused?: boolean; + + cfd?: float; + crossfadeDuration?: float; }; type Model3DObjectNetworkSyncData = Object3DNetworkSyncData & @@ -254,17 +270,19 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): Model3DObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - mt: this._materialType, - op: this._originPoint, - cp: this._centerPoint, + [getKey('mt', 'materialType')]: this._materialType, + [getKey('op', 'originPoint')]: this._originPoint, + [getKey('cp', 'centerPoint')]: this._centerPoint, anis: this._animations, - ai: this._currentAnimationIndex, - ass: this._animationSpeedScale, - aet: this.getAnimationElapsedTime(), - ap: this._animationPaused, - cfd: this._crossfadeDuration, + [getKey('ai', 'animationIndex')]: this._currentAnimationIndex, + [getKey('ass', 'animationSpeedScale')]: this._animationSpeedScale, + [getKey('aet', 'animationElapsedTime')]: this.getAnimationElapsedTime(), + [getKey('ap', 'animationPaused')]: this._animationPaused, + [getKey('cfd', 'crossfadeDuration')]: this._crossfadeDuration, }; } diff --git a/Extensions/BBText/bbtextruntimeobject.ts b/Extensions/BBText/bbtextruntimeobject.ts index 05437b713c38..6bd2eb444a4c 100644 --- a/Extensions/BBText/bbtextruntimeobject.ts +++ b/Extensions/BBText/bbtextruntimeobject.ts @@ -34,16 +34,33 @@ namespace gdjs { * @category Objects > BBText */ export type BBTextObjectNetworkSyncDataType = { - text: string; - o: float; - c: number[]; - ff: string; - fs: number; - wwrap: boolean; - wwidth: float; - align: string; - vta: string; - hidden: boolean; + text?: string; + + o?: float; + opacity?: float; + + c?: number[]; + color?: number[]; + + ff?: string; + fontFamily?: string; + + fs?: number; + fontSize?: number; + + wwrap?: boolean; + wordWrap?: boolean; + + wwidth?: float; + wrappingWidth?: float; + + align?: string; + textAlignment?: string; + + vta?: string; + verticalTextAlignment?: string; + + hidden?: boolean; }; /** @@ -162,17 +179,19 @@ namespace gdjs { override getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): BBTextObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), text: this._text, - o: this._opacity, - c: this._color, - ff: this._fontFamily, - fs: this._fontSize, - wwrap: this._wrapping, - wwidth: this._wrappingWidth, - align: this._textAlign, - vta: this._verticalTextAlignment, + [getKey('o', 'opacity')]: this._opacity, + [getKey('c', 'color')]: this._color, + [getKey('ff', 'fontFamily')]: this._fontFamily, + [getKey('fs', 'fontSize')]: this._fontSize, + [getKey('wwrap', 'wordWrap')]: this._wrapping, + [getKey('wwidth', 'wrappingWidth')]: this._wrappingWidth, + [getKey('align', 'textAlignment')]: this._textAlign, + [getKey('vta', 'verticalTextAlignment')]: this._verticalTextAlignment, hidden: this.hidden, }; } @@ -182,35 +201,35 @@ namespace gdjs { options: UpdateFromNetworkSyncDataOptions ): void { super.updateFromNetworkSyncData(networkSyncData, options); - if (this._text !== undefined) { + if (networkSyncData.text !== undefined) { this.setBBText(networkSyncData.text); } - if (this._opacity !== undefined) { + if (networkSyncData.o !== undefined) { this.setOpacity(networkSyncData.o); } - if (this._color !== undefined) { + if (networkSyncData.c !== undefined) { this._color = networkSyncData.c; this._renderer.updateColor(); } - if (this._fontFamily !== undefined) { + if (networkSyncData.ff !== undefined) { this.setFontFamily(networkSyncData.ff); } - if (this._fontSize !== undefined) { + if (networkSyncData.fs !== undefined) { this.setFontSize(networkSyncData.fs); } - if (this._wrapping !== undefined) { + if (networkSyncData.wwrap !== undefined) { this.setWrapping(networkSyncData.wwrap); } - if (this._wrappingWidth !== undefined) { + if (networkSyncData.wwidth !== undefined) { this.setWrappingWidth(networkSyncData.wwidth); } - if (this._textAlign !== undefined) { + if (networkSyncData.align !== undefined) { this.setTextAlignment(networkSyncData.align); } - if (this._verticalTextAlignment !== undefined) { + if (networkSyncData.vta !== undefined) { this.setVerticalTextAlignment(networkSyncData.vta); } - if (this.hidden !== undefined) { + if (networkSyncData.hidden !== undefined) { this.hide(networkSyncData.hidden); } } diff --git a/Extensions/BitmapText/bitmaptextruntimeobject.ts b/Extensions/BitmapText/bitmaptextruntimeobject.ts index 9fdf1ce01e11..a61c9e0813fd 100644 --- a/Extensions/BitmapText/bitmaptextruntimeobject.ts +++ b/Extensions/BitmapText/bitmaptextruntimeobject.ts @@ -34,16 +34,30 @@ namespace gdjs { * @category Objects > Bitmap Text */ export type BitmapTextObjectNetworkSyncDataType = { - text: string; - opa: float; - tint: number[]; - bfrn: string; - tarn: string; - scale: number; - wwrap: boolean; - wwidth: float; - align: string; - vta: string; + text?: string; + tint?: number[]; + scale?: number; + + opa?: float; + opacity?: float; + + bfrn?: string; + bitmapFontResourceName?: string; + + tarn?: string; + textureAtlasResourceName?: string; + + wwrap?: boolean; + wordWrap?: boolean; + + wwidth?: float; + wrappingWidth?: float; + + align?: string; + textAlignment?: string; + + vta?: string; + verticalTextAlignment?: string; }; /** @@ -172,18 +186,22 @@ namespace gdjs { override getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): BitmapTextObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), text: this._text, - opa: this._opacity, + [getKey('opa', 'opacity')]: this._opacity, tint: this._tint, - bfrn: this._bitmapFontResourceName, - tarn: this._textureAtlasResourceName, + [getKey('bfrn', 'bitmapFontResourceName')]: + this._bitmapFontResourceName, + [getKey('tarn', 'textureAtlasResourceName')]: + this._textureAtlasResourceName, scale: this.getScale(), - wwrap: this._wrapping, - wwidth: this._wrappingWidth, - align: this._textAlign, - vta: this._verticalTextAlignment, + [getKey('wwrap', 'wordWrap')]: this._wrapping, + [getKey('wwidth', 'wrappingWidth')]: this._wrappingWidth, + [getKey('align', 'textAlignment')]: this._textAlign, + [getKey('vta', 'verticalTextAlignment')]: this._verticalTextAlignment, }; } @@ -192,35 +210,35 @@ namespace gdjs { options: UpdateFromNetworkSyncDataOptions ): void { super.updateFromNetworkSyncData(networkSyncData, options); - if (this._text !== undefined) { + if (networkSyncData.text !== undefined) { this.setText(networkSyncData.text); } - if (this._opacity !== undefined) { + if (networkSyncData.opa !== undefined) { this.setOpacity(networkSyncData.opa); } - if (this._tint !== undefined) { + if (networkSyncData.tint !== undefined) { this._tint = networkSyncData.tint; this._renderer.updateTint(); } - if (this._bitmapFontResourceName !== undefined) { + if (networkSyncData.bfrn !== undefined) { this.setBitmapFontResourceName(networkSyncData.bfrn); } - if (this._textureAtlasResourceName !== undefined) { + if (networkSyncData.tarn !== undefined) { this.setTextureAtlasResourceName(networkSyncData.tarn); } - if (this._scaleX !== undefined) { + if (networkSyncData.scale !== undefined) { this.setScale(networkSyncData.scale); } - if (this._wrapping !== undefined) { + if (networkSyncData.wwrap !== undefined) { this.setWrapping(networkSyncData.wwrap); } - if (this._wrappingWidth !== undefined) { + if (networkSyncData.wwidth !== undefined) { this.setWrappingWidth(networkSyncData.wwidth); } - if (this._textAlign !== undefined) { + if (networkSyncData.align !== undefined) { this.setTextAlignment(networkSyncData.align); } - if (this._verticalTextAlignment !== undefined) { + if (networkSyncData.vta !== undefined) { this.setVerticalTextAlignment(networkSyncData.vta); } } diff --git a/Extensions/Lighting/lightruntimeobject.ts b/Extensions/Lighting/lightruntimeobject.ts index a278f064bc02..41d6477d93aa 100644 --- a/Extensions/Lighting/lightruntimeobject.ts +++ b/Extensions/Lighting/lightruntimeobject.ts @@ -25,8 +25,11 @@ namespace gdjs { * @category Objects > Light */ export type LightNetworkSyncDataType = { - rad: number; - col: string; + rad?: number; + radius?: number; + + col?: string; + color?: string; }; /** @@ -104,10 +107,12 @@ namespace gdjs { override getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): LightNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - rad: this.getRadius(), - col: this.getColor(), + [getKey('rad', 'radius')]: this.getRadius(), + [getKey('col', 'color')]: this.getColor(), }; } diff --git a/Extensions/PanelSpriteObject/panelspriteruntimeobject.ts b/Extensions/PanelSpriteObject/panelspriteruntimeobject.ts index 813c9f3b3107..863fd7e4d276 100644 --- a/Extensions/PanelSpriteObject/panelspriteruntimeobject.ts +++ b/Extensions/PanelSpriteObject/panelspriteruntimeobject.ts @@ -34,8 +34,10 @@ namespace gdjs { * @category Objects > Panel Sprite */ export type PanelSpriteNetworkSyncDataType = { - op: number; - color: string; + op?: number; + opacity?: number; + + color?: string; }; /** @@ -140,9 +142,11 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): PanelSpriteNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - op: this.getOpacity(), + [getKey('op', 'opacity')]: this.getOpacity(), color: this.getColor(), }; } diff --git a/Extensions/ParticleSystem/particleemitterobject.ts b/Extensions/ParticleSystem/particleemitterobject.ts index cae8cca61d66..5284a65671f3 100644 --- a/Extensions/ParticleSystem/particleemitterobject.ts +++ b/Extensions/ParticleSystem/particleemitterobject.ts @@ -68,42 +68,76 @@ namespace gdjs { // TODO: ensure we only send props that change to optimize the sync. // dirty attributes are not synced, they are defined by the update method if the value has changed. // Particle Rotation Speed - prms: number; - prmx: number; + prms?: number; + particleRotationMinSpeed?: number; + + prmx?: number; + particleRotationMaxSpeed?: number; + // Max Particles Count - mpc: number; + mpc?: number; + maxParticlesCount?: number; + // Additive Rendering - addr: boolean; + addr?: boolean; + additiveRendering?: boolean; + // Angle - angb: number; + angb?: number; + angleB?: number; + // Force - formin: number; - formax: number; + formin?: number; + forceMin?: number; + + formax?: number; + forceMax?: number; + // Zone Radius - zr: number; + zr?: number; + zoneRadius?: number; + // Life Time - ltmin: number; - ltmax: number; + ltmin?: number; + lifeTimeMin?: number; + + ltmax?: number; + lifeTimeMax?: number; + // Gravity - gravx: number; - gravy: number; + gravx?: number; + gravityX?: number; + + gravy?: number; + gravityY?: number; + // Color - color1: number; - color2: number; + color1?: number; + color2?: number; + // Size - size1: number; - size2: number; + size1?: number; + size2?: number; + // Alpha - alp1: number; - alp2: number; + alp1?: number; + alpha1?: number; + + alp2?: number; + alpha2?: number; + // Flow - flow: number; + flow?: number; + // Tank - tank: number; + tank?: number; + // Texture - text: string; + text?: string; + texture?: string; + // Pause - paused: boolean; + paused?: boolean; }; /** @category Objects > Particle Emitter */ @@ -391,29 +425,33 @@ namespace gdjs { override getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): ParticleEmitterObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - prms: this.particleRotationMinSpeed, - prmx: this.particleRotationMaxSpeed, - mpc: this.maxParticlesCount, - addr: this.additiveRendering, - angb: this.angleB, - formin: this.forceMin, - formax: this.forceMax, - zr: this.zoneRadius, - ltmin: this.lifeTimeMin, - ltmax: this.lifeTimeMax, - gravx: this.gravityX, - gravy: this.gravityY, + [getKey('prms', 'particleRotationMinSpeed')]: + this.particleRotationMinSpeed, + [getKey('prmx', 'particleRotationMaxSpeed')]: + this.particleRotationMaxSpeed, + [getKey('mpc', 'maxParticlesCount')]: this.maxParticlesCount, + [getKey('addr', 'additiveRendering')]: this.additiveRendering, + [getKey('angb', 'angleB')]: this.angleB, + [getKey('formin', 'forceMin')]: this.forceMin, + [getKey('formax', 'forceMax')]: this.forceMax, + [getKey('zr', 'zoneRadius')]: this.zoneRadius, + [getKey('ltmin', 'lifeTimeMin')]: this.lifeTimeMin, + [getKey('ltmax', 'lifeTimeMax')]: this.lifeTimeMax, + [getKey('gravx', 'gravityX')]: this.gravityX, + [getKey('gravy', 'gravityY')]: this.gravityY, color1: this.color1, color2: this.color2, size1: this.size1, size2: this.size2, - alp1: this.alpha1, - alp2: this.alpha2, + [getKey('alp1', 'alpha1')]: this.alpha1, + [getKey('alp2', 'alpha2')]: this.alpha2, flow: this.flow, tank: this.tank, - text: this.texture, + [getKey('text', 'texture')]: this.texture, paused: this._isEmissionPaused, }; } diff --git a/Extensions/PathfindingBehavior/pathfindingruntimebehavior.ts b/Extensions/PathfindingBehavior/pathfindingruntimebehavior.ts index 045b0f9fd11b..ca8243e1da67 100644 --- a/Extensions/PathfindingBehavior/pathfindingruntimebehavior.ts +++ b/Extensions/PathfindingBehavior/pathfindingruntimebehavior.ts @@ -7,15 +7,31 @@ namespace gdjs { interface PathfindingNetworkSyncDataType { // Syncing the path and its position on it should be enough to have a good prediction. - path: FloatPoint[]; - pf: boolean; - sp: number; - as: number; - cs: number; - tss: number; - re: boolean; - ma: number; - dos: number; + path?: FloatPoint[]; + + pf?: boolean; + pathFound?: boolean; + + sp?: number; + speed?: number; + + as?: number; + angularSpeed?: number; + + cs?: number; + currentSegment?: number; + + tss?: number; + totalSegmentDistance?: number; + + re?: boolean; + reachedEnd?: boolean; + + ma?: number; + movementAngle?: number; + + dos?: number; + distanceOnSegment?: number; } /** @category Behaviors > 2D Pathfinding */ @@ -136,19 +152,21 @@ namespace gdjs { getNetworkSyncData( options: GetNetworkSyncDataOptions ): PathfindingNetworkSyncData { + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(options), props: { path: this._path, - pf: this._pathFound, - sp: this._speed, - as: this._angularSpeed, - cs: this._currentSegment, - tss: this._totalSegmentDistance, - re: this._reachedEnd, - ma: this._movementAngle, - dos: this._distanceOnSegment, - }, + [getKey('pf', 'pathFound')]: this._pathFound, + [getKey('sp', 'speed')]: this._speed, + [getKey('as', 'angularSpeed')]: this._angularSpeed, + [getKey('cs', 'currentSegment')]: this._currentSegment, + [getKey('tss', 'totalSegmentDistance')]: this._totalSegmentDistance, + [getKey('re', 'reachedEnd')]: this._reachedEnd, + [getKey('ma', 'movementAngle')]: this._movementAngle, + [getKey('dos', 'distanceOnSegment')]: this._distanceOnSegment, + } as PathfindingNetworkSyncDataType, }; } diff --git a/Extensions/Physics2Behavior/physics2runtimebehavior.ts b/Extensions/Physics2Behavior/physics2runtimebehavior.ts index 3ac33586eeb3..d53262519437 100644 --- a/Extensions/Physics2Behavior/physics2runtimebehavior.ts +++ b/Extensions/Physics2Behavior/physics2runtimebehavior.ts @@ -11,15 +11,29 @@ namespace gdjs { physics2SharedData: gdjs.Physics2SharedData | null; } interface Physics2NetworkSyncDataType { - tpx: number | undefined; - tpy: number | undefined; - tqa: number | undefined; - lvx: number | undefined; - lvy: number | undefined; - av: number | undefined; - aw: boolean | undefined; - layers: number; - masks: number; + tpx?: number; + transformPositionX?: number; + + tpy?: number; + transformPositionY?: number; + + tqa?: number; + transformAngle?: number; + + lvx?: number; + linearVelocityX?: number; + + lvy?: number; + linearVelocityY?: number; + + av?: number; + angularVelocity?: number; + + aw?: boolean; + isAwake?: boolean; + + layers?: number; + masks?: number; } /** @@ -514,24 +528,39 @@ namespace gdjs { getNetworkSyncData( options: GetNetworkSyncDataOptions ): Physics2NetworkSyncData { + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; const bodyProps = this._body ? { - tpx: this._body.GetTransform().get_p().get_x(), - tpy: this._body.GetTransform().get_p().get_y(), - tqa: this._body.GetTransform().get_q().GetAngle(), - lvx: this._body.GetLinearVelocity().get_x(), - lvy: this._body.GetLinearVelocity().get_y(), - av: this._body.GetAngularVelocity(), - aw: this._body.IsAwake(), + [getKey('tpx', 'transformPositionX')]: this._body + .GetTransform() + .get_p() + .get_x(), + [getKey('tpy', 'transformPositionY')]: this._body + .GetTransform() + .get_p() + .get_y(), + [getKey('tqa', 'transformAngle')]: this._body + .GetTransform() + .get_q() + .GetAngle(), + [getKey('lvx', 'linearVelocityX')]: this._body + .GetLinearVelocity() + .get_x(), + [getKey('lvy', 'linearVelocityY')]: this._body + .GetLinearVelocity() + .get_y(), + [getKey('av', 'angularVelocity')]: this._body.GetAngularVelocity(), + [getKey('aw', 'isAwake')]: this._body.IsAwake(), } : { - tpx: undefined, - tpy: undefined, - tqa: undefined, - lvx: undefined, - lvy: undefined, - av: undefined, - aw: undefined, + [getKey('tpx', 'transformPositionX')]: undefined, + [getKey('tpy', 'transformPositionY')]: undefined, + [getKey('tqa', 'transformAngle')]: undefined, + [getKey('lvx', 'linearVelocityX')]: undefined, + [getKey('lvy', 'linearVelocityY')]: undefined, + [getKey('av', 'angularVelocity')]: undefined, + [getKey('aw', 'isAwake')]: undefined, }; return { ...super.getNetworkSyncData(options), diff --git a/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts b/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts index 2a6aa28fbdda..e84a8029bb4b 100644 --- a/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts +++ b/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts @@ -515,6 +515,8 @@ namespace gdjs { override getNetworkSyncData( options: GetNetworkSyncDataOptions ): Physics3DNetworkSyncData { + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; let bodyProps; if (this._body) { const position = this._body.GetPosition(); @@ -522,37 +524,37 @@ namespace gdjs { const linearVelocity = this._body.GetLinearVelocity(); const angularVelocity = this._body.GetAngularVelocity(); bodyProps = { - px: position.GetX(), - py: position.GetY(), - pz: position.GetZ(), - rx: rotation.GetX(), - ry: rotation.GetY(), - rz: rotation.GetZ(), - rw: rotation.GetW(), - lvx: linearVelocity.GetX(), - lvy: linearVelocity.GetY(), - lvz: linearVelocity.GetZ(), - avx: angularVelocity.GetX(), - avy: angularVelocity.GetY(), - avz: angularVelocity.GetZ(), - aw: this._body.IsActive(), + [getKey('px', 'positionX')]: position.GetX(), + [getKey('py', 'positionY')]: position.GetY(), + [getKey('pz', 'positionZ')]: position.GetZ(), + [getKey('rx', 'rotationX')]: rotation.GetX(), + [getKey('ry', 'rotationY')]: rotation.GetY(), + [getKey('rz', 'rotationZ')]: rotation.GetZ(), + [getKey('rw', 'rotationW')]: rotation.GetW(), + [getKey('lvx', 'linearVelocityX')]: linearVelocity.GetX(), + [getKey('lvy', 'linearVelocityY')]: linearVelocity.GetY(), + [getKey('lvz', 'linearVelocityZ')]: linearVelocity.GetZ(), + [getKey('avx', 'angularVelocityX')]: angularVelocity.GetX(), + [getKey('avy', 'angularVelocityY')]: angularVelocity.GetY(), + [getKey('avz', 'angularVelocityZ')]: angularVelocity.GetZ(), + [getKey('aw', 'isActive')]: this._body.IsActive(), }; } else { bodyProps = { - px: undefined, - py: undefined, - pz: undefined, - rx: undefined, - ry: undefined, - rz: undefined, - rw: undefined, - lvx: undefined, - lvy: undefined, - lvz: undefined, - avx: undefined, - avy: undefined, - avz: undefined, - aw: undefined, + [getKey('px', 'positionX')]: undefined, + [getKey('py', 'positionY')]: undefined, + [getKey('pz', 'positionZ')]: undefined, + [getKey('rx', 'rotationX')]: undefined, + [getKey('ry', 'rotationY')]: undefined, + [getKey('rz', 'rotationZ')]: undefined, + [getKey('rw', 'rotationW')]: undefined, + [getKey('lvx', 'linearVelocityX')]: undefined, + [getKey('lvy', 'linearVelocityY')]: undefined, + [getKey('lvz', 'linearVelocityZ')]: undefined, + [getKey('avx', 'angularVelocityX')]: undefined, + [getKey('avy', 'angularVelocityY')]: undefined, + [getKey('avz', 'angularVelocityZ')]: undefined, + [getKey('aw', 'isActive')]: undefined, }; } return { diff --git a/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.ts b/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.ts index 6e66ec3a8f19..c5c83c4ae852 100644 --- a/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.ts +++ b/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.ts @@ -2,17 +2,38 @@ namespace gdjs { interface PhysicsCar3DNetworkSyncDataType { - lek: boolean; - rik: boolean; - upk: boolean; - dok: boolean; - hbk: boolean; - asf: float; - ssf: float; - etm: float; - esm: float; - ei: float; - es: float; + lek?: boolean; + wasLeftKeyPressed?: boolean; + + rik?: boolean; + wasRightKeyPressed?: boolean; + + upk?: boolean; + wasForwardKeyPressed?: boolean; + + dok?: boolean; + wasBackwardKeyPressed?: boolean; + + hbk?: boolean; + wasHandBrakeKeyPressed?: boolean; + + asf?: float; + previousAcceleratorStickForce?: float; + + ssf?: float; + previousSteeringStickForce?: float; + + etm?: float; + engineTorqueMax?: float; + + esm?: float; + engineSpeedMax?: float; + + ei?: float; + engineInertia?: float; + + es?: float; + engineSpeed?: float; } /** @@ -295,20 +316,25 @@ namespace gdjs { // Let's clear the inputs between frames as we control it. this._clearInputsBetweenFrames = true; + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), props: { - lek: this._wasLeftKeyPressed, - rik: this._wasRightKeyPressed, - upk: this._wasForwardKeyPressed, - dok: this._wasBackwardKeyPressed, - hbk: this._wasHandBrakeKeyPressed, - asf: this._previousAcceleratorStickForce, - ssf: this._previousSteeringStickForce, - etm: this._engineTorqueMax, - esm: this._engineSpeedMax, - ei: this._engineInertia, - es: this.getEngineSpeed(), + [getKey('lek', 'wasLeftKeyPressed')]: this._wasLeftKeyPressed, + [getKey('rik', 'wasRightKeyPressed')]: this._wasRightKeyPressed, + [getKey('upk', 'wasForwardKeyPressed')]: this._wasForwardKeyPressed, + [getKey('dok', 'wasBackwardKeyPressed')]: this._wasBackwardKeyPressed, + [getKey('hbk', 'wasHandBrakeKeyPressed')]: + this._wasHandBrakeKeyPressed, + [getKey('asf', 'previousAcceleratorStickForce')]: + this._previousAcceleratorStickForce, + [getKey('ssf', 'previousSteeringStickForce')]: + this._previousSteeringStickForce, + [getKey('etm', 'engineTorqueMax')]: this._engineTorqueMax, + [getKey('esm', 'engineSpeedMax')]: this._engineSpeedMax, + [getKey('ei', 'engineInertia')]: this._engineInertia, + [getKey('es', 'engineSpeed')]: this.getEngineSpeed(), }, }; } @@ -320,17 +346,27 @@ namespace gdjs { super.updateFromNetworkSyncData(networkSyncData, options); const behaviorSpecificProps = networkSyncData.props; - this._hasPressedForwardKey = behaviorSpecificProps.upk; - this._hasPressedBackwardKey = behaviorSpecificProps.dok; - this._hasPressedLeftKey = behaviorSpecificProps.lek; - this._hasPressedRightKey = behaviorSpecificProps.rik; - this._hasPressedHandBrakeKey = behaviorSpecificProps.hbk; - this._acceleratorStickForce = behaviorSpecificProps.asf; - this._steeringStickForce = behaviorSpecificProps.ssf; - this._engineTorqueMax = behaviorSpecificProps.etm; - this._engineSpeedMax = behaviorSpecificProps.esm; - this._engineInertia = behaviorSpecificProps.ei; - if (this._vehicleController) { + if (behaviorSpecificProps.upk !== undefined) + this._hasPressedForwardKey = behaviorSpecificProps.upk; + if (behaviorSpecificProps.dok !== undefined) + this._hasPressedBackwardKey = behaviorSpecificProps.dok; + if (behaviorSpecificProps.lek !== undefined) + this._hasPressedLeftKey = behaviorSpecificProps.lek; + if (behaviorSpecificProps.rik !== undefined) + this._hasPressedRightKey = behaviorSpecificProps.rik; + if (behaviorSpecificProps.hbk !== undefined) + this._hasPressedHandBrakeKey = behaviorSpecificProps.hbk; + if (behaviorSpecificProps.asf !== undefined) + this._acceleratorStickForce = behaviorSpecificProps.asf; + if (behaviorSpecificProps.ssf !== undefined) + this._steeringStickForce = behaviorSpecificProps.ssf; + if (behaviorSpecificProps.etm !== undefined) + this._engineTorqueMax = behaviorSpecificProps.etm; + if (behaviorSpecificProps.esm !== undefined) + this._engineSpeedMax = behaviorSpecificProps.esm; + if (behaviorSpecificProps.ei !== undefined) + this._engineInertia = behaviorSpecificProps.ei; + if (this._vehicleController && behaviorSpecificProps.es !== undefined) { this._vehicleController .GetEngine() .SetCurrentRPM(behaviorSpecificProps.es); diff --git a/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts b/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts index a9277a6a8bcb..3a13c6117b2d 100644 --- a/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts +++ b/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts @@ -2,35 +2,92 @@ namespace gdjs { interface PhysicsCharacter3DNetworkSyncDataType { - sma: float; - shm: float; - grav: float; - mfs: float; - facc: float; - fdec: float; - fsm: float; - sacc: float; - sdec: float; - ssm: float; - jumpspeed: float; - jumpsustime: float; - sbpa: boolean; - fwa: float; - fws: float; - sws: float; - cfs: float; - cjs: float; - cj: boolean; - lek: boolean; - rik: boolean; - upk: boolean; - dok: boolean; - juk: boolean; - us: boolean; - sa: float; - sf: float; - tscjs: float; - jkhsjs: boolean; + sma?: float; + slopeMaxAngle?: float; + + shm?: float; + stairHeightMax?: float; + + grav?: float; + gravity?: float; + + mfs?: float; + maxFallingSpeed?: float; + + facc?: float; + forwardAcceleration?: float; + + fdec?: float; + forwardDeceleration?: float; + + fsm?: float; + forwardSpeedMax?: float; + + sacc?: float; + sidewaysAcceleration?: float; + + sdec?: float; + sidewaysDeceleration?: float; + + ssm?: float; + sidewaysSpeedMax?: float; + + jumpspeed?: float; + jumpSpeed?: float; + + jumpsustime?: float; + jumpSustainTime?: float; + + sbpa?: boolean; + shouldBindObjectAndForwardAngle?: boolean; + + fwa?: float; + forwardAngle?: float; + + fws?: float; + currentForwardSpeed?: float; + + sws?: float; + currentSidewaysSpeed?: float; + + cfs?: float; + currentFallSpeed?: float; + + cjs?: float; + currentJumpSpeed?: float; + + cj?: boolean; + canJump?: boolean; + + lek?: boolean; + wasLeftKeyPressed?: boolean; + + rik?: boolean; + wasRightKeyPressed?: boolean; + + upk?: boolean; + wasForwardKeyPressed?: boolean; + + dok?: boolean; + wasBackwardKeyPressed?: boolean; + + juk?: boolean; + wasJumpKeyPressed?: boolean; + + us?: boolean; + wasStickUsed?: boolean; + + sa?: float; + stickAngle?: float; + + sf?: float; + stickForce?: float; + + tscjs?: float; + timeSinceCurrentJumpStart?: float; + + jkhsjs?: boolean; + jumpKeyHeldSinceJumpStart?: boolean; } /** @category Behaviors > Physics 3D */ @@ -312,38 +369,43 @@ namespace gdjs { // Let's clear the inputs between frames as we control it. this._clearInputsBetweenFrames = true; + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(options), props: { - sma: this._slopeMaxAngle, - shm: this._stairHeightMax, - grav: this._gravity, - mfs: this._maxFallingSpeed, - facc: this._forwardAcceleration, - fdec: this._forwardDeceleration, - fsm: this._forwardSpeedMax, - sacc: this._sidewaysAcceleration, - sdec: this._sidewaysDeceleration, - ssm: this._sidewaysSpeedMax, - jumpspeed: this._jumpSpeed, - jumpsustime: this._jumpSustainTime, - fwa: this._forwardAngle, - sbpa: this._shouldBindObjectAndForwardAngle, - fws: this._currentForwardSpeed, - sws: this._currentSidewaysSpeed, - cfs: this._currentFallSpeed, - cjs: this._currentJumpSpeed, - cj: this._canJump, - lek: this._wasLeftKeyPressed, - rik: this._wasRightKeyPressed, - upk: this._wasForwardKeyPressed, - dok: this._wasBackwardKeyPressed, - juk: this._wasJumpKeyPressed, - us: this._wasStickUsed, - sa: this._stickAngle, - sf: this._stickForce, - tscjs: this._timeSinceCurrentJumpStart, - jkhsjs: this._jumpKeyHeldSinceJumpStart, + [getKey('sma', 'slopeMaxAngle')]: this._slopeMaxAngle, + [getKey('shm', 'stairHeightMax')]: this._stairHeightMax, + [getKey('grav', 'gravity')]: this._gravity, + [getKey('mfs', 'maxFallingSpeed')]: this._maxFallingSpeed, + [getKey('facc', 'forwardAcceleration')]: this._forwardAcceleration, + [getKey('fdec', 'forwardDeceleration')]: this._forwardDeceleration, + [getKey('fsm', 'forwardSpeedMax')]: this._forwardSpeedMax, + [getKey('sacc', 'sidewaysAcceleration')]: this._sidewaysAcceleration, + [getKey('sdec', 'sidewaysDeceleration')]: this._sidewaysDeceleration, + [getKey('ssm', 'sidewaysSpeedMax')]: this._sidewaysSpeedMax, + [getKey('jumpspeed', 'jumpSpeed')]: this._jumpSpeed, + [getKey('jumpsustime', 'jumpSustainTime')]: this._jumpSustainTime, + [getKey('fwa', 'forwardAngle')]: this._forwardAngle, + [getKey('sbpa', 'shouldBindObjectAndForwardAngle')]: + this._shouldBindObjectAndForwardAngle, + [getKey('fws', 'currentForwardSpeed')]: this._currentForwardSpeed, + [getKey('sws', 'currentSidewaysSpeed')]: this._currentSidewaysSpeed, + [getKey('cfs', 'currentFallSpeed')]: this._currentFallSpeed, + [getKey('cjs', 'currentJumpSpeed')]: this._currentJumpSpeed, + [getKey('cj', 'canJump')]: this._canJump, + [getKey('lek', 'wasLeftKeyPressed')]: this._wasLeftKeyPressed, + [getKey('rik', 'wasRightKeyPressed')]: this._wasRightKeyPressed, + [getKey('upk', 'wasForwardKeyPressed')]: this._wasForwardKeyPressed, + [getKey('dok', 'wasBackwardKeyPressed')]: this._wasBackwardKeyPressed, + [getKey('juk', 'wasJumpKeyPressed')]: this._wasJumpKeyPressed, + [getKey('us', 'wasStickUsed')]: this._wasStickUsed, + [getKey('sa', 'stickAngle')]: this._stickAngle, + [getKey('sf', 'stickForce')]: this._stickForce, + [getKey('tscjs', 'timeSinceCurrentJumpStart')]: + this._timeSinceCurrentJumpStart, + [getKey('jkhsjs', 'jumpKeyHeldSinceJumpStart')]: + this._jumpKeyHeldSinceJumpStart, }, }; } @@ -355,35 +417,64 @@ namespace gdjs { super.updateFromNetworkSyncData(networkSyncData, options); const behaviorSpecificProps = networkSyncData.props; - this._slopeMaxAngle = behaviorSpecificProps.sma; - this._stairHeightMax = behaviorSpecificProps.shm; - this._gravity = behaviorSpecificProps.grav; - this._maxFallingSpeed = behaviorSpecificProps.mfs; - this._forwardAcceleration = behaviorSpecificProps.facc; - this._forwardDeceleration = behaviorSpecificProps.fdec; - this._forwardSpeedMax = behaviorSpecificProps.fsm; - this._sidewaysAcceleration = behaviorSpecificProps.sacc; - this._sidewaysDeceleration = behaviorSpecificProps.sdec; - this._sidewaysSpeedMax = behaviorSpecificProps.ssm; - this._jumpSpeed = behaviorSpecificProps.jumpspeed; - this._jumpSustainTime = behaviorSpecificProps.jumpsustime; - this._forwardAngle = behaviorSpecificProps.fwa; - this._shouldBindObjectAndForwardAngle = behaviorSpecificProps.sbpa; - this._currentForwardSpeed = behaviorSpecificProps.fws; - this._currentSidewaysSpeed = behaviorSpecificProps.sws; - this._currentFallSpeed = behaviorSpecificProps.cfs; - this._currentJumpSpeed = behaviorSpecificProps.cjs; - this._canJump = behaviorSpecificProps.cj; - this._hasPressedForwardKey = behaviorSpecificProps.upk; - this._hasPressedBackwardKey = behaviorSpecificProps.dok; - this._hasPressedLeftKey = behaviorSpecificProps.lek; - this._hasPressedRightKey = behaviorSpecificProps.rik; - this._hasPressedJumpKey = behaviorSpecificProps.juk; - this._hasUsedStick = behaviorSpecificProps.us; - this._stickAngle = behaviorSpecificProps.sa; - this._stickForce = behaviorSpecificProps.sf; - this._timeSinceCurrentJumpStart = behaviorSpecificProps.tscjs; - this._jumpKeyHeldSinceJumpStart = behaviorSpecificProps.jkhsjs; + if (behaviorSpecificProps.sma !== undefined) + this._slopeMaxAngle = behaviorSpecificProps.sma; + if (behaviorSpecificProps.shm !== undefined) + this._stairHeightMax = behaviorSpecificProps.shm; + if (behaviorSpecificProps.grav !== undefined) + this._gravity = behaviorSpecificProps.grav; + if (behaviorSpecificProps.mfs !== undefined) + this._maxFallingSpeed = behaviorSpecificProps.mfs; + if (behaviorSpecificProps.facc !== undefined) + this._forwardAcceleration = behaviorSpecificProps.facc; + if (behaviorSpecificProps.fdec !== undefined) + this._forwardDeceleration = behaviorSpecificProps.fdec; + if (behaviorSpecificProps.fsm !== undefined) + this._forwardSpeedMax = behaviorSpecificProps.fsm; + if (behaviorSpecificProps.sacc !== undefined) + this._sidewaysAcceleration = behaviorSpecificProps.sacc; + if (behaviorSpecificProps.sdec !== undefined) + this._sidewaysDeceleration = behaviorSpecificProps.sdec; + if (behaviorSpecificProps.ssm !== undefined) + this._sidewaysSpeedMax = behaviorSpecificProps.ssm; + if (behaviorSpecificProps.jumpspeed !== undefined) + this._jumpSpeed = behaviorSpecificProps.jumpspeed; + if (behaviorSpecificProps.jumpsustime !== undefined) + this._jumpSustainTime = behaviorSpecificProps.jumpsustime; + if (behaviorSpecificProps.fwa !== undefined) + this._forwardAngle = behaviorSpecificProps.fwa; + if (behaviorSpecificProps.sbpa !== undefined) + this._shouldBindObjectAndForwardAngle = behaviorSpecificProps.sbpa; + if (behaviorSpecificProps.fws !== undefined) + this._currentForwardSpeed = behaviorSpecificProps.fws; + if (behaviorSpecificProps.sws !== undefined) + this._currentSidewaysSpeed = behaviorSpecificProps.sws; + if (behaviorSpecificProps.cfs !== undefined) + this._currentFallSpeed = behaviorSpecificProps.cfs; + if (behaviorSpecificProps.cjs !== undefined) + this._currentJumpSpeed = behaviorSpecificProps.cjs; + if (behaviorSpecificProps.cj !== undefined) + this._canJump = behaviorSpecificProps.cj; + if (behaviorSpecificProps.upk !== undefined) + this._hasPressedForwardKey = behaviorSpecificProps.upk; + if (behaviorSpecificProps.dok !== undefined) + this._hasPressedBackwardKey = behaviorSpecificProps.dok; + if (behaviorSpecificProps.lek !== undefined) + this._hasPressedLeftKey = behaviorSpecificProps.lek; + if (behaviorSpecificProps.rik !== undefined) + this._hasPressedRightKey = behaviorSpecificProps.rik; + if (behaviorSpecificProps.juk !== undefined) + this._hasPressedJumpKey = behaviorSpecificProps.juk; + if (behaviorSpecificProps.us !== undefined) + this._hasUsedStick = behaviorSpecificProps.us; + if (behaviorSpecificProps.sa !== undefined) + this._stickAngle = behaviorSpecificProps.sa; + if (behaviorSpecificProps.sf !== undefined) + this._stickForce = behaviorSpecificProps.sf; + if (behaviorSpecificProps.tscjs !== undefined) + this._timeSinceCurrentJumpStart = behaviorSpecificProps.tscjs; + if (behaviorSpecificProps.jkhsjs !== undefined) + this._jumpKeyHeldSinceJumpStart = behaviorSpecificProps.jkhsjs; // Clear user inputs between frames only if requested. this._clearInputsBetweenFrames = !!options.clearInputs; diff --git a/Extensions/PlatformBehavior/platformerobjectruntimebehavior.ts b/Extensions/PlatformBehavior/platformerobjectruntimebehavior.ts index 22803a67e0c3..2fb80784d318 100644 --- a/Extensions/PlatformBehavior/platformerobjectruntimebehavior.ts +++ b/Extensions/PlatformBehavior/platformerobjectruntimebehavior.ts @@ -13,22 +13,35 @@ namespace gdjs { }; interface OnFloorStateNetworkSyncData { - flx: number; - fly: number; - oh: number; + flx?: number; + floorLastX?: number; + + fly?: number; + floorLastY?: number; + + oh?: number; + oldHeight?: number; } interface FallingStateNetworkSyncData {} interface JumpingStateNetworkSyncData { - cjs: number; - tscjs: number; - jfd: boolean; + cjs?: number; + currentJumpSpeed?: number; + + tscjs?: number; + timeSinceCurrentJumpStart?: number; + + jfd?: boolean; + jumpingFirstDelta?: boolean; } interface GrabbingPlatformStateNetworkSyncData { - gplx: float; - gply: float; + gplx?: float; + grabbedPlatformLastX?: float; + + gply?: float; + grabbedPlatformLastY?: float; } interface OnLadderStateNetworkSyncData {} @@ -41,24 +54,59 @@ namespace gdjs { | OnLadderStateNetworkSyncData; interface PlatformerObjectNetworkSyncDataType { - cs: float; - rdx: float; - rdy: float; - ldy: float; - cfs: float; - cj: boolean; - ldl: boolean; - lek: boolean; - rik: boolean; - lak: boolean; - upk: boolean; - dok: boolean; - juk: boolean; - rpk: boolean; - rlk: boolean; - jkhsjs: boolean; - sn: string; - ssd: StateNetworkSyncData; + cs?: float; + currentSpeed?: float; + + rdx?: float; + requestedDeltaX?: float; + + rdy?: float; + requestedDeltaY?: float; + + ldy?: float; + lastDeltaY?: float; + + cfs?: float; + currentFallSpeed?: float; + + cj?: boolean; + canJump?: boolean; + + ldl?: boolean; + lastDirectionIsLeft?: boolean; + + lek?: boolean; + wasLeftKeyPressed?: boolean; + + rik?: boolean; + wasRightKeyPressed?: boolean; + + lak?: boolean; + wasLadderKeyPressed?: boolean; + + upk?: boolean; + wasUpKeyPressed?: boolean; + + dok?: boolean; + wasDownKeyPressed?: boolean; + + juk?: boolean; + wasJumpKeyPressed?: boolean; + + rpk?: boolean; + wasReleasePlatformKeyPressed?: boolean; + + rlk?: boolean; + wasReleaseLadderKeyPressed?: boolean; + + jkhsjs?: boolean; + jumpKeyHeldSinceJumpStart?: boolean; + + sn?: string; + state?: string; + + ssd?: StateNetworkSyncData; + stateSyncData?: StateNetworkSyncData; } /** @category Behaviors > Platform */ @@ -237,31 +285,38 @@ namespace gdjs { this._clearInputsBetweenFrames = true; this._ignoreDefaultControlsAsSyncedByNetwork = false; + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; + return { ...super.getNetworkSyncData(syncOptions), props: { - cs: this._currentSpeed, + [getKey('cs', 'currentSpeed')]: this._currentSpeed, // TODO Try to remove these 3 fields from the synch // They are reset every frame and are not part of the state. - rdx: this._requestedDeltaX, - rdy: this._requestedDeltaY, - ldy: this._lastDeltaY, - - cfs: this._currentFallSpeed, - cj: this._canJump, - ldl: this._lastDirectionIsLeft, - lek: this._wasLeftKeyPressed, - rik: this._wasRightKeyPressed, - lak: this._wasLadderKeyPressed, - upk: this._wasUpKeyPressed, - dok: this._wasDownKeyPressed, - juk: this._wasJumpKeyPressed, - rpk: this._wasReleasePlatformKeyPressed, - rlk: this._wasReleaseLadderKeyPressed, - jkhsjs: this._jumpKeyHeldSinceJumpStart, - sn: this._state.toString(), - ssd: this._state.getNetworkSyncData(), + [getKey('rdx', 'requestedDeltaX')]: this._requestedDeltaX, + [getKey('rdy', 'requestedDeltaY')]: this._requestedDeltaY, + [getKey('ldy', 'lastDeltaY')]: this._lastDeltaY, + + [getKey('cfs', 'currentFallSpeed')]: this._currentFallSpeed, + [getKey('cj', 'canJump')]: this._canJump, + [getKey('ldl', 'lastDirectionIsLeft')]: this._lastDirectionIsLeft, + [getKey('lek', 'wasLeftKeyPressed')]: this._wasLeftKeyPressed, + [getKey('rik', 'wasRightKeyPressed')]: this._wasRightKeyPressed, + [getKey('lak', 'wasLadderKeyPressed')]: this._wasLadderKeyPressed, + [getKey('upk', 'wasUpKeyPressed')]: this._wasUpKeyPressed, + [getKey('dok', 'wasDownKeyPressed')]: this._wasDownKeyPressed, + [getKey('juk', 'wasJumpKeyPressed')]: this._wasJumpKeyPressed, + [getKey('rpk', 'wasReleasePlatformKeyPressed')]: + this._wasReleasePlatformKeyPressed, + [getKey('rlk', 'wasReleaseLadderKeyPressed')]: + this._wasReleaseLadderKeyPressed, + [getKey('jkhsjs', 'jumpKeyHeldSinceJumpStart')]: + this._jumpKeyHeldSinceJumpStart, + [getKey('sn', 'state')]: this._state.toString(), + [getKey('ssd', 'stateSyncData')]: + this._state.getNetworkSyncData(syncOptions), }, }; } @@ -274,91 +329,141 @@ namespace gdjs { const behaviorSpecificProps = networkSyncData.props; - switch (behaviorSpecificProps.sn) { - case 'Falling': - if (behaviorSpecificProps.sn !== this._state.toString()) { - this._setFalling(); - } - this._falling.updateFromNetworkSyncData(behaviorSpecificProps.ssd); - break; - case 'OnFloor': - // Let it handle automatically as we don't know which platform to land on. - // @ts-ignore - we assume it's OnFloorStateNetworkSyncData - this._onFloor.updateFromNetworkSyncData(behaviorSpecificProps.ssd); - break; - case 'Jumping': - if (behaviorSpecificProps.sn !== this._state.toString()) { - this._setJumping(); - } - // @ts-ignore - we assume it's JumpingStateNetworkSyncData - this._jumping.updateFromNetworkSyncData(behaviorSpecificProps.ssd); - break; - case 'GrabbingPlatform': - // Let it handle automatically as we don't know which platform to grab. - this._grabbingPlatform.updateFromNetworkSyncData( - // @ts-ignore - we assume it's GrabbingPlatformStateNetworkSyncData - behaviorSpecificProps.ssd - ); - break; - case 'OnLadder': - if (behaviorSpecificProps.sn !== this._state.toString()) { - this._setOnLadder(); - } - this._onLadder.updateFromNetworkSyncData(behaviorSpecificProps.ssd); - break; - default: - console.error( - 'Unknown state name: ' + behaviorSpecificProps.sn + '.' - ); - break; + if (behaviorSpecificProps.ssd !== undefined) { + switch (behaviorSpecificProps.sn) { + case 'Falling': + if (behaviorSpecificProps.sn !== this._state.toString()) { + this._setFalling(); + } + this._falling.updateFromNetworkSyncData(behaviorSpecificProps.ssd); + break; + case 'OnFloor': + // Let it handle automatically as we don't know which platform to land on. + // @ts-ignore - we assume it's OnFloorStateNetworkSyncData + this._onFloor.updateFromNetworkSyncData(behaviorSpecificProps.ssd); + break; + case 'Jumping': + if (behaviorSpecificProps.sn !== this._state.toString()) { + this._setJumping(); + } + // @ts-ignore - we assume it's JumpingStateNetworkSyncData + this._jumping.updateFromNetworkSyncData(behaviorSpecificProps.ssd); + break; + case 'GrabbingPlatform': + // Let it handle automatically as we don't know which platform to grab. + this._grabbingPlatform.updateFromNetworkSyncData( + // @ts-ignore - we assume it's GrabbingPlatformStateNetworkSyncData + behaviorSpecificProps.ssd + ); + break; + case 'OnLadder': + if (behaviorSpecificProps.sn !== this._state.toString()) { + this._setOnLadder(); + } + this._onLadder.updateFromNetworkSyncData(behaviorSpecificProps.ssd); + break; + default: + console.error( + 'Unknown state name: ' + behaviorSpecificProps.sn + '.' + ); + break; + } } - if (behaviorSpecificProps.cs !== this._currentSpeed) { + if ( + behaviorSpecificProps.cs !== undefined && + behaviorSpecificProps.cs !== this._currentSpeed + ) { this._currentSpeed = behaviorSpecificProps.cs; } - if (behaviorSpecificProps.rdx !== this._requestedDeltaX) { + if ( + behaviorSpecificProps.rdx !== undefined && + behaviorSpecificProps.rdx !== this._requestedDeltaX + ) { this._requestedDeltaX = behaviorSpecificProps.rdx; } - if (behaviorSpecificProps.rdy !== this._requestedDeltaY) { + if ( + behaviorSpecificProps.rdy !== undefined && + behaviorSpecificProps.rdy !== this._requestedDeltaY + ) { this._requestedDeltaY = behaviorSpecificProps.rdy; } - if (behaviorSpecificProps.ldy !== this._lastDeltaY) { + if ( + behaviorSpecificProps.ldy !== undefined && + behaviorSpecificProps.ldy !== this._lastDeltaY + ) { this._lastDeltaY = behaviorSpecificProps.ldy; } - if (behaviorSpecificProps.cfs !== this._currentFallSpeed) { + if ( + behaviorSpecificProps.cfs !== undefined && + behaviorSpecificProps.cfs !== this._currentFallSpeed + ) { this._currentFallSpeed = behaviorSpecificProps.cfs; } - if (behaviorSpecificProps.cj !== this._canJump) { + if ( + behaviorSpecificProps.cj !== undefined && + behaviorSpecificProps.cj !== this._canJump + ) { this._canJump = behaviorSpecificProps.cj; } - if (behaviorSpecificProps.ldl !== this._lastDirectionIsLeft) { + if ( + behaviorSpecificProps.ldl !== undefined && + behaviorSpecificProps.ldl !== this._lastDirectionIsLeft + ) { this._lastDirectionIsLeft = behaviorSpecificProps.ldl; } - if (behaviorSpecificProps.lek !== this._leftKey) { + if ( + behaviorSpecificProps.lek !== undefined && + behaviorSpecificProps.lek !== this._leftKey + ) { this._leftKey = behaviorSpecificProps.lek; } - if (behaviorSpecificProps.rik !== this._rightKey) { + if ( + behaviorSpecificProps.rik !== undefined && + behaviorSpecificProps.rik !== this._rightKey + ) { this._rightKey = behaviorSpecificProps.rik; } - if (behaviorSpecificProps.lak !== this._ladderKey) { + if ( + behaviorSpecificProps.lak !== undefined && + behaviorSpecificProps.lak !== this._ladderKey + ) { this._ladderKey = behaviorSpecificProps.lak; } - if (behaviorSpecificProps.upk !== this._upKey) { + if ( + behaviorSpecificProps.upk !== undefined && + behaviorSpecificProps.upk !== this._upKey + ) { this._upKey = behaviorSpecificProps.upk; } - if (behaviorSpecificProps.dok !== this._downKey) { + if ( + behaviorSpecificProps.dok !== undefined && + behaviorSpecificProps.dok !== this._downKey + ) { this._downKey = behaviorSpecificProps.dok; } - if (behaviorSpecificProps.juk !== this._jumpKey) { + if ( + behaviorSpecificProps.juk !== undefined && + behaviorSpecificProps.juk !== this._jumpKey + ) { this._jumpKey = behaviorSpecificProps.juk; } - if (behaviorSpecificProps.rpk !== this._releasePlatformKey) { + if ( + behaviorSpecificProps.rpk !== undefined && + behaviorSpecificProps.rpk !== this._releasePlatformKey + ) { this._releasePlatformKey = behaviorSpecificProps.rpk; } - if (behaviorSpecificProps.rlk !== this._releaseLadderKey) { + if ( + behaviorSpecificProps.rlk !== undefined && + behaviorSpecificProps.rlk !== this._releaseLadderKey + ) { this._releaseLadderKey = behaviorSpecificProps.rlk; } - if (behaviorSpecificProps.jkhsjs !== this._jumpKeyHeldSinceJumpStart) { + if ( + behaviorSpecificProps.jkhsjs !== undefined && + behaviorSpecificProps.jkhsjs !== this._jumpKeyHeldSinceJumpStart + ) { this._jumpKeyHeldSinceJumpStart = behaviorSpecificProps.jkhsjs; } @@ -1910,7 +2015,9 @@ namespace gdjs { */ beforeMovingY(timeDelta: float, oldX: float): void; - getNetworkSyncData(): StateNetworkSyncData; + getNetworkSyncData( + options: GetNetworkSyncDataOptions + ): StateNetworkSyncData; updateFromNetworkSyncData(syncData: StateNetworkSyncData): void; } @@ -2214,18 +2321,22 @@ namespace gdjs { } } - getNetworkSyncData(): OnFloorStateNetworkSyncData { + getNetworkSyncData( + options: GetNetworkSyncDataOptions + ): OnFloorStateNetworkSyncData { + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; return { - flx: this._floorLastX, - fly: this._floorLastY, - oh: this._oldHeight, - }; + [getKey('flx', 'floorLastX')]: this._floorLastX, + [getKey('fly', 'floorLastY')]: this._floorLastY, + [getKey('oh', 'oldHeight')]: this._oldHeight, + } as OnFloorStateNetworkSyncData; } updateFromNetworkSyncData(data: OnFloorStateNetworkSyncData) { - this._floorLastX = data.flx; - this._floorLastY = data.fly; - this._oldHeight = data.oh; + if (data.flx !== undefined) this._floorLastX = data.flx; + if (data.fly !== undefined) this._floorLastY = data.fly; + if (data.oh !== undefined) this._oldHeight = data.oh; } toString(): String { @@ -2285,7 +2396,9 @@ namespace gdjs { this._behavior._fall(timeDelta); } - getNetworkSyncData(): FallingStateNetworkSyncData { + getNetworkSyncData( + _options: GetNetworkSyncDataOptions + ): FallingStateNetworkSyncData { return {}; } @@ -2398,18 +2511,24 @@ namespace gdjs { } } - getNetworkSyncData(): JumpingStateNetworkSyncData { + getNetworkSyncData( + options: GetNetworkSyncDataOptions + ): JumpingStateNetworkSyncData { + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; return { - cjs: this._currentJumpSpeed, - tscjs: this._timeSinceCurrentJumpStart, - jfd: this._jumpingFirstDelta, - }; + [getKey('cjs', 'currentJumpSpeed')]: this._currentJumpSpeed, + [getKey('tscjs', 'timeSinceCurrentJumpStart')]: + this._timeSinceCurrentJumpStart, + [getKey('jfd', 'jumpingFirstDelta')]: this._jumpingFirstDelta, + } as JumpingStateNetworkSyncData; } updateFromNetworkSyncData(data: JumpingStateNetworkSyncData) { - this._currentJumpSpeed = data.cjs; - this._timeSinceCurrentJumpStart = data.tscjs; - this._jumpingFirstDelta = data.jfd; + if (data.cjs !== undefined) this._currentJumpSpeed = data.cjs; + if (data.tscjs !== undefined) + this._timeSinceCurrentJumpStart = data.tscjs; + if (data.jfd !== undefined) this._jumpingFirstDelta = data.jfd; } toString(): String { @@ -2484,16 +2603,20 @@ namespace gdjs { this._grabbedPlatformLastY = this._grabbedPlatform.owner.getY(); } - getNetworkSyncData(): GrabbingPlatformStateNetworkSyncData { + getNetworkSyncData( + options: GetNetworkSyncDataOptions + ): GrabbingPlatformStateNetworkSyncData { + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; return { - gplx: this._grabbedPlatformLastX, - gply: this._grabbedPlatformLastY, - }; + [getKey('gplx', 'grabbedPlatformLastX')]: this._grabbedPlatformLastX, + [getKey('gply', 'grabbedPlatformLastY')]: this._grabbedPlatformLastY, + } as GrabbingPlatformStateNetworkSyncData; } updateFromNetworkSyncData(data: GrabbingPlatformStateNetworkSyncData) { - this._grabbedPlatformLastX = data.gplx; - this._grabbedPlatformLastY = data.gply; + if (data.gplx !== undefined) this._grabbedPlatformLastX = data.gplx; + if (data.gply !== undefined) this._grabbedPlatformLastY = data.gply; } toString(): String { @@ -2552,7 +2675,9 @@ namespace gdjs { } } - getNetworkSyncData(): OnLadderStateNetworkSyncData { + getNetworkSyncData( + _options: GetNetworkSyncDataOptions + ): OnLadderStateNetworkSyncData { return {}; } diff --git a/Extensions/PlatformBehavior/platformruntimebehavior.ts b/Extensions/PlatformBehavior/platformruntimebehavior.ts index c66e418b7c47..6c72ef3fb3b1 100644 --- a/Extensions/PlatformBehavior/platformruntimebehavior.ts +++ b/Extensions/PlatformBehavior/platformruntimebehavior.ts @@ -192,7 +192,15 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): BehaviorNetworkSyncData { - return super.getNetworkSyncData(syncOptions); + const base = super.getNetworkSyncData(syncOptions); + if (syncOptions.useFullNames) { + const typeNames = ['Platform', 'Jumpthru', 'Ladder']; + (base as any).props = { + platformType: typeNames[this._platformType] ?? 'Platform', + canBeGrabbed: this._canBeGrabbed, + }; + } + return base; } updateFromNetworkSyncData( diff --git a/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts b/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts index 87946410b313..1237cfa9e42c 100644 --- a/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts +++ b/Extensions/PrimitiveDrawing/shapepainterruntimeobject.ts @@ -48,18 +48,38 @@ namespace gdjs { export type ShapePainterObjectData = ObjectData & ShapePainterObjectDataType; type ShapePainterNetworkSyncDataType = { - cbf: boolean; // clearBetweenFrames - aa: Antialiasing; // antialiasing - ac: boolean; // absoluteCoordinates - fc: integer; // fillColor - oc: integer; // outlineColor - os: float; // outlineSize - fo: float; // fillOpacity - oo: float; // outlineOpacity - scaleX: number; - scaleY: number; - ifx: boolean; // isFlippedX - ify: boolean; // isFlippedY + cbf?: boolean; + clearBetweenFrames?: boolean; + + aa?: Antialiasing; + antialiasing?: Antialiasing; + + ac?: boolean; + useAbsoluteCoordinates?: boolean; + + fc?: integer; + fillColor?: integer; + + oc?: integer; + outlineColor?: integer; + + os?: float; + outlineSize?: float; + + fo?: float; + fillOpacity?: float; + + oo?: float; + outlineOpacity?: float; + + scaleX?: number; + scaleY?: number; + + ifx?: boolean; + isFlippedX?: boolean; + + ify?: boolean; + isFlippedY?: boolean; }; /** @category Objects > Shape Painter */ @@ -225,20 +245,22 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): ShapePainterNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - cbf: this._clearBetweenFrames, - aa: this._antialiasing, - ac: this._useAbsoluteCoordinates, - fc: this._fillColor, - oc: this._outlineColor, - os: this._outlineSize, - fo: this._fillOpacity, - oo: this._outlineOpacity, + [getKey('cbf', 'clearBetweenFrames')]: this._clearBetweenFrames, + [getKey('aa', 'antialiasing')]: this._antialiasing, + [getKey('ac', 'useAbsoluteCoordinates')]: this._useAbsoluteCoordinates, + [getKey('fc', 'fillColor')]: this._fillColor, + [getKey('oc', 'outlineColor')]: this._outlineColor, + [getKey('os', 'outlineSize')]: this._outlineSize, + [getKey('fo', 'fillOpacity')]: this._fillOpacity, + [getKey('oo', 'outlineOpacity')]: this._outlineOpacity, scaleX: this.getScaleX(), scaleY: this.getScaleY(), - ifx: this._flippedX, - ify: this._flippedY, + [getKey('ifx', 'isFlippedX')]: this._flippedX, + [getKey('ify', 'isFlippedY')]: this._flippedY, }; } diff --git a/Extensions/SaveState/SaveStateTools.ts b/Extensions/SaveState/SaveStateTools.ts index 2bfebd379b96..78ce875df931 100644 --- a/Extensions/SaveState/SaveStateTools.ts +++ b/Extensions/SaveState/SaveStateTools.ts @@ -206,8 +206,7 @@ namespace gdjs { const getNetworkSyncOptions: GetNetworkSyncDataOptions = { syncObjectIdentifiers: true, - shouldExcludeVariableFromData: - makeIsVariableExcludedFromSaveState(profileNames), + shouldExcludeVariableFromData: undefined, syncAllBehaviors: true, syncGameVariables: true, syncSceneTimers: true, diff --git a/Extensions/Spine/spineruntimeobject.ts b/Extensions/Spine/spineruntimeobject.ts index fe17d9483f69..894ebb56b829 100644 --- a/Extensions/Spine/spineruntimeobject.ts +++ b/Extensions/Spine/spineruntimeobject.ts @@ -17,16 +17,32 @@ namespace gdjs { /** @category Objects > Spine */ export type SpineNetworkSyncDataType = { - opa: float; - scaX: float; - scaY: float; - flipX: boolean; - flipY: boolean; - ani: number; - anmd: number; - anp: boolean; - anss: float; - anet: number; + opa?: float; + opacity?: float; + + scaX?: float; + scaleX?: float; + + scaY?: float; + scaleY?: float; + + flipX?: boolean; + flipY?: boolean; + + ani?: number; + animationIndex?: number; + + anmd?: number; + animationMixingDuration?: number; + + anp?: boolean; + animationPaused?: boolean; + + anss?: float; + animationSpeedScale?: float; + + anet?: number; + animationElapsedTime?: number; }; /** @category Objects > Spine */ @@ -136,18 +152,22 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): SpineNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - opa: this._opacity, - scaX: this.getScaleX(), - scaY: this.getScaleY(), + [getKey('opa', 'opacity')]: this._opacity, + [getKey('scaX', 'scaleX')]: this.getScaleX(), + [getKey('scaY', 'scaleY')]: this.getScaleY(), flipX: this.isFlippedX(), flipY: this.isFlippedY(), - ani: this.getAnimationIndex(), - anmd: this.getAnimationMixingDuration(), - anp: this.isAnimationPaused(), - anss: this.getAnimationSpeedScale(), - anet: this.getAnimationElapsedTime(), + [getKey('ani', 'animationIndex')]: this.getAnimationIndex(), + [getKey('anmd', 'animationMixingDuration')]: + this.getAnimationMixingDuration(), + [getKey('anp', 'animationPaused')]: this.isAnimationPaused(), + [getKey('anss', 'animationSpeedScale')]: this.getAnimationSpeedScale(), + [getKey('anet', 'animationElapsedTime')]: + this.getAnimationElapsedTime(), }; } diff --git a/Extensions/TextInput/textinputruntimeobject.ts b/Extensions/TextInput/textinputruntimeobject.ts index 80be7646f234..ed1f7003f228 100644 --- a/Extensions/TextInput/textinputruntimeobject.ts +++ b/Extensions/TextInput/textinputruntimeobject.ts @@ -70,21 +70,50 @@ namespace gdjs { * @category Objects > Text Input */ export type TextInputNetworkSyncDataType = { - opa: float; - txt: string; - frn: string; - fs: number; - place: string; - it: SupportedInputType; - tc: string; - fc: string; - fo: float; - bc: string; - bo: float; - bw: float; - dis: boolean; - ro: boolean; - sc: boolean; + opa?: float; + opacity?: float; + + txt?: string; + text?: string; + + frn?: string; + fontResourceName?: string; + + fs?: number; + fontSize?: number; + + place?: string; + placeholder?: string; + + it?: SupportedInputType; + inputType?: SupportedInputType; + + tc?: string; + textColor?: string; + + fc?: string; + fillColor?: string; + + fo?: float; + fillOpacity?: float; + + bc?: string; + borderColor?: string; + + bo?: float; + borderOpacity?: float; + + bw?: float; + borderWidth?: float; + + dis?: boolean; + isDisabled?: boolean; + + ro?: boolean; + isReadOnly?: boolean; + + sc?: boolean; + isSpellCheckEnabled?: boolean; }; /** @@ -283,23 +312,25 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): TextInputNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - opa: this.getOpacity(), - txt: this.getText(), - frn: this.getFontResourceName(), - fs: this.getFontSize(), - place: this.getPlaceholder(), - it: this.getInputType(), - tc: this.getTextColor(), - fc: this.getFillColor(), - fo: this.getFillOpacity(), - bc: this.getBorderColor(), - bo: this.getBorderOpacity(), - bw: this.getBorderWidth(), - dis: this.isDisabled(), - ro: this.isReadOnly(), - sc: this.isSpellCheckEnabled(), + [getKey('opa', 'opacity')]: this.getOpacity(), + [getKey('txt', 'text')]: this.getText(), + [getKey('frn', 'fontResourceName')]: this.getFontResourceName(), + [getKey('fs', 'fontSize')]: this.getFontSize(), + [getKey('place', 'placeholder')]: this.getPlaceholder(), + [getKey('it', 'inputType')]: this.getInputType(), + [getKey('tc', 'textColor')]: this.getTextColor(), + [getKey('fc', 'fillColor')]: this.getFillColor(), + [getKey('fo', 'fillOpacity')]: this.getFillOpacity(), + [getKey('bc', 'borderColor')]: this.getBorderColor(), + [getKey('bo', 'borderOpacity')]: this.getBorderOpacity(), + [getKey('bw', 'borderWidth')]: this.getBorderWidth(), + [getKey('dis', 'isDisabled')]: this.isDisabled(), + [getKey('ro', 'isReadOnly')]: this.isReadOnly(), + [getKey('sc', 'isSpellCheckEnabled')]: this.isSpellCheckEnabled(), }; } diff --git a/Extensions/TextObject/textruntimeobject.ts b/Extensions/TextObject/textruntimeobject.ts index 339c35938462..3e43efae47f5 100644 --- a/Extensions/TextObject/textruntimeobject.ts +++ b/Extensions/TextObject/textruntimeobject.ts @@ -51,30 +51,76 @@ namespace gdjs { * @category Objects > Text */ export type TextObjectNetworkSyncDataType = { - str: string; - o: float; - cs: number; - fn: string; - b: boolean; - i: boolean; - u: boolean; - c: number[]; - scale: number; - ta: string; - vta: string; - wrap: boolean; - wrapw: float; - oena: boolean; - ot: float; - oc: number[]; - sh: boolean; - shc: number[]; - sho: float; - shd: float; - sha: float; - shb: float; - pad: integer; - lh: float; + str?: string; + text?: string; + + o?: float; + opacity?: float; + + cs?: number; + characterSize?: number; + + fn?: string; + fontName?: string; + + b?: boolean; + bold?: boolean; + + i?: boolean; + italic?: boolean; + + u?: boolean; + underlined?: boolean; + + c?: number[]; + color?: number[]; + + scale?: number; + + ta?: string; + textAlignment?: string; + + vta?: string; + verticalTextAlignment?: string; + + wrap?: boolean; + wrapping?: boolean; + + wrapw?: float; + wrappingWidth?: float; + + oena?: boolean; + outlineEnabled?: boolean; + + ot?: float; + outlineThickness?: float; + + oc?: number[]; + outlineColor?: number[]; + + sh?: boolean; + shadowEnabled?: boolean; + + shc?: number[]; + shadowColor?: number[]; + + sho?: float; + shadowOpacity?: float; + + shd?: float; + shadowDistance?: float; + + sha?: float; + shadowAngle?: float; + + shb?: float; + shadowBlur?: float; + + pad?: integer; + padding?: integer; + + lh?: float; + lineHeight?: float; }; /** @@ -242,32 +288,34 @@ namespace gdjs { override getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): TextObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - str: this._str, - o: this.opacity, - cs: this._characterSize, - fn: this._fontName, - b: this._bold, - i: this._italic, - u: this._underlined, - c: this._color, + [getKey('str', 'text')]: this._str, + [getKey('o', 'opacity')]: this.opacity, + [getKey('cs', 'characterSize')]: this._characterSize, + [getKey('fn', 'fontName')]: this._fontName, + [getKey('b', 'bold')]: this._bold, + [getKey('i', 'italic')]: this._italic, + [getKey('u', 'underlined')]: this._underlined, + [getKey('c', 'color')]: this._color, scale: this.getScale(), - ta: this._textAlign, - vta: this._verticalTextAlignment, - wrap: this._wrapping, - wrapw: this._wrappingWidth, - oena: this._isOutlineEnabled, - ot: this._outlineThickness, - oc: this._outlineColor, - sh: this._shadow, - shc: this._shadowColor, - sho: this._shadowOpacity, - shd: this._shadowDistance, - sha: this._shadowAngle, - shb: this._shadowBlur, - lh: this._lineHeight, - pad: this._padding, + [getKey('ta', 'textAlignment')]: this._textAlign, + [getKey('vta', 'verticalTextAlignment')]: this._verticalTextAlignment, + [getKey('wrap', 'wrapping')]: this._wrapping, + [getKey('wrapw', 'wrappingWidth')]: this._wrappingWidth, + [getKey('oena', 'outlineEnabled')]: this._isOutlineEnabled, + [getKey('ot', 'outlineThickness')]: this._outlineThickness, + [getKey('oc', 'outlineColor')]: this._outlineColor, + [getKey('sh', 'shadowEnabled')]: this._shadow, + [getKey('shc', 'shadowColor')]: this._shadowColor, + [getKey('sho', 'shadowOpacity')]: this._shadowOpacity, + [getKey('shd', 'shadowDistance')]: this._shadowDistance, + [getKey('sha', 'shadowAngle')]: this._shadowAngle, + [getKey('shb', 'shadowBlur')]: this._shadowBlur, + [getKey('lh', 'lineHeight')]: this._lineHeight, + [getKey('pad', 'padding')]: this._padding, }; } diff --git a/Extensions/TileMap/simpletilemapruntimeobject.ts b/Extensions/TileMap/simpletilemapruntimeobject.ts index 479b94fd2938..60d23e9e6ba7 100644 --- a/Extensions/TileMap/simpletilemapruntimeobject.ts +++ b/Extensions/TileMap/simpletilemapruntimeobject.ts @@ -23,8 +23,11 @@ namespace gdjs { * @category Objects > Tile Map */ export type SimpleTileMapNetworkSyncDataType = { - op: number; + op?: number; + opacity?: number; + tm?: TileMapHelper.EditableTileMapAsJsObject; + tileMap?: TileMapHelper.EditableTileMapAsJsObject; }; /** @@ -175,13 +178,15 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): SimpleTileMapNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; const syncData: SimpleTileMapNetworkSyncData = { ...super.getNetworkSyncData(syncOptions), - op: this._opacity, + [getKey('op', 'opacity')]: this._opacity, }; if (this._tileMap && syncOptions.syncFullTileMaps) { const currentTileMapAsJsObject = this._tileMap.toJSObject(); - syncData.tm = currentTileMapAsJsObject; + syncData[getKey('tm', 'tileMap')] = currentTileMapAsJsObject; } return syncData; diff --git a/Extensions/TileMap/tilemapcollisionmaskruntimeobject.ts b/Extensions/TileMap/tilemapcollisionmaskruntimeobject.ts index e3cce2a79040..628c7c7f1eb5 100644 --- a/Extensions/TileMap/tilemapcollisionmaskruntimeobject.ts +++ b/Extensions/TileMap/tilemapcollisionmaskruntimeobject.ts @@ -27,14 +27,29 @@ namespace gdjs { * @category Objects > Tile Map */ export type TilemapCollisionMaskNetworkSyncDataType = { - tmjf: string; - tsjf: string; - dm: boolean; - oc: integer; - fc: integer; - os: float; - fo: float; - oo: float; + tmjf?: string; + tilemapJsonFile?: string; + + tsjf?: string; + tilesetJsonFile?: string; + + dm?: boolean; + debugMode?: boolean; + + oc?: integer; + outlineColor?: integer; + + fc?: integer; + fillColor?: integer; + + os?: float; + outlineSize?: float; + + fo?: float; + fillOpacity?: float; + + oo?: float; + outlineOpacity?: float; }; /** @@ -209,16 +224,18 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): TilemapCollisionMaskNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - tmjf: this.getTilemapJsonFile(), - tsjf: this.getTilesetJsonFile(), - dm: this.getDebugMode(), - oc: this.getOutlineColor(), - fc: this.getFillColor(), - os: this.getOutlineSize(), - fo: this.getFillOpacity(), - oo: this.getOutlineOpacity(), + [getKey('tmjf', 'tilemapJsonFile')]: this.getTilemapJsonFile(), + [getKey('tsjf', 'tilesetJsonFile')]: this.getTilesetJsonFile(), + [getKey('dm', 'debugMode')]: this.getDebugMode(), + [getKey('oc', 'outlineColor')]: this.getOutlineColor(), + [getKey('fc', 'fillColor')]: this.getFillColor(), + [getKey('os', 'outlineSize')]: this.getOutlineSize(), + [getKey('fo', 'fillOpacity')]: this.getFillOpacity(), + [getKey('oo', 'outlineOpacity')]: this.getOutlineOpacity(), }; } diff --git a/Extensions/TileMap/tilemapruntimeobject.ts b/Extensions/TileMap/tilemapruntimeobject.ts index 7dbce4c4e5cb..966f8f5fefc9 100644 --- a/Extensions/TileMap/tilemapruntimeobject.ts +++ b/Extensions/TileMap/tilemapruntimeobject.ts @@ -25,14 +25,29 @@ namespace gdjs { * @category Objects > Tile Map */ export type TilemapNetworkSyncDataType = { - op: number; - tmjf: string; - tsjf: string; - tmai: string; - dm: string; - lai: number; - lei: number; - asps: number; + op?: number; + opacity?: number; + + tmjf?: string; + tilemapJsonFile?: string; + + tsjf?: string; + tilesetJsonFile?: string; + + tmai?: string; + tilemapAtlasImage?: string; + + dm?: string; + displayMode?: string; + + lai?: number; + layerIndex?: number; + + lei?: number; + levelIndex?: number; + + asps?: number; + animationSpeedScale?: number; }; /** @@ -161,16 +176,18 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): TilemapNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - op: this._opacity, - tmjf: this._tilemapJsonFile, - tsjf: this._tilesetJsonFile, - tmai: this._tilemapAtlasImage, - dm: this._displayMode, - lai: this._layerIndex, - lei: this._levelIndex, - asps: this._animationSpeedScale, + [getKey('op', 'opacity')]: this._opacity, + [getKey('tmjf', 'tilemapJsonFile')]: this._tilemapJsonFile, + [getKey('tsjf', 'tilesetJsonFile')]: this._tilesetJsonFile, + [getKey('tmai', 'tilemapAtlasImage')]: this._tilemapAtlasImage, + [getKey('dm', 'displayMode')]: this._displayMode, + [getKey('lai', 'layerIndex')]: this._layerIndex, + [getKey('lei', 'levelIndex')]: this._levelIndex, + [getKey('asps', 'animationSpeedScale')]: this._animationSpeedScale, }; } diff --git a/Extensions/TiledSpriteObject/tiledspriteruntimeobject.ts b/Extensions/TiledSpriteObject/tiledspriteruntimeobject.ts index 7925b0c84a5b..78ad84364089 100644 --- a/Extensions/TiledSpriteObject/tiledspriteruntimeobject.ts +++ b/Extensions/TiledSpriteObject/tiledspriteruntimeobject.ts @@ -24,10 +24,16 @@ namespace gdjs { * @category Objects > Tiled Sprite */ export type TiledSpriteNetworkSyncDataType = { - xo: number; - yo: number; - op: number; - color: string; + xo?: number; + xOffset?: number; + + yo?: number; + yOffset?: number; + + op?: number; + opacity?: number; + + color?: string; }; /** @@ -99,11 +105,13 @@ namespace gdjs { getNetworkSyncData( syncOptons: GetNetworkSyncDataOptions ): TiledSpriteNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptons.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptons), - xo: this.getXOffset(), - yo: this.getYOffset(), - op: this.getOpacity(), + [getKey('xo', 'xOffset')]: this.getXOffset(), + [getKey('yo', 'yOffset')]: this.getYOffset(), + [getKey('op', 'opacity')]: this.getOpacity(), color: this.getColor(), }; } diff --git a/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.ts b/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.ts index 305c9374c27f..317e85599da8 100644 --- a/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.ts +++ b/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.ts @@ -5,17 +5,38 @@ Copyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com) namespace gdjs { interface TopDownMovementNetworkSyncDataType { - a: float; - xv: float; - yv: float; - as: float; - lk: boolean; - rk: boolean; - uk: boolean; - dk: boolean; - wsu: boolean; - sa: float; - sf: float; + a?: float; + angle?: float; + + xv?: float; + xVelocity?: float; + + yv?: float; + yVelocity?: float; + + as?: float; + angularSpeed?: float; + + lk?: boolean; + leftKey?: boolean; + + rk?: boolean; + rightKey?: boolean; + + uk?: boolean; + upKey?: boolean; + + dk?: boolean; + downKey?: boolean; + + wsu?: boolean; + wasStickUsed?: boolean; + + sa?: float; + stickAngle?: float; + + sf?: float; + stickForce?: float; } /** @category Behaviors > Top-down movement */ @@ -119,21 +140,23 @@ namespace gdjs { this._clearInputsBetweenFrames = true; this._ignoreDefaultControlsAsSyncedByNetwork = false; + const getKey = (abbrev: string, full: string) => + options.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(options), props: { - a: this._angle, - xv: this._xVelocity, - yv: this._yVelocity, - as: this._angularSpeed, - lk: this._wasLeftKeyPressed, - rk: this._wasRightKeyPressed, - uk: this._wasUpKeyPressed, - dk: this._wasDownKeyPressed, - wsu: this._wasStickUsed, - sa: this._stickAngle, - sf: this._stickForce, - }, + [getKey('a', 'angle')]: this._angle, + [getKey('xv', 'xVelocity')]: this._xVelocity, + [getKey('yv', 'yVelocity')]: this._yVelocity, + [getKey('as', 'angularSpeed')]: this._angularSpeed, + [getKey('lk', 'leftKey')]: this._wasLeftKeyPressed, + [getKey('rk', 'rightKey')]: this._wasRightKeyPressed, + [getKey('uk', 'upKey')]: this._wasUpKeyPressed, + [getKey('dk', 'downKey')]: this._wasDownKeyPressed, + [getKey('wsu', 'wasStickUsed')]: this._wasStickUsed, + [getKey('sa', 'stickAngle')]: this._stickAngle, + [getKey('sf', 'stickForce')]: this._stickForce, + } as TopDownMovementNetworkSyncDataType, }; } diff --git a/Extensions/Video/videoruntimeobject.ts b/Extensions/Video/videoruntimeobject.ts index 852e63d2bffe..6e5421e5c017 100644 --- a/Extensions/Video/videoruntimeobject.ts +++ b/Extensions/Video/videoruntimeobject.ts @@ -26,12 +26,20 @@ namespace gdjs { * @category Objects > Video */ export type VideoObjectNetworkSyncDataType = { - op: float; + op?: float; + opacity?: float; + // We don't sync volume, as it's probably a user setting? - pla: boolean; - loop: boolean; - ct: float; - ps: number; + pla?: boolean; + played?: boolean; + + loop?: boolean; + + ct?: float; + currentTime?: float; + + ps?: number; + playbackSpeed?: number; }; /** @@ -116,13 +124,15 @@ namespace gdjs { getNetworkSyncData( syncOptions: GetNetworkSyncDataOptions ): VideoObjectNetworkSyncData { + const getKey = (abbrev: string, full: string) => + syncOptions.useFullNames ? full : abbrev; return { ...super.getNetworkSyncData(syncOptions), - op: this._opacity, - pla: this.isPlayed(), + [getKey('op', 'opacity')]: this._opacity, + [getKey('pla', 'played')]: this.isPlayed(), loop: this.isLooped(), - ct: this.getCurrentTime(), - ps: this.getPlaybackSpeed(), + [getKey('ct', 'currentTime')]: this.getCurrentTime(), + [getKey('ps', 'playbackSpeed')]: this.getPlaybackSpeed(), }; } diff --git a/GDJS/GDJS/IDE/ExporterHelper.cpp b/GDJS/GDJS/IDE/ExporterHelper.cpp index fa8e1c580ba5..b7d4e31d4c3e 100644 --- a/GDJS/GDJS/IDE/ExporterHelper.cpp +++ b/GDJS/GDJS/IDE/ExporterHelper.cpp @@ -500,6 +500,10 @@ void ExporterHelper::SerializeRuntimeGameOptions( scriptFilesElement.ConsiderAsArrayOf("scriptFile"); for (const auto &includeFile : includesFiles) { + // Non-JS files (e.g. .wasm binaries) are not script files and should + // not be in the scriptFiles list used by the hot-reloader. + if (includeFile.size() >= 5 && includeFile.substr(includeFile.size() - 5) == ".wasm") continue; + auto hashIt = options.includeFileHashes.find(includeFile); gd::String scriptSrc = GetExportedIncludeFilename(fs, gdjsRoot, includeFile); scriptFilesElement.AddChild("scriptFile") @@ -1089,6 +1093,11 @@ bool ExporterHelper::CompleteIndexFile( gd::String scriptSrc = GetExportedIncludeFilename(fs, gdjsRoot, include, nonRuntimeScriptsCacheBurst); + // Non-JS files (e.g. .wasm binaries) must be copied to the export + // directory but must NOT be loaded as