Skip to content

Commit ac281fd

Browse files
Simplify map
1 parent 12cef32 commit ac281fd

1 file changed

Lines changed: 17 additions & 30 deletions

File tree

islanders-client/src/lib/components/Map.svelte

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import type { Grid as HoneycombGrid } from 'honeycomb-grid';
3232
const { defineHex, Grid, Orientation } = honeycombGrid;
3333
34-
let container: HTMLDivElement | undefined;
35-
let parentElement: HTMLElement | null = null;
34+
type HexType = ReturnType<typeof defineHex>;
35+
type CustomHex = InstanceType<HexType>;
3636
3737
const currentPlayer: Player | undefined = $derived(
3838
gameStore.world?.players.find((player: Player) => player.name === gameStore.playerName)
@@ -74,54 +74,46 @@
7474
'/img/numbers/12.png'
7575
];
7676
77-
let app: Application | undefined;
78-
let worldContainer: Container | undefined;
7977
const tileGraphics = new Graphics();
8078
const pieceGraphics = new Graphics();
8179
const lineGraphics = new Graphics();
8280
const cursorGraphics = new Graphics();
8381
const sprites = generateSprites();
8482
85-
type HexType = ReturnType<typeof defineHex>;
86-
type CustomHex = InstanceType<HexType>;
83+
let app: Application | undefined;
84+
let worldContainer: Container | undefined;
8785
let grid: HoneycombGrid<CustomHex> | undefined;
86+
let container: HTMLDivElement | undefined;
87+
let parentElement: HTMLElement | null = null;
8888
let hexFactory: HexType | undefined;
8989
9090
let height = 0;
9191
let width = 0;
9292
93-
// Pan and zoom state
9493
let scale = 1;
9594
let panX = 0;
9695
let panY = 0;
96+
9797
let isDragging = false;
9898
let lastPointerPosition = { x: 0, y: 0 };
9999
let pointerDownPosition = { x: 0, y: 0 };
100100
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;
107103
108104
let resizeObserver: ResizeObserver | undefined;
109105
110-
// Store event handlers for cleanup
111-
let wheelHandler: ((event: WheelEvent) => void) | undefined;
112106
let assetsLoaded = false;
113107
let latestWorld: World | undefined;
114108
let loadingPromise: Promise<void> | undefined;
115109
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);
119114
120115
$effect(() => {
121-
isBuilding = uiStore.isBuilding;
122-
isMovingThief = uiStore.isMovingThief;
123-
isPlayingKnight = uiStore.isPlayingKnight;
124-
isPlayingRoadBuilding = uiStore.isPlayingRoadBuilding;
116+
updateMap(gameStore.world);
125117
});
126118
127119
const toWorld = (screenPoint: { x: number; y: number }): { x: number; y: number } => {
@@ -592,13 +584,8 @@
592584
};
593585
594586
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();
602589
handleResize();
603590
604591
if (container) {
@@ -622,4 +609,4 @@
622609
});
623610
</script>
624611

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

Comments
 (0)