[orx-parameters, orx-property-watchers, orx-file-watcher, orx-gui] Add @PathParameter, file watcher delegates and property delegates
This commit is contained in:
@@ -12,32 +12,33 @@ fun main() {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
oliveProgram(scriptHost = OliveScriptHost.JSR223) {
|
||||
oliveProgram(scriptHost = OliveScriptHost.JSR223_REUSE) {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.GRAY)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
for (i in 0 until 100) {
|
||||
drawer.circle(
|
||||
width / 2.0 + cos(seconds + i) * 320.0,
|
||||
i * 7.2,
|
||||
cos(i + seconds * 0.5) * 20.0 + 20.0)
|
||||
width / 2.0 + cos(seconds + i) * 320.0,
|
||||
i * 7.2,
|
||||
cos(i + seconds * 0.5) * 20.0 + 20.0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// -- this is only needed for the automated screenshots
|
||||
.olive.scriptLoaded.listen {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
// -- this is a bit of hack, we need to push the screenshot extension in front of the olive one
|
||||
fun <T : Extension> extendHead(extension: T, configure: T.() -> Unit): T {
|
||||
program.extensions.add(0, extension)
|
||||
extension.configure()
|
||||
extension.setup(program)
|
||||
return extension
|
||||
}
|
||||
extendHead(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
// -- this is only needed for the automated screenshots
|
||||
.olive.scriptLoaded.listen {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
// -- this is a bit of hack, we need to push the screenshot extension in front of the olive one
|
||||
fun <T : Extension> extendHead(extension: T, configure: T.() -> Unit): T {
|
||||
program.extensions.add(0, extension)
|
||||
extension.configure()
|
||||
extension.setup(program)
|
||||
return extension
|
||||
}
|
||||
extendHead(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,6 @@ import org.openrndr.events.Event
|
||||
import org.openrndr.exceptions.stackRootClassName
|
||||
import org.openrndr.extra.kotlinparser.extractProgram
|
||||
import org.openrndr.launch
|
||||
import org.openrndr.extra.filewatcher.stop
|
||||
import org.openrndr.extra.filewatcher.triggerChange
|
||||
import org.openrndr.extra.filewatcher.watchFile
|
||||
import java.io.File
|
||||
|
||||
@@ -63,9 +61,14 @@ class Olive<P : Program>(val resources: Resources? = null, private var scriptMod
|
||||
* reloads the active script
|
||||
*/
|
||||
fun reload() {
|
||||
watcher?.triggerChange()
|
||||
// watcher?.triggerChange()
|
||||
}
|
||||
|
||||
class ScriptWatcher
|
||||
|
||||
|
||||
|
||||
private var watcherRequestStopEvent = Event<Unit>()
|
||||
private var watcher: (() -> Unit)? = null
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@@ -99,7 +102,12 @@ class Olive<P : Program>(val resources: Resources? = null, private var scriptMod
|
||||
val originalAssetProperties = program.assetProperties.toMutableMap()
|
||||
|
||||
fun setupScript(scriptFile: String) {
|
||||
watcher?.stop()
|
||||
if (watcher != null) {
|
||||
logger.info { "requesting watcher stop" }
|
||||
watcherRequestStopEvent.trigger(Unit)
|
||||
} else {
|
||||
logger.info { "no existing watcher" }
|
||||
}
|
||||
val f = File(scriptFile)
|
||||
if (!f.exists()) {
|
||||
f.parentFile.mkdirs()
|
||||
@@ -124,7 +132,7 @@ class Olive<P : Program>(val resources: Resources? = null, private var scriptMod
|
||||
|
||||
val jsr233ObjectLoader = if (scriptHost == OliveScriptHost.JSR223_REUSE) ScriptObjectLoader() else null
|
||||
|
||||
watcher = program.watchFile(File(script)) {
|
||||
watcher = watchFile(File(script), requestStopEvent = watcherRequestStopEvent) {
|
||||
try {
|
||||
logger.info("change detected, reloading script")
|
||||
|
||||
@@ -188,7 +196,7 @@ class Olive<P : Program>(val resources: Resources? = null, private var scriptMod
|
||||
|
||||
val destFile = File("$dest/${filePath}").absoluteFile
|
||||
|
||||
program.watchFile(file) {
|
||||
watchFile(file) {
|
||||
if (resources[file]!! && filePath != null) {
|
||||
file.copyTo(destFile, overwrite = true)
|
||||
reload()
|
||||
|
||||
Reference in New Issue
Block a user