Skip to content

Commit 809cc5f

Browse files
authored
Update libGDX to 1.13.5. #499 #500
Update LibGDX to 1.13.5, add TextMapObject to shape extension and add new forEachCell extension (#500) * update LibGDX from 1.13.1 to 1.13.5 * add TextMapObject to shape extension * add forEachCell TiledMapTileLayer extension * fix Box2D tests for LibGDX 1.13.5 * inc fault tolerance * update snapshot version and changelog
1 parent aa5429d commit 809cc5f

File tree

12 files changed

+79
-10
lines changed

12 files changed

+79
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
_See also: [the official libGDX changelog](https://github.com/libgdx/libgdx/blob/master/CHANGES)._
22

3-
#### 1.13.1-SNAPSHOT
3+
#### 1.13.5-SNAPSHOT
4+
- **[UPDATE]** Updated to libGDX 1.13.5.
5+
- **[UPDATE]** Updated `shape` extension function for tiled to support the new `TextMapObject`.
6+
- **[FEATURE]** Add a new `forEachCell` extension function for `TiledMapTileLayer` objects.
47

58
#### 1.13.1-rc1
69

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ repositories {
305305
306306
ext {
307307
// Update this version to match the latest libGDX release:
308-
ktxVersion = '1.13.1-SNAPSHOT'
308+
ktxVersion = '1.13.5-SNAPSHOT'
309309
}
310310
```
311311

@@ -320,7 +320,7 @@ repositories {
320320
}
321321

322322
// Update this version to match the latest libGDX release:
323-
val ktxVersion = "1.13.1-SNAPSHOT"
323+
val ktxVersion = "1.13.5-SNAPSHOT"
324324
```
325325

326326
</details>

app/src/test/kotlin/ktx/app/ProfilingTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ProfilingTest {
2828
assertEquals(10, performanceCounter.time.mean.windowSize)
2929
assertEquals(10, performanceCounter.time.count)
3030
assertEquals(10, repeats)
31-
assertEquals(0.01f, performanceCounter.time.mean.mean, 0.002f)
31+
assertEquals(0.01f, performanceCounter.time.mean.mean, 0.01f)
3232
}
3333

3434
@Test
@@ -44,7 +44,7 @@ class ProfilingTest {
4444
assertEquals("Thread.sleep", performanceCounter.name)
4545
assertEquals(10, performanceCounter.time.count)
4646
assertEquals(10, repeats)
47-
assertEquals(0.01f, performanceCounter.time.mean.mean, 0.002f)
47+
assertEquals(0.01f, performanceCounter.time.mean.mean, 0.01f)
4848
}
4949

5050
@After

box2d/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import ktx.*
1+
import ktx.gdxVersion
22

33
dependencies {
44
api("com.badlogicgames.gdx:gdx-box2d:$gdxVersion")
55
testImplementation("com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop")
6+
testImplementation("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop")
67
}

box2d/src/test/kotlin/ktx/box2d/Box2DTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.badlogic.gdx.physics.box2d.Box2D
55
import com.badlogic.gdx.physics.box2d.ChainShape
66
import com.badlogic.gdx.physics.box2d.EdgeShape
77
import com.badlogic.gdx.physics.box2d.PolygonShape
8+
import com.badlogic.gdx.utils.GdxNativesLoader
89
import org.junit.Assert.assertEquals
910
import org.junit.BeforeClass
1011

@@ -67,6 +68,7 @@ abstract class Box2DTest {
6768
@JvmStatic
6869
@BeforeClass
6970
fun `initiate Box2D`() {
71+
GdxNativesLoader.load()
7072
Box2D.init()
7173
}
7274
}

buildSrc/src/main/kotlin/ktx/Versions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ktx
22

3-
const val gdxVersion = "1.13.1"
3+
const val gdxVersion = "1.13.5"
44
const val kotlinCoroutinesVersion = "1.10.1"
55

66
const val artemisOdbVersion = "2.3.0"

tiled/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ a certain function on them.
8181

8282
### `MapLayers` and `MapObjects`
8383

84-
`isEmpty` and `isNotEmpty` extension method to check if the specific collection is empty or not.
84+
- `isEmpty` and `isNotEmpty` extension method to check if the specific collection is empty or not.
85+
- `forEachCell` extension method iterates through all cells in a `TiledMapTileLayer`, executing the given action for each cell along with its coordinates. Non-null cells only are processed during iteration.
8586

8687
### `BatchTiledMapRenderer`
8788

@@ -244,6 +245,22 @@ map.forEachLayer<MapLayer> { layer ->
244245
}
245246
```
246247

248+
Iterating over all non-null cells of a `TiledMapTileLayer`:
249+
250+
```kotlin
251+
import com.badlogic.gdx.maps.tiled.TiledMap
252+
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer
253+
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
254+
import ktx.tiled.*
255+
256+
val map: TiledMap = getTiledMap()
257+
map.forEachLayer<TiledMapTileLayer> { layer ->
258+
layer.forEachCell { cell, cellX, cellY ->
259+
println("Processing cell $cell. Coordinates($cellX/$cellY)")
260+
}
261+
}
262+
```
263+
247264
Checking if `MapLayers` and `MapObjects` collections are empty:
248265

249266
```kotlin

tiled/src/main/kotlin/ktx/tiled/mapLayers.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package ktx.tiled
33
import com.badlogic.gdx.maps.MapLayer
44
import com.badlogic.gdx.maps.MapLayers
55
import com.badlogic.gdx.maps.MapProperties
6+
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer
7+
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
68

79
/**
810
* Extension method to directly access the [MapProperties] of a [MapLayer]. If the property
@@ -53,3 +55,15 @@ fun MapLayers.isEmpty() = this.count <= 0
5355
* Returns **true** if and only if the [MapLayers] collection is not empty.
5456
*/
5557
fun MapLayers.isNotEmpty() = this.count > 0
58+
59+
/**
60+
* Iterates through all cells in the [TiledMapTileLayer], executing the given [action] for each cell.
61+
* The action receives the cell and its coordinates within the layer.
62+
*/
63+
fun TiledMapTileLayer.forEachCell(action: (cell: Cell, cellX: Int, cellY: Int) -> (Unit)) {
64+
for (y in 0 until this.height) {
65+
for (x in 0 until this.width) {
66+
this.getCell(x, y)?.let { action(it, x, y) }
67+
}
68+
}
69+
}

tiled/src/main/kotlin/ktx/tiled/mapObjects.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.badlogic.gdx.maps.objects.EllipseMapObject
88
import com.badlogic.gdx.maps.objects.PolygonMapObject
99
import com.badlogic.gdx.maps.objects.PolylineMapObject
1010
import com.badlogic.gdx.maps.objects.RectangleMapObject
11+
import com.badlogic.gdx.maps.objects.TextMapObject
1112
import com.badlogic.gdx.maps.objects.TextureMapObject
1213
import com.badlogic.gdx.math.Circle
1314
import com.badlogic.gdx.math.Ellipse
@@ -105,7 +106,7 @@ val MapObject.type: String?
105106

106107
/**
107108
* Extension method to retrieve the [Shape2D] instance of a [MapObject].
108-
* Depending on the type of the object a different shape will be returned:
109+
* Depending on the type of the object, a different shape will be returned:
109110
*
110111
* - [CircleMapObject] -> [Circle]
111112
* - [EllipseMapObject] -> [Ellipse]
@@ -124,6 +125,7 @@ val MapObject.shape: Shape2D
124125
is PolylineMapObject -> polyline
125126
is PolygonMapObject -> polygon
126127
is RectangleMapObject -> rectangle
128+
is TextMapObject -> rectangle
127129
else -> throw MissingShapeException("MapObject of type ${this::class.java} does not have a shape.")
128130
}
129131

tiled/src/test/kotlin/ktx/tiled/MapLayerTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package ktx.tiled
22

33
import com.badlogic.gdx.maps.MapLayer
44
import com.badlogic.gdx.maps.MapLayers
5+
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer
6+
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
57
import org.junit.Assert.assertEquals
68
import org.junit.Assert.assertFalse
79
import org.junit.Assert.assertNull
@@ -85,4 +87,24 @@ class MapLayerTest {
8587

8688
assertFalse(actual.isNotEmpty())
8789
}
90+
91+
@Test
92+
fun `should iterate over each cell in the TiledMapTileLayer`() {
93+
val layer = TiledMapTileLayer(2, 2, 32, 32).apply {
94+
setCell(0, 0, Cell())
95+
setCell(1, 0, null) // this cell is skipped during iteration
96+
setCell(0, 1, Cell())
97+
setCell(1, 1, Cell())
98+
}
99+
100+
val collectedCells = mutableListOf<Triple<Int, Int, Cell>>()
101+
layer.forEachCell { cell, cellX, cellY ->
102+
collectedCells.add(Triple(cellX, cellY, cell))
103+
}
104+
105+
assertEquals(3, collectedCells.size)
106+
assertEquals(Triple(0, 0, layer.getCell(0, 0)), collectedCells[0])
107+
assertEquals(Triple(0, 1, layer.getCell(0, 1)), collectedCells[1])
108+
assertEquals(Triple(1, 1, layer.getCell(1, 1)), collectedCells[2])
109+
}
88110
}

0 commit comments

Comments
 (0)