2 import Sensor from '$lib/components/sensor.svelte';
3 import Background from '$lib/components/background.svelte';
4 import Palette from '$lib/components/palette.svelte';
5 import Hud from '$lib/components/hud.svelte';
6 import Minimap from '$lib/components/minimap.svelte';
7 import Widget from '$lib/components/widget.svelte';
8 import { modulo } from '$lib/math';
9 import { widgets } from '$lib/stores/widgets';
10 import { canvas } from '$lib/stores/canvas';
12 import { coordinateLength, maxSize } from '$lib/config';
14 $: shouldShowPalette = false;
18 const moveCanvas = function moveCanvas(event) {
21 let deltaX = event.x - dragging.x;
22 let deltaY = event.y - dragging.y;
23 let x = modulo($canvas.x - deltaX, maxSize);
24 let y = modulo($canvas.y - deltaY, maxSize);
31 const startDragging = function startDragging(event) {
38 const stopDragging = function startDragging() {
42 const showPalette = function showPalette(event) {
43 event.preventDefault();
45 document.documentElement.style.setProperty('--palette-x', event.clientX + 'px');
46 document.documentElement.style.setProperty('--palette-y', event.clientY + 'px');
47 shouldShowPalette = true;
50 const hidePalette = function hidePalette() {
51 event.preventDefault();
52 shouldShowPalette = false;
58 on:click={hidePalette}
59 on:contextmenu={showPalette}
60 on:mousedown={startDragging}
61 on:mouseup={stopDragging}
62 on:mousemove={moveCanvas}
69 {#if shouldShowPalette }
74 {#each $widgets as widget}
75 <Widget widget={widget}/>