| 1 | import { MessageType, CHUNK_SIZE, SPRITE_SIZE_PX, VISIBLE_CHUNK_RADIUS } from "/shared/protocol/constants.js"; |
| 2 | import |
| 3 | { |
| 4 | GROUND_DEFINITIONS, |
| 5 | BLOCK_DEFINITIONS, |
| 6 | GroundType, |
| 7 | BlockType, |
| 8 | normalizeGround, |
| 9 | normalizeBlock, |
| 10 | listPlaceableBlockPaletteEntries |
| 11 | } from "/shared/definitions/tiles.js"; |
| 12 | import { cycleState, defaultStateForType, resolveState, statesForType } from "/shared/definitions/tileSprites.js"; |
| 13 | import |
| 14 | { |
| 15 | SeasonId, |
| 16 | seasonIdAt, |
| 17 | seasonalCycleStates, |
| 18 | seasonIdFromVisualState, |
| 19 | placeableStatesForType |
| 20 | } from "/shared/world/season.js"; |
| 21 | import { loadGraphicsSettings } from "/shared/graphics/settings.js"; |
| 22 | import { randomFlowerColorId, flowerBlockState } from "/shared/definitions/dyes.js"; |
| 23 | import { defaultSpawnerConfig, normalizeSpawnerConfig, mobDefinition, mobSpriteName } from "/shared/definitions/mobs.js"; |
| 24 | import |
| 25 | { |
| 26 | computeNeighborConnectMask, |
| 27 | composeNeighborConnectState, |
| 28 | definitionUsesNeighborConnect, |
| 29 | neighborConnectBlocksMatch, |
| 30 | neighborConnectRefreshTiles, |
| 31 | worldTileToChunkLocal |
| 32 | } from "/shared/world/neighborConnect.js"; |
| 33 | import { GameSocket, defaultSocketUrl } from "../net/socket.js"; |
| 34 | import { fetchAuthStatus, loginUrl, logoutUrl } from "../net/auth.js"; |
| 35 | import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour } from "../render/sprites.js"; |
| 36 | import { WorldView } from "../render/worldView.js"; |
| 37 | import { initSettingsModal, initDimensionSettings } from "./settingsModal.js"; |
| 38 | import { initPaletteModal } from "./paletteModal.js"; |
| 39 | import { initTileConfigModal } from "./tileConfigModal.js"; |
| 40 | import { initQuestsModal } from "./questsModal.js"; |
| 41 | import { initDialoguesModal } from "./dialoguesModal.js"; |
| 42 | import { initGiftsModal } from "./giftsModal.js"; |
| 43 | import { initDimensionPickerModal } from "./dimensionPickerModal.js"; |
| 44 | import |
| 45 | { |
| 46 | OVERWORLD_ID, |
| 47 | normalizeDimensionId, |
| 48 | isOverworld |
| 49 | } from "/shared/world/dimensions.js"; |
| 50 | import { normalizeDoorConfig } from "/shared/world/doorRequirements.js"; |
| 51 | |
| 52 | const game = new Game(); |
| 53 | let socket; |
| 54 | let scene; |
| 55 | let view; |
| 56 | let draft = null; |
| 57 | /** @type {string|null} JSON snapshot of last loaded/saved draft (grounds/blocks/spawners/open). */ |
| 58 | let draftBaseline = null; |
| 59 | /** @type {ReturnType<typeof cloneDraftContents>|null} In-memory chunk clipboard for copy/paste. */ |
| 60 | let chunkClipboard = null; |
| 61 | /** |
| 62 | * Neighbor chunks whose connect masks were updated while editing the selected chunk. |
| 63 | * Key `"chunkX,chunkY"` → `{ open, grounds, blocks, spawners }`. |
| 64 | * @type {Map<string, { open: boolean, grounds: object[], blocks: object[], spawners: object[] }>} |
| 65 | */ |
| 66 | let dirtyNeighborChunks = new Map(); |
| 67 | /** Spawners for loaded non-selected chunks (needed when saving edge-mask fixes). */ |
| 68 | let neighborSpawnersByChunk = new Map(); |
| 69 | /** @type {{ chunkX: number, chunkY: number, dimensionId?: string }|null} */ |
| 70 | let pendingNavigate = null; |
| 71 | /** When true, next matching editorChunk after save should navigate to pendingNavigate. */ |
| 72 | let navigateAfterSave = false; |
| 73 | let chunkX = 0; |
| 74 | let chunkY = 0; |
| 75 | let selectedDimensionId = OVERWORLD_ID; |
| 76 | /** @type {string|null} */ |
| 77 | let pendingCreatedDimensionId = null; |
| 78 | /** @type {Map<string, object>} */ |
| 79 | let dimensionsById = new Map(); |
| 80 | let dimensionPicker = null; |
| 81 | let dimensionSettings = null; |
| 82 | let tool = { kind: "ground", typeId: GroundType.grass, state: null }; |
| 83 | let settingsModal; |
| 84 | let paletteModal; |
| 85 | let tileConfigModal; |
| 86 | let questsModal; |
| 87 | let dialoguesModal; |
| 88 | let giftsModal; |
| 89 | let catalog = { grounds: {}, blocks: {}, images: [] }; |
| 90 | let imageUrlByName = new Map(); |
| 91 | let hoverLocal = null; |
| 92 | let editorZoom = null; |
| 93 | let activeRevisionId = null; |
| 94 | let pendingRevisionId = null; |
| 95 | let applyInFlight = false; |
| 96 | /** @type {string|null} */ |
| 97 | let sessionAuthSubject = null; |
| 98 | const EDITOR_ZOOM_MIN = 0.25; |
| 99 | const EDITOR_ZOOM_MAX = 8; |
| 100 | const EDITOR_ZOOM_STEP = 1.12; |
| 101 | const CONSOLE_MAX_LINES = 2000; |
| 102 | |
| 103 | function $ (id) |
| 104 | { |
| 105 | return document.getElementById(id); |
| 106 | } |
| 107 | |
| 108 | function formatConsoleTime (t) |
| 109 | { |
| 110 | try |
| 111 | { return new Date(t).toLocaleTimeString(); } |
| 112 | catch |
| 113 | { return ""; } |
| 114 | } |
| 115 | |
| 116 | function appendConsoleLine (entry, { scroll = true } = {}) |
| 117 | { |
| 118 | const pre = $("editor-console"); |
| 119 | if (!pre || !entry) |
| 120 | { return; } |
| 121 | const line = document.createElement("div"); |
| 122 | const level = entry.level || "info"; |
| 123 | line.className = `console-${level}`; |
| 124 | line.textContent = `[${formatConsoleTime(entry.t)}] ${entry.text ?? ""}`; |
| 125 | pre.append(line); |
| 126 | while (pre.childElementCount > CONSOLE_MAX_LINES) |
| 127 | { pre.firstChild?.remove(); } |
| 128 | if (scroll) |
| 129 | { pre.scrollTop = pre.scrollHeight; } |
| 130 | } |
| 131 | |
| 132 | function applyConsoleSnapshot (lines) |
| 133 | { |
| 134 | const pre = $("editor-console"); |
| 135 | if (!pre) |
| 136 | { return; } |
| 137 | pre.replaceChildren(); |
| 138 | for (const entry of lines ?? []) |
| 139 | { appendConsoleLine(entry, { scroll: false }); } |
| 140 | pre.scrollTop = pre.scrollHeight; |
| 141 | } |
| 142 | |
| 143 | function initSidePanelTabs () |
| 144 | { |
| 145 | const tabs = document.querySelectorAll(".side-panel-tab"); |
| 146 | const bodies = document.querySelectorAll("[data-side-panel-body]"); |
| 147 | function activate (name) |
| 148 | { |
| 149 | for (const tab of tabs) |
| 150 | { |
| 151 | const on = tab.dataset.sidePanel === name; |
| 152 | tab.classList.toggle("active", on); |
| 153 | tab.setAttribute("aria-selected", on ? "true" : "false"); |
| 154 | } |
| 155 | for (const body of bodies) |
| 156 | { body.hidden = body.dataset.sidePanelBody !== name; } |
| 157 | if (name === "console") |
| 158 | { |
| 159 | const pre = $("editor-console"); |
| 160 | if (pre) |
| 161 | { pre.scrollTop = pre.scrollHeight; } |
| 162 | } |
| 163 | } |
| 164 | for (const tab of tabs) |
| 165 | { |
| 166 | tab.addEventListener("click", () => activate(tab.dataset.sidePanel)); |
| 167 | } |
| 168 | $("console-clear")?.addEventListener("click", () => |
| 169 | { |
| 170 | const pre = $("editor-console"); |
| 171 | if (pre) |
| 172 | { pre.replaceChildren(); } |
| 173 | }); |
| 174 | activate("changelog"); |
| 175 | } |
| 176 | |
| 177 | function selectedToolLabel () |
| 178 | { |
| 179 | if (tool.kind === "erase") |
| 180 | { return "Erase block"; } |
| 181 | if (tool.kind === "spawner") |
| 182 | { |
| 183 | const def = mobDefinition(tool.mobTypeId); |
| 184 | return `Spawner · ${def?.displayName ?? tool.mobTypeId}`; |
| 185 | } |
| 186 | const def = tool.kind === "ground" ? GROUND_DEFINITIONS[tool.typeId] : BLOCK_DEFINITIONS[tool.typeId]; |
| 187 | const layer = tool.kind === "ground" ? "ground" : "block"; |
| 188 | const states = statesForType(catalog, layer, def.key); |
| 189 | const state = resolveState(states, tool.state); |
| 190 | if (tool.kind === "block" && def.id === BlockType.flower) |
| 191 | { return "Flower"; } |
| 192 | if (tool.kind === "block" && def.id === BlockType.boulder) |
| 193 | { |
| 194 | const entry = listPlaceableBlockPaletteEntries(catalog) |
| 195 | .find((row) => row.typeId === def.id && row.state === state); |
| 196 | if (entry) |
| 197 | { return entry.displayName; } |
| 198 | } |
| 199 | if (states.length > 1) |
| 200 | { return `${def.displayName} (${state})`; } |
| 201 | return def.displayName; |
| 202 | } |
| 203 | |
| 204 | function selectTool (next) |
| 205 | { |
| 206 | if (next.kind === "erase") |
| 207 | { |
| 208 | tool = { kind: "erase" }; |
| 209 | return; |
| 210 | } |
| 211 | if (next.kind === "spawner") |
| 212 | { |
| 213 | tool = { kind: "spawner", mobTypeId: next.mobTypeId }; |
| 214 | return; |
| 215 | } |
| 216 | const layer = next.kind === "ground" ? "ground" : "block"; |
| 217 | const def = next.kind === "ground" ? GROUND_DEFINITIONS[next.typeId] : BLOCK_DEFINITIONS[next.typeId]; |
| 218 | tool = { |
| 219 | kind: next.kind, |
| 220 | typeId: next.typeId, |
| 221 | state: next.state ?? defaultStateForType(catalog, layer, def.key) |
| 222 | }; |
| 223 | } |
| 224 | |
| 225 | function placeableToolState () |
| 226 | { |
| 227 | if (tool.kind === "erase" || tool.kind === "spawner") |
| 228 | { return null; } |
| 229 | const layer = tool.kind === "ground" ? "ground" : "block"; |
| 230 | const def = tool.kind === "ground" ? GROUND_DEFINITIONS[tool.typeId] : BLOCK_DEFINITIONS[tool.typeId]; |
| 231 | return resolveState(statesForType(catalog, layer, def.key), tool.state); |
| 232 | } |
| 233 | |
| 234 | function previewFromTool () |
| 235 | { |
| 236 | if (tool.kind === "erase") |
| 237 | { return { block: null }; } |
| 238 | if (tool.kind === "spawner") |
| 239 | { return {}; } |
| 240 | const state = placeableToolState(); |
| 241 | if (tool.kind === "ground") |
| 242 | { return { ground: { typeId: tool.typeId, state } }; } |
| 243 | return { block: { typeId: tool.typeId, state, config: null } }; |
| 244 | } |
| 245 | |
| 246 | function inEditorView (x, y) |
| 247 | { |
| 248 | return Math.abs(x - chunkX) <= VISIBLE_CHUNK_RADIUS && Math.abs(y - chunkY) <= VISIBLE_CHUNK_RADIUS; |
| 249 | } |
| 250 | |
| 251 | function neighborhoodCoords (centerX, centerY) |
| 252 | { |
| 253 | const coords = []; |
| 254 | for (let dy = -VISIBLE_CHUNK_RADIUS; dy <= VISIBLE_CHUNK_RADIUS; dy++) |
| 255 | { |
| 256 | for (let dx = -VISIBLE_CHUNK_RADIUS; dx <= VISIBLE_CHUNK_RADIUS; dx++) |
| 257 | { coords.push({ chunkX: centerX + dx, chunkY: centerY + dy }); } |
| 258 | } |
| 259 | return coords; |
| 260 | } |
| 261 | |
| 262 | function snapshotFromPayload (payload) |
| 263 | { |
| 264 | return { |
| 265 | chunkX: payload.chunkX, |
| 266 | chunkY: payload.chunkY, |
| 267 | open: payload.data.open, |
| 268 | closedEdges: payload.closedEdges, |
| 269 | grounds: payload.data.grounds, |
| 270 | blocks: payload.data.blocks, |
| 271 | light: payload.data.light, |
| 272 | entities: [] |
| 273 | }; |
| 274 | } |
| 275 | |
| 276 | function syncSpawnersOverlay (cx, cy, spawners) |
| 277 | { |
| 278 | view.setEditorSpawners(cx, cy, spawners ?? [], (mobTypeId) => mobSpriteName(mobTypeId)); |
| 279 | } |
| 280 | |
| 281 | function spawnerAt (localX, localY) |
| 282 | { |
| 283 | return (draft?.spawners ?? []).find((entry) => entry.localX === localX && entry.localY === localY) ?? null; |
| 284 | } |
| 285 | |
| 286 | function draftPersistable () |
| 287 | { |
| 288 | if (!draft) |
| 289 | { return null; } |
| 290 | return { |
| 291 | open: !!draft.open, |
| 292 | grounds: draft.grounds, |
| 293 | blocks: draft.blocks, |
| 294 | spawners: draft.spawners ?? [] |
| 295 | }; |
| 296 | } |
| 297 | |
| 298 | function cloneDraftContents (source) |
| 299 | { |
| 300 | if (!source) |
| 301 | { return null; } |
| 302 | const tileCount = CHUNK_SIZE * CHUNK_SIZE; |
| 303 | return { |
| 304 | open: !!source.open, |
| 305 | grounds: (source.grounds ?? []).map((ground) => normalizeGround(ground)), |
| 306 | blocks: (source.blocks ?? []).map((block) => (block |
| 307 | ? { |
| 308 | ...block, |
| 309 | config: block.config != null ? structuredClone(block.config) : null |
| 310 | } |
| 311 | : null)), |
| 312 | light: Array.isArray(source.light) && source.light.length === tileCount |
| 313 | ? source.light.slice() |
| 314 | : new Array(tileCount).fill(0), |
| 315 | spawners: (source.spawners ?? []).map((entry) => ({ |
| 316 | localX: entry.localX | 0, |
| 317 | localY: entry.localY | 0, |
| 318 | config: structuredClone(entry.config ?? {}) |
| 319 | })) |
| 320 | }; |
| 321 | } |
| 322 | |
| 323 | function blankChunkContents () |
| 324 | { |
| 325 | const groundTypeId = dimensionsById.get(selectedDimensionId)?.defaultGroundTypeId |
| 326 | ?? GroundType.grass; |
| 327 | const tileCount = CHUNK_SIZE * CHUNK_SIZE; |
| 328 | return { |
| 329 | open: false, |
| 330 | grounds: new Array(tileCount).fill(null).map(() => normalizeGround(groundTypeId, groundTypeId)), |
| 331 | blocks: new Array(tileCount).fill(null), |
| 332 | light: new Array(tileCount).fill(0), |
| 333 | spawners: [] |
| 334 | }; |
| 335 | } |
| 336 | |
| 337 | function applyDraftContents (next) |
| 338 | { |
| 339 | if (!draft || !next || isSelectedDimensionSoftDeleted()) |
| 340 | { return; } |
| 341 | clearNeighborEditState(); |
| 342 | draft.open = !!next.open; |
| 343 | draft.grounds = next.grounds.map((ground) => normalizeGround(ground)); |
| 344 | draft.blocks = next.blocks.map((block) => (block |
| 345 | ? { ...block, config: block.config ?? null } |
| 346 | : null)); |
| 347 | draft.light = Array.isArray(next.light) ? next.light.slice() : new Array(CHUNK_SIZE * CHUNK_SIZE).fill(0); |
| 348 | draft.spawners = (next.spawners ?? []).map((entry) => ({ |
| 349 | localX: entry.localX | 0, |
| 350 | localY: entry.localY | 0, |
| 351 | config: { ...(entry.config ?? {}) } |
| 352 | })); |
| 353 | $("open").checked = draft.open; |
| 354 | const existing = view?.chunks.get(chunkKey(chunkX, chunkY)); |
| 355 | view.applySnapshot({ |
| 356 | chunkX, |
| 357 | chunkY, |
| 358 | open: draft.open, |
| 359 | closedEdges: existing?.closedEdges, |
| 360 | grounds: draft.grounds, |
| 361 | blocks: draft.blocks, |
| 362 | light: draft.light, |
| 363 | entities: [] |
| 364 | }); |
| 365 | syncSpawnersOverlay(chunkX, chunkY, draft.spawners); |
| 366 | afterDraftMutation(); |
| 367 | } |
| 368 | |
| 369 | function syncChunkClipboardButtons () |
| 370 | { |
| 371 | const softDeleted = isSelectedDimensionSoftDeleted(); |
| 372 | const copyBtn = $("copy-chunk"); |
| 373 | const pasteBtn = $("paste-chunk"); |
| 374 | const clearBtn = $("clear-chunk"); |
| 375 | if (copyBtn) |
| 376 | { |
| 377 | copyBtn.disabled = !draft || softDeleted; |
| 378 | copyBtn.title = softDeleted |
| 379 | ? "Cannot copy while this dimension is soft-deleted" |
| 380 | : "Copy this chunk into the editor clipboard"; |
| 381 | } |
| 382 | if (pasteBtn) |
| 383 | { |
| 384 | const canPaste = !!draft && !!chunkClipboard && !softDeleted; |
| 385 | pasteBtn.disabled = !canPaste; |
| 386 | pasteBtn.title = softDeleted |
| 387 | ? "Cannot paste while this dimension is soft-deleted" |
| 388 | : chunkClipboard |
| 389 | ? "Paste the copied chunk over the current draft (does not save)" |
| 390 | : "Copy a chunk first"; |
| 391 | } |
| 392 | if (clearBtn) |
| 393 | { |
| 394 | clearBtn.disabled = !draft || softDeleted; |
| 395 | clearBtn.title = softDeleted |
| 396 | ? "Cannot clear while this dimension is soft-deleted" |
| 397 | : "Erase this chunk to a blank slate (does not save)"; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | function copySelectedChunk () |
| 402 | { |
| 403 | if (!draft || isSelectedDimensionSoftDeleted()) |
| 404 | { return; } |
| 405 | chunkClipboard = cloneDraftContents(draft); |
| 406 | syncChunkClipboardButtons(); |
| 407 | } |
| 408 | |
| 409 | function pasteSelectedChunk () |
| 410 | { |
| 411 | if (!draft || !chunkClipboard || isSelectedDimensionSoftDeleted()) |
| 412 | { return; } |
| 413 | const ok = window.confirm( |
| 414 | "This will replace your current chunk entirely with your copied chunk. Are you sure?" |
| 415 | ); |
| 416 | if (!ok) |
| 417 | { return; } |
| 418 | applyDraftContents(cloneDraftContents(chunkClipboard)); |
| 419 | } |
| 420 | |
| 421 | function clearSelectedChunk () |
| 422 | { |
| 423 | if (!draft || isSelectedDimensionSoftDeleted()) |
| 424 | { return; } |
| 425 | const ok = window.confirm( |
| 426 | "this will erase the chunk and reset it to a default blank slate. Are you certain?" |
| 427 | ); |
| 428 | if (!ok) |
| 429 | { return; } |
| 430 | applyDraftContents(blankChunkContents()); |
| 431 | } |
| 432 | |
| 433 | function captureDraftBaseline () |
| 434 | { |
| 435 | const payload = draftPersistable(); |
| 436 | draftBaseline = payload ? JSON.stringify(payload) : null; |
| 437 | syncSaveButton(); |
| 438 | } |
| 439 | |
| 440 | function chunkKey (cx, cy) |
| 441 | { |
| 442 | return `${cx},${cy}`; |
| 443 | } |
| 444 | |
| 445 | function isDraftDirty () |
| 446 | { |
| 447 | if (dirtyNeighborChunks.size > 0) |
| 448 | { return true; } |
| 449 | if (!draft || draftBaseline == null) |
| 450 | { return false; } |
| 451 | return JSON.stringify(draftPersistable()) !== draftBaseline; |
| 452 | } |
| 453 | |
| 454 | function syncSaveButton () |
| 455 | { |
| 456 | const btn = $("save"); |
| 457 | if (!btn) |
| 458 | { return; } |
| 459 | const softDeleted = isSelectedDimensionSoftDeleted(); |
| 460 | const dirty = isDraftDirty(); |
| 461 | btn.disabled = !dirty || softDeleted; |
| 462 | btn.classList.toggle("save-dirty", dirty && !softDeleted); |
| 463 | btn.title = softDeleted |
| 464 | ? "Cannot save while this dimension is soft-deleted" |
| 465 | : dirty |
| 466 | ? "Save unsaved chunk changes" |
| 467 | : "No unsaved changes"; |
| 468 | syncChunkClipboardButtons(); |
| 469 | } |
| 470 | |
| 471 | function afterDraftMutation () |
| 472 | { |
| 473 | syncSaveButton(); |
| 474 | } |
| 475 | |
| 476 | function clearNeighborEditState () |
| 477 | { |
| 478 | dirtyNeighborChunks.clear(); |
| 479 | } |
| 480 | |
| 481 | function groundAtWorld (tileX, tileY) |
| 482 | { |
| 483 | const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE); |
| 484 | const index = localY * CHUNK_SIZE + localX; |
| 485 | if (cx === chunkX && cy === chunkY && draft) |
| 486 | { return draft.grounds[index] ?? null; } |
| 487 | const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy)); |
| 488 | if (dirty) |
| 489 | { return dirty.grounds[index] ?? null; } |
| 490 | const snapshot = view?.chunks.get(chunkKey(cx, cy)); |
| 491 | return snapshot?.grounds?.[index] ?? null; |
| 492 | } |
| 493 | |
| 494 | function spawnerAtWorld (tileX, tileY) |
| 495 | { |
| 496 | const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE); |
| 497 | if (cx === chunkX && cy === chunkY && draft) |
| 498 | { return spawnerAt(localX, localY); } |
| 499 | const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy)); |
| 500 | if (dirty) |
| 501 | { return dirty.spawners?.find((entry) => entry.localX === localX && entry.localY === localY) ?? null; } |
| 502 | return (neighborSpawnersByChunk.get(chunkKey(cx, cy)) ?? []) |
| 503 | .find((entry) => entry.localX === localX && entry.localY === localY) ?? null; |
| 504 | } |
| 505 | |
| 506 | /** Human-readable summary of authored ground/block/spawner on a world tile. */ |
| 507 | function describeWorldTile (tileX, tileY, dimensionId = selectedDimensionId) |
| 508 | { |
| 509 | const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID); |
| 510 | if (dim !== selectedDimensionId) |
| 511 | { |
| 512 | return `Currently editing “${selectedDimensionId}”; switch to “${dim}” to inspect this tile.`; |
| 513 | } |
| 514 | const { chunkX: cx, chunkY: cy } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE); |
| 515 | const key = chunkKey(cx, cy); |
| 516 | const loaded = (cx === chunkX && cy === chunkY && draft) |
| 517 | || dirtyNeighborChunks.has(key) |
| 518 | || view?.chunks?.has(key); |
| 519 | if (!loaded) |
| 520 | { return `Chunk (${cx}, ${cy}) not loaded — center on this tile to load it.`; } |
| 521 | |
| 522 | const lines = []; |
| 523 | const ground = normalizeGround(groundAtWorld(tileX, tileY)); |
| 524 | const groundDef = GROUND_DEFINITIONS[ground?.typeId]; |
| 525 | lines.push(`Ground: ${groundDef?.displayName ?? `type ${ground?.typeId ?? "?"}`}`); |
| 526 | const block = normalizeBlock(blockAtWorld(tileX, tileY)); |
| 527 | if (block) |
| 528 | { |
| 529 | const blockDef = BLOCK_DEFINITIONS[block.typeId]; |
| 530 | lines.push(`Block: ${blockDef?.displayName ?? `type ${block.typeId}`}${block.state ? ` (${block.state})` : ""}`); |
| 531 | if (block.config && Object.keys(block.config).length) |
| 532 | { |
| 533 | for (const [keyName, value] of Object.entries(block.config)) |
| 534 | { lines.push(` ${keyName}: ${value}`); } |
| 535 | } |
| 536 | } |
| 537 | else |
| 538 | { lines.push("Block: (none)"); } |
| 539 | const spawner = spawnerAtWorld(tileX, tileY); |
| 540 | if (spawner) |
| 541 | { |
| 542 | const config = normalizeSpawnerConfig(spawner.config, spawner.config?.spawnerId); |
| 543 | const mob = mobDefinition(config.mobTypeId); |
| 544 | lines.push(`Spawner: ${mob?.displayName ?? config.mobTypeId} (${config.spawnerId})`); |
| 545 | } |
| 546 | else |
| 547 | { lines.push("Spawner: (none)"); } |
| 548 | return lines.join("\n"); |
| 549 | } |
| 550 | |
| 551 | /** Pan the editor to a world tile without closing other UI; loads its chunk neighborhood. */ |
| 552 | function centerEditorOnTile (tileX, tileY, dimensionId = selectedDimensionId) |
| 553 | { |
| 554 | const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID); |
| 555 | const { chunkX: cx, chunkY: cy } = worldTileToChunkLocal(tileX | 0, tileY | 0, CHUNK_SIZE); |
| 556 | if (dim !== selectedDimensionId) |
| 557 | { |
| 558 | if (isDraftDirty()) |
| 559 | { |
| 560 | showUnsavedModal({ chunkX: cx, chunkY: cy, dimensionId: dim }); |
| 561 | return false; |
| 562 | } |
| 563 | selectedDimensionId = dim; |
| 564 | syncDimensionUi(); |
| 565 | clearNeighborhoodView(); |
| 566 | doLoadNeighborhood(cx, cy); |
| 567 | } |
| 568 | else if (cx !== chunkX || cy !== chunkY) |
| 569 | { |
| 570 | if (isDraftDirty()) |
| 571 | { |
| 572 | showUnsavedModal({ chunkX: cx, chunkY: cy, dimensionId: selectedDimensionId }); |
| 573 | return false; |
| 574 | } |
| 575 | doLoadNeighborhood(cx, cy); |
| 576 | } |
| 577 | if (!view?.scene) |
| 578 | { return true; } |
| 579 | const size = view.tileSize(); |
| 580 | view.followPlayer = false; |
| 581 | view.scene.cameraPosition.x = view.scene.real_size.x / 2 - ((tileX | 0) + 0.5) * size; |
| 582 | view.scene.cameraPosition.y = view.scene.real_size.y / 2 - ((tileY | 0) + 0.5) * size; |
| 583 | view.refreshViewport(); |
| 584 | updateSelectionBorder(); |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | function blockAtWorld (tileX, tileY) |
| 589 | { |
| 590 | const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE); |
| 591 | if (cx === chunkX && cy === chunkY && draft) |
| 592 | { return draft.blocks[localY * CHUNK_SIZE + localX] ?? null; } |
| 593 | const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy)); |
| 594 | if (dirty) |
| 595 | { return dirty.blocks[localY * CHUNK_SIZE + localX] ?? null; } |
| 596 | const snapshot = view?.chunks.get(chunkKey(cx, cy)); |
| 597 | return snapshot?.blocks?.[localY * CHUNK_SIZE + localX] ?? null; |
| 598 | } |
| 599 | |
| 600 | function ensureDirtyNeighborChunk (cx, cy) |
| 601 | { |
| 602 | const key = chunkKey(cx, cy); |
| 603 | let data = dirtyNeighborChunks.get(key); |
| 604 | if (data) |
| 605 | { return data; } |
| 606 | const snapshot = view?.chunks.get(key); |
| 607 | if (!snapshot) |
| 608 | { return null; } |
| 609 | data = { |
| 610 | open: !!snapshot.open, |
| 611 | grounds: (snapshot.grounds ?? []).map((ground) => normalizeGround(ground)), |
| 612 | blocks: (snapshot.blocks ?? []).map((block) => (block ? { ...block, config: block.config ?? null } : null)), |
| 613 | spawners: structuredClone(neighborSpawnersByChunk.get(key) ?? []) |
| 614 | }; |
| 615 | dirtyNeighborChunks.set(key, data); |
| 616 | return data; |
| 617 | } |
| 618 | |
| 619 | function writeBlockAtWorld (tileX, tileY, block) |
| 620 | { |
| 621 | const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE); |
| 622 | const index = localY * CHUNK_SIZE + localX; |
| 623 | if (cx === chunkX && cy === chunkY && draft) |
| 624 | { |
| 625 | draft.blocks[index] = block; |
| 626 | view.updateAuthoredTile(cx, cy, localX, localY, { |
| 627 | ground: draft.grounds[index], |
| 628 | block: draft.blocks[index], |
| 629 | light: draft.light[index] |
| 630 | }); |
| 631 | return true; |
| 632 | } |
| 633 | const data = ensureDirtyNeighborChunk(cx, cy); |
| 634 | if (!data) |
| 635 | { return false; } |
| 636 | data.blocks[index] = block; |
| 637 | const snapshot = view?.chunks.get(chunkKey(cx, cy)); |
| 638 | const light = snapshot?.light?.[index]; |
| 639 | view.updateAuthoredTile(cx, cy, localX, localY, { |
| 640 | ground: data.grounds[index], |
| 641 | block: data.blocks[index], |
| 642 | light |
| 643 | }); |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | function showUnsavedModal (target) |
| 648 | { |
| 649 | pendingNavigate = target; |
| 650 | $("unsaved-chunk-backdrop").hidden = false; |
| 651 | $("unsaved-chunk-modal").hidden = false; |
| 652 | } |
| 653 | |
| 654 | function hideUnsavedModal () |
| 655 | { |
| 656 | $("unsaved-chunk-backdrop").hidden = true; |
| 657 | $("unsaved-chunk-modal").hidden = true; |
| 658 | } |
| 659 | |
| 660 | function saveSelectedChunk () |
| 661 | { |
| 662 | if (!draft || !isDraftDirty()) |
| 663 | { return false; } |
| 664 | if (isSelectedDimensionSoftDeleted()) |
| 665 | { |
| 666 | $("error").textContent = "Cannot save while this dimension is soft-deleted."; |
| 667 | return false; |
| 668 | } |
| 669 | $("error").textContent = ""; |
| 670 | $("apply-status").textContent = ""; |
| 671 | $("apply-status").className = "hint"; |
| 672 | const neighborSaves = [...dirtyNeighborChunks.entries()]; |
| 673 | clearNeighborEditState(); |
| 674 | const savedChunks = [{ chunkX, chunkY }]; |
| 675 | socket.send({ |
| 676 | type: MessageType.editorSaveChunk, |
| 677 | chunkX, |
| 678 | chunkY, |
| 679 | dimensionId: selectedDimensionId, |
| 680 | draft: { |
| 681 | open: $("open").checked, |
| 682 | grounds: draft.grounds, |
| 683 | blocks: draft.blocks, |
| 684 | spawners: draft.spawners ?? [] |
| 685 | } |
| 686 | }); |
| 687 | for (const [key, data] of neighborSaves) |
| 688 | { |
| 689 | const [cx, cy] = key.split(",").map(Number); |
| 690 | savedChunks.push({ chunkX: cx, chunkY: cy }); |
| 691 | socket.send({ |
| 692 | type: MessageType.editorSaveChunk, |
| 693 | chunkX: cx, |
| 694 | chunkY: cy, |
| 695 | dimensionId: selectedDimensionId, |
| 696 | draft: { |
| 697 | open: data.open, |
| 698 | grounds: data.grounds, |
| 699 | blocks: data.blocks, |
| 700 | spawners: data.spawners ?? [] |
| 701 | } |
| 702 | }); |
| 703 | } |
| 704 | view?.bakeNatureTintForChunks?.(savedChunks); |
| 705 | requestNeighbors(); |
| 706 | return true; |
| 707 | } |
| 708 | |
| 709 | function isSelectedDimensionSoftDeleted () |
| 710 | { |
| 711 | const record = dimensionsById.get(selectedDimensionId); |
| 712 | return record?.deletedAt != null; |
| 713 | } |
| 714 | |
| 715 | function formatPurgeHint (record) |
| 716 | { |
| 717 | if (!record?.purgeAfter) |
| 718 | { return "Soft-deleted — painting disabled."; } |
| 719 | const when = new Date(record.purgeAfter); |
| 720 | return `Soft-deleted — purges ${when.toLocaleString()} (painting disabled).`; |
| 721 | } |
| 722 | |
| 723 | function syncDimensionUi () |
| 724 | { |
| 725 | const record = dimensionsById.get(selectedDimensionId); |
| 726 | const softDeleted = record?.deletedAt != null; |
| 727 | const hint = $("dimension-purge-hint"); |
| 728 | if (hint) |
| 729 | { |
| 730 | hint.hidden = !softDeleted; |
| 731 | hint.textContent = softDeleted ? formatPurgeHint(record) : ""; |
| 732 | } |
| 733 | const openToggle = $("open"); |
| 734 | if (openToggle) |
| 735 | { openToggle.disabled = softDeleted; } |
| 736 | dimensionPicker?.setValue(selectedDimensionId); |
| 737 | dimensionSettings?.refresh(); |
| 738 | syncSaveButton(); |
| 739 | } |
| 740 | |
| 741 | function applyDimensionsList (payload) |
| 742 | { |
| 743 | const list = Array.isArray(payload?.dimensions) ? payload.dimensions : []; |
| 744 | dimensionsById = new Map(list.map((dim) => [dim.dimensionId, dim])); |
| 745 | if (!dimensionsById.has(OVERWORLD_ID)) |
| 746 | { |
| 747 | dimensionsById.set(OVERWORLD_ID, { |
| 748 | dimensionId: OVERWORLD_ID, |
| 749 | displayName: "Overworld", |
| 750 | lightingMode: "dayNight", |
| 751 | seasonMode: "auto", |
| 752 | defaultGroundTypeId: 1, |
| 753 | deletedAt: null, |
| 754 | purgeAfter: null |
| 755 | }); |
| 756 | } |
| 757 | const options = [...dimensionsById.values()].map((dim) => ({ |
| 758 | id: dim.dimensionId, |
| 759 | label: dim.displayName || dim.dimensionId, |
| 760 | disabled: dim.deletedAt != null, |
| 761 | hint: dim.deletedAt != null ? formatPurgeHint(dim) : null |
| 762 | })); |
| 763 | dimensionPicker?.setOptions(options); |
| 764 | const createdId = pendingCreatedDimensionId; |
| 765 | pendingCreatedDimensionId = null; |
| 766 | if (createdId && dimensionsById.has(createdId)) |
| 767 | { |
| 768 | setRevisionState({ |
| 769 | activeRevisionId: payload.activeRevisionId, |
| 770 | pendingRevisionId: payload.pendingRevisionId |
| 771 | }); |
| 772 | selectDimension(createdId, { force: true }); |
| 773 | return; |
| 774 | } |
| 775 | if (!dimensionsById.has(selectedDimensionId)) |
| 776 | { selectedDimensionId = OVERWORLD_ID; } |
| 777 | setRevisionState({ |
| 778 | activeRevisionId: payload.activeRevisionId, |
| 779 | pendingRevisionId: payload.pendingRevisionId |
| 780 | }); |
| 781 | syncDimensionUi(); |
| 782 | if (!isDraftDirty()) |
| 783 | { requestChunks(neighborhoodCoords(chunkX, chunkY)); } |
| 784 | } |
| 785 | |
| 786 | function requestDimensions () |
| 787 | { |
| 788 | socket.send({ type: MessageType.editorListDimensions }); |
| 789 | } |
| 790 | |
| 791 | function selectDimension (dimensionId, { force = false } = {}) |
| 792 | { |
| 793 | const nextId = normalizeDimensionId(dimensionId); |
| 794 | if (!force && nextId === selectedDimensionId) |
| 795 | { return; } |
| 796 | if (!force && isDraftDirty()) |
| 797 | { |
| 798 | showUnsavedModal({ chunkX, chunkY, dimensionId: nextId }); |
| 799 | dimensionPicker?.setValue(selectedDimensionId); |
| 800 | return; |
| 801 | } |
| 802 | selectedDimensionId = nextId; |
| 803 | syncDimensionUi(); |
| 804 | clearNeighborhoodView(); |
| 805 | doLoadNeighborhood(chunkX, chunkY); |
| 806 | } |
| 807 | |
| 808 | function clearNeighborhoodView () |
| 809 | { |
| 810 | draft = null; |
| 811 | draftBaseline = null; |
| 812 | clearNeighborEditState(); |
| 813 | neighborSpawnersByChunk.clear(); |
| 814 | if (!view) |
| 815 | { return; } |
| 816 | for (const key of [...view.chunks.keys()]) |
| 817 | { |
| 818 | const [x, y] = key.split(",").map(Number); |
| 819 | view.removeChunk(x, y); |
| 820 | } |
| 821 | view.clearEditorSpawners?.(); |
| 822 | syncSaveButton(); |
| 823 | } |
| 824 | |
| 825 | function paintAt (localX, localY) |
| 826 | { |
| 827 | if (!draft || localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE) |
| 828 | { return; } |
| 829 | if (isSelectedDimensionSoftDeleted()) |
| 830 | { return; } |
| 831 | const index = localY * CHUNK_SIZE + localX; |
| 832 | const state = placeableToolState(); |
| 833 | if (tool.kind === "ground") |
| 834 | { draft.grounds[index] = { typeId: tool.typeId, state }; } |
| 835 | else if (tool.kind === "erase") |
| 836 | { |
| 837 | const removed = draft.blocks[index]; |
| 838 | draft.blocks[index] = null; |
| 839 | view.updateAuthoredTile(chunkX, chunkY, localX, localY, { |
| 840 | ground: draft.grounds[index], |
| 841 | block: draft.blocks[index], |
| 842 | light: draft.light[index] |
| 843 | }); |
| 844 | if (removed && definitionUsesNeighborConnect(BLOCK_DEFINITIONS[removed.typeId])) |
| 845 | { refreshNeighborConnect(localX, localY, removed.typeId); } |
| 846 | afterDraftMutation(); |
| 847 | return; |
| 848 | } |
| 849 | else if (tool.kind === "spawner") |
| 850 | { |
| 851 | const existing = spawnerAt(localX, localY); |
| 852 | const spawnerId = existing?.config?.spawnerId |
| 853 | ?? `${normalizeDimensionId(selectedDimensionId)}:${chunkX}:${chunkY}:${index}`; |
| 854 | const entry = { |
| 855 | localX, |
| 856 | localY, |
| 857 | config: normalizeSpawnerConfig({ |
| 858 | ...defaultSpawnerConfig(spawnerId, tool.mobTypeId), |
| 859 | ...(existing?.config ?? {}), |
| 860 | spawnerId, |
| 861 | mobTypeId: tool.mobTypeId |
| 862 | }, spawnerId) |
| 863 | }; |
| 864 | draft.spawners = (draft.spawners ?? []).filter((s) => s.localX !== localX || s.localY !== localY); |
| 865 | draft.spawners.push(entry); |
| 866 | syncSpawnersOverlay(chunkX, chunkY, draft.spawners); |
| 867 | afterDraftMutation(); |
| 868 | return; |
| 869 | } |
| 870 | else |
| 871 | { |
| 872 | const def = BLOCK_DEFINITIONS[tool.typeId]; |
| 873 | if (def?.id === BlockType.fishingSpot) |
| 874 | { |
| 875 | const groundType = draft.grounds[index]?.typeId; |
| 876 | if (groundType !== GroundType.water && groundType !== GroundType.deepWater) |
| 877 | { return; } |
| 878 | } |
| 879 | let nextState = definitionUsesNeighborConnect(def) |
| 880 | ? composeNeighborConnectState(def, state, 0) |
| 881 | : state; |
| 882 | if (def?.id === BlockType.flower) |
| 883 | { nextState = flowerBlockState(randomFlowerColorId()); } |
| 884 | if (def?.id === BlockType.fishingSpot && !nextState) |
| 885 | { nextState = "fishing-spot"; } |
| 886 | const config = def?.id === BlockType.doorway |
| 887 | ? { |
| 888 | targetDimensionId: selectedDimensionId, |
| 889 | tileX: chunkX * CHUNK_SIZE + localX, |
| 890 | tileY: chunkY * CHUNK_SIZE + localY |
| 891 | } |
| 892 | : (def?.id === BlockType.fishingSpot |
| 893 | ? { fishes: [] } |
| 894 | : null); |
| 895 | if (def?.id === BlockType.doorway && !nextState) |
| 896 | { nextState = "door"; } |
| 897 | draft.blocks[index] = { typeId: tool.typeId, state: nextState, config }; |
| 898 | view.updateAuthoredTile(chunkX, chunkY, localX, localY, { |
| 899 | ground: draft.grounds[index], |
| 900 | block: draft.blocks[index], |
| 901 | light: draft.light[index] |
| 902 | }); |
| 903 | if (definitionUsesNeighborConnect(def)) |
| 904 | { refreshNeighborConnect(localX, localY, tool.typeId); } |
| 905 | afterDraftMutation(); |
| 906 | return; |
| 907 | } |
| 908 | view.updateAuthoredTile(chunkX, chunkY, localX, localY, { |
| 909 | ground: draft.grounds[index], |
| 910 | block: draft.blocks[index], |
| 911 | light: draft.light[index] |
| 912 | }); |
| 913 | afterDraftMutation(); |
| 914 | } |
| 915 | |
| 916 | /** Recompute neighbor-connect masks around a local tile, including across chunk edges. */ |
| 917 | function refreshNeighborConnect (localX, localY, typeId) |
| 918 | { |
| 919 | const def = BLOCK_DEFINITIONS[typeId]; |
| 920 | if (!draft || !definitionUsesNeighborConnect(def)) |
| 921 | { return; } |
| 922 | const originTileX = chunkX * CHUNK_SIZE + localX; |
| 923 | const originTileY = chunkY * CHUNK_SIZE + localY; |
| 924 | for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY)) |
| 925 | { |
| 926 | const block = blockAtWorld(tileX, tileY); |
| 927 | if (!block || block.typeId !== typeId) |
| 928 | { continue; } |
| 929 | const mask = computeNeighborConnectMask((dx, dy) => |
| 930 | { |
| 931 | const neighbor = blockAtWorld(tileX + dx, tileY + dy); |
| 932 | return neighborConnectBlocksMatch(block, neighbor, def); |
| 933 | }); |
| 934 | const nextState = composeNeighborConnectState(def, block.state, mask); |
| 935 | if (block.state === nextState) |
| 936 | { continue; } |
| 937 | writeBlockAtWorld(tileX, tileY, { ...block, state: nextState }); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | function updateRevisionUI () |
| 942 | { |
| 943 | const applyBtn = $("apply"); |
| 944 | $("revision").textContent = `active ${activeRevisionId ?? "?"}` + |
| 945 | (pendingRevisionId ? ` · pending ${pendingRevisionId}` : " · no pending revision"); |
| 946 | if (applyBtn) |
| 947 | { |
| 948 | applyBtn.disabled = !pendingRevisionId || applyInFlight; |
| 949 | applyBtn.title = pendingRevisionId |
| 950 | ? "Reload the live world with the pending map revision" |
| 951 | : "Save a chunk first to create a pending revision"; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | function setRevisionState ({ activeRevisionId: active, pendingRevisionId: pending }) |
| 956 | { |
| 957 | if (active != null) |
| 958 | { activeRevisionId = active; } |
| 959 | pendingRevisionId = pending ?? null; |
| 960 | updateRevisionUI(); |
| 961 | } |
| 962 | |
| 963 | function showSelectedChunk (payload) |
| 964 | { |
| 965 | clearNeighborEditState(); |
| 966 | draft = { |
| 967 | open: payload.data.open, |
| 968 | grounds: payload.data.grounds.map((ground) => normalizeGround(ground)), |
| 969 | blocks: payload.data.blocks.map((block) => (block ? { ...block, config: block.config ?? null } : null)), |
| 970 | light: payload.data.light.slice(), |
| 971 | spawners: (payload.data.spawners ?? []).map((entry) => ({ |
| 972 | localX: entry.localX, |
| 973 | localY: entry.localY, |
| 974 | config: { ...entry.config } |
| 975 | })) |
| 976 | }; |
| 977 | $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`; |
| 978 | $("open").checked = draft.open; |
| 979 | setRevisionState({ |
| 980 | activeRevisionId: payload.activeRevisionId, |
| 981 | pendingRevisionId: payload.pendingRevisionId |
| 982 | }); |
| 983 | $("authored").textContent = payload.authored ? "authored" : "unauthored (dimension default ground)"; |
| 984 | const log = $("changelog"); |
| 985 | log.innerHTML = ""; |
| 986 | for (const entry of payload.changelog ?? []) |
| 987 | { |
| 988 | const item = document.createElement("article"); |
| 989 | item.innerHTML = `<header>${entry.editorDisplayName || entry.editor_admin_id} · ${new Date(entry.edited_at).toLocaleString()}</header>`; |
| 990 | const list = document.createElement("ul"); |
| 991 | for (const bullet of entry.diffEntries) |
| 992 | { |
| 993 | const li = document.createElement("li"); |
| 994 | li.textContent = bullet; |
| 995 | list.append(li); |
| 996 | } |
| 997 | item.append(list); |
| 998 | log.append(item); |
| 999 | } |
| 1000 | view.applySnapshot(snapshotFromPayload(payload)); |
| 1001 | syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners); |
| 1002 | captureDraftBaseline(); |
| 1003 | syncSaveButton(); |
| 1004 | if (navigateAfterSave && pendingNavigate) |
| 1005 | { |
| 1006 | const next = pendingNavigate; |
| 1007 | navigateAfterSave = false; |
| 1008 | pendingNavigate = null; |
| 1009 | const nextDim = next.dimensionId != null ? normalizeDimensionId(next.dimensionId) : selectedDimensionId; |
| 1010 | if (nextDim !== selectedDimensionId) |
| 1011 | { |
| 1012 | selectedDimensionId = nextDim; |
| 1013 | syncDimensionUi(); |
| 1014 | clearNeighborhoodView(); |
| 1015 | } |
| 1016 | doLoadNeighborhood(next.chunkX, next.chunkY); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | function pruneView () |
| 1021 | { |
| 1022 | for (const key of [...view.chunks.keys()]) |
| 1023 | { |
| 1024 | const [x, y] = key.split(",").map(Number); |
| 1025 | if (!inEditorView(x, y)) |
| 1026 | { |
| 1027 | view.removeChunk(x, y); |
| 1028 | neighborSpawnersByChunk.delete(key); |
| 1029 | dirtyNeighborChunks.delete(key); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | function frameNeighborhood () |
| 1035 | { |
| 1036 | const size = view.tileSize(); |
| 1037 | view.followPlayer = false; |
| 1038 | const centerX = (chunkX + 0.5) * CHUNK_SIZE * size; |
| 1039 | const centerY = (chunkY + 0.5) * CHUNK_SIZE * size; |
| 1040 | view.scene.cameraPosition.x = view.scene.real_size.x / 2 - centerX; |
| 1041 | view.scene.cameraPosition.y = view.scene.real_size.y / 2 - centerY; |
| 1042 | view.refreshViewport(); |
| 1043 | updateSelectionBorder(); |
| 1044 | } |
| 1045 | |
| 1046 | function updateSelectionBorder () |
| 1047 | { |
| 1048 | const border = $("selection-border"); |
| 1049 | const canvas = scene?.canvas; |
| 1050 | if (!border || !canvas) |
| 1051 | { return; } |
| 1052 | |
| 1053 | const rect = canvas.getBoundingClientRect(); |
| 1054 | const size = view.tileSize(); |
| 1055 | const chunkPx = CHUNK_SIZE * size; |
| 1056 | const screenLeft = chunkX * CHUNK_SIZE * size + scene.cameraPosition.x; |
| 1057 | const screenTop = chunkY * CHUNK_SIZE * size + scene.cameraPosition.y; |
| 1058 | border.style.left = `${rect.left + screenLeft}px`; |
| 1059 | border.style.top = `${rect.top + screenTop}px`; |
| 1060 | border.style.width = `${chunkPx}px`; |
| 1061 | border.style.height = `${chunkPx}px`; |
| 1062 | } |
| 1063 | |
| 1064 | function layoutScene () |
| 1065 | { |
| 1066 | const header = document.querySelector("body > header"); |
| 1067 | const aside = document.querySelector("body > aside"); |
| 1068 | const sidePanels = $("side-panels") || $("changelog-wrap"); |
| 1069 | const top = header.offsetHeight; |
| 1070 | aside.style.top = `${top}px`; |
| 1071 | sidePanels.style.top = `${top}px`; |
| 1072 | const left = aside.offsetWidth; |
| 1073 | const right = sidePanels.offsetWidth; |
| 1074 | const width = Math.max(64, window.innerWidth - left - right); |
| 1075 | const height = Math.max(64, window.innerHeight - top); |
| 1076 | scene.position.x = left; |
| 1077 | scene.position.y = top; |
| 1078 | scene.size.x = width; |
| 1079 | scene.size.y = height; |
| 1080 | scene.g_fixSize(); |
| 1081 | useNearestNeighbour(scene, game.images); |
| 1082 | const fit = Math.min(width, height) / (CHUNK_SIZE * 3 * SPRITE_SIZE_PX); |
| 1083 | if (editorZoom == null) |
| 1084 | { editorZoom = fit; } |
| 1085 | else |
| 1086 | { editorZoom = Math.min(EDITOR_ZOOM_MAX, Math.max(EDITOR_ZOOM_MIN, editorZoom)); } |
| 1087 | view.setZoom(editorZoom, { min: EDITOR_ZOOM_MIN, max: EDITOR_ZOOM_MAX }); |
| 1088 | frameNeighborhood(); |
| 1089 | } |
| 1090 | |
| 1091 | function zoomEditor (direction) |
| 1092 | { |
| 1093 | if (!view) |
| 1094 | { return; } |
| 1095 | const factor = direction > 0 ? EDITOR_ZOOM_STEP : 1 / EDITOR_ZOOM_STEP; |
| 1096 | editorZoom = Math.min(EDITOR_ZOOM_MAX, Math.max(EDITOR_ZOOM_MIN, (editorZoom ?? view.zoom) * factor)); |
| 1097 | scheduleEditorZoom(); |
| 1098 | } |
| 1099 | |
| 1100 | let editorZoomRaf = 0; |
| 1101 | function scheduleEditorZoom () |
| 1102 | { |
| 1103 | if (editorZoomRaf) |
| 1104 | { return; } |
| 1105 | editorZoomRaf = requestAnimationFrame(() => |
| 1106 | { |
| 1107 | editorZoomRaf = 0; |
| 1108 | if (!view) |
| 1109 | { return; } |
| 1110 | view.setZoom(editorZoom, { min: EDITOR_ZOOM_MIN, max: EDITOR_ZOOM_MAX }); |
| 1111 | frameNeighborhood(); |
| 1112 | }); |
| 1113 | } |
| 1114 | |
| 1115 | function requestChunks (coords) |
| 1116 | { |
| 1117 | if (!socket?.socket || socket.socket.readyState !== WebSocket.OPEN) |
| 1118 | { return; } |
| 1119 | for (const coord of coords) |
| 1120 | { |
| 1121 | try |
| 1122 | { |
| 1123 | socket.send({ |
| 1124 | type: MessageType.editorLoadChunk, |
| 1125 | chunkX: coord.chunkX, |
| 1126 | chunkY: coord.chunkY, |
| 1127 | dimensionId: selectedDimensionId |
| 1128 | }); |
| 1129 | } |
| 1130 | catch (_) |
| 1131 | { break; } |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | function doLoadNeighborhood (x, y) |
| 1136 | { |
| 1137 | chunkX = x; |
| 1138 | chunkY = y; |
| 1139 | $("coords").textContent = `${chunkX}, ${chunkY}`; |
| 1140 | requestChunks(neighborhoodCoords(x, y)); |
| 1141 | } |
| 1142 | |
| 1143 | function loadNeighborhood (x, y) |
| 1144 | { |
| 1145 | if ((x !== chunkX || y !== chunkY) && isDraftDirty()) |
| 1146 | { |
| 1147 | showUnsavedModal({ chunkX: x, chunkY: y, dimensionId: selectedDimensionId }); |
| 1148 | return; |
| 1149 | } |
| 1150 | doLoadNeighborhood(x, y); |
| 1151 | } |
| 1152 | |
| 1153 | function requestNeighbors () |
| 1154 | { |
| 1155 | requestChunks(neighborhoodCoords(chunkX, chunkY).filter((coord) => coord.chunkX !== chunkX || coord.chunkY !== chunkY)); |
| 1156 | } |
| 1157 | |
| 1158 | function anyModalOpen () |
| 1159 | { |
| 1160 | return settingsModal?.isOpen() |
| 1161 | || paletteModal?.isOpen() |
| 1162 | || tileConfigModal?.isOpen() |
| 1163 | || questsModal?.isOpen() |
| 1164 | || dialoguesModal?.isOpen() |
| 1165 | || giftsModal?.isOpen() |
| 1166 | || dimensionPicker?.isOpen() |
| 1167 | || !$("unsaved-chunk-modal")?.hidden |
| 1168 | || !$("global-changelog-modal")?.hidden |
| 1169 | || !$("dimension-picker-modal")?.hidden; |
| 1170 | } |
| 1171 | |
| 1172 | function updateHoverStatus (local) |
| 1173 | { |
| 1174 | const el = $("hover-status-text"); |
| 1175 | if (!el) |
| 1176 | { return; } |
| 1177 | if (!local) |
| 1178 | { |
| 1179 | el.textContent = "Hover a tile for coordinates"; |
| 1180 | return; |
| 1181 | } |
| 1182 | const hoverChunkX = local.chunkX ?? Math.floor(local.tileX / CHUNK_SIZE); |
| 1183 | const hoverChunkY = local.chunkY ?? Math.floor(local.tileY / CHUNK_SIZE); |
| 1184 | el.textContent = `Tile (${local.tileX}, ${local.tileY}) · Chunk (${hoverChunkX}, ${hoverChunkY})`; |
| 1185 | } |
| 1186 | |
| 1187 | function updateTooltip (local, options = {}) |
| 1188 | { |
| 1189 | if (!options.keepStatus) |
| 1190 | { updateHoverStatus(local); } |
| 1191 | const tip = $("tile-tooltip"); |
| 1192 | if (!tip || !local || !draft) |
| 1193 | { |
| 1194 | if (tip) |
| 1195 | { tip.hidden = true; } |
| 1196 | view?.clearSpawnRangeHighlight(); |
| 1197 | return; |
| 1198 | } |
| 1199 | const block = normalizeBlock(draft.blocks[local.y * CHUNK_SIZE + local.x]); |
| 1200 | const spawner = spawnerAt(local.x, local.y); |
| 1201 | const lines = []; |
| 1202 | if (block) |
| 1203 | { |
| 1204 | const def = BLOCK_DEFINITIONS[block.typeId]; |
| 1205 | lines.push(def?.displayName ?? `Block ${block.typeId}`); |
| 1206 | if (block.config && Object.keys(block.config).length) |
| 1207 | { |
| 1208 | for (const [key, value] of Object.entries(block.config)) |
| 1209 | { lines.push(`${key}: ${value}`); } |
| 1210 | } |
| 1211 | } |
| 1212 | if (spawner) |
| 1213 | { |
| 1214 | const config = normalizeSpawnerConfig(spawner.config, spawner.config.spawnerId); |
| 1215 | const mob = mobDefinition(config.mobTypeId); |
| 1216 | lines.push(`Spawner · ${mob?.displayName ?? config.mobTypeId}`); |
| 1217 | lines.push(`maxAlive: ${config.maxAlive}`); |
| 1218 | lines.push(`spawnRange: ${config.spawnRangeTiles}`); |
| 1219 | lines.push(`wanderRange: ${config.maxWanderRangeTiles}`); |
| 1220 | lines.push(`id: ${config.spawnerId}`); |
| 1221 | view.setSpawnRangeHighlight( |
| 1222 | local.tileX, |
| 1223 | local.tileY, |
| 1224 | config.spawnRangeTiles, |
| 1225 | config.maxWanderRangeTiles |
| 1226 | ); |
| 1227 | } |
| 1228 | else |
| 1229 | { view.clearSpawnRangeHighlight(); } |
| 1230 | if (!lines.length) |
| 1231 | { |
| 1232 | tip.hidden = true; |
| 1233 | return; |
| 1234 | } |
| 1235 | tip.hidden = false; |
| 1236 | tip.textContent = lines.join("\n"); |
| 1237 | const canvas = scene.canvas; |
| 1238 | const rect = canvas.getBoundingClientRect(); |
| 1239 | const size = view.tileSize(); |
| 1240 | const screenX = local.tileX * size + scene.cameraPosition.x + rect.left + size; |
| 1241 | const screenY = local.tileY * size + scene.cameraPosition.y + rect.top; |
| 1242 | tip.style.left = `${screenX}px`; |
| 1243 | tip.style.top = `${screenY}px`; |
| 1244 | } |
| 1245 | |
| 1246 | async function main () |
| 1247 | { |
| 1248 | const authStatus = await fetchAuthStatus(); |
| 1249 | const signIn = document.getElementById("auth-sign-in"); |
| 1250 | const signOut = document.getElementById("auth-sign-out"); |
| 1251 | if (signIn) |
| 1252 | { |
| 1253 | signIn.hidden = !!authStatus?.authenticated; |
| 1254 | signIn.href = loginUrl("/editor"); |
| 1255 | } |
| 1256 | if (signOut) |
| 1257 | { |
| 1258 | signOut.hidden = !authStatus?.authenticated; |
| 1259 | signOut.href = logoutUrl("/editor"); |
| 1260 | } |
| 1261 | if (!authStatus.authenticated) |
| 1262 | { |
| 1263 | $("who").textContent = "Sign in required"; |
| 1264 | $("error").textContent = "Sign in with your Tim Falken account to use the world editor."; |
| 1265 | return; |
| 1266 | } |
| 1267 | |
| 1268 | const accountLabel = authStatus.username ?? authStatus.email ?? authStatus.authSubject ?? "Signed in"; |
| 1269 | $("who").textContent = `${accountLabel} · loading sprites…`; |
| 1270 | |
| 1271 | catalog = await loadSpriteCatalog(); |
| 1272 | imageUrlByName = new Map((catalog.images ?? []).map((entry) => [entry.name, entry.url])); |
| 1273 | await preloadCatalogImages(game, catalog, { |
| 1274 | onProgress ({ loaded, total }) |
| 1275 | { |
| 1276 | $("who").textContent = `${accountLabel} · loading sprites ${loaded}/${total}`; |
| 1277 | } |
| 1278 | }); |
| 1279 | applySpriteSheets(game.images, catalog); |
| 1280 | scene = new Scene(250, 56, 64, 64); |
| 1281 | game.loadScene(scene); |
| 1282 | view = new WorldView(game, scene, catalog); |
| 1283 | view.followPlayer = false; |
| 1284 | view.natureTintEnabled = false; |
| 1285 | view.setGraphicsPrefs(loadGraphicsSettings()); |
| 1286 | syncSeasonControls(view.worldSeason ?? seasonIdAt()); |
| 1287 | layoutScene(); |
| 1288 | selectTool(tool); |
| 1289 | $("tool").textContent = selectedToolLabel(); |
| 1290 | |
| 1291 | paletteModal = initPaletteModal({ |
| 1292 | catalog, |
| 1293 | imageUrlFor (name) |
| 1294 | { |
| 1295 | const sprite = game.images[name]; |
| 1296 | const html = sprite?.g_image; |
| 1297 | if (html && typeof html.toDataURL === "function") |
| 1298 | { |
| 1299 | try |
| 1300 | { return html.toDataURL("image/png"); } |
| 1301 | catch (_) |
| 1302 | { /* fall through */ } |
| 1303 | } |
| 1304 | return imageUrlByName.get(name) ?? null; |
| 1305 | }, |
| 1306 | onSelect (next) |
| 1307 | { |
| 1308 | selectTool(next); |
| 1309 | $("tool").textContent = selectedToolLabel(); |
| 1310 | } |
| 1311 | }); |
| 1312 | |
| 1313 | tileConfigModal = initTileConfigModal({ |
| 1314 | socket: { |
| 1315 | send (payload) |
| 1316 | { |
| 1317 | socket?.send(payload); |
| 1318 | } |
| 1319 | }, |
| 1320 | MessageType, |
| 1321 | getDialogues: () => dialoguesModal?.getDialogues?.() ?? [], |
| 1322 | getQuests: () => questsModal?.getQuests?.() ?? [], |
| 1323 | describeWorldTile, |
| 1324 | centerEditorOnTile, |
| 1325 | getDimensionOptions: () => [...dimensionsById.values()].map((dim) => ({ |
| 1326 | id: dim.dimensionId, |
| 1327 | label: dim.displayName || dim.dimensionId, |
| 1328 | disabled: !!dim.deletedAt, |
| 1329 | hint: dim.deletedAt ? "soft-deleted" : undefined |
| 1330 | })), |
| 1331 | onSave (ctx, config) |
| 1332 | { |
| 1333 | if (!draft) |
| 1334 | { return; } |
| 1335 | if (ctx.kind === "doorway") |
| 1336 | { |
| 1337 | const index = ctx.localY * CHUNK_SIZE + ctx.localX; |
| 1338 | draft.blocks[index] = { |
| 1339 | typeId: BlockType.doorway, |
| 1340 | state: config.state || "door", |
| 1341 | config: { |
| 1342 | targetDimensionId: normalizeDimensionId(config.targetDimensionId ?? OVERWORLD_ID), |
| 1343 | tileX: Number(config.tileX) || 0, |
| 1344 | tileY: Number(config.tileY) || 0 |
| 1345 | } |
| 1346 | }; |
| 1347 | view.updateAuthoredTile(chunkX, chunkY, ctx.localX, ctx.localY, { |
| 1348 | ground: draft.grounds[index], |
| 1349 | block: draft.blocks[index], |
| 1350 | light: draft.light[index] |
| 1351 | }); |
| 1352 | afterDraftMutation(); |
| 1353 | return; |
| 1354 | } |
| 1355 | if (ctx.kind === "door") |
| 1356 | { |
| 1357 | const index = ctx.localY * CHUNK_SIZE + ctx.localX; |
| 1358 | const existing = draft.blocks[index]; |
| 1359 | if (!existing || existing.typeId !== BlockType.door) |
| 1360 | { return; } |
| 1361 | const prev = existing.config && typeof existing.config === "object" ? { ...existing.config } : {}; |
| 1362 | const nextConfig = normalizeDoorConfig({ |
| 1363 | ...prev, |
| 1364 | when: config.when, |
| 1365 | blockedMessage: config.blockedMessage |
| 1366 | }); |
| 1367 | draft.blocks[index] = { |
| 1368 | typeId: BlockType.door, |
| 1369 | state: existing.state, |
| 1370 | config: nextConfig |
| 1371 | }; |
| 1372 | view.updateAuthoredTile(chunkX, chunkY, ctx.localX, ctx.localY, { |
| 1373 | ground: draft.grounds[index], |
| 1374 | block: draft.blocks[index], |
| 1375 | light: draft.light[index] |
| 1376 | }); |
| 1377 | afterDraftMutation(); |
| 1378 | return; |
| 1379 | } |
| 1380 | if (ctx.kind === "fishing-spot") |
| 1381 | { |
| 1382 | const index = ctx.localY * CHUNK_SIZE + ctx.localX; |
| 1383 | const existing = draft.blocks[index]; |
| 1384 | draft.blocks[index] = { |
| 1385 | typeId: BlockType.fishingSpot, |
| 1386 | state: existing?.state === "exhausted" ? "exhausted" : "fishing-spot", |
| 1387 | config: { fishes: [...(config.fishes ?? [])] } |
| 1388 | }; |
| 1389 | view.updateAuthoredTile(chunkX, chunkY, ctx.localX, ctx.localY, { |
| 1390 | ground: draft.grounds[index], |
| 1391 | block: draft.blocks[index], |
| 1392 | light: draft.light[index] |
| 1393 | }); |
| 1394 | afterDraftMutation(); |
| 1395 | return; |
| 1396 | } |
| 1397 | draft.spawners = (draft.spawners ?? []).filter((s) => s.localX !== ctx.localX || s.localY !== ctx.localY); |
| 1398 | draft.spawners.push({ localX: ctx.localX, localY: ctx.localY, config }); |
| 1399 | syncSpawnersOverlay(chunkX, chunkY, draft.spawners); |
| 1400 | afterDraftMutation(); |
| 1401 | }, |
| 1402 | onRemove (ctx) |
| 1403 | { |
| 1404 | if (!draft) |
| 1405 | { return; } |
| 1406 | if (ctx.kind === "door") |
| 1407 | { |
| 1408 | const index = ctx.localY * CHUNK_SIZE + ctx.localX; |
| 1409 | const existing = draft.blocks[index]; |
| 1410 | if (!existing || existing.typeId !== BlockType.door) |
| 1411 | { return; } |
| 1412 | const prev = existing.config && typeof existing.config === "object" ? { ...existing.config } : {}; |
| 1413 | delete prev.when; |
| 1414 | delete prev.requirements; |
| 1415 | delete prev.blockedMessage; |
| 1416 | delete prev.denyMessage; |
| 1417 | draft.blocks[index] = { |
| 1418 | typeId: BlockType.door, |
| 1419 | state: existing.state, |
| 1420 | config: normalizeDoorConfig(prev) |
| 1421 | }; |
| 1422 | view.updateAuthoredTile(chunkX, chunkY, ctx.localX, ctx.localY, { |
| 1423 | ground: draft.grounds[index], |
| 1424 | block: draft.blocks[index], |
| 1425 | light: draft.light[index] |
| 1426 | }); |
| 1427 | afterDraftMutation(); |
| 1428 | return; |
| 1429 | } |
| 1430 | if (ctx.kind === "doorway") |
| 1431 | { |
| 1432 | const index = ctx.localY * CHUNK_SIZE + ctx.localX; |
| 1433 | draft.blocks[index] = null; |
| 1434 | view.updateAuthoredTile(chunkX, chunkY, ctx.localX, ctx.localY, { |
| 1435 | ground: draft.grounds[index], |
| 1436 | block: draft.blocks[index], |
| 1437 | light: draft.light[index] |
| 1438 | }); |
| 1439 | afterDraftMutation(); |
| 1440 | return; |
| 1441 | } |
| 1442 | if (ctx.kind === "fishing-spot") |
| 1443 | { |
| 1444 | const index = ctx.localY * CHUNK_SIZE + ctx.localX; |
| 1445 | draft.blocks[index] = null; |
| 1446 | view.updateAuthoredTile(chunkX, chunkY, ctx.localX, ctx.localY, { |
| 1447 | ground: draft.grounds[index], |
| 1448 | block: draft.blocks[index], |
| 1449 | light: draft.light[index] |
| 1450 | }); |
| 1451 | afterDraftMutation(); |
| 1452 | return; |
| 1453 | } |
| 1454 | draft.spawners = (draft.spawners ?? []).filter((s) => s.localX !== ctx.localX || s.localY !== ctx.localY); |
| 1455 | syncSpawnersOverlay(chunkX, chunkY, draft.spawners); |
| 1456 | afterDraftMutation(); |
| 1457 | } |
| 1458 | }); |
| 1459 | |
| 1460 | const ticker = new GameObject(0, 0, null, 10); |
| 1461 | ticker.update = (dt) => |
| 1462 | { |
| 1463 | hoverLocal = null; |
| 1464 | const canvas = scene.canvas; |
| 1465 | const rect = canvas.getBoundingClientRect(); |
| 1466 | const mouseX = GameInput.mousePosition.x - rect.left; |
| 1467 | const mouseY = GameInput.mousePosition.y - rect.top; |
| 1468 | const overCanvas = mouseX >= 0 && mouseY >= 0 && mouseX < rect.width && mouseY < rect.height; |
| 1469 | if (overCanvas && draft && !anyModalOpen()) |
| 1470 | { |
| 1471 | const tile = view.screenToTile(mouseX, mouseY); |
| 1472 | const localX = tile.tileX - chunkX * CHUNK_SIZE; |
| 1473 | const localY = tile.tileY - chunkY * CHUNK_SIZE; |
| 1474 | const hoverChunkX = Math.floor(tile.tileX / CHUNK_SIZE); |
| 1475 | const hoverChunkY = Math.floor(tile.tileY / CHUNK_SIZE); |
| 1476 | updateHoverStatus({ |
| 1477 | tileX: tile.tileX, |
| 1478 | tileY: tile.tileY, |
| 1479 | x: ((tile.tileX % CHUNK_SIZE) + CHUNK_SIZE) % CHUNK_SIZE, |
| 1480 | y: ((tile.tileY % CHUNK_SIZE) + CHUNK_SIZE) % CHUNK_SIZE, |
| 1481 | chunkX: hoverChunkX, |
| 1482 | chunkY: hoverChunkY |
| 1483 | }); |
| 1484 | if (localX >= 0 && localY >= 0 && localX < CHUNK_SIZE && localY < CHUNK_SIZE) |
| 1485 | { |
| 1486 | hoverLocal = { x: localX, y: localY, tileX: tile.tileX, tileY: tile.tileY }; |
| 1487 | view.setTilePreview(tile.tileX, tile.tileY, previewFromTool()); |
| 1488 | updateTooltip(hoverLocal); |
| 1489 | if (GameInput.mouseHeld(GameInput.MouseButtons.Left)) |
| 1490 | { paintAt(localX, localY); } |
| 1491 | } |
| 1492 | else |
| 1493 | { |
| 1494 | hoverLocal = null; |
| 1495 | view.clearTilePreview(); |
| 1496 | updateTooltip(null, { keepStatus: true }); |
| 1497 | } |
| 1498 | } |
| 1499 | else |
| 1500 | { |
| 1501 | view.clearTilePreview(); |
| 1502 | updateTooltip(null); |
| 1503 | } |
| 1504 | view.update(dt); |
| 1505 | frameNeighborhood(); |
| 1506 | }; |
| 1507 | scene.addObject(ticker); |
| 1508 | window.addEventListener("resize", layoutScene); |
| 1509 | |
| 1510 | $("who").textContent = `${accountLabel} · connecting…`; |
| 1511 | |
| 1512 | socket = new GameSocket(defaultSocketUrl(), (message) => |
| 1513 | { |
| 1514 | if (message.type === MessageType.session) |
| 1515 | { |
| 1516 | sessionAuthSubject = message.authSubject ?? null; |
| 1517 | const label = message.username ?? message.authSubject ?? "Unknown"; |
| 1518 | $("who").textContent = `${label}${message.isAdmin ? " · admin" : " · not admin"}`; |
| 1519 | if (!message.isAdmin) |
| 1520 | { |
| 1521 | $("error").textContent = "Admin access required."; |
| 1522 | return; |
| 1523 | } |
| 1524 | $("error").textContent = ""; |
| 1525 | const restartBtn = document.getElementById("editor-restart-now"); |
| 1526 | if (restartBtn) |
| 1527 | { |
| 1528 | restartBtn.hidden = false; |
| 1529 | restartBtn.disabled = false; |
| 1530 | } |
| 1531 | socket.send({ type: MessageType.editorLoadSettings }); |
| 1532 | socket.send({ type: MessageType.editorLoadGameAdmins }); |
| 1533 | socket.send({ type: MessageType.editorConsoleSubscribe }); |
| 1534 | requestDimensions(); |
| 1535 | loadNeighborhood(0, 0); |
| 1536 | } |
| 1537 | else if (message.type === MessageType.editorSettings |
| 1538 | || message.type === MessageType.editorGameAdmins) |
| 1539 | { settingsModal.handleMessage(message); } |
| 1540 | else if (message.type === MessageType.editorConsoleSnapshot) |
| 1541 | { applyConsoleSnapshot(message.lines); } |
| 1542 | else if (message.type === MessageType.editorConsoleLine) |
| 1543 | { appendConsoleLine(message.line); } |
| 1544 | else if (message.type === MessageType.editorDimensions) |
| 1545 | { |
| 1546 | applyDimensionsList(message); |
| 1547 | } |
| 1548 | else if (message.type === MessageType.editorQuests) |
| 1549 | { |
| 1550 | questsModal?.handleMessage(message); |
| 1551 | settingsModal?.handleMessage(message); |
| 1552 | dialoguesModal?.handleMessage(message); |
| 1553 | tileConfigModal?.handleMessage(message); |
| 1554 | } |
| 1555 | else if (message.type === MessageType.editorDialogues) |
| 1556 | { |
| 1557 | dialoguesModal?.handleMessage(message); |
| 1558 | tileConfigModal?.handleMessage(message); |
| 1559 | questsModal?.handleMessage(message); |
| 1560 | } |
| 1561 | else if (message.type === MessageType.editorGiftCharacters |
| 1562 | || message.type === MessageType.editorGiftSent) |
| 1563 | { giftsModal?.handleMessage(message); } |
| 1564 | else if (message.type === MessageType.editorGlobalChangelog) |
| 1565 | { renderGlobalChangelog(message.changelog ?? []); } |
| 1566 | else if (message.type === MessageType.editorChunk) |
| 1567 | { |
| 1568 | const msgDim = normalizeDimensionId(message.dimensionId ?? OVERWORLD_ID); |
| 1569 | if (msgDim !== selectedDimensionId) |
| 1570 | { return; } |
| 1571 | if (message.settings) |
| 1572 | { view.setSettings(message.settings); } |
| 1573 | if (!inEditorView(message.chunkX, message.chunkY)) |
| 1574 | { return; } |
| 1575 | if (message.chunkX === chunkX && message.chunkY === chunkY) |
| 1576 | { showSelectedChunk(message); } |
| 1577 | else |
| 1578 | { |
| 1579 | const key = chunkKey(message.chunkX, message.chunkY); |
| 1580 | neighborSpawnersByChunk.set(key, message.data.spawners ?? []); |
| 1581 | if (!dirtyNeighborChunks.has(key)) |
| 1582 | { |
| 1583 | view.applySnapshot(snapshotFromPayload(message)); |
| 1584 | syncSpawnersOverlay(message.chunkX, message.chunkY, message.data.spawners); |
| 1585 | } |
| 1586 | } |
| 1587 | pruneView(); |
| 1588 | } |
| 1589 | else if (message.type === MessageType.editorRevisionApplied) |
| 1590 | { |
| 1591 | applyInFlight = false; |
| 1592 | setRevisionState({ |
| 1593 | activeRevisionId: message.activeRevisionId, |
| 1594 | pendingRevisionId: message.pendingRevisionId |
| 1595 | }); |
| 1596 | const status = $("apply-status"); |
| 1597 | status.textContent = `Applied revision ${message.appliedRevisionId}. Live world reloaded.`; |
| 1598 | status.className = "hint ok"; |
| 1599 | requestDimensions(); |
| 1600 | requestChunks(neighborhoodCoords(chunkX, chunkY)); |
| 1601 | } |
| 1602 | else if (message.type === MessageType.forceLogout) |
| 1603 | { |
| 1604 | $("who").textContent = "Server restarting…"; |
| 1605 | $("error").textContent = message.reason || "Server shutting down."; |
| 1606 | } |
| 1607 | else if (message.type === MessageType.error) |
| 1608 | { |
| 1609 | $("error").textContent = message.message; |
| 1610 | if (giftsModal?.isOpen()) |
| 1611 | { giftsModal.handleError?.(message.message); } |
| 1612 | pendingCreatedDimensionId = null; |
| 1613 | navigateAfterSave = false; |
| 1614 | dimensionPicker?.setValue(selectedDimensionId); |
| 1615 | if (applyInFlight) |
| 1616 | { |
| 1617 | applyInFlight = false; |
| 1618 | $("apply-status").textContent = ""; |
| 1619 | $("apply-status").className = "hint"; |
| 1620 | updateRevisionUI(); |
| 1621 | } |
| 1622 | } |
| 1623 | }, { |
| 1624 | onClose (event) |
| 1625 | { |
| 1626 | if (event.code === 1000) |
| 1627 | { return; } |
| 1628 | const reasons = { |
| 1629 | 4401: "Sign in expired or missing. Use Sign out, then sign in again.", |
| 1630 | 1011: "Server could not verify your account with auth.timfalken.com.", |
| 1631 | 1006: "Connection dropped before the editor session started.", |
| 1632 | 1001: "Server is restarting. Reload this page in a moment." |
| 1633 | }; |
| 1634 | const detail = reasons[event.code] ?? `Connection closed (code ${event.code}).`; |
| 1635 | $("who").textContent = "Connection failed"; |
| 1636 | $("error").textContent = detail; |
| 1637 | }, |
| 1638 | onError () |
| 1639 | { |
| 1640 | $("who").textContent = "Connection failed"; |
| 1641 | $("error").textContent = "Could not open a live connection to the server."; |
| 1642 | } |
| 1643 | }); |
| 1644 | settingsModal = initSettingsModal({ |
| 1645 | socket, |
| 1646 | MessageType, |
| 1647 | getAuthSubject: () => sessionAuthSubject, |
| 1648 | onApplied (settings) |
| 1649 | { |
| 1650 | view.setSettings(settings); |
| 1651 | }, |
| 1652 | onPreviewNight (hour) |
| 1653 | { |
| 1654 | view.nightPreview = hour; |
| 1655 | $("night").value = String(hour); |
| 1656 | $("night-label").textContent = Number(hour).toFixed(1); |
| 1657 | } |
| 1658 | }); |
| 1659 | dimensionPicker = initDimensionPickerModal({ |
| 1660 | onSelect (id) |
| 1661 | { |
| 1662 | selectDimension(id); |
| 1663 | }, |
| 1664 | onCreate (rawId, displayName) |
| 1665 | { |
| 1666 | const id = normalizeDimensionId(rawId); |
| 1667 | $("error").textContent = ""; |
| 1668 | pendingCreatedDimensionId = id; |
| 1669 | socket.send({ |
| 1670 | type: MessageType.editorCreateDimension, |
| 1671 | dimensionId: id, |
| 1672 | displayName: displayName ?? rawId.trim() |
| 1673 | }); |
| 1674 | } |
| 1675 | }); |
| 1676 | dimensionPicker.setOptions([{ |
| 1677 | id: OVERWORLD_ID, |
| 1678 | label: "Overworld" |
| 1679 | }]); |
| 1680 | dimensionPicker.setValue(OVERWORLD_ID); |
| 1681 | dimensionSettings = initDimensionSettings({ |
| 1682 | socket, |
| 1683 | MessageType, |
| 1684 | GROUND_DEFINITIONS, |
| 1685 | OVERWORLD_ID, |
| 1686 | getSelectedDimensionId: () => selectedDimensionId, |
| 1687 | getDimensionRecord: (id) => dimensionsById.get(id) ?? null, |
| 1688 | isOverworld |
| 1689 | }); |
| 1690 | questsModal = initQuestsModal({ |
| 1691 | socket, |
| 1692 | MessageType, |
| 1693 | describeWorldTile, |
| 1694 | centerEditorOnTile, |
| 1695 | getDimensionOptions: () => [...dimensionsById.values()].map((dim) => ({ |
| 1696 | id: dim.dimensionId, |
| 1697 | label: dim.displayName || dim.dimensionId, |
| 1698 | disabled: dim.deletedAt != null, |
| 1699 | hint: dim.deletedAt != null ? "soft-deleted" : null |
| 1700 | })) |
| 1701 | }); |
| 1702 | dialoguesModal = initDialoguesModal({ |
| 1703 | socket, |
| 1704 | MessageType, |
| 1705 | describeWorldTile, |
| 1706 | centerEditorOnTile, |
| 1707 | getDimensionOptions: () => [...dimensionsById.values()].map((dim) => ({ |
| 1708 | id: dim.dimensionId, |
| 1709 | label: dim.displayName || dim.dimensionId, |
| 1710 | disabled: dim.deletedAt != null, |
| 1711 | hint: dim.deletedAt != null ? "soft-deleted" : null |
| 1712 | })) |
| 1713 | }); |
| 1714 | giftsModal = initGiftsModal({ socket, MessageType }); |
| 1715 | initSidePanelTabs(); |
| 1716 | game.startGame(); |
| 1717 | useNearestNeighbour(scene, game.images); |
| 1718 | await socket.connect(); |
| 1719 | } |
| 1720 | |
| 1721 | $("tool").textContent = selectedToolLabel(); |
| 1722 | $("tool-erase").addEventListener("click", () => |
| 1723 | { |
| 1724 | selectTool({ kind: "erase" }); |
| 1725 | $("tool").textContent = selectedToolLabel(); |
| 1726 | }); |
| 1727 | |
| 1728 | $("north").addEventListener("click", () => loadNeighborhood(chunkX, chunkY - 1)); |
| 1729 | $("south").addEventListener("click", () => loadNeighborhood(chunkX, chunkY + 1)); |
| 1730 | $("west").addEventListener("click", () => loadNeighborhood(chunkX - 1, chunkY)); |
| 1731 | $("east").addEventListener("click", () => loadNeighborhood(chunkX + 1, chunkY)); |
| 1732 | $("copy-chunk")?.addEventListener("click", () => copySelectedChunk()); |
| 1733 | $("paste-chunk")?.addEventListener("click", () => pasteSelectedChunk()); |
| 1734 | $("clear-chunk")?.addEventListener("click", () => clearSelectedChunk()); |
| 1735 | |
| 1736 | function isTypingTarget (target) |
| 1737 | { |
| 1738 | if (!(target instanceof Element)) |
| 1739 | { return false; } |
| 1740 | const tag = target.tagName; |
| 1741 | if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") |
| 1742 | { return true; } |
| 1743 | return !!target.closest("[contenteditable='true']"); |
| 1744 | } |
| 1745 | |
| 1746 | window.addEventListener("keydown", (event) => |
| 1747 | { |
| 1748 | if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) |
| 1749 | { return; } |
| 1750 | if (anyModalOpen() || isTypingTarget(event.target)) |
| 1751 | { return; } |
| 1752 | if (event.key === "ArrowUp") |
| 1753 | { |
| 1754 | event.preventDefault(); |
| 1755 | loadNeighborhood(chunkX, chunkY - 1); |
| 1756 | } |
| 1757 | else if (event.key === "ArrowDown") |
| 1758 | { |
| 1759 | event.preventDefault(); |
| 1760 | loadNeighborhood(chunkX, chunkY + 1); |
| 1761 | } |
| 1762 | else if (event.key === "ArrowLeft") |
| 1763 | { |
| 1764 | event.preventDefault(); |
| 1765 | loadNeighborhood(chunkX - 1, chunkY); |
| 1766 | } |
| 1767 | else if (event.key === "ArrowRight") |
| 1768 | { |
| 1769 | event.preventDefault(); |
| 1770 | loadNeighborhood(chunkX + 1, chunkY); |
| 1771 | } |
| 1772 | }); |
| 1773 | $("open").addEventListener("change", () => |
| 1774 | { |
| 1775 | if (isSelectedDimensionSoftDeleted()) |
| 1776 | { |
| 1777 | $("open").checked = !!draft?.open; |
| 1778 | return; |
| 1779 | } |
| 1780 | if (draft) |
| 1781 | { |
| 1782 | draft.open = $("open").checked; |
| 1783 | view.setChunkOpen(chunkX, chunkY, draft.open); |
| 1784 | afterDraftMutation(); |
| 1785 | } |
| 1786 | }); |
| 1787 | $("save").addEventListener("click", () => |
| 1788 | { |
| 1789 | saveSelectedChunk(); |
| 1790 | }); |
| 1791 | $("unsaved-chunk-cancel")?.addEventListener("click", () => |
| 1792 | { |
| 1793 | pendingNavigate = null; |
| 1794 | navigateAfterSave = false; |
| 1795 | hideUnsavedModal(); |
| 1796 | }); |
| 1797 | $("unsaved-chunk-backdrop")?.addEventListener("click", () => |
| 1798 | { |
| 1799 | pendingNavigate = null; |
| 1800 | navigateAfterSave = false; |
| 1801 | hideUnsavedModal(); |
| 1802 | }); |
| 1803 | $("unsaved-chunk-discard")?.addEventListener("click", () => |
| 1804 | { |
| 1805 | const next = pendingNavigate; |
| 1806 | hideUnsavedModal(); |
| 1807 | pendingNavigate = null; |
| 1808 | navigateAfterSave = false; |
| 1809 | if (!next) |
| 1810 | { return; } |
| 1811 | const nextDim = next.dimensionId != null ? normalizeDimensionId(next.dimensionId) : selectedDimensionId; |
| 1812 | if (nextDim !== selectedDimensionId) |
| 1813 | { |
| 1814 | selectedDimensionId = nextDim; |
| 1815 | syncDimensionUi(); |
| 1816 | clearNeighborhoodView(); |
| 1817 | } |
| 1818 | doLoadNeighborhood(next.chunkX, next.chunkY); |
| 1819 | }); |
| 1820 | $("unsaved-chunk-save")?.addEventListener("click", () => |
| 1821 | { |
| 1822 | hideUnsavedModal(); |
| 1823 | if (!pendingNavigate) |
| 1824 | { return; } |
| 1825 | navigateAfterSave = true; |
| 1826 | if (!saveSelectedChunk()) |
| 1827 | { |
| 1828 | navigateAfterSave = false; |
| 1829 | const next = pendingNavigate; |
| 1830 | pendingNavigate = null; |
| 1831 | if (next) |
| 1832 | { |
| 1833 | const nextDim = next.dimensionId != null ? normalizeDimensionId(next.dimensionId) : selectedDimensionId; |
| 1834 | if (nextDim !== selectedDimensionId) |
| 1835 | { |
| 1836 | selectedDimensionId = nextDim; |
| 1837 | syncDimensionUi(); |
| 1838 | clearNeighborhoodView(); |
| 1839 | } |
| 1840 | doLoadNeighborhood(next.chunkX, next.chunkY); |
| 1841 | } |
| 1842 | } |
| 1843 | }); |
| 1844 | $("apply").addEventListener("click", () => |
| 1845 | { |
| 1846 | if (!pendingRevisionId || applyInFlight) |
| 1847 | { return; } |
| 1848 | $("error").textContent = ""; |
| 1849 | const status = $("apply-status"); |
| 1850 | status.textContent = "Applying…"; |
| 1851 | status.className = "hint"; |
| 1852 | applyInFlight = true; |
| 1853 | updateRevisionUI(); |
| 1854 | socket.send({ type: MessageType.editorApplyRevision }); |
| 1855 | }); |
| 1856 | document.getElementById("editor-restart-now")?.addEventListener("click", () => |
| 1857 | { |
| 1858 | if (!socket) |
| 1859 | { return; } |
| 1860 | const ok = window.confirm( |
| 1861 | "Restart the server now?\n\nAll players and editor sessions will disconnect. " |
| 1862 | + "systemd will start a fresh process and pull the latest code from git." |
| 1863 | ); |
| 1864 | if (!ok) |
| 1865 | { return; } |
| 1866 | const restartBtn = document.getElementById("editor-restart-now"); |
| 1867 | if (restartBtn) |
| 1868 | { restartBtn.disabled = true; } |
| 1869 | $("who").textContent = "Restarting server…"; |
| 1870 | $("error").textContent = ""; |
| 1871 | socket.send({ type: MessageType.editorRestartNow }); |
| 1872 | }); |
| 1873 | $("night").addEventListener("input", () => |
| 1874 | { |
| 1875 | view.nightPreview = Number($("night").value); |
| 1876 | $("night-label").textContent = view.nightPreview.toFixed(1); |
| 1877 | }); |
| 1878 | $("season").addEventListener("change", () => |
| 1879 | { |
| 1880 | applySeasonPreview($("season").value); |
| 1881 | }); |
| 1882 | |
| 1883 | function showGlobalChangelog (visible) |
| 1884 | { |
| 1885 | const backdrop = $("global-changelog-backdrop"); |
| 1886 | const modal = $("global-changelog-modal"); |
| 1887 | if (backdrop) |
| 1888 | { backdrop.hidden = !visible; } |
| 1889 | if (modal) |
| 1890 | { modal.hidden = !visible; } |
| 1891 | } |
| 1892 | |
| 1893 | function renderGlobalChangelog (changelog) |
| 1894 | { |
| 1895 | const log = $("global-changelog"); |
| 1896 | if (!log) |
| 1897 | { return; } |
| 1898 | log.innerHTML = ""; |
| 1899 | if (!changelog.length) |
| 1900 | { |
| 1901 | log.innerHTML = "<p class=\"hint\">No edits logged yet.</p>"; |
| 1902 | return; |
| 1903 | } |
| 1904 | const kindLabel = { |
| 1905 | chunk: "Chunk", |
| 1906 | settings: "Settings", |
| 1907 | quest: "Quest", |
| 1908 | dialogue: "Dialogue" |
| 1909 | }; |
| 1910 | for (const entry of changelog) |
| 1911 | { |
| 1912 | const item = document.createElement("article"); |
| 1913 | const who = entry.editorDisplayName || entry.editor_admin_id; |
| 1914 | const kind = kindLabel[entry.kind] || entry.kind || "Edit"; |
| 1915 | const scope = entry.scope ? ` · ${entry.scope}` : ""; |
| 1916 | item.innerHTML = `<header>${kind}${scope} · ${who} · ${new Date(entry.edited_at).toLocaleString()}</header>`; |
| 1917 | const list = document.createElement("ul"); |
| 1918 | for (const bullet of entry.diffEntries ?? []) |
| 1919 | { |
| 1920 | const li = document.createElement("li"); |
| 1921 | li.textContent = bullet; |
| 1922 | list.append(li); |
| 1923 | } |
| 1924 | item.append(list); |
| 1925 | log.append(item); |
| 1926 | } |
| 1927 | log.scrollTop = 0; |
| 1928 | } |
| 1929 | |
| 1930 | document.getElementById("open-global-changelog")?.addEventListener("click", () => |
| 1931 | { |
| 1932 | const log = $("global-changelog"); |
| 1933 | if (log) |
| 1934 | { log.innerHTML = "<p class=\"hint\">Loading…</p>"; } |
| 1935 | showGlobalChangelog(true); |
| 1936 | socket.send({ type: MessageType.editorLoadGlobalChangelog }); |
| 1937 | }); |
| 1938 | document.getElementById("global-changelog-close")?.addEventListener("click", () => showGlobalChangelog(false)); |
| 1939 | document.getElementById("global-changelog-backdrop")?.addEventListener("click", () => showGlobalChangelog(false)); |
| 1940 | |
| 1941 | function syncSeasonControls (season) |
| 1942 | { |
| 1943 | const next = season === SeasonId.spring |
| 1944 | || season === SeasonId.fall |
| 1945 | || season === SeasonId.winter |
| 1946 | || season === SeasonId.summer |
| 1947 | ? season |
| 1948 | : seasonIdAt(); |
| 1949 | $("season").value = next; |
| 1950 | view?.setWorldSeason(next); |
| 1951 | } |
| 1952 | |
| 1953 | function applySeasonPreview (season) |
| 1954 | { |
| 1955 | syncSeasonControls(season); |
| 1956 | } |
| 1957 | |
| 1958 | function cycleToolState (direction) |
| 1959 | { |
| 1960 | if (tool.kind === "erase" || tool.kind === "spawner") |
| 1961 | { return; } |
| 1962 | const layer = tool.kind === "ground" ? "ground" : "block"; |
| 1963 | const def = tool.kind === "ground" ? GROUND_DEFINITIONS[tool.typeId] : BLOCK_DEFINITIONS[tool.typeId]; |
| 1964 | if (definitionUsesNeighborConnect(def)) |
| 1965 | { return; } |
| 1966 | if (tool.kind === "block" && def?.id === BlockType.flower) |
| 1967 | { return; } |
| 1968 | const allStates = statesForType(catalog, layer, def.key); |
| 1969 | const seasonal = seasonalCycleStates(allStates); |
| 1970 | const states = seasonal ?? placeableStatesForType(catalog, layer, def.key); |
| 1971 | if (states.length < 2) |
| 1972 | { return; } |
| 1973 | tool.state = cycleState(states, tool.state, direction); |
| 1974 | $("tool").textContent = selectedToolLabel(); |
| 1975 | const season = seasonIdFromVisualState(tool.state); |
| 1976 | if (season) |
| 1977 | { applySeasonPreview(season); } |
| 1978 | if (!draft || !hoverLocal) |
| 1979 | { return; } |
| 1980 | const index = hoverLocal.y * CHUNK_SIZE + hoverLocal.x; |
| 1981 | if (tool.kind === "ground" && normalizeGround(draft.grounds[index]).typeId === tool.typeId) |
| 1982 | { paintAt(hoverLocal.x, hoverLocal.y); } |
| 1983 | else if (tool.kind === "block" && draft.blocks[index]?.typeId === tool.typeId) |
| 1984 | { paintAt(hoverLocal.x, hoverLocal.y); } |
| 1985 | } |
| 1986 | |
| 1987 | document.addEventListener("wheel", (event) => |
| 1988 | { |
| 1989 | if (!scene?.canvas || anyModalOpen()) |
| 1990 | { return; } |
| 1991 | const rect = scene.canvas.getBoundingClientRect(); |
| 1992 | if (event.clientX < rect.left || event.clientX >= rect.right || event.clientY < rect.top || event.clientY >= rect.bottom) |
| 1993 | { return; } |
| 1994 | event.preventDefault(); |
| 1995 | if (event.shiftKey) |
| 1996 | { |
| 1997 | cycleToolState(event.deltaY < 0 ? 1 : -1); |
| 1998 | if (hoverLocal) |
| 1999 | { view.setTilePreview(hoverLocal.tileX, hoverLocal.tileY, previewFromTool()); } |
| 2000 | return; |
| 2001 | } |
| 2002 | zoomEditor(event.deltaY < 0 ? 1 : -1); |
| 2003 | }, { passive: false }); |
| 2004 | |
| 2005 | document.addEventListener("contextmenu", (event) => |
| 2006 | { |
| 2007 | if (!scene?.canvas || anyModalOpen() || !draft) |
| 2008 | { return; } |
| 2009 | const rect = scene.canvas.getBoundingClientRect(); |
| 2010 | if (event.clientX < rect.left || event.clientX >= rect.right || event.clientY < rect.top || event.clientY >= rect.bottom) |
| 2011 | { return; } |
| 2012 | event.preventDefault(); |
| 2013 | const tile = view.screenToTile(event.clientX - rect.left, event.clientY - rect.top); |
| 2014 | const localX = tile.tileX - chunkX * CHUNK_SIZE; |
| 2015 | const localY = tile.tileY - chunkY * CHUNK_SIZE; |
| 2016 | if (localX < 0 || localY < 0 || localX >= CHUNK_SIZE || localY >= CHUNK_SIZE) |
| 2017 | { return; } |
| 2018 | const spawner = spawnerAt(localX, localY); |
| 2019 | if (spawner) |
| 2020 | { |
| 2021 | tileConfigModal.openSpawner({ |
| 2022 | localX, |
| 2023 | localY, |
| 2024 | tileX: tile.tileX, |
| 2025 | tileY: tile.tileY, |
| 2026 | config: { ...spawner.config } |
| 2027 | }); |
| 2028 | return; |
| 2029 | } |
| 2030 | const index = localY * CHUNK_SIZE + localX; |
| 2031 | const block = draft.blocks[index]; |
| 2032 | if (block?.typeId === BlockType.doorway) |
| 2033 | { |
| 2034 | tileConfigModal.openDoorway({ |
| 2035 | localX, |
| 2036 | localY, |
| 2037 | tileX: tile.tileX, |
| 2038 | tileY: tile.tileY, |
| 2039 | state: block.state ?? "door", |
| 2040 | config: block.config ? { ...block.config } : {} |
| 2041 | }); |
| 2042 | return; |
| 2043 | } |
| 2044 | if (block?.typeId === BlockType.door) |
| 2045 | { |
| 2046 | tileConfigModal.openDoor({ |
| 2047 | localX, |
| 2048 | localY, |
| 2049 | tileX: tile.tileX, |
| 2050 | tileY: tile.tileY, |
| 2051 | state: block.state, |
| 2052 | config: block.config ? { ...block.config } : {} |
| 2053 | }); |
| 2054 | return; |
| 2055 | } |
| 2056 | if (block?.typeId === BlockType.fishingSpot) |
| 2057 | { |
| 2058 | tileConfigModal.openFishingSpot({ |
| 2059 | localX, |
| 2060 | localY, |
| 2061 | tileX: tile.tileX, |
| 2062 | tileY: tile.tileY, |
| 2063 | config: block.config ? { ...block.config } : { fishes: [] } |
| 2064 | }); |
| 2065 | } |
| 2066 | }); |
| 2067 | |
| 2068 | main().catch((error) => |
| 2069 | { |
| 2070 | $("error").textContent = error.message; |
| 2071 | console.error(error); |
| 2072 | }); |