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

feat: text shadow support and adveture 4.18.0 bump #224

Merged
merged 2 commits into from
Jan 1, 2025
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
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
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -154,7 +155,7 @@
background-color: rgba(1, 1, 1, 0);
}
#output-pre.mode-hologram span {
text-shadow: none !important;
text-shadow: none;
}
#output-pre.mode-hologram > div {
background-color: rgba(1, 1, 1, 0.4);
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
Loading