Hopefully fix sitemap
authorLanius Trolling <lanius@laniustrolling.dev>
Sun, 24 Dec 2023 15:48:01 +0000 (10:48 -0500)
committerLanius Trolling <lanius@laniustrolling.dev>
Sun, 24 Dec 2023 15:48:01 +0000 (10:48 -0500)
.idea/misc.xml
build.gradle.kts
patch
src/jvmMain/kotlin/info/mechyrdia/lore/views_robots.kt
src/mapMain/kotlin/info/mechyrdia/mapviewer/history.kt
src/mapMain/kotlin/info/mechyrdia/mapviewer/render.kt
src/mapMain/kotlin/info/mechyrdia/mapviewer/utils.kt
update

index 45ba6840282b4cd597bdac6009003defafdeaaca..1ad7afe2ee65abc9378b34639a0c859d6a1bb5ae 100644 (file)
@@ -94,7 +94,7 @@
   <component name="PWA">
     <option name="wasEnabledAtLeastOnce" value="true" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
   <component name="RustProjectSettings">
index f6b57155361340baeec675f1938eb3cde27610d7..fbf07459e6eb91e2742feab25185179e8a4bc8ba 100644 (file)
@@ -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<KotlinCompile> {
-       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<ShadowJar> {
-       val mapWebpackTask = tasks.getByName<KotlinWebpack>("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<KotlinWebpack>("$name$browserWebpackSuffix")
+       dependsOn(webpackTask)
        
        doFirst {
                val assetsDirPath = configFile["assetDir"]?.let { "$it" }
@@ -199,36 +209,40 @@ tasks.withType<ShadowJar> {
                        ?: "../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<ShadowJar> {
+       copyToAssets("map", "map", "main")
+}
+
 tasks.withType<JavaExec> {
        javaLauncher.set(javaToolchains.launcherFor {
-               languageVersion.set(JavaLanguageVersion.of(14))
+               languageVersion.set(JavaLanguageVersion.of(17))
        })
 }
diff --git a/patch b/patch
index 4de65ee62ddc639d682d9e4547ab7cd8a46240ae..4c0f5ae32577be491c86fec81b14810d742adc3e 100755 (executable)
--- 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
index 5ea8eff92ece9675d9d5a5127e05febbb9322537..60bac0165d69113c81d9122909d9ae3df31c0221 100644 (file)
@@ -77,7 +77,7 @@ private fun Appendable.renderIntroSitemap() {
 
 fun Appendable.generateSitemap() {
        appendLine("<?xml version='1.0' encoding='UTF-8'?>")
-       appendLine("<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">")
+       appendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">")
        renderIntroSitemap()
        renderLoreSitemap()
        appendLine("</urlset>")
index aecfcb45a71c8b4591faaa82951493a75cbe4fa3..6575c56ed0f5f415e1efb57a7073664fa90d955f 100644 (file)
@@ -54,7 +54,7 @@ fun CoroutineScope.initPopHistoryEntryHandler(): () -> MapObjectPtr {
                val ev = e.unsafeCast<PopStateEvent>()
                val statePtr = JsonCodec.decodeFromDynamic(MapObjectPtr.serializer(), ev.state)
                
-               if (renderJob != null) {
+               if (isRenderActive) {
                        isHandlingPopState = true
                        renderMap(statePtr)
                        isHandlingPopState = false
index 973b0bac744a5c99c52c150f621e406de4fd773c..300bdcd0620521809b2de42dc55a8e3c2089e205 100644 (file)
@@ -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<InterSectorLinkDestination>, scope: CoroutineScope) : MapPan(scope) {
+private class SectorMapPan(private val camera: PerspectiveCamera, override val sectorId: String, private val sector: SectorMap, private val interSectorLinks: List<InterSectorLinkDestination>, 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<InterSectorLinkDestination>) = 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
index 4542ef77f2d3fa33e46b275b5a559251e17b45ba..772756d97540d7398d63937b5d1a6b0aba9e629c 100644 (file)
@@ -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 <T : Any> configure(block: T.() -> Unit): T = js("{}").unsafeCast<T>().apply(block)
diff --git a/update b/update
index 28ac59c904c62ecaf2c31faba98f7620bb33bc64..8f1e17569736dd725fd41b56ad490ea86eafcdb6 100755 (executable)
--- 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