diff --git a/modules/web-map/src/main/kotlin/dev/adamko/kafkatorio/webmap/layout/homePage.kt b/modules/web-map/src/main/kotlin/dev/adamko/kafkatorio/webmap/layout/homePage.kt
index 799dd7a..27fe4a4 100644
--- a/modules/web-map/src/main/kotlin/dev/adamko/kafkatorio/webmap/layout/homePage.kt
+++ b/modules/web-map/src/main/kotlin/dev/adamko/kafkatorio/webmap/layout/homePage.kt
@@ -1,113 +1,143 @@
package dev.adamko.kafkatorio.webmap.layout
+import dev.adamko.kafkatorio.schema.common.FactorioServerId
+import dev.adamko.kafkatorio.schema.common.MapSurface
+import dev.adamko.kafkatorio.webmap.services.EventsServerClient
import dev.adamko.kafkatorio.webmap.state.SiteState
import io.kvision.core.Container
-import io.kvision.html.ListType
import io.kvision.html.div
-import io.kvision.html.h5
-import io.kvision.html.li
+import io.kvision.html.h1
+import io.kvision.html.h2
+import io.kvision.html.h3
+import io.kvision.html.image
import io.kvision.html.link
-import io.kvision.html.listTag
import io.kvision.html.p
+import io.kvision.html.span
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.SupervisorJob
+import kotlinx.coroutines.launch
+
+
+private val homePageScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
fun Container.homePage(state: SiteState) {
div(className = "home-page") {
- introduction()
+ hero()
servers(state)
+ about()
}
}
-private fun Container.introduction() {
- div {
- h5("Introduction")
- // Kafkatorio
- p(
- """
- Kafkatorio is a platform used for creating
- Factorio mods that require communication with an external server.
- """.trimIndent(),
- rich = true,
- )
- p(
- """
- It was created to explore the possibilities of using
- Apache Kafka
- to process updates from a Factorio server.
- """.trimIndent(),
- rich = true,
- )
- p("To keep up to date on progress, check out:")
- listTag(ListType.UL) {
- link(
- label = "Factorio Mod Portal",
- url = "https://mods.factorio.com/mod/kafkatorio-events",
- target = "_blank"
- )
- link(
- label = "Factorio forum discussion",
- url = "https://forums.factorio.com/viewtopic.php?f=190&t=102841&p=570598#p570598",
- target = "_blank"
- )
+private fun Container.hero() {
+ div(className = "home-hero") {
+ image("/img/kafkatorio-logo.png", alt = "Kafkatorio logo", className = "home-hero-logo")
+ div {
+ h1("Kafkatorio")
+ p("Live maps of Factorio servers, streamed through Apache Kafka.", className = "home-hero-tagline")
}
- p(
- """
- Development is ongoing. Presently it used to create a live-updating web-map of a Factorio
- server.
- """.trimIndent(),
- rich = true,
- )
}
}
private fun Container.servers(state: SiteState) {
- div(className = "servers") {
- h5("Factorio Servers Live maps")
- if (state.serverIds != null) {
- p("View live-updating maps of the following Factorio servers")
- p("Available servers: ${state.serverIds.size}")
- listTag(ListType.UL) {
- state.serverIds.forEach { serverId ->
- li {
- div {
- link(
- label = "$serverId",
- url = "/servers/$serverId",
-// url = routing.link("servers/$serverId"),
- )
+ div(className = "home-section") {
+ h2("Servers")
+ val serverIds = state.serverIds
+ when {
+ serverIds == null -> p("Loading servers…", className = "home-muted")
+ serverIds.isEmpty() -> p("No servers are sending data yet.", className = "home-muted")
+ else -> div(className = "server-cards") {
+ serverIds.forEach { serverCard(it) }
+ }
+ }
+ }
+}
+
+
+private fun Container.serverCard(serverId: FactorioServerId) {
+ link(label = "", url = "/servers/${serverId.id}", className = "server-card") {
+ setAttribute("data-navigo", "true")
+
+ mapPreview(serverId)
+
+ div(className = "server-card-body") {
+ h3(serverId.id)
+ val surfaces = div(className = "server-card-surfaces") {
+ span("Loading surfaces…", className = "home-muted")
+ }
+ span("Open map →", className = "server-card-action")
+
+ homePageScope.launch {
+ val loaded = runCatching { EventsServerClient.surfaces(serverId) }.getOrNull()
+ surfaces.removeAll()
+ surfaces.surfaceChips(loaded)
+ }
+ }
+ }
+}
+
+
+private fun Container.surfaceChips(surfaces: List?) {
+ if (surfaces.isNullOrEmpty()) {
+ span("No map data yet", className = "home-muted")
+ return
+ }
+ surfaces.forEach { surface ->
+ span(surface.name.replaceFirstChar { it.uppercase() }, className = "surface-chip")
+ }
+}
+
+
+/**
+ * The centre of the map (1024x1024 Factorio tiles around the origin), from the lowest-zoom map
+ * tiles, with the resource and building layers on top of the terrain.
+ */
+private fun Container.mapPreview(serverId: FactorioServerId) {
+ div(className = "server-card-preview") {
+ PREVIEW_LAYERS.forEach { layer ->
+ div(className = "server-card-preview-layer") {
+ for (y in listOf(-1, 0)) {
+ for (x in listOf(-1, 0)) {
+ image(
+ "/kafkatorio/data/servers/${serverId.id}/map/layers/$layer/s1/z-1/x$x/y$y.png",
+ alt = "",
+ ) {
+ // hide missing tiles, instead of showing a broken image
+ setAttribute("onerror", "this.style.visibility='hidden'")
+ setAttribute("loading", "lazy")
}
}
}
}
-
-// div {
-// state.serverIds.forEach { serverId ->
-// div {
-// link(
-// label = "$serverId",
-// dataNavigo = true,
-// url = "/servers/$serverId",
-// ) {
-//// onClick {
-//// SiteRouting.serverView(serverId)
-//// }
-// }
-// }
-//
-// button(text = "$serverId", className = "btn btn-link") {
-// style = ButtonStyle.PRIMARY
-// size = ButtonSize.SMALL
-//
-// onClick {
-// SiteRouting.serverView(serverId)
-// }
-// }
-// }
-// }
- } else {
- div("no servers available")
}
}
}
+
+private val PREVIEW_LAYERS = listOf("terrain", "resource", "building")
+
+
+private fun Container.about() {
+ div(className = "home-section home-about") {
+ h2("About")
+ p(
+ """
+ Kafkatorio is a platform for Factorio mods that need to talk to an external server.
+ A Factorio mod
+ sends updates from the game to Apache Kafka,
+ where they're processed into the live maps on this site: terrain, resources, buildings and players,
+ on every planet and orbit.
+ """.trimIndent(),
+ rich = true,
+ )
+ p(
+ """
+ More on the Factorio forum
+ and on GitHub.
+ """.trimIndent(),
+ rich = true,
+ )
+ }
+}
diff --git a/modules/web-map/src/main/resources/css/kafkatorio.css b/modules/web-map/src/main/resources/css/kafkatorio.css
index dc6fd81..b3d4d61 100644
--- a/modules/web-map/src/main/resources/css/kafkatorio.css
+++ b/modules/web-map/src/main/resources/css/kafkatorio.css
@@ -1,3 +1,209 @@
+/* Site theme - dark, like Factorio's UI */
+:root {
+ --kt-bg: #1e1d1e;
+ --kt-panel: #2f2e2f;
+ --kt-panel-raised: #3a393a;
+ --kt-border: #4a494a;
+ --kt-text: #e8e6e3;
+ --kt-muted: #a09d99;
+ --kt-heading: #ffe6c0;
+ --kt-accent: #ff9f1b;
+ --kt-accent-hover: #ffb547;
+}
+
+body {
+ background: var(--kt-bg);
+ color: var(--kt-text);
+ font-family: "Titillium Web", system-ui, sans-serif;
+}
+
+a {
+ color: var(--kt-accent);
+}
+
+a:hover {
+ color: var(--kt-accent-hover);
+}
+
+header .navbar {
+ background: #141314 !important;
+ border-bottom: 2px solid var(--kt-accent);
+}
+
+header .navbar-brand,
+header .navbar-brand:hover {
+ color: var(--kt-heading);
+ font-weight: 700;
+ letter-spacing: 0.02em;
+}
+
+
+/* Home page */
+
+.home-page {
+ max-width: 1100px;
+ margin: 0 auto;
+ padding: 32px 0 48px;
+}
+
+.home-hero {
+ display: flex;
+ align-items: center;
+ gap: 24px;
+ padding: 24px 0 32px;
+}
+
+.home-hero-logo {
+ width: 96px;
+ height: 96px;
+ border-radius: 18px;
+ flex-shrink: 0;
+}
+
+.home-hero h1 {
+ margin: 0;
+ color: var(--kt-heading);
+ font-weight: 700;
+ font-size: 2.6rem;
+}
+
+.home-hero-tagline {
+ margin: 0;
+ color: var(--kt-muted);
+ font-size: 1.2rem;
+}
+
+.home-section {
+ margin-top: 24px;
+}
+
+.home-section h2 {
+ color: var(--kt-heading);
+ font-size: 1.4rem;
+ font-weight: 600;
+ border-bottom: 1px solid var(--kt-border);
+ padding-bottom: 6px;
+ margin-bottom: 16px;
+}
+
+.home-muted {
+ color: var(--kt-muted);
+}
+
+.home-about p {
+ max-width: 70ch;
+}
+
+.server-cards {
+ display: grid;
+ gap: 20px;
+}
+
+.server-card {
+ display: flex;
+ background: var(--kt-panel);
+ border: 1px solid var(--kt-border);
+ border-radius: 8px;
+ overflow: hidden;
+ color: var(--kt-text);
+ text-decoration: none;
+ transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
+}
+
+.server-card:hover {
+ color: var(--kt-text);
+ border-color: var(--kt-accent);
+ transform: translateY(-2px);
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
+}
+
+.server-card-preview {
+ position: relative;
+ width: 360px;
+ aspect-ratio: 1 / 1;
+ flex-shrink: 0;
+ background: #111;
+ overflow: hidden;
+}
+
+.server-card-preview-layer {
+ position: absolute;
+ inset: 0;
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ grid-template-rows: 1fr 1fr;
+}
+
+.server-card-preview-layer img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ image-rendering: pixelated;
+}
+
+.server-card-body {
+ display: flex;
+ flex-direction: column;
+ padding: 18px 22px;
+}
+
+.server-card-body h3 {
+ margin: 0 0 8px;
+ color: var(--kt-heading);
+ font-size: 1.3rem;
+ font-weight: 600;
+}
+
+.server-card-surfaces {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ margin-bottom: 12px;
+}
+
+.surface-chip {
+ background: var(--kt-panel-raised);
+ border: 1px solid var(--kt-border);
+ border-radius: 12px;
+ padding: 1px 10px;
+ font-size: 0.85rem;
+}
+
+.server-card-action {
+ margin-top: auto;
+ color: var(--kt-accent);
+ font-weight: 600;
+}
+
+@media (max-width: 700px) {
+ .server-card {
+ flex-direction: column;
+ }
+
+ .server-card-preview {
+ width: 100%;
+ }
+ .home-page {
+ padding: 16px 0 32px;
+ }
+
+ .home-hero {
+ gap: 16px;
+ }
+
+ .home-hero-logo {
+ width: 64px;
+ height: 64px;
+ }
+
+ .home-hero h1 {
+ font-size: 2rem;
+ }
+}
+
+
+/* Map */
+
.leaflet-tile {
/* https://github.com/Leaflet/Leaflet/issues/3575 */
/*width: 257px !important;*/
diff --git a/modules/web-map/src/main/web/index.html b/modules/web-map/src/main/web/index.html
index dc31aa7..64726d2 100644
--- a/modules/web-map/src/main/web/index.html
+++ b/modules/web-map/src/main/web/index.html
@@ -3,7 +3,10 @@
- Kafkatorio Web Map
+ Kafkatorio
+
+
+