Skip to content

Commit

Permalink
test: Validate relative TMX image source path loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-René Lavoie committed Nov 6, 2023
1 parent 4a6d32c commit f8853b4
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.almasb.fxgl.entity.components.IDComponent
import com.almasb.fxgl.entity.level.LevelLoadingException
import com.almasb.fxgl.test.RunWithFX
import javafx.geometry.Point2D
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.scene.paint.Color
import javafx.scene.shape.Polygon
Expand Down Expand Up @@ -361,6 +362,38 @@ class TMXLevelLoaderTest {
assertThat(tileset.transparentcolor, `is`(""))
}

@Test
fun `Load tmx level with relative image source path`() {
// Relative Path check
val level = TMXLevelLoader().load(javaClass.getResource("relative_image_source.tmx"), GameWorld())
val levelImageChecksum = imageChecksum((level.entities[0].viewComponent.children[0] as ImageView).image)

// Validate that the Checksum strategy is legitimate
val levelIdem = TMXLevelLoader().load(javaClass.getResource("relative_image_source.tmx"), GameWorld())
val levelIdemChecksum = imageChecksum((levelIdem.entities[0].viewComponent.children[0] as ImageView).image)
assertEquals(levelImageChecksum, levelIdemChecksum)

// Standard none-relative Path check (uses the "same" image - different files, but it's the same image)
val levelValidator = TMXLevelLoader().load(javaClass.getResource("relative_image_source_validator.tmx"), GameWorld())
val levelValidatorChecksum = imageChecksum((levelValidator.entities[0].viewComponent.children[0] as ImageView).image)
assertEquals(levelImageChecksum, levelValidatorChecksum)

// Relative Path file doesn't exist - The checksum need to fail
val levelDummyImage = TMXLevelLoader().load(javaClass.getResource("relative_image_source_missing.tmx"), GameWorld())
val levelDummyImageChecksum = imageChecksum((levelDummyImage.entities[0].viewComponent.children[0] as ImageView).image)
assertNotEquals(levelImageChecksum, levelDummyImageChecksum)
}

fun imageChecksum(image: Image): Int {
var sum = 0
for (x in 0 until image.getWidth().toInt()) {
for (y in 0 until image.getHeight().toInt()) {
sum += image.getPixelReader().getArgb(x, y)
}
}
return sum
}

class MyEntityFactory : EntityFactory {

@Spawns("no_type,type1")
Expand Down Expand Up @@ -415,4 +448,5 @@ class TMXLevelLoaderTest {
return Entity().also { it.type = data.get("type") }
}
}

}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="40" height="30" tilewidth="20" tileheight="20" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" name="relative_image_source" tilewidth="20" tileheight="20" spacing="1" margin="1" tilecount="238" columns="17">
<image source="relative/image_source.png" trans="ffffff" width="358" height="295"/>
</tileset>
<layer id="1" name="Tile Layer 1" width="40" height="30">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,177,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,179,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,177,229,229,229,229,229,179,0,177,229,229,229,229,229,179,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,211,229,213,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,211,229,229,229,229,229,229,229,229,229,229,229,229,229,213,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,211,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,213,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="40" height="30" tilewidth="20" tileheight="20" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" name="relative_image_source_missing" tilewidth="20" tileheight="20" spacing="1" margin="1" tilecount="238" columns="17">
<image source="relative/missing.png" trans="ffffff" width="358" height="295"/>
</tileset>
<layer id="1" name="Tile Layer 1" width="40" height="30">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,177,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,179,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,177,229,229,229,229,229,179,0,177,229,229,229,229,229,179,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,211,229,213,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,211,229,229,229,229,229,229,229,229,229,229,229,229,229,213,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,211,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,213,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="40" height="30" tilewidth="20" tileheight="20" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" name="relative_image_source_missing" tilewidth="20" tileheight="20" spacing="1" margin="1" tilecount="238" columns="17">
<image source="image_source_validator.png" trans="ffffff" width="358" height="295"/>
</tileset>
<layer id="1" name="Tile Layer 1" width="40" height="30">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,177,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,179,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,177,229,229,229,229,229,179,0,177,229,229,229,229,229,179,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,211,229,213,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,211,229,229,229,229,229,229,229,229,229,229,229,229,229,213,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,228,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,211,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,213,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>

0 comments on commit f8853b4

Please sign in to comment.