@@ -162,6 +162,15 @@ function showSelected(el: HTMLElement | undefined, region: string) {
162162 if ( el ) el . classList . add ( 'region-selected' )
163163}
164164
165+ window . addEventListener ( 'popstate' , ( ) => {
166+ const url = new URL ( window . location . toString ( ) )
167+ const regionName = url . pathname . substring ( 1 ) . toUpperCase ( )
168+ const region = regions [ regionName ]
169+ if ( region ) {
170+ showRegion ( regionName , regions [ regionName ] , undefined )
171+ }
172+ } )
173+
165174let regionEls : Map < string , HTMLElement > = new Map ( )
166175
167176const regionElsArr = [ ...document . querySelectorAll ( '#regions > .region' ) ]
@@ -402,8 +411,8 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
402411 setLayer ( curLayer )
403412
404413 if ( ! pos ) pos = [ ( minX + maxX ) * 0.5 , ( minY + maxY ) * 0.5 ]
405- context . camera . posX = pos [ 0 ]
406- context . camera . posY = pos [ 1 ]
414+ context . camera . posX = pos [ 0 ] + halfWidth
415+ context . camera . posY = pos [ 1 ] + halfHeight
407416 context . requestRender ( )
408417
409418 {
@@ -532,29 +541,10 @@ function showRegion(regionName: RegionKey, region: Region, pos?: [number, number
532541{
533542 const defaultReg = ( window as any ) . defaultRegion as string
534543
535- let pos : Pos
544+ let pos : Pos | undefined = undefined
536545 if ( new URL ( window . location . toString ( ) ) . pathname === '/' ) {
537546 pos = [ - 0 , 150 ]
538547 }
539- else {
540- const reg = regions [ defaultReg ]
541-
542- let totalX = 0
543- let totalY = 0
544- let count = 0
545- for ( const roomK in reg . rooms ) {
546- const room = reg . rooms [ roomK ]
547- if ( ! room . data . mapPos ) continue
548- totalX += room . data . mapPos [ 0 ] / 3 - room . data . size [ 0 ] * 0.5
549- totalY += room . data . mapPos [ 1 ] / 3 - room . data . size [ 1 ] * 0.5
550- count ++
551- }
552-
553- const avgX = totalX / count + halfWidth
554- const avgY = totalY / count + halfHeight
555-
556- pos = [ avgX , avgY ]
557- }
558548
559549 fillRegions ( null )
560550 showRegion ( defaultReg , regions [ defaultReg ] , pos , 1 )
0 commit comments