|
8 | 8 | "name": "CurvedMovement", |
9 | 9 | "previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/Line Hero Pack/Master/SVG/Graphic Design/Graphic Design_bezier_curve.svg", |
10 | 10 | "shortDescription": "Move objects on curved paths.", |
11 | | - "version": "1.0.4", |
| 11 | + "version": "1.0.5", |
12 | 12 | "description": [ |
13 | 13 | "This extension allows to move objects on Bézier curve paths.", |
14 | 14 | "- Paths can be built dynamically or from predetermined paths in SVG format.", |
|
293 | 293 | " const clone = curve.clone();", |
294 | 294 | " for (const point of clone.points) {", |
295 | 295 | " point[0] += endX;", |
296 | | - " point[1] *= path.scaleY / this.speedScaleY;", |
| 296 | + " point[1] *= path.speedScaleY / this.speedScaleY;", |
297 | 297 | " point[1] += endY;", |
298 | 298 | " }", |
299 | | - " this.add(clone);", |
| 299 | + " this._add(clone);", |
300 | 300 | " }", |
301 | 301 | " };", |
302 | 302 | "", |
|
523 | 523 | " * @param {number} angle", |
524 | 524 | " */", |
525 | 525 | " 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 | + " ", |
528 | 537 | " for (const curve of this.curves) {", |
529 | 538 | " for (const point of curve.points) {", |
530 | 539 | " const x = point[0];", |
|
636 | 645 | " const clone = new CubicBezierCurve();", |
637 | 646 | " clone.points = this.points.map(point => [...point]);", |
638 | 647 | " clone.arcLengths = [...this.arcLengths];", |
| 648 | + " clone.speedScaleY = this.speedScaleY;", |
639 | 649 | " return clone;", |
640 | 650 | " }", |
641 | 651 | "", |
|
970 | 980 | " * @param {CurvedPath} path", |
971 | 981 | " */", |
972 | 982 | "CurvedPath.toSvg = function (path) {", |
973 | | - " let svgString = 'C';", |
| 983 | + " let svgString = '';", |
974 | 984 | " for (const curve of path.curves) {", |
| 985 | + " svgString += 'C'", |
975 | 986 | " for (const point of curve.points) {", |
976 | | - " svgString += `${point[0]},${point[0]}`;", |
| 987 | + " svgString += `${point[0]},${point[1]} `;", |
977 | 988 | " }", |
978 | | - " svgString += ' ';", |
979 | 989 | " }", |
980 | | - " return path;", |
| 990 | + " return svgString;", |
981 | 991 | "}", |
982 | 992 | "", |
983 | 993 | "gdjs.__curvedMovementExtension = gdjs.__curvedMovementExtension || {};", |
|
1439 | 1449 | ], |
1440 | 1450 | "objectGroups": [] |
1441 | 1451 | }, |
| 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 | + }, |
1442 | 1494 | { |
1443 | 1495 | "description": "Append a path to another path. The appended path is rotated to have a smooth junction.", |
1444 | 1496 | "fullName": "Append a rotated path", |
|
6266 | 6318 | "subInstructions": [ |
6267 | 6319 | { |
6268 | 6320 | "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 | + ] |
6277 | 6329 | }, |
6278 | 6330 | { |
6279 | 6331 | "type": { |
|
6315 | 6367 | "subInstructions": [ |
6316 | 6368 | { |
6317 | 6369 | "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 | + ] |
6326 | 6378 | }, |
6327 | 6379 | { |
6328 | 6380 | "type": { |
|
6334 | 6386 | "<", |
6335 | 6387 | "0" |
6336 | 6388 | ] |
6337 | | - } |
6338 | | - ] |
6339 | 6389 | } |
6340 | 6390 | ] |
6341 | 6391 | } |
6342 | 6392 | ] |
6343 | 6393 | } |
| 6394 | + ] |
| 6395 | + } |
6344 | 6396 | ], |
6345 | 6397 | "actions": [ |
6346 | 6398 | { |
|
0 commit comments