From 163116061fdeaf34b461b0f7a4e99db2ca98435b Mon Sep 17 00:00:00 2001 From: Lanius Trolling Date: Sun, 24 Dec 2023 10:48:01 -0500 Subject: [PATCH] Hopefully fix sitemap --- .idea/misc.xml | 2 +- build.gradle.kts | 136 ++++++++++-------- patch | 4 +- .../info/mechyrdia/lore/views_robots.kt | 2 +- .../info/mechyrdia/mapviewer/history.kt | 2 +- .../kotlin/info/mechyrdia/mapviewer/render.kt | 15 +- .../kotlin/info/mechyrdia/mapviewer/utils.kt | 3 - update | 4 +- 8 files changed, 91 insertions(+), 77 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 45ba684..1ad7afe 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -94,7 +94,7 @@ - + diff --git a/build.gradle.kts b/build.gradle.kts index f6b5715..fbf0745 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,10 +3,11 @@ import com.nixxcode.jvmbrotli.common.BrotliLoader import com.nixxcode.jvmbrotli.enc.BrotliOutputStream import com.nixxcode.jvmbrotli.enc.Encoder import groovy.json.JsonSlurper +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackDevtool -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.util.concurrent.CountDownLatch import java.util.concurrent.Executors import java.util.zip.GZIPOutputStream @@ -40,54 +41,72 @@ val configFile = (JsonSlurper().parse(File(rootDir, "config.json")) as Map<*, *> val isDevMode = (configFile["isDevMode"] as? Boolean) ?: false -repositories { - mavenCentral() - maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") +val configureOutput: KotlinJsBrowserDsl.(name: String) -> Unit = { name -> + val fileName = "$name.js" + + commonWebpackConfig { + outputFileName = fileName + if (isDevMode) { + mode = KotlinWebpackConfig.Mode.DEVELOPMENT + devtool = WebpackDevtool.SOURCE_MAP + sourceMaps = true + } else { + mode = KotlinWebpackConfig.Mode.PRODUCTION + devtool = null + sourceMaps = false + } + } + + webpackTask { + mainOutputFileName.set(fileName) + if (isDevMode) { + mode = KotlinWebpackConfig.Mode.DEVELOPMENT + devtool = WebpackDevtool.SOURCE_MAP + sourceMaps = true + } else { + mode = KotlinWebpackConfig.Mode.PRODUCTION + sourceMaps = false + } + } } -kotlin { - js("map") { +val jsTarget: KotlinMultiplatformExtension.(name: String) -> Unit = { name -> + js(name) { browser { - commonWebpackConfig { - outputFileName = "map.js" - if (isDevMode) { - mode = KotlinWebpackConfig.Mode.DEVELOPMENT - devtool = WebpackDevtool.SOURCE_MAP - sourceMaps = true - } else { - mode = KotlinWebpackConfig.Mode.PRODUCTION - devtool = null - sourceMaps = false - } - } - - webpackTask { - mainOutputFileName.set("map.js") - if (isDevMode) { - mode = KotlinWebpackConfig.Mode.DEVELOPMENT - devtool = WebpackDevtool.SOURCE_MAP - sourceMaps = true - } else { - mode = KotlinWebpackConfig.Mode.PRODUCTION - sourceMaps = false - } - } + configureOutput(name) } binaries.executable() } +} + +repositories { + mavenCentral() + maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") +} + +kotlin { + jsTarget("map") + jvmToolchain(17) jvm { withJava() } sourceSets { + all { + languageSettings { + optIn("kotlin.RequiresOptIn") + enableLanguageFeature("ContextReceivers") + } + } + val commonMain by getting val mapMain by getting { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2") - implementation("org.jetbrains.kotlinx:kotlinx-html:0.10.1") + implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.10.1") } } @@ -131,18 +150,7 @@ kotlin { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(14)) - } -} - -kotlin { - jvmToolchain(14) -} - -tasks.withType { - kotlinOptions { - jvmTarget = "14" - freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn", "-Xcontext-receivers") + languageVersion.set(JavaLanguageVersion.of(17)) } } @@ -189,9 +197,11 @@ application { mainClass.set("info.mechyrdia.Factbooks") } -tasks.withType { - val mapWebpackTask = tasks.getByName("mapBrowserProductionWebpack") - dependsOn(mapWebpackTask) +val browserWebpackSuffix = if (isDevMode) "BrowserDevelopmentWebpack" else "BrowserProductionWebpack" + +val copyToAssets: Task.(name: String, destSubDir: String, destFileName: String) -> Unit = { name, destSubDir, destFileName -> + val webpackTask = tasks.getByName("$name$browserWebpackSuffix") + dependsOn(webpackTask) doFirst { val assetsDirPath = configFile["assetDir"]?.let { "$it" } @@ -199,36 +209,40 @@ tasks.withType { ?: "../assets" val assetsDir = File(rootDir, assetsDirPath) - val destMapJsName = "main.js" + val destJsName = "$destFileName.js" - val mapJsFile = mapWebpackTask + val jsFile = webpackTask .mainOutputFile .get() .asFile - val mapJsText = mapJsFile.readText() - val mapJsMapName = "${mapWebpackTask.mainOutputFileName.get()}.map" - val sourceMapReplaceText = "//# sourceMappingURL=$mapJsMapName" - val sourceMapReplacement = "//# sourceMappingURL=${destMapJsName}.map" + val jsText = jsFile.readText() + val jsMapName = "${webpackTask.mainOutputFileName.get()}.map" + val sourceMapReplaceText = "//# sourceMappingURL=$jsMapName" + val sourceMapReplacement = "//# sourceMappingURL=$destJsName.map" - val destMapJsFile = File(assetsDir, "map/$destMapJsName") - val destMapJsMapFile = File(assetsDir, "map/${destMapJsName}.map") + val destJsFile = File(assetsDir, "$destSubDir/$destJsName") + val destJsMapFile = File(assetsDir, "$destSubDir/$destJsName.map") if (isDevMode) { - val mapJsMapFile = File(mapJsFile.parentFile, mapJsMapName) - val mapJsMapText = mapJsMapFile.readText() + val jsMapFile = File(jsFile.parentFile, jsMapName) + val jsMapText = jsMapFile.readText() - destMapJsFile.writeText(mapJsText.replace(sourceMapReplaceText, sourceMapReplacement)) - destMapJsMapFile.writeText(mapJsMapText) + destJsFile.writeText(jsText.replace(sourceMapReplaceText, sourceMapReplacement)) + destJsMapFile.writeText(jsMapText) } else { - destMapJsFile.writeText(mapJsText.replace(sourceMapReplaceText, "")) - destMapJsMapFile.delete() + destJsFile.writeText(jsText.replace(sourceMapReplaceText, "")) + destJsMapFile.delete() } } } +tasks.withType { + copyToAssets("map", "map", "main") +} + tasks.withType { javaLauncher.set(javaToolchains.launcherFor { - languageVersion.set(JavaLanguageVersion.of(14)) + languageVersion.set(JavaLanguageVersion.of(17)) }) } diff --git a/patch b/patch index 4de65ee..4c0f5ae 100755 --- a/patch +++ b/patch @@ -2,5 +2,5 @@ screen -S factbooks -X quit git pull -/opt/gradle/gradle-7.1/bin/gradle shadowJar -screen -dmS factbooks /opt/gradle/gradle-7.1/bin/gradle runShadow +/opt/gradle/gradle-7.6.3/bin/gradle shadowJar +screen -dmS factbooks /opt/gradle/gradle-7.6.3/bin/gradle runShadow diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/views_robots.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/views_robots.kt index 5ea8eff..60bac01 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/views_robots.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/views_robots.kt @@ -77,7 +77,7 @@ private fun Appendable.renderIntroSitemap() { fun Appendable.generateSitemap() { appendLine("") - appendLine("") + appendLine("") renderIntroSitemap() renderLoreSitemap() appendLine("") diff --git a/src/mapMain/kotlin/info/mechyrdia/mapviewer/history.kt b/src/mapMain/kotlin/info/mechyrdia/mapviewer/history.kt index aecfcb4..6575c56 100644 --- a/src/mapMain/kotlin/info/mechyrdia/mapviewer/history.kt +++ b/src/mapMain/kotlin/info/mechyrdia/mapviewer/history.kt @@ -54,7 +54,7 @@ fun CoroutineScope.initPopHistoryEntryHandler(): () -> MapObjectPtr { val ev = e.unsafeCast() val statePtr = JsonCodec.decodeFromDynamic(MapObjectPtr.serializer(), ev.state) - if (renderJob != null) { + if (isRenderActive) { isHandlingPopState = true renderMap(statePtr) isHandlingPopState = false diff --git a/src/mapMain/kotlin/info/mechyrdia/mapviewer/render.kt b/src/mapMain/kotlin/info/mechyrdia/mapviewer/render.kt index 973b0ba..300bdcd 100644 --- a/src/mapMain/kotlin/info/mechyrdia/mapviewer/render.kt +++ b/src/mapMain/kotlin/info/mechyrdia/mapviewer/render.kt @@ -237,8 +237,8 @@ private const val GALAXY_MAP_SIZE_FACTOR = 8.0 private fun preparePan(pan: GalaxyMapPan, panPosition: Vector2? = null) { if (panPosition != null) { - pan.x = (window.innerWidth / 2) - (panPosition.x.toDouble() * GALAXY_MAP_SIZE_FACTOR) - pan.y = (window.innerHeight / 2) - (panPosition.y.toDouble() * GALAXY_MAP_SIZE_FACTOR) + pan.x = (window.innerWidth * 0.5) - (panPosition.x.toDouble() * GALAXY_MAP_SIZE_FACTOR) + pan.y = (window.innerHeight * 0.5) - (panPosition.y.toDouble() * GALAXY_MAP_SIZE_FACTOR) } else { pan.x = (window.innerWidth - (galaxyMap.background.size.x.toDouble() * GALAXY_MAP_SIZE_FACTOR)) / 2 pan.y = (window.innerHeight - (galaxyMap.background.size.y.toDouble() * GALAXY_MAP_SIZE_FACTOR)) / 2 @@ -277,7 +277,10 @@ private fun updateElementPan(element: HTMLElement, pan: GalaxyMapPan) { element.style.transform = "translate(${pan.x}px, ${pan.y}px)" } -var renderJob: Job? = null +private var renderJob: Job? = null + +val isRenderActive: Boolean + get() = renderJob != null private fun setTitle(ptr: MapObjectPtr) { document.title = when (ptr) { @@ -499,7 +502,7 @@ private fun CoroutineScope.renderGalaxy(panPosition: Vector2? = null) { } } -private class SectorMapPan(val camera: PerspectiveCamera, override val sectorId: String, private val sector: SectorMap, private val interSectorLinks: List, scope: CoroutineScope) : MapPan(scope) { +private class SectorMapPan(private val camera: PerspectiveCamera, override val sectorId: String, private val sector: SectorMap, private val interSectorLinks: List, scope: CoroutineScope) : MapPan(scope) { private val rayCaster = Raycaster() override fun handleClick(currX: Double, currY: Double): MapObjectPtr? { @@ -555,7 +558,7 @@ private class SectorMapPan(val camera: PerspectiveCamera, override val sectorId: private fun CoroutineScope.SectorMapPan(camera: PerspectiveCamera, sectorId: String, sector: SectorMap, interSectorLinks: List) = SectorMapPan(camera, sectorId, sector, interSectorLinks, this) -private fun prepareElement(element: HTMLElement) { +private fun fullscreenElement(element: HTMLElement) { element.style.width = "100vw" element.style.height = "100vh" element.style.position = "fixed" @@ -702,7 +705,7 @@ private fun CoroutineScope.renderSector(sectorId: String, initialSelection: Sect val glCanvas = document.create.canvas(content = "") glCanvas.width = (window.innerWidth * window.devicePixelRatio).roundToInt() glCanvas.height = (window.innerHeight * window.devicePixelRatio).roundToInt() - prepareElement(glCanvas) + fullscreenElement(glCanvas) addPanEvents(glCanvas, pan) val glRenderer = WebGLRenderer(configure { canvas = glCanvas diff --git a/src/mapMain/kotlin/info/mechyrdia/mapviewer/utils.kt b/src/mapMain/kotlin/info/mechyrdia/mapviewer/utils.kt index 4542ef7..772756d 100644 --- a/src/mapMain/kotlin/info/mechyrdia/mapviewer/utils.kt +++ b/src/mapMain/kotlin/info/mechyrdia/mapviewer/utils.kt @@ -1,7 +1,6 @@ package info.mechyrdia.mapviewer import com.github.nwillc.ksvg.RenderMode -import kotlinx.browser.document import kotlinx.browser.window import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.flow.Flow @@ -10,9 +9,7 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.html.* import org.w3c.dom.Window -import org.w3c.dom.svg.SVGElement import kotlin.coroutines.resume -import com.github.nwillc.ksvg.elements.Element as KSVGElement import com.github.nwillc.ksvg.elements.SVG as KSVG fun configure(block: T.() -> Unit): T = js("{}").unsafeCast().apply(block) diff --git a/update b/update index 28ac59c..8f1e175 100755 --- a/update +++ b/update @@ -2,5 +2,5 @@ screen -S factbooks -X quit git pull -/opt/gradle/gradle-7.1/bin/gradle clean shadowJar -screen -dmS factbooks /opt/gradle/gradle-7.1/bin/gradle runShadow +/opt/gradle/gradle-7.6.3/bin/gradle clean shadowJar +screen -dmS factbooks /opt/gradle/gradle-7.6.3/bin/gradle runShadow -- 2.25.1