From cce17237a408a44339d4301ea7664ab87edbdf26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 11 Apr 2024 11:41:53 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Add=20HTML=20output=20to=20game?= =?utf8?q?=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../filters/webpages/epicgames/FreeGamesState.kt | 62 ++++++++++++++++++++-- .../webpages/epicgames/FreeGamesStateTest.kt | 60 +++++++++++++++++++++ 2 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 src/test/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesStateTest.kt diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesState.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesState.kt index 580f0b4..47a78fd 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesState.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesState.kt @@ -1,12 +1,66 @@ package net.pterodactylus.rhynodge.filters.webpages.epicgames +import kotlinx.html.body +import kotlinx.html.div +import kotlinx.html.dom.createHTMLDocument +import kotlinx.html.dom.serialize +import kotlinx.html.head +import kotlinx.html.html +import kotlinx.html.img +import kotlinx.html.style +import kotlinx.html.unsafe import net.pterodactylus.rhynodge.states.AbstractState +import java.time.ZoneId +import java.util.Comparator.comparing -class FreeGamesState(val games: Set, private val triggered: Boolean = false) : AbstractState(true) { +class FreeGamesState(val games: Set, private val triggered: Boolean = false, private val timezone: ZoneId = ZoneId.systemDefault()) : AbstractState(true) { - override fun plainText(): String { - TODO("Not yet implemented") - } + override fun plainText() = games + .sortedWith(comparing(FreeGame::startDate).thenBy(FreeGame::title)) + .joinToString("\n") { game -> + "${game.title}: ${"%tF % + div("game") { + div("game-image") { + img(src = game.imageUrl) + } + div("game-title") { + +game.title + } + div("game-start") { + +"%tF %