Repository navigation
Expand file tree
/
Copy pathfast-hud-render.ts
More file actions
90 lines (87 loc) · 2.93 KB
/
Copy pathfast-hud-render.ts
File metadata and controls
90 lines (87 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import type { AiHudSnapshot } from "./ai-hud-state";
import { drawFastCanvasHud } from "./fast-canvas-hud";
import { drawFastDetailHud } from "./fast-detail-hud";
import type { FastHudPage } from "./fast-hud-pages";
import { drawFastFullscreenMap } from "./fast-map";
import { paginateFastNewsSummary } from "./fast-news-pages";
import type { FastHudViewContext, FastHudViewState } from "./fast-hud-view";
import type { FastCanvasBattery } from "./glasses";
import type { LiveDashboardState } from "./live-state";
import type { PhoneLocale } from "./phone-types";
import type { ConversateSnapshot } from "./conversate-state";
export type FastHudNewsPageCache = {
readonly key: string;
readonly counts: readonly number[];
};
export function resolveFastHudViewContext(
canvas: HTMLCanvasElement,
live: LiveDashboardState,
locale: PhoneLocale,
ai: AiHudSnapshot,
cache: FastHudNewsPageCache,
): { readonly context: FastHudViewContext; readonly cache: FastHudNewsPageCache } {
const route = live.route.value;
const news = live.news.value ?? [];
const key = [live.news.status, live.news.fetchedAt ?? "", news.length].join(":");
let counts = cache.counts;
if (key !== cache.key) {
const context = canvas.getContext("2d");
counts = news.length === 0
? []
: context
? news.map((item) => paginateFastNewsSummary(
context,
item.summary,
locale,
).length)
: news.map(() => 1);
}
return {
context: {
newsCount: news.length,
newsPageCounts: counts,
todoCount: live.todos.value?.length ?? 0,
maneuverCount: route?.maneuvers.length ?? 0,
activeManeuverIndex: route?.activeManeuverIndex ?? 0,
aiLineCount: ai.transcriptLines.length,
},
cache: { key, counts },
};
}
export function drawFastHudSurface(options: {
readonly canvas: HTMLCanvasElement;
readonly page: FastHudPage;
readonly view: FastHudViewState;
readonly live: LiveDashboardState;
readonly battery?: FastCanvasBattery;
readonly mapRadiusMeters: number;
readonly ai: AiHudSnapshot;
readonly conversate: ConversateSnapshot;
readonly locale: PhoneLocale;
}) {
const { canvas, page, view, live, battery, mapRadiusMeters, ai, conversate, locale } = options;
if (view.mode === "map") {
drawFastFullscreenMap(canvas, live, mapRadiusMeters, locale);
return;
}
if (view.mode !== "dashboard") {
drawFastDetailHud(canvas, {
mode: view.mode,
live,
newsIndex: view.newsIndex,
newsPage: view.newsPage,
todoIndex: view.todoIndex,
navigationIndex: view.navigationIndex,
...(view.mode === "ai" ? { ai, aiLine: view.aiLine } : {}),
...(view.mode === "conversate" ? { conversate } : {}),
}, locale);
return;
}
drawFastCanvasHud(canvas, new Date(), page, {
battery,
live,
mapRadiusMeters,
...(page === "ai" ? { ai } : {}),
...(page === "conversate" ? { conversate } : {}),
}, locale);
}