define("icywildsTension", ["icyWildsComponentsTensionDeclaration", "viewBuilderApi", "componentmodelComponentApi", "clientkernelLoaderApi", "displayEngineApi", "gameLayoutApi", "clientkernelEventbusApi", "clientkernelModulesApi", "icywildsComponentsTensionPort"],
    function(icyWildsComponentsTensionDeclaration, viewBuilderApi, componentmodelComponentApi, clientkernelLoaderApi, displayEngineApi, gameLayoutApi, clientkernelEventbusApi, clientkernelModulesApi, icywildsComponentsTensionPort) {
        "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"
                };
            }
        };
        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 icywildsTension == 'undefined') {
            var icywildsTension = {};
        };
        icywildsTension.Activator = function(context) {};
        icywildsTension.Activator = ck_implements(icywildsTension.Activator, clientkernelModulesApi.IModuleActivator);
        icywildsTension.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        icywildsTension.Activator.__name__ = ["icywildsTension", "Activator"];
        icywildsTension.Activator.prototype.start = function(context) {
            context.getServiceTracker([viewBuilderApi.IViewBuilderFactory, clientkernelLoaderApi.IAssetRegistry, displayEngineApi.IDisplayProvider]).then(function(context1) {
                icywildsTension.ExternalService.initialize(context1);
                var vbf = context1.getAnyService(viewBuilderApi.IViewBuilderFactory, null);
                icywildsTension.ExternalService.viewBuilderFactory = vbf;
                context1.registerService(new icywildsTension.TensionFactory(vbf, context1), icyWildsComponentsTensionDeclaration.TensionDeclaration, null);
            });
        };
        icywildsTension.Activator.prototype.stop = function(context) {};
        icywildsTension.Activator.main = function() {};
        icywildsTension.Activator.prototype.__class__ = icywildsTension.Activator;
        icywildsTension.ExternalService = function() {};
        icywildsTension.ExternalService.__name__ = ["icywildsTension", "ExternalService"];
        icywildsTension.ExternalService.displayProvider = null;
        icywildsTension.ExternalService.assetRegistry = null;
        icywildsTension.ExternalService.viewBuilderFactory = null;
        icywildsTension.ExternalService.loadedCallback = null;
        icywildsTension.ExternalService.initialize = function(context) {
            icywildsTension.ExternalService.displayProvider = context.getAnyService(displayEngineApi.IDisplayProvider, null);
            icywildsTension.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
        };
        icywildsTension.ExternalService.loadAssets = function(id, loadedCallback) {
            haxe.Log.trace("ew loadVBAssets(" + id + ")", {
                fileName: "ExternalService.hx",
                lineNumber: 33,
                className: "icywilds.components.tension.ExternalService",
                methodName: "loadAssets"
            });
            if (loadedCallback) icywildsTension.ExternalService.loadedCallback = loadedCallback;
            icywildsTension.ExternalService.loading++;
            icywildsTension.ExternalService.assetRegistry.getAsset(id).getContent().then(function(vba) {
                var value = vba;
                icywildsTension.ExternalService.loadedAssets.set(id, value);
                icywildsTension.ExternalService.ceheckLoaded(id);
            });
        };
        icywildsTension.ExternalService.ceheckLoaded = function(id) {
            icywildsTension.ExternalService.totalLoaded++;
            haxe.Log.trace("ew loaded(" + icywildsTension.ExternalService.totalLoaded + "/" + icywildsTension.ExternalService.loading + "):" + id, {
                fileName: "ExternalService.hx",
                lineNumber: 44,
                className: "icywilds.components.tension.ExternalService",
                methodName: "ceheckLoaded"
            });
            if (icywildsTension.ExternalService.totalLoaded == icywildsTension.ExternalService.loading) icywildsTension.ExternalService.loadedCallback();
        };
        icywildsTension.ExternalService.setLoadedCallback = function(callback) {
            icywildsTension.ExternalService.loadedCallback = callback;
        };
        icywildsTension.ExternalService.prototype.__class__ = icywildsTension.ExternalService;
        icywildsTension.Tension = function(context, vbf, cfgId) {
            this.initialized = false;
            this.layoutPayload = null;
            this.assetsLoaded = false;
            this.vbf = vbf;
            this.cfgId = "tension-assets/tension_container_config_json";
            this.context = context;
            this.layoutPort = context.getUsedPort(gameLayoutApi.IGameLayoutPort);
            this.layoutPort.getUpdateComponentLayout().subscribe($bind(this, this.updateLayout));
            icywildsTension.ExternalService.loadAssets("tension-assets/TENSION_SPIN_VB");
            icywildsTension.ExternalService.loadAssets("tension-assets/tension_definition_config");
            icywildsTension.ExternalService.loadAssets("tension-assets/tension_container_config_json", $bind(this, this.loadViewBuilder));
            this.port = context.getImplementedPort(icywildsComponentsTensionPort.ITensionImplementationPort);
        };
        icywildsTension.Tension.__name__ = ["icywildsTension", "Tension"];
        icywildsTension.Tension.prototype.view = null;
        icywildsTension.Tension.prototype.layoutPort = null;
        icywildsTension.Tension.prototype.context = null;
        icywildsTension.Tension.prototype.cfgId = null;
        icywildsTension.Tension.prototype.vba = null;
        icywildsTension.Tension.prototype.expandingWildAnimAssets = null;
        icywildsTension.Tension.prototype.assetsLoaded = null;
        icywildsTension.Tension.prototype.vbf = null;
        icywildsTension.Tension.prototype.layoutPayload = null;
        icywildsTension.Tension.prototype.initialized = null;
        icywildsTension.Tension.prototype.tensionAnim = null;
        icywildsTension.Tension.prototype.port = null;
        icywildsTension.Tension.prototype.loadViewBuilder = function() {
            this.vba = icywildsTension.ExternalService.loadedAssets.get("tension-assets/tension_container_config_json");
            this.initialize();
        };
        icywildsTension.Tension.prototype.updateLayout = function(e) {
            this.layoutPayload = e.getPayload();
            if (!this.initialized) this.initialize();
            else this.handleUpdateLayout(this.layoutPayload);
        };
        icywildsTension.Tension.prototype.initialize = function() {
            haxe.Log.trace("[dex] loaded try initialize", {
                fileName: "Tension.hx",
                lineNumber: 83,
                className: "icywilds.components.tension.Tension",
                methodName: "initialize",
                customParams: [this.initialized, this.vba != null, this.layoutPayload != null]
            });
            if (!this.initialized && this.vba != null && this.layoutPayload != null) {
                this.view = this.vbf.createView(this.vba);
                this.registerComponent(icywildsTension.ExternalService.loadedAssets.get("tension-assets/tension_definition_config"));
                this.handleUpdateLayout(this.layoutPayload);
                this.initialized = true;
                this.port.getShow().subscribe($bind(this, this.handleShow));
            }
        };
        icywildsTension.Tension.prototype.handleUpdateLayout = function(layoutPayload) {
            var layerId = "TENSION";
            var layerPayload = layoutPayload.containers.get(layerId);
            var stage;
            var this2 = icywildsTension.ExternalService.displayProvider.getStages();
            stage = this2.get(layerPayload.stage);
            var container = ((function($this) {
                var $r;
                var this1 = $this.view.getChildComponents();
                $r = this1.get(layerId);
                return $r;
            }(this))).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);
            this.layoutPort.getComponentLayoutUpdated().publish(this.context.getInstance());
        };
        icywildsTension.Tension.prototype.handleShow = function(e) {
            if (e.getPayload().spinStopped != null) {
                if (e.getPayload().spinStopped) this.tensionAnim.stop();
            }
            if (e.getPayload().reelId != null) this.tensionAnim.reelStopped(e.getPayload().reelId);
            if (e.getPayload().stopSpin != null) {
                if (e.getPayload().stopSpin) {
                    var tensionReels = e.getPayload().data;
                    var sum = 0;
                    var _g1 = 0;
                    var _g = tensionReels.length;
                    while (_g1 < _g) {
                        var i = _g1++;
                        sum += tensionReels[i];
                    }
                    if (sum > 0) this.tensionAnim.init(tensionReels);
                }
            }
        };
        icywildsTension.Tension.prototype.registerComponent = function(cfg) {
            var container = this.view.getComponentById("TENSION");
            this.tensionAnim = new icywildsTension.TensionAnim(container, cfg);
        };
        icywildsTension.Tension.prototype.__class__ = icywildsTension.Tension;
        icywildsTension.TensionFactory = function(vbf, context) {
            this.context = context;
            this.vbf = vbf;
        };
        icywildsTension.TensionFactory = ck_implements(icywildsTension.TensionFactory, clientkernelModulesApi.IService);
        icywildsTension.TensionFactory = ck_implements(icywildsTension.TensionFactory, componentmodelComponentApi.IComponentFactory);
        icywildsTension.TensionFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        icywildsTension.TensionFactory.__name__ = ["icywildsTension", "TensionFactory"];
        icywildsTension.TensionFactory.prototype.vbf = null;
        icywildsTension.TensionFactory.prototype.context = null;
        icywildsTension.TensionFactory.prototype.getComponentDeclaration = function() {
            return icyWildsComponentsTensionDeclaration.TensionDeclaration;
        };
        icywildsTension.TensionFactory.prototype.createComponent = function(context) {
            var cfgId = context.getConfiguration();
            new icywildsTension.Tension(context, this.vbf, cfgId);
        };
        icywildsTension.TensionFactory.prototype.__class__ = icywildsTension.TensionFactory;
        icywildsTension.TensionAnim = function(container, cfg) {
            this.active = false;
            this.cfg = cfg;
            this.container = container;
            container.show();
            this.animatonComponents = [];
            var _g1 = 0;
            var _g = this.cfg.numReels;
            while (_g1 < _g) {
                var col = _g1++;
                var vbAsset = icywildsTension.ExternalService.loadedAssets.get("tension-assets/TENSION_SPIN_VB");
                if (vbAsset != null) {
                    var vbAnimView = icywildsTension.ExternalService.viewBuilderFactory.createView(vbAsset);
                    var vbAnimationHolder = vbAnimView.createContainerFromStoredConfig("ANIMATION_HOLDER");
                    var vbAnimationComponent;
                    vbAnimationComponent = _hcmn_.js_Boot.__cast(vbAnimationHolder.getComponentById("ANIMATION_CONTENT"), viewBuilderApi.IVBAnimationComponent);
                    vbAnimationHolder.setX((this.cfg.width + this.cfg.gap) * col);
                    vbAnimationHolder.setY(0);
                    vbAnimationHolder.getDisplayObject().setScaleY(this.cfg.height / vbAnimationComponent.getDisplayObject().getHeight());
                    vbAnimationHolder.getDisplayObject().setScaleX(this.cfg.width / vbAnimationComponent.getDisplayObject().getWidth());
                    vbAnimationComponent.toOffScreen();
                    container.addChildComponent(vbAnimationHolder, "TENSION_SPIN_VB_" + col);
                    this.animatonComponents.push(vbAnimationComponent);
                }
            }
        };
        icywildsTension.TensionAnim.__name__ = ["icywildsTension", "TensionAnim"];
        icywildsTension.TensionAnim.prototype.container = null;
        icywildsTension.TensionAnim.prototype.animatonComponents = null;
        icywildsTension.TensionAnim.prototype.cfg = null;
        icywildsTension.TensionAnim.prototype.active = null;
        icywildsTension.TensionAnim.prototype.tensionMask = null;
        icywildsTension.TensionAnim.prototype.init = function(tensionReels) {
            this.tensionMask = [];
            var _g1 = 0;
            var _g = this.cfg.numReels;
            while (_g1 < _g) {
                var j = _g1++;
                if (tensionReels[j] == 0) this.tensionMask.push(false);
                else this.tensionMask.push(true);
            }
            this.active = true;
        };
        icywildsTension.TensionAnim.prototype.reelStopped = function(reel) {
            if (this.active) {
                var _g1 = 0;
                var _g = this.cfg.numReels;
                while (_g1 < _g) {
                    var j = _g1++;
                    if (this.tensionMask[j] == true && j == reel + 1) {
                        this.animatonComponents[j].show();
                        this.animatonComponents[j].gotoAndPlay(true, "2");
                    } else this.animatonComponents[j].hide();
                }
            }
        };
        icywildsTension.TensionAnim.prototype.stop = function() {
            if (this.active) {
                this.active = false;
                var _g1 = 0;
                var _g = this.cfg.numReels;
                while (_g1 < _g) {
                    var i = _g1++;
                    if (this.animatonComponents[i].isPlaying()) this.animatonComponents[i].stop();
                    if (this.animatonComponents[i].getDisplayObject().getVisible()) this.animatonComponents[i].hide();
                }
            }
        };
        icywildsTension.TensionAnim.prototype.__class__ = icywildsTension.TensionAnim;
        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;
        icywildsTension.ExternalService.loadedAssets = new _hcmn_.haxe_ds_StringMap();;
        icywildsTension.ExternalService.loading = 0;;
        icywildsTension.ExternalService.totalLoaded = 0;;
        return {
            exports: icywildsTension,
            activator: icywildsTension.Activator
        };
    });
//# sourceURL=icyWildsTension.js