net.peanuuutz.fork.ui.inspection.Inspector.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fork-ui Show documentation
Show all versions of fork-ui Show documentation
Comprehensive API designed for Minecraft modders
The newest version!
package net.peanuuutz.fork.ui.inspection
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
interface Inspector {
fun push(phase: String)
fun push(inspectable: Inspectable) {
push(inspectable.name)
}
fun pop()
fun reset()
}
inline fun Inspector.inspect(
phase: String,
block: () -> R
): R {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
push(phase)
val result = block()
pop()
return result
}
inline fun Inspector.inspect(
inspectable: Inspectable,
block: () -> R
): R {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
push(inspectable)
val result = block()
pop()
return result
}
fun Inspector.swap(phase: String) {
pop()
push(phase)
}
fun Inspector.swap(inspectable: Inspectable) {
pop()
push(inspectable)
}
var debugInspector: Boolean = true