<script>
import { browser } from '$app/env';
-
- export let x;
- export let y;
+ import { canvas } from '$lib/stores/canvas';
const kDotSize = 32;
$: {
if (browser) {
document.documentElement.style.setProperty('--dot-size', kDotSize + 'px');
- document.documentElement.style.setProperty('--dot-x', kDotSize - x % kDotSize + 'px');
- document.documentElement.style.setProperty('--dot-y', kDotSize - y % kDotSize + 'px');
+ document.documentElement.style.setProperty('--dot-x', kDotSize - $canvas.x % kDotSize + 'px');
+ document.documentElement.style.setProperty('--dot-y', kDotSize - $canvas.y % kDotSize + 'px');
}
}
</script>
<script>
import { coordinateLength } from '$lib/config';
-
- export let x;
- export let y;
+ import { canvas } from '$lib/stores/canvas';
const kSeparatorRegex = /([0-9a-z]{2})/g;
</script>
<div class="hud">
- { formatCoordinate(x) } × { formatCoordinate(y) }
+ { formatCoordinate($canvas.x) } × { formatCoordinate($canvas.y) }
</div>
<style>
<script>
import { browser } from '$app/env';
import { maxSize } from '$lib/config';
+ import { canvas } from '$lib/stores/canvas';
import { sensor } from '$lib/stores/widgets';
- export let x;
- export let y;
-
const kSensorSize = 2;
let left;
$: {
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;
+ left = $canvas.x - window.screen.width * kSensorSize;
+ top = $canvas.y - window.screen.height * kSensorSize;
+ right = $canvas.x + window.screen.width * kSensorSize;
+ bottom = $canvas.y + window.screen.height * kSensorSize;
fetchItems(left, top, right, bottom);
}
--- /dev/null
+<script>
+ import { bottomRight, topLeft } from '$lib/stores/canvas';
+ import { modulo } from '$lib/math';
+ import { maxSize } from '$lib/config';
+ export let widget;
+
+ const width = widget.box.right - widget.box.left;
+ const height = widget.box.bottom - widget.box.top;
+
+ $: renderX = widget.box.left - modulo($topLeft.x, maxSize);
+ $: renderY = widget.box.top - modulo($topLeft.y, maxSize);
+
+ console.log('Max', maxSize,
+ 'Widget Actual', widget.box.left, widget.box.top,
+ 'Top Left', $topLeft.x, $topLeft.y,
+ 'Mod Top Left', modulo($topLeft.x, maxSize), modulo($topLeft.y, maxSize),
+ 'Calculated',
+ modulo(widget.box.left - modulo($topLeft.x, maxSize), maxSize),
+ modulo(widget.box.top - modulo($topLeft.y, maxSize), maxSize))
+
+</script>
+
+<div class="widget"
+ style:width="{width}px"
+ style:height="{height}px"
+ style:left="{renderX}px"
+ style:top="{renderY}px"
+>
+ {widget.type}
+</div>
+
+<style>
+ .widget {
+ position: fixed;
+ background-color: #f0f;
+ border: 1px solid black;
+ opacity: 0.5;
+ }
+</style>
--- /dev/null
+import { browser } from '$app/env';
+import { derived, writable } from 'svelte/store';
+
+export const canvas = writable({x: 0, y: 0});
+
+export const topLeft = derived(canvas, ($canvas) => {
+ if (browser) {
+ return {
+ x: $canvas.x - window.screen.width/2,
+ y: $canvas.y - window.screen.height/2
+ };
+ }
+ return {x: 0, y: 0}
+});
+
+export const bottomRight = derived(canvas, ($canvas) => {
+ if (browser) {
+ return {
+ x: $canvas.x + window.screen.width/2,
+ y: $canvas.y + window.screen.height/2
+ };
+ }
+ return {x: 0, y: 0}
+});
import { supabase } from '$lib/config';
import { maxSize } from '$lib/config';
+const boxParser = /\(([0-9]+),([0-9]+)\),\(([0-9]+),([0-9]+)\)/
const client = createClient(supabase.url, supabase.key);
export const sensor = writable({left: 0, top: 0, right: 0, bottom: 0});
const getBoxes = function getBoxes ({left, top, right, bottom}) {
- return [
- `box.ov."(${left},${top},${right},${bottom})"`,
- `box.ov."(${left+maxSize},${top+maxSize},${right+maxSize},${bottom+maxSize})"`,
- `box.ov."(${left+maxSize},${top},${right+maxSize},${bottom})"`,
- `box.ov."(${left},${top+maxSize},${right},${bottom+maxSize})"`
- ]
+ const results = [
+ `box.ov."((${left},${top}),(${right},${bottom}))"`,
+ `box.ov."((${left+maxSize},${top+maxSize}),(${right+maxSize},${bottom+maxSize}))"`,
+ `box.ov."((${left+maxSize},${top}),(${right+maxSize},${bottom}))"`,
+ `box.ov."((${left},${top+maxSize}),(${right},${bottom+maxSize}))"`
+ ];
+
+ if (right > maxSize || bottom > maxSize) {
+ return [...results,
+ `box.ov."((${left-maxSize},${top-maxSize}),(${right-maxSize},${bottom-maxSize}))"`,
+ `box.ov."((${left-maxSize},${top}),(${right-maxSize},${bottom}))"`,
+ `box.ov."((${left},${top-maxSize}),(${right},${bottom-maxSize}))"`
+ ];
+ }
+
+ return results
+};
+
+const serialize = function serialize(widget) {
+
+ const boxComponents = widget.box
+ .match(boxParser)
+ .slice(1,5)
+ .map(Number);
+ const box = {
+ left: Math.min(boxComponents[0], boxComponents[2]),
+ right: Math.max(boxComponents[0], boxComponents[2]),
+ top: Math.min(boxComponents[1], boxComponents[3]),
+ bottom: Math.max(boxComponents[1], boxComponents[3])
+ };
+
+ return {...widget, box }
};
let ac = null;
.select()
.or(boxes.join(','))
.abortSignal(ac.signal)
- return set(data);
+ if (data) {
+ return set(data.map(serialize));
+ }
});
import Background from '$lib/components/background.svelte';
import Palette from '$lib/components/palette.svelte';
import Hud from '$lib/components/hud.svelte';
+ import Widget from '$lib/components/widget.svelte';
import { modulo } from '$lib/math';
import { widgets } from '$lib/stores/widgets';
+ import { canvas } from '$lib/stores/canvas';
import { coordinateLength, maxSize } from '$lib/config';
- $: x = 0;
- $: y = 0;
$: shouldShowPalette = false;
let dragging = false;
if (dragging) {
let deltaX = event.x - dragging.x;
let deltaY = event.y - dragging.y;
- x = modulo(x - deltaX, maxSize);
- y = modulo(y - deltaY, maxSize);
+ let x = modulo($canvas.x - deltaX, maxSize);
+ let y = modulo($canvas.y - deltaY, maxSize);
dragging.x = event.x;
dragging.y = event.y;
+ canvas.set({ x, y })
}
}
on:mouseup={stopDragging}
on:mousemove={moveCanvas}
>
- <Sensor x={x} y={y} />
- <Background x={x} y={y} />
- <Hud x={x} y={y} />
+ <Sensor />
+ <Background />
+ <Hud />
{#if shouldShowPalette }
<Palette/>
{/if}
- <p>{JSON.stringify($widgets)}</p>
+ {#if $widgets}
+ {#each $widgets as widget}
+ <Widget widget={widget}/>
+ {/each}
+ {/if}
</div>
<style>