| 1 | import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js"; |
| 2 | |
| 3 | /** |
| 4 | * Editor chunk saves and reloads share the same `EDITOR_CHUNK` reply. |
| 5 | * After `EDITOR_SAVE_CHUNK` the local draft is still dirty (baseline is not |
| 6 | * updated until the ack is applied). Treating that ack like a reconnect reload |
| 7 | * leaves the Save button dirty even though the server already persisted. |
| 8 | */ |
| 9 | |
| 10 | export function editorChunkSaveKey (dimensionId, chunkX, chunkY) |
| 11 | { |
| 12 | return `${normalizeDimensionId(dimensionId ?? OVERWORLD_ID)}:${chunkX | 0},${chunkY | 0}`; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Whether an incoming selected-chunk `EDITOR_CHUNK` should replace the local draft. |
| 17 | * Save acks must apply even while dirty. Non-ack reloads must not wipe unsaved paint. |
| 18 | * |
| 19 | * @param {{ isSaveAck?: boolean, isDirty?: boolean }} options |
| 20 | */ |
| 21 | export function shouldApplySelectedEditorChunk ({ isSaveAck = false, isDirty = false } = {}) |
| 22 | { |
| 23 | return !!isSaveAck || !isDirty; |
| 24 | } |