Convert orx-shader-phrases and orx-noise to MPP

This commit is contained in:
Edwin Jakobs
2021-06-24 13:31:27 +02:00
parent 6a45db4491
commit 1cf5c825d6
69 changed files with 813 additions and 741 deletions

View File

@@ -0,0 +1,24 @@
package org.openrndr.extra.shaderphrases
import org.openrndr.resourceUrl
import java.net.URL
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
/**
* PhraseResource can be used as a delegate
*/
class PhraseResource<R>(private val resourceUrl: String) : ReadOnlyProperty<R, String> {
override fun getValue(thisRef: R, property: KProperty<*>): String {
return URL(resourceUrl).readText()
}
}
/**
*
* PhraseResource delegate builder function
*/
fun phraseResource(resource: String) : PhraseResource<Any?> {
return PhraseResource(resourceUrl(resource))
}

View File

@@ -0,0 +1,26 @@
package org.openrndr.extra.shaderphrases
import kotlin.reflect.KProperty1
import kotlin.reflect.full.declaredMemberProperties
/**
* A book of shader phrases.
*/
actual open class ShaderPhraseBook actual constructor(val bookId: String) {
private var registered = false
/**
* Registers all known shader phrases
*/
actual fun register() {
if (!registered) {
this::class.declaredMemberProperties.filter {
it.returnType.toString() == "org.openrndr.extra.shaderphrases.ShaderPhrase"
}.map {
@Suppress("UNCHECKED_CAST")
val m = it as? KProperty1<ShaderPhraseBook, ShaderPhrase>
m?.get(this)?.register(bookId)
}
registered = true
}
}
}