]>
Commit | Line | Data |
---|---|---|
2df937df | 1 | <script> |
587d8fe6 RBR |
2 | import { browser } from '$app/environment'; |
3 | import { maxSize } from '$lib/config'; | |
4 | import { modulo } from '$lib/math'; | |
5 | import { canvas } from '$lib/stores/canvas'; | |
6 | import { sensor } from '$lib/stores/widgets'; | |
2df937df | 7 | |
587d8fe6 | 8 | const kSensorSize = 2; |
2df937df | 9 | |
587d8fe6 RBR |
10 | let left; |
11 | let right; | |
12 | let top; | |
13 | let bottom; | |
2df937df | 14 | |
587d8fe6 RBR |
15 | let timer; |
16 | const fetchItems = function fetchItems(left, top, right, bottom) { | |
17 | clearTimeout(timer); | |
2df937df | 18 | timer = setTimeout(() => { |
587d8fe6 | 19 | sensor.set({ left, top, right, bottom }); |
2df937df | 20 | }, 50); |
587d8fe6 | 21 | }; |
2df937df | 22 | |
587d8fe6 RBR |
23 | $: { |
24 | if (browser) { | |
25 | left = modulo($canvas.x - window.screen.width * kSensorSize, maxSize); | |
26 | top = modulo($canvas.y - window.screen.height * kSensorSize, maxSize); | |
27 | right = left + 2 * window.screen.width * kSensorSize; | |
28 | bottom = top + 2 * window.screen.height * kSensorSize; | |
2df937df | 29 | |
587d8fe6 RBR |
30 | fetchItems(left, top, right, bottom); |
31 | } | |
32 | } | |
2df937df | 33 | </script> |