visionforge/demo/playground/src/jvmMain/kotlin/serverExtensions.kt

43 lines
1.5 KiB
Kotlin
Raw Normal View History

2021-03-07 16:19:43 +03:00
package space.kscience.visionforge.examples
2021-01-12 12:52:22 +03:00
2021-03-07 16:19:43 +03:00
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionForge
import space.kscience.visionforge.html.HtmlVisionFragment
import space.kscience.visionforge.html.ResourceLocation
import space.kscience.visionforge.html.page
import space.kscience.visionforge.html.scriptHeader
import space.kscience.visionforge.makeFile
import space.kscience.visionforge.three.server.VisionServer
import space.kscience.visionforge.three.server.useScript
2021-01-12 12:52:22 +03:00
import java.awt.Desktop
import java.nio.file.Path
public fun VisionServer.usePlayground(): Unit {
useScript("js/visionforge-playground.js")
}
@DFExperimental
2021-02-26 13:03:40 +03:00
public fun VisionForge.makeVisionFile(
2021-01-12 12:52:22 +03:00
content: HtmlVisionFragment,
path: Path? = null,
title: String = "VisionForge page",
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true,
): Unit {
2021-03-02 16:33:29 +03:00
val actualPath = page(title, content = content).makeFile(path) { actualPath ->
2021-03-10 21:58:28 +03:00
mapOf("threeJs" to scriptHeader("js/visionforge-playground.js", resourceLocation, actualPath))
2021-01-12 12:52:22 +03:00
}
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())
}
2021-02-24 18:26:15 +03:00
@DFExperimental
2021-02-26 13:03:40 +03:00
public fun VisionForge.makeVisionFile(
2021-02-24 18:26:15 +03:00
vision: Vision,
path: Path? = null,
title: String = "VisionForge page",
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true,
): Unit = makeVisionFile({ vision(vision) }, path, title, resourceLocation, show)