/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ 996:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ERunType = void 0;
__exportStar(__webpack_require__(246), exports);
__exportStar(__webpack_require__(799), exports);
var types_1 = __webpack_require__(886);
Object.defineProperty(exports, "ERunType", ({ enumerable: true, get: function () { return types_1.ERunType; } }));


/***/ }),

/***/ 799:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.withHitbox = void 0;
var Game_1 = __importDefault(__webpack_require__(513));
var common_types_1 = __webpack_require__(475);
function drawObjectWithHitbox(shape) {
    return function (canvas) {
        var _a = this.state, _b = _a.sprite, imageX = _b.imageX, imageY = _b.imageY, realImageWidth = _b.realImageWidth, realImageHeight = _b.realImageHeight, imageWidth = _b.imageWidth, imageHeight = _b.imageHeight, _c = _b.hitboxWidth, hitboxWidth = _c === void 0 ? imageWidth : _c, _d = _b.hitboxHeight, hitboxHeight = _d === void 0 ? imageHeight : _d, _e = _b.hitboxLeft, hitboxLeft = _e === void 0 ? 0 : _e, _f = _b.hitboxTop, hitboxTop = _f === void 0 ? 0 : _f, x = _a.x, y = _a.y;
        if (shape === common_types_1.EHitboxShape.Rect) {
            this.object = canvas.drawRect({
                fillStyle: 'transparent',
                strokeStyle: Game_1.default.isShowHitbox ? this.gridColor : 'transparent',
                x: x,
                y: y,
                width: hitboxWidth,
                height: hitboxHeight,
            });
        }
        if (shape === common_types_1.EHitboxShape.Ellipse) {
            this.object = canvas.drawEllipse({
                fillStyle: 'transparent',
                strokeStyle: Game_1.default.isShowHitbox ? this.gridColor : 'transparent',
                x: x + imageWidth / 2,
                y: y + imageHeight / 2,
                radiusX: hitboxWidth / 2,
                radiusY: hitboxHeight / 2,
                startAngle: 0,
                endAngle: 180,
                rotation: 0,
            });
        }
        canvas.drawImage(this.sprite, imageX, imageY, realImageWidth, realImageHeight, x - hitboxLeft, y - hitboxTop, imageWidth, imageHeight);
    };
}
/**
 *
 * @param CanvasObjectClass
 * @description Класс должен иметь поле sprite, стейт sprite со свойствами imageX, imageY, realImageWidth, realImageHeight, imageWidth, imageHeight, hitboxWidth, hitboxHeight, hitboxLeft, hitboxTop
 */
var withHitbox = function (CanvasObjectClass, shape) {
    if (shape === void 0) { shape = common_types_1.EHitboxShape.Rect; }
    return /** @class */ (function (_super) {
        __extends(CanvasObjectWithHitbox, _super);
        function CanvasObjectWithHitbox() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, args) || this;
            _this.draw = drawObjectWithHitbox.bind(_this)(shape);
            return _this;
        }
        return CanvasObjectWithHitbox;
    }(CanvasObjectClass));
};
exports.withHitbox = withHitbox;


/***/ }),

/***/ 117:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.INTERVAL = void 0;
exports.INTERVAL = 50;


/***/ }),

/***/ 246:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.withRun = void 0;
var types_1 = __webpack_require__(886);
var runCathet_1 = __importDefault(__webpack_require__(777));
var runDiagonal_1 = __importDefault(__webpack_require__(814));
var runSmartCathet_1 = __importDefault(__webpack_require__(191));
/**
 *
 * @param type
 * @param changeStateFields
 */
var withRun = function (type, changeStateFields) {
    if (type === void 0) { type = types_1.ERunType.Diagonal; }
    /**
     *
     * @param CanvasObjectClass - Класс должен иметь поле step, стейты x, y
     */
    return function (CanvasObjectClass) { return /** @class */ (function (_super) {
        __extends(CanvasObjectWithRun, _super);
        function CanvasObjectWithRun() {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var _this = _super.apply(this, args) || this;
            _this._interval = null;
            switch (type) {
                case types_1.ERunType.Cathet: {
                    _this.run = (0, runCathet_1.default)(changeStateFields).bind(_this);
                    break;
                }
                case types_1.ERunType.Diagonal: {
                    _this.run = (0, runDiagonal_1.default)(changeStateFields).bind(_this);
                    break;
                }
                case types_1.ERunType.SmartCathet: {
                    _this.run = (0, runSmartCathet_1.default)(changeStateFields).bind(_this);
                    break;
                }
            }
            return _this;
        }
        return CanvasObjectWithRun;
    }(CanvasObjectClass)); };
};
exports.withRun = withRun;


/***/ }),

/***/ 777:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
var constants_1 = __webpack_require__(117);
var runCathet = function (changeStateFields) {
    return function (_a) {
        var _this = this;
        var toX = _a.x, toY = _a.y;
        if (this._interval) {
            clearInterval(this._interval);
        }
        var yPath = toY - this.state.y;
        var xPath = toX - this.state.x;
        var xSign = xPath / Math.abs(xPath) * this.step;
        var ySign = yPath / Math.abs(yPath) * this.step;
        this._interval = setInterval(function () {
            _this.setState(function (currentState) {
                if (currentState.x === toX && currentState.y === toY)
                    clearInterval(_this._interval);
                var newState = __assign({ x: currentState.x, y: currentState.y }, changeStateFields({ dX: xSign, dY: ySign }));
                if (Math.abs(currentState.x - toX) >= _this.step)
                    newState.x = currentState.x + xSign;
                else
                    newState.x = toX;
                if (Math.abs(currentState.y - toY) >= _this.step)
                    newState.y = currentState.y + ySign;
                else
                    newState.y = toY;
                return newState;
            });
        }, constants_1.INTERVAL);
    };
};
exports["default"] = runCathet;


/***/ }),

/***/ 814:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
var constants_1 = __webpack_require__(117);
var runDiagonal = function (changeStateFields) {
    return function (_a) {
        var _this = this;
        var toX = _a.x, toY = _a.y;
        if (this._interval) {
            clearInterval(this._interval);
        }
        var yPath = toY - this.state.y;
        var xPath = toX - this.state.x;
        var xSign = xPath / Math.abs(xPath) * this.step;
        var ySign = yPath / Math.abs(yPath) * this.step;
        this._interval = setInterval(function () {
            _this.setState(function (currentState) {
                var newState = {};
                if (Math.abs(yPath) > Math.abs(xPath)) {
                    if (Math.abs(toY - _this.state.y) >= _this.step) {
                        newState = __assign({ y: currentState.y + ySign, x: currentState.x + Math.abs(xPath / yPath) * xSign }, changeStateFields({ dX: xSign, dY: ySign }));
                    }
                    else {
                        newState = __assign({ y: toY, x: toX }, changeStateFields({ dX: xSign, dY: ySign, isLast: true }));
                        clearInterval(_this._interval);
                    }
                }
                else {
                    if (Math.abs(toX - _this.state.x) >= _this.step) {
                        newState = __assign({ x: currentState.x + xSign, y: currentState.y + Math.abs(yPath / xPath) * ySign }, changeStateFields({ dX: xSign, dY: ySign }));
                    }
                    else {
                        newState = __assign({ y: toY, x: toX }, changeStateFields({ dX: xSign, dY: ySign, isLast: true }));
                        clearInterval(_this._interval);
                    }
                }
                return newState;
            });
        }, constants_1.INTERVAL);
    };
};
exports["default"] = runDiagonal;


/***/ }),

/***/ 191:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
var utils_1 = __webpack_require__(147);
var constants_1 = __webpack_require__(117);
var runSmartCathet = function (changeStateFields) {
    return function (_a) {
        var _this = this;
        var toX = _a.x, toY = _a.y;
        if (this._interval) {
            clearInterval(this._interval);
        }
        var path = findPath.call(this, { x: this.state.x, y: this.state.y, cost: 0 }, { x: toX, y: toY, cost: 0 });
        var currentIndex = path.length - 1;
        var prevPoint = path[currentIndex];
        this._interval = setInterval(function () {
            var point = path[currentIndex];
            if (!point) {
                _this.setState(__assign({}, changeStateFields({ dX: 0, dY: 0, isLast: true })));
                clearInterval(_this._interval);
                return;
            }
            var xSign = point.x - prevPoint.x;
            var ySign = point.y - prevPoint.y;
            if (point) {
                _this.setState(__assign({ x: point.x, y: point.y }, changeStateFields({ dX: xSign, dY: ySign })));
            }
            currentIndex--;
            prevPoint = point;
        }, constants_1.INTERVAL);
    };
};
function findPath(startNode, endNode) {
    var _a;
    console.log('findPath');
    var reachable = (_a = {}, _a[(0, utils_1.getMapKey)(startNode.x, startNode.y)] = startNode, _a);
    var explored = {};
    while (Object.keys(reachable).length) {
        var node = chooseNode(reachable);
        var nodeKey = (0, utils_1.getMapKey)(node.x, node.y);
        if (node.x === endNode.x && node.y === endNode.y) {
            return buildPath(node);
        }
        explored[nodeKey] = node;
        delete reachable[nodeKey];
        var newReachable = omitNodes(getAdjacentNodes.call(this, node), explored);
        for (var adjacentKey in newReachable) {
            if (!reachable[adjacentKey]) {
                newReachable[adjacentKey].previous = node;
                reachable[adjacentKey] = newReachable[adjacentKey];
            }
            if (node.cost + 1 < newReachable[adjacentKey].cost) {
                newReachable[adjacentKey].previous = node;
                newReachable[adjacentKey].cost = node.cost + 1;
            }
        }
    }
    console.log('Путь не найден');
    return [];
}
function getAdjacentNodes(node) {
    var _this = this;
    var isExistPoint = function (x, y) { return !!_this.map[(0, utils_1.getMapKey)(x, y)]; };
    var isOwnPoints = function (x, y) { return _this.map[(0, utils_1.getMapKey)(x, y)].id === _this.id; };
    var isInfinity = function (x, y) { return _this.map[(0, utils_1.getMapKey)(x, y)].cost === Infinity; };
    var nodes = {};
    for (var x = -1; x <= 1; x++) {
        for (var y = -1; y <= 1; y++) {
            if (x === 0 && y === 0)
                continue;
            var itemX = node.x + x;
            var itemY = node.y + y;
            var isAllow = true;
            for (var oX = 0; oX < this.state.sprite.hitboxWidth; oX++) {
                for (var oY = 0; oY < this.state.sprite.hitboxHeight; oY++) {
                    var xInObjectWidth = itemX + oX;
                    var yInObjectHeight = itemY + oY;
                    if (!isExistPoint(xInObjectWidth, yInObjectHeight)) {
                        isAllow = false;
                        continue;
                    }
                    if (isInfinity(xInObjectWidth, yInObjectHeight) && !isOwnPoints(xInObjectWidth, yInObjectHeight)) {
                        isAllow = false;
                    }
                }
            }
            if (isAllow) {
                nodes[(0, utils_1.getMapKey)(itemX, itemY)] = __assign(__assign({}, this.map[(0, utils_1.getMapKey)(itemX, itemY)]), { cost: 0 });
            }
        }
    }
    return nodes;
}
var omitNodes = function (map, omitted) {
    return Object.entries(map).reduce(function (prev, _a) {
        var _b;
        var key = _a[0], value = _a[1];
        if (!omitted[key]) {
            return __assign(__assign({}, prev), (_b = {}, _b[key] = value, _b));
        }
        return prev;
    }, {});
};
var buildPath = function (goalNode) {
    var path = [];
    while (goalNode) {
        path.push(goalNode);
        goalNode = goalNode.previous;
    }
    return path;
};
var chooseNode = function (reachable) {
    var bestNode = null;
    for (var key in reachable) {
        if (bestNode === null || bestNode.cost > reachable[key].cost) {
            bestNode = reachable[key];
        }
    }
    return bestNode;
};
exports["default"] = runSmartCathet;


/***/ }),

/***/ 886:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ERunType = void 0;
var ERunType;
(function (ERunType) {
    ERunType["Diagonal"] = "diagonal";
    ERunType["Cathet"] = "cathet";
    ERunType["SmartCathet"] = "smart-cathet";
})(ERunType = exports.ERunType || (exports.ERunType = {}));


/***/ }),

/***/ 475:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.EHitboxShape = exports.ECanvasEventType = exports.ActionTypes = void 0;
var ActionTypes;
(function (ActionTypes) {
    ActionTypes["MouseDown"] = "mousedown";
    ActionTypes["MouseUp"] = "mouseup";
    ActionTypes["MouseOver"] = "mouseover";
    ActionTypes["MouseOut"] = "mouseout";
})(ActionTypes = exports.ActionTypes || (exports.ActionTypes = {}));
var ECanvasEventType;
(function (ECanvasEventType) {
    ECanvasEventType["Click"] = "click";
})(ECanvasEventType = exports.ECanvasEventType || (exports.ECanvasEventType = {}));
var EHitboxShape;
(function (EHitboxShape) {
    EHitboxShape["Rect"] = "rect";
    EHitboxShape["Ellipse"] = "ellipse";
})(EHitboxShape = exports.EHitboxShape || (exports.EHitboxShape = {}));


/***/ }),

/***/ 513:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Game = void 0;
var Game = /** @class */ (function () {
    function Game() {
        var _this = this;
        this.showToolbox = function (root) {
            var form = document.createElement('form');
            form.style.padding = '10px 5px';
            form.style.background = '#2f2f2f';
            form.style.color = 'white';
            form.style.position = 'fixed';
            form.style.top = '50vh';
            form.style.left = '0';
            form.style.display = 'flex';
            form.style.flexDirection = 'column';
            var isShowHitboxCheckbox = _this.createCheckbox('Хитбокс', 'isShowHitbox');
            var isShowGridCheckbox = _this.createCheckbox('Сетка', 'isShowGrid');
            var isShowHitboxGridCheckbox = _this.createCheckbox('Сетка хитбокса', 'isShowHitboxGrid');
            form.append(isShowHitboxCheckbox);
            form.append(isShowGridCheckbox);
            form.append(isShowHitboxGridCheckbox);
            document.querySelector(root || 'body').append(form);
        };
        this.createCheckbox = function (innerText, name) {
            var checkbox = document.createElement('input');
            checkbox.name = name;
            checkbox.type = 'checkbox';
            // @ts-ignore
            checkbox.onchange = function () { return Game[name] = !Game[name]; };
            var label = document.createElement('label');
            label.innerText = innerText;
            label.append(checkbox);
            return label;
        };
        if (!Game.instance) {
            Game.instance = this;
        }
        return Game.instance;
    }
    return Game;
}());
exports.Game = Game;
exports["default"] = Game;


/***/ }),

/***/ 147:
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getMapKey = void 0;
var getMapKey = function (x, y) { return "x".concat(x, "y").concat(y); };
exports.getMapKey = getMapKey;


/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module is referenced by other modules so it can't be inlined
/******/ 	var __webpack_exports__ = __webpack_require__(996);
/******/ 	var __webpack_export_target__ = exports;
/******/ 	for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
/******/ 	if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/ 	
/******/ })()
;