Skip to content

Commit

Permalink
Support combining Unicode.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Jan 4, 2025
1 parent 10d1421 commit c5763b5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 10 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion changelog/1.11.3.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# BetterHud 1.11.3

### Fix
- Fix mmocore skill reference.
- Fix mmocore skill reference.

### Add
- Add 'turkish' language.
- Support combining Unicode.
48 changes: 46 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/TextManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,24 @@ object TextManagerImpl : BetterHudManager, TextManager {
addAll(0x0985..0x09B9)
},
"thailand" to HashSet<Int>().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<Int>().apply {
addAll(0x0390..0x03CE)
Expand All @@ -108,6 +124,34 @@ object TextManagerImpl : BetterHudManager, TextManager {
},
"hebrew" to HashSet<Int>().apply {
addAll(0x05D0..0x05EA)
},
"turkish" to HashSet<Int>().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)
}
)

Expand Down
7 changes: 5 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/renderer/TextRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 21 additions & 5 deletions dist/src/main/kotlin/kr/toxicity/hud/util/Adventures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -126,13 +126,21 @@ 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<Style, Int>) -> Int?): List<WidthComponent> {
var i = 0
val list = ArrayList<WidthComponent>()
val topBuilder = SplitBuilder {
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()
Expand All @@ -156,15 +164,23 @@ fun Component.split(option: SplitOption, charWidth: (Pair<Style, Int>) -> 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
}
Expand Down

0 comments on commit c5763b5

Please sign in to comment.