BlueGit

timfa questward

Files

questward / client / src / editor / main.js

main.js

spawner tweaks
timfa Tim Falken · pushed by timfa · 2 months ago
661b81e5 History
main.js 19.9 KiB Download Raw
1import { MessageType, CHUNK_SIZE, SPRITE_SIZE_PX, VISIBLE_CHUNK_RADIUS } from "/shared/protocol/constants.js";
2import {
3 GROUND_DEFINITIONS,
4 BLOCK_DEFINITIONS,
5 GroundType,
6 normalizeGround,
7 normalizeBlock
8} from "/shared/definitions/tiles.js";
9import { cycleState, defaultStateForType, resolveState, statesForType } from "/shared/definitions/tileSprites.js";
10import { defaultSpawnerConfig, normalizeSpawnerConfig, mobDefinition, mobSpriteName } from "/shared/definitions/mobs.js";
11import { GameSocket, defaultSocketUrl } from "../net/socket.js";
12import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour } from "../render/sprites.js";
13import { WorldView } from "../render/worldView.js";
14import { initSettingsModal } from "./settingsModal.js";
15import { initPaletteModal } from "./paletteModal.js";
16import { initTileConfigModal } from "./tileConfigModal.js";
17
18const game = new Game();
19let socket;
20let scene;
21let view;
22let draft = null;
23let chunkX = 0;
24let chunkY = 0;
25let tool = { kind: "ground", typeId: GroundType.grass, state: null };
26let settingsModal;
27let paletteModal;
28let tileConfigModal;
29let catalog = { grounds: {}, blocks: {}, images: [] };
30let imageUrlByName = new Map();
31let hoverLocal = null;
32let editorZoom = null;
33let activeRevisionId = null;
34let pendingRevisionId = null;
35let applyInFlight = false;
36const EDITOR_ZOOM_MIN = 0.25;
37const EDITOR_ZOOM_MAX = 8;
38const EDITOR_ZOOM_STEP = 1.12;
39
40function $ (id)
41{
42 return document.getElementById(id);
43}
44
45function selectedToolLabel ()
46{
47 if (tool.kind === "erase")
48 { return "Erase block"; }
49 if (tool.kind === "spawner")
50 {
51 const def = mobDefinition(tool.mobTypeId);
52 return `Spawner · ${def?.displayName ?? tool.mobTypeId}`;
53 }
54 const def = tool.kind === "ground" ? GROUND_DEFINITIONS[tool.typeId] : BLOCK_DEFINITIONS[tool.typeId];
55 const layer = tool.kind === "ground" ? "ground" : "block";
56 const states = statesForType(catalog, layer, def.key);
57 const state = resolveState(states, tool.state);
58 if (states.length > 1)
59 { return `${def.displayName} (${state})`; }
60 return def.displayName;
61}
62
63function selectTool (next)
64{
65 if (next.kind === "erase")
66 {
67 tool = { kind: "erase" };
68 return;
69 }
70 if (next.kind === "spawner")
71 {
72 tool = { kind: "spawner", mobTypeId: next.mobTypeId };
73 return;
74 }
75 const layer = next.kind === "ground" ? "ground" : "block";
76 const def = next.kind === "ground" ? GROUND_DEFINITIONS[next.typeId] : BLOCK_DEFINITIONS[next.typeId];
77 tool = {
78 kind: next.kind,
79 typeId: next.typeId,
80 state: defaultStateForType(catalog, layer, def.key)
81 };
82}
83
84function placeableToolState ()
85{
86 if (tool.kind === "erase" || tool.kind === "spawner")
87 { return null; }
88 const layer = tool.kind === "ground" ? "ground" : "block";
89 const def = tool.kind === "ground" ? GROUND_DEFINITIONS[tool.typeId] : BLOCK_DEFINITIONS[tool.typeId];
90 return resolveState(statesForType(catalog, layer, def.key), tool.state);
91}
92
93function previewFromTool ()
94{
95 if (tool.kind === "erase")
96 { return { block: null }; }
97 if (tool.kind === "spawner")
98 { return {}; }
99 const state = placeableToolState();
100 if (tool.kind === "ground")
101 { return { ground: { typeId: tool.typeId, state } }; }
102 return { block: { typeId: tool.typeId, state, config: null } };
103}
104
105function inEditorView (x, y)
106{
107 return Math.abs(x - chunkX) <= VISIBLE_CHUNK_RADIUS && Math.abs(y - chunkY) <= VISIBLE_CHUNK_RADIUS;
108}
109
110function neighborhoodCoords (centerX, centerY)
111{
112 const coords = [];
113 for (let dy = -VISIBLE_CHUNK_RADIUS; dy <= VISIBLE_CHUNK_RADIUS; dy++)
114 {
115 for (let dx = -VISIBLE_CHUNK_RADIUS; dx <= VISIBLE_CHUNK_RADIUS; dx++)
116 { coords.push({ chunkX: centerX + dx, chunkY: centerY + dy }); }
117 }
118 return coords;
119}
120
121function snapshotFromPayload (payload)
122{
123 return {
124 chunkX: payload.chunkX,
125 chunkY: payload.chunkY,
126 open: payload.data.open,
127 closedEdges: payload.closedEdges,
128 grounds: payload.data.grounds,
129 blocks: payload.data.blocks,
130 light: payload.data.light,
131 entities: []
132 };
133}
134
135function syncSpawnersOverlay (cx, cy, spawners)
136{
137 view.setEditorSpawners(cx, cy, spawners ?? [], (mobTypeId) => mobSpriteName(mobTypeId));
138}
139
140function spawnerAt (localX, localY)
141{
142 return (draft?.spawners ?? []).find((entry) => entry.localX === localX && entry.localY === localY) ?? null;
143}
144
145function paintAt (localX, localY)
146{
147 if (!draft || localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
148 { return; }
149 const index = localY * CHUNK_SIZE + localX;
150 const state = placeableToolState();
151 if (tool.kind === "ground")
152 { draft.grounds[index] = { typeId: tool.typeId, state }; }
153 else if (tool.kind === "erase")
154 { draft.blocks[index] = null; }
155 else if (tool.kind === "spawner")
156 {
157 const existing = spawnerAt(localX, localY);
158 const spawnerId = existing?.config?.spawnerId ?? `${chunkX}:${chunkY}:${index}`;
159 const entry = {
160 localX,
161 localY,
162 config: normalizeSpawnerConfig({
163 ...defaultSpawnerConfig(spawnerId, tool.mobTypeId),
164 ...(existing?.config ?? {}),
165 spawnerId,
166 mobTypeId: tool.mobTypeId
167 }, spawnerId)
168 };
169 draft.spawners = (draft.spawners ?? []).filter((s) => s.localX !== localX || s.localY !== localY);
170 draft.spawners.push(entry);
171 syncSpawnersOverlay(chunkX, chunkY, draft.spawners);
172 return;
173 }
174 else
175 { draft.blocks[index] = { typeId: tool.typeId, state, config: null }; }
176 view.updateAuthoredTile(chunkX, chunkY, localX, localY, {
177 ground: draft.grounds[index],
178 block: draft.blocks[index],
179 light: draft.light[index]
180 });
181}
182
183function updateRevisionUI ()
184{
185 const applyBtn = $("apply");
186 $("revision").textContent = `active ${activeRevisionId ?? "?"}` +
187 (pendingRevisionId ? ` · pending ${pendingRevisionId}` : " · no pending revision");
188 if (applyBtn)
189 {
190 applyBtn.disabled = !pendingRevisionId || applyInFlight;
191 applyBtn.title = pendingRevisionId
192 ? "Reload the live world with the pending map revision"
193 : "Save a chunk first to create a pending revision";
194 }
195}
196
197function setRevisionState ({ activeRevisionId: active, pendingRevisionId: pending })
198{
199 if (active != null)
200 { activeRevisionId = active; }
201 pendingRevisionId = pending ?? null;
202 updateRevisionUI();
203}
204
205function showSelectedChunk (payload)
206{
207 draft = {
208 open: payload.data.open,
209 grounds: payload.data.grounds.map((ground) => normalizeGround(ground)),
210 blocks: payload.data.blocks.map((block) => (block ? { ...block, config: block.config ?? null } : null)),
211 light: payload.data.light.slice(),
212 spawners: (payload.data.spawners ?? []).map((entry) => ({
213 localX: entry.localX,
214 localY: entry.localY,
215 config: { ...entry.config }
216 }))
217 };
218 $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`;
219 $("open").checked = draft.open;
220 setRevisionState({
221 activeRevisionId: payload.activeRevisionId,
222 pendingRevisionId: payload.pendingRevisionId
223 });
224 $("authored").textContent = payload.authored ? "authored" : "default grass (closed until saved open)";
225 const log = $("changelog");
226 log.innerHTML = "";
227 for (const entry of payload.changelog ?? [])
228 {
229 const item = document.createElement("article");
230 item.innerHTML = `<header>${entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`;
231 const list = document.createElement("ul");
232 for (const bullet of entry.diffEntries)
233 {
234 const li = document.createElement("li");
235 li.textContent = bullet;
236 list.append(li);
237 }
238 item.append(list);
239 log.append(item);
240 }
241 view.applySnapshot(snapshotFromPayload(payload));
242 syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);
243}
244
245function pruneView ()
246{
247 for (const key of [...view.chunks.keys()])
248 {
249 const [x, y] = key.split(",").map(Number);
250 if (!inEditorView(x, y))
251 { view.removeChunk(x, y); }
252 }
253}
254
255function frameNeighborhood ()
256{
257 const size = view.tileSize();
258 view.followPlayer = false;
259 const centerX = (chunkX + 0.5) * CHUNK_SIZE * size;
260 const centerY = (chunkY + 0.5) * CHUNK_SIZE * size;
261 view.scene.cameraPosition.x = view.scene.real_size.x / 2 - centerX;
262 view.scene.cameraPosition.y = view.scene.real_size.y / 2 - centerY;
263 updateSelectionBorder();
264}
265
266function updateSelectionBorder ()
267{
268 const border = $("selection-border");
269 const canvas = scene?.canvas;
270 if (!border || !canvas)
271 { return; }
272
273 const rect = canvas.getBoundingClientRect();
274 const size = view.tileSize();
275 const chunkPx = CHUNK_SIZE * size;
276 const screenLeft = chunkX * CHUNK_SIZE * size + scene.cameraPosition.x;
277 const screenTop = chunkY * CHUNK_SIZE * size + scene.cameraPosition.y;
278 border.style.left = `${rect.left + screenLeft}px`;
279 border.style.top = `${rect.top + screenTop}px`;
280 border.style.width = `${chunkPx}px`;
281 border.style.height = `${chunkPx}px`;
282}
283
284function layoutScene ()
285{
286 const header = document.querySelector("body > header");
287 const aside = document.querySelector("body > aside");
288 const changelog = $("changelog-wrap");
289 const top = header.offsetHeight;
290 aside.style.top = `${top}px`;
291 changelog.style.top = `${top}px`;
292 const left = aside.offsetWidth;
293 const right = changelog.offsetWidth;
294 const width = Math.max(64, window.innerWidth - left - right);
295 const height = Math.max(64, window.innerHeight - top);
296 scene.position.x = left;
297 scene.position.y = top;
298 scene.size.x = width;
299 scene.size.y = height;
300 scene.g_fixSize();
301 useNearestNeighbour(scene, game.images);
302 const fit = Math.min(width, height) / (CHUNK_SIZE * 3 * SPRITE_SIZE_PX);
303 if (editorZoom == null)
304 { editorZoom = fit; }
305 else
306 { editorZoom = Math.min(EDITOR_ZOOM_MAX, Math.max(EDITOR_ZOOM_MIN, editorZoom)); }
307 view.setZoom(editorZoom, { min: EDITOR_ZOOM_MIN, max: EDITOR_ZOOM_MAX });
308 frameNeighborhood();
309}
310
311function zoomEditor (direction)
312{
313 if (!view)
314 { return; }
315 const factor = direction > 0 ? EDITOR_ZOOM_STEP : 1 / EDITOR_ZOOM_STEP;
316 editorZoom = Math.min(EDITOR_ZOOM_MAX, Math.max(EDITOR_ZOOM_MIN, (editorZoom ?? view.zoom) * factor));
317 view.setZoom(editorZoom, { min: EDITOR_ZOOM_MIN, max: EDITOR_ZOOM_MAX });
318 useNearestNeighbour(scene, game.images);
319 frameNeighborhood();
320}
321
322function requestChunks (coords)
323{
324 for (const coord of coords)
325 {
326 socket.send({ type: MessageType.editorLoadChunk, chunkX: coord.chunkX, chunkY: coord.chunkY });
327 }
328}
329
330function loadNeighborhood (x, y)
331{
332 chunkX = x;
333 chunkY = y;
334 $("coords").textContent = `${chunkX}, ${chunkY}`;
335 requestChunks(neighborhoodCoords(x, y));
336}
337
338function requestNeighbors ()
339{
340 requestChunks(neighborhoodCoords(chunkX, chunkY).filter((coord) => coord.chunkX !== chunkX || coord.chunkY !== chunkY));
341}
342
343function anyModalOpen ()
344{
345 return settingsModal?.isOpen() || paletteModal?.isOpen() || tileConfigModal?.isOpen();
346}
347
348function updateTooltip (local)
349{
350 const tip = $("tile-tooltip");
351 if (!tip || !local || !draft)
352 {
353 if (tip)
354 { tip.hidden = true; }
355 view?.clearSpawnRangeHighlight();
356 return;
357 }
358 const block = normalizeBlock(draft.blocks[local.y * CHUNK_SIZE + local.x]);
359 const spawner = spawnerAt(local.x, local.y);
360 const lines = [];
361 if (block)
362 {
363 const def = BLOCK_DEFINITIONS[block.typeId];
364 lines.push(def?.displayName ?? `Block ${block.typeId}`);
365 if (block.config && Object.keys(block.config).length)
366 {
367 for (const [key, value] of Object.entries(block.config))
368 { lines.push(`${key}: ${value}`); }
369 }
370 }
371 if (spawner)
372 {
373 const config = normalizeSpawnerConfig(spawner.config, spawner.config.spawnerId);
374 const mob = mobDefinition(config.mobTypeId);
375 lines.push(`Spawner · ${mob?.displayName ?? config.mobTypeId}`);
376 lines.push(`maxAlive: ${config.maxAlive}`);
377 lines.push(`spawnRange: ${config.spawnRangeTiles}`);
378 lines.push(`wanderRange: ${config.maxWanderRangeTiles}`);
379 lines.push(`id: ${config.spawnerId}`);
380 view.setSpawnRangeHighlight(
381 local.tileX,
382 local.tileY,
383 config.spawnRangeTiles,
384 config.maxWanderRangeTiles
385 );
386 }
387 else
388 { view.clearSpawnRangeHighlight(); }
389 if (!lines.length)
390 {
391 tip.hidden = true;
392 return;
393 }
394 tip.hidden = false;
395 tip.textContent = lines.join("\n");
396 const canvas = scene.canvas;
397 const rect = canvas.getBoundingClientRect();
398 const size = view.tileSize();
399 const screenX = local.tileX * size + scene.cameraPosition.x + rect.left + size;
400 const screenY = local.tileY * size + scene.cameraPosition.y + rect.top;
401 tip.style.left = `${screenX}px`;
402 tip.style.top = `${screenY}px`;
403}
404
405async function main ()
406{
407 catalog = await loadSpriteCatalog();
408 imageUrlByName = new Map((catalog.images ?? []).map((entry) => [entry.name, entry.url]));
409 await preloadCatalogImages(game, catalog);
410 applySpriteSheets(game.images, catalog);
411 scene = new Scene(250, 56, 64, 64);
412 game.loadScene(scene);
413 useNearestNeighbour(scene, game.images);
414 view = new WorldView(game, scene, catalog);
415 view.followPlayer = false;
416 layoutScene();
417 selectTool(tool);
418 $("tool").textContent = selectedToolLabel();
419
420 paletteModal = initPaletteModal({
421 catalog,
422 imageUrlFor: (name) => imageUrlByName.get(name) ?? null,
423 onSelect (next)
424 {
425 selectTool(next);
426 $("tool").textContent = selectedToolLabel();
427 }
428 });
429
430 tileConfigModal = initTileConfigModal({
431 onSave (ctx, config)
432 {
433 if (!draft)
434 { return; }
435 draft.spawners = (draft.spawners ?? []).filter((s) => s.localX !== ctx.localX || s.localY !== ctx.localY);
436 draft.spawners.push({ localX: ctx.localX, localY: ctx.localY, config });
437 syncSpawnersOverlay(chunkX, chunkY, draft.spawners);
438 },
439 onRemove (ctx)
440 {
441 if (!draft)
442 { return; }
443 draft.spawners = (draft.spawners ?? []).filter((s) => s.localX !== ctx.localX || s.localY !== ctx.localY);
444 syncSpawnersOverlay(chunkX, chunkY, draft.spawners);
445 }
446 });
447
448 const ticker = new GameObject(0, 0, null, 10);
449 ticker.update = (dt) =>
450 {
451 hoverLocal = null;
452 const canvas = scene.canvas;
453 const rect = canvas.getBoundingClientRect();
454 const mouseX = GameInput.mousePosition.x - rect.left;
455 const mouseY = GameInput.mousePosition.y - rect.top;
456 const overCanvas = mouseX >= 0 && mouseY >= 0 && mouseX < rect.width && mouseY < rect.height;
457 if (overCanvas && draft && !anyModalOpen())
458 {
459 const tile = view.screenToTile(mouseX, mouseY);
460 const localX = tile.tileX - chunkX * CHUNK_SIZE;
461 const localY = tile.tileY - chunkY * CHUNK_SIZE;
462 if (localX >= 0 && localY >= 0 && localX < CHUNK_SIZE && localY < CHUNK_SIZE)
463 {
464 hoverLocal = { x: localX, y: localY, tileX: tile.tileX, tileY: tile.tileY };
465 view.setTilePreview(tile.tileX, tile.tileY, previewFromTool());
466 updateTooltip(hoverLocal);
467 if (GameInput.mouseHeld(GameInput.MouseButtons.Left))
468 { paintAt(localX, localY); }
469 }
470 else
471 {
472 view.clearTilePreview();
473 updateTooltip(null);
474 }
475 }
476 else
477 {
478 view.clearTilePreview();
479 updateTooltip(null);
480 }
481 view.update(dt);
482 frameNeighborhood();
483 };
484 scene.addObject(ticker);
485 window.addEventListener("resize", layoutScene);
486
487 socket = new GameSocket(defaultSocketUrl(), (message) =>
488 {
489 if (message.type === MessageType.session)
490 {
491 $("who").textContent = `${message.authSubject}${message.isAdmin ? " · admin" : ""}`;
492 socket.send({ type: MessageType.editorLoadSettings });
493 loadNeighborhood(0, 0);
494 }
495 else if (message.type === MessageType.editorSettings)
496 { settingsModal.handleMessage(message); }
497 else if (message.type === MessageType.editorChunk)
498 {
499 if (message.settings)
500 { view.setSettings(message.settings); }
501 if (!inEditorView(message.chunkX, message.chunkY))
502 { return; }
503 if (message.chunkX === chunkX && message.chunkY === chunkY)
504 { showSelectedChunk(message); }
505 else
506 {
507 view.applySnapshot(snapshotFromPayload(message));
508 syncSpawnersOverlay(message.chunkX, message.chunkY, message.data.spawners);
509 }
510 pruneView();
511 }
512 else if (message.type === MessageType.editorRevisionApplied)
513 {
514 applyInFlight = false;
515 setRevisionState({
516 activeRevisionId: message.activeRevisionId,
517 pendingRevisionId: message.pendingRevisionId
518 });
519 const status = $("apply-status");
520 status.textContent = `Applied revision ${message.appliedRevisionId}. Live world reloaded.`;
521 status.className = "hint ok";
522 requestChunks(neighborhoodCoords(chunkX, chunkY));
523 }
524 else if (message.type === MessageType.error)
525 {
526 $("error").textContent = message.message;
527 if (applyInFlight)
528 {
529 applyInFlight = false;
530 $("apply-status").textContent = "";
531 $("apply-status").className = "hint";
532 updateRevisionUI();
533 }
534 }
535 });
536 settingsModal = initSettingsModal({
537 socket,
538 MessageType,
539 onApplied (settings)
540 {
541 view.setSettings(settings);
542 },
543 onPreviewNight (hour)
544 {
545 view.nightPreview = hour;
546 $("night").value = String(hour);
547 $("night-label").textContent = Number(hour).toFixed(1);
548 }
549 });
550 game.startGame();
551 await socket.connect();
552}
553
554$("tool").textContent = selectedToolLabel();
555$("tool-erase").addEventListener("click", () =>
556{
557 selectTool({ kind: "erase" });
558 $("tool").textContent = selectedToolLabel();
559});
560
561$("north").addEventListener("click", () => loadNeighborhood(chunkX, chunkY - 1));
562$("south").addEventListener("click", () => loadNeighborhood(chunkX, chunkY + 1));
563$("west").addEventListener("click", () => loadNeighborhood(chunkX - 1, chunkY));
564$("east").addEventListener("click", () => loadNeighborhood(chunkX + 1, chunkY));
565$("open").addEventListener("change", () =>
566{
567 if (draft)
568 {
569 draft.open = $("open").checked;
570 view.setChunkOpen(chunkX, chunkY, draft.open);
571 }
572});
573$("save").addEventListener("click", () =>
574{
575 $("error").textContent = "";
576 $("apply-status").textContent = "";
577 $("apply-status").className = "hint";
578 socket.send({
579 type: MessageType.editorSaveChunk,
580 chunkX,
581 chunkY,
582 draft: {
583 open: $("open").checked,
584 grounds: draft.grounds,
585 blocks: draft.blocks,
586 spawners: draft.spawners ?? []
587 }
588 });
589 requestNeighbors();
590});
591$("apply").addEventListener("click", () =>
592{
593 if (!pendingRevisionId || applyInFlight)
594 { return; }
595 $("error").textContent = "";
596 const status = $("apply-status");
597 status.textContent = "Applying…";
598 status.className = "hint";
599 applyInFlight = true;
600 updateRevisionUI();
601 socket.send({ type: MessageType.editorApplyRevision });
602});
603$("night").addEventListener("input", () =>
604{
605 view.nightPreview = Number($("night").value);
606 $("night-label").textContent = view.nightPreview.toFixed(1);
607});
608
609function cycleToolState (direction)
610{
611 if (tool.kind === "erase" || tool.kind === "spawner")
612 { return; }
613 const layer = tool.kind === "ground" ? "ground" : "block";
614 const def = tool.kind === "ground" ? GROUND_DEFINITIONS[tool.typeId] : BLOCK_DEFINITIONS[tool.typeId];
615 const states = statesForType(catalog, layer, def.key);
616 if (states.length < 2)
617 { return; }
618 tool.state = cycleState(states, tool.state, direction);
619 $("tool").textContent = selectedToolLabel();
620 if (!draft || !hoverLocal)
621 { return; }
622 const index = hoverLocal.y * CHUNK_SIZE + hoverLocal.x;
623 if (tool.kind === "ground" && normalizeGround(draft.grounds[index]).typeId === tool.typeId)
624 { paintAt(hoverLocal.x, hoverLocal.y); }
625 else if (tool.kind === "block" && draft.blocks[index]?.typeId === tool.typeId)
626 { paintAt(hoverLocal.x, hoverLocal.y); }
627}
628
629document.addEventListener("wheel", (event) =>
630{
631 if (!scene?.canvas || anyModalOpen())
632 { return; }
633 const rect = scene.canvas.getBoundingClientRect();
634 if (event.clientX < rect.left || event.clientX >= rect.right || event.clientY < rect.top || event.clientY >= rect.bottom)
635 { return; }
636 event.preventDefault();
637 if (event.shiftKey)
638 {
639 cycleToolState(event.deltaY < 0 ? 1 : -1);
640 if (hoverLocal)
641 { view.setTilePreview(hoverLocal.tileX, hoverLocal.tileY, previewFromTool()); }
642 return;
643 }
644 zoomEditor(event.deltaY < 0 ? 1 : -1);
645}, { passive: false });
646
647document.addEventListener("contextmenu", (event) =>
648{
649 if (!scene?.canvas || anyModalOpen() || !draft)
650 { return; }
651 const rect = scene.canvas.getBoundingClientRect();
652 if (event.clientX < rect.left || event.clientX >= rect.right || event.clientY < rect.top || event.clientY >= rect.bottom)
653 { return; }
654 event.preventDefault();
655 const tile = view.screenToTile(event.clientX - rect.left, event.clientY - rect.top);
656 const localX = tile.tileX - chunkX * CHUNK_SIZE;
657 const localY = tile.tileY - chunkY * CHUNK_SIZE;
658 if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE)
659 { return; }
660 const spawner = spawnerAt(localX, localY);
661 if (!spawner)
662 { return; }
663 tileConfigModal.openSpawner({
664 localX,
665 localY,
666 tileX: tile.tileX,
667 tileY: tile.tileY,
668 config: { ...spawner.config }
669 });
670});
671
672main().catch((error) =>
673{
674 $("error").textContent = error.message;
675 console.error(error);
676});