feat: streamline location and orientation tracking by consolidating start functions
All checks were successful
Migrate supabase / migrate (push) Successful in 16s
All checks were successful
Migrate supabase / migrate (push) Successful in 16s
This commit is contained in:
@@ -95,6 +95,9 @@
|
|||||||
|
|
||||||
// If we have device heading, rotate relative to it; otherwise just use absolute bearing
|
// If we have device heading, rotate relative to it; otherwise just use absolute bearing
|
||||||
arrowRotation = heading !== null ? bearing - heading : bearing;
|
arrowRotation = heading !== null ? bearing - heading : bearing;
|
||||||
|
} else {
|
||||||
|
distance = null;
|
||||||
|
arrowRotation = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -218,6 +221,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startAllTracking() {
|
||||||
|
startLocationTracking();
|
||||||
|
void startOrientationTracking();
|
||||||
|
}
|
||||||
|
|
||||||
function stopLocationTracking() {
|
function stopLocationTracking() {
|
||||||
if (watchId !== null) {
|
if (watchId !== null) {
|
||||||
navigator.geolocation.clearWatch(watchId);
|
navigator.geolocation.clearWatch(watchId);
|
||||||
@@ -231,8 +239,7 @@
|
|||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (currentStep?.type === 'location' && isCurrentActiveStep) {
|
if (currentStep?.type === 'location' && isCurrentActiveStep) {
|
||||||
checkLocationPermission().then(() => {
|
checkLocationPermission().then(() => {
|
||||||
startLocationTracking();
|
startAllTracking();
|
||||||
startOrientationTracking();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +248,17 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If step data arrives after mount, start/stop tracking reactively.
|
||||||
|
$effect(() => {
|
||||||
|
if (currentStep?.type === 'location' && isCurrentActiveStep) {
|
||||||
|
if (watchId === null) {
|
||||||
|
startAllTracking();
|
||||||
|
}
|
||||||
|
} else if (watchId !== null) {
|
||||||
|
stopLocationTracking();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function handleOrientation(event: Event) {
|
function handleOrientation(event: Event) {
|
||||||
const e = event as DeviceOrientationEvent;
|
const e = event as DeviceOrientationEvent;
|
||||||
if (e.absolute && e.alpha !== null) {
|
if (e.absolute && e.alpha !== null) {
|
||||||
@@ -412,7 +430,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => startLocationTracking()}
|
onclick={() => startAllTracking()}
|
||||||
class="w-full rounded-lg bg-red-600 px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-red-700"
|
class="w-full rounded-lg bg-red-600 px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-red-700"
|
||||||
>
|
>
|
||||||
{$t.gameplay.tryAgain}
|
{$t.gameplay.tryAgain}
|
||||||
@@ -432,7 +450,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => startLocationTracking()}
|
onclick={() => startAllTracking()}
|
||||||
class="w-full rounded-lg bg-indigo-600 px-4 py-3 text-base font-semibold text-white transition-colors hover:bg-indigo-700"
|
class="w-full rounded-lg bg-indigo-600 px-4 py-3 text-base font-semibold text-white transition-colors hover:bg-indigo-700"
|
||||||
>
|
>
|
||||||
{$t.gameplay.enableLocation}
|
{$t.gameplay.enableLocation}
|
||||||
|
|||||||
Reference in New Issue
Block a user