mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
new runes impl and test
Former-commit-id: f92f6d528128ed19aadffee7e112daa5736d50e3
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
out/*
|
out/*
|
||||||
bin/*
|
bin/*
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
.idea/workspace.xml
|
Thumbs.db
|
||||||
|
.DS_Store
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
56
src/net/torvald/imagefont/NewRunes.kt
Normal file
56
src/net/torvald/imagefont/NewRunes.kt
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package net.torvald.imagefont
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color
|
||||||
|
import org.newdawn.slick.Font
|
||||||
|
import org.newdawn.slick.SpriteSheet
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by SKYHi14 on 2017-03-24.
|
||||||
|
*/
|
||||||
|
class NewRunes : Font {
|
||||||
|
private val runeSize = 12
|
||||||
|
|
||||||
|
private val encPlane = IntArray(128, {
|
||||||
|
if (it < 0x10)
|
||||||
|
0x20 + it
|
||||||
|
else if (it < 0x30)
|
||||||
|
0x3000 + (it - 0x20)
|
||||||
|
else
|
||||||
|
0x3130 + (it - 0x30)
|
||||||
|
})
|
||||||
|
|
||||||
|
private fun codeToEnc(c: Char): Int? {
|
||||||
|
val result = encPlane.binarySearch(c.toInt())
|
||||||
|
return if (result >= 0) result else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private val runes = SpriteSheet("./assets/graphics/fonts/newrunes.tga", runeSize, runeSize)
|
||||||
|
|
||||||
|
var scale = 1
|
||||||
|
var linegap = 8
|
||||||
|
|
||||||
|
|
||||||
|
override fun getHeight(str: String) = 12
|
||||||
|
|
||||||
|
override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white)
|
||||||
|
|
||||||
|
override fun drawString(x: Float, y: Float, text: String, col: Color) {
|
||||||
|
text.forEachIndexed { index, c ->
|
||||||
|
val encodePoint = codeToEnc(c)
|
||||||
|
|
||||||
|
if (encodePoint != null) {
|
||||||
|
runes.getSubImage(encodePoint % 16, encodePoint / 16).draw(
|
||||||
|
x + runeSize * index * scale, y, scale.toFloat(), col
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) {
|
||||||
|
UnsupportedOperationException("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getWidth(str: String) = runeSize * str.length
|
||||||
|
|
||||||
|
override fun getLineHeight() = (runeSize + linegap) * scale
|
||||||
|
}
|
||||||
42
src/net/torvald/terrarum/StateNewRunesTest.kt
Normal file
42
src/net/torvald/terrarum/StateNewRunesTest.kt
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package net.torvald.terrarum
|
||||||
|
|
||||||
|
import net.torvald.imagefont.NewRunes
|
||||||
|
import org.newdawn.slick.*
|
||||||
|
import org.newdawn.slick.state.BasicGameState
|
||||||
|
import org.newdawn.slick.state.StateBasedGame
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by SKYHi14 on 2017-03-24.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class StateNewRunesTest : BasicGameState() {
|
||||||
|
|
||||||
|
lateinit var runes: NewRunes
|
||||||
|
|
||||||
|
override fun init(gc: GameContainer, game: StateBasedGame) {
|
||||||
|
runes = NewRunes()
|
||||||
|
runes.scale = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||||
|
|
||||||
|
g.background = Color(0x282828)
|
||||||
|
g.font = runes
|
||||||
|
g.color = Color(0x00c0f3)
|
||||||
|
|
||||||
|
val text = arrayOf(
|
||||||
|
"ㅎㅏㅣㄹㅏㄹㅍㅏㄴㅌㅏㅈㅣ",
|
||||||
|
"ㅈㅔㄹㄷㅏㅢㅈㅓㄴㅅㅓㄹ." // <<insert troll_face here>>
|
||||||
|
)
|
||||||
|
|
||||||
|
text.forEachIndexed { index, s ->
|
||||||
|
g.drawString(s, 30f, 30f + (runes.lineHeight * index))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getID(): Int = Terrarum.STATE_ID_TEST_FONT
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user