mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Fix the card previews' review findings
- A route globe that cannot draw tells the card, which shows another view. - A card opened before the model set has loaded waits for that load. - The model turns at the same rate on any display, and holds still under reduced motion. - A hidden cockpit view stops drawing. - The route plane keeps the craft's latest position through the fly-in. - Metric altitude graphs keep main's 0.5% change threshold. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
7b53427a28
commit
efffe3005c
6 files changed
+76
-22
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { aircraftModelSpec, fleetModelSet } from '../../../data/fleetModels.js';
|
||||
import { aircraftModelSpec, fleetModelSet, fleetModelSetLoading } from '../../../data/fleetModels.js';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import { useEntityCardStore } from '../../stores/entityCard.js';
|
||||
import PreviewHud from './PreviewHud.vue';
|
||||
@@ -50,21 +50,27 @@ const shown = computed(() => {
|
||||
});
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
|
||||
/** The fleet model's spec and bytes, or null before the set has loaded. */
|
||||
function fleetModel(aircraft) {
|
||||
const set = fleetModelSet();
|
||||
/** The fleet model's spec and bytes, or null when it has none. */
|
||||
function fleetModel(set, aircraft) {
|
||||
if (!set || !aircraft) return null;
|
||||
const spec = aircraftModelSpec(set, aircraft);
|
||||
const gltf = set.bytes.get(spec.model);
|
||||
return gltf ? { gltf, basePath: spec.url } : null;
|
||||
}
|
||||
|
||||
function show() {
|
||||
let showing = 0;
|
||||
async function show() {
|
||||
preview?.destroy();
|
||||
preview = null;
|
||||
phase.value = 'plain';
|
||||
const asked = ++showing;
|
||||
// A card opened before the Flights layer's model set has loaded waits for
|
||||
// that load rather than giving up.
|
||||
let set = fleetModelSet();
|
||||
if (!set) set = await fleetModelSetLoading()?.catch(() => null);
|
||||
if (asked !== showing) return;
|
||||
const previews = store.previews();
|
||||
const model = fleetModel(props.aircraft);
|
||||
const model = fleetModel(set, props.aircraft);
|
||||
if (!previews?.model || !model || !host.value) {
|
||||
failed.value = true;
|
||||
return;
|
||||
@@ -99,6 +105,7 @@ watch(
|
||||
(active) => preview?.setActive(active),
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
showing++;
|
||||
clearInterval(cycle);
|
||||
preview?.destroy();
|
||||
preview = null;
|
||||
|
||||
@@ -84,7 +84,7 @@ const graph = computed(() => {
|
||||
const line = points.map(([px, py], index) => `${index ? 'L' : 'M'}${px.toFixed(2)} ${py.toFixed(2)}`).join(' ');
|
||||
const moved = last.m - first.m;
|
||||
const feetScale = !SHOW[props.unit];
|
||||
const change = feetScale ? feet(last.m) - feet(first.m) : Math.abs(moved) >= Math.max(1, last.m * 0.0005) ? moved : 0;
|
||||
const change = feetScale ? feet(last.m) - feet(first.m) : Math.abs(moved) >= Math.max(1, last.m * (props.unit === 'metric' ? 0.005 : 0.0005)) ? moved : 0;
|
||||
const changeText = feetScale ? t('{n} ft', { n: number(Math.abs(change)) }) : shown(Math.abs(moved));
|
||||
const minutes = Math.floor((last.at - first.at) / 60_000);
|
||||
return {
|
||||
|
||||
@@ -208,7 +208,8 @@ watch(
|
||||
// Anything else gets a quiet placeholder with its icon and its headline
|
||||
// figures until it has imagery of its own. Previews stay mounted so switching
|
||||
// shows the next one at once.
|
||||
const routeKnown = computed(() => Boolean(card.value?.route?.fromAt && card.value?.route?.toAt));
|
||||
const routeFailed = ref(false);
|
||||
const routeKnown = computed(() => Boolean(card.value?.route?.fromAt && card.value?.route?.toAt) && !routeFailed.value);
|
||||
const modelFailed = ref(false);
|
||||
const cockpitFailed = ref(false);
|
||||
const hasPosition = computed(() => Number.isFinite(card.value?.lat) && Number.isFinite(card.value?.lon));
|
||||
@@ -302,6 +303,7 @@ watch(
|
||||
() => card.value?.key,
|
||||
() => {
|
||||
preview.value = null;
|
||||
routeFailed.value = false;
|
||||
modelFailed.value = false;
|
||||
cockpitFailed.value = false;
|
||||
clearTimeout(turnTimer);
|
||||
@@ -358,7 +360,7 @@ watch(
|
||||
<img :src="photo.src" :alt="t('Photo of {name}', { name: shownTitle })" v-on="{ error: onPhotoError }" />
|
||||
<small v-if="photo.credit">{{ photo.credit }}</small>
|
||||
</a>
|
||||
<RouteGlobe v-if="routeKnown" :key="`route-${card.key}`" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'route' }" :active="activeFlightPreview === 'route'" :from="card.route.fromAt" :to="card.route.toAt" :at="{ lat: card.lat, lon: card.lon }" />
|
||||
<RouteGlobe v-if="routeKnown" :key="`route-${card.key}`" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'route' }" :active="activeFlightPreview === 'route'" :from="card.route.fromAt" :to="card.route.toAt" :at="{ lat: card.lat, lon: card.lon }" @failed="routeFailed = true" />
|
||||
<AircraftModelHero v-if="modelKnown" :key="card.key" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'model' }" :active="activeFlightPreview === 'model'" :aircraft="card.aircraftModel" :heading="card.heading || 0" :callouts="callouts" @failed="modelFailed = true" @cycle="showOtherView" />
|
||||
<FlightCockpitView v-if="cockpitMade && cockpitKnown" :key="`cockpit-${card.key}`" class="entity-hero__layer" :class="{ 'is-shown': activeFlightPreview === 'cockpit' }" :active="activeFlightPreview === 'cockpit'" :lat="card.lat" :lon="card.lon" :altitude-m="card.altitudeM" :heading="card.heading" :speed-mps="card.speedMps" @failed="onCockpitFailed" />
|
||||
<div v-if="cockpitKnown || (routeKnown && modelKnown) || (photoAvailable && (routeKnown || modelKnown))" class="entity-card__preview-switch" role="group" :aria-label="t('Preview')">
|
||||
|
||||
@@ -19,11 +19,19 @@ const props = defineProps({
|
||||
/** Whether the tile is the one showing; a hidden one stops drawing. */
|
||||
active: { type: Boolean, default: true },
|
||||
});
|
||||
const emit = defineEmits(['failed']);
|
||||
const store = useEntityCardStore();
|
||||
|
||||
const host = ref(null);
|
||||
const failed = ref(false);
|
||||
let preview = null;
|
||||
// A globe that cannot draw tells the card, which then shows another view.
|
||||
watch(failed, (now) => {
|
||||
if (!now) return;
|
||||
preview?.destroy();
|
||||
preview = null;
|
||||
emit('failed');
|
||||
});
|
||||
|
||||
const place = (p) => ({ code: p?.code || '', lat: Number(p?.lat), lon: Number(p?.lon) });
|
||||
const at = () =>
|
||||
|
||||
Reference in new issue
Block a user