<script>
-
- import { browser } from '$app/env';
+ import Sensor from '$lib/components/sensor.svelte';
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';
- const kCoordinateLength = 6;
- const kMaxSize = Math.pow(16, kCoordinateLength);
+ import { coordinateLength, maxSize } from '$lib/config';
- $: x = 0;
- $: y = 0;
$: shouldShowPalette = false;
let dragging = false;
- const modulo = function modulo (number, base) {
- return ((number % base) + base) % base
- };
-
const moveCanvas = function moveCanvas(event) {
if (dragging) {
let deltaX = event.x - dragging.x;
let deltaY = event.y - dragging.y;
- x = modulo(x - deltaX, kMaxSize);
- y = modulo(y - deltaY, kMaxSize);
+ 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:contextmenu={showPalette}
on:mousedown={startDragging}
on:mouseup={stopDragging}
- on:mousemove={moveCanvas}>
+ on:mousemove={moveCanvas}
>
- <Background x={x} y={y}/>
- <Hud x={x} y={y} />
+ <Sensor />
+ <Background />
+ <Hud />
{#if shouldShowPalette }
<Palette/>
{/if}
+
+ {#if $widgets}
+ {#each $widgets as widget}
+ <Widget widget={widget}/>
+ {/each}
+ {/if}
</div>
<style>