From 5ca8a213cefd182f98b99f471d0c4118016cc3a8 Mon Sep 17 00:00:00 2001 From: Heather Kiefer Date: Tue, 2 Apr 2019 11:37:38 -0600 Subject: [PATCH] another fix for small font sheets --- .../halfdeadgames/kterminal/KTerminalData.kt | 4 +-- .../kterminal/KTerminalRenderer.kt | 35 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/com/halfdeadgames/kterminal/KTerminalData.kt b/src/com/halfdeadgames/kterminal/KTerminalData.kt index 278d2ae..7275161 100644 --- a/src/com/halfdeadgames/kterminal/KTerminalData.kt +++ b/src/com/halfdeadgames/kterminal/KTerminalData.kt @@ -33,7 +33,7 @@ class KTerminalData(width: Int, var terminal = Array(width) { Array(height) { - KTerminalGlyph(' ', defaultForegroundColor, defaultBackgroundColor) + KTerminalGlyph(0, defaultForegroundColor, defaultBackgroundColor) } } @@ -44,7 +44,7 @@ class KTerminalData(width: Int, terminal = Array(width) { Array(height) { - KTerminalGlyph(' ', defaultForegroundColor, defaultBackgroundColor) + KTerminalGlyph(0, defaultForegroundColor, defaultBackgroundColor) } } } diff --git a/src/com/halfdeadgames/kterminal/KTerminalRenderer.kt b/src/com/halfdeadgames/kterminal/KTerminalRenderer.kt index 01f8c16..09a38d0 100644 --- a/src/com/halfdeadgames/kterminal/KTerminalRenderer.kt +++ b/src/com/halfdeadgames/kterminal/KTerminalRenderer.kt @@ -35,13 +35,16 @@ class KTerminalRenderer(val batch: SpriteBatch, } private fun init(tilesetFile: String?, scale: Float = 1f) { - val tempTilesetFile = tilesetFile ?: "defaultKTerminalFontSheet.png" - if(tilesetFile == null) { columns = 16 rows = 17 } + val tempTilesetFile = tilesetFile ?: "defaultKTerminalFontSheet.png" + + println(tempTilesetFile) + + val pixmap = Pixmap(Gdx.files.internal(tempTilesetFile)) @@ -174,19 +177,23 @@ class KTerminalRenderer(val batch: SpriteBatch, val scaleX = if(glyph.isFlippedY) -glyph.scale else glyph.scale val scaleY = if(glyph.isFlippedX) -glyph.scale else glyph.scale - if(glyph.isSubCellEnabled) { - val topLeft = glyph.subCellGlyph.topLeft - val topRight = glyph.subCellGlyph.topRight - val bottomLeft = glyph.subCellGlyph.bottomLeft - val bottomRight = glyph.subCellGlyph.bottomRight - - draw(glyphs[topLeft.value], topLeft.color, glyph, i, j, scaleX, scaleY) - draw(glyphs[topRight.value], topRight.color, glyph, i, j, scaleX, scaleY) - draw(glyphs[bottomLeft.value], bottomLeft.color, glyph, i, j, scaleX, scaleY) - draw(glyphs[bottomRight.value], bottomRight.color, glyph, i, j, scaleX, scaleY) + if(glyph.value >= columns * rows) { + throw IllegalArgumentException("glyph value [${glyph.value}] exceeds found glyph count [${(columns * rows) - 1}]") + } else { + if(glyph.isSubCellEnabled) { + val topLeft = glyph.subCellGlyph.topLeft + val topRight = glyph.subCellGlyph.topRight + val bottomLeft = glyph.subCellGlyph.bottomLeft + val bottomRight = glyph.subCellGlyph.bottomRight + + draw(glyphs[topLeft.value], topLeft.color, glyph, i, j, scaleX, scaleY) + draw(glyphs[topRight.value], topRight.color, glyph, i, j, scaleX, scaleY) + draw(glyphs[bottomLeft.value], bottomLeft.color, glyph, i, j, scaleX, scaleY) + draw(glyphs[bottomRight.value], bottomRight.color, glyph, i, j, scaleX, scaleY) + } + + draw(glyphs[glyph.value], kTerminalData.terminal[i][j].foregroundColor, glyph, i, j, scaleX, scaleY) } - - draw(glyphs[glyph.value], kTerminalData.terminal[i][j].foregroundColor, glyph, i, j, scaleX, scaleY) } }