generated from rnentjes/kotlin-server-web-undertow
Refactor PlatformSpecific, update MonTanaMiniComputer and MTMCDisplay logic, add splash screen rendering with SplashData, and optimize observer calls and color initialization.
This commit is contained in:
@@ -18,13 +18,8 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
LIGHT(87, 124, 68),
|
||||
LIGHTEST(127, 134, 15);
|
||||
|
||||
val intVal: Int
|
||||
val javaColor: Color
|
||||
|
||||
init {
|
||||
this.intVal = 0xFF shl 24 or (r shl 16) or (g shl 8) or b
|
||||
javaColor = Color(r, g, b)
|
||||
}
|
||||
val intVal: Int = 0xFF shl 24 or (r shl 16) or (g shl 8) or b
|
||||
val javaColor: Color = Color(r, g, b)
|
||||
|
||||
fun distance(r: Int, g: Int, b: Int): Int {
|
||||
val dr = this.r - r
|
||||
@@ -56,15 +51,20 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
}
|
||||
|
||||
private fun loadSplashScreen() {
|
||||
/* try {
|
||||
val bytes: ByteArray = Base64.getDecoder().decode(SPLASH_SCREEN)
|
||||
val bais = ByteArrayInputStream(bytes)
|
||||
var img: BufferedImage? = null
|
||||
img = ImageIO.read(bais)
|
||||
loadScaledImage(img)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}*/
|
||||
currentColor = DisplayColor.DARK
|
||||
var currentColorCount = 0
|
||||
var currentColor = 0
|
||||
var colorIndex = 0
|
||||
for (col in 0..<COLS) {
|
||||
for (row in 0..<ROWS) {
|
||||
if (currentColorCount == 0) {
|
||||
currentColorCount = SPLASH_SCREEN_COLORS[colorIndex++]
|
||||
currentColor = SPLASH_SCREEN_COLORS[colorIndex++]
|
||||
}
|
||||
setPixel(col, row, DisplayColor.entries[currentColor])
|
||||
currentColorCount--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadImage(data: ByteArray): BufferedImage? {
|
||||
@@ -107,7 +107,11 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
}
|
||||
|
||||
fun setPixel(col: Int, row: Int, color: DisplayColor) {
|
||||
buffer.setRGB(col, row, color.intVal)
|
||||
try {
|
||||
buffer.setRGB(col, row, color.intVal)
|
||||
} catch (e: Throwable) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
fun getPixel(col: Int, row: Int): Short {
|
||||
@@ -173,7 +177,7 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
//computer.notifyOfDisplayUpdate()
|
||||
}
|
||||
|
||||
fun toPng(): ByteArray? {
|
||||
fun toPng(): ByteArray {
|
||||
return byteArray
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user