40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import {
|
|
DEFAULT_MAP_SIZE,
|
|
getObjectKey,
|
|
mapForMode,
|
|
normalizeMapObject,
|
|
objectsForMode,
|
|
} from "./locationMapUtils";
|
|
|
|
export function getDefaultMapDraft() {
|
|
return {
|
|
name: "Store Map",
|
|
width: DEFAULT_MAP_SIZE.width,
|
|
height: DEFAULT_MAP_SIZE.height,
|
|
};
|
|
}
|
|
|
|
export function getMapDraftSnapshot(nextState, nextMode, nextPreviewDraft, options = {}) {
|
|
const nextMap = mapForMode(nextState, nextMode, nextPreviewDraft);
|
|
const nextObjects = objectsForMode(nextState, nextMode, nextPreviewDraft);
|
|
if (!nextMap) return null;
|
|
|
|
const normalizedObjects = nextObjects.map(normalizeMapObject);
|
|
const preserveSelectedIndex = Number.isInteger(options.preserveSelectedIndex)
|
|
? options.preserveSelectedIndex
|
|
: -1;
|
|
const preservedSelectedObject = preserveSelectedIndex >= 0
|
|
? normalizedObjects[preserveSelectedIndex]
|
|
: null;
|
|
|
|
return {
|
|
mapDraft: {
|
|
name: nextMap.name || "Store Map",
|
|
width: nextMap.width || DEFAULT_MAP_SIZE.width,
|
|
height: nextMap.height || DEFAULT_MAP_SIZE.height,
|
|
},
|
|
objects: normalizedObjects,
|
|
selectedObjectKey: preservedSelectedObject ? getObjectKey(preservedSelectedObject) : null,
|
|
};
|
|
}
|