From d3da4a33c6388f6b9eb2498d00221a81c98f721f Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 12 Jun 2023 15:08:29 +0900 Subject: [PATCH] reflection function update --- tsvm_core/src/net/torvald/reflection/Reflection.kt | 8 ++++---- tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt | 8 ++++---- tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tsvm_core/src/net/torvald/reflection/Reflection.kt b/tsvm_core/src/net/torvald/reflection/Reflection.kt index 919c811..3733baf 100644 --- a/tsvm_core/src/net/torvald/reflection/Reflection.kt +++ b/tsvm_core/src/net/torvald/reflection/Reflection.kt @@ -3,15 +3,15 @@ package net.torvald.reflection /** * Created by minjaesong on 2023-03-25. */ -fun Any.extortField(name: String): Any? { // yes I'm deliberately using negative words for the function name +inline fun Any.extortField(name: String): T? { // yes I'm deliberately using negative words for the function name return this.javaClass.getDeclaredField(name).let { it.isAccessible = true - it.get(this) + it.get(this) as T? } } -fun Any.forceInvoke(name: String, params: Array): Any? { // yes I'm deliberately using negative words for the function name +inline fun Any.forceInvoke(name: String, params: Array): T? { // yes I'm deliberately using negative words for the function name return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let { it.isAccessible = true - it.invoke(this, *params) + it.invoke(this, *params) as T? } } \ No newline at end of file diff --git a/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt b/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt index eb598f0..7d3d42e 100644 --- a/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt +++ b/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt @@ -48,7 +48,7 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe for (i in 0..3) { batch.fillRect(7, 5 + 115*i, 102, 8*FONT.H + 4) } } for (i in 0..3) { - val ahead = (adev.extortField("playheads") as Array)[i] + val ahead = adev.extortField>("playheads")!![i] drawStatusLCD(adev, ahead, batch, i, 9f + 7, 7f + 7 + 115 * i) } @@ -59,7 +59,7 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe for (i in 0..3) { batch.fillRect(117, 5 + 115*i, 512, 8*FONT.H + 4) } } for (i in 0..3) { - val ahead = (adev.extortField("playheads") as Array)[i] + val ahead = adev.extortField>("playheads")!![i] drawSoundscope(adev, ahead, batch, i, 117f, 5f + 115 * i) } } @@ -127,8 +127,8 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe private fun drawSoundscope(audio: AudioAdapter, ahead: AudioAdapter.Playhead, batch: SpriteBatch, index: Int, x: Float, y: Float) { val gdxadev = ahead.audioDevice - val bytes = gdxadev.extortField("bytes") as ByteArray? - val bytesLen = gdxadev.extortField("bytesLength") as Int + val bytes = gdxadev.extortField("bytes") + val bytesLen = gdxadev.extortField("bytesLength")!! val envelopeHalfHeight = 27 batch.inUse { diff --git a/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt b/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt index df011fe..077cfc0 100644 --- a/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt +++ b/tsvm_executable/src/net/torvald/tsvm/TevdMenu.kt @@ -28,7 +28,7 @@ class TevdMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMen if (dev?.javaClass?.simpleName == "TevdDiskDrive") { val dev = dev as TevdDiskDrive - val DOM = dev.extortField("DOM") as PartialDOM + val DOM = dev.extortField("DOM") batch.inUse { batch.color = Color.WHITE