+32
-10
lines changedFilter options
+32
-10
lines changed Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import com.almasb.fxgl.entity.level.LevelLoadingException
16
16
import com.almasb.fxgl.logging.Logger
17
17
import javafx.scene.paint.Color
18
18
import javafx.scene.shape.Polygon
19
+
import javafx.scene.shape.Polyline
19
20
import java.io.InputStream
20
21
import java.net.URL
21
22
import java.util.*
@@ -247,7 +248,11 @@ class TMXLevelLoader
247
248
}
248
249
249
250
"polygon" -> {
250
-
parseObjectPolygon(currentObject, start)
251
+
parseObjectPolyline(currentObject, start, isClosed = true)
252
+
}
253
+
254
+
"polyline" -> {
255
+
parseObjectPolyline(currentObject, start, isClosed = false)
251
256
}
252
257
}
253
258
}
@@ -502,18 +507,23 @@ class TMXLevelLoader
502
507
}
503
508
}
504
509
505
-
private fun parseObjectPolygon(obj: TiledObject, start: StartElement) {
510
+
private fun parseObjectPolyline(obj: TiledObject, start: StartElement, isClosed: Boolean) {
506
511
val data = start.getString("points")
507
512
508
513
val points = data.split(" +".toRegex())
509
514
.flatMap { it.split(",") }
510
515
.map { it.toDouble() }
511
516
.toDoubleArray()
512
517
513
-
// https://github.com/AlmasB/FXGL/issues/575
514
-
val polygon = Polygon(*points)
518
+
if (isClosed) {
519
+
val polygon = Polygon(*points)
515
520
516
-
(obj.properties as MutableMap)["polygon"] = polygon
521
+
(obj.properties as MutableMap)["polygon"] = polygon
522
+
} else {
523
+
val polyline = Polyline(*points)
524
+
525
+
(obj.properties as MutableMap)["polyline"] = polyline
526
+
}
517
527
}
518
528
}
519
529
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import javafx.geometry.Point2D
13
13
import javafx.scene.image.ImageView
14
14
import javafx.scene.paint.Color
15
15
import javafx.scene.shape.Polygon
16
+
import javafx.scene.shape.Polyline
16
17
import org.hamcrest.CoreMatchers.`is`
17
18
import org.hamcrest.CoreMatchers.not
18
19
import org.hamcrest.MatcherAssert.assertThat
@@ -43,8 +44,8 @@ class TMXLevelLoaderTest {
43
44
assertThat(level.width, `is`(24*64))
44
45
assertThat(level.height, `is`(24*64))
45
46
46
-
// 4 object entities + 2 background tile layers
47
-
assertThat(level.entities.size, `is`(4 + 2))
47
+
// 5 object entities + 2 background tile layers
48
+
assertThat(level.entities.size, `is`(5 + 2))
48
49
}
49
50
50
51
@ParameterizedTest
@@ -200,7 +201,7 @@ class TMXLevelLoaderTest {
200
201
assertThat(map.height, `is`(64))
201
202
assertThat(map.tilewidth, `is`(24))
202
203
assertThat(map.tileheight, `is`(24))
203
-
assertThat(map.nextobjectid, `is`(5))
204
+
assertThat(map.nextobjectid, `is`(7))
204
205
assertThat(map.orientation, `is`("orthogonal"))
205
206
assertThat(map.renderorder, `is`("right-down"))
206
207
assertFalse(map.infinite)
@@ -281,6 +282,11 @@ class TMXLevelLoaderTest {
281
282
assertThat(obj4.id, `is`(4))
282
283
assertThat((obj4.properties["polygon"] as Polygon).points, `is`(Polygon(0.0, 0.0, 120.0, -72.0, 192.0, 48.0, 24.0, 48.0).points))
283
284
285
+
val obj6 = layer3.objects[3]
286
+
287
+
assertThat(obj6.id, `is`(6))
288
+
assertThat((obj6.properties["polyline"] as Polyline).points, `is`(Polyline(0.0,0.0, 96.0,0.0, 96.0,-96.0, 192.0,-96.0, 192.0,96.0, 24.0,96.0).points))
289
+
284
290
val layer4 = map.layers[3]
285
291
286
292
assertThat(layer4.name, `is`("Group2"))
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1
1
<?xml version="1.0" encoding="UTF-8"?>
2
-
<map version="1.0" tiledversion="1.1.2" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="24" tileheight="24" infinite="0" nextobjectid="5">
2
+
<map version="1.0" tiledversion="1.1.2" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="24" tileheight="24" infinite="0" nextobjectid="7">
3
3
<tileset firstgid="1" name="sewer_tileset" tilewidth="24" tileheight="24" tilecount="72" columns="8">
4
4
<image source="sewer_tileset.png" trans="ff00ff" width="192" height="217"/>
5
5
</tileset>
@@ -26,6 +26,9 @@
26
26
<object id="4" name="polygon_name" type="no_type" x="696" y="504">
27
27
<polygon points="0,0 120,-72 192,48 24,48"/>
28
28
</object>
29
+
<object id="6" name="polyline_name" type="no_type" x="936" y="432">
30
+
<polyline points="0,0 96,0 96,-96 192,-96 192,96 24,96"/>
31
+
</object>
29
32
</objectgroup>
30
33
<objectgroup name="Group2">
31
34
<object id="3" name="no name" x="240" y="504" width="120" height="120"/>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1
1
<?xml version="1.0" encoding="UTF-8"?>
2
-
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="24" tileheight="24" infinite="0" nextlayerid="5" nextobjectid="5">
2
+
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="24" tileheight="24" infinite="0" nextlayerid="5" nextobjectid="7">
3
3
<tileset firstgid="1" name="sewer_tileset" tilewidth="24" tileheight="24" tilecount="72" columns="8">
4
4
<image source="sewer_tileset.png" trans="ff00ff" width="192" height="217"/>
5
5
</tileset>
@@ -26,6 +26,9 @@
26
26
<object id="4" name="polygon_name" type="no_type" x="696" y="504">
27
27
<polygon points="0,0 120,-72 192,48 24,48"/>
28
28
</object>
29
+
<object id="6" name="polyline_name" type="no_type" x="936" y="432">
30
+
<polyline points="0,0 96,0 96,-96 192,-96 192,96 24,96"/>
31
+
</object>
29
32
</objectgroup>
30
33
<objectgroup id="4" name="Group2">
31
34
<object id="3" name="no name" x="240" y="504" width="120" height="120"/>
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4