]> git.r.bdr.sh - rbdr/canvas/blobdiff - src/lib/components/sensor.svelte
Save WIP
[rbdr/canvas] / src / lib / components / sensor.svelte
index da968a3220432c74dc24401af9fa54d48175cd7a..94587058024a4f1b728c42aedd70d2afdd0b158a 100644 (file)
@@ -1,34 +1,33 @@
 <script>
 <script>
-  import { browser } from '$app/env';
-  import { maxSize } from '$lib/config';
+       import { browser } from '$app/environment';
+       import { maxSize } from '$lib/config';
+       import { modulo } from '$lib/math';
+       import { canvas } from '$lib/stores/canvas';
+       import { sensor } from '$lib/stores/widgets';
 
 
-  export let x;
-  export let y;
+       const kSensorSize = 2;
 
 
-  const kSensorSize = 2;
+       let left;
+       let right;
+       let top;
+       let bottom;
 
 
-  let left;
-  let right;
-  let top;
-  let bottom;
-
-  let timer;
-  const fetchItems = function fetchItems( left, top, right, bottom ) {
-    clearTimeout(timer);
+       let timer;
+       const fetchItems = function fetchItems(left, top, right, bottom) {
+               clearTimeout(timer);
                timer = setTimeout(() => {
                timer = setTimeout(() => {
-      console.log('fetching', left, top, right, bottom);
+                       sensor.set({ left, top, right, bottom });
                }, 50);
                }, 50);
-  }
-
-  $: {
-    if (browser) {
-      left = x - window.screen.width * kSensorSize;
-      top = y - window.screen.height * kSensorSize;
-      right = x + window.screen.width * kSensorSize;
-      bottom = y + window.screen.height * kSensorSize;
+       };
 
 
-      fetchItems(left, top, right, bottom);
-    }
-  }
+       $: {
+               if (browser) {
+                       left = modulo($canvas.x - window.screen.width * kSensorSize, maxSize);
+                       top = modulo($canvas.y - window.screen.height * kSensorSize, maxSize);
+                       right = left + 2 * window.screen.width * kSensorSize;
+                       bottom = top + 2 * window.screen.height * kSensorSize;
 
 
+                       fetchItems(left, top, right, bottom);
+               }
+       }
 </script>
 </script>