Skip to content

Commit 1ab3beb

Browse files
author
Julien
committed
fix(sdk): polygon paths can be interpolated
1 parent 3adfaa4 commit 1ab3beb

File tree

2 files changed

+37
-6
lines changed
  • engine/modules/entities/src/main

2 files changed

+37
-6
lines changed

engine/modules/entities/src/main/java/com/codingame/gameengine/module/entities/Polygon.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,52 @@ public Point(int x, int y) {
1919
this.x = x;
2020
this.y = y;
2121
}
22-
22+
2323
}
24-
24+
2525
private List<Point> points = new ArrayList<>();
2626

2727
Polygon() {
2828
super();
2929
}
30-
30+
3131
/**
3232
* Adds a point to the path of this <code>Polygon</code>.
33-
* @param x the x coordinate in world units
34-
* @param y the x coordinate in world units
33+
*
34+
* @param x
35+
* the x coordinate in world units
36+
* @param y
37+
* the x coordinate in world units
3538
* @return this <code>Polygon</code>
3639
*/
3740
public Polygon addPoint(int x, int y) {
3841
points.add(new Point(x, y));
3942
set("points", asString(points));
4043
return this;
4144
}
42-
45+
46+
/**
47+
* Clears the path of this <code>Polygon</code>.
48+
*
49+
* @return this <code>Polygon</code>
50+
*/
51+
public Polygon clearPoints() {
52+
points.clear();
53+
set("points", asString(points));
54+
return this;
55+
}
56+
57+
/**
58+
* Sets the transition used to animate the positions of each point. Only used if the path has the same number of points.
59+
* @param curve
60+
* the transition to animate between coordinates of each point in the path.
61+
* @return this <code>Polygon</code>
62+
*/
63+
public Polygon setPointsInterpolationCurve(Curve curve) {
64+
set("points", asString(points), curve);
65+
return this;
66+
}
67+
4368
private String asString(List<Point> points) {
4469
return points.stream().map(p -> p.x + "," + p.y).collect(Collectors.joining(","));
4570
}

engine/modules/entities/src/main/resources/view/entity-module/properties.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ export const PROPERTIES = {
117117
return []
118118
}
119119
return value.split(',').map(v => parseInt(v))
120+
},
121+
lerpMethod: (a, b, u) => {
122+
if (a.length === b.length) {
123+
return a.map((v, idx) => lerp(v, b[idx], u))
124+
}
125+
return noLerp(a, b, u)
120126
}
121127
}
122128
}

0 commit comments

Comments
 (0)