| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272 |
- import {
- MapEngine,
- type MapEngineGameInfoRow,
- type MapEngineGameInfoSnapshot,
- type MapEngineResultSnapshot,
- type MapEngineStageRect,
- type MapEngineViewState,
- } from '../../engine/map/mapEngine'
- import {
- getBackendSessionContextFromLaunchEnvelope,
- getDemoGameLaunchEnvelope,
- resolveGameLaunchEnvelope,
- type GameLaunchEnvelope,
- type MapPageLaunchOptions,
- } from '../../utils/gameLaunch'
- import { finishSession, startSession, type BackendSessionFinishSummaryPayload } from '../../utils/backendApi'
- import { loadBackendBaseUrl } from '../../utils/backendAuth'
- import { loadRemoteMapConfig, type RemoteMapConfig } from '../../utils/remoteMapConfig'
- import { type H5ExperienceFallbackPayload, type H5ExperienceRequest } from '../../game/experience/h5Experience'
- import { type TrackColorPreset } from '../../game/presentation/trackStyleConfig'
- import { type GpsMarkerColorPreset } from '../../game/presentation/gpsMarkerStyleConfig'
- import { type PlayerTelemetryProfile } from '../../game/telemetry/playerTelemetryProfile'
- import {
- DEFAULT_SETTING_LOCKS,
- DEFAULT_STORED_USER_SETTINGS,
- loadStoredUserSettings,
- mergeStoredUserSettings,
- persistStoredUserSettings,
- resolveSystemSettingsState,
- type SystemSettingsConfig,
- type CenterScaleRulerAnchorMode,
- type ResolvedSystemSettingsState,
- type SideButtonPlacement,
- type StoredUserSettings,
- } from '../../game/core/systemSettingsState'
- import {
- compileRuntimeProfile,
- } from '../../game/core/runtimeProfileCompiler'
- import {
- clearSessionRecoverySnapshot,
- loadSessionRecoverySnapshot,
- saveSessionRecoverySnapshot,
- type SessionRecoverySnapshot,
- } from '../../game/core/sessionRecovery'
- type CompassTickData = {
- angle: number
- long: boolean
- major: boolean
- }
- type CompassLabelData = {
- text: string
- angle: number
- rotateBack: number
- radius: number
- className: string
- }
- type ScaleRulerMinorTickData = {
- key: string
- topPx: number
- long: boolean
- }
- type ScaleRulerMajorMarkData = {
- key: string
- topPx: number
- label: string
- }
- type SideButtonMode = 'shown' | 'hidden'
- type SideActionButtonState = 'muted' | 'default' | 'active'
- type MapPageData = MapEngineViewState & {
- showDebugPanel: boolean
- showGameInfoPanel: boolean
- showResultScene: boolean
- showSystemSettingsPanel: boolean
- showHeartRateDevicePicker: boolean
- showCenterScaleRuler: boolean
- showPunchHintBanner: boolean
- punchHintFxClass: string
- centerScaleRulerAnchorMode: CenterScaleRulerAnchorMode
- statusBarHeight: number
- topInsetHeight: number
- hudPanelIndex: number
- configSourceText: string
- mockBridgeUrlDraft: string
- mockHeartRateBridgeUrlDraft: string
- mockDebugLogBridgeUrlDraft: string
- mockChannelIdDraft: string
- gameInfoTitle: string
- gameInfoSubtitle: string
- gameInfoLocalRows: MapEngineGameInfoRow[]
- gameInfoGlobalRows: MapEngineGameInfoRow[]
- resultSceneTitle: string
- resultSceneSubtitle: string
- resultSceneHeroLabel: string
- resultSceneHeroValue: string
- resultSceneRows: MapEngineGameInfoRow[]
- resultSceneCountdownText: string
- panelTimerText: string
- panelTimerMode: 'elapsed' | 'countdown'
- panelMileageText: string
- panelTargetSummaryText: string
- panelDistanceValueText: string
- panelProgressText: string
- panelSpeedValueText: string
- panelTimerFxClass: string
- panelMileageFxClass: string
- panelSpeedFxClass: string
- panelHeartRateFxClass: string
- compassTicks: CompassTickData[]
- compassLabels: CompassLabelData[]
- sideButtonMode: SideButtonMode
- sideButtonPlacement: SideButtonPlacement
- autoRotateEnabled: boolean
- lockAnimationLevel: boolean
- lockTrackMode: boolean
- lockTrackTailLength: boolean
- lockTrackColor: boolean
- lockTrackStyle: boolean
- lockGpsMarkerVisible: boolean
- lockGpsMarkerStyle: boolean
- lockGpsMarkerSize: boolean
- lockGpsMarkerColor: boolean
- lockSideButtonPlacement: boolean
- lockAutoRotate: boolean
- lockCompassTuning: boolean
- lockScaleRulerVisible: boolean
- lockScaleRulerAnchor: boolean
- lockNorthReference: boolean
- lockHeartRateDevice: boolean
- sideToggleIconSrc: string
- sideButton2Class: string
- sideButton4Class: string
- sideButton11Class: string
- sideButton12Class: string
- sideButton13Class: string
- sideButton14Class: string
- sideButton16Class: string
- centerScaleRulerVisible: boolean
- centerScaleRulerCenterXPx: number
- centerScaleRulerZeroYPx: number
- centerScaleRulerHeightPx: number
- centerScaleRulerAxisBottomPx: number
- centerScaleRulerZeroVisible: boolean
- centerScaleRulerZeroLabel: string
- centerScaleRulerMinorTicks: ScaleRulerMinorTickData[]
- centerScaleRulerMajorMarks: ScaleRulerMajorMarkData[]
- showLeftButtonGroup: boolean
- showRightButtonGroups: boolean
- showBottomDebugButton: boolean
- }
- function getGlobalTelemetryProfile(): PlayerTelemetryProfile | null {
- const app = getApp<IAppOption>()
- const profile = app.globalData && app.globalData.telemetryPlayerProfile
- return profile ? { ...profile } : null
- }
- const INTERNAL_BUILD_VERSION = 'map-build-293'
- const PUNCH_HINT_AUTO_HIDE_MS = 30000
- const PUNCH_HINT_FX_DURATION_MS = 420
- const PUNCH_HINT_HAPTIC_GAP_MS = 2400
- const SESSION_RECOVERY_PERSIST_INTERVAL_MS = 5000
- const RESULT_EXIT_REDIRECT_DELAY_MS = 3000
- let currentGameLaunchEnvelope: GameLaunchEnvelope = getDemoGameLaunchEnvelope()
- let mapEngine: MapEngine | null = null
- let stageCanvasAttached = false
- let gameInfoPanelSyncTimer = 0
- let centerScaleRulerSyncTimer = 0
- let contentAudioRecorder: WechatMiniprogram.RecorderManager | null = null
- let contentAudioRecording = false
- let centerScaleRulerUpdateTimer = 0
- let punchHintDismissTimer = 0
- let punchHintFxTimer = 0
- let panelTimerFxTimer = 0
- let panelMileageFxTimer = 0
- let panelSpeedFxTimer = 0
- let panelHeartRateFxTimer = 0
- let sessionRecoveryPersistTimer = 0
- let resultExitRedirectTimer = 0
- let resultExitCountdownTimer = 0
- let lastPunchHintHapticAt = 0
- let currentSystemSettingsConfig: SystemSettingsConfig | undefined
- let currentRemoteMapConfig: RemoteMapConfig | undefined
- let systemSettingsLockLifetimeActive = false
- let syncedBackendSessionStartId = ''
- let syncedBackendSessionFinishId = ''
- let shouldAutoRestoreRecoverySnapshot = false
- let redirectedToResultPage = false
- let pendingHeartRateSwitchDeviceName: string | null = null
- const DEBUG_MOCK_CHANNEL_ID_STORAGE_KEY = 'cmr.debug.mockChannelId.v1'
- const DEBUG_MOCK_AUTO_CONNECT_STORAGE_KEY = 'cmr.debug.autoConnectMockSources.v1'
- let lastCenterScaleRulerStablePatch: Pick<
- MapPageData,
- | 'centerScaleRulerVisible'
- | 'centerScaleRulerCenterXPx'
- | 'centerScaleRulerZeroYPx'
- | 'centerScaleRulerHeightPx'
- | 'centerScaleRulerAxisBottomPx'
- | 'centerScaleRulerZeroVisible'
- | 'centerScaleRulerZeroLabel'
- | 'centerScaleRulerMinorTicks'
- | 'centerScaleRulerMajorMarks'
- > = {
- centerScaleRulerVisible: false,
- centerScaleRulerCenterXPx: 0,
- centerScaleRulerZeroYPx: 0,
- centerScaleRulerHeightPx: 0,
- centerScaleRulerAxisBottomPx: 0,
- centerScaleRulerZeroVisible: false,
- centerScaleRulerZeroLabel: '0 m',
- centerScaleRulerMinorTicks: [],
- centerScaleRulerMajorMarks: [],
- }
- let centerScaleRulerInputCache: Partial<Pick<
- MapPageData,
- 'stageWidth'
- | 'stageHeight'
- | 'zoom'
- | 'centerTileY'
- | 'tileSizePx'
- | 'previewScale'
- >> = {}
- const DEBUG_ONLY_VIEW_KEYS = new Set<string>([
- 'buildVersion',
- 'renderMode',
- 'projectionMode',
- 'mapReady',
- 'mapReadyText',
- 'mapName',
- 'configStatusText',
- 'deviceHeadingText',
- 'devicePoseText',
- 'headingConfidenceText',
- 'accelerometerText',
- 'gyroscopeText',
- 'deviceMotionText',
- 'compassSourceText',
- 'compassTuningProfile',
- 'compassTuningProfileText',
- 'northReferenceButtonText',
- 'autoRotateSourceText',
- 'autoRotateCalibrationText',
- 'northReferenceText',
- 'centerText',
- 'tileSource',
- 'visibleTileCount',
- 'readyTileCount',
- 'memoryTileCount',
- 'diskTileCount',
- 'memoryHitCount',
- 'diskHitCount',
- 'networkFetchCount',
- 'cacheHitRateText',
- 'locationSourceMode',
- 'locationSourceText',
- 'mockBridgeConnected',
- 'mockBridgeStatusText',
- 'mockBridgeUrlText',
- 'mockCoordText',
- 'mockSpeedText',
- 'gpsCoordText',
- 'heartRateSourceMode',
- 'heartRateSourceText',
- 'heartRateConnected',
- 'heartRateStatusText',
- 'heartRateDeviceText',
- 'heartRateScanText',
- 'heartRateDiscoveredDevices',
- 'mockHeartRateBridgeConnected',
- 'mockHeartRateBridgeStatusText',
- 'mockHeartRateBridgeUrlText',
- 'mockHeartRateText',
- ])
- const CENTER_SCALE_RULER_DEP_KEYS = new Set<string>([
- 'showCenterScaleRuler',
- 'centerScaleRulerAnchorMode',
- 'stageWidth',
- 'stageHeight',
- 'topInsetHeight',
- 'zoom',
- 'centerTileY',
- 'tileSizePx',
- 'previewScale',
- ])
- const CENTER_SCALE_RULER_CACHE_KEYS: Array<keyof typeof centerScaleRulerInputCache> = [
- 'stageWidth',
- 'stageHeight',
- 'zoom',
- 'centerTileY',
- 'tileSizePx',
- 'previewScale',
- ]
- const RULER_ONLY_VIEW_KEYS = new Set<string>([
- 'zoom',
- 'centerTileX',
- 'centerTileY',
- 'tileSizePx',
- 'previewScale',
- 'stageWidth',
- 'stageHeight',
- 'stageLeft',
- 'stageTop',
- ])
- const SIDE_BUTTON_DEP_KEYS = new Set<string>([
- 'sideButtonMode',
- 'showGameInfoPanel',
- 'showCenterScaleRuler',
- 'centerScaleRulerAnchorMode',
- 'skipButtonEnabled',
- 'gameSessionStatus',
- 'gpsLockEnabled',
- 'gpsLockAvailable',
- ])
- function hasAnyPatchKey(patch: Record<string, unknown>, keys: Set<string>): boolean {
- return Object.keys(patch).some((key) => keys.has(key))
- }
- function filterDebugOnlyPatch(
- patch: Partial<MapPageData>,
- includeDebugFields: boolean,
- includeRulerFields: boolean,
- ): Partial<MapPageData> {
- if (includeDebugFields && includeRulerFields) {
- return patch
- }
- const filteredPatch: Partial<MapPageData> = {}
- for (const [key, value] of Object.entries(patch)) {
- if (!includeDebugFields && DEBUG_ONLY_VIEW_KEYS.has(key)) {
- continue
- }
- if (!includeRulerFields && RULER_ONLY_VIEW_KEYS.has(key)) {
- continue
- }
- {
- ;(filteredPatch as Record<string, unknown>)[key] = value
- }
- }
- return filteredPatch
- }
- function clearGameInfoPanelSyncTimer() {
- if (gameInfoPanelSyncTimer) {
- clearTimeout(gameInfoPanelSyncTimer)
- gameInfoPanelSyncTimer = 0
- }
- }
- function clearCenterScaleRulerSyncTimer() {
- if (centerScaleRulerSyncTimer) {
- clearTimeout(centerScaleRulerSyncTimer)
- centerScaleRulerSyncTimer = 0
- }
- }
- function clearCenterScaleRulerUpdateTimer() {
- if (centerScaleRulerUpdateTimer) {
- clearTimeout(centerScaleRulerUpdateTimer)
- centerScaleRulerUpdateTimer = 0
- }
- }
- function clearPunchHintDismissTimer() {
- if (punchHintDismissTimer) {
- clearTimeout(punchHintDismissTimer)
- punchHintDismissTimer = 0
- }
- }
- function clearPunchHintFxTimer() {
- if (punchHintFxTimer) {
- clearTimeout(punchHintFxTimer)
- punchHintFxTimer = 0
- }
- }
- function clearHudFxTimer(key: 'timer' | 'mileage' | 'speed' | 'heartRate') {
- const timerMap = {
- timer: panelTimerFxTimer,
- mileage: panelMileageFxTimer,
- speed: panelSpeedFxTimer,
- heartRate: panelHeartRateFxTimer,
- }
- const timer = timerMap[key]
- if (timer) {
- clearTimeout(timer)
- }
- if (key === 'timer') {
- panelTimerFxTimer = 0
- } else if (key === 'mileage') {
- panelMileageFxTimer = 0
- } else if (key === 'speed') {
- panelSpeedFxTimer = 0
- } else {
- panelHeartRateFxTimer = 0
- }
- }
- function updateCenterScaleRulerInputCache(patch: Partial<MapPageData>) {
- for (const key of CENTER_SCALE_RULER_CACHE_KEYS) {
- if (Object.prototype.hasOwnProperty.call(patch, key)) {
- ;(centerScaleRulerInputCache as Record<string, unknown>)[key] =
- (patch as Record<string, unknown>)[key]
- }
- }
- }
- function updateStoredUserSettings(patch: Partial<StoredUserSettings>) {
- persistStoredUserSettings(
- mergeStoredUserSettings(loadStoredUserSettings(), patch),
- )
- }
- function loadStoredMockChannelId(): string {
- try {
- const value = wx.getStorageSync(DEBUG_MOCK_CHANNEL_ID_STORAGE_KEY)
- if (typeof value === 'string' && value.trim().length > 0) {
- return value.trim()
- }
- } catch (_error) {
- // Ignore storage read failures and fall back to default.
- }
- return 'default'
- }
- function persistMockChannelId(channelId: string) {
- try {
- wx.setStorageSync(DEBUG_MOCK_CHANNEL_ID_STORAGE_KEY, channelId)
- } catch (_error) {
- // Ignore storage write failures in debug preference persistence.
- }
- }
- function loadMockAutoConnectEnabled(): boolean {
- try {
- return wx.getStorageSync(DEBUG_MOCK_AUTO_CONNECT_STORAGE_KEY) === true
- } catch (_error) {
- return false
- }
- }
- function persistMockAutoConnectEnabled(enabled: boolean) {
- try {
- wx.setStorageSync(DEBUG_MOCK_AUTO_CONNECT_STORAGE_KEY, enabled)
- } catch (_error) {
- // Ignore storage write failures in debug preference persistence.
- }
- }
- function buildResolvedSystemSettingsPatch(
- resolvedSettings: ResolvedSystemSettingsState,
- ): Partial<MapPageData> {
- return {
- ...resolvedSettings.values,
- ...resolvedSettings.locks,
- autoRotateEnabled: resolvedSettings.values.autoRotateEnabled,
- sideButtonPlacement: resolvedSettings.values.sideButtonPlacement,
- showCenterScaleRuler: resolvedSettings.values.showCenterScaleRuler,
- centerScaleRulerAnchorMode: resolvedSettings.values.centerScaleRulerAnchorMode,
- }
- }
- function isSystemSettingsLockLifetimeActive(): boolean {
- return systemSettingsLockLifetimeActive
- }
- function clearSessionRecoveryPersistTimer() {
- if (sessionRecoveryPersistTimer) {
- clearInterval(sessionRecoveryPersistTimer)
- sessionRecoveryPersistTimer = 0
- }
- }
- function clearResultExitRedirectTimer() {
- if (resultExitRedirectTimer) {
- clearTimeout(resultExitRedirectTimer)
- resultExitRedirectTimer = 0
- }
- }
- function clearResultExitCountdownTimer() {
- if (resultExitCountdownTimer) {
- clearInterval(resultExitCountdownTimer)
- resultExitCountdownTimer = 0
- }
- }
- function navigateAwayFromMapAfterCancel() {
- const pages = getCurrentPages()
- if (pages.length > 1) {
- wx.navigateBack({
- delta: 1,
- })
- return
- }
- wx.redirectTo({
- url: '/pages/home/home',
- })
- }
- function hasExplicitLaunchOptions(options?: MapPageLaunchOptions | null): boolean {
- if (!options) {
- return false
- }
- return !!(
- options.launchId
- || options.preset
- || options.configUrl
- || options.competitionId
- || options.eventId
- || options.sessionId
- || options.launchRequestId
- )
- }
- function getCurrentBackendSessionContext(): { sessionId: string; sessionToken: string } | null {
- return getBackendSessionContextFromLaunchEnvelope(currentGameLaunchEnvelope)
- }
- function getCurrentBackendBaseUrl(): string {
- const app = getApp<IAppOption>()
- if (app.globalData && app.globalData.backendBaseUrl) {
- return app.globalData.backendBaseUrl
- }
- return loadBackendBaseUrl()
- }
- function buildSideButtonVisibility(mode: SideButtonMode) {
- return {
- sideButtonMode: mode,
- showLeftButtonGroup: mode === 'shown',
- showRightButtonGroups: false,
- showBottomDebugButton: true,
- }
- }
- function getNextSideButtonMode(currentMode: SideButtonMode): SideButtonMode {
- return currentMode === 'shown' ? 'hidden' : 'shown'
- }
- function buildCompassTicks(): CompassTickData[] {
- const ticks: CompassTickData[] = []
- for (let angle = 0; angle < 360; angle += 5) {
- ticks.push({
- angle,
- long: angle % 15 === 0,
- major: angle % 45 === 0,
- })
- }
- return ticks
- }
- function buildCompassLabels(): CompassLabelData[] {
- return [
- { text: '\u5317', angle: 0, rotateBack: 0, radius: 68, className: 'compass-widget__mark--cardinal compass-widget__mark--north' },
- { text: '\u4e1c\u5317', angle: 45, rotateBack: 0, radius: 58, className: 'compass-widget__mark--intermediate compass-widget__mark--northeast' },
- { text: '\u4e1c', angle: 90, rotateBack: 0, radius: 68, className: 'compass-widget__mark--cardinal' },
- { text: '\u4e1c\u5357', angle: 135, rotateBack: 0, radius: 58, className: 'compass-widget__mark--intermediate' },
- { text: '\u5357', angle: 180, rotateBack: 0, radius: 68, className: 'compass-widget__mark--cardinal' },
- { text: '\u897f\u5357', angle: 225, rotateBack: 0, radius: 58, className: 'compass-widget__mark--intermediate' },
- { text: '\u897f', angle: 270, rotateBack: 0, radius: 68, className: 'compass-widget__mark--cardinal' },
- { text: '\u897f\u5317', angle: 315, rotateBack: 0, radius: 58, className: 'compass-widget__mark--intermediate compass-widget__mark--northwest' },
- ]
- }
- function getFallbackStageRect(): MapEngineStageRect {
- const systemInfo = wx.getSystemInfoSync()
- const width = Math.max(320, systemInfo.windowWidth)
- const height = Math.max(280, systemInfo.windowHeight)
- return {
- width,
- height,
- left: 0,
- top: 0,
- }
- }
- function getSideToggleIconSrc(mode: SideButtonMode): string {
- if (mode === 'hidden') {
- return '../../assets/btn_more1.png'
- }
- return '../../assets/btn_more3.png'
- }
- function getSideActionButtonClass(state: SideActionButtonState): string {
- if (state === 'muted') {
- return 'map-side-button map-side-button--muted'
- }
- if (state === 'active') {
- return 'map-side-button map-side-button--active'
- }
- return 'map-side-button map-side-button--default'
- }
- function buildSideButtonState(data: Pick<MapPageData, 'sideButtonMode' | 'showGameInfoPanel' | 'showSystemSettingsPanel' | 'showCenterScaleRuler' | 'centerScaleRulerAnchorMode' | 'skipButtonEnabled' | 'gameSessionStatus' | 'gpsLockEnabled' | 'gpsLockAvailable'>) {
- const sideButton2State: SideActionButtonState = !data.gpsLockAvailable
- ? 'muted'
- : data.gpsLockEnabled
- ? 'active'
- : 'default'
- const sideButton4State: SideActionButtonState = data.gameSessionStatus === 'running' ? 'active' : 'muted'
- const sideButton11State: SideActionButtonState = data.showGameInfoPanel ? 'active' : 'default'
- const sideButton12State: SideActionButtonState = data.showSystemSettingsPanel ? 'active' : 'default'
- const sideButton13State: SideActionButtonState = data.showCenterScaleRuler ? 'active' : 'default'
- const sideButton14State: SideActionButtonState = !data.showCenterScaleRuler
- ? 'muted'
- : data.centerScaleRulerAnchorMode === 'compass-center'
- ? 'active'
- : 'default'
- const sideButton16State: SideActionButtonState = data.skipButtonEnabled ? 'default' : 'muted'
- return {
- sideToggleIconSrc: getSideToggleIconSrc(data.sideButtonMode),
- sideButton2Class: getSideActionButtonClass(sideButton2State),
- sideButton4Class: getSideActionButtonClass(sideButton4State),
- sideButton11Class: getSideActionButtonClass(sideButton11State),
- sideButton12Class: getSideActionButtonClass(sideButton12State),
- sideButton13Class: getSideActionButtonClass(sideButton13State),
- sideButton14Class: getSideActionButtonClass(sideButton14State),
- sideButton16Class: getSideActionButtonClass(sideButton16State),
- }
- }
- function getRpxUnitInPx(): number {
- const systemInfo = wx.getSystemInfoSync()
- return systemInfo.windowWidth / 750
- }
- function worldTileYToLat(worldTileY: number, zoom: number): number {
- const scale = Math.pow(2, zoom)
- const n = Math.PI - (2 * Math.PI * worldTileY) / scale
- return (180 / Math.PI) * Math.atan(Math.sinh(n))
- }
- function getNiceDistanceMeters(rawDistanceMeters: number): number {
- if (!Number.isFinite(rawDistanceMeters) || rawDistanceMeters <= 0) {
- return 50
- }
- const exponent = Math.floor(Math.log10(rawDistanceMeters))
- const base = Math.pow(10, exponent)
- const normalized = rawDistanceMeters / base
- if (normalized <= 1) {
- return base
- }
- if (normalized <= 2) {
- return 2 * base
- }
- if (normalized <= 5) {
- return 5 * base
- }
- return 10 * base
- }
- function formatScaleDistanceLabel(distanceMeters: number): string {
- if (distanceMeters >= 1000) {
- const distanceKm = distanceMeters / 1000
- const formatted = distanceKm >= 10 ? distanceKm.toFixed(0) : distanceKm.toFixed(1)
- return `${formatted.replace(/\.0$/, '')} km`
- }
- return `${Math.round(distanceMeters)} m`
- }
- function buildCenterScaleRulerPatch(data: Pick<MapPageData, 'showCenterScaleRuler' | 'centerScaleRulerAnchorMode' | 'stageWidth' | 'stageHeight' | 'topInsetHeight' | 'zoom' | 'centerTileY' | 'tileSizePx' | 'previewScale'>) {
- if (!data.showCenterScaleRuler) {
- lastCenterScaleRulerStablePatch = {
- centerScaleRulerVisible: false,
- centerScaleRulerCenterXPx: 0,
- centerScaleRulerZeroYPx: 0,
- centerScaleRulerHeightPx: 0,
- centerScaleRulerAxisBottomPx: 0,
- centerScaleRulerZeroVisible: false,
- centerScaleRulerZeroLabel: '0 m',
- centerScaleRulerMinorTicks: [] as ScaleRulerMinorTickData[],
- centerScaleRulerMajorMarks: [] as ScaleRulerMajorMarkData[],
- }
- return { ...lastCenterScaleRulerStablePatch }
- }
- if (!data.stageWidth || !data.stageHeight) {
- return { ...lastCenterScaleRulerStablePatch }
- }
- const topPadding = 12
- const rpxUnitPx = getRpxUnitInPx()
- const compassBottomPaddingPx = 248 * rpxUnitPx
- const compassDialRadiusPx = (196 * rpxUnitPx) / 2
- const compassHeadingOverlayHeightPx = 40 * rpxUnitPx
- const compassOcclusionPaddingPx = 10 * rpxUnitPx
- const zeroYPx = data.centerScaleRulerAnchorMode === 'compass-center'
- ? Math.round(data.stageHeight - compassBottomPaddingPx - compassDialRadiusPx)
- : Math.round(data.stageHeight / 2)
- const fallbackHeight = Math.max(zeroYPx - topPadding, 160)
- const coveredBottomPx = data.centerScaleRulerAnchorMode === 'compass-center'
- ? Math.round(compassDialRadiusPx + compassHeadingOverlayHeightPx + compassOcclusionPaddingPx)
- : 0
- if (
- !data.tileSizePx
- || !Number.isFinite(data.zoom)
- || !Number.isFinite(data.centerTileY)
- ) {
- return {
- ...lastCenterScaleRulerStablePatch,
- centerScaleRulerVisible: true,
- centerScaleRulerCenterXPx: Math.round(data.stageWidth / 2),
- centerScaleRulerZeroYPx: zeroYPx,
- centerScaleRulerHeightPx: lastCenterScaleRulerStablePatch.centerScaleRulerHeightPx || fallbackHeight,
- centerScaleRulerAxisBottomPx: coveredBottomPx,
- centerScaleRulerZeroVisible: data.centerScaleRulerAnchorMode !== 'compass-center',
- }
- }
- const centerLat = worldTileYToLat(data.centerTileY + 0.5, data.zoom)
- const metersPerTile = Math.cos(centerLat * Math.PI / 180) * 40075016.686 / Math.pow(2, data.zoom)
- const metersPerPixel = metersPerTile / data.tileSizePx
- const effectivePreviewScale = Number.isFinite(data.previewScale) && data.previewScale > 0 ? data.previewScale : 1
- const effectiveMetersPerPixel = metersPerPixel / effectivePreviewScale
- const rulerHeight = Math.floor(zeroYPx - topPadding)
- if (!Number.isFinite(effectiveMetersPerPixel) || effectiveMetersPerPixel <= 0 || rulerHeight < 120) {
- return {
- ...lastCenterScaleRulerStablePatch,
- centerScaleRulerVisible: true,
- centerScaleRulerCenterXPx: Math.round(data.stageWidth / 2),
- centerScaleRulerZeroYPx: zeroYPx,
- centerScaleRulerHeightPx: lastCenterScaleRulerStablePatch.centerScaleRulerHeightPx || fallbackHeight,
- centerScaleRulerAxisBottomPx: coveredBottomPx,
- centerScaleRulerZeroVisible: data.centerScaleRulerAnchorMode !== 'compass-center',
- }
- }
- const labelDistanceMeters = getNiceDistanceMeters(effectiveMetersPerPixel * 80)
- const minorDistanceMeters = labelDistanceMeters / 8
- const minorStepPx = minorDistanceMeters / effectiveMetersPerPixel
- const visibleTopLimitPx = rulerHeight - coveredBottomPx
- const minorTicks: ScaleRulerMinorTickData[] = []
- const majorMarks: ScaleRulerMajorMarkData[] = []
- for (let index = 1; index <= 200; index += 1) {
- const topPx = Math.round(rulerHeight - index * minorStepPx)
- if (topPx < 0) {
- break
- }
- if (topPx >= visibleTopLimitPx) {
- continue
- }
- const isHalfMajor = index % 4 === 0
- const isLabelMajor = index % 8 === 0
- minorTicks.push({
- key: `minor-${index}`,
- topPx,
- long: isHalfMajor,
- })
- if (isLabelMajor) {
- majorMarks.push({
- key: `major-${index}`,
- topPx,
- label: formatScaleDistanceLabel((index / 8) * labelDistanceMeters),
- })
- }
- }
- lastCenterScaleRulerStablePatch = {
- centerScaleRulerVisible: true,
- centerScaleRulerCenterXPx: Math.round(data.stageWidth / 2),
- centerScaleRulerZeroYPx: zeroYPx,
- centerScaleRulerHeightPx: rulerHeight,
- centerScaleRulerAxisBottomPx: coveredBottomPx,
- centerScaleRulerZeroVisible: data.centerScaleRulerAnchorMode !== 'compass-center',
- centerScaleRulerZeroLabel: '0 m',
- centerScaleRulerMinorTicks: minorTicks,
- centerScaleRulerMajorMarks: majorMarks,
- }
- return { ...lastCenterScaleRulerStablePatch }
- }
- function buildEmptyGameInfoSnapshot(): MapEngineGameInfoSnapshot {
- return {
- title: '当前游戏',
- subtitle: '未开始',
- localRows: [],
- globalRows: [
- { label: '全球积分', value: '未接入' },
- { label: '全球排名', value: '未接入' },
- { label: '在线人数', value: '未接入' },
- { label: '队伍状态', value: '未接入' },
- { label: '实时广播', value: '未接入' },
- ],
- }
- }
- function buildEmptyResultSceneSnapshot(): MapEngineResultSnapshot {
- return {
- title: '本局结果',
- subtitle: '未开始',
- heroLabel: '本局用时',
- heroValue: '--',
- rows: [],
- }
- }
- function buildRuntimeSummaryRows(envelope: GameLaunchEnvelope): MapEngineGameInfoRow[] {
- const runtime = envelope.runtime
- const variantName = envelope.variant ? (envelope.variant.variantName || envelope.variant.variantId || null) : null
- const variantRouteCode = envelope.variant ? (envelope.variant.routeCode || null) : null
- if (!runtime) {
- return []
- }
- const rows: MapEngineGameInfoRow[] = []
- rows.push({ label: '运行绑定', value: runtime.runtimeBindingId || '--' })
- rows.push({ label: '地点', value: runtime.placeName || runtime.placeId || '--' })
- rows.push({ label: '地图', value: runtime.mapName || runtime.mapId || '--' })
- rows.push({ label: '赛道集', value: runtime.courseSetId || '--' })
- rows.push({ label: '赛道版本', value: runtime.courseVariantId || variantName || '--' })
- rows.push({ label: 'RouteCode', value: runtime.routeCode || variantRouteCode || '--' })
- rows.push({ label: '瓦片版本', value: runtime.tileReleaseId || '--' })
- return rows
- }
- Page({
- data: {
- showDebugPanel: false,
- showGameInfoPanel: false,
- showResultScene: false,
- showSystemSettingsPanel: false,
- showHeartRateDevicePicker: false,
- showCenterScaleRuler: false,
- statusBarHeight: 0,
- topInsetHeight: 12,
- hudPanelIndex: 0,
- configSourceText: '顺序赛配置',
- centerScaleRulerAnchorMode: DEFAULT_STORED_USER_SETTINGS.centerScaleRulerAnchorMode,
- punchHintFxClass: '',
- autoRotateEnabled: DEFAULT_STORED_USER_SETTINGS.autoRotateEnabled,
- ...DEFAULT_SETTING_LOCKS,
- gameInfoTitle: '当前游戏',
- gameInfoSubtitle: '未开始',
- gameInfoLocalRows: [],
- gameInfoGlobalRows: buildEmptyGameInfoSnapshot().globalRows,
- resultSceneTitle: '本局结果',
- resultSceneSubtitle: '未开始',
- resultSceneHeroLabel: '本局用时',
- resultSceneHeroValue: '--',
- resultSceneRows: buildEmptyResultSceneSnapshot().rows,
- resultSceneCountdownText: '',
- panelTimerText: '00:00:00',
- panelTimerMode: 'elapsed',
- panelMileageText: '0m',
- panelActionTagText: '目标',
- panelDistanceTagText: '点距',
- panelTargetSummaryText: '等待选择目标',
- panelDistanceValueText: '--',
- panelDistanceUnitText: '',
- panelProgressText: '0/0',
- showPunchHintBanner: true,
- sideButtonPlacement: 'left',
- gameSessionStatus: 'idle',
- gameModeText: '顺序赛',
- gpsLockEnabled: false,
- gpsLockAvailable: false,
- locationSourceMode: 'real',
- locationSourceText: '真实定位',
- mockBridgeConnected: false,
- mockBridgeStatusText: '未连接',
- mockBridgeUrlText: 'wss://gs.gotomars.xyz/mock-gps',
- mockChannelIdText: 'default',
- mockBridgeUrlDraft: 'wss://gs.gotomars.xyz/mock-gps',
- mockChannelIdDraft: 'default',
- mockCoordText: '--',
- mockSpeedText: '--',
- heartRateSourceMode: 'real',
- heartRateSourceText: '真实心率',
- mockHeartRateBridgeConnected: false,
- mockHeartRateBridgeStatusText: '未连接',
- mockHeartRateBridgeUrlText: 'wss://gs.gotomars.xyz/mock-hr',
- mockHeartRateBridgeUrlDraft: 'wss://gs.gotomars.xyz/mock-hr',
- mockHeartRateText: '--',
- mockDebugLogBridgeConnected: false,
- mockDebugLogBridgeStatusText: '已关闭 (wss://gs.gotomars.xyz/debug-log)',
- mockDebugLogBridgeUrlText: 'wss://gs.gotomars.xyz/debug-log',
- mockDebugLogBridgeUrlDraft: 'wss://gs.gotomars.xyz/debug-log',
- heartRateScanText: '未扫描',
- heartRateDiscoveredDevices: [],
- panelSpeedValueText: '0',
- panelTelemetryTone: 'blue',
- trackDisplayMode: DEFAULT_STORED_USER_SETTINGS.trackDisplayMode,
- trackTailLength: DEFAULT_STORED_USER_SETTINGS.trackTailLength,
- trackColorPreset: DEFAULT_STORED_USER_SETTINGS.trackColorPreset,
- trackStyleProfile: DEFAULT_STORED_USER_SETTINGS.trackStyleProfile,
- gpsMarkerVisible: DEFAULT_STORED_USER_SETTINGS.gpsMarkerVisible,
- gpsMarkerStyle: DEFAULT_STORED_USER_SETTINGS.gpsMarkerStyle,
- gpsMarkerSize: DEFAULT_STORED_USER_SETTINGS.gpsMarkerSize,
- gpsMarkerColorPreset: DEFAULT_STORED_USER_SETTINGS.gpsMarkerColorPreset,
- gpsLogoStatusText: '未配置',
- gpsLogoSourceText: '--',
- panelHeartRateZoneNameText: '--',
- panelHeartRateZoneRangeText: '',
- heartRateConnected: false,
- heartRateStatusText: '心率带未连接',
- heartRateDeviceText: '--',
- panelHeartRateValueText: '--',
- panelHeartRateUnitText: '',
- panelCaloriesValueText: '0',
- panelCaloriesUnitText: 'kcal',
- panelAverageSpeedValueText: '0',
- panelAverageSpeedUnitText: 'km/h',
- panelAccuracyValueText: '--',
- panelAccuracyUnitText: '',
- deviceHeadingText: '--',
- devicePoseText: '竖持',
- headingConfidenceText: '低',
- accelerometerText: '--',
- gyroscopeText: '--',
- deviceMotionText: '--',
- compassSourceText: '无数据',
- compassTuningProfile: DEFAULT_STORED_USER_SETTINGS.compassTuningProfile,
- compassTuningProfileText: '平衡',
- punchButtonText: '打点',
- punchButtonEnabled: false,
- skipButtonEnabled: false,
- punchHintText: '等待进入检查点范围',
- punchFeedbackVisible: false,
- punchFeedbackText: '',
- punchFeedbackTone: 'neutral',
- contentCardVisible: false,
- contentCardTemplate: 'story',
- contentCardTitle: '',
- contentCardBody: '',
- contentCardActions: [],
- contentQuizVisible: false,
- contentQuizQuestionText: '',
- contentQuizCountdownText: '',
- contentQuizOptions: [],
- contentQuizFeedbackVisible: false,
- contentQuizFeedbackText: '',
- contentQuizFeedbackTone: 'neutral',
- punchButtonFxClass: '',
- panelProgressFxClass: '',
- panelDistanceFxClass: '',
- punchFeedbackFxClass: '',
- contentCardFxClass: '',
- mapPulseVisible: false,
- mapPulseLeftPx: 0,
- mapPulseTopPx: 0,
- mapPulseFxClass: '',
- stageFxVisible: false,
- stageFxClass: '',
- centerScaleRulerVisible: false,
- centerScaleRulerCenterXPx: 0,
- centerScaleRulerZeroYPx: 0,
- centerScaleRulerHeightPx: 0,
- centerScaleRulerAxisBottomPx: 0,
- centerScaleRulerZeroVisible: false,
- centerScaleRulerZeroLabel: '0 m',
- centerScaleRulerMinorTicks: [],
- centerScaleRulerMajorMarks: [],
- compassTicks: buildCompassTicks(),
- compassLabels: buildCompassLabels(),
- ...buildSideButtonVisibility('shown'),
- ...buildSideButtonState({
- sideButtonMode: 'shown',
- showGameInfoPanel: false,
- showSystemSettingsPanel: false,
- showCenterScaleRuler: false,
- centerScaleRulerAnchorMode: 'screen-center',
- skipButtonEnabled: false,
- gameSessionStatus: 'idle',
- gpsLockEnabled: false,
- gpsLockAvailable: false,
- }),
- } as unknown as MapPageData,
- onLoad(options: MapPageLaunchOptions) {
- clearSessionRecoveryPersistTimer()
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- syncedBackendSessionStartId = ''
- syncedBackendSessionFinishId = ''
- redirectedToResultPage = false
- shouldAutoRestoreRecoverySnapshot = options && options.recoverSession === '1'
- currentGameLaunchEnvelope = resolveGameLaunchEnvelope(options)
- if (!hasExplicitLaunchOptions(options)) {
- const recoverySnapshot = loadSessionRecoverySnapshot()
- if (recoverySnapshot) {
- currentGameLaunchEnvelope = recoverySnapshot.launchEnvelope
- }
- }
- currentSystemSettingsConfig = undefined
- currentRemoteMapConfig = undefined
- systemSettingsLockLifetimeActive = false
- const storedMockChannelId = loadStoredMockChannelId()
- const shouldAutoConnectMockSources = loadMockAutoConnectEnabled()
- const systemInfo = wx.getSystemInfoSync()
- const statusBarHeight = systemInfo.statusBarHeight || 0
- const menuButtonRect = wx.getMenuButtonBoundingClientRect()
- const menuButtonBottom = menuButtonRect && typeof menuButtonRect.bottom === 'number' ? menuButtonRect.bottom : statusBarHeight
- if (mapEngine) {
- mapEngine.destroy()
- mapEngine = null
- }
- mapEngine = new MapEngine(INTERNAL_BUILD_VERSION, {
- onData: (patch) => {
- const nextPatch = patch as Partial<MapPageData>
- const includeDebugFields = this.data.showDebugPanel
- const includeRulerFields = this.data.showCenterScaleRuler
- let shouldSyncRuntimeSystemSettings = false
- let nextLockLifetimeActive = isSystemSettingsLockLifetimeActive()
- let heartRateSwitchToastText = ''
- const nextData: Partial<MapPageData> = filterDebugOnlyPatch({
- ...nextPatch,
- }, includeDebugFields, includeRulerFields)
- if (
- typeof nextPatch.mockBridgeUrlText === 'string'
- && this.data.mockBridgeUrlDraft === this.data.mockBridgeUrlText
- ) {
- nextData.mockBridgeUrlDraft = nextPatch.mockBridgeUrlText
- }
- if (
- typeof nextPatch.mockHeartRateBridgeUrlText === 'string'
- && this.data.mockHeartRateBridgeUrlDraft === this.data.mockHeartRateBridgeUrlText
- ) {
- nextData.mockHeartRateBridgeUrlDraft = nextPatch.mockHeartRateBridgeUrlText
- }
- if (
- typeof nextPatch.mockDebugLogBridgeUrlText === 'string'
- && this.data.mockDebugLogBridgeUrlDraft === this.data.mockDebugLogBridgeUrlText
- ) {
- nextData.mockDebugLogBridgeUrlDraft = nextPatch.mockDebugLogBridgeUrlText
- }
- if (
- typeof nextPatch.mockChannelIdText === 'string'
- && this.data.mockChannelIdDraft === this.data.mockChannelIdText
- ) {
- nextData.mockChannelIdDraft = nextPatch.mockChannelIdText
- }
- updateCenterScaleRulerInputCache(nextPatch)
- const mergedData = {
- ...centerScaleRulerInputCache,
- ...this.data,
- ...nextData,
- } as MapPageData
- const derivedPatch: Partial<MapPageData> = {}
- if (typeof nextPatch.orientationMode === 'string') {
- nextData.autoRotateEnabled = nextPatch.orientationMode === 'heading-up'
- }
- if (
- this.data.showCenterScaleRuler
- && hasAnyPatchKey(nextPatch as Record<string, unknown>, CENTER_SCALE_RULER_DEP_KEYS)
- ) {
- clearCenterScaleRulerUpdateTimer()
- Object.assign(derivedPatch, buildCenterScaleRulerPatch(mergedData))
- }
- if (hasAnyPatchKey(nextPatch as Record<string, unknown>, SIDE_BUTTON_DEP_KEYS)) {
- Object.assign(derivedPatch, buildSideButtonState(mergedData))
- }
- if (typeof nextPatch.punchHintText === 'string') {
- const nextHintText = nextPatch.punchHintText.trim()
- if (nextHintText !== this.data.punchHintText) {
- clearPunchHintDismissTimer()
- clearPunchHintFxTimer()
- nextData.showPunchHintBanner = nextHintText.length > 0
- if (nextHintText.length > 0) {
- nextData.punchHintFxClass = 'game-punch-hint--fx-enter'
- punchHintFxTimer = setTimeout(() => {
- punchHintFxTimer = 0
- this.setData({
- punchHintFxClass: '',
- })
- }, PUNCH_HINT_FX_DURATION_MS) as unknown as number
- const now = Date.now()
- if (mapEngine && now - lastPunchHintHapticAt >= PUNCH_HINT_HAPTIC_GAP_MS) {
- mapEngine.playPunchHintHaptic()
- lastPunchHintHapticAt = now
- }
- punchHintDismissTimer = setTimeout(() => {
- punchHintDismissTimer = 0
- this.setData({
- showPunchHintBanner: false,
- })
- }, PUNCH_HINT_AUTO_HIDE_MS) as unknown as number
- }
- } else if (!nextHintText) {
- clearPunchHintDismissTimer()
- clearPunchHintFxTimer()
- nextData.showPunchHintBanner = false
- nextData.punchHintFxClass = ''
- }
- }
- const nextAnimationLevel = typeof nextPatch.animationLevel === 'string'
- ? nextPatch.animationLevel
- : this.data.animationLevel
- let shouldSyncBackendSessionStart = false
- let backendSessionFinishStatus: 'finished' | 'failed' | null = null
- let shouldOpenResultExitPrompt = false
- let resultPageSnapshot: MapEngineResultSnapshot | null = null
- if (nextAnimationLevel === 'lite') {
- clearHudFxTimer('timer')
- clearHudFxTimer('mileage')
- clearHudFxTimer('speed')
- clearHudFxTimer('heartRate')
- nextData.panelTimerFxClass = ''
- nextData.panelMileageFxClass = ''
- nextData.panelSpeedFxClass = ''
- nextData.panelHeartRateFxClass = ''
- } else {
- if (typeof nextPatch.panelTimerText === 'string' && nextPatch.panelTimerText !== this.data.panelTimerText && this.data.panelTimerText !== '00:00:00') {
- clearHudFxTimer('timer')
- nextData.panelTimerFxClass = 'race-panel__timer--fx-tick'
- panelTimerFxTimer = setTimeout(() => {
- panelTimerFxTimer = 0
- this.setData({ panelTimerFxClass: '' })
- }, 320) as unknown as number
- }
- if (typeof nextPatch.panelMileageText === 'string' && nextPatch.panelMileageText !== this.data.panelMileageText && this.data.panelMileageText !== '0m') {
- clearHudFxTimer('mileage')
- nextData.panelMileageFxClass = 'race-panel__mileage-wrap--fx-update'
- panelMileageFxTimer = setTimeout(() => {
- panelMileageFxTimer = 0
- this.setData({ panelMileageFxClass: '' })
- }, 360) as unknown as number
- }
- if (typeof nextPatch.panelSpeedValueText === 'string' && nextPatch.panelSpeedValueText !== this.data.panelSpeedValueText && this.data.panelSpeedValueText !== '0') {
- clearHudFxTimer('speed')
- nextData.panelSpeedFxClass = 'race-panel__metric-group--fx-speed-update'
- panelSpeedFxTimer = setTimeout(() => {
- panelSpeedFxTimer = 0
- this.setData({ panelSpeedFxClass: '' })
- }, 360) as unknown as number
- }
- if (typeof nextPatch.panelHeartRateValueText === 'string' && nextPatch.panelHeartRateValueText !== this.data.panelHeartRateValueText && this.data.panelHeartRateValueText !== '--') {
- clearHudFxTimer('heartRate')
- nextData.panelHeartRateFxClass = 'race-panel__metric-group--fx-heart-rate-update'
- panelHeartRateFxTimer = setTimeout(() => {
- panelHeartRateFxTimer = 0
- this.setData({ panelHeartRateFxClass: '' })
- }, 400) as unknown as number
- }
- }
- if (typeof nextPatch.gameSessionStatus === 'string') {
- if (
- nextPatch.gameSessionStatus !== this.data.gameSessionStatus
- && (nextPatch.gameSessionStatus === 'finished' || nextPatch.gameSessionStatus === 'failed')
- ) {
- systemSettingsLockLifetimeActive = false
- nextLockLifetimeActive = false
- shouldSyncRuntimeSystemSettings = true
- clearSessionRecoverySnapshot()
- clearSessionRecoveryPersistTimer()
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- resultPageSnapshot = mapEngine ? mapEngine.getResultSceneSnapshot() : null
- nextData.showResultScene = true
- nextData.showDebugPanel = false
- nextData.showGameInfoPanel = false
- nextData.showSystemSettingsPanel = false
- clearGameInfoPanelSyncTimer()
- backendSessionFinishStatus = nextPatch.gameSessionStatus === 'finished' ? 'finished' : 'failed'
- shouldOpenResultExitPrompt = true
- if (resultPageSnapshot) {
- nextData.resultSceneTitle = resultPageSnapshot.title
- nextData.resultSceneSubtitle = resultPageSnapshot.subtitle
- nextData.resultSceneHeroLabel = resultPageSnapshot.heroLabel
- nextData.resultSceneHeroValue = resultPageSnapshot.heroValue
- nextData.resultSceneRows = resultPageSnapshot.rows
- }
- nextData.resultSceneCountdownText = '3 秒后自动进入成绩页'
- } else if (
- nextPatch.gameSessionStatus !== this.data.gameSessionStatus
- && nextPatch.gameSessionStatus === 'idle'
- && !isSystemSettingsLockLifetimeActive()
- ) {
- nextLockLifetimeActive = false
- shouldSyncRuntimeSystemSettings = true
- clearSessionRecoverySnapshot()
- clearSessionRecoveryPersistTimer()
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- } else if (
- nextPatch.gameSessionStatus !== this.data.gameSessionStatus
- && nextPatch.gameSessionStatus === 'running'
- ) {
- shouldSyncBackendSessionStart = true
- } else if (nextPatch.gameSessionStatus === 'running' || nextPatch.gameSessionStatus === 'idle') {
- nextData.showResultScene = false
- }
- }
- if (
- pendingHeartRateSwitchDeviceName
- && nextPatch.heartRateConnected === true
- && typeof nextPatch.heartRateDeviceText === 'string'
- ) {
- const connectedDeviceName = nextPatch.heartRateDeviceText.trim()
- if (connectedDeviceName && connectedDeviceName === pendingHeartRateSwitchDeviceName) {
- heartRateSwitchToastText = `已切换到 ${connectedDeviceName}`
- nextData.statusText = `已切换心率带:${connectedDeviceName}`
- pendingHeartRateSwitchDeviceName = null
- }
- }
- if (Object.keys(nextData).length || Object.keys(derivedPatch).length) {
- this.setData({
- ...nextData,
- ...derivedPatch,
- }, () => {
- if (typeof nextPatch.gameSessionStatus === 'string') {
- this.syncSessionRecoveryLifecycle(nextPatch.gameSessionStatus)
- }
- if (shouldSyncBackendSessionStart) {
- this.syncBackendSessionStart()
- }
- if (backendSessionFinishStatus) {
- this.syncBackendSessionFinish(backendSessionFinishStatus)
- }
- if (shouldOpenResultExitPrompt && resultPageSnapshot) {
- this.stashPendingResultSnapshot(resultPageSnapshot)
- this.presentResultExitPrompt()
- }
- if (heartRateSwitchToastText) {
- wx.showToast({
- title: `${heartRateSwitchToastText},并设为首选设备`,
- icon: 'none',
- duration: 1800,
- })
- }
- if (shouldSyncRuntimeSystemSettings) {
- this.applyRuntimeSystemSettings(nextLockLifetimeActive)
- }
- if (this.data.showGameInfoPanel) {
- this.scheduleGameInfoPanelSnapshotSync()
- }
- })
- } else {
- if (typeof nextPatch.gameSessionStatus === 'string') {
- this.syncSessionRecoveryLifecycle(nextPatch.gameSessionStatus)
- }
- if (shouldSyncBackendSessionStart) {
- this.syncBackendSessionStart()
- }
- if (backendSessionFinishStatus) {
- this.syncBackendSessionFinish(backendSessionFinishStatus)
- }
- if (shouldOpenResultExitPrompt && resultPageSnapshot) {
- this.stashPendingResultSnapshot(resultPageSnapshot)
- this.presentResultExitPrompt()
- }
- if (shouldSyncRuntimeSystemSettings) {
- this.applyRuntimeSystemSettings(nextLockLifetimeActive)
- }
- if (this.data.showGameInfoPanel) {
- this.scheduleGameInfoPanelSnapshotSync()
- }
- }
- },
- onOpenH5Experience: (request) => {
- this.openH5Experience(request)
- },
- })
- mapEngine.applyTelemetryPlayerProfile(getGlobalTelemetryProfile())
- const systemSettingsState = resolveSystemSettingsState(undefined, undefined, false)
- const initialSystemSettings = systemSettingsState.values
- mapEngine.applyCompiledSettingsProfile({
- values: initialSystemSettings,
- locks: systemSettingsState.locks,
- lockLifetimeActive: false,
- })
- mapEngine.setDiagnosticUiEnabled(false)
- centerScaleRulerInputCache = {
- stageWidth: 0,
- stageHeight: 0,
- zoom: 0,
- centerTileY: 0,
- tileSizePx: 0,
- previewScale: 1,
- }
- const initialEngineData = mapEngine.getInitialData()
- this.setData({
- ...initialEngineData,
- ...buildResolvedSystemSettingsPatch(systemSettingsState),
- showDebugPanel: false,
- showGameInfoPanel: false,
- showResultScene: false,
- showSystemSettingsPanel: false,
- statusBarHeight,
- topInsetHeight: Math.max(statusBarHeight + 12, menuButtonBottom + 20),
- hudPanelIndex: 0,
- configSourceText: currentGameLaunchEnvelope.config.configLabel,
- gameInfoTitle: '当前游戏',
- gameInfoSubtitle: '未开始',
- gameInfoLocalRows: [],
- gameInfoGlobalRows: buildEmptyGameInfoSnapshot().globalRows,
- resultSceneTitle: '本局结果',
- resultSceneSubtitle: '未开始',
- resultSceneHeroLabel: '本局用时',
- resultSceneHeroValue: '--',
- resultSceneRows: buildEmptyResultSceneSnapshot().rows,
- resultSceneCountdownText: '',
- panelTimerText: '00:00:00',
- panelTimerMode: 'elapsed',
- panelTimerFxClass: '',
- panelMileageText: '0m',
- panelMileageFxClass: '',
- panelActionTagText: '目标',
- panelDistanceTagText: '点距',
- panelTargetSummaryText: '等待选择目标',
- panelDistanceValueText: '--',
- panelDistanceUnitText: '',
- panelProgressText: '0/0',
- showPunchHintBanner: true,
- gameSessionStatus: 'idle',
- gameModeText: '顺序赛',
- gpsLockEnabled: false,
- gpsLockAvailable: false,
- locationSourceMode: 'real',
- locationSourceText: '真实定位',
- mockBridgeConnected: false,
- mockBridgeStatusText: '未连接',
- mockBridgeUrlText: 'wss://gs.gotomars.xyz/mock-gps',
- mockChannelIdText: storedMockChannelId,
- mockBridgeUrlDraft: 'wss://gs.gotomars.xyz/mock-gps',
- mockChannelIdDraft: storedMockChannelId,
- mockCoordText: '--',
- mockSpeedText: '--',
- heartRateSourceMode: 'real',
- heartRateSourceText: '真实心率',
- mockHeartRateBridgeConnected: false,
- mockHeartRateBridgeStatusText: '未连接',
- mockHeartRateBridgeUrlText: 'wss://gs.gotomars.xyz/mock-hr',
- mockHeartRateBridgeUrlDraft: 'wss://gs.gotomars.xyz/mock-hr',
- mockHeartRateText: '--',
- mockDebugLogBridgeConnected: false,
- mockDebugLogBridgeStatusText: '已关闭 (wss://gs.gotomars.xyz/debug-log)',
- mockDebugLogBridgeUrlText: 'wss://gs.gotomars.xyz/debug-log',
- mockDebugLogBridgeUrlDraft: 'wss://gs.gotomars.xyz/debug-log',
- panelSpeedValueText: '0',
- panelSpeedFxClass: '',
- panelTelemetryTone: 'blue',
- gpsLogoStatusText: '未配置',
- gpsLogoSourceText: '--',
- panelHeartRateZoneNameText: '--',
- panelHeartRateZoneRangeText: '',
- heartRateConnected: false,
- heartRateStatusText: '心率带未连接',
- heartRateDeviceText: '--',
- panelHeartRateValueText: '--',
- panelHeartRateFxClass: '',
- panelHeartRateUnitText: '',
- panelCaloriesValueText: '0',
- panelCaloriesUnitText: 'kcal',
- panelAverageSpeedValueText: '0',
- panelAverageSpeedUnitText: 'km/h',
- panelAccuracyValueText: '--',
- panelAccuracyUnitText: '',
- deviceHeadingText: '--',
- devicePoseText: '竖持',
- headingConfidenceText: '低',
- accelerometerText: '--',
- gyroscopeText: '--',
- deviceMotionText: '--',
- compassSourceText: '无数据',
- compassTuningProfileText: initialEngineData.compassTuningProfileText || '平衡',
- punchButtonText: '打点',
- punchButtonEnabled: false,
- skipButtonEnabled: false,
- punchHintText: '等待进入检查点范围',
- punchHintFxClass: '',
- punchFeedbackVisible: false,
- punchFeedbackText: '',
- punchFeedbackTone: 'neutral',
- contentCardVisible: false,
- contentCardTemplate: 'story',
- contentCardTitle: '',
- contentCardBody: '',
- contentCardActions: [],
- contentQuizVisible: false,
- contentQuizQuestionText: '',
- contentQuizCountdownText: '',
- contentQuizOptions: [],
- contentQuizFeedbackVisible: false,
- contentQuizFeedbackText: '',
- contentQuizFeedbackTone: 'neutral',
- punchButtonFxClass: '',
- panelProgressFxClass: '',
- panelDistanceFxClass: '',
- punchFeedbackFxClass: '',
- contentCardFxClass: '',
- mapPulseVisible: false,
- mapPulseLeftPx: 0,
- mapPulseTopPx: 0,
- mapPulseFxClass: '',
- stageFxVisible: false,
- stageFxClass: '',
- compassTicks: buildCompassTicks(),
- compassLabels: buildCompassLabels(),
- ...buildSideButtonVisibility('shown'),
- ...buildSideButtonState({
- sideButtonMode: 'shown',
- showGameInfoPanel: false,
- showSystemSettingsPanel: false,
- showCenterScaleRuler: initialSystemSettings.showCenterScaleRuler,
- centerScaleRulerAnchorMode: initialSystemSettings.centerScaleRulerAnchorMode,
- skipButtonEnabled: false,
- gameSessionStatus: 'idle',
- gpsLockEnabled: false,
- gpsLockAvailable: false,
- }),
- ...buildCenterScaleRulerPatch({
- ...(mapEngine.getInitialData() as MapPageData),
- showCenterScaleRuler: initialSystemSettings.showCenterScaleRuler,
- centerScaleRulerAnchorMode: initialSystemSettings.centerScaleRulerAnchorMode,
- stageWidth: 0,
- stageHeight: 0,
- topInsetHeight: Math.max(statusBarHeight + 12, menuButtonBottom + 20),
- zoom: 0,
- centerTileY: 0,
- tileSizePx: 0,
- }),
- }, () => {
- if (shouldAutoConnectMockSources) {
- this.handleConnectAllMockSources()
- }
- })
- },
- onReady() {
- stageCanvasAttached = false
- this.measureStageAndCanvas()
- this.loadGameLaunchEnvelope(currentGameLaunchEnvelope)
- const app = getApp<IAppOption>()
- const pendingHeartRateAutoConnect = app.globalData ? app.globalData.pendingHeartRateAutoConnect : null
- if (pendingHeartRateAutoConnect && pendingHeartRateAutoConnect.enabled && mapEngine) {
- const pendingDeviceName = pendingHeartRateAutoConnect.deviceName || '心率带'
- app.globalData.pendingHeartRateAutoConnect = null
- mapEngine.handleConnectHeartRate()
- this.setData({
- statusText: `正在自动连接局前设备:${pendingDeviceName}`,
- heartRateStatusText: `正在自动连接 ${pendingDeviceName}`,
- heartRateDeviceText: pendingDeviceName,
- })
- }
- },
- onShow() {
- if (mapEngine) {
- this.applyCompiledRuntimeProfiles()
- mapEngine.handleAppShow()
- }
- },
- onHide() {
- this.persistSessionRecoverySnapshot()
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- if (mapEngine) {
- mapEngine.handleAppHide()
- }
- },
- onUnload() {
- this.persistSessionRecoverySnapshot()
- clearSessionRecoveryPersistTimer()
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- syncedBackendSessionStartId = ''
- syncedBackendSessionFinishId = ''
- clearGameInfoPanelSyncTimer()
- clearCenterScaleRulerSyncTimer()
- clearCenterScaleRulerUpdateTimer()
- clearPunchHintDismissTimer()
- clearPunchHintFxTimer()
- clearHudFxTimer('timer')
- clearHudFxTimer('mileage')
- clearHudFxTimer('speed')
- clearHudFxTimer('heartRate')
- if (mapEngine) {
- mapEngine.destroy()
- mapEngine = null
- }
- currentSystemSettingsConfig = undefined
- currentRemoteMapConfig = undefined
- systemSettingsLockLifetimeActive = false
- currentGameLaunchEnvelope = getDemoGameLaunchEnvelope()
- shouldAutoRestoreRecoverySnapshot = false
- redirectedToResultPage = false
- stageCanvasAttached = false
- },
- loadGameLaunchEnvelope(envelope: GameLaunchEnvelope) {
- this.loadMapConfigFromRemote(
- envelope.config.configUrl,
- envelope.config.configLabel,
- )
- },
- persistSessionRecoverySnapshot() {
- if (!mapEngine || !currentRemoteMapConfig) {
- return false
- }
- const runtimeSnapshot = mapEngine.buildSessionRecoveryRuntimeSnapshot()
- if (!runtimeSnapshot) {
- return false
- }
- const snapshot: SessionRecoverySnapshot = {
- schemaVersion: 1,
- savedAt: Date.now(),
- launchEnvelope: currentGameLaunchEnvelope,
- configAppId: currentRemoteMapConfig.configAppId,
- configVersion: currentRemoteMapConfig.configVersion,
- runtime: runtimeSnapshot,
- }
- saveSessionRecoverySnapshot(snapshot)
- return true
- },
- syncBackendSessionStart() {
- const sessionContext = getCurrentBackendSessionContext()
- if (!sessionContext || syncedBackendSessionStartId === sessionContext.sessionId) {
- return
- }
- startSession({
- baseUrl: getCurrentBackendBaseUrl(),
- sessionId: sessionContext.sessionId,
- sessionToken: sessionContext.sessionToken,
- })
- .then(() => {
- syncedBackendSessionStartId = sessionContext.sessionId
- })
- .catch((error) => {
- const message = error && error.message ? error.message : '未知错误'
- this.setData({
- statusText: `session start 上报失败: ${message}`,
- })
- })
- },
- syncBackendSessionFinish(statusOverride?: 'finished' | 'failed' | 'cancelled') {
- const sessionContext = getCurrentBackendSessionContext()
- if (!sessionContext || syncedBackendSessionFinishId === sessionContext.sessionId || !mapEngine) {
- return
- }
- const finishSummary = mapEngine.getSessionFinishSummary(statusOverride)
- if (!finishSummary) {
- return
- }
- const summaryPayload: BackendSessionFinishSummaryPayload = {}
- if (typeof finishSummary.finalDurationSec === 'number') {
- summaryPayload.finalDurationSec = finishSummary.finalDurationSec
- }
- if (typeof finishSummary.finalScore === 'number') {
- summaryPayload.finalScore = finishSummary.finalScore
- }
- if (typeof finishSummary.completedControls === 'number') {
- summaryPayload.completedControls = finishSummary.completedControls
- }
- if (typeof finishSummary.totalControls === 'number') {
- summaryPayload.totalControls = finishSummary.totalControls
- }
- if (typeof finishSummary.distanceMeters === 'number') {
- summaryPayload.distanceMeters = finishSummary.distanceMeters
- }
- if (typeof finishSummary.averageSpeedKmh === 'number') {
- summaryPayload.averageSpeedKmh = finishSummary.averageSpeedKmh
- }
- finishSession({
- baseUrl: getCurrentBackendBaseUrl(),
- sessionId: sessionContext.sessionId,
- sessionToken: sessionContext.sessionToken,
- status: finishSummary.status,
- summary: summaryPayload,
- })
- .then(() => {
- syncedBackendSessionFinishId = sessionContext.sessionId
- })
- .catch((error) => {
- const message = error && error.message ? error.message : '未知错误'
- this.setData({
- statusText: `session finish 上报失败: ${message}`,
- })
- })
- },
- reportAbandonedRecoverySnapshot(snapshot: SessionRecoverySnapshot) {
- const sessionContext = getBackendSessionContextFromLaunchEnvelope(snapshot.launchEnvelope)
- if (!sessionContext) {
- clearSessionRecoverySnapshot()
- return
- }
- finishSession({
- baseUrl: getCurrentBackendBaseUrl(),
- sessionId: sessionContext.sessionId,
- sessionToken: sessionContext.sessionToken,
- status: 'cancelled',
- summary: {},
- })
- .then(() => {
- syncedBackendSessionFinishId = sessionContext.sessionId
- clearSessionRecoverySnapshot()
- wx.showToast({
- title: '已放弃上次对局',
- icon: 'none',
- duration: 1400,
- })
- })
- .catch((error) => {
- clearSessionRecoverySnapshot()
- const message = error && error.message ? error.message : '未知错误'
- this.setData({
- statusText: `放弃恢复已生效,后端取消上报失败: ${message}`,
- })
- wx.showToast({
- title: '已放弃上次对局',
- icon: 'none',
- duration: 1400,
- })
- })
- },
- stashPendingResultSnapshot(snapshot: MapEngineResultSnapshot) {
- const app = getApp<IAppOption>()
- if (app.globalData) {
- app.globalData.pendingResultSnapshot = snapshot
- app.globalData.pendingResultLaunchEnvelope = currentGameLaunchEnvelope
- }
- },
- redirectToResultPage() {
- if (redirectedToResultPage) {
- return
- }
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- redirectedToResultPage = true
- const sessionContext = getCurrentBackendSessionContext()
- const resultUrl = sessionContext
- ? `/pages/result/result?sessionId=${encodeURIComponent(sessionContext.sessionId)}`
- : '/pages/result/result'
- wx.redirectTo({
- url: resultUrl,
- })
- },
- presentResultExitPrompt() {
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- let remainingSeconds = Math.ceil(RESULT_EXIT_REDIRECT_DELAY_MS / 1000)
- this.setData({
- showResultScene: true,
- resultSceneCountdownText: `${remainingSeconds} 秒后自动进入成绩页`,
- })
- resultExitCountdownTimer = setInterval(() => {
- remainingSeconds -= 1
- if (remainingSeconds <= 0) {
- clearResultExitCountdownTimer()
- return
- }
- this.setData({
- resultSceneCountdownText: `${remainingSeconds} 秒后自动进入成绩页`,
- })
- }, 1000) as unknown as number
- resultExitRedirectTimer = setTimeout(() => {
- resultExitRedirectTimer = 0
- this.redirectToResultPage()
- }, RESULT_EXIT_REDIRECT_DELAY_MS) as unknown as number
- },
- restoreRecoverySnapshot(snapshot: SessionRecoverySnapshot) {
- systemSettingsLockLifetimeActive = true
- this.applyRuntimeSystemSettings(true)
- const restored = mapEngine ? mapEngine.restoreSessionRecoveryRuntimeSnapshot(snapshot.runtime) : false
- if (!restored) {
- clearSessionRecoverySnapshot()
- wx.showToast({
- title: '恢复失败,已回到初始状态',
- icon: 'none',
- duration: 1600,
- })
- return false
- }
- this.setData({
- showResultScene: false,
- showDebugPanel: false,
- showGameInfoPanel: false,
- showSystemSettingsPanel: false,
- })
- const sessionContext = getCurrentBackendSessionContext()
- if (sessionContext) {
- syncedBackendSessionStartId = sessionContext.sessionId
- }
- this.syncSessionRecoveryLifecycle('running')
- return true
- },
- syncSessionRecoveryLifecycle(status: MapPageData['gameSessionStatus']) {
- if (status === 'running') {
- this.persistSessionRecoverySnapshot()
- if (!sessionRecoveryPersistTimer) {
- sessionRecoveryPersistTimer = setInterval(() => {
- this.persistSessionRecoverySnapshot()
- }, SESSION_RECOVERY_PERSIST_INTERVAL_MS) as unknown as number
- }
- return
- }
- clearSessionRecoveryPersistTimer()
- },
- maybePromptSessionRecoveryRestore(config: RemoteMapConfig) {
- const snapshot = loadSessionRecoverySnapshot()
- if (!snapshot || !mapEngine) {
- return
- }
- if (
- snapshot.launchEnvelope.config.configUrl !== currentGameLaunchEnvelope.config.configUrl
- || snapshot.configAppId !== config.configAppId
- || snapshot.configVersion !== config.configVersion
- ) {
- clearSessionRecoverySnapshot()
- return
- }
- if (shouldAutoRestoreRecoverySnapshot) {
- shouldAutoRestoreRecoverySnapshot = false
- this.restoreRecoverySnapshot(snapshot)
- return
- }
- wx.showModal({
- title: '恢复对局',
- content: '检测到上次有未正常结束的对局,是否继续恢复?',
- confirmText: '继续恢复',
- cancelText: '放弃',
- success: (result) => {
- if (!result.confirm) {
- this.reportAbandonedRecoverySnapshot(snapshot)
- return
- }
- this.restoreRecoverySnapshot(snapshot)
- },
- })
- },
- compileCurrentRuntimeProfile(lockLifetimeActive = isSystemSettingsLockLifetimeActive()) {
- if (!currentRemoteMapConfig) {
- return null
- }
- return compileRuntimeProfile(currentRemoteMapConfig, {
- playerTelemetryProfile: getGlobalTelemetryProfile(),
- settingsLockLifetimeActive: lockLifetimeActive,
- })
- },
- applyCompiledRuntimeProfiles(
- lockLifetimeActive = isSystemSettingsLockLifetimeActive(),
- options?: {
- includeSettings?: boolean
- includeMap?: boolean
- includeGame?: boolean
- includePresentation?: boolean
- includeTelemetry?: boolean
- includeFeedback?: boolean
- },
- ) {
- const currentEngine = mapEngine
- if (!currentEngine) {
- return null
- }
- const compiledProfile = this.compileCurrentRuntimeProfile(lockLifetimeActive)
- if (!compiledProfile) {
- return null
- }
- if (options && options.includeMap) {
- currentEngine.applyCompiledMapProfile(compiledProfile.map)
- }
- if (options && options.includeSettings) {
- currentEngine.applyCompiledSettingsProfile(compiledProfile.settings)
- }
- if (options && options.includeGame) {
- currentEngine.applyCompiledGameProfile(compiledProfile.game)
- }
- if (options && options.includePresentation) {
- currentEngine.applyCompiledPresentationProfile(compiledProfile.presentation)
- }
- if (!options || options.includeTelemetry !== false) {
- currentEngine.applyCompiledTelemetryProfile(compiledProfile.telemetry)
- }
- if (!options || options.includeFeedback !== false) {
- currentEngine.applyCompiledFeedbackProfile(compiledProfile.feedback)
- }
- return compiledProfile
- },
- applyRuntimeSystemSettings(lockLifetimeActive = isSystemSettingsLockLifetimeActive()) {
- const currentEngine = mapEngine
- if (!currentEngine) {
- return null
- }
- const compiledProfile = this.applyCompiledRuntimeProfiles(lockLifetimeActive, {
- includeSettings: true,
- })
- || {
- settings: resolveSystemSettingsState(
- currentSystemSettingsConfig,
- undefined,
- lockLifetimeActive,
- ),
- }
- const resolvedSettings = compiledProfile.settings
- const engineSnapshot = currentEngine.getInitialData() as Partial<MapPageData>
- updateCenterScaleRulerInputCache(engineSnapshot)
- const resolvedPatch = buildResolvedSystemSettingsPatch(resolvedSettings)
- const mergedData = {
- ...centerScaleRulerInputCache,
- ...this.data,
- ...engineSnapshot,
- ...resolvedPatch,
- } as MapPageData
- this.setData({
- ...filterDebugOnlyPatch(engineSnapshot, this.data.showDebugPanel, resolvedSettings.values.showCenterScaleRuler),
- ...resolvedPatch,
- ...buildCenterScaleRulerPatch(mergedData),
- ...buildSideButtonState(mergedData),
- })
- return resolvedSettings
- },
- persistAndApplySystemSettings(
- patch: Partial<StoredUserSettings>,
- options?: {
- applyCenterScaleRuler?: boolean
- },
- ) {
- updateStoredUserSettings(patch)
- const lockLifetimeActive = isSystemSettingsLockLifetimeActive()
- const resolvedSettings = this.applyRuntimeSystemSettings(lockLifetimeActive)
- if (!resolvedSettings || !(options && options.applyCenterScaleRuler)) {
- return resolvedSettings
- }
- this.applyCenterScaleRulerSettings(
- resolvedSettings.values.showCenterScaleRuler,
- resolvedSettings.values.centerScaleRulerAnchorMode,
- )
- return resolvedSettings
- },
- loadMapConfigFromRemote(configUrl: string, configLabel: string) {
- const currentEngine = mapEngine
- if (!currentEngine) {
- return
- }
- this.setData({
- configSourceText: configLabel,
- configStatusText: `加载中: ${configLabel}`,
- })
- loadRemoteMapConfig(configUrl)
- .then((config) => {
- if (mapEngine !== currentEngine) {
- return
- }
- currentEngine.applyRemoteMapConfig(config)
- this.applyConfiguredSystemSettings(config)
- this.applyCompiledRuntimeProfiles(true, {
- includeMap: true,
- includeGame: true,
- includePresentation: true,
- })
- this.maybePromptSessionRecoveryRestore(config)
- })
- .catch((error) => {
- if (mapEngine !== currentEngine) {
- return
- }
- const rawErrorMessage = error && error.message ? error.message : '未知错误'
- const errorMessage = rawErrorMessage.indexOf('404') >= 0
- ? `release manifest 不存在或未发布 (${configLabel})`
- : rawErrorMessage
- this.setData({
- configStatusText: `载入失败: ${errorMessage}`,
- statusText: `远程地图配置载入失败: ${errorMessage} (${INTERNAL_BUILD_VERSION})`,
- })
- })
- },
- applyConfiguredSystemSettings(config: RemoteMapConfig) {
- currentRemoteMapConfig = config
- currentSystemSettingsConfig = config.systemSettingsConfig
- systemSettingsLockLifetimeActive = true
- this.applyRuntimeSystemSettings(true)
- },
- measureStageAndCanvas(onApplied?: () => void) {
- const page = this
- const applyStage = (rawRect?: Partial<WechatMiniprogram.BoundingClientRectCallbackResult>) => {
- const fallbackRect = getFallbackStageRect()
- const rect: MapEngineStageRect = {
- width: rawRect && typeof rawRect.width === 'number' ? rawRect.width : fallbackRect.width,
- height: rawRect && typeof rawRect.height === 'number' ? rawRect.height : fallbackRect.height,
- left: rawRect && typeof rawRect.left === 'number' ? rawRect.left : fallbackRect.left,
- top: rawRect && typeof rawRect.top === 'number' ? rawRect.top : fallbackRect.top,
- }
- const currentEngine = mapEngine
- if (!currentEngine) {
- return
- }
- currentEngine.setStage(rect)
- if (onApplied) {
- onApplied()
- }
- if (stageCanvasAttached) {
- return
- }
- const canvasQuery = wx.createSelectorQuery().in(page)
- canvasQuery.select('#mapCanvas').fields({ node: true, size: true })
- canvasQuery.select('#routeLabelCanvas').fields({ node: true, size: true })
- canvasQuery.exec((canvasRes) => {
- const canvasRef = canvasRes[0] as any
- const labelCanvasRef = canvasRes[1] as any
- if (!canvasRef || !canvasRef.node) {
- page.setData({
- statusText: `WebGL 引擎初始化失败 (${INTERNAL_BUILD_VERSION})`,
- })
- return
- }
- const dpr = wx.getSystemInfoSync().pixelRatio || 1
- try {
- currentEngine.attachCanvas(
- canvasRef.node,
- rect.width,
- rect.height,
- dpr,
- labelCanvasRef && labelCanvasRef.node ? labelCanvasRef.node : undefined,
- )
- stageCanvasAttached = true
- } catch (error) {
- page.setData({
- statusText: `WebGL 鍒濆鍖栧け璐?(${INTERNAL_BUILD_VERSION})`,
- })
- }
- })
- }
- const query = wx.createSelectorQuery().in(page)
- query.select('.map-stage').boundingClientRect()
- query.exec((res) => {
- const rect = res[0] as WechatMiniprogram.BoundingClientRectCallbackResult | undefined
- applyStage(rect)
- })
- },
- handleTouchStart(event: WechatMiniprogram.TouchEvent) {
- if (mapEngine) {
- mapEngine.handleTouchStart(event)
- }
- },
- handleTouchMove(event: WechatMiniprogram.TouchEvent) {
- if (mapEngine) {
- mapEngine.handleTouchMove(event)
- }
- },
- handleTouchEnd(event: WechatMiniprogram.TouchEvent) {
- if (mapEngine) {
- mapEngine.handleTouchEnd(event)
- }
- },
- handleTouchCancel() {
- if (mapEngine) {
- mapEngine.handleTouchCancel()
- }
- },
- handleRecenter() {
- if (mapEngine) {
- mapEngine.handleRecenter()
- }
- },
- handleRotateStep() {
- if (mapEngine) {
- mapEngine.handleRotateStep()
- }
- },
- handleRotationReset() {
- if (mapEngine) {
- mapEngine.handleRotationReset()
- }
- },
- handleSetManualMode() {
- if (mapEngine) {
- mapEngine.handleSetManualMode()
- }
- },
- handleSetNorthUpMode() {
- if (mapEngine) {
- mapEngine.handleSetNorthUpMode()
- }
- },
- handleSetHeadingUpMode() {
- if (mapEngine) {
- mapEngine.handleSetHeadingUpMode()
- }
- },
- handleCycleNorthReferenceMode() {
- if (mapEngine) {
- mapEngine.handleCycleNorthReferenceMode()
- }
- },
- handleAutoRotateCalibrate() {
- if (mapEngine) {
- mapEngine.handleAutoRotateCalibrate()
- }
- },
- handleToggleGpsTracking() {
- if (mapEngine) {
- mapEngine.handleToggleGpsTracking()
- }
- },
- handleSetRealLocationMode() {
- if (mapEngine) {
- mapEngine.handleSetRealLocationMode()
- }
- },
- handleSetMockLocationMode() {
- if (mapEngine) {
- mapEngine.handleSetMockLocationMode()
- }
- },
- handleConnectMockLocationBridge() {
- if (mapEngine) {
- mapEngine.handleConnectMockLocationBridge()
- }
- },
- handleConnectAllMockSources() {
- if (!mapEngine) {
- return
- }
- const channelId = (this.data.mockChannelIdDraft || '').trim() || 'default'
- this.setData({
- mockChannelIdDraft: channelId,
- })
- persistMockChannelId(channelId)
- persistMockAutoConnectEnabled(true)
- mapEngine.handleSetMockChannelId(channelId)
- mapEngine.handleSetMockLocationBridgeUrl(this.data.mockBridgeUrlDraft)
- mapEngine.handleSetMockHeartRateBridgeUrl(this.data.mockHeartRateBridgeUrlDraft)
- mapEngine.handleSetMockDebugLogBridgeUrl(this.data.mockDebugLogBridgeUrlDraft)
- mapEngine.handleConnectMockLocationBridge()
- mapEngine.handleSetMockLocationMode()
- mapEngine.handleSetMockHeartRateMode()
- mapEngine.handleConnectMockHeartRateBridge()
- mapEngine.handleConnectMockDebugLogBridge()
- },
- handleOpenWebViewTest() {
- wx.navigateTo({
- url: '/pages/webview-test/webview-test',
- })
- },
- handleMockChannelIdInput(event: WechatMiniprogram.Input) {
- this.setData({
- mockChannelIdDraft: event.detail.value,
- })
- },
- handleSaveMockChannelId() {
- const channelId = (this.data.mockChannelIdDraft || '').trim() || 'default'
- this.setData({
- mockChannelIdDraft: channelId,
- })
- persistMockChannelId(channelId)
- if (mapEngine) {
- mapEngine.handleSetMockChannelId(channelId)
- }
- },
- handleMockBridgeUrlInput(event: WechatMiniprogram.Input) {
- this.setData({
- mockBridgeUrlDraft: event.detail.value,
- })
- },
- handleSaveMockBridgeUrl() {
- if (mapEngine) {
- mapEngine.handleSetMockLocationBridgeUrl(this.data.mockBridgeUrlDraft)
- }
- },
- handleDisconnectMockLocationBridge() {
- persistMockAutoConnectEnabled(false)
- if (mapEngine) {
- mapEngine.handleDisconnectMockLocationBridge()
- }
- },
- handleSetRealHeartRateMode() {
- if (mapEngine) {
- mapEngine.handleSetRealHeartRateMode()
- }
- },
- handleSetMockHeartRateMode() {
- if (mapEngine) {
- mapEngine.handleSetMockHeartRateMode()
- }
- },
- handleMockHeartRateBridgeUrlInput(event: WechatMiniprogram.Input) {
- this.setData({
- mockHeartRateBridgeUrlDraft: event.detail.value,
- })
- },
- handleSaveMockHeartRateBridgeUrl() {
- if (mapEngine) {
- mapEngine.handleSetMockHeartRateBridgeUrl(this.data.mockHeartRateBridgeUrlDraft)
- }
- },
- handleMockDebugLogBridgeUrlInput(event: WechatMiniprogram.Input) {
- this.setData({
- mockDebugLogBridgeUrlDraft: event.detail.value,
- })
- },
- handleSaveMockDebugLogBridgeUrl() {
- if (mapEngine) {
- mapEngine.handleSetMockDebugLogBridgeUrl(this.data.mockDebugLogBridgeUrlDraft)
- }
- },
- handleConnectMockDebugLogBridge() {
- if (mapEngine) {
- mapEngine.handleConnectMockDebugLogBridge()
- }
- },
- handleDisconnectMockDebugLogBridge() {
- persistMockAutoConnectEnabled(false)
- if (mapEngine) {
- mapEngine.handleDisconnectMockDebugLogBridge()
- }
- },
- handleConnectMockHeartRateBridge() {
- if (mapEngine) {
- mapEngine.handleConnectMockHeartRateBridge()
- }
- },
- handleDisconnectMockHeartRateBridge() {
- persistMockAutoConnectEnabled(false)
- if (mapEngine) {
- mapEngine.handleDisconnectMockHeartRateBridge()
- }
- },
- handleConnectHeartRate() {
- if (this.data.lockHeartRateDevice || this.data.heartRateSourceMode !== 'real') {
- return
- }
- if (mapEngine) {
- mapEngine.handleConnectHeartRate()
- }
- },
- handleOpenHeartRateDevicePicker() {
- if (this.data.lockHeartRateDevice || this.data.heartRateSourceMode !== 'real') {
- return
- }
- this.setData({
- showHeartRateDevicePicker: true,
- })
- if (mapEngine) {
- mapEngine.handleConnectHeartRate()
- }
- },
- handleCloseHeartRateDevicePicker() {
- this.setData({
- showHeartRateDevicePicker: false,
- })
- },
- handleDisconnectHeartRate() {
- if (this.data.lockHeartRateDevice || this.data.heartRateSourceMode !== 'real') {
- return
- }
- if (mapEngine) {
- mapEngine.handleDisconnectHeartRate()
- }
- },
- handleConnectHeartRateDevice(event: WechatMiniprogram.BaseEvent<{ deviceId?: string }>) {
- if (mapEngine && event.currentTarget && event.currentTarget.dataset && event.currentTarget.dataset.deviceId) {
- const targetDeviceId = event.currentTarget.dataset.deviceId
- const targetDevice = this.data.heartRateDiscoveredDevices.find((item) => item.deviceId === targetDeviceId)
- pendingHeartRateSwitchDeviceName = targetDevice ? targetDevice.name : null
- mapEngine.handleConnectHeartRateDevice(targetDeviceId)
- this.setData({
- showHeartRateDevicePicker: false,
- statusText: targetDevice
- ? `正在切换到 ${targetDevice.name}`
- : '正在切换心率带设备',
- })
- }
- },
- handleClearPreferredHeartRateDevice() {
- if (this.data.lockHeartRateDevice) {
- return
- }
- if (mapEngine) {
- mapEngine.handleClearPreferredHeartRateDevice()
- }
- },
- handleDebugHeartRateBlue() {
- if (mapEngine) {
- mapEngine.handleDebugHeartRateTone('blue')
- }
- },
- handleDebugHeartRatePurple() {
- if (mapEngine) {
- mapEngine.handleDebugHeartRateTone('purple')
- }
- },
- handleDebugHeartRateGreen() {
- if (mapEngine) {
- mapEngine.handleDebugHeartRateTone('green')
- }
- },
- handleDebugHeartRateYellow() {
- if (mapEngine) {
- mapEngine.handleDebugHeartRateTone('yellow')
- }
- },
- handleDebugHeartRateOrange() {
- if (mapEngine) {
- mapEngine.handleDebugHeartRateTone('orange')
- }
- },
- handleDebugHeartRateRed() {
- if (mapEngine) {
- mapEngine.handleDebugHeartRateTone('red')
- }
- },
- handleDebugSetSessionRemainingWarning() {
- if (mapEngine) {
- mapEngine.handleDebugSetSessionRemainingWarning()
- }
- },
- handleDebugSetSessionRemainingOneMinute() {
- if (mapEngine) {
- mapEngine.handleDebugSetSessionRemainingOneMinute()
- }
- },
- handleDebugTimeoutSession() {
- if (mapEngine) {
- mapEngine.handleDebugTimeoutSession()
- }
- },
- handleClearDebugHeartRate() {
- if (mapEngine) {
- mapEngine.handleClearDebugHeartRate()
- }
- },
- handleToggleOsmReference() {
- if (mapEngine) {
- mapEngine.handleToggleOsmReference()
- }
- },
- handleStartGame() {
- if (mapEngine) {
- systemSettingsLockLifetimeActive = true
- this.applyRuntimeSystemSettings(true)
- mapEngine.handleStartGame()
- }
- },
- handleLoadClassicConfig() {
- currentGameLaunchEnvelope = getDemoGameLaunchEnvelope('classic')
- this.loadGameLaunchEnvelope(currentGameLaunchEnvelope)
- },
- handleLoadScoreOConfig() {
- currentGameLaunchEnvelope = getDemoGameLaunchEnvelope('score-o')
- this.loadGameLaunchEnvelope(currentGameLaunchEnvelope)
- },
- handleForceExitGame() {
- if (!mapEngine || this.data.gameSessionStatus !== 'running') {
- return
- }
- wx.showModal({
- title: '确认退出',
- content: '确认强制结束当前对局并返回开始前状态?',
- confirmText: '确认退出',
- cancelText: '取消',
- success: (result) => {
- if (result.confirm && mapEngine) {
- clearResultExitRedirectTimer()
- clearResultExitCountdownTimer()
- this.syncBackendSessionFinish('cancelled')
- clearSessionRecoverySnapshot()
- clearSessionRecoveryPersistTimer()
- systemSettingsLockLifetimeActive = false
- mapEngine.handleForceExitGame()
- wx.showToast({
- title: '已退出当前对局',
- icon: 'none',
- duration: 1000,
- })
- setTimeout(() => {
- navigateAwayFromMapAfterCancel()
- }, 180)
- }
- },
- })
- },
- handleSkipAction() {
- if (!mapEngine || !this.data.skipButtonEnabled) {
- return
- }
- if (!mapEngine.shouldConfirmSkipAction()) {
- mapEngine.handleSkipAction()
- return
- }
- wx.showModal({
- title: '确认跳点',
- content: '确认跳过当前检查点并切换到下一个目标点?',
- confirmText: '确认跳过',
- cancelText: '取消',
- success: (result) => {
- if (result.confirm && mapEngine) {
- mapEngine.handleSkipAction()
- }
- },
- })
- },
- handleClearMapTestArtifacts() {
- if (mapEngine) {
- mapEngine.handleClearMapTestArtifacts()
- }
- },
- syncGameInfoPanelSnapshot() {
- if (!mapEngine) {
- return
- }
- const snapshot = mapEngine.getGameInfoSnapshot()
- const localRows = snapshot.localRows.concat([
- ...buildRuntimeSummaryRows(currentGameLaunchEnvelope),
- { label: '比例尺开关', value: this.data.showCenterScaleRuler ? '开启' : '关闭' },
- { label: '比例尺锚点', value: this.data.centerScaleRulerAnchorMode === 'compass-center' ? '指北针圆心' : '屏幕中心' },
- { label: '按钮习惯', value: this.data.sideButtonPlacement === 'right' ? '右手' : '左手' },
- { label: '比例尺可见', value: this.data.centerScaleRulerVisible ? 'true' : 'false' },
- { label: '比例尺中心X', value: `${this.data.centerScaleRulerCenterXPx}px` },
- { label: '比例尺零点Y', value: `${this.data.centerScaleRulerZeroYPx}px` },
- { label: '比例尺高度', value: `${this.data.centerScaleRulerHeightPx}px` },
- { label: '比例尺主刻度数', value: String(this.data.centerScaleRulerMajorMarks.length) },
- ])
- this.setData({
- gameInfoTitle: snapshot.title,
- gameInfoSubtitle: snapshot.subtitle,
- gameInfoLocalRows: localRows,
- gameInfoGlobalRows: snapshot.globalRows,
- })
- },
- syncResultSceneSnapshot() {
- if (!mapEngine) {
- return
- }
- const snapshot = mapEngine.getResultSceneSnapshot()
- this.setData({
- resultSceneTitle: snapshot.title,
- resultSceneSubtitle: snapshot.subtitle,
- resultSceneHeroLabel: snapshot.heroLabel,
- resultSceneHeroValue: snapshot.heroValue,
- resultSceneRows: snapshot.rows.concat(buildRuntimeSummaryRows(currentGameLaunchEnvelope)),
- })
- },
- scheduleGameInfoPanelSnapshotSync() {
- if (!this.data.showGameInfoPanel) {
- clearGameInfoPanelSyncTimer()
- return
- }
- if (gameInfoPanelSyncTimer) {
- return
- }
- gameInfoPanelSyncTimer = setTimeout(() => {
- gameInfoPanelSyncTimer = 0
- if (this.data.showGameInfoPanel) {
- this.syncGameInfoPanelSnapshot()
- }
- }, 400) as unknown as number
- },
- handleOpenGameInfoPanel() {
- clearGameInfoPanelSyncTimer()
- this.syncGameInfoPanelSnapshot()
- this.setData({
- showDebugPanel: false,
- showSystemSettingsPanel: false,
- showGameInfoPanel: true,
- ...buildSideButtonState({
- sideButtonMode: this.data.sideButtonMode,
- showGameInfoPanel: true,
- showSystemSettingsPanel: false,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- handleCloseGameInfoPanel() {
- clearGameInfoPanelSyncTimer()
- this.setData({
- showGameInfoPanel: false,
- ...buildSideButtonState({
- sideButtonMode: this.data.sideButtonMode,
- showGameInfoPanel: false,
- showSystemSettingsPanel: this.data.showSystemSettingsPanel,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- handleGameInfoPanelTap() {},
- handleResultSceneTap() {},
- handleCloseResultScene() {
- this.redirectToResultPage()
- },
- handleRestartFromResult() {
- this.redirectToResultPage()
- },
- handleOpenSystemSettingsPanel() {
- clearGameInfoPanelSyncTimer()
- this.setData({
- showDebugPanel: false,
- showGameInfoPanel: false,
- showSystemSettingsPanel: true,
- ...buildSideButtonState({
- sideButtonMode: this.data.sideButtonMode,
- showGameInfoPanel: false,
- showSystemSettingsPanel: true,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- handleCloseSystemSettingsPanel() {
- this.setData({
- showSystemSettingsPanel: false,
- ...buildSideButtonState({
- sideButtonMode: this.data.sideButtonMode,
- showGameInfoPanel: this.data.showGameInfoPanel,
- showSystemSettingsPanel: false,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- handleSystemSettingsPanelTap() {},
- handleSetAnimationLevelStandard() {
- if (this.data.lockAnimationLevel || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- animationLevel: 'standard',
- })
- },
- handleSetAnimationLevelLite() {
- if (this.data.lockAnimationLevel || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- animationLevel: 'lite',
- })
- },
- handleSetTrackModeNone() {
- if (this.data.lockTrackMode || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackDisplayMode: 'none',
- })
- },
- handleSetTrackModeTail() {
- if (this.data.lockTrackMode || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackDisplayMode: 'tail',
- })
- },
- handleSetTrackModeFull() {
- if (this.data.lockTrackMode || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackDisplayMode: 'full',
- })
- },
- handleSetTrackTailLengthShort() {
- if (this.data.lockTrackTailLength || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackTailLength: 'short',
- })
- },
- handleSetTrackTailLengthMedium() {
- if (this.data.lockTrackTailLength || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackTailLength: 'medium',
- })
- },
- handleSetTrackTailLengthLong() {
- if (this.data.lockTrackTailLength || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackTailLength: 'long',
- })
- },
- handleSetTrackColorPreset(event: WechatMiniprogram.TouchEvent) {
- if (this.data.lockTrackColor || !mapEngine) {
- return
- }
- const color = event.currentTarget.dataset.color as TrackColorPreset | undefined
- if (!color) {
- return
- }
- this.persistAndApplySystemSettings({
- trackColorPreset: color,
- })
- },
- handleSetTrackStyleClassic() {
- if (this.data.lockTrackStyle || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackStyleProfile: 'classic',
- })
- },
- handleSetTrackStyleNeon() {
- if (this.data.lockTrackStyle || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- trackStyleProfile: 'neon',
- })
- },
- handleSetGpsMarkerVisibleOn() {
- if (this.data.lockGpsMarkerVisible || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerVisible: true,
- })
- },
- handleSetGpsMarkerVisibleOff() {
- if (this.data.lockGpsMarkerVisible || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerVisible: false,
- })
- },
- handleSetGpsMarkerStyleDot() {
- if (this.data.lockGpsMarkerStyle || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerStyle: 'dot',
- })
- },
- handleSetGpsMarkerStyleBeacon() {
- if (this.data.lockGpsMarkerStyle || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerStyle: 'beacon',
- })
- },
- handleSetGpsMarkerStyleDisc() {
- if (this.data.lockGpsMarkerStyle || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerStyle: 'disc',
- })
- },
- handleSetGpsMarkerStyleBadge() {
- if (this.data.lockGpsMarkerStyle || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerStyle: 'badge',
- })
- },
- handleSetGpsMarkerSizeSmall() {
- if (this.data.lockGpsMarkerSize || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerSize: 'small',
- })
- },
- handleSetGpsMarkerSizeMedium() {
- if (this.data.lockGpsMarkerSize || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerSize: 'medium',
- })
- },
- handleSetGpsMarkerSizeLarge() {
- if (this.data.lockGpsMarkerSize || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerSize: 'large',
- })
- },
- handleSetGpsMarkerColorPreset(event: WechatMiniprogram.TouchEvent) {
- if (this.data.lockGpsMarkerColor || !mapEngine) {
- return
- }
- const color = event.currentTarget.dataset.color as GpsMarkerColorPreset | undefined
- if (!color) {
- return
- }
- this.persistAndApplySystemSettings({
- gpsMarkerColorPreset: color,
- })
- },
- handleSetSideButtonPlacementLeft() {
- if (this.data.lockSideButtonPlacement) {
- return
- }
- this.persistAndApplySystemSettings({
- sideButtonPlacement: 'left',
- })
- },
- handleSetSideButtonPlacementRight() {
- if (this.data.lockSideButtonPlacement) {
- return
- }
- this.persistAndApplySystemSettings({
- sideButtonPlacement: 'right',
- })
- },
- handleSetAutoRotateEnabledOn() {
- if (this.data.lockAutoRotate || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- autoRotateEnabled: true,
- })
- },
- handleSetAutoRotateEnabledOff() {
- if (this.data.lockAutoRotate || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- autoRotateEnabled: false,
- })
- },
- handleSetCompassTuningSmooth() {
- if (this.data.lockCompassTuning || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- compassTuningProfile: 'smooth',
- })
- },
- handleSetCompassTuningBalanced() {
- if (this.data.lockCompassTuning || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- compassTuningProfile: 'balanced',
- })
- },
- handleSetCompassTuningResponsive() {
- if (this.data.lockCompassTuning || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- compassTuningProfile: 'responsive',
- })
- },
- handleSetNorthReferenceMagnetic() {
- if (this.data.lockNorthReference || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- northReferenceMode: 'magnetic',
- })
- },
- handleSetNorthReferenceTrue() {
- if (this.data.lockNorthReference || !mapEngine) {
- return
- }
- this.persistAndApplySystemSettings({
- northReferenceMode: 'true',
- })
- },
- handleOverlayTouch() {},
- handlePunchAction() {
- if (!this.data.punchButtonEnabled) {
- return
- }
- if (mapEngine) {
- mapEngine.handlePunchAction()
- }
- },
- handleOpenPendingContentCard() {
- if (mapEngine) {
- mapEngine.openPendingContentCard()
- }
- },
- handleOpenContentCardAction(event: WechatMiniprogram.BaseEvent) {
- if (!mapEngine) {
- return
- }
- wx.showToast({
- title: '点击CTA',
- icon: 'none',
- duration: 900,
- })
- const actionType = event.currentTarget.dataset.type
- const action = typeof actionType === 'string' ? mapEngine.openCurrentContentCardAction(actionType) : null
- if (action === 'detail') {
- wx.showToast({
- title: '打开详情',
- icon: 'none',
- duration: 900,
- })
- return
- }
- if (action === 'quiz') {
- return
- }
- if (action === 'photo') {
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['camera'],
- success: () => {
- if (mapEngine) {
- mapEngine.handleContentCardPhotoCaptured()
- }
- },
- })
- return
- }
- if (action === 'audio') {
- if (!contentAudioRecorder) {
- contentAudioRecorder = wx.getRecorderManager()
- contentAudioRecorder.onStop(() => {
- contentAudioRecording = false
- if (mapEngine) {
- mapEngine.handleContentCardAudioRecorded()
- }
- })
- }
- const recorder = contentAudioRecorder
- if (!contentAudioRecording) {
- contentAudioRecording = true
- recorder.start({
- duration: 8000,
- format: 'mp3',
- } as any)
- wx.showToast({
- title: '开始录音',
- icon: 'none',
- duration: 800,
- })
- } else {
- recorder.stop()
- }
- }
- },
- handleContentQuizAnswer(event: WechatMiniprogram.BaseEvent) {
- if (!mapEngine) {
- return
- }
- const optionKey = event.currentTarget.dataset.key
- if (typeof optionKey === 'string') {
- mapEngine.handleContentCardQuizAnswer(optionKey)
- }
- },
- handleDismissTransientContentCard() {
- if (mapEngine) {
- mapEngine.closeContentCard()
- }
- },
- handleContentCardTap() {
- if (!mapEngine) {
- return
- }
- if (!this.data.contentCardActions.length) {
- mapEngine.closeContentCard()
- }
- },
- openH5Experience(request: H5ExperienceRequest) {
- wx.navigateTo({
- url: '/pages/experience-webview/experience-webview',
- success: (result) => {
- const eventChannel = result.eventChannel
- eventChannel.on('fallback', (payload: H5ExperienceFallbackPayload) => {
- if (mapEngine) {
- mapEngine.handleH5ExperienceFallback(payload)
- }
- })
- eventChannel.on('close', () => {
- if (mapEngine) {
- mapEngine.handleH5ExperienceClosed()
- }
- })
- eventChannel.on('submitResult', () => {
- if (mapEngine) {
- mapEngine.handleH5ExperienceClosed()
- }
- })
- eventChannel.emit('init', request)
- },
- fail: () => {
- if (mapEngine) {
- mapEngine.handleH5ExperienceFallback(request.fallback)
- }
- },
- })
- },
- handleCloseContentCard() {
- if (mapEngine) {
- mapEngine.closeContentCard()
- }
- },
- handleClosePunchHint() {
- clearPunchHintDismissTimer()
- this.setData({
- showPunchHintBanner: false,
- })
- },
- handlePunchHintTap() {},
- handleHudPanelChange(event: WechatMiniprogram.CustomEvent<{ current: number }>) {
- this.setData({
- hudPanelIndex: event.detail.current || 0,
- })
- },
- handleCycleSideButtons() {
- const nextMode = getNextSideButtonMode(this.data.sideButtonMode)
- this.setData({
- ...buildSideButtonVisibility(nextMode),
- ...buildSideButtonState({
- sideButtonMode: nextMode,
- showGameInfoPanel: this.data.showGameInfoPanel,
- showSystemSettingsPanel: this.data.showSystemSettingsPanel,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- handleToggleGpsLock() {
- if (mapEngine) {
- mapEngine.handleToggleGpsLock()
- }
- },
- handleToggleMapRotateMode() {
- if (!mapEngine || this.data.lockAutoRotate) {
- return
- }
- if (this.data.orientationMode === 'heading-up') {
- this.persistAndApplySystemSettings({
- autoRotateEnabled: false,
- })
- return
- }
- this.persistAndApplySystemSettings({
- autoRotateEnabled: true,
- })
- },
- handleToggleDebugPanel() {
- const nextShowDebugPanel = !this.data.showDebugPanel
- if (!nextShowDebugPanel) {
- clearGameInfoPanelSyncTimer()
- }
- if (mapEngine) {
- mapEngine.setDiagnosticUiEnabled(nextShowDebugPanel)
- }
- this.setData({
- showDebugPanel: nextShowDebugPanel,
- showGameInfoPanel: false,
- showSystemSettingsPanel: false,
- ...buildSideButtonState({
- sideButtonMode: this.data.sideButtonMode,
- showGameInfoPanel: false,
- showSystemSettingsPanel: false,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- handleCloseDebugPanel() {
- if (mapEngine) {
- mapEngine.setDiagnosticUiEnabled(false)
- }
- this.setData({
- showDebugPanel: false,
- ...buildSideButtonState({
- sideButtonMode: this.data.sideButtonMode,
- showGameInfoPanel: this.data.showGameInfoPanel,
- showSystemSettingsPanel: this.data.showSystemSettingsPanel,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- skipButtonEnabled: this.data.skipButtonEnabled,
- gameSessionStatus: this.data.gameSessionStatus,
- gpsLockEnabled: this.data.gpsLockEnabled,
- gpsLockAvailable: this.data.gpsLockAvailable,
- }),
- })
- },
- applyCenterScaleRulerSettings(nextEnabled: boolean, nextAnchorMode: CenterScaleRulerAnchorMode) {
- this.data.showCenterScaleRuler = nextEnabled
- this.data.centerScaleRulerAnchorMode = nextAnchorMode
- clearCenterScaleRulerSyncTimer()
- clearCenterScaleRulerUpdateTimer()
- const syncRulerFromEngine = () => {
- if (!mapEngine) {
- return
- }
- const engineSnapshot = mapEngine.getInitialData() as Partial<MapPageData>
- updateCenterScaleRulerInputCache(engineSnapshot)
- const mergedData = {
- ...centerScaleRulerInputCache,
- ...this.data,
- showCenterScaleRuler: nextEnabled,
- centerScaleRulerAnchorMode: nextAnchorMode,
- } as MapPageData
- this.setData({
- ...filterDebugOnlyPatch(engineSnapshot, this.data.showDebugPanel, nextEnabled),
- showCenterScaleRuler: nextEnabled,
- centerScaleRulerAnchorMode: nextAnchorMode,
- ...buildCenterScaleRulerPatch(mergedData),
- ...buildSideButtonState(mergedData),
- })
- }
- if (!nextEnabled) {
- syncRulerFromEngine()
- return
- }
- this.setData({
- showCenterScaleRuler: true,
- centerScaleRulerAnchorMode: nextAnchorMode,
- ...buildSideButtonState({
- ...this.data,
- showCenterScaleRuler: true,
- centerScaleRulerAnchorMode: nextAnchorMode,
- } as MapPageData),
- })
- this.measureStageAndCanvas(() => {
- syncRulerFromEngine()
- })
- centerScaleRulerSyncTimer = setTimeout(() => {
- centerScaleRulerSyncTimer = 0
- if (!this.data.showCenterScaleRuler) {
- return
- }
- syncRulerFromEngine()
- }, 96) as unknown as number
- },
- handleSetCenterScaleRulerVisibleOn() {
- if (this.data.lockScaleRulerVisible) {
- return
- }
- this.persistAndApplySystemSettings({
- showCenterScaleRuler: true,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- }, {
- applyCenterScaleRuler: true,
- })
- },
- handleSetCenterScaleRulerVisibleOff() {
- if (this.data.lockScaleRulerVisible) {
- return
- }
- this.persistAndApplySystemSettings({
- showCenterScaleRuler: false,
- centerScaleRulerAnchorMode: this.data.centerScaleRulerAnchorMode,
- }, {
- applyCenterScaleRuler: true,
- })
- },
- handleSetCenterScaleRulerAnchorScreenCenter() {
- if (this.data.lockScaleRulerAnchor) {
- return
- }
- this.persistAndApplySystemSettings({
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: 'screen-center',
- }, {
- applyCenterScaleRuler: true,
- })
- },
- handleSetCenterScaleRulerAnchorCompassCenter() {
- if (this.data.lockScaleRulerAnchor) {
- return
- }
- this.persistAndApplySystemSettings({
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- centerScaleRulerAnchorMode: 'compass-center',
- }, {
- applyCenterScaleRuler: true,
- })
- },
- handleToggleCenterScaleRulerAnchor() {
- if (!this.data.showCenterScaleRuler || this.data.lockScaleRulerAnchor) {
- return
- }
- const nextAnchorMode: CenterScaleRulerAnchorMode = this.data.centerScaleRulerAnchorMode === 'screen-center'
- ? 'compass-center'
- : 'screen-center'
- this.persistAndApplySystemSettings({
- centerScaleRulerAnchorMode: nextAnchorMode,
- showCenterScaleRuler: this.data.showCenterScaleRuler,
- }, {
- applyCenterScaleRuler: true,
- })
- },
- handleDebugPanelTap() {},
- })
|