Remove context receivers entirely
authorLanius Trolling <lanius@laniustrolling.dev>
Sat, 24 Aug 2024 13:35:53 +0000 (09:35 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sat, 24 Aug 2024 13:35:53 +0000 (09:35 -0400)
build.gradle.kts
src/mapMain/kotlin/info/mechyrdia/mapviewer/render.kt

index c75a7398234733c3c88a0d749a451e47627e23d1..61f736768eeb9e262cd9c6793786d6dd343ffde2 100644 (file)
@@ -103,7 +103,6 @@ kotlin {
                all {
                        languageSettings {
                                optIn("kotlin.RequiresOptIn")
-                               enableLanguageFeature("ContextReceivers")
                        }
                }
                
index 50be7303eb9b420f52ecca3134ff417dd15af32c..dfcf4b1deb7c22ee538f500b00ba06453b3cb167 100644 (file)
@@ -335,7 +335,7 @@ private fun setTitle(ptr: MapObjectPtr) {
 
 private fun CoroutineScope.setCurrentLocation(ptr: MapObjectPtr) {
        pushHistoryEntry(ptr)
-       renderLore(ptr)
+       renderLore(ptr, this)
        setTitle(ptr)
 }
 
@@ -936,20 +936,19 @@ private fun CoroutineScope.renderSector(sectorId: String, initialSelection: Sect
        }
 }
 
-context(CoroutineScope)
 @HtmlTagMarker
-private inline fun FlowOrInteractiveOrPhrasingContent.a(ptr: MapObjectPtr, currentSectorId: String?, crossinline block: A.() -> Unit = {}) {
+private inline fun FlowOrInteractiveOrPhrasingContent.a(ptr: MapObjectPtr, currentSectorId: String?, coroutineScope: CoroutineScope, crossinline block: A.() -> Unit) {
        a(href = ptr.toUrl().href) {
                onClickFunction = { ev ->
                        ev.preventDefault()
-                       openPtr(ptr, currentSectorId, true)
+                       coroutineScope.openPtr(ptr, currentSectorId, true)
                }
                
                block()
        }
 }
 
-private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
+private fun renderLore(ptr: MapObjectPtr, coroutineScope: CoroutineScope) {
        val loreBar = document.getElementById("lore-bar")!!.unsafeCast<HTMLDivElement>()
        
        loreBar.clear()
@@ -963,7 +962,7 @@ private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
                        is SectorPtr -> {
                                val sector = galaxyMap.sectors.getValue(ptr.sector)
                                p {
-                                       a(GalaxyPtr, ptr.sector) {
+                                       a(GalaxyPtr, ptr.sector, coroutineScope) {
                                                +galaxyMap.universeTitle
                                        }
                                }
@@ -976,12 +975,12 @@ private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
                                val sector = galaxyMap.sectors.getValue(ptr.sector)
                                val system = sector.starSystems.getValue(ptr.system)
                                p {
-                                       a(GalaxyPtr, ptr.sector) {
+                                       a(GalaxyPtr, ptr.sector, coroutineScope) {
                                                +galaxyMap.universeTitle
                                        }
                                        +" > "
                                        val sectorPtr = SectorPtr(ptr.sector)
-                                       a(sectorPtr, ptr.sector) {
+                                       a(sectorPtr, ptr.sector, coroutineScope) {
                                                +sector.name
                                        }
                                }
@@ -1000,17 +999,17 @@ private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
                                val system = sector.starSystems.getValue(ptr.system)
                                val body = system.celestialBodies.getValue(ptr.body)
                                p {
-                                       a(GalaxyPtr, ptr.sector) {
+                                       a(GalaxyPtr, ptr.sector, coroutineScope) {
                                                +galaxyMap.universeTitle
                                        }
                                        +" > "
                                        val sectorPtr = SectorPtr(ptr.sector)
-                                       a(sectorPtr, ptr.sector) {
+                                       a(sectorPtr, ptr.sector, coroutineScope) {
                                                +sector.name
                                        }
                                        +" > "
                                        val starSystemPtr = StarSystemPtr(ptr.sector, ptr.system)
-                                       a(starSystemPtr, ptr.sector) {
+                                       a(starSystemPtr, ptr.sector, coroutineScope) {
                                                +system.name
                                        }
                                }
@@ -1049,7 +1048,7 @@ private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
                                                        for ((sectorId, sector) in sectorsList)
                                                                li {
                                                                        val sectorPtr = SectorPtr(sectorId)
-                                                                       a(sectorPtr, null) {
+                                                                       a(sectorPtr, null, coroutineScope) {
                                                                                +sector.name
                                                                        }
                                                                }
@@ -1069,7 +1068,7 @@ private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
                                                        for ((systemId, system) in systemsList)
                                                                li {
                                                                        val systemPtr = StarSystemPtr(ptr.sector, systemId)
-                                                                       a(systemPtr, ptr.sector) {
+                                                                       a(systemPtr, ptr.sector, coroutineScope) {
                                                                                +system.name
                                                                        }
                                                                }
@@ -1091,7 +1090,7 @@ private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
                                                        for ((bodyId, body) in bodiesList)
                                                                li {
                                                                        val bodyPtr = CelestialBodyPtr(ptr.sector, ptr.system, bodyId)
-                                                                       a(bodyPtr, ptr.sector) {
+                                                                       a(bodyPtr, ptr.sector, coroutineScope) {
                                                                                +body.name
                                                                        }
                                                                }