Skip to content

Commit

Permalink
feat: text shadow support and adveture 4.18.0 bump
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 23, 2024
1 parent 9a89b7b commit f5348a9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
adventure = "4.17.0"
adventure = "4.18.0"
kotlin = "2.1.0"
ktlint = "1.0.1"
ktor = "3.0.1"
Expand Down
1 change: 1 addition & 0 deletions src/commonMain/resources/web/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
}
.mc-font {
font-family: "Minecraft", monospace;
text-shadow: 3px 3px hsl(0, 0%, 24%);
}
.mono-font {
font-family: monospace, monospace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.ktor.server.http.content.defaultResource
import io.ktor.server.http.content.resource
import io.ktor.server.http.content.resources
import io.ktor.server.http.content.static
import io.ktor.server.http.content.staticResources
import io.ktor.server.request.receiveText
import io.ktor.server.response.respondText
import io.ktor.server.routing.get
Expand Down Expand Up @@ -53,6 +54,7 @@ import net.kyori.adventure.webui.websocket.ParseResult
import net.kyori.adventure.webui.websocket.Placeholders
import net.kyori.adventure.webui.websocket.Response
import java.time.Instant
import net.kyori.adventure.webui.jvm.minimessage.hook.SHADOW_COLOR_RENDER_HOOK

private val startedAt = Instant.now()

Expand Down Expand Up @@ -87,6 +89,7 @@ public fun Application.miniMessage() {
component(INSERTION_RENDER_HOOK)
component(COMPONENT_CLASS_RENDER_HOOK)
component(TEXT_COLOR_RENDER_HOOK)
component(SHADOW_COLOR_RENDER_HOOK)
component(TEXT_DECORATION_RENDER_HOOK)
component(FONT_RENDER_HOOK)
component(TEXT_RENDER_HOOK, 500) // content needs to be set last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.html.classes
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TextComponent
import net.kyori.adventure.text.event.HoverEvent
import net.kyori.adventure.text.format.ShadowColor
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.webui.COMPONENT_CLASS
import net.kyori.adventure.webui.DATA_CLICK_EVENT_ACTION
Expand Down Expand Up @@ -56,16 +57,27 @@ public val COMPONENT_CLASS_RENDER_HOOK: ComponentRenderHook = { _ ->
public val TEXT_COLOR_RENDER_HOOK: ComponentRenderHook = { component ->
component.color()?.let { color ->
addStyle("color: ${color.asHexString()}")

val r = color.red() / 4.0
val g = color.green() / 4.0
val b = color.blue() / 4.0
addStyle("text-shadow: 3px 3px rgb($r, $g, $b)")
}

true
}

/** A render hook for text coloring and shadow. */
public val SHADOW_COLOR_RENDER_HOOK: ComponentRenderHook = { component ->
component.shadowColor()?.let { color ->
if (color == ShadowColor.none()) {
addStyle("text-shadow: initial")
} else {
val r = color.red()
val g = color.green()
val b = color.blue()
val a = color.alpha().toFloat() / (0xff).toFloat()
addStyle("text-shadow: 3px 3px rgb($r $g $b / $a)")
}
}

true
}
/** A render hook for text decoration. */
public val TEXT_DECORATION_RENDER_HOOK: ComponentRenderHook = { component ->
TextDecoration.NAMES.values().forEach { decoration ->
Expand Down

0 comments on commit f5348a9

Please sign in to comment.