feat: reveal device cards progressively with camera zoom
This commit is contained in:
1 parent
e62f987563
commit
a2a119d3ee
18 files changed
+458
-265
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import type { LiveCard } from "./cards.ts";
|
||||
|
||||
/** Screen pixels per plan metre at the anchor, independent of building size and camera angle. */
|
||||
export function cardDetail(card: LiveCard): { density: number; priority: number } {
|
||||
switch (card.kind) {
|
||||
case "house": return { density:0,priority:100 };
|
||||
case "roomclimate": return { density:24,priority:80 };
|
||||
case "hydronic": return { density:42,priority:45 };
|
||||
case "power": {
|
||||
const active=card.power!==null&&Math.abs(card.power)>1;
|
||||
return active ? {density:48,priority:60} : card.readings?.length ? {density:56,priority:30} : {density:card.power===null?64:72,priority:20};
|
||||
}
|
||||
case "car": return {density:card.car.charging?36:60,priority:card.car.charging?60:20};
|
||||
case "printer": return {density:card.printer.printing?36:60,priority:card.printer.printing?60:20};
|
||||
case "heatpump": return {density:card.pump.mode!=="idle"?36:60,priority:card.pump.mode!=="idle"?60:20};
|
||||
case "media": return {density:48,priority:40};
|
||||
}
|
||||
}
|
||||
|
||||
/** A small dead band prevents cards flickering at a zoom boundary. Summary cards keep their existing visibility. */
|
||||
export function cardVisibleAtZoom(card: LiveCard, density: number, previouslyVisible: boolean): boolean {
|
||||
const limit=cardDetail(card).density;
|
||||
if (!limit) return true;
|
||||
return Number.isFinite(density) && density >= limit * (previouslyVisible ? .88 : 1.12);
|
||||
}
|
||||
Reference in new issue
Block a user