]>
Commit | Line | Data |
---|---|---|
c336b229 | 1 | <script> |
587d8fe6 RBR |
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'; | |
3717f7fb | 11 | |
587d8fe6 | 12 | import { maxSize } from '$lib/config'; |
c336b229 | 13 | |
587d8fe6 | 14 | $: shouldShowPalette = false; |
c336b229 | 15 | |
587d8fe6 | 16 | let dragging = false; |
c336b229 | 17 | |
587d8fe6 RBR |
18 | const moveCanvas = function moveCanvas(event) { |
19 | if (dragging) { | |
20 | let deltaX = event.x - dragging.x; | |
21 | let deltaY = event.y - dragging.y; | |
22 | let x = modulo($canvas.x - deltaX, maxSize); | |
23 | let y = modulo($canvas.y - deltaY, maxSize); | |
24 | dragging.x = event.x; | |
25 | dragging.y = event.y; | |
26 | canvas.set({ x, y }); | |
27 | } | |
28 | }; | |
c336b229 | 29 | |
587d8fe6 RBR |
30 | const startDragging = function startDragging(event) { |
31 | dragging = { | |
32 | x: event.x, | |
33 | y: event.y | |
34 | }; | |
35 | }; | |
c336b229 | 36 | |
587d8fe6 RBR |
37 | const stopDragging = function startDragging() { |
38 | dragging = null; | |
39 | }; | |
c336b229 | 40 | |
587d8fe6 RBR |
41 | const showPalette = function showPalette(event) { |
42 | event.preventDefault(); | |
43 | dragging = null; | |
44 | document.documentElement.style.setProperty('--palette-x', event.clientX + 'px'); | |
45 | document.documentElement.style.setProperty('--palette-y', event.clientY + 'px'); | |
46 | shouldShowPalette = true; | |
47 | }; | |
c336b229 | 48 | |
587d8fe6 RBR |
49 | const hidePalette = function hidePalette() { |
50 | event.preventDefault(); | |
51 | shouldShowPalette = false; | |
52 | }; | |
c336b229 RBR |
53 | </script> |
54 | ||
f106543f | 55 | <div |
587d8fe6 RBR |
56 | class="canvas" |
57 | on:click={hidePalette} | |
58 | on:contextmenu={showPalette} | |
59 | on:mousedown={startDragging} | |
60 | on:mouseup={stopDragging} | |
61 | on:mousemove={moveCanvas} | |
3717f7fb | 62 | > |
587d8fe6 RBR |
63 | <Sensor /> |
64 | <Background /> | |
65 | <Hud /> | |
66 | <Minimap /> | |
c336b229 | 67 | |
587d8fe6 RBR |
68 | {#if shouldShowPalette} |
69 | <Palette /> | |
70 | {/if} | |
c30e6881 | 71 | |
587d8fe6 RBR |
72 | {#if $widgets} |
73 | {#each $widgets as widget} | |
74 | <Widget {widget} /> | |
75 | {/each} | |
76 | {/if} | |
c336b229 RBR |
77 | </div> |
78 | ||
79 | <style> | |
587d8fe6 RBR |
80 | .canvas { |
81 | user-select: none; | |
82 | padding: 0; | |
83 | margin: 0; | |
84 | width: 100vw; | |
85 | height: 100vh; | |
86 | } | |
c336b229 | 87 | </style> |