From c5763b535819ed4bfb15b2055c4695f962f58875 Mon Sep 17 00:00:00 2001 From: Yang Seong Mo Date: Sat, 4 Jan 2025 20:25:47 +0900 Subject: [PATCH] Support combining Unicode. --- build.gradle.kts | 6 +++ changelog/1.11.3.md | 6 ++- .../toxicity/hud/manager/TextManagerImpl.kt | 48 ++++++++++++++++++- .../kr/toxicity/hud/renderer/TextRenderer.kt | 7 ++- .../kotlin/kr/toxicity/hud/util/Adventures.kt | 26 ++++++++-- 5 files changed, 83 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 588e584d..be5ac446 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -407,6 +407,12 @@ tasks { version(minecraft) pluginJars(pluginJar.get().archiveFile) pluginJars(fileTree("plugins")) + downloadPlugins { + hangar("ViaVersion", "5.2.1") + hangar("ViaBackwards", "5.2.1") + hangar("PlaceholderAPI", "2.11.6") + hangar("Skript", "2.9.5") + } } build { finalizedBy(sourcesJar, javadocJar, pluginJar, velocityJar, fabricJar) diff --git a/changelog/1.11.3.md b/changelog/1.11.3.md index 37da65dd..45f568d5 100644 --- a/changelog/1.11.3.md +++ b/changelog/1.11.3.md @@ -1,4 +1,8 @@ # BetterHud 1.11.3 ### Fix -- Fix mmocore skill reference. \ No newline at end of file +- Fix mmocore skill reference. + +### Add +- Add 'turkish' language. +- Support combining Unicode. \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManagerImpl.kt index 3fce7510..d9048be8 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManagerImpl.kt @@ -90,8 +90,24 @@ object TextManagerImpl : BetterHudManager, TextManager { addAll(0x0985..0x09B9) }, "thailand" to HashSet().apply { - addAll(0x0E01..0x0E3A) - addAll(0x0E40..0x0E4E) + addAll(0x20..0x25) + addAll(0x27..0x3A) + addAll(0x3C..0x3E) + add(0x40) + addAll(0x5B..0x5F) + add(0x7C) + add(0xA0) + add(0xA9) + addAll(0xE01..0xE3A) + addAll(0xE40..0xE4E) + addAll(0x2010..0x2011) + addAll(0x2013..0x2014) + addAll(0x2018..0x2019) + addAll(0x201C..0x201D) + add(0x2026) + add(0x2030) + addAll(0x2032..0x2033) + add(0x20AC) }, "greece" to HashSet().apply { addAll(0x0390..0x03CE) @@ -108,6 +124,34 @@ object TextManagerImpl : BetterHudManager, TextManager { }, "hebrew" to HashSet().apply { addAll(0x05D0..0x05EA) + }, + "turkish" to HashSet().apply { + addAll(0x20..0x5F) + addAll(0x61..0x70) + addAll(0x72..0x76) + addAll(0x79..0x7A) + add(0x7C) + add(0xA0) + add(0xA7) + add(0xA9) + add(0xC7) + add(0xD6) + add(0xDC) + add(0xE7) + add(0xF6) + add(0xFC) + addAll(0x11E..0x11F) + addAll(0x130..0x131) + addAll(0x15E..0x15F) + addAll(0x2010..0x2011) + addAll(0x2013..0x2014) + addAll(0x2018..0x2019) + addAll(0x201C..0x201D) + addAll(0x2020..0x2021) + add(0x2026) + add(0x2030) + addAll(0x2032..0x2033) + add(0x20AC) } ) diff --git a/dist/src/main/kotlin/kr/toxicity/hud/renderer/TextRenderer.kt b/dist/src/main/kotlin/kr/toxicity/hud/renderer/TextRenderer.kt index 916f896d..a9833b6b 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/renderer/TextRenderer.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/renderer/TextRenderer.kt @@ -108,9 +108,12 @@ class TextRenderer( var build = EMPTY_WIDTH_COMPONENT.finalizeFont() if (it.x != 0) build += it.x.toSpaceComponent() - finalComp = build + WidthComponent(builder.append(it.right.component).font(backgroundKey.key), total) + minus.toSpaceComponent() + finalComp + build += WidthComponent(builder.append(it.right.component).font(backgroundKey.key), total) + if (max < build.width) max = build.width + finalComp = build + minus.toSpaceComponent() + finalComp + } ?: run { + if (max < finalComp.width) max = finalComp.width } - if (finalComp.width > max) max = finalComp.width widthComp = widthComp plusWithAlign finalComp } widthComp.applyColor(colorApply(targetHudPlayer)).toPixelComponent(when (align) { diff --git a/dist/src/main/kotlin/kr/toxicity/hud/util/Adventures.kt b/dist/src/main/kotlin/kr/toxicity/hud/util/Adventures.kt index 3a95af17..979a7794 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/util/Adventures.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/util/Adventures.kt @@ -93,13 +93,13 @@ private class SplitBuilder( var isClean = true private set fun accept(block: TextComponent.Builder.() -> Unit = {}) { - val build = builder.apply(block) + val build = if (isClean) builder.apply(block) else builder.append(Component.text().apply(block)) builder = Component.text() isClean = true chain(build) } fun build(block: TextComponent.Builder.() -> Unit = {}): TextComponent.Builder { - val build = builder.apply(block) + val build = if (isClean) builder.apply(block) else builder.append(Component.text().apply(block)) builder = Component.text() isClean = true return build @@ -126,6 +126,13 @@ data class SplitOption( val forceSplit: Boolean ) +private val COMBINE = sequenceOf( + Character.NON_SPACING_MARK, + Character.COMBINING_SPACING_MARK, +).map { + it.toInt() +}.toSet() + fun Component.split(option: SplitOption, charWidth: (Pair) -> Int?): List { var i = 0 val list = ArrayList() @@ -133,6 +140,7 @@ fun Component.split(option: SplitOption, charWidth: (Pair) -> Int?): list += WidthComponent(it, i) i = 0 } + val shouldApplySpace = option.space > 0 fun Component.parse(target: SplitBuilder, bold: Boolean, italic: Boolean) { if (this is TextComponent) { var style = style() @@ -156,15 +164,23 @@ fun Component.split(option: SplitOption, charWidth: (Pair) -> Int?): } sb.setLength(0) } + fun add(component: ComponentLike) { + subBuilder.append(Component.text(sb.toString())) + subBuilder.append(component) + sb.setLength(0) + } for (codepoint in content().codePoints()) { if ('\n'.code == codepoint) { end() continue } + val length = (if (codepoint == ' '.code) 4 else charWidth(style to codepoint) ?: continue) + add + val shouldCombine = COMBINE.contains(Character.getType(codepoint)) + if (shouldCombine) { + add((-length - (if (shouldApplySpace) option.space + add else 0)).toSpaceComponent().finalizeFont().component) + } else i += length sb.appendCodePoint(codepoint) - i += if (codepoint == ' '.code) 4 else charWidth(style to codepoint) ?: continue - i += add - if (option.space > 0) { + if (shouldApplySpace) { sb.appendCodePoint(TEXT_SPACE_KEY_CODEPOINT) i += option.space + add }