"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateBase = void 0;
var immer_1 = require("immer");
function updateBase(editing, baseTile) {
    var patches = [];
    var sceneMap = immer_1.default(editing.sceneMap, function (draft) {
        draft.base = baseTile.index;
        var exists = draft.squares.some(function (item) { return item.index === baseTile.index; });
        if (exists) {
            return; // 既に存在するタイルなので何もしない
        }
        // タイルが存在しなかったので追加
        draft.squares.push({
            index: baseTile.index,
            placement: baseTile.placement,
            tile: {
                size: [32, 32],
                image: {
                    type: 'url',
                    src: baseTile.src
                },
                author: baseTile.author
            }
        });
    }, function (_, invertPatches) {
        patches = invertPatches;
    });
    if (patches.length === 0) {
        return editing;
    }
    return {
        sceneMap: sceneMap,
        undoPatches: editing.undoPatches.concat({
            patches: patches
        })
    };
}
exports.updateBase = updateBase;
//# sourceMappingURL=updateBase.js.map