window.open(ptr.toUrl().href, "_blank")
}
+private var mapPan: MapPan? = null
+
private var hammerInstance: HammerManager? = null
-private fun CoroutineScope.openPtr(target: MapObjectPtr, currentSectorId: String?) {
+private fun SectorMapPan.moveCameraToSelection(sector: SectorMap, selection: SectorMapSelection) {
+ val (newX, newY) = when (selection) {
+ SectorMapSelection.NoSelection -> Vector2(0, 0)
+ is SectorMapSelection.SelectedSystem -> sector.starSystems.getValue(selection.system).location
+ is SectorMapSelection.SelectedBody -> {
+ val system = sector.starSystems.getValue(selection.system)
+ Vector2().copy(system.location).add(system.celestialBodies.getValue(selection.body).location)
+ }
+ }
+
+ moveTo(newX, newY)
+}
+
+private fun CoroutineScope.openPtr(target: MapObjectPtr, currentSectorId: String?, panToSelection: Boolean) {
if (target.sector == currentSectorId) {
val selection = when (target) {
GalaxyPtr -> null
setSelectedLabel(selection)
setCurrentLocation(target)
+
+ if (panToSelection)
+ (mapPan as? SectorMapPan)?.moveCameraToSelection(galaxyMap.sectors.getValue(currentSectorId!!), selection!!)
} else {
if (target == GalaxyPtr && currentSectorId != null)
renderGalaxy(galaxyMap.sectors.getValue(currentSectorId).location)
private var prevMouseX = 0.0
private var prevMouseY = 0.0
+ abstract fun moveTo(newX: Double, newY: Double)
+
abstract fun handleClick(currX: Double, currY: Double): MapObjectPtr?
abstract fun handleDrag(currX: Double, currY: Double, prevX: Double, prevY: Double)
if (ev.ctrlKey)
renderInNewTab(target)
else
- scope.openPtr(target, sectorId)
+ scope.openPtr(target, sectorId, false)
}
private fun onAuxClick(ev: MouseEvent) {
val target = handleClick(ev.center.x.toDouble(), ev.center.y.toDouble()) ?: return
- scope.openPtr(target, sectorId)
+ scope.openPtr(target, sectorId, false)
}
private fun onHammerPress(ev: HammerInput) {
var x = 0.0
var y = 0.0
+ override fun moveTo(newX: Double, newY: Double) {
+ x = newX
+ y = newY
+ }
+
override fun handleClick(currX: Double, currY: Double): MapObjectPtr? {
val worldX = (currX - x) / GALAXY_MAP_SIZE_FACTOR
val worldY = (currY - y) / GALAXY_MAP_SIZE_FACTOR
setCurrentLocation(GalaxyPtr)
val pan = GalaxyMapPan()
-
preparePan(pan, panPosition)
+ mapPan = pan
val galaxySvg = document.create.ksvg {
viewBox = "0 0 ${galaxyMap.background.size.x.toDouble()} ${galaxyMap.background.size.y.toDouble()}"
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 moveTo(newX: Double, newY: Double) {
+ camera.position.set(newX, 110.851252, newY + 64)
+ camera.updateMatrixWorld(true)
+ }
+
override fun handleClick(currX: Double, currY: Double): MapObjectPtr? {
rayCaster.setFromCamera(configure {
x = (currX / window.innerWidth * 2) - 1
val interSectorLinks = mutableListOf<InterSectorLinkDestination>()
- val cameraPos = when (initialSelection) {
- SectorMapSelection.NoSelection -> Vector2(0, 0)
- is SectorMapSelection.SelectedSystem -> sector.starSystems.getValue(initialSelection.system).location
- is SectorMapSelection.SelectedBody -> {
- val system = sector.starSystems.getValue(initialSelection.system)
- Vector2().copy(system.location).add(system.celestialBodies.getValue(initialSelection.body).location)
- }
- }
-
val camera = PerspectiveCamera(69, window.aspectRatio, 1, 10000)
camera.rotateX(-PI / 3)
- camera.position.set(cameraPos.x, 110.851252, cameraPos.y.toDouble() + 64)
- camera.updateMatrixWorld(true)
val pan = SectorMapPan(camera, sectorId, sector, interSectorLinks)
+ pan.moveCameraToSelection(sector, initialSelection)
val glCanvas = document.create.canvas(content = "")
glCanvas.width = (window.innerWidth * window.devicePixelRatio).roundToInt()
powerPreference = "high-performance"
})
+ mapPan = pan
+
val cssCanvas = document.create.div {
style = "pointer-events:none;position:fixed;top:0;left:0;width:100vw;height:100vh"
}
}
}
+context(CoroutineScope)
+@HtmlTagMarker
+private inline fun FlowOrInteractiveOrPhrasingContent.a(ptr: MapObjectPtr, currentSectorId: String?, crossinline block: A.() -> Unit = {}) {
+ a(href = ptr.toUrl().href) {
+ onClickFunction = { ev ->
+ ev.preventDefault()
+ openPtr(ptr, currentSectorId, true)
+ }
+
+ block()
+ }
+}
+
private fun CoroutineScope.renderLore(ptr: MapObjectPtr) {
val loreBar = document.getElementById("lore-bar")!!.unsafeCast<HTMLDivElement>()
is SectorPtr -> {
val sector = galaxyMap.sectors.getValue(ptr.sector)
p {
- a(href = GalaxyPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- openPtr(GalaxyPtr, ptr.sector)
- }
-
+ a(GalaxyPtr, ptr.sector) {
+galaxyMap.universeTitle
}
}
val sector = galaxyMap.sectors.getValue(ptr.sector)
val system = sector.starSystems.getValue(ptr.system)
p {
- a(href = GalaxyPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- openPtr(GalaxyPtr, ptr.sector)
- }
-
+ a(GalaxyPtr, ptr.sector) {
+galaxyMap.universeTitle
}
+" > "
val sectorPtr = SectorPtr(ptr.sector)
- a(href = sectorPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- openPtr(sectorPtr, ptr.sector)
- }
-
+ a(sectorPtr, ptr.sector) {
+sector.name
}
}
val system = sector.starSystems.getValue(ptr.system)
val body = system.celestialBodies.getValue(ptr.body)
p {
- a(href = GalaxyPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- openPtr(GalaxyPtr, ptr.sector)
- }
-
+ a(GalaxyPtr, ptr.sector) {
+galaxyMap.universeTitle
}
+" > "
val sectorPtr = SectorPtr(ptr.sector)
- a(href = sectorPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- openPtr(sectorPtr, ptr.sector)
- }
-
+ a(sectorPtr, ptr.sector) {
+sector.name
}
+" > "
val starSystemPtr = StarSystemPtr(ptr.sector, ptr.system)
- a(href = starSystemPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- openPtr(starSystemPtr, ptr.sector)
- }
-
+ a(starSystemPtr, ptr.sector) {
+system.name
}
}
for ((sectorId, sector) in sectorsList)
li {
val sectorPtr = SectorPtr(sectorId)
- a(href = sectorPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- renderMap(sectorPtr)
- }
-
+ a(sectorPtr, null) {
+sector.name
}
}
for ((systemId, system) in systemsList)
li {
val systemPtr = StarSystemPtr(ptr.sector, systemId)
- a(href = systemPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- renderMap(systemPtr)
- }
-
+ a(systemPtr, ptr.sector) {
+system.name
}
}
for ((bodyId, body) in bodiesList)
li {
val bodyPtr = CelestialBodyPtr(ptr.sector, ptr.system, bodyId)
- a(href = bodyPtr.toUrl().href) {
- onClickFunction = { ev ->
- ev.preventDefault()
- renderMap(CelestialBodyPtr(ptr.sector, ptr.system, bodyId))
- }
-
+ a(bodyPtr, ptr.sector) {
+body.name
}
}