Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LDtk level map view to korge 6.0.0-beta4 #6

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
java-version: '21'
distribution: 'zulu'
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[plugins]
korge = { id = "com.soywiz.korge", version = "5.0.5" }
korge = { id = "com.soywiz.korge", version = "6.0.0-beta4" }
#korge = { id = "com.soywiz.korge", version = "999.0.0.999" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class LDTKEntityView(

}

/**
* A view that represents a layer of a LDTK level map.
*/
class LDTKLayerView(
val llayer: LDTKLayer,
var showCollisions: Boolean = false
Expand All @@ -100,9 +103,16 @@ class LDTKLayerView(
val layerDef = world.layersDefsById[layer.layerDefUid]
val tilesetExt = world.tilesetDefsById[layer.tilesetDefUid]

val intGrid = IntArray2(layer.cWid, layer.cHei, layer.intGridCSV.copyOf(layer.cWid * layer.cHei))
val tileData = StackedIntArray2(layer.cWid, layer.cHei, -1)
val intGrid = TileMapData(width = layer.cWid, height = layer.cHei, tileSet = world.intsTileSet)
val tileData = TileMapData(
width = layer.cWid,
height = layer.cHei,
tileSet = if(tilesetExt?.tileset != null) tilesetExt.tileset else TileSet.EMPTY
)

/**
* Function to add all tiles from the layer to the tileMap view.
*/
fun addTiles() {
if (tilesetExt != null && layerDef != null) {
val tileset = tilesetExt.def
Expand All @@ -125,14 +135,14 @@ class LDTKLayerView(
val tileId = ty * cellsTilesPerRow + tx
val flipX = tile.f.hasBitSet(0)
val flipY = tile.f.hasBitSet(1)
tileData.push(x, y, TileInfo(tileId, flipX = flipX, flipY = flipY, offsetX = dx, offsetY = dy).data)
tileData.push(x, y, Tile(tile = tileId, offsetX = dx, offsetY = dy, flipX = flipX, flipY = flipY, rotate = false))
}
if (tilesetExt.tileset != null) {
tileMap(tileData, tilesetExt.tileset!!, smoothing = false)
tileMap(tileData, smoothing = false)
.alpha(layerDef.displayOpacity)
.also { if (!world.tilesetIsExtruded) it.filters(IdentityFilter.Nearest) }
.also { it.overdrawTiles = 1 }
tileMap(intGrid, world.intsTileSet, smoothing = false)
tileMap(intGrid, smoothing = false)
.visible(showCollisions)
.also { if (!world.tilesetIsExtruded) it.filters(IdentityFilter.Nearest) }
.also { it.overdrawTiles = 1 }
Expand Down
39 changes: 20 additions & 19 deletions src/commonMain/kotlin/MainLDTKSampleScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import korlibs.datastructure.StackedIntArray2
import korlibs.image.bitmap.slice
import korlibs.image.color.Colors
import korlibs.image.format.readBitmap
import korlibs.image.tiles.TileSet
import korlibs.image.tiles.*
import korlibs.io.file.std.resourcesVfs
import korlibs.korge.input.onMagnify
import korlibs.korge.input.onRotate
Expand All @@ -15,7 +15,6 @@ import korlibs.korge.tween.tween
import korlibs.korge.view.*
import korlibs.korge.view.filter.IdentityFilter
import korlibs.korge.view.filter.filters
import korlibs.korge.view.tiles.TileInfo
import korlibs.korge.view.tiles.tileMap
import korlibs.math.geom.Anchor
import korlibs.math.geom.ScaleMode
Expand Down Expand Up @@ -61,30 +60,32 @@ class MainLDTKSampleScene : PixelatedScene(SizeInt(1280, 720), sceneScaleMode =
val layerDef = layersDefsById[layer.layerDefUid] ?: continue
val tilesetExt = tilesetDefsById[layer.tilesetDefUid] ?: continue
val intGrid = IntArray2(layer.cWid, layer.cHei, layer.intGridCSV.copyOf(layer.cWid * layer.cHei))
val tileData = StackedIntArray2(layer.cWid, layer.cHei, -1)
val tileset = tilesetExt.def
val gridSize = tileset.tileGridSize

//val fsprites = FSprites(layer.autoLayerTiles.size)
//val view = fsprites.createView(bitmap).also { it.scale(2) }
//addChild(view)
for (tile in layer.autoLayerTiles) {
val (px, py) = tile.px
val (tileX, tileY) = tile.src
val x = px / gridSize
val y = py / gridSize
val dx = px % gridSize
val dy = py % gridSize
val tx = tileX / gridSize
val ty = tileY / gridSize
val cellsTilesPerRow = tileset.pxWid / gridSize
val tileId = ty * cellsTilesPerRow + tx
val flipX = tile.f.hasBitSet(0)
val flipY = tile.f.hasBitSet(1)
tileData.push(x, y, TileInfo(tileId, flipX = flipX, flipY = flipY, offsetX = dx, offsetY = dy).data)
}
if (tilesetExt.tileset != null) {
tileMap(tileData, tilesetExt.tileset).alpha(layerDef.displayOpacity)
val tileData = TileMapData(width = layer.cWid, height = layer.cHei, tileSet = tilesetExt.tileset)

for (tile in layer.autoLayerTiles) {
val (px, py) = tile.px
val (tileX, tileY) = tile.src
val x = px / gridSize
val y = py / gridSize
val dx = px % gridSize
val dy = py % gridSize
val tx = tileX / gridSize
val ty = tileY / gridSize
val cellsTilesPerRow = tileset.pxWid / gridSize
val tileId = ty * cellsTilesPerRow + tx
val flipX = tile.f.hasBitSet(0)
val flipY = tile.f.hasBitSet(1)
tileData.push(x, y, Tile(tileId, flipX = flipX, flipY = flipY, offsetX = dx, offsetY = dy, rotate = false))
}

tileMap(tileData).alpha(layerDef.displayOpacity)
}
//tileset!!.
//println(intGrid)
Expand Down
Loading