define("scarabTension", ["viewBuilderApi", "componentmodelComponentApi", "translationmanagerApi", "clientkernelLoaderApi", "displayEngineApi", "scarabTensionApi", "gameLayoutApi", "PIXI", "BABYLON", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(viewBuilderApi, componentmodelComponentApi, translationmanagerApi, clientkernelLoaderApi, displayEngineApi, scarabTensionApi, gameLayoutApi, PIXI, BABYLON, clientkernelEventbusApi, clientkernelModulesApi) {
        "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 scarabTension == 'undefined') {
            var scarabTension = {};
        };
        scarabTension.Activator = function(context) {};
        scarabTension.Activator = ck_implements(scarabTension.Activator, clientkernelModulesApi.IModuleActivator);
        scarabTension.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        scarabTension.Activator.__name__ = ["scarabTension", "Activator"];
        scarabTension.Activator.prototype.start = function(context) {
            context.getServiceTracker([viewBuilderApi.IViewBuilderFactory, clientkernelLoaderApi.IAssetRegistry, displayEngineApi.IDisplayProvider]).then(function(context1) {
                scarabTension.ExternalService.initialize(context1);
                var vbf = context1.getAnyService(viewBuilderApi.IViewBuilderFactory, null);
                scarabTension.ExternalService.viewBuilderFactory = vbf;
                context1.registerService(new scarabTension.TensionFactory(vbf, context1), scarabTensionApi.TensionDeclaration, null);
            });
        };
        scarabTension.Activator.prototype.stop = function(context) {};
        scarabTension.Activator.main = function() {};
        scarabTension.Activator.prototype.__class__ = scarabTension.Activator;
        scarabTension.ExternalService = function() {};
        scarabTension.ExternalService.__name__ = ["scarabTension", "ExternalService"];
        scarabTension.ExternalService.assetRegistry = null;
        scarabTension.ExternalService.vbf = null;
        scarabTension.ExternalService.displayProvider = null;
        scarabTension.ExternalService.translationManager = null;
        scarabTension.ExternalService.bus = null;
        scarabTension.ExternalService.viewBuilderFactory = null;
        scarabTension.ExternalService.assets = null;
        scarabTension.ExternalService.initialize = function(context) {
            scarabTension.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
            scarabTension.ExternalService.vbf = context.getAnyService(viewBuilderApi.IViewBuilderFactory, null);
            scarabTension.ExternalService.displayProvider = context.getAnyService(displayEngineApi.IDisplayProvider, null);
            scarabTension.ExternalService.assets = new _hcmn_.haxe_ds_StringMap();
        };
        scarabTension.ExternalService.prototype.__class__ = scarabTension.ExternalService;
        scarabTension.Tension = function(context, vbf) {
            this.assetsLoaded = false;
            this.initialized = false;
            this.layoutPayload = null;
            this.vba = null;
            this.vbAssetID = "tension.viewbuilder.json";
            this.cfgId = "tension_definition_config.json";
            this.vbf = vbf;
            this.context = context;
            this.port = context.getImplementedPort(scarabTensionApi.ITensionImplementationPort);
            this.layoutPort = context.getUsedPort(gameLayoutApi.IGameLayoutPort);
            this.layoutPort.getUpdateComponentLayout().subscribe($bind(this, this.updateLayout));
            haxe.Log.trace("[TENSION] loadConfigData() ", {
                fileName: "Tension.hx",
                lineNumber: 52,
                className: "game.tension.Tension",
                methodName: "new"
            });
            this.loadConfigData();
        };
        scarabTension.Tension.__name__ = ["scarabTension", "Tension"];
        scarabTension.Tension.prototype.cfgId = null;
        scarabTension.Tension.prototype.vbAssetID = null;
        scarabTension.Tension.prototype.view = null;
        scarabTension.Tension.prototype.vba = null;
        scarabTension.Tension.prototype.context = null;
        scarabTension.Tension.prototype.vbf = null;
        scarabTension.Tension.prototype.controller = null;
        scarabTension.Tension.prototype.layoutPayload = null;
        scarabTension.Tension.prototype.initialized = null;
        scarabTension.Tension.prototype.assetsLoaded = null;
        scarabTension.Tension.prototype.port = null;
        scarabTension.Tension.prototype.layoutPort = null;
        scarabTension.Tension.prototype.cfg = null;
        scarabTension.Tension.prototype.tensionFrame = null;
        scarabTension.Tension.prototype.wildTension = null;
        scarabTension.Tension.prototype.loadConfigData = function() {
            var _g = this;
            scarabTension.ExternalService.assetRegistry.getAsset(this.cfgId).getContent().then(function(data) {
                _g.cfg = data;
                haxe.Log.trace("[TENSION] loadConfigData() ", {
                    fileName: "Tension.hx",
                    lineNumber: 62,
                    className: "game.tension.Tension",
                    methodName: "loadConfigData",
                    customParams: [_g.cfg]
                });
                _g.loadVBAssets();
            });
        };
        scarabTension.Tension.prototype.loadVBAssets = function() {
            var _g = this;
            haxe.Log.trace("[TENSION] loadVBAssets() " + _hcmn_.Std.string(this.cfg.vbAssets), {
                fileName: "Tension.hx",
                lineNumber: 70,
                className: "game.tension.Tension",
                methodName: "loadVBAssets"
            });
            scarabTension.ExternalService.assetRegistry.getAssetsContent(this.cfg.vbAssets).then(function(data) {
                scarabTension.ExternalService.assets = data;
                _g.loadMainAssets();
            });
        };
        scarabTension.Tension.prototype.loadMainAssets = function() {
            var _g = this;
            haxe.Log.trace("[TENSION] loadMainAssets()", {
                fileName: "Tension.hx",
                lineNumber: 80,
                className: "game.tension.Tension",
                methodName: "loadMainAssets"
            });
            scarabTension.ExternalService.assetRegistry.getAsset(this.vbAssetID).getContent().then(function(vba) {
                _g.vba = vba;
                _g.assetsLoaded = true;
                _g.initialize();
            });
        };
        scarabTension.Tension.prototype.updateLayout = function(e) {
            haxe.Log.trace("[TENSION] updateLayout() ", {
                fileName: "Tension.hx",
                lineNumber: 92,
                className: "game.tension.Tension",
                methodName: "updateLayout"
            });
            this.layoutPayload = e.getPayload();
            if (!this.initialized) this.initialize();
            else {
                this.controller.updateLayout(this.layoutPayload);
                this.layoutPort.getComponentLayoutUpdated().publish(this.context.getInstance());
            }
        };
        scarabTension.Tension.prototype.initialize = function() {
            haxe.Log.trace("[TENSION] initialize() " + _hcmn_.Std.string(this.initialized), {
                fileName: "Tension.hx",
                lineNumber: 107,
                className: "game.tension.Tension",
                methodName: "initialize"
            });
            if (!this.initialized && this.vba != null && this.layoutPayload != null) {
                this.controller = new scarabTension.TensionController(this);
                this.view = this.vbf.createView(this.vba);
                this.registerAllComponents();
                this.controller.updateLayout(this.layoutPayload);
                this.layoutPort.getComponentLayoutUpdated().publish(this.context.getInstance());
                this.port.getShowTension().subscribe($bind(this, this.handleShowTension));
                this.port.getHideTension().subscribe($bind(this, this.handleHideTension));
                this.port.getShowWildTension().subscribe($bind(this, this.hanldeShowWildTension));
                this.port.getHideWildTension().subscribe($bind(this, this.hanldeHideWildTension));
                this.initialized = true;
            }
        };
        scarabTension.Tension.prototype.registerAllComponents = function() {
            haxe.Log.trace("[TENSION] registerAllComponents()", {
                fileName: "Tension.hx",
                lineNumber: 129,
                className: "game.tension.Tension",
                methodName: "registerAllComponents"
            });
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.view.getChildComponents();
                $r = this1.keys();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var compId = $it0.next();
                haxe.Log.trace("[WILDS] registerAllComponents() " + compId, {
                    fileName: "Tension.hx",
                    lineNumber: 132,
                    className: "game.tension.Tension",
                    methodName: "registerAllComponents"
                });
                var constructorIndex;
                var _this = _hcmn_.Type.getEnumConstructs(scarabTensionApi.TensionTypeEnum);
                constructorIndex = _hcmn_.HxOverrides.indexOf(_this, compId, 0);
                if (constructorIndex < 0) continue;
                var componentEnum = _hcmn_.Type.createEnum(scarabTensionApi.TensionTypeEnum, compId, null);
                this.registerComponent(componentEnum);
            }
        };
        scarabTension.Tension.prototype.registerComponent = function(componentEnum) {
            haxe.Log.trace("[TENSION] registerComponent", {
                fileName: "Tension.hx",
                lineNumber: 143,
                className: "game.tension.Tension",
                methodName: "registerComponent",
                customParams: [componentEnum]
            });
            switch (componentEnum[1]) {
                case 1:
                    this.tensionFrame = new scarabTension.TensionFrame(this.view.getContainerById(componentEnum[0]), this.cfg);
                    break;
                case 0:
                    this.wildTension = new scarabTension.WildTension(this.view.getContainerById(componentEnum[0]), this.cfg);
                    break;
            }
            return true;
        };
        scarabTension.Tension.prototype.handleShowTension = function(e) {
            var reelId = e.getPayload().reelId;
            var allFrames = e.getPayload().reels;
            var _g1 = 0;
            var _g = allFrames.length;
            while (_g1 < _g) {
                var i = _g1++;
                if (allFrames[i] == 1 && i == reelId + 1) this.tensionFrame.show(i);
                else this.tensionFrame.hideFrame(i);
            }
        };
        scarabTension.Tension.prototype.handleHideTension = function(e) {
            this.tensionFrame.hide();
        };
        scarabTension.Tension.prototype.hanldeShowWildTension = function(e) {
            this.wildTension.show(e.getPayload());
        };
        scarabTension.Tension.prototype.hanldeHideWildTension = function(e) {
            this.wildTension.hide();
        };
        scarabTension.Tension.prototype.__class__ = scarabTension.Tension;
        scarabTension.TensionController = function(tension) {
            this.flag_addedToStage = false;
            this.tension = tension;
        };
        scarabTension.TensionController.__name__ = ["scarabTension", "TensionController"];
        scarabTension.TensionController.prototype.flag_addedToStage = null;
        scarabTension.TensionController.prototype.tension = null;
        scarabTension.TensionController.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 = scarabTension.ExternalService.displayProvider.getStages();
                stage = this1.get(layerPayload.stage);
                var container;
                container = (function($this) {
                    var $r;
                    var this2 = $this.tension.view.getChildComponents();
                    $r = this2.get(layerId);
                    return $r;
                }(this));
                var containerDO = container.getDisplayObject();
                if (!this.flag_addedToStage) stage.addChild(containerDO);
                containerDO.setX(layerPayload.left);
                containerDO.setY(layerPayload.top);
                containerDO.setScaleX(layerPayload.width / containerDO.getUserData().viewBuilderW);
                containerDO.setScaleY(layerPayload.height / containerDO.getUserData().viewBuilderH);
                containerDO.setZIndex(layerPayload.zIndex);
                if (cfg != null) {}
            }
            if (!this.flag_addedToStage) this.flag_addedToStage = true;
        };
        scarabTension.TensionController.prototype.__class__ = scarabTension.TensionController;
        scarabTension.TensionFactory = function(vbf, context) {
            this.context = context;
            this.vbf = vbf;
        };
        scarabTension.TensionFactory = ck_implements(scarabTension.TensionFactory, clientkernelModulesApi.IService);
        scarabTension.TensionFactory = ck_implements(scarabTension.TensionFactory, componentmodelComponentApi.IComponentFactory);
        scarabTension.TensionFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        scarabTension.TensionFactory.__name__ = ["scarabTension", "TensionFactory"];
        scarabTension.TensionFactory.prototype.vbf = null;
        scarabTension.TensionFactory.prototype.context = null;
        scarabTension.TensionFactory.prototype.getComponentDeclaration = function() {
            return scarabTensionApi.TensionDeclaration;
        };
        scarabTension.TensionFactory.prototype.createComponent = function(context) {
            new scarabTension.Tension(context, this.vbf);
        };
        scarabTension.TensionFactory.prototype.__class__ = scarabTension.TensionFactory;
        scarabTension.TensionFrame = function(container, cfg) {
            this.cfg = cfg;
            this.container = container;
            this.container.show();
            var vbAnimView = scarabTension.ExternalService.viewBuilderFactory.createView(scarabTension.ExternalService.assets.get("tension_vb"));
            var _g1 = 0;
            var _g = this.cfg.numReels;
            while (_g1 < _g) {
                var i = _g1++;
                var vbAnimationHolder = vbAnimView.createContainerFromStoredConfig("TENSION_REGULAR");
                vbAnimationHolder.hide();
                vbAnimationHolder.setX(i * cfg.tensionSize[0] | 0);
                vbAnimationHolder.setY(0);
                var vbAnimationComponent = vbAnimationHolder.getVBAnimationById("ANIMATION_CONTENT");
                vbAnimationComponent.gotoAndPlay(false, "loop");
                container.addChildComponent(vbAnimationHolder, "TENSION_REGULAR_" + i);
            }
        };
        scarabTension.TensionFrame.__name__ = ["scarabTension", "TensionFrame"];
        scarabTension.TensionFrame.prototype.container = null;
        scarabTension.TensionFrame.prototype.cfg = null;
        scarabTension.TensionFrame.prototype.hide = function() {
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.container.getChildComponents();
                $r = this1.keys();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var key = $it0.next();
                var vbAnimationHolder = this.container.getContainerById(key);
                vbAnimationHolder.hide();
                var vbAnimationComponent = vbAnimationHolder.getVBAnimationById("ANIMATION_CONTENT");
                vbAnimationComponent.stop();
            }
        };
        scarabTension.TensionFrame.prototype.hideFrame = function(reelId) {
            var symbolId = "TENSION_REGULAR_" + reelId;
            if ((function($this) {
                    var $r;
                    var this1 = $this.container.getChildComponents();
                    $r = this1.exists(symbolId);
                    return $r;
                }(this))) {
                var vbAnimationHolder = this.container.getContainerById(symbolId);
                vbAnimationHolder.hide();
                var vbAnimationComponent = vbAnimationHolder.getVBAnimationById("ANIMATION_CONTENT");
                vbAnimationComponent.stop();
            }
        };
        scarabTension.TensionFrame.prototype.show = function(reelId) {
            haxe.Log.trace("[TENSION] TensionFrame: ", {
                fileName: "TensionFrame.hx",
                lineNumber: 63,
                className: "game.tension.components.TensionFrame",
                methodName: "show",
                customParams: [reelId]
            });
            var symbolId = "TENSION_REGULAR_" + reelId;
            if ((function($this) {
                    var $r;
                    var this1 = $this.container.getChildComponents();
                    $r = this1.exists(symbolId);
                    return $r;
                }(this))) {
                var vbAnimationHolder = this.container.getContainerById(symbolId);
                vbAnimationHolder.show();
                var vbAnimationComponent = vbAnimationHolder.getVBAnimationById("ANIMATION_CONTENT");
                vbAnimationComponent.gotoAndPlay(false, "loop");
            }
        };
        scarabTension.TensionFrame.prototype.__class__ = scarabTension.TensionFrame;
        scarabTension.WildTension = function(container, cfg) {
            this.currentValue = "0";
            this.cfg = cfg;
            this.container = container;
            this.range = [0, 0, 0, 0, 1, 1, 1, 2, 3, 3, 3];
            container.show();
            var tensionVb = scarabTension.ExternalService.assets.get("tension_vb");
            var vbAnimView = scarabTension.ExternalService.viewBuilderFactory.createView(tensionVb);
            this.createAnim("LEFT", vbAnimView);
            this.createAnim("RIGHT", vbAnimView);
            var vbParticleHolderTop = vbAnimView.createContainerFromStoredConfig("WT_PARTICLE_TOP");
            var vbParticleContentTop = vbParticleHolderTop.getVBAnimationById("ANIMATION_CONTENT");
            vbParticleHolderTop.setX(cfg.particles.top[0]);
            vbParticleHolderTop.setY(cfg.particles.top[1]);
            vbParticleHolderTop.show();
            vbParticleContentTop.show();
            container.addChildComponent(vbParticleHolderTop, "WT_PARTICLE_TOP");
            vbParticleContentTop.gotoAndPlay(false);
            var vbParticleHolderLeft = vbAnimView.createContainerFromStoredConfig("WT_PARTICLE_SIDE");
            var vbParticleContentLeft = vbParticleHolderLeft.getVBAnimationById("ANIMATION_CONTENT");
            vbParticleHolderLeft.setX(cfg.particles.left[0]);
            vbParticleHolderLeft.setY(cfg.particles.left[1]);
            vbParticleHolderLeft.show();
            vbParticleContentLeft.show();
            container.addChildComponent(vbParticleHolderLeft, "WT_PARTICLE_LEFT");
            vbParticleContentLeft.gotoAndPlay(false);
            var vbParticleHolderRight = vbAnimView.createContainerFromStoredConfig("WT_PARTICLE_SIDE");
            var vbParticleContentRight = vbParticleHolderRight.getVBAnimationById("ANIMATION_CONTENT");
            vbParticleHolderRight.setX(cfg.particles.right[0]);
            vbParticleHolderRight.setY(cfg.particles.right[1]);
            vbParticleHolderRight.show();
            vbParticleContentRight.show();
            container.addChildComponent(vbParticleHolderRight, "WT_PARTICLE_RIGHT");
            vbParticleContentRight.gotoAndPlay(false);
        };
        scarabTension.WildTension.__name__ = ["scarabTension", "WildTension"];
        scarabTension.WildTension.prototype.container = null;
        scarabTension.WildTension.prototype.cfg = null;
        scarabTension.WildTension.prototype.range = null;
        scarabTension.WildTension.prototype.currentValue = null;
        scarabTension.WildTension.prototype.createAnim = function(type, vbAnimView) {
            var vbContainer = vbAnimView.createContainerFromStoredConfig("WILD_TENSION");
            vbContainer.show();
            var animId = "WILD_TENSION" + "_" + type;
            this.container.addChildComponent(vbContainer, "WILD_TENSION" + "_" + type);
            var vbAnim = vbContainer.getVBAnimationById("ANIMATION_CONTENT");
            vbAnim.addEventListener("evtComplete", $bind(this, this.handleComplete), [animId]);
            vbAnim.show();
            vbAnim.gotoAndPlay(false, this.currentValue);
            if (type == "LEFT") {
                vbAnim.getDisplayObject().setX(this.cfg.width);
                vbAnim.getDisplayObject().setScaleX(-1);
            }
        };
        scarabTension.WildTension.prototype.handleComplete = function(evt) {
            haxe.Log.trace("[WILD_TENSIONx handleComplete " + this.currentValue, {
                fileName: "WildTension.hx",
                lineNumber: 78,
                className: "game.tension.components.WildTension",
                methodName: "handleComplete"
            });
            var childId = evt[0];
            var vbAnimHolder = this.container.getContainerById(childId);
            var vbAnimContent = vbAnimHolder.getVBAnimationById("ANIMATION_CONTENT");
            vbAnimContent.gotoAndPlay(false, this.currentValue);
        };
        scarabTension.WildTension.prototype.hide = function() {
            haxe.Log.trace("[WILD_TENSION hide", {
                fileName: "WildTension.hx",
                lineNumber: 87,
                className: "game.tension.components.WildTension",
                methodName: "hide"
            });
            this.container.hide();
        };
        scarabTension.WildTension.prototype.show = function(value) {
            this.container.show();
            this.currentValue = _hcmn_.Std.string(this.range[value]);
            var alpha = 0;
            if (value < 5) alpha = 1;
            else alpha = value;
            var vbAnimationHolderRight = this.container.getContainerById("WILD_TENSION_RIGHT");
            vbAnimationHolderRight.getDisplayObject().setAlpha(alpha / 10);
            var vbAnimationHolderLeft = this.container.getContainerById("WILD_TENSION_LEFT");
            vbAnimationHolderLeft.getDisplayObject().setAlpha(alpha / 10);
            this.container.getContainerById("WT_PARTICLE_LEFT").getDisplayObject().setAlpha(alpha / 10);
            this.container.getContainerById("WT_PARTICLE_TOP").getDisplayObject().setAlpha(alpha / 10);
            this.container.getContainerById("WT_PARTICLE_RIGHT").getDisplayObject().setAlpha(alpha / 10);
        };
        scarabTension.WildTension.prototype.__class__ = scarabTension.WildTension;
        if (typeof haxe == 'undefined') {
            var haxe = {};
        };

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

            get: function(k) {
                return {
                    arguments: ["*"],
                    returns: "null"
                };
            },
            exists: function(k) {
                return {
                    arguments: ["*"],
                    returns: "boolean"
                };
            },
            keys: function() {
                return {
                    arguments: [],
                    returns: "null"
                };
            }
        };
        haxe.Log = function() {};
        haxe.Log.__name__ = ["haxe", "Log"];
        haxe.Log.trace = function(v, infos) {
            _hcmn_.js_Boot.__trace(v, infos);
        };
        haxe.Log.prototype.__class__ = haxe.Log;
        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;
        return {
            exports: scarabTension,
            activator: scarabTension.Activator
        };
    });
//# sourceURL=scarabTension.js