aboutsummaryrefslogtreecommitdiff
path: root/src/lib/components
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2022-07-05 23:34:03 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2022-07-05 23:34:03 +0200
commit2df937df1372359babd123d1361e702a1a4b8168 (patch)
treea44f4e3e51469c173127ce8660e39c20aa5309d7 /src/lib/components
parent3717f7fbf9ec110b51fe002cdced5d73ebd6136b (diff)
Create the sensor, move values to config
Diffstat (limited to 'src/lib/components')
-rw-r--r--src/lib/components/hud.svelte5
-rw-r--r--src/lib/components/sensor.svelte34
2 files changed, 37 insertions, 2 deletions
diff --git a/src/lib/components/hud.svelte b/src/lib/components/hud.svelte
index ce32e0d..f79658a 100644
--- a/src/lib/components/hud.svelte
+++ b/src/lib/components/hud.svelte
@@ -1,14 +1,15 @@
<script>
+ import { coordinateLength } from '$lib/config';
+
export let x;
export let y;
- const kCoordinateLength = 6;
const kSeparatorRegex = /([0-9a-z]{2})/g;
const formatCoordinate = function formatCoordinate(coordinate) {
return coordinate
.toString(16)
- .padStart(kCoordinateLength, 0)
+ .padStart(coordinateLength, 0)
.replace(kSeparatorRegex, '$1 ');
}
</script>
diff --git a/src/lib/components/sensor.svelte b/src/lib/components/sensor.svelte
index e69de29..da968a3 100644
--- a/src/lib/components/sensor.svelte
+++ b/src/lib/components/sensor.svelte
@@ -0,0 +1,34 @@
+<script>
+ import { browser } from '$app/env';
+ import { maxSize } from '$lib/config';
+
+ export let x;
+ export let y;
+
+ const kSensorSize = 2;
+
+ let left;
+ let right;
+ let top;
+ let bottom;
+
+ let timer;
+ const fetchItems = function fetchItems( left, top, right, bottom ) {
+ clearTimeout(timer);
+ timer = setTimeout(() => {
+ console.log('fetching', left, top, right, bottom);
+ }, 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);
+ }
+ }
+
+</script>