define("wolfrunComponentsSpaghetti", ["viewBuilderApi", "componentmodelComponentApi", "clientkernelLoaderApi", "slotModelApi", "displayEngineApi", "clientkernelTestableApi", "displayEngineUtils", "gameLayoutApi", "clientkernelEventbusApi", "clientkernelModulesApi", "wolfRunSpaghettiPort", "wolfRunSpaghettiDeclaration"],
    function(viewBuilderApi, componentmodelComponentApi, clientkernelLoaderApi, slotModelApi, displayEngineApi, clientkernelTestableApi, displayEngineUtils, gameLayoutApi, clientkernelEventbusApi, clientkernelModulesApi, wolfRunSpaghettiPort, wolfRunSpaghettiDeclaration) {
        "use strict";

        function $iterator(o) {
            if (o instanceof Array) return function() {
                return {
                    cur: 0,
                    arr: o,
                    hasNext: function() {
                        return this.cur < this.arr.length;
                    },
                    next: function() {
                        return this.arr[this.cur++];
                    }
                };
            };
            return typeof(o.iterator) == 'function' ? $bind(o, o.iterator) : o.iterator;
        };;
        var $fid = 0;

        function $bind(o, m) {
            if (m == null) return null;
            if (m.__id__ == null) m.__id__ = $fid++;
            var f;
            if (o.hx__closures__ == null) o.hx__closures__ = {};
            else f = o.hx__closures__[m.__id__];
            if (f == null) {
                f = function() {
                    return f.method.apply(f.scope, arguments);
                };
                f.scope = o;
                f.method = m;
                o.hx__closures__[m.__id__] = f;
            }
            return f;
        };
        var $_;
        var $estr = function() {
            return _hcmn_.js_Boot.__string_rec(this, '');
        };
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

        haxe.IMap = function() {}
        haxe.IMap.prototype = {

            get: function(k) {
                return {
                    arguments: ["*"],
                    returns: "null"
                };
            },
            keys: function() {
                return {
                    arguments: [],
                    returns: "null"
                };
            }
        };
        if (typeof js == 'undefined') {
            var js = {};
        };
        if (!js._Boot) {
            js._Boot = {};
        };
        js._Boot.HaxeError = function(val) {
            Error.call(this);
            this.val = val;
            this.message = String(val);
            if (Error.captureStackTrace) Error.captureStackTrace(this, js._Boot.HaxeError);
        };
        js._Boot.HaxeError.__name__ = ["js", "_Boot", "HaxeError"];
        js._Boot.HaxeError.__super__ = Error;
        for (var k in Error.prototype) js._Boot.HaxeError.prototype[k] = Error.prototype[k];
        js._Boot.HaxeError.prototype.val = null;
        js._Boot.HaxeError.prototype.__class__ = js._Boot.HaxeError;
        if (typeof wolfrunComponentsSpaghetti == 'undefined') {
            var wolfrunComponentsSpaghetti = {};
        };
        wolfrunComponentsSpaghetti.Activator = function(context) {};
        wolfrunComponentsSpaghetti.Activator = ck_implements(wolfrunComponentsSpaghetti.Activator, clientkernelModulesApi.IModuleActivator);
        wolfrunComponentsSpaghetti.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        wolfrunComponentsSpaghetti.Activator.__name__ = ["wolfrunComponentsSpaghetti", "Activator"];
        wolfrunComponentsSpaghetti.Activator.prototype.start = function(context) {
            context.getServiceTracker([displayEngineApi.IDisplayProvider, clientkernelTestableApi.ITestable, viewBuilderApi.IViewBuilderFactory]).then(function(context1) {
                var factory = context1.getAnyService(viewBuilderApi.IViewBuilderFactory, null);
                wolfrunComponentsSpaghetti.ExternalService.initialize(context1, factory);
                context1.registerService(new wolfrunComponentsSpaghetti.SpaghettiFactory(context1), wolfRunSpaghettiDeclaration.SpaghettiDeclaration, null);
            });
        };
        wolfrunComponentsSpaghetti.Activator.prototype.stop = function(context) {};
        wolfrunComponentsSpaghetti.Activator.main = function() {};
        wolfrunComponentsSpaghetti.Activator.prototype.__class__ = wolfrunComponentsSpaghetti.Activator;
        wolfrunComponentsSpaghetti.ExternalService = function() {};
        wolfrunComponentsSpaghetti.ExternalService.__name__ = ["wolfrunComponentsSpaghetti", "ExternalService"];
        wolfrunComponentsSpaghetti.ExternalService.displayProvider = null;
        wolfrunComponentsSpaghetti.ExternalService.assetRegistry = null;
        wolfrunComponentsSpaghetti.ExternalService.viewBuilderFactory = null;
        wolfrunComponentsSpaghetti.ExternalService.loadedAssets = null;
        wolfrunComponentsSpaghetti.ExternalService.loadedDefinitionConfig = null;
        wolfrunComponentsSpaghetti.ExternalService._moduleContext = null;
        wolfrunComponentsSpaghetti.ExternalService.initialize = function(context, vbf) {
            wolfrunComponentsSpaghetti.ExternalService.displayProvider = context.getAnyService(displayEngineApi.IDisplayProvider, null);
            wolfrunComponentsSpaghetti.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
            wolfrunComponentsSpaghetti.ExternalService.viewBuilderFactory = vbf;
            wolfrunComponentsSpaghetti.ExternalService._moduleContext = context;
        };
        wolfrunComponentsSpaghetti.ExternalService.prototype.__class__ = wolfrunComponentsSpaghetti.ExternalService;
        wolfrunComponentsSpaghetti.Spaghetti = function(context) {
            this.assetsLoaded = false;
            this.initialized = false;
            this.layoutPayload = null;
            this.MAIN_CONFIG_ID = "spaghetti-assets/spaghetti_config_json";
            this.TABS_COMPONENT_ID = "TABS";
            this.LINES_COMPONENT_ID = "LINES";
            var _g = this;
            this.context = context;
            this.spaghettiPort = context.getImplementedPort(wolfRunSpaghettiPort.ISpaghettiImplementationPort);
            this.layoutPort = context.getUsedPort(gameLayoutApi.IGameLayoutPort);
            this.layoutPort.getUpdateComponentLayout().subscribe($bind(this, this.updateLayout));
            this.controller = new wolfrunComponentsSpaghetti.SpaghettiController(this);
            wolfrunComponentsSpaghetti.ExternalService.assetRegistry.getAsset(this.MAIN_CONFIG_ID).getContent().then(function(vb) {
                wolfrunComponentsSpaghetti.ExternalService.loadedAssets = vb;
                _g.assetsLoaded = true;
                _g.initialize();
            });
        };
        wolfrunComponentsSpaghetti.Spaghetti.__name__ = ["wolfrunComponentsSpaghetti", "Spaghetti"];
        wolfrunComponentsSpaghetti.Spaghetti.prototype.LINES_COMPONENT_ID = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.TABS_COMPONENT_ID = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.MAIN_CONFIG_ID = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.view = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.spaghettiPort = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.layoutPort = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.spaghettiComponent = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.context = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.controller = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.layoutPayload = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.initialized = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.assetsLoaded = null;
        wolfrunComponentsSpaghetti.Spaghetti.prototype.updateLayout = function(e) {
            this.layoutPayload = e.getPayload();
            if (!this.initialized) this.initialize();
            else {
                this.controller.updateLayout(this.layoutPayload);
                this.layoutPort.getComponentLayoutUpdated().publish(this.context.getInstance());
            }
        };
        wolfrunComponentsSpaghetti.Spaghetti.prototype.initialize = function() {
            if (this.assetsLoaded && this.layoutPayload != null) {
                this.view = wolfrunComponentsSpaghetti.ExternalService.viewBuilderFactory.createView(wolfrunComponentsSpaghetti.ExternalService.loadedAssets);
                var linesContainer = this.view.getComponentById(this.LINES_COMPONENT_ID);
                var tabsContainer = this.view.getComponentById(this.TABS_COMPONENT_ID);
                this.spaghettiComponent = new wolfrunComponentsSpaghetti.SpaghettiComponent(linesContainer, tabsContainer);
                this.controller.init();
                this.controller.updateLayout(this.layoutPayload);
                this.layoutPort.getComponentLayoutUpdated().publish(this.context.getInstance());
                this.initialized = true;
            }
        };
        wolfrunComponentsSpaghetti.Spaghetti.prototype.getSpaghettiComponent = function() {
            return this.spaghettiComponent;
        };
        wolfrunComponentsSpaghetti.Spaghetti.prototype.__class__ = wolfrunComponentsSpaghetti.Spaghetti;
        wolfrunComponentsSpaghetti.SpaghettiFactory = function(context) {
            this.context = context;
        };
        wolfrunComponentsSpaghetti.SpaghettiFactory = ck_implements(wolfrunComponentsSpaghetti.SpaghettiFactory, clientkernelModulesApi.IService);
        wolfrunComponentsSpaghetti.SpaghettiFactory = ck_implements(wolfrunComponentsSpaghetti.SpaghettiFactory, componentmodelComponentApi.IComponentFactory);
        wolfrunComponentsSpaghetti.SpaghettiFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        wolfrunComponentsSpaghetti.SpaghettiFactory.__name__ = ["wolfrunComponentsSpaghetti", "SpaghettiFactory"];
        wolfrunComponentsSpaghetti.SpaghettiFactory.prototype.context = null;
        wolfrunComponentsSpaghetti.SpaghettiFactory.prototype.getComponentDeclaration = function() {
            return wolfRunSpaghettiDeclaration.SpaghettiDeclaration;
        };
        wolfrunComponentsSpaghetti.SpaghettiFactory.prototype.createComponent = function(context) {
            new wolfrunComponentsSpaghetti.Spaghetti(context);
        };
        wolfrunComponentsSpaghetti.SpaghettiFactory.prototype.__class__ = wolfrunComponentsSpaghetti.SpaghettiFactory;

        wolfrunComponentsSpaghetti.ISpaghettiComponent = function() {}
        wolfrunComponentsSpaghetti.ISpaghettiComponent.prototype = {

            showLinesById: function(ids) {
                return {
                    arguments: ["array"],
                    returns: "void"
                };
            },
            showSelectedLines: function(quantity) {
                return {
                    arguments: ["number"],
                    returns: "void"
                };
            },
            showSelectedTabs: function(quantity) {
                return {
                    arguments: ["number"],
                    returns: "void"
                };
            },
            hideLines: function() {
                return {
                    arguments: [],
                    returns: "void"
                };
            },
            setVisible: function(val) {
                return {
                    arguments: ["boolean"],
                    returns: "void"
                };
            },
            configure: function(cfg) {
                return {
                    arguments: ["*"],
                    returns: "void"
                };
            }
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent = function(linesContainer, tabsContainer) {
            this.isVisible = true;
            this.FADE_DELAY = 3000;
            this.FADE_DURATION = 1000;
            this.TAB = "tab";
            this.LINE = "line";
            this.SCATTER_WIN_ID = -1;
            this.PAYLINES_QUANTITY = 40;
            this.linesContainer = linesContainer;
            this.tabsContainer = tabsContainer;
            this.enabledTabsContainer = tabsContainer.getContainerById("enabled");
            this.disabledTabsContainer = tabsContainer.getContainerById("disabled");
            this.initialize();
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent = ck_implements(wolfrunComponentsSpaghetti.SpaghettiComponent, wolfrunComponentsSpaghetti.ISpaghettiComponent);
        wolfrunComponentsSpaghetti.SpaghettiComponent.__interfaces__ = [wolfrunComponentsSpaghetti.ISpaghettiComponent];
        wolfrunComponentsSpaghetti.SpaghettiComponent.__name__ = ["wolfrunComponentsSpaghetti", "SpaghettiComponent"];
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.PAYLINES_QUANTITY = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.SCATTER_WIN_ID = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.LINE = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.TAB = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.FADE_DURATION = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.FADE_DELAY = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.fadeTween = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.linesContainer = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.tabsContainer = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.enabledTabsContainer = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.disabledTabsContainer = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.lines = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.tabs = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.isVisible = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.currentIds = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.currentIdsStr = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.shownIdsStr = null;
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.initialize = function() {
            var _g = [];
            var _g2 = 0;
            var _g1 = this.PAYLINES_QUANTITY;
            while (_g2 < _g1) {
                var i = _g2++;
                _g.push(null);
            }
            this.lines = _g;
            var _g11 = [];
            var _g3 = 0;
            var _g21 = this.PAYLINES_QUANTITY;
            while (_g3 < _g21) {
                var i1 = _g3++;
                _g11.push(null);
            }
            this.tabs = _g11;
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.linesContainer.getChildComponents();
                $r = this1.keys();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var line = $it0.next();
                var index = _hcmn_.Std.parseInt(_hcmn_.StringTools.replace(line, this.LINE, ""));
                this.lines[index] = _hcmn_.js_Boot.__cast((function($this) {
                    var $r;
                    var this2 = $this.linesContainer.getChildComponents();
                    $r = this2.get(line);
                    return $r;
                }(this)), viewBuilderApi.IViewBuilderComponent);
            }
            var $it1 = (function($this) {
                var $r;
                var this3 = $this.enabledTabsContainer.getChildComponents();
                $r = this3.keys();
                return $r;
            }(this));
            while ($it1.hasNext()) {
                var tab = $it1.next();
                var index1 = _hcmn_.Std.parseInt(_hcmn_.StringTools.replace(tab, this.TAB, ""));
                this.tabs[index1] = _hcmn_.js_Boot.__cast((function($this) {
                    var $r;
                    var this4 = $this.enabledTabsContainer.getChildComponents();
                    $r = this4.get(tab);
                    return $r;
                }(this)), viewBuilderApi.IViewBuilderComponent);
            }
            this.disabledTabsContainer.show();
            this.disabledTabsContainer.getDisplayObject().setCacheAsBitmap(true);
            this.hideLines();
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.showLinesById = function(ids) {
            this.currentIds = ids;
            this.currentIdsStr = ids.toString();
            if (!this.isVisible) return;
            this.linesContainer.getDisplayObject().setCacheAsBitmap(false);
            this.resetTween();
            this.hideLines();
            var _g = 0;
            while (_g < ids.length) {
                var id = ids[_g];
                ++_g;
                if (id != this.SCATTER_WIN_ID) {
                    this.lines[id].show();
                    this.tabs[id].show();
                }
            }
            this.linesContainer.getDisplayObject().setCacheAsBitmap(true);
            this.shownIdsStr = this.currentIdsStr;
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.showSelectedLines = function(quantity) {
            this.resetCurrentLineIds();
            this.linesContainer.getDisplayObject().setCacheAsBitmap(false);
            this.resetTween();
            var _g1 = 0;
            var _g = this.PAYLINES_QUANTITY;
            while (_g1 < _g) {
                var i = _g1++;
                if (i < quantity) {
                    this.lines[i].show();
                    this.currentIds.push(i);
                } else this.lines[i].hide();
            }
            this.currentIdsStr = this.currentIds.toString();
            this.fadeTween = displayEngineUtils.TweenX.to(this.linesContainer.getDisplayObject(), {
                alpha: 0
            }, this.FADE_DURATION, displayEngineUtils.EaseX.linear, this.FADE_DELAY, null, null, null, null, null, {
                fileName: "SpaghettiComponent.hx",
                lineNumber: 103,
                className: "wolfrun.components.spaghetti.component.SpaghettiComponent",
                methodName: "showSelectedLines"
            });
            this.linesContainer.getDisplayObject().setCacheAsBitmap(true);
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.resetTween = function() {
            if (this.fadeTween != null) {
                this.fadeTween["goto"](0, false);
                this.fadeTween.stop();
                this.fadeTween = null;
            }
            this.linesContainer.getDisplayObject().setAlpha(1);
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.showSelectedTabs = function(quantity) {
            this.enabledTabsContainer.getDisplayObject().setCacheAsBitmap(false);
            var _g1 = 0;
            var _g = this.PAYLINES_QUANTITY;
            while (_g1 < _g) {
                var i = _g1++;
                if (i < quantity) this.tabs[i].show();
                else this.tabs[i].hide();
            }
            this.enabledTabsContainer.getDisplayObject().setCacheAsBitmap(true);
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.hideLines = function() {
            this.linesContainer.getDisplayObject().setCacheAsBitmap(false);
            this.enabledTabsContainer.getDisplayObject().setCacheAsBitmap(false);
            var _g1 = 0;
            var _g = this.PAYLINES_QUANTITY;
            while (_g1 < _g) {
                var i = _g1++;
                this.lines[i].hide();
                this.tabs[i].hide();
            }
            this.resetCurrentLineIds();
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.setVisible = function(val) {
            this.isVisible = val;
            if (val) {
                if (this.currentIdsStr != this.shownIdsStr) this.showLinesById(this.currentIds);
                this.linesContainer.show();
                this.tabsContainer.show();
            } else {
                this.linesContainer.hide();
                this.tabsContainer.hide();
            }
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.configure = function(cfg) {};
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.resetCurrentLineIds = function() {
            this.shownIdsStr = "";
            this.currentIdsStr = "";
            this.currentIds = [];
        };
        wolfrunComponentsSpaghetti.SpaghettiComponent.prototype.__class__ = wolfrunComponentsSpaghetti.SpaghettiComponent;
        wolfrunComponentsSpaghetti.SpaghettiController = function(spaghetti) {
            this.spaghetti = spaghetti;
        };
        wolfrunComponentsSpaghetti.SpaghettiController.__name__ = ["wolfrunComponentsSpaghetti", "SpaghettiController"];
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.spaghetti = null;
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.init = function() {
            this.spaghetti.spaghettiPort.getShowLinesById().subscribe($bind(this, this.handleShowLinesById));
            this.spaghetti.spaghettiPort.getShowSelectedLines().subscribe($bind(this, this.handleShowSelectedLines));
            this.spaghetti.spaghettiPort.getShowSelectedTabs().subscribe($bind(this, this.handleShowSelectedTabs));
            this.spaghetti.spaghettiPort.getHideLines().subscribe($bind(this, this.handleHideLines));
            this.spaghetti.spaghettiPort.getVisible().subscribe($bind(this, this.handleSetVisible));
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.updateLayout = function(layoutPayload) {
            var $it0 = layoutPayload.containers.keys();
            while ($it0.hasNext()) {
                var layerId = $it0.next();
                var layerPayload = layoutPayload.containers.get(layerId);
                var cfg = layerPayload.configuration;
                var stage;
                var this1 = wolfrunComponentsSpaghetti.ExternalService.displayProvider.getStages();
                stage = this1.get(layerPayload.stage);
                var container = this.spaghetti.view.getComponentById(layerId).getDisplayObject();
                try {
                    stage.removeChild(container);
                } catch (e) {
                    if (e instanceof js._Boot.HaxeError) e = e.val;
                    if (_hcmn_.js_Boot.__instanceof(e, Error)) {} else throw (e);
                }
                stage.addChild(container);
                container.setX(layerPayload.left);
                container.setY(layerPayload.top);
                container.setScaleX(layerPayload.width / container.getUserData().viewBuilderW);
                container.setScaleY(layerPayload.height / container.getUserData().viewBuilderH);
                container.setZIndex(layerPayload.zIndex);
                if (cfg == null) continue;
                this.spaghetti.getSpaghettiComponent().configure(cfg);
            }
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.handleShowLinesById = function(e) {
            this.spaghetti.getSpaghettiComponent().showLinesById(e.getPayload());
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.handleShowSelectedLines = function(e) {
            this.spaghetti.getSpaghettiComponent().showSelectedLines(e.getPayload());
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.handleShowSelectedTabs = function(e) {
            this.spaghetti.getSpaghettiComponent().showSelectedTabs(e.getPayload());
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.handleHideLines = function(e) {
            this.spaghetti.getSpaghettiComponent().hideLines();
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.handleSetVisible = function(e) {
            this.spaghetti.getSpaghettiComponent().setVisible(e.getPayload());
        };
        wolfrunComponentsSpaghetti.SpaghettiController.prototype.__class__ = wolfrunComponentsSpaghetti.SpaghettiController;
        return {
            exports: wolfrunComponentsSpaghetti,
            activator: wolfrunComponentsSpaghetti.Activator
        };
    });
//# sourceURL=wolfRunSpaghetti.js