more tiles stuff working...
This commit is contained in:
parent
a7a095ecbf
commit
6fe3132f23
8 changed files with 66 additions and 21 deletions
1
modules/events-server/.gitignore
vendored
1
modules/events-server/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
**/kafkatorio-web-map/**
|
|
||||||
|
|
@ -49,6 +49,7 @@ import org.apache.kafka.streams.TopologyDescription
|
||||||
import org.apache.kafka.streams.kstream.Consumed
|
import org.apache.kafka.streams.kstream.Consumed
|
||||||
import org.apache.kafka.streams.kstream.KStream
|
import org.apache.kafka.streams.kstream.KStream
|
||||||
import org.apache.kafka.streams.kstream.KTable
|
import org.apache.kafka.streams.kstream.KTable
|
||||||
|
import org.apache.kafka.streams.kstream.Suppressed
|
||||||
import org.apache.kafka.streams.processor.RecordContext
|
import org.apache.kafka.streams.processor.RecordContext
|
||||||
import org.apache.kafka.streams.state.QueryableStoreTypes
|
import org.apache.kafka.streams.state.QueryableStoreTypes
|
||||||
import org.apache.kafka.streams.state.ReadOnlyKeyValueStore
|
import org.apache.kafka.streams.state.ReadOnlyKeyValueStore
|
||||||
|
|
@ -219,14 +220,14 @@ class KafkatorioTopology(
|
||||||
"kafkatorio.${KafkatorioPacket.PacketType.EVENT}.${FactorioObjectData.ObjectName.LuaTiles}",
|
"kafkatorio.${KafkatorioPacket.PacketType.EVENT}.${FactorioObjectData.ObjectName.LuaTiles}",
|
||||||
Consumed.with(Serdes.String(), jsonMapper.serde<FactorioEvent>())
|
Consumed.with(Serdes.String(), jsonMapper.serde<FactorioEvent>())
|
||||||
)
|
)
|
||||||
.peek { k, v ->
|
// .peek { k, v ->
|
||||||
println("trying to handle MapChunk update... $k: ${v.eventType}")
|
// println("trying to handle MapChunk update... $k: ${v.eventType}")
|
||||||
}
|
// }
|
||||||
.filter("events.filter.map-tiles") { _: String, event: FactorioEvent -> event.data is MapTiles }
|
.filter("events.filter.map-tiles") { _: String, event: FactorioEvent -> event.data is MapTiles }
|
||||||
.mapValues("events.extract-map-tiles") { _, event: FactorioEvent -> (event.data as? MapTiles)!! }
|
.mapValues("events.extract-map-tiles") { _, event: FactorioEvent -> (event.data as? MapTiles)!! }
|
||||||
.peek { key, value ->
|
// .peek { key, value ->
|
||||||
println("MapChunk update $key, tiles count: ${value.tiles.size}")
|
// println("MapChunk update $key, tiles count: ${value.tiles.size}")
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
val chunkTilesUpdateStream: KStream<String, MapTiles> = builder.stream(
|
val chunkTilesUpdateStream: KStream<String, MapTiles> = builder.stream(
|
||||||
|
|
@ -262,7 +263,7 @@ class KafkatorioTopology(
|
||||||
luaTilesUpdatesStream
|
luaTilesUpdatesStream
|
||||||
.merge("luaTilesUpdatesStream-and-chunkTilesUpdateStream", chunkTilesUpdateStream)
|
.merge("luaTilesUpdatesStream-and-chunkTilesUpdateStream", chunkTilesUpdateStream)
|
||||||
.flatMapTopicRecords("all-tiles-convert-to-TileUpdateRecord") { _, mapTiles: MapTiles ->
|
.flatMapTopicRecords("all-tiles-convert-to-TileUpdateRecord") { _, mapTiles: MapTiles ->
|
||||||
println("all map tiles update ${mapTiles.tiles.size}")
|
// println("all map tiles update ${mapTiles.tiles.size}")
|
||||||
mapTiles.tiles.map { tile ->
|
mapTiles.tiles.map { tile ->
|
||||||
TileUpdateRecord(
|
TileUpdateRecord(
|
||||||
mapTiles.surfaceIndex,
|
mapTiles.surfaceIndex,
|
||||||
|
|
@ -288,6 +289,12 @@ class KafkatorioTopology(
|
||||||
.reduce { tileA, tileB ->
|
.reduce { tileA, tileB ->
|
||||||
tileA.copy(tiles = tileA.tiles + tileB.tiles)
|
tileA.copy(tiles = tileA.tiles + tileB.tiles)
|
||||||
}
|
}
|
||||||
|
.suppress(
|
||||||
|
Suppressed.untilTimeLimit(
|
||||||
|
Duration.ofSeconds(30),
|
||||||
|
Suppressed.BufferConfig.maxRecords(30)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
chunksTable
|
chunksTable
|
||||||
.toStream()
|
.toStream()
|
||||||
|
|
@ -302,7 +309,7 @@ class KafkatorioTopology(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("KotlinConstantConditions")
|
// @Suppress("KotlinConstantConditions")
|
||||||
private fun saveMapTilesPng(key: MapChunkDataPosition, chunk: MapChunkData) {
|
private fun saveMapTilesPng(key: MapChunkDataPosition, chunk: MapChunkData) {
|
||||||
|
|
||||||
val chunkOriginX = chunk.chunkPosition.position.leftTopTile.x
|
val chunkOriginX = chunk.chunkPosition.position.leftTopTile.x
|
||||||
|
|
@ -325,7 +332,10 @@ class KafkatorioTopology(
|
||||||
?.toHexadecimal()
|
?.toHexadecimal()
|
||||||
|
|
||||||
val rgbColour = when (prototypeColour) {
|
val rgbColour = when (prototypeColour) {
|
||||||
null -> RGBColor(11, 11, 11, 0)
|
null -> {
|
||||||
|
println("missing prototype: ${tile.prototypeName}")
|
||||||
|
RGBColor(11, 11, 11, 0)
|
||||||
|
}
|
||||||
else -> RGBColor(
|
else -> RGBColor(
|
||||||
prototypeColour.red.roundToInt(),
|
prototypeColour.red.roundToInt(),
|
||||||
prototypeColour.green.roundToInt(),
|
prototypeColour.green.roundToInt(),
|
||||||
|
|
@ -347,7 +357,7 @@ class KafkatorioTopology(
|
||||||
|
|
||||||
val zoom = 1u
|
val zoom = 1u
|
||||||
val file =
|
val file =
|
||||||
File("kafkatorio-web-map/s${key.surfaceIndex}/z$zoom/x${key.position.x}/y${key.position.y}.png")
|
File("src/main/resources/kafkatorio-web-map/s${key.surfaceIndex}/z$zoom/x${key.position.x}/y${key.position.y}.png")
|
||||||
|
|
||||||
if (file.parentFile.mkdirs()) {
|
if (file.parentFile.mkdirs()) {
|
||||||
println("created new map tile parentFile directory ${file.absolutePath}")
|
println("created new map tile parentFile directory ${file.absolutePath}")
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import org.http4k.routing.bind
|
||||||
import org.http4k.routing.websockets
|
import org.http4k.routing.websockets
|
||||||
import org.http4k.server.PolyHandler
|
import org.http4k.server.PolyHandler
|
||||||
import org.http4k.websocket.Websocket
|
import org.http4k.websocket.Websocket
|
||||||
|
import org.http4k.websocket.WsHandler
|
||||||
import org.http4k.websocket.WsMessage
|
import org.http4k.websocket.WsMessage
|
||||||
import org.http4k.websocket.WsStatus
|
import org.http4k.websocket.WsStatus
|
||||||
|
|
||||||
|
|
@ -47,7 +48,7 @@ class WebsocketServer {
|
||||||
messages.emit(msg)
|
messages.emit(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun build(): PolyHandler = supervisorScope builder@{
|
suspend fun build(): WsHandler = supervisorScope builder@{
|
||||||
|
|
||||||
coroutineContext.job.invokeOnCompletion { e ->
|
coroutineContext.job.invokeOnCompletion { e ->
|
||||||
e?.let { serverJob.completeExceptionally(it) } ?: serverJob.complete()
|
e?.let { serverJob.completeExceptionally(it) } ?: serverJob.complete()
|
||||||
|
|
@ -89,10 +90,8 @@ class WebsocketServer {
|
||||||
}
|
}
|
||||||
.launchIn(serverScope)
|
.launchIn(serverScope)
|
||||||
|
|
||||||
val http = { _: Request -> Response(OK) }
|
|
||||||
val ws = websockets("/ws" bind ::bindClient)
|
|
||||||
|
|
||||||
return@builder PolyHandler(http, ws)
|
return@builder websockets("/ws" bind ::bindClient)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package dev.adamko.kafkatorio.processor
|
||||||
|
|
||||||
|
|
||||||
import dev.adamko.kafkatorio.processor.config.ApplicationProperties
|
import dev.adamko.kafkatorio.processor.config.ApplicationProperties
|
||||||
|
import dev.adamko.kafkatorio.processor.tileserver.WebMapTileServer
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.http4k.server.PolyHandler
|
||||||
import org.http4k.server.Undertow
|
import org.http4k.server.Undertow
|
||||||
import org.http4k.server.asServer
|
import org.http4k.server.asServer
|
||||||
|
|
||||||
|
|
@ -11,10 +13,16 @@ val appProps = ApplicationProperties()
|
||||||
fun main() = runBlocking {
|
fun main() = runBlocking {
|
||||||
|
|
||||||
val wsServer = WebsocketServer()
|
val wsServer = WebsocketServer()
|
||||||
|
val tileServer = WebMapTileServer()
|
||||||
|
|
||||||
val topology = KafkatorioTopology(wsServer)
|
val topology = KafkatorioTopology(wsServer)
|
||||||
topology.build()
|
topology.build()
|
||||||
|
|
||||||
wsServer.build().asServer(Undertow(9073)).start().block()
|
PolyHandler(
|
||||||
|
tileServer.build(),
|
||||||
|
wsServer.build(),
|
||||||
|
).asServer(Undertow(9073))
|
||||||
|
.start()
|
||||||
|
.block()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package dev.adamko.kafkatorio.processor.tileserver
|
||||||
|
|
||||||
|
import org.http4k.core.HttpHandler
|
||||||
|
import org.http4k.routing.ResourceLoader
|
||||||
|
import org.http4k.routing.RoutingHttpHandler
|
||||||
|
import org.http4k.routing.bind
|
||||||
|
import org.http4k.routing.routes
|
||||||
|
import org.http4k.routing.static
|
||||||
|
|
||||||
|
class WebMapTileServer {
|
||||||
|
|
||||||
|
private val routes: RoutingHttpHandler = routes(
|
||||||
|
"/tiles" bind static(ResourceLoader.Classpath("/kafkatorio-web-map"))
|
||||||
|
)
|
||||||
|
|
||||||
|
fun build(): HttpHandler {
|
||||||
|
return routes
|
||||||
|
}
|
||||||
|
}
|
||||||
1
modules/events-server/src/main/resources/.gitignore
vendored
Normal file
1
modules/events-server/src/main/resources/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
kafkatorio-web-map/**
|
||||||
|
|
@ -5,13 +5,13 @@
|
||||||
<!-- encoders are assigned the type
|
<!-- encoders are assigned the type
|
||||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n
|
<pattern>%cyan(%d{HH:mm:ss.SSS}) %white([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n
|
||||||
</pattern>
|
</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<logger name="org.apache.kafka" level="info" additivity="false">
|
<logger name="org.apache.kafka" level="info" additivity="false">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<root level="info">
|
<root level="info">
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package dev.adamko.kafkatorio.webmap
|
package dev.adamko.kafkatorio.webmap
|
||||||
|
|
||||||
|
import io.kvision.maps.DefaultTileLayers
|
||||||
import io.kvision.maps.externals.leaflet.geo.CRS
|
import io.kvision.maps.externals.leaflet.geo.CRS
|
||||||
import io.kvision.maps.externals.leaflet.geo.LatLng
|
import io.kvision.maps.externals.leaflet.geo.LatLng
|
||||||
import io.kvision.maps.Maps
|
import io.kvision.maps.Maps
|
||||||
|
import io.kvision.maps.Maps.Companion.L
|
||||||
import io.kvision.utils.px
|
import io.kvision.utils.px
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -24,9 +26,16 @@ fun createFactorioMap() = Maps {
|
||||||
margin = 10.px
|
margin = 10.px
|
||||||
|
|
||||||
configureLeafletMap {
|
configureLeafletMap {
|
||||||
setView(LatLng(0, 0), 13)
|
setView(LatLng(0, 0), 1)
|
||||||
|
|
||||||
// DefaultTileLayers.OpenStreetMap.addTo(this)
|
// DefaultTileLayers.OpenStreetMap.addTo(this)
|
||||||
|
L.tileLayer(
|
||||||
|
"""http://localhost:9073/tiles/s1/z1/x{x}/y{y}.png"""
|
||||||
|
) {
|
||||||
|
attribution = "kafkatorio"
|
||||||
|
tms = true
|
||||||
|
minZoom = 1
|
||||||
|
}.addTo(this)
|
||||||
|
|
||||||
with(options) {
|
with(options) {
|
||||||
crs = CRS.Simple
|
crs = CRS.Simple
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue