|
31 | 31 | import type { Grid as HoneycombGrid } from 'honeycomb-grid'; |
32 | 32 | const { defineHex, Grid, Orientation } = honeycombGrid; |
33 | 33 |
|
34 | | - let container: HTMLDivElement | undefined; |
35 | | - let parentElement: HTMLElement | null = null; |
| 34 | + type HexType = ReturnType<typeof defineHex>; |
| 35 | + type CustomHex = InstanceType<HexType>; |
36 | 36 |
|
37 | 37 | const currentPlayer: Player | undefined = $derived( |
38 | 38 | gameStore.world?.players.find((player: Player) => player.name === gameStore.playerName) |
|
74 | 74 | '/img/numbers/12.png' |
75 | 75 | ]; |
76 | 76 |
|
77 | | - let app: Application | undefined; |
78 | | - let worldContainer: Container | undefined; |
79 | 77 | const tileGraphics = new Graphics(); |
80 | 78 | const pieceGraphics = new Graphics(); |
81 | 79 | const lineGraphics = new Graphics(); |
82 | 80 | const cursorGraphics = new Graphics(); |
83 | 81 | const sprites = generateSprites(); |
84 | 82 |
|
85 | | - type HexType = ReturnType<typeof defineHex>; |
86 | | - type CustomHex = InstanceType<HexType>; |
| 83 | + let app: Application | undefined; |
| 84 | + let worldContainer: Container | undefined; |
87 | 85 | let grid: HoneycombGrid<CustomHex> | undefined; |
| 86 | + let container: HTMLDivElement | undefined; |
| 87 | + let parentElement: HTMLElement | null = null; |
88 | 88 | let hexFactory: HexType | undefined; |
89 | 89 |
|
90 | 90 | let height = 0; |
91 | 91 | let width = 0; |
92 | 92 |
|
93 | | - // Pan and zoom state |
94 | 93 | let scale = 1; |
95 | 94 | let panX = 0; |
96 | 95 | let panY = 0; |
| 96 | +
|
97 | 97 | let isDragging = false; |
98 | 98 | let lastPointerPosition = { x: 0, y: 0 }; |
99 | 99 | let pointerDownPosition = { x: 0, y: 0 }; |
100 | 100 | let hasDragged = false; |
101 | | - const wheelPointerPosition = new Point(); |
102 | | -
|
103 | | - let isBuilding: BuildingType = 'None'; |
104 | | - let isMovingThief = false; |
105 | | - let isPlayingKnight = false; |
106 | | - let isPlayingRoadBuilding = false; |
| 101 | + let wheelPointerPosition = new Point(); |
| 102 | + let wheelHandler: ((event: WheelEvent) => void) | undefined; |
107 | 103 |
|
108 | 104 | let resizeObserver: ResizeObserver | undefined; |
109 | 105 |
|
110 | | - // Store event handlers for cleanup |
111 | | - let wheelHandler: ((event: WheelEvent) => void) | undefined; |
112 | 106 | let assetsLoaded = false; |
113 | 107 | let latestWorld: World | undefined; |
114 | 108 | let loadingPromise: Promise<void> | undefined; |
115 | 109 |
|
116 | | - $effect(() => { |
117 | | - updateMap(gameStore.world); |
118 | | - }); |
| 110 | + let isBuilding: BuildingType = $derived(uiStore.isBuilding); |
| 111 | + let isMovingThief = $derived(uiStore.isMovingThief); |
| 112 | + let isPlayingKnight = $derived(uiStore.isPlayingKnight); |
| 113 | + let isPlayingRoadBuilding = $derived(uiStore.isPlayingRoadBuilding); |
119 | 114 |
|
120 | 115 | $effect(() => { |
121 | | - isBuilding = uiStore.isBuilding; |
122 | | - isMovingThief = uiStore.isMovingThief; |
123 | | - isPlayingKnight = uiStore.isPlayingKnight; |
124 | | - isPlayingRoadBuilding = uiStore.isPlayingRoadBuilding; |
| 116 | + updateMap(gameStore.world); |
125 | 117 | }); |
126 | 118 |
|
127 | 119 | const toWorld = (screenPoint: { x: number; y: number }): { x: number; y: number } => { |
|
592 | 584 | }; |
593 | 585 |
|
594 | 586 | onMount(() => { |
595 | | - try { |
596 | | - void gameStore.bindToWorld(); |
597 | | - } catch (error) { |
598 | | - console.warn('Unable to bind to world socket', error); |
599 | | - } |
600 | | -
|
601 | | - void setupCanvas(); |
| 587 | + gameStore.bindToWorld(); |
| 588 | + setupCanvas(); |
602 | 589 | handleResize(); |
603 | 590 |
|
604 | 591 | if (container) { |
|
622 | 609 | }); |
623 | 610 | </script> |
624 | 611 |
|
625 | | -<div bind:this={container} class="h-full w-full flex-1 bg-[#03518b]"></div> |
| 612 | +<div bind:this={container} class="h-full w-full flex-1 bg-slate-500"></div> |
0 commit comments