Add Olive.scriptLoaded event
This commit is contained in:
@@ -1,9 +1,25 @@
|
||||
sourceSets {
|
||||
demo {
|
||||
java {
|
||||
srcDirs = ["src/demo/kotlin"]
|
||||
compileClasspath += main.getCompileClasspath()
|
||||
runtimeClasspath += main.getRuntimeClasspath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":orx-file-watcher")
|
||||
|
||||
// -- JSR 223, old style script loader
|
||||
implementation "org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion"
|
||||
implementation "org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlinVersion"
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
||||
implementation "org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion"
|
||||
|
||||
demoImplementation(project(":orx-camera"))
|
||||
demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
demoImplementation(sourceSets.getByName("main").output)
|
||||
}
|
||||
34
orx-olive/src/demo/kotlin/DemoOlive01.kt
Normal file
34
orx-olive/src/demo/kotlin/DemoOlive01.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
import org.openrndr.Extension
|
||||
import org.openrndr.Program
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.olive.Olive
|
||||
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 768
|
||||
height = 576
|
||||
}
|
||||
program {
|
||||
|
||||
extend(Olive<Program>()) {
|
||||
script = "orx-olive/src/demo/kotlin/demo-olive-01.kts"
|
||||
|
||||
// -- this block is for automation purposes only
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
scriptLoaded.listen {
|
||||
// -- this is a bit of hack, we need to push the screenshot extension in front of the olive one
|
||||
fun <T : Extension> Program.extendHead(extension: T, configure: T.() -> Unit): T {
|
||||
extensions.add(0, extension)
|
||||
extension.configure()
|
||||
extension.setup(this)
|
||||
return extension
|
||||
}
|
||||
extendHead(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
orx-olive/src/demo/kotlin/demo-olive-01.kts
Normal file
14
orx-olive/src/demo/kotlin/demo-olive-01.kts
Normal file
@@ -0,0 +1,14 @@
|
||||
@file:Suppress("UNUSED_LAMBDA_EXPRESSION")
|
||||
import org.openrndr.Program
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
|
||||
{ program: Program ->
|
||||
program.apply {
|
||||
extend {
|
||||
drawer.background(ColorRGBa.GRAY)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.circle(width/2.0, height/2.0 ,200.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,11 +31,15 @@ enum class OliveScriptHost {
|
||||
KOTLIN_SCRIPT
|
||||
}
|
||||
|
||||
data class ScriptLoadedEvent(val scriptFile: String)
|
||||
|
||||
class Olive<P : Program>(val resources: Resources? = null) : Extension {
|
||||
override var enabled: Boolean = true
|
||||
var session: Session? = null
|
||||
var scriptHost = OliveScriptHost.JSR223_REUSE
|
||||
|
||||
val scriptLoaded = Event<ScriptLoadedEvent>()
|
||||
|
||||
internal var scriptChange: (String) -> Unit = {}
|
||||
|
||||
var script = "src/main/kotlin/live.kts"
|
||||
@@ -131,7 +135,7 @@ class Olive<P : Program>(val resources: Resources? = null) : Extension {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
func(program as P)
|
||||
|
||||
scriptLoaded.trigger(ScriptLoadedEvent(scriptFile))
|
||||
Unit
|
||||
}
|
||||
Unit
|
||||
|
||||
Reference in New Issue
Block a user