diff --git a/FontTestGDX/src/FontTestGDX.kt b/FontTestGDX/src/FontTestGDX.kt index 87a7c57..17e1f08 100644 --- a/FontTestGDX/src/FontTestGDX.kt +++ b/FontTestGDX/src/FontTestGDX.kt @@ -27,7 +27,7 @@ class FontTestGDX : Game() { private val outimageName = "demo.png" override fun create() { - font = GameFontBase("./assets", flipY = false, errorOnUnknownChar = false) // must test for two flipY cases + font = GameFontBase("./assets", flipY = false, errorOnUnknownChar = true) // must test for two flipY cases val inTextFile = Gdx.files.internal("./$demotextName") val reader = inTextFile.reader("UTF-8") diff --git a/assets/hayeren_variable.tga b/assets/hayeren_variable.tga index 9764076..cf34689 100644 Binary files a/assets/hayeren_variable.tga and b/assets/hayeren_variable.tga differ diff --git a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt index ea2d756..81eb6bd 100644 --- a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt @@ -386,6 +386,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo val isVariable1 = it.endsWith("_variable.tga") val isVariable2 = variableWidthSheets.contains(index) val isVariable = isVariable1 && isVariable2 + val isXYSwapped = it.contains("xyswap", true) // idiocity check if (isVariable1 && !isVariable2) @@ -442,7 +443,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo val texture = Texture(pixmap) val texRegPack = if (isVariable) { - TextureRegionPack(texture, W_VAR_INIT, H, HGAP_VAR, 0) + TextureRegionPack(texture, W_VAR_INIT, H, HGAP_VAR, 0, xySwapped = isXYSwapped) } else if (index == SHEET_UNIHAN) { TextureRegionPack(texture, W_UNIHAN, H_UNIHAN) // the only exception that is height is 16 @@ -592,8 +593,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo charsetOverride = c - CHARSET_OVERRIDE_DEFAULT } else if (sheetID == SHEET_HANGUL) { - // FIXME input text is normalised as Initial-Peak-Final - // requires lookahead for {I, P, F} + // Flookahead for {I, P, F} val cNext = if (index + 1 <= textBuffer.size) textBuffer[index + 1] else 0 val cNextNext = if (index + 2 <= textBuffer.size) textBuffer[index + 2] else 0 @@ -607,12 +607,12 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo val hangulSheet = sheets[SHEET_HANGUL] - println("${c.toHex()} ${cNext.toHex()} ${cNextNext.toHex()}") - println("I: $indexCho,\t$choRow") - println("P: $indexJung,\t$jungRow") - println("F: $indexJong,\t$jongRow") - println("skip: $hangulLength") - println("====") + //println("${c.toHex()} ${cNext.toHex()} ${cNextNext.toHex()}") + //println("I: $indexCho,\t$choRow") + //println("P: $indexJung,\t$jungRow") + //println("F: $indexJong,\t$jongRow") + //println("skip: $hangulLength") + //println("====") when (run) { diff --git a/src/net/torvald/terrarumsansbitmap/gdx/TextureRegionPack.kt b/src/net/torvald/terrarumsansbitmap/gdx/TextureRegionPack.kt index f7675a9..3713636 100644 --- a/src/net/torvald/terrarumsansbitmap/gdx/TextureRegionPack.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/TextureRegionPack.kt @@ -38,13 +38,14 @@ class TextureRegionPack( val hGap: Int = 0, val vGap: Int = 0, val hFrame: Int = 0, - val vFrame: Int = 0 + val vFrame: Int = 0, + val xySwapped: Boolean = false // because Unicode chart does, duh ) { - constructor(ref: String, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0) : - this(Texture(ref), tileW, tileH, hGap, vGap, hFrame, vFrame) - constructor(fileHandle: FileHandle, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0) : - this(Texture(fileHandle), tileW, tileH, hGap, vGap, hFrame, vFrame) + constructor(ref: String, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0, xySwapped: Boolean = false) : + this(Texture(ref), tileW, tileH, hGap, vGap, hFrame, vFrame, xySwapped) + constructor(fileHandle: FileHandle, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0, xySwapped: Boolean = false) : + this(Texture(fileHandle), tileW, tileH, hGap, vGap, hFrame, vFrame, xySwapped) companion object { /** Intented for Y-down coord system, typically fon Non-GDX codebase */ @@ -59,18 +60,34 @@ class TextureRegionPack( init { //println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH") - regions = Array(horizontalCount * verticalCount, { - val region = TextureRegion() - val rx = (it % horizontalCount * (tileW + hGap)) + hFrame - val ry = (it / horizontalCount * (tileH + vGap)) + vFrame + if (!xySwapped) { + regions = Array(horizontalCount * verticalCount, { + val region = TextureRegion() + val rx = (it % horizontalCount * (tileW + hGap)) + hFrame + val ry = (it / horizontalCount * (tileH + vGap)) + vFrame - region.setRegion(texture) - region.setRegion(rx, ry, tileW, tileH) + region.setRegion(texture) + region.setRegion(rx, ry, tileW, tileH) - region.flip(false, globalFlipY) + region.flip(false, globalFlipY) - /*return*/region - }) + /*return*/region + }) + } + else { + regions = Array(horizontalCount * verticalCount, { + val region = TextureRegion() + val rx = (it % verticalCount * (tileW + hGap)) + hFrame + val ry = (it / verticalCount * (tileH + vGap)) + vFrame + + region.setRegion(texture) + region.setRegion(ry, rx, tileW, tileH) + + region.flip(false, globalFlipY) + + /*return*/region + }) + } } fun get(x: Int, y: Int) = regions[y * horizontalCount + x]