Release Vulpes OS 2.7-preview.22
This commit is contained in:
parent
200d1fb235
commit
a138f97877
294 changed files with 515786 additions and 187 deletions
19
services/keypad-navigation.mjs
Normal file
19
services/keypad-navigation.mjs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export function nextKeypadTarget(items, current, direction) {
|
||||
if (!items.length) return -1;
|
||||
if (current < 0 || current >= items.length) return 0;
|
||||
const vectors = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]};
|
||||
const vector = vectors[direction];
|
||||
if (!vector) return -1;
|
||||
const origin = items[current];
|
||||
let best = -1, score = Infinity;
|
||||
for (let index = 0; index < items.length; index++) {
|
||||
if (index === current) continue;
|
||||
const dx = items[index].x - origin.x, dy = items[index].y - origin.y;
|
||||
const forward = dx * vector[0] + dy * vector[1];
|
||||
if (forward <= 1) continue;
|
||||
const sideways = Math.abs(dx * vector[1] - dy * vector[0]);
|
||||
const distance = forward + sideways * 3;
|
||||
if (distance < score) { best = index; score = distance; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
Loading…
Reference in a new issue