/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });

// CONCATENATED MODULE: ./src/cgt/utils/canvas2d.js
const emptyInit = function () {};

const defaultOptions = {
    autoresize: false,
    keepaspectratio: false,
    init: emptyInit
};

const addResizeFunction = fn => {
    fn();
    window.addEventListener('resize', () => fn());
};

const canvas2d = (canvas, options) => {
    const opts = Object.assign({}, defaultOptions, options);
    const ctx = canvas.getContext('2d');

    if (opts.autoresize) {
        addResizeFunction(() => {
            const rect = canvas.getBoundingClientRect();
            canvas.width = rect.width;
            canvas.height = rect.height;
        });
    }

    if (opts.keepaspectratio) {
        addResizeFunction(() => {
            const height = window.innerWidth * canvas.height / canvas.width;
            canvas.style.height = height + 'px';
        });
    }

    options.init(ctx);

    return ctx;
};

/* harmony default export */ var utils_canvas2d = (canvas2d);
// CONCATENATED MODULE: ./src/cgt/utils/looper.js
const looper = cb => {
    let lastTime = Date.now();

    const fn = time => {
        cb(Math.max(time - lastTime, 0));
        lastTime = time;
        requestAnimationFrame(fn);
    };

    fn(lastTime);
};

/* harmony default export */ var utils_looper = (looper);
// CONCATENATED MODULE: ./src/cgt/inputs/mouseinput.js
const init = () => {
    window.addEventListener('click', evt => {
        emit('click', {
            x: evt.pageX,
            y: evt.pageY
        });
    });

    window.addEventListener('mousemove', evt => {
        emit('move', {
            x: evt.pageX,
            y: evt.pageY
        });
    });

    window.addEventListener('mousedown', evt => {
        emit('down', {
            x: evt.pageX,
            y: evt.pageY
        });
    });

    window.addEventListener('mouseup', evt => {
        emit('up', {
            x: evt.pageX,
            y: evt.pageY
        });
    });

    const onWheel = e => {
        e = e || window.event;

        // wheelDelta не дает возможность узнать количество пикселей
        var delta = e.deltaY || e.detail || e.wheelDelta;
        emit('zoom', {
            delta
        });
    };

    if (window.addEventListener) {
        if ('onwheel' in document) {
            // IE9+, FF17+, Ch31+
            window.addEventListener('wheel', onWheel);
        } else if ('onmousewheel' in document) {
            // устаревший вариант события
            window.addEventListener('mousewheel', onWheel);
        } else {
            // Firefox < 17
            window.addEventListener('MozMousePixelScroll', onWheel);
        }
    } else {
        // IE8-
        // @ts-ignore
        window.attachEvent('onmousewheel', onWheel);
    }
};

init();

let events = {};
const on = (event, fn) => {
    if (!events[event]) {
        events[event] = [];
    }
    events[event].push(fn);
};

const emit = (event, data) => {
    if (events[event]) {
        events[event].forEach(ev => ev(data));
    }
};

/* harmony default export */ var mouseinput = ({
    on
});
// CONCATENATED MODULE: ./src/cgt/index.js




const canvas = document.getElementById('canvas');

let _scenes = {
    start: () => {}
};

let _currentScene = null;

const start = (scenes, options) => {
    _scenes = scenes;

    scene('start');

    const ctx = utils_canvas2d(canvas, options);

    utils_looper(dt => {
        _currentScene.update(dt);
        _currentScene.draw(ctx);
    });
};

const scene = new_scene => {
    if (!_scenes[new_scene]) return;

    if (_currentScene) {
        _currentScene.stop();
    }

    _currentScene = _scenes[new_scene];

    _currentScene.start();
};

let k = 1;
const update_multipliers = () => k = canvas.width / window.innerWidth;
window.addEventListener('resize', () => update_multipliers);
update_multipliers();

mouseinput.on('click', ({ x, y }) => {
    _currentScene && _currentScene.onMouseClick(x * k, y * k);
});

mouseinput.on('move', ({ x, y }) => {
    _currentScene && _currentScene.onMouseMove(x * k, y * k);
});

mouseinput.on('zoom', ({ delta }) => {
    _currentScene && _currentScene.onMouseZoom(delta);
});

/* harmony default export */ var cgt = ({
    start,
    scene

    /*
    class App {
        constructor() {
    
        }
    
        start(options) {
            const ctx = canvas2d(canvas, options)
    
            looper(dt => {
                this.scene.update(dt)
                this.scene.draw(ctx)
            })
        }
    
        withResources(items) {
            return this
        }
    
        withMouse(events) {
            return this
        }
    
        setScene(scene) {
            this.scene.stop()
            this.scene = scene
            this.scene.start()
        }
    }
    */

});
// CONCATENATED MODULE: ./src/cgt/scene/index.js
class Scene {
    start() {}
    stop() {}
    draw() {}
    update() {}

    onMouseClick() {}
    onMouseMove() {}
    onMouseZoom() {}
}
// CONCATENATED MODULE: ./src/menu/menu-item.js
const COLOR_NORMAL = '#555';
const COLOR_DISABLED = '#aaa';
const COLOR_HOVER = '#222';
const COLOR_LABEL = '#888';

class MenuItem {
    constructor(data = {}) {
        this.text = data.text || '';
        this.x = data.x || 0;
        this.y = data.y || 0;
        this.width = data.width || 0;
        this.height = data.height || 0;
        this.size = data.size || 24;
        this.disabled = data.disabled || false;
        this.action = data.action || '';
        this.align = data.align || 'center';
        this.border = data.border || false;
        this.type = data.type || 'button';
        this.data = data.data || {};
        this.icon = data.icon || null;
    }

    draw(ctx, hovered = false) {
        ctx.textAlign = this.align;
        ctx.textBaseline = 'middle';

        const size = hovered ? this.size * 1.01 : this.size;

        ctx.font = `bold ${size}px Lato`;

        const color = this.getColor(hovered);
        ctx.fillStyle = color;
        ctx.fillText(this.text, this.x, this.y);

        if (this.icon) {
            ctx.drawImage(this.icon, this.x - 20, this.y - 15, 20, 20);
        }

        if (this.border) {
            ctx.strokeStyle = color;
            ctx.strokeRect(this.x - this.width / 2, this.y - this.height / 2, this.width, this.height - 3);
        }
    }

    getColor(hovered) {
        if (this.type === 'label') return COLOR_LABEL;
        if (this.disabled) return COLOR_DISABLED;
        if (hovered) return COLOR_HOVER;
        return COLOR_NORMAL;
    }

    isDisabled() {
        return this.disabled;
    }

    isUnderCursor(x, y) {
        return Math.abs(x - this.x) < this.width / 2 && Math.abs(y - this.y) < this.height / 2;
    }
}
// CONCATENATED MODULE: ./src/menu/menu-item-res.js
class MenuItemRes {
    constructor(data = {}) {
        this.resources = data.resources || [];
        this.x = data.x || 0;
        this.y = data.y || 0;
        this.type = 'resources';
    }

    draw(ctx) {
        ctx.fillStyle = '#000';
        ctx.font = '16px Lato';
        ctx.textAlign = 'left';

        const w = 70;
        let offset_x = -this.resources.length / 2 * w + 20;
        this.resources.forEach(item => {
            ctx.drawImage(item.icon, this.x + offset_x, this.y, 20, 20);
            ctx.fillText(item.value, this.x + offset_x + 25, this.y + 10);

            offset_x += w;
        });
    }
}
// CONCATENATED MODULE: ./src/menu/menu.js




class menu_Menu {
    constructor(items = []) {
        this.items = items.map(data => new MenuItem(data));
        this.lastHoveredItem = null;
    }

    add(item) {
        this.items.push(item);
    }

    addLabel(text, x, y, size = 28) {
        const item = new MenuItem({
            text, x, y, size, type: 'label'
        });

        this.add(item);
    }

    addLabelWithIcon(text, icon, x, y, size = 28) {
        const item = new MenuItem({
            text, icon, x, y, size,
            type: 'label', align: 'left'
        });

        this.add(item);
    }

    addResources(items, x, y) {
        const resources = items.map(item => app.Helpers.makeResourceItem(item.type, item.amount));
        const item = new MenuItemRes({
            resources, x, y
        });

        this.add(item);
    }

    draw(ctx) {
        this.items.forEach(item => item.draw(ctx, this.lastHoveredItem == item));
    }

    mouse(x, y) {
        const activeItems = this.items.filter(item => item.type === 'button' && !item.isDisabled());
        const menuUnderCursor = activeItems.find(item => item.isUnderCursor(x, y));

        if (this.lastHoveredItem !== menuUnderCursor) {
            this.lastHoveredItem = menuUnderCursor;
        }
    }

    getHovered() {
        return this.lastHoveredItem;
    }
}
// CONCATENATED MODULE: ./src/menu/config.js
/* harmony default export */ var config = ({
    start: [{
        text: 'НАЧАТЬ ИГРУ',
        x: 990,
        y: 400,
        width: 450,
        height: 60,
        size: 48,
        disabled: false,
        action: 'new'
    }, {
        text: 'Загляните в README файл, там есть небольшое обяснение происходящему',
        x: 990,
        y: 500,
        size: 12,
        type: 'label'
    }, {
        text: 'F11 - на весь экран',
        x: 990,
        y: 550,
        width: 450,
        height: 60,
        size: 24,
        type: 'label',
        action: 'fullscreen'
    }],

    win: [{
        text: 'ВЫ ПОБЕДИЛИ',
        x: 990,
        y: 400,
        width: 450,
        height: 60,
        size: 48,
        disabled: true
    }],

    fail: [{
        text: 'СОПЕРНИК ОКАЗАЛСЯ БЫСТРЕЕ',
        x: 990,
        y: 400,
        width: 450,
        height: 60,
        size: 48,
        disabled: true
    }]
});
// CONCATENATED MODULE: ./src/menu/index.js





const resTitle = type => app.Config.resources[type] ? app.Config.resources[type].title : '';

const makeBuildMenuItem = (menu, title, requirements, level, x, y, btn_text, action, data) => {
    menu.addLabel(title, x, y, 14);

    menu.addResources(requirements, x, y + 20);

    // if (buildProduct) {
    //     menu.addLabel(buildProduct, x, y, 14)
    // }

    menu.add(new MenuItem({
        text: btn_text,
        x: x,
        y: y + 80,
        width: 125,
        height: 40,
        size: 18,
        border: true,
        action,
        disabled: !app.Helpers.isMetRequirements(app.Player, requirements, level),
        data
    }));
};

const generate = (type, area) => {
    const menu = new menu_Menu();

    menu.addLabel(area.info().title, 990, 400);

    const building = area.getBuilding();
    if (building) {
        const buildingInfo = app.getBuildingInfo(building.type);

        let convert = '';
        if (building.config.convert && building.config.convert.length) {
            const titles = building.config.convert.map(item => resTitle(item.type));
            convert = ' из ' + titles.join(', ');
        }

        const buildProductType = resTitle(building.config.produce);
        let buildProduct = '';
        if (buildProductType) {
            buildProduct = 'производит ' + resTitle(building.config.produce) + convert;
        }

        const infoText = [buildingInfo.title, area.buildingOwner === app.Player ? 'игрока' : 'бота', 'уровень ' + (building.level + 1), buildProduct].join(' ');
        menu.addLabel(infoText, 990, 440, 18);

        if (area.buildingOwner === app.Player) {
            if (building.type === 'MARKET') {
                const market = app.Market.get();
                market.forEach((item, i) => {
                    const x = 900;
                    const y = 490 + i * 60;
                    menu.addResources([{ type: item.from.type, amount: item.from.value }], x, y);
                    menu.addLabel('>', x + 52, y + 10);
                    menu.addResources([{ type: item.to.type, amount: item.to.value }], x + 90, y);
                    menu.add(new MenuItem({
                        text: 'Обменять',
                        x: x + 210,
                        y: y + 12,
                        width: 125,
                        height: 40,
                        size: 18,
                        border: true,
                        action: 'buy',
                        disabled: !app.Helpers.isMetRequirements(app.Player, [{ type: item.from.type, amount: item.from.value }]),
                        data: { item }
                    }));
                });
            } else {
                let pos_y = 450;

                const maxLevel = buildingInfo.requirements.length - 1;
                if (building.level < maxLevel) {
                    const requirements = buildingInfo.requirements[building.level + 1];
                    const data = { area, buildingType: building.type, requirements };
                    const level = building.type === 'SCHOOL' ? 0 : building.level + 1;
                    makeBuildMenuItem(menu, '', requirements, level, 990, pos_y, 'Улучшить', 'upgrade', data);

                    pos_y += 130;
                } else {
                    pos_y += 130;
                }

                const requirements = buildingInfo.requirements[0];
                menu.add(new MenuItem({
                    text: 'Снести',
                    x: 990,
                    y: pos_y,
                    width: 125,
                    height: 40,
                    size: 18,
                    border: true,
                    action: 'destroy',
                    data: { area, requirements }
                }));
            }
        }
    } else {
        const availableBuildings = area.getAvalilableBuildings();
        const columnWidth = 200;
        availableBuildings.forEach((buildingType, i) => {
            const offset_x = columnWidth * i - availableBuildings.length * columnWidth / 2 + columnWidth / 2;
            const buildingInfo = app.getBuildingInfo(buildingType);

            // const buildProductType = resTitle(buildingInfo.produce)
            // let buildProduct = ''
            // if (buildProductType) {
            //     buildProduct = 'производит ' + resTitle(buildingInfo.produce)
            // }

            const requirements = buildingInfo.requirements[0];
            const data = { area, buildingType, requirements };
            makeBuildMenuItem(menu, buildingInfo.title.toUpperCase(), requirements, 0, 990 + offset_x, 450, 'Построить', 'build', data);
        });
    }

    return menu;
};

/* harmony default export */ var src_menu = ({
    get: name => new menu_Menu(config[name]),
    generate
});
// CONCATENATED MODULE: ./src/scenes/scene-start.js





class scene_start_StartScene extends Scene {

    start() {
        this.menu = src_menu.get('start');

        this.lastItemSelected = null;

        this.lastWorldLoaded = 'new';

        this.world = app.getWorld();
        this.world.loadNew(180);
        this.world.angle.setOptions(.1, 0);
    }

    onMouseClick() {
        const menuItem = this.menu.getHovered();
        if (menuItem) {
            if (menuItem.action == 'new') {
                cgt.scene('play');
            }
        }
    }

    onMouseMove(x, y) {
        this.menu.mouse(x, y);
    }

    update(dt) {
        this.world.angle.inc(10);
        this.world.update(dt);
    }

    draw(ctx) {
        this.world.draw(ctx);
        this.menu.draw(ctx);
    }
}
// CONCATENATED MODULE: ./src/cgt/utils/logger.js
let info = {};

const draw = ctx => {
    ctx.save();
    let i = 1;
    ctx.font = '18px sans';
    ctx.fillStyle = '#fff';
    ctx.shadowColor = 'black';
    ctx.textAlign = 'left';
    ctx.shadowBlur = 3;
    for (let key in info) {
        ctx.fillText(info[key], 10, 22 * i);
        i++;
    }
    ctx.restore();
};

const set = (key, text) => {
    info[key] = text;
};

const clear = () => {
    info = {};
};

/* harmony default export */ var logger = ({
    draw,
    set,
    clear
});
// CONCATENATED MODULE: ./src/cgt/utils/tact.js
const create_tact = interval => {
    let start = Date.now();

    return () => {
        const diff = Date.now() - start;
        if (diff > interval) {
            start += ~~(diff / interval) * interval;
            return true;
        }

        return false;
    };
};

/* harmony default export */ var tact = (create_tact);

/*
const everySecond = create_tact(1000)

let i = 0
while (i < 10) {
    if (everySecond()) {
        console.log(i++)
    }
}

*/
// CONCATENATED MODULE: ./src/cgt/utils/grid.js
/* harmony default export */ var utils_grid = ((columns, offset_x, offset_y, width, height) => {
    let _i = 0;
    return (i = _i) => {
        const c = i % columns;
        const r = ~~(i / columns);
        _i = i + 1;

        const x = offset_x + c * width;
        const y = offset_y + r * height;
        return { x, y };
    };
});

/*
const grid = createGrid(1, 10, 10, 100, 10)
const {x, y} = grid()
*/
// CONCATENATED MODULE: ./src/scenes/scene-play.js









class scene_play_StartScene extends Scene {

    start() {

        this.world = app.getWorld();
        this.world.angle.setOptions(20, 100);

        this.menu = null;
        this.hovered = null;

        logger.clear();

        this.world.drawAreasWithResources = true;

        this.tactResources = tact(10000);
        this.tactMarket = tact(60000);
        this.tactBot = tact(5000);

        app.Market.update();
    }

    update(dt) {
        this.world.update(dt);

        if (this.tactResources()) {
            app.Helpers.processTact(app.Player, this.world.areas);
            app.Helpers.processTact(app.Bot, this.world.areas);

            if (this.world.selectedSector !== null) {
                const area = this.world.areas[this.world.selectedSector];
                this.menu = src_menu.generate('build', area);
            }
        }

        if (this.tactBot()) {
            const botDone = app.Helpers.scriptBot(app.Bot);
            if (botDone) {
                cgt.scene('end');
            }

            logger.set('bot ', JSON.stringify(app.Bot.getResources(), null, '\t'));
        }

        if (this.tactMarket()) {
            app.Market.update();
        }
    }

    draw(ctx) {
        this.world.draw(ctx);

        ctx.fillStyle = '#555';
        ctx.font = '18px Lato';
        ctx.textAlign = 'left';
        ctx.fillText('РЕСУРСЫ', 120, 430);

        ctx.fillStyle = '#000';
        ctx.font = '16px Lato';

        const grid = utils_grid(2, 40, 450, 150, 35);
        ctx.fillStyle = '#000';
        ctx.font = '16px Lato';

        app.Player.getResources().forEach(item => {
            const { x, y } = grid();

            ctx.textAlign = 'right';
            ctx.fillText(item.value, x, y + 10);

            ctx.drawImage(item.icon, x + 10, y, 20, 20);

            ctx.textAlign = 'left';
            ctx.fillText(item.label, x + 40, y + 10);
        });

        // Logger.draw(ctx)

        if (this.menu) {
            this.menu.draw(ctx);
        }
    }

    onMouseZoom(delta) {
        this.world.angle.inc(-Math.sign(delta) * 10);
    }

    onMouseMove(x, y) {
        this.world.hoverObject(x, y);
        if (this.menu) {
            this.menu.mouse(x, y);
        }
    }

    onMouseClick() {
        if (this.world.hoveredSector !== null) {
            this.world.selectedSector = this.world.hoveredSector;
            const area = this.world.areas[this.world.hoveredSector];
            this.menu = src_menu.generate('build', area);
            return;
        }

        if (this.menu) {
            const menuItem = this.menu.getHovered();
            if (menuItem) {
                if (menuItem.action === 'build') {
                    const { area, buildingType, requirements } = menuItem.data;

                    area.build(buildingType, app.Player);

                    if (buildingType === 'WIN') {
                        cgt.scene('end');
                        return;
                    }

                    app.Player.increaseResources(requirements, -1);
                    this.menu = src_menu.generate('build', area);

                    return;
                }

                if (menuItem.action === 'destroy') {
                    const { area, requirements } = menuItem.data;
                    area.removeBuilding();
                    app.Player.increaseResources(requirements);
                    this.menu = src_menu.generate('build', area);
                    return;
                }

                if (menuItem.action === 'upgrade') {
                    const { area, requirements } = menuItem.data;
                    area.upgradeBuilding();
                    app.Player.increaseResources(requirements, -1);

                    if (area.getBuilding().type === 'SCHOOL') {
                        const newLevel = Math.max(area.getBuilding().level, app.Player.getResource('LEVEL').value);
                        app.Player.setResourceAmount('LEVEL', newLevel);
                    }

                    this.menu = src_menu.generate('build', area);
                    return;
                }

                if (menuItem.action === 'buy') {
                    const { item } = menuItem.data;
                    app.Player.increaseResources([{ type: item.from.type, amount: item.from.value }], -1);
                    app.Player.increaseResources([{ type: item.to.type, amount: item.to.value }]);
                    app.Market.removeOffer(item.id);

                    if (this.world.selectedSector !== null) {
                        const area = this.world.areas[this.world.selectedSector];
                        this.menu = src_menu.generate('build', area);
                    }
                }
            }
        }
    }
}
// CONCATENATED MODULE: ./src/scenes/scene-end.js




class scene_end_EndScene extends Scene {

    start() {
        this.lastItemSelected = null;

        this.lastWorldLoaded = 'new';

        this.world = app.getWorld();
        this.world.angle.setOptions(.1, 0);
        this.world.drawAreasWithResources = false;
        this.world.hoveredSector = null;
        this.world.selectedSector = null;

        const area = this.world.areas.find(area => area.getBuilding() && area.getBuilding().type === 'WIN');
        const menuType = area.buildingOwner === app.Player ? 'win' : 'fail';
        this.menu = src_menu.get(menuType);
    }

    update(dt) {
        this.world.angle.inc(10);
        this.world.update(dt);
    }

    draw(ctx) {
        this.world.draw(ctx);
        this.menu.draw(ctx);
    }
}
// CONCATENATED MODULE: ./src/scenes/index.js




const scenes_scenes = () => {
    return {
        start: new scene_start_StartScene(),
        play: new scene_play_StartScene(),
        end: new scene_end_EndScene()
    };
};

/* harmony default export */ var src_scenes = (scenes_scenes);
// CONCATENATED MODULE: ./src/cgt/resources/atlas.js
/* global Image */

const newResourceItem = (resources, name, data) => {
    return new Promise((resolve, reject) => {
        const newImage = new Image();
        newImage.onload = () => {
            resources[name] = {
                type: 'image',
                data: newImage
            };
            resolve(resources[name]);
        };
        newImage.onerror = reject;

        newImage.src = data;
    });
};

const cutImage = (img, { x, y, w, h }) => {
    const canvas = document.createElement('canvas');
    let ctx = canvas.getContext('2d');

    canvas.width = w;
    canvas.height = h;
    ctx.clearRect(0, 0, w, h);
    ctx.drawImage(img, x, y, w, h, 0, 0, w, h);

    const data = canvas.toDataURL('image/png');

    ctx = null;
    canvas.remove();

    return data;
};

const loadAtlas = (path, data, resources) => {
    return new Promise((resolve, reject) => {
        const img = new Image();

        img.onload = () => {
            const promises = data.map(item => {
                const imgcut = cutImage(img, item);
                return newResourceItem(resources, item.name, imgcut);
            });

            const result = Promise.all(promises);
            resolve(result);
        };

        img.onerror = reject;

        img.src = path;
    });
};

/* harmony default export */ var atlas = (loadAtlas);
// CONCATENATED MODULE: ./src/cgt/resources/image.js
const loadImage = (name, path, resources) => {
    return new Promise((resolve, reject) => {
        const img = new Image();

        img.onload = () => {
            resources[name] = {
                type: 'image',
                data: img
            };

            resolve(img);
        };

        img.onerror = reject;

        img.src = path;
    });
};

/* harmony default export */ var resources_image = (loadImage);
// CONCATENATED MODULE: ./src/cgt/resources/index.js



let resources_resources = {};

const loadAll = arr => {
    const promises = arr.map(item => {
        if (item.type === 'image') return resources_image(item.name, item.path, resources_resources);
        if (item.type === 'atlas') return atlas(item.path, item.items, resources_resources);
    });
    return Promise.all(promises);
};

const load = {
    image: (name, path) => resources_image(name, path, resources_resources),
    atlas: (path, items) => atlas(path, items, resources_resources),
    all: loadAll
};

const get = name => {
    return resources_resources[name] ? resources_resources[name].data : null;
};

/* harmony default export */ var cgt_resources = ({
    loadAll,
    load,
    get
});
// CONCATENATED MODULE: ./src/config/areas.js
/* harmony default export */ var config_areas = ({
    FOREST: {
        title: 'Лес',
        images: [{ src: 'grass', y: -19, h: 19 }, { src: 'trees', y: -57, h: 57 }],
        resources: [{ type: 'ANIMALS', min: 2, max: 8 }, { type: 'WOOD', min: 2, max: 10 }],
        buildings: ['HUNTER', 'SAWMILL', 'FORESTER'],
        probability: 5
    },

    FIELD: {
        title: 'Поле',
        images: [{ src: 'grass', y: -19, h: 19 }],
        resources: [{ type: 'WHEAT', min: 2, max: 10 }, { type: 'ANIMALS', min: -4, max: 2 }],
        buildings: ['FARM', 'FORGE', 'SAWMILL', 'HOUSE', 'MARKET', 'SCHOOL', 'WIN'],
        probability: 2
    },

    MOUNTAINS: {
        title: 'Горы',
        images: [{ src: 'mountains', y: -48, h: 48 }],
        resources: [{ type: 'STONE', min: 0, max: 5 }, { type: 'IRON', min: -5, max: 5 }, { type: 'COAL', min: -5, max: 5 }],
        buildings: ['COAL', 'STEAL', 'QUARRY'],
        probability: 2
    },

    WATER: {
        title: 'Вода',
        images: [{ src: 'water', y: -30, h: 30 }],
        resources: [{ type: 'FISH', min: 1, max: 10 }],
        buildings: ['FISHER'],
        probability: 1
    }
});
// CONCATENATED MODULE: ./src/config/buildings.js
/* harmony default export */ var buildings = ({
    FISHER: {
        title: 'рыбацкая хижина',
        produce: 'FISH',
        requirements: [[{ type: 'WOOD', amount: 5 }], [{ type: 'PLUNK', amount: 4 }, { type: 'STONE', amount: 2 }], [{ type: 'PLUNK', amount: 4 }, { type: 'STONE', amount: 3 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_fish_1'],
        convert: [],
        people: 1
    },

    FARM: {
        title: 'ферма',
        produce: 'WHEAT',
        requirements: [[{ type: 'WOOD', amount: 5 }, { type: 'STONE', amount: 7 }], [{ type: 'PLUNK', amount: 6 }, { type: 'STONE', amount: 9 }], [{ type: 'PLUNK', amount: 7 }, { type: 'STONE', amount: 12 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_farm_1'],
        convert: [],
        people: 1
    },

    HUNTER: {
        title: 'охотничий домик',
        produce: 'ANIMALS',
        requirements: [[{ type: 'WOOD', amount: 5 }], [{ type: 'PLUNK', amount: 7 }, { type: 'STONE', amount: 2 }], [{ type: 'PLUNK', amount: 9 }, { type: 'STONE', amount: 5 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_hunter_1'],
        convert: [],
        people: 1
    },

    FORGE: {
        title: 'кузница',
        produce: 'STEAL',
        requirements: [[{ type: 'WOOD', amount: 2 }, { type: 'STONE', amount: 15 }], [{ type: 'PLUNK', amount: 4 }, { type: 'STONE', amount: 15 }], [{ type: 'PLUNK', amount: 6 }, { type: 'STONE', amount: 15 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_forge_1'],
        convert: [{ type: 'IRON', amount: 1 }, { type: 'COAL', amount: 1 }],
        people: 1
    },

    SAWMILL: {
        title: 'лесопилка',
        produce: 'PLUNK',
        requirements: [[{ type: 'WOOD', amount: 10 }, { type: 'STONE', amount: 4 }], [{ type: 'WOOD', amount: 20 }, { type: 'STONE', amount: 8 }], [{ type: 'WOOD', amount: 30 }, { type: 'STONE', amount: 10 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_sawmill_1'],
        convert: [{ type: 'WOOD', amount: 1 }],
        people: 1
    },

    COAL: {
        title: 'угольная шахта',
        produce: 'COAL',
        requirements: [[{ type: 'WOOD', amount: 5 }, { type: 'STONE', amount: 5 }], [{ type: 'PLUNK', amount: 7 }, { type: 'STONE', amount: 7 }], [{ type: 'PLUNK', amount: 9 }, { type: 'STONE', amount: 9 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_coal_mine_1'],
        convert: [],
        people: 1
    },

    STEAL: {
        title: 'железная шахта',
        produce: 'IRON',
        requirements: [[{ type: 'WOOD', amount: 5 }, { type: 'STONE', amount: 5 }], [{ type: 'PLUNK', amount: 7 }, { type: 'STONE', amount: 7 }], [{ type: 'PLUNK', amount: 9 }, { type: 'STONE', amount: 9 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_iron_mine_1'],
        convert: [],
        people: 1
    },

    HOUSE: {
        title: 'жилой дом',
        produce: '',
        requirements: [[{ type: 'WOOD', amount: 5 }, { type: 'STONE', amount: 5 }], [{ type: 'PLUNK', amount: 4 }, { type: 'STONE', amount: 10 }], [{ type: 'PLUNK', amount: 8 }, { type: 'STONE', amount: 15 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_house_1'],
        convert: [],
        people: 0
    },

    MARKET: {
        title: 'рынок',
        produce: '',
        requirements: [[{ type: 'WOOD', amount: 10 }, { type: 'STONE', amount: 10 }]],
        images: ['b_market_1'],
        convert: [],
        people: 0
    },

    SCHOOL: {
        title: 'школа',
        produce: '',
        requirements: [[{ type: 'WOOD', amount: 10 }, { type: 'STONE', amount: 10 }], [{ type: 'PLUNK', amount: 20 }, { type: 'STONE', amount: 20 }], [{ type: 'PLUNK', amount: 30 }, { type: 'STONE', amount: 30 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_school_1'],
        convert: [],
        people: 0
    },

    FORESTER: {
        title: 'дом лесника',
        produce: 'WOOD',
        requirements: [[{ type: 'WOOD', amount: 5 }], [{ type: 'PLUNK', amount: 7 }, { type: 'STONE', amount: 2 }], [{ type: 'PLUNK', amount: 9 }, { type: 'STONE', amount: 4 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_forester_1'],
        convert: [],
        people: 1
    },

    QUARRY: {
        title: 'каменоломня',
        produce: 'STONE',
        requirements: [[{ type: 'WOOD', amount: 10 }], [{ type: 'PLUNK', amount: 12 }, { type: 'STONE', amount: 5 }], [{ type: 'PLUNK', amount: 14 }, { type: 'STONE', amount: 10 }, { type: 'STEAL', amount: 5 }]],
        images: ['b_stone_1'],
        convert: [],
        people: 1
    },

    WIN: {
        title: 'статуя победы',
        produce: '',
        requirements: [[{ type: 'STEAL', amount: 100 }, { type: 'PLUNK', amount: 100 }]],
        images: ['b_win_1'],
        convert: [],
        people: 0
    }
});
// CONCATENATED MODULE: ./src/config/resources.js
/* harmony default export */ var config_resources = ({
    ANIMALS: {
        title: 'мясо',
        icon: 'i_animals',
        market: true
    },

    WOOD: {
        title: 'дерево',
        icon: 'i_wood',
        market: true
    },

    FISH: {
        title: 'рыба',
        icon: 'i_fish',
        market: true
    },

    STONE: {
        title: 'камень',
        icon: 'i_stone',
        market: true
    },

    WHEAT: {
        title: 'пшеница',
        icon: 'i_wheat',
        market: true
    },

    IRON: {
        title: 'железо',
        icon: 'i_iron',
        market: true
    },

    STEAL: {
        title: 'сталь',
        icon: 'i_steal',
        market: true
    },

    PLUNK: {
        title: 'доски',
        icon: 'i_plunk',
        market: true
    },

    COAL: {
        title: 'уголь',
        icon: 'i_coal',
        market: true
    },

    PEOPLE: {
        title: 'люди',
        icon: 'i_people',
        market: false
    },

    LEVEL: {
        title: 'уровень',
        icon: 'i_level',
        market: false
    }
});
// CONCATENATED MODULE: ./src/config/images.js
/* harmony default export */ var config_images = ([{ type: 'image', name: 'grass', path: 'img/grass.png' }, { type: 'image', name: 'trees', path: 'img/trees.png' }, { type: 'image', name: 'water', path: 'img/water.png' }, { type: 'image', name: 'mountains', path: 'img/mountains.png' }, { type: 'image', name: 'i_animals', path: 'img/i_animals.png' }, { type: 'image', name: 'i_wood', path: 'img/i_wood.png' }, { type: 'image', name: 'i_fish', path: 'img/i_fish.png' }, { type: 'image', name: 'i_stone', path: 'img/i_stone.png' }, { type: 'image', name: 'i_wheat', path: 'img/i_wheat.png' }, { type: 'image', name: 'i_iron', path: 'img/i_iron.png' }, { type: 'image', name: 'i_coal', path: 'img/i_coal.png' }, { type: 'image', name: 'i_people', path: 'img/i_people.png' }, { type: 'image', name: 'i_steal', path: 'img/i_steal.png' }, { type: 'image', name: 'i_plunk', path: 'img/i_plunk2.png' }, { type: 'image', name: 'i_level', path: 'img/i_level.png' }, { type: 'image', name: 'b_fish_1', path: 'img/b_fish_1.png' }, { type: 'image', name: 'b_farm_1', path: 'img/b_farm_1.png' }, { type: 'image', name: 'b_hunter_1', path: 'img/b_hunter_1.png' }, { type: 'image', name: 'b_forge_1', path: 'img/b_forge_1.png' }, { type: 'image', name: 'b_sawmill_1', path: 'img/b_sawmill_1.png' }, { type: 'image', name: 'b_coal_mine_1', path: 'img/b_coal_mine_1.png' }, { type: 'image', name: 'b_iron_mine_1', path: 'img/b_iron_mine_1.png' }, { type: 'image', name: 'b_house_1', path: 'img/b_house_1.png' }, { type: 'image', name: 'b_market_1', path: 'img/b_market_1.png' }, { type: 'image', name: 'b_school_1', path: 'img/b_school_1.png' }, { type: 'image', name: 'b_forester_1', path: 'img/b_forester_1.png' }, { type: 'image', name: 'b_stone_1', path: 'img/b_stone_1.png' }, { type: 'image', name: 'b_win_1', path: 'img/b_win_1.png' }]);
// CONCATENATED MODULE: ./src/config/index.js





/* harmony default export */ var src_config = ({
    areas: config_areas,
    buildings: buildings,
    resources: config_resources,
    images: config_images
});
// CONCATENATED MODULE: ./src/world/world-angle.js
let slowBefore = 100;
let defaultSpeed = 20;

let angle = 0;
let dest = 0;

const normalize = val => {
    let result = val % 360;
    if (result < 0) result = 360 + result;
    return result;
};

const world_angle_to = val => {
    dest = val;
};

const world_angle_get = () => normalize(angle);

const update = dt => {
    const dif = Math.abs(dest - angle);
    if (dif < .1) return;

    let speed = Math.sign(dest - angle) * defaultSpeed;
    if (dif < slowBefore) {
        // const easeOut = progress => Math.pow(--progress, 5) + 1
        const k = dif / slowBefore * 2;
        speed = speed * k;
    }

    const normalized_dt = dt / 100;
    angle += speed * normalized_dt;
    angle = angle;
};

const inc = (val = 10) => {
    dest = angle + val;
};

const setOptions = (speed, distanceBeforeSlow) => {
    defaultSpeed = speed;
    slowBefore = distanceBeforeSlow;
};

/* harmony default export */ var world_angle = ({
    update,
    to: world_angle_to,
    get: world_angle_get,
    inc,
    setOptions
});
// CONCATENATED MODULE: ./src/world/index.js




const CANVAS_WIDTH = 1920;
const CANVAS_HEIGHT = 720;

const GRADUS = Math.PI / 180;

const hypot = Math.hypot || ((a, b) => Math.sqrt(a * a + b * b));

class world_World {
    constructor() {
        this.units = [];
        this.angle = world_angle;

        this.RADIUS = 4000;
        this.CENTER_X = CANVAS_WIDTH / 2;
        this.CENTER_Y = this.RADIUS + 200;

        this.hoveredSector = null;
        this.selectedSector = null;
        this.drawAreasWithResources = false;

        this.areas = [];
    }

    draw(ctx) {
        ctx.fillStyle = 'rgb(210, 234, 252)';
        ctx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);

        // rotate
        ctx.translate(this.CENTER_X, this.CENTER_Y);
        ctx.rotate(this.angle.get() * GRADUS);
        ctx.translate(-this.CENTER_X, -this.CENTER_Y);

        // horizont
        ctx.fillStyle = '#fff';
        ctx.beginPath();
        ctx.arc(this.CENTER_X, this.CENTER_Y, this.RADIUS, 0, 2 * Math.PI);
        ctx.stroke();
        ctx.fill();

        // draw areas and buildings
        const sectorsCount = this.areas.length;
        const rotationAngle = 180 / sectorsCount * GRADUS * 2;
        this.areas.forEach((area, i) => {
            ctx.save();

            ctx.translate(this.CENTER_X, this.CENTER_Y);
            ctx.rotate(rotationAngle * i);
            ctx.translate(-this.CENTER_X, -this.CENTER_Y);

            ctx.translate(this.CENTER_X, this.CENTER_Y - this.RADIUS);

            area.draw(ctx, this.drawAreasWithResources);

            if (this.hoveredSector === i) {
                ctx.fillStyle = 'rgba(210, 234, 252, .5)';
                ctx.fillRect(-70, -60, 140, 61);
            }

            if (this.selectedSector === i) {
                ctx.fillStyle = 'rgba(210, 234, 252, .5)';
                ctx.fillRect(-70, -60, 140, 61);
            }

            ctx.restore();
        });

        // restore
        ctx.resetTransform();
    }

    update(dt) {
        this.angle.update(dt);
        this.areas.forEach(area => {
            area.update(dt);
        });
    }

    hoverSector(sector) {
        this.hoveredSector = sector;
    }

    hoverObject(_x, _y) {
        const x = _x - this.CENTER_X;
        const y = _y - this.CENTER_Y;

        const distance = hypot(x, y);

        const between = (val, min, max) => val >= min && val <= max;
        if (between(distance - this.RADIUS, -40, 100)) {
            const sectorLength = 360 / this.areas.length;
            let angle = Math.atan2(x, -y) * 180 / Math.PI + sectorLength / 2;

            angle = angle - this.angle.get();
            angle = angle % 360;
            if (angle < 0) angle = 360 + angle;

            this.hoveredSector = ~~(angle / sectorLength);
        } else {
            this.hoveredSector = null;
        }
    }

    loadNew(count) {

        const PROBABILITY_OF_OCCURRENCE = {
            'FIELD': 50,
            'FOREST': 20,
            'MOUNTAINS': 20,
            'WATER': 10
        };

        this.areas = [];

        for (let i = 0; i < count; i++) {
            const rand = Math.random() * 100;

            let probability = 0;
            for (let type in PROBABILITY_OF_OCCURRENCE) {
                probability += PROBABILITY_OF_OCCURRENCE[type];
                if (rand < probability) {
                    this.areas.push(app.makeArea(type));
                    break;
                }
            }
        }
    }
}
// CONCATENATED MODULE: ./src/app/helpers.js




const drawResourcesItems = (ctx, items, x, y) => {
    ctx.fillStyle = '#000';
    ctx.font = '16px Lato';
    items.forEach((item, i) => {
        const offset_y = i * 35;

        ctx.textAlign = 'right';
        ctx.fillText(item.value, x, y + 10 + offset_y);

        ctx.drawImage(item.icon, x + 10, y + offset_y, 20, 20);

        ctx.textAlign = 'left';
        ctx.fillText(item.label, x + 40, y + 10 + offset_y);
    });
};

const drawResource = (ctx, type, x, y) => {
    const icon = src_config.resources[type].icon;
    const img = cgt_resources.get(icon);
    ctx.drawImage(img, x, y, 20, 20);
};

const makeResourceItem = (type, min, max = null) => {
    const value = max ? Math.max(0, (Math.random() * (max - min) + min).toFixed()) : min;
    const res = src_config.resources[type];
    return {
        type,
        value,
        icon: cgt_resources.get(res.icon),
        label: res.title
    };
};

const isMetRequirements = (player, neededResources, level = 0) => {
    const playerLevel = player.getResource('LEVEL').value;
    if (playerLevel < level) return false;

    const availableResources = player.getResources();
    const ok = neededResources.every(item => {
        const playerResource = availableResources.find(res => item.type === res.type);
        const playerResourceAmount = playerResource ? playerResource.value : 0;
        return item.amount <= playerResourceAmount;
    });

    return ok;
};

const processTact = (player, areas) => {
    const hasPlayerBuilding = area => area.getBuilding() && area.buildingOwner === player;
    const areasWithBuildings = areas.filter(hasPlayerBuilding);

    const places = areasWithBuildings.reduce((result, area) => {
        const building = area.getBuilding();
        if (building.type === 'HOUSE') {
            if (building.level === 0) result += 3;else if (building.level === 1) result += 6;else if (building.level === 2) result += 9;
        }
        return result;
    }, 0);

    const resourcesCount = player.getResources().reduce((result, res) => {
        if (['FISH', 'ANIMALS', 'WHEAT'].indexOf(res.type)) {
            result += res.value;
        }
        return result;
    }, 0);

    const peopleCount = Math.max(3, Math.min(places, resourcesCount / 2));

    const peopleNeed = areasWithBuildings.reduce((result, area) => result + area.building.config.people, 0);
    player.setResourceAmount('PEOPLE', peopleCount - peopleNeed);

    let resToEat = peopleCount * 2;
    player.getResources().slice(0).sort((a, b) => a.value === b.value ? 0 : a.value > b.value ? 1 : -1).forEach(res => {
        if (['FISH', 'ANIMALS', 'WHEAT'].indexOf(res.type) >= 0) {
            const eat = Math.min(resToEat, res.value);
            resToEat -= eat;
            player.setResourceAmount(res.type, res.value - eat);
        }
    });

    areasWithBuildings.sort(() => Math.random() - 0.5).slice(0, peopleCount).forEach(area => {
        const building = area.getBuilding();

        const multiplier = building.level == 0 ? 1 : building == 1 ? 2 : 3;

        const convert = building.config.convert;
        if (convert && convert.length) {
            if (isMetRequirements(player, convert)) {
                player.increaseResources(convert, -1);
                player.increaseResources([{
                    type: building.config.produce,
                    amount: multiplier
                }]);
            }
        } else {
            const resForIncrease = area.resources.filter(item => item.type === building.config.produce).map(item => {
                return {
                    type: item.type,
                    amount: item.value * multiplier
                };
            });
            player.increaseResources(resForIncrease);
        }
    });
};

let steps = ['FORESTER', 'QUARRY', 'FARM', 'HOUSE', 'HOUSE', 'FISHER', 'FORESTER', 'QUARRY', 'FISHER', 'STEAL', 'COAL', 'SAWMILL', 'FISHER', 'FORGE', 'SAWMILL', 'FORGE', 'WIN'];
const scriptBot = bot => {
    const step = steps[0];

    if (!isMetRequirements(bot, app.Config.buildings[step].requirements[0])) {
        return false;
    }

    const areas = app.getWorld().areas.filter(area => {
        return !area.getBuilding() && area.avalilableBuildings.indexOf(step) >= 0;
    });

    if (!areas.length) {
        steps.shift();
        return false;
    }

    const area = areas[Math.floor(Math.random() * areas.length)];

    area.build(step, bot);
    steps.shift();

    return step === 'WIN';
};

/* harmony default export */ var helpers = ({
    drawResourcesItems,
    makeResourceItem,
    isMetRequirements,
    drawResource,
    processTact,
    scriptBot
});
// CONCATENATED MODULE: ./src/app/building.js



class building_Building {
    constructor(type) {
        this.config = buildings[type];
        this.level = 0;
        this.type = type;

        const imageData = this.config.images[this.level];
        this.image = {
            img: cgt_resources.get(imageData),
            x: -70,
            y: -70,
            w: 140,
            h: 70
        };
    }

    draw(ctx) {
        ctx.drawImage(this.image.img, this.image.x, this.image.y, this.image.w, this.image.h);
    }

    update() {}
}
// CONCATENATED MODULE: ./src/app/area.js






class area_Area {
    constructor(data) {
        this.title = data.title;
        this.images = data.images.map(item => {
            return {
                img: cgt_resources.get(item.src),
                x: -70,
                y: item.y,
                w: 140,
                h: item.h
            };
        });
        this.resources = data.resources.map(item => makeResourceItem(item.type, item.min, item.max)).filter(item => item.value > 0);

        this.avalilableBuildings = data.buildings;

        this.building = null;
        this.buildingOwner = null;
    }

    update() {}

    draw(ctx, withResources = true) {
        this.images.forEach(item => {
            ctx.drawImage(item.img, item.x, item.y, item.w, item.h);
        });

        let produce = null;
        let ownerColor = '';

        if (this.building) {
            this.building.draw(ctx);
            produce = this.building.config.produce;
            ownerColor = this.buildingOwner === app.Player ? 'green' : 'red';

            ctx.beginPath();
            ctx.fillStyle = ownerColor;
            ctx.arc(0, 10, 2, 0, 2 * Math.PI);
            ctx.fill();
        }

        if (withResources) {
            this.resources.forEach((item, i) => {
                const offset_y = i * 25 + 10;

                ctx.drawImage(item.icon, -20, 10 + offset_y, 20, 20);

                ctx.fillStyle = '#000';
                ctx.font = '16px Lato';
                ctx.textAlign = 'left';
                ctx.fillText(item.value, 10, 20 + offset_y);

                if (produce === item.type) {
                    ctx.strokeStyle = ownerColor;
                    ctx.strokeRect(-60, offset_y + 7, 120, 26);
                }
            });
        }
    }

    info() {
        return {
            title: this.title,
            resources: this.resources
        };
    }

    getBuilding() {
        return this.building;
    }

    removeBuilding() {
        this.building = null;
    }

    upgradeBuilding() {
        this.building.level++;
    }

    getAvalilableBuildings() {
        return this.avalilableBuildings;
    }

    build(type, owner) {
        this.building = new building_Building(type);
        this.buildingOwner = owner;
    }
}
// CONCATENATED MODULE: ./src/app/market.js



let offers = [];

const market_update = () => {
    const items = Object.keys(config_resources).filter(item => config_resources[item].market).sort(() => Math.random() - 0.5).slice(0, 6);

    const from = [items[0], items[1], items[2]];
    const to = [items[3], items[4], items[5]];

    offers = from.map((_, i) => {
        return {
            id: i,
            from: makeResourceItem(from[i], 50, 150),
            to: makeResourceItem(to[i], 50, 150)
        };
    });
};

const removeOffer = id => {
    offers = offers.filter(item => item.id !== id);
};

const market_get = () => offers;

/* harmony default export */ var app_market = ({
    update: market_update,
    get: market_get,
    removeOffer
});
// CONCATENATED MODULE: ./src/app/player.js



class player_Unit {
    init() {
        const defaults = {
            'WOOD': 10,
            'STONE': 10,
            'PEOPLE': 3
        };
        this.resources = Object.keys(config_resources).map(item => makeResourceItem(item, defaults[item] || 0));
    }

    getResources() {
        return this.resources;
    }

    getResource(key) {
        return this.resources.find(item => item.type === key);
    }

    getResourceIndex(key) {
        return this.resources.findIndex(item => item.type === key);
    }

    setResourceAmount(type, val) {
        this.resources.forEach((item, i) => {
            if (item.type === type) {
                this.resources[i].value = val;
            }
        });
    }

    increaseResources(requirements, k = 1) {
        requirements.forEach(req => {
            const resId = this.getResourceIndex(req.type);
            if (resId < 0) return;

            this.resources[resId].value += req.amount * k;
        });
    }
}

const Player = new player_Unit();
const Bot = new player_Unit();

/* harmony default export */ var player = ({
    Player,
    Bot
});
// CONCATENATED MODULE: ./src/app/index.js










const app_start = () => {
    Player.init();
    Bot.init();

    cgt.start(src_scenes(), {
        keepaspectratio: true,
        init: ctx => {
            ctx.imageSmoothingEnabled = true;
            ctx.imageSmoothingQuality = 'high';
        }
    });
};

const makeArea = type => new area_Area(src_config.areas[type]);

const getBuildingInfo = type => src_config.buildings[type];

let world = null;
const getWorld = createNew => {
    if (!world || createNew) {
        world = new world_World();
    }
    return world;
};

/* harmony default export */ var app = ({
    CGT: cgt,
    Resources: cgt_resources,
    Config: src_config,
    Helpers: helpers,
    Market: app_market,

    Player: Player,
    Bot: Bot,

    start: app_start,
    makeArea,

    getBuildingInfo,
    getWorld
});
// CONCATENATED MODULE: ./src/main.js


app.Resources.loadAll(app.Config.images).then(app.start);

/***/ })
/******/ ]);