Skip to content

Commit afff7d5

Browse files
authored
[Community] [Curved movement] Fix the action to append paths (#940)
* Add an action to duplicate a path.
1 parent c4aa58a commit afff7d5

File tree

1 file changed

+79
-27
lines changed

1 file changed

+79
-27
lines changed

extensions/community/CurvedMovement.json

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "CurvedMovement",
99
"previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/Line Hero Pack/Master/SVG/Graphic Design/Graphic Design_bezier_curve.svg",
1010
"shortDescription": "Move objects on curved paths.",
11-
"version": "1.0.4",
11+
"version": "1.0.5",
1212
"description": [
1313
"This extension allows to move objects on Bézier curve paths.",
1414
"- Paths can be built dynamically or from predetermined paths in SVG format.",
@@ -293,10 +293,10 @@
293293
" const clone = curve.clone();",
294294
" for (const point of clone.points) {",
295295
" point[0] += endX;",
296-
" point[1] *= path.scaleY / this.speedScaleY;",
296+
" point[1] *= path.speedScaleY / this.speedScaleY;",
297297
" point[1] += endY;",
298298
" }",
299-
" this.add(clone);",
299+
" this._add(clone);",
300300
" }",
301301
" };",
302302
"",
@@ -523,8 +523,17 @@
523523
" * @param {number} angle",
524524
" */",
525525
" CurvedPath.prototype.rotate = function (angle) {",
526-
" const cos = Math.cos(angle);",
527-
" const sin = Math.sin(angle);",
526+
" let cos = Math.cos(angle);",
527+
" let sin = Math.sin(angle);",
528+
"",
529+
" // Avoid rounding errors around 0.",
530+
" if (cos === -1 || cos === 1) {",
531+
" sin = 0;",
532+
" }",
533+
" if (sin === -1 || sin === 1) {",
534+
" cos = 0;",
535+
" }",
536+
" ",
528537
" for (const curve of this.curves) {",
529538
" for (const point of curve.points) {",
530539
" const x = point[0];",
@@ -636,6 +645,7 @@
636645
" const clone = new CubicBezierCurve();",
637646
" clone.points = this.points.map(point => [...point]);",
638647
" clone.arcLengths = [...this.arcLengths];",
648+
" clone.speedScaleY = this.speedScaleY;",
639649
" return clone;",
640650
" }",
641651
"",
@@ -970,14 +980,14 @@
970980
" * @param {CurvedPath} path",
971981
" */",
972982
"CurvedPath.toSvg = function (path) {",
973-
" let svgString = 'C';",
983+
" let svgString = '';",
974984
" for (const curve of path.curves) {",
985+
" svgString += 'C'",
975986
" for (const point of curve.points) {",
976-
" svgString += `${point[0]},${point[0]}`;",
987+
" svgString += `${point[0]},${point[1]} `;",
977988
" }",
978-
" svgString += ' ';",
979989
" }",
980-
" return path;",
990+
" return svgString;",
981991
"}",
982992
"",
983993
"gdjs.__curvedMovementExtension = gdjs.__curvedMovementExtension || {};",
@@ -1439,6 +1449,48 @@
14391449
],
14401450
"objectGroups": []
14411451
},
1452+
{
1453+
"description": "Duplicate a path.",
1454+
"fullName": "Duplicate a path",
1455+
"functionType": "Action",
1456+
"name": "DuplicatedPath",
1457+
"sentence": "Create path _PARAM1_ as a duplicate of path _PARAM2_",
1458+
"events": [
1459+
{
1460+
"type": "BuiltinCommonInstructions::JsCode",
1461+
"inlineCode": [
1462+
"const createdPathName = eventsFunctionContext.getArgument(\"CreatedPathName\");",
1463+
"const sourcePathName = eventsFunctionContext.getArgument(\"SourcePathName\");",
1464+
"/** @type {Map<string, gdjs.__curvedMovementExtension.CurvedPath>} */",
1465+
"const curvedPaths = runtimeScene.__curvedMovementExtension.curvedPaths;",
1466+
"",
1467+
"let sourcePath = curvedPaths.get(sourcePathName);",
1468+
"if (sourcePath) {",
1469+
" const createdPath = sourcePath.clone();",
1470+
" curvedPaths.set(createdPathName, createdPath);",
1471+
"}"
1472+
],
1473+
"parameterObjects": "",
1474+
"useStrict": true,
1475+
"eventsSheetExpanded": true
1476+
}
1477+
],
1478+
"parameters": [
1479+
{
1480+
"description": "Name of the path to create",
1481+
"name": "CreatedPathName",
1482+
"supplementaryInformation": "sceneBezierCurve",
1483+
"type": "identifier"
1484+
},
1485+
{
1486+
"description": "Name of the source path",
1487+
"name": "SourcePathName",
1488+
"supplementaryInformation": "sceneBezierCurve",
1489+
"type": "identifier"
1490+
}
1491+
],
1492+
"objectGroups": []
1493+
},
14421494
{
14431495
"description": "Append a path to another path. The appended path is rotated to have a smooth junction.",
14441496
"fullName": "Append a rotated path",
@@ -6266,14 +6318,14 @@
62666318
"subInstructions": [
62676319
{
62686320
"type": {
6269-
"value": "CurvedMovement::SpeedPathMovement::PropertySpeed"
6270-
},
6271-
"parameters": [
6272-
"Object",
6273-
"Behavior",
6274-
">",
6275-
"0"
6276-
]
6321+
"value": "CurvedMovement::SpeedPathMovement::PropertySpeed"
6322+
},
6323+
"parameters": [
6324+
"Object",
6325+
"Behavior",
6326+
">",
6327+
"0"
6328+
]
62776329
},
62786330
{
62796331
"type": {
@@ -6315,14 +6367,14 @@
63156367
"subInstructions": [
63166368
{
63176369
"type": {
6318-
"value": "CurvedMovement::SpeedPathMovement::PropertySpeed"
6319-
},
6320-
"parameters": [
6321-
"Object",
6322-
"Behavior",
6323-
"<",
6324-
"0"
6325-
]
6370+
"value": "CurvedMovement::SpeedPathMovement::PropertySpeed"
6371+
},
6372+
"parameters": [
6373+
"Object",
6374+
"Behavior",
6375+
"<",
6376+
"0"
6377+
]
63266378
},
63276379
{
63286380
"type": {
@@ -6334,13 +6386,13 @@
63346386
"<",
63356387
"0"
63366388
]
6337-
}
6338-
]
63396389
}
63406390
]
63416391
}
63426392
]
63436393
}
6394+
]
6395+
}
63446396
],
63456397
"actions": [
63466398
{

0 commit comments

Comments
 (0)