BlueGit

timfa questward

Files

questward / client / src / editor / saveAck.js

saveAck.js

fix: apply editor chunk save acks so dirty drafts clear
timfa project_85689633_bot_782f591ee30607a5698798444cb41267 · pushed by timfa · 2 months ago
cf62e091 History
saveAck.js 940 B Download Raw
1import { 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
10export 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 */
21export function shouldApplySelectedEditorChunk ({ isSaveAck = false, isDirty = false } = {})
22{
23 return !!isSaveAck || !isDirty;
24}