Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 13, 2024
1 parent 28f7e64 commit 7e1b3c9
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 130 deletions.
4 changes: 3 additions & 1 deletion changelog/1.10.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
- This is a bug fix version of 1.10.1

## Fix
- Fix concurrent issue in update.
- Fix concurrent issue in update.
- Change resource pack obfuscation.
- Fix big mistake in text manager :(
9 changes: 5 additions & 4 deletions dist/src/main/kotlin/kr/toxicity/hud/element/TextElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package kr.toxicity.hud.element

import kr.toxicity.hud.api.yaml.YamlObject
import kr.toxicity.hud.placeholder.ConditionSource
import kr.toxicity.hud.text.CharWidth
import kr.toxicity.hud.text.HudTextArray
import kr.toxicity.hud.text.ImageCharWidth
import kr.toxicity.hud.text.ImageTextScale
import kr.toxicity.hud.text.TextScale

class TextElement(
override val path: String,
override val name: String,
val scale: Int?,
val array: List<HudTextArray>,
val charWidth: Map<Int, CharWidth>,
val imageCharWidth: Map<Int, ImageCharWidth>,
val charWidth: Map<Int, TextScale>,
val imageTextScale: Map<Int, ImageTextScale>,
yamlObject: YamlObject
) : HudElement, ConditionSource by ConditionSource.Impl(yamlObject)
31 changes: 20 additions & 11 deletions dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ class HudTextParser(
loc.opacity,
text.property
)
val imageCodepointMap = text.imageCharMap.map {
it.value.name to it.key
}.toMap()
val scaledMap = text.source.charWidth.entries.associate { (k, v) ->
k to v * text.scale
}
val scaledImageMap = text.imageCharMap.entries.associate { (k, v) ->
k to v * text.scale * text.emoji.scale
}
val index2 = ++parent.textIndex
val keys = (0..<text.line).map { lineIndex ->
val yAxis = (loc.y + lineIndex * text.lineWidth).coerceAtLeast(-HUD_ADD_HEIGHT).coerceAtMost(HUD_ADD_HEIGHT)
Expand All @@ -58,18 +61,17 @@ class HudTextParser(
)
}
}
var textIndex = TEXT_IMAGE_START_CODEPOINT + text.imageCharMap.size
var textIndex = TEXT_IMAGE_START_CODEPOINT + scaledImageMap.size
val textEncoded = "hud_${parent.name}_text_${index2 + 1}_${lineIndex + 1}".encodeKey(EncodeManager.EncodeNamespace.FONT)
val key = createAdventureKey(textEncoded)
text.imageCharMap.forEach {
val height = (it.value.height.toDouble() * text.scale * text.emoji.scale * it.value.scale).roundToInt()
createAscent(shader, loc.y + it.value.location.y + lineIndex * text.lineWidth) { y ->
scaledImageMap.forEach { (k, v) ->
createAscent(shader, loc.y + v.location.y + lineIndex * text.lineWidth + v.ascent) { y ->
array += jsonObjectOf(
"type" to "bitmap",
"file" to it.value.fileName,
"file" to v.fileName,
"ascent" to y,
"height" to height,
"chars" to jsonArrayOf(it.key.parseChar())
"height" to v.normalizedHeight,
"chars" to jsonArrayOf(k.parseChar())
)
}
}
Expand Down Expand Up @@ -118,7 +120,14 @@ class HudTextParser(
text,
HudTextData(
keys,
imageCodepointMap,
scaledMap.entries.associate { (k, v) ->
k to v.normalizedWidth
} + scaledImageMap.entries.associate { (k, v) ->
k to v.normalizedWidth
},
scaledImageMap.map {
it.value.name to it.key
}.toMap(),
text.splitWidth,
),
loc.x
Expand Down
10 changes: 5 additions & 5 deletions dist/src/main/kotlin/kr/toxicity/hud/layout/TextLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kr.toxicity.hud.manager.TextManagerImpl
import kr.toxicity.hud.element.TextElement
import kr.toxicity.hud.shader.HudShader
import kr.toxicity.hud.shader.ShaderGroup
import kr.toxicity.hud.text.ImageCharWidth
import kr.toxicity.hud.text.ImageTextScale
import kr.toxicity.hud.util.*
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextColor
Expand All @@ -21,7 +21,7 @@ import java.text.DecimalFormat
interface TextLayout : HudLayout<TextElement> {

companion object {
private fun interface EmojiProvider : (TextLayout, () -> Int) -> Map<Int, ImageCharWidth>
private fun interface EmojiProvider : (TextLayout, () -> Int) -> Map<Int, ImageTextScale>
private val emojiProviderMap: List<EmojiProvider> = listOf(
EmojiProvider { layout, getter ->
if (ConfigManagerImpl.loadMinecraftDefaultTextures) {
Expand Down Expand Up @@ -105,7 +105,7 @@ interface TextLayout : HudLayout<TextElement> {
)
)

val imageCharMap: Map<Int, ImageCharWidth>
val imageCharMap: Map<Int, ImageTextScale>

class Impl(
s: String,
Expand Down Expand Up @@ -166,8 +166,8 @@ interface TextLayout : HudLayout<TextElement> {
if (this < 1) throw RuntimeException("split-width cannot be < 1: $s")
}
override val lineWidth = yamlObject.getAsInt("line-width", 10)
override val imageCharMap: Map<Int, ImageCharWidth> = run {
val map = source.imageCharWidth.toMutableMap()
override val imageCharMap: Map<Int, ImageTextScale> = run {
val map = source.imageTextScale.toMutableMap()
var baseValue = TEXT_IMAGE_START_CODEPOINT + map.size
val getter = {
++baseValue
Expand Down
16 changes: 8 additions & 8 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/MinecraftManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kr.toxicity.hud.manager

import kr.toxicity.hud.layout.TextLayout
import kr.toxicity.hud.resource.GlobalResource
import kr.toxicity.hud.text.ImageCharWidth
import kr.toxicity.hud.text.ImageTextScale
import kr.toxicity.hud.util.*
import net.kyori.adventure.audience.Audience
import java.io.File
Expand All @@ -20,23 +20,23 @@ object MinecraftManager : BetterHudManager {

private val assetsMap = Collections.synchronizedSet(HashSet<MinecraftAsset>())

fun applyAll(layout: TextLayout, intGetter: () -> Int): Map<Int, ImageCharWidth> {
val map = HashMap<Int, ImageCharWidth>()
fun applyAll(layout: TextLayout, intGetter: () -> Int): Map<Int, ImageTextScale> {
val map = HashMap<Int, ImageTextScale>()
assetsMap.forEach {
map[intGetter()] = it.toCharWidth(layout)
}
return map
}

private data class MinecraftAsset(val namespace: String, val width: Int, val height: Int) {
fun toCharWidth(layout: TextLayout): ImageCharWidth {
return ImageCharWidth(
fun toCharWidth(layout: TextLayout): ImageTextScale {
return ImageTextScale(
namespace.replace('/', '_'),
"minecraft:$namespace.png",
layout.emoji.location,
1.0,
width,
height
layout.source.scale?.let { it - height } ?: 0,
width.toDouble(),
height.toDouble()
)
}
}
Expand Down
Loading

0 comments on commit 7e1b3c9

Please sign in to comment.