Skip to content

Commit

Permalink
added an action to change the color of a cube
Browse files Browse the repository at this point in the history
  • Loading branch information
NeylMahfouf2608 committed Feb 5, 2025
1 parent 3f3a4c3 commit 4117f53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Extensions/3D/Cube3DRuntimeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace gdjs {
trfb: integer;
frn: [string, string, string, string, string, string];
mt: number;
c: number;
};

type Cube3DObjectNetworkSyncData = Object3DNetworkSyncData &
Expand Down Expand Up @@ -211,7 +212,7 @@ namespace gdjs {
this._faceResourceNames[faceIndex] = resourceName;
this._renderer.updateFace(faceIndex);
}
setCubeColor(color: string): void {
setColor(color: string): void {
let colorinHex = gdjs.rgbOrHexStringToNumber(color);
if (colorinHex === this._color) return;
this._color = colorinHex;
Expand Down Expand Up @@ -302,7 +303,7 @@ namespace gdjs {
);
}
if (oldObjectData.content.color !== newObjectData.content.color) {
this.setCubeColor(newObjectData.content.color);
this.setColor(newObjectData.content.color);
}

if (
Expand Down Expand Up @@ -437,6 +438,7 @@ namespace gdjs {
vfb: this._visibleFacesBitmask,
trfb: this._textureRepeatFacesBitmask,
frn: this._faceResourceNames,
c: this._color,
};
}

Expand Down Expand Up @@ -490,6 +492,12 @@ namespace gdjs {
}
}
}
if (networkSyncData.c !== undefined) {
if (this._color !== networkSyncData.c) {
this._color = networkSyncData.c;
this._renderer.updateColor();
}
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions Extensions/3D/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,21 @@ module.exports = {
.addParameter('imageResource', _('Image'), '', false)
.setFunctionName('setFaceResourceName');

object
.addScopedAction(
'SetColor',
_('Color'),
_('Change the color of the cube.'),
_('Change the color of _PARAM0_ to _PARAM1_'),
_('Color'),
'res/actions/color24.png',
'res/actions/color.png'
)
.addParameter('object', _('3D Cube'), 'Cube3DObject', false)
.addParameter('color', _('Color'), '', false)
.getCodeExtraInformation()
.setFunctionName('setColor');

extension
.addExpressionAndConditionAndAction(
'number',
Expand Down

0 comments on commit 4117f53

Please sign in to comment.