"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Pen = /** @class */ (function () {
    function Pen(x, y, mode, nib, dragId) {
        this._layer = null;
        this.x = x;
        this.y = y;
        this.mode = mode;
        this.nib = nib;
        this.dragId = dragId;
    }
    Pen.prototype.isEqual = function (other) {
        return (this.x === other.x &&
            this.y === other.y &&
            this.mode === other.mode &&
            this.nib === other.nib &&
            this.dragId === other.dragId);
    };
    Object.defineProperty(Pen.prototype, "layer", {
        /**
         * mode==='pen'の場合: 現在の nib に対して最適なレイヤーを決定する (オートレイヤー機能)
         * mode==='eraser'の場合: layer にセットされた値を返す
         */
        get: function () {
            if (this.mode === 'pen') {
                if (!this.nib) {
                    throw new Error("Auto layer is failed. nib is null");
                }
                return autoLayer(this.nib.placement);
            }
            else {
                if (this._layer === null) {
                    throw new Error("No layer set. Do 'pen.layer = 0;'");
                }
                return this._layer;
            }
        },
        set: function (value) {
            this._layer = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Pen.prototype, "index", {
        get: function () {
            return this.mode === 'pen' && this.nib ? this.nib.index : -88; // とりあえず３桁にしたい
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Pen.prototype, "disabled", {
        /**
         * ペンツールが選択されているのにペン先がない
         */
        get: function () {
            return this.mode === 'pen' && this.nib === null;
        },
        enumerable: true,
        configurable: true
    });
    return Pen;
}());
exports.default = Pen;
function autoLayer(placement) {
    switch (placement.type) {
        case 'Ground':
            return 2;
        case 'Wall':
        case 'Road':
        case 'Rug':
        case 'Barrier':
            return 1;
        case 'Float':
        case 'Sky':
            return 0;
    }
}
//# sourceMappingURL=pen.js.map