define("smashthepigTension", ["viewBuilderApi", "smashthepigComponentsTensionPort", "componentmodelComponentApi", "smashThePigComponentsTensionDeclaration", "clientkernelLoaderApi", "displayEngineApi", "gameLayoutApi", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(viewBuilderApi, smashthepigComponentsTensionPort, componentmodelComponentApi, smashThePigComponentsTensionDeclaration, clientkernelLoaderApi, displayEngineApi, gameLayoutApi, 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 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 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 smashthepigTension == 'undefined') {
            var smashthepigTension = {};
        };
        smashthepigTension.Activator = function(context) {};
        smashthepigTension.Activator = ck_implements(smashthepigTension.Activator, clientkernelModulesApi.IModuleActivator);
        smashthepigTension.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        smashthepigTension.Activator.__name__ = ["smashthepigTension", "Activator"];
        smashthepigTension.Activator.prototype.start = function(context) {
            context.getServiceTracker([viewBuilderApi.IViewBuilderFactory, clientkernelLoaderApi.IAssetRegistry, displayEngineApi.IDisplayProvider]).then(function(context1) {
                smashthepigTension.ExternalService.initialize(context1);
                var vbf = context1.getAnyService(viewBuilderApi.IViewBuilderFactory, null);
                smashthepigTension.ExternalService.viewBuilderFactory = vbf;
                context1.registerService(new smashthepigTension.TensionFactory(vbf, context1), smashThePigComponentsTensionDeclaration.TensionDeclaration, null);
            });
        };
        smashthepigTension.Activator.prototype.stop = function(context) {};
        smashthepigTension.Activator.main = function() {};
        smashthepigTension.Activator.prototype.__class__ = smashthepigTension.Activator;
        smashthepigTension.ExternalService = function() {};
        smashthepigTension.ExternalService.__name__ = ["smashthepigTension", "ExternalService"];
        smashthepigTension.ExternalService.displayProvider = null;
        smashthepigTension.ExternalService.assetRegistry = null;
        smashthepigTension.ExternalService.viewBuilderFactory = null;
        smashthepigTension.ExternalService.loadedCallback = null;
        smashthepigTension.ExternalService.initialize = function(context) {
            smashthepigTension.ExternalService.displayProvider = context.getAnyService(displayEngineApi.IDisplayProvider, null);
            smashthepigTension.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
        };
        smashthepigTension.ExternalService.loadAssets = function(id, loadedCallback) {
            haxe.Log.trace("ew loadVBAssets(" + id + ")", {
                fileName: "ExternalService.hx",
                lineNumber: 34,
                className: "smashthepig.components.tension.ExternalService",
                methodName: "loadAssets"
            });
            if (loadedCallback) smashthepigTension.ExternalService.loadedCallback = loadedCallback;
            smashthepigTension.ExternalService.loading++;
            smashthepigTension.ExternalService.assetRegistry.getAsset(id).getContent().then(function(vba) {
                var value = vba;
                smashthepigTension.ExternalService.loadedAssets.set(id, value);
                smashthepigTension.ExternalService.ceheckLoaded(id);
            });
        };
        smashthepigTension.ExternalService.ceheckLoaded = function(id) {
            smashthepigTension.ExternalService.totalLoaded++;
            haxe.Log.trace("ew loaded(" + smashthepigTension.ExternalService.totalLoaded + "/" + smashthepigTension.ExternalService.loading + "):" + id, {
                fileName: "ExternalService.hx",
                lineNumber: 45,
                className: "smashthepig.components.tension.ExternalService",
                methodName: "ceheckLoaded"
            });
            if (smashthepigTension.ExternalService.totalLoaded == smashthepigTension.ExternalService.loading) smashthepigTension.ExternalService.loadedCallback();
        };
        smashthepigTension.ExternalService.setLoadedCallback = function(callback) {
            smashthepigTension.ExternalService.loadedCallback = callback;
        };
        smashthepigTension.ExternalService.prototype.__class__ = smashthepigTension.ExternalService;
        smashthepigTension.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));
            smashthepigTension.ExternalService.loadAssets("tension-assets/TENSION_SPIN_VB");
            smashthepigTension.ExternalService.loadAssets("tension-assets/tension_definition_config");
            smashthepigTension.ExternalService.loadAssets("tension-assets/TENSION_SPIN_AFRIKA_VB");
            smashthepigTension.ExternalService.loadAssets("tension-assets/tension_frame_definition_config");
            smashthepigTension.ExternalService.loadAssets("tension-assets/tension_container_config_json", $bind(this, this.loadViewBuilder));
            this.port = context.getImplementedPort(smashthepigComponentsTensionPort.ITensionImplementationPort);
        };
        smashthepigTension.Tension.__name__ = ["smashthepigTension", "Tension"];
        smashthepigTension.Tension.prototype.view = null;
        smashthepigTension.Tension.prototype.layoutPort = null;
        smashthepigTension.Tension.prototype.context = null;
        smashthepigTension.Tension.prototype.cfgId = null;
        smashthepigTension.Tension.prototype.vba = null;
        smashthepigTension.Tension.prototype.expandingWildAnimAssets = null;
        smashthepigTension.Tension.prototype.assetsLoaded = null;
        smashthepigTension.Tension.prototype.vbf = null;
        smashthepigTension.Tension.prototype.layoutPayload = null;
        smashthepigTension.Tension.prototype.initialized = null;
        smashthepigTension.Tension.prototype.tensionAnim = null;
        smashthepigTension.Tension.prototype.tensionFrameAnim = null;
        smashthepigTension.Tension.prototype.layerContainers = null;
        smashthepigTension.Tension.prototype.port = null;
        smashthepigTension.Tension.prototype.loadViewBuilder = function() {
            this.vba = smashthepigTension.ExternalService.loadedAssets.get("tension-assets/tension_container_config_json");
            this.initialize();
        };
        smashthepigTension.Tension.prototype.updateLayout = function(e) {
            this.layoutPayload = e.getPayload();
            if (!this.initialized) this.initialize();
            else this.handleUpdateLayout(this.layoutPayload);
        };
        smashthepigTension.Tension.prototype.initialize = function() {
            haxe.Log.trace("[dex] loaded try initialize", {
                fileName: "Tension.hx",
                lineNumber: 88,
                className: "smashthepig.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.registerAllComponents();
                this.handleUpdateLayout(this.layoutPayload);
                this.initialized = true;
                this.port.getShow().subscribe($bind(this, this.handleShow));
                this.port.getShowTensionFrame().subscribe($bind(this, this.handleShowTensionFrame));
                this.port.getHideTensionFrame().subscribe($bind(this, this.handleHideTensionFrame));
            }
        };
        smashthepigTension.Tension.prototype.handleUpdateLayout = function(layoutPayload) {
            var $it0 = this.layerContainers.keys();
            while ($it0.hasNext()) {
                var layerId = $it0.next();
                var layerPayload = layoutPayload.containers.get(layerId);
                var stage;
                var this2 = smashthepigTension.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());
        };
        smashthepigTension.Tension.prototype.handleShowTensionFrame = function(e) {
            haxe.Log.trace("[mg] Tension.handleShowTensionFrame " + _hcmn_.Std.string(e.getPayload()), {
                fileName: "Tension.hx",
                lineNumber: 123,
                className: "smashthepig.components.tension.Tension",
                methodName: "handleShowTensionFrame"
            });
            this.tensionFrameAnim.showAnimation(e.getPayload().reelId, e.getPayload().data);
        };
        smashthepigTension.Tension.prototype.handleHideTensionFrame = function(e) {
            haxe.Log.trace("showtensionframe - hide", {
                fileName: "Tension.hx",
                lineNumber: 128,
                className: "smashthepig.components.tension.Tension",
                methodName: "handleHideTensionFrame"
            });
            this.tensionFrameAnim.hideFrames();
        };
        smashthepigTension.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);
                }
            }
        };
        smashthepigTension.Tension.prototype.registerAllComponents = function() {
            this.layerContainers = this.view.getChildComponents();
            var $it0 = this.layerContainers.keys();
            while ($it0.hasNext()) {
                var layerId = $it0.next();
                var construktorIndex;
                var _this = _hcmn_.Type.getEnumConstructs(smashthepigTension.ComponentsEnum);
                construktorIndex = _hcmn_.HxOverrides.indexOf(_this, layerId, 0);
                if (construktorIndex < 0) continue;
                var componentEnum = _hcmn_.Type.createEnum(smashthepigTension.ComponentsEnum, layerId, null);
                this.registerComponent(componentEnum);
            }
        };
        smashthepigTension.Tension.prototype.registerComponent = function(component) {
            switch (component[1]) {
                case 0:
                    this.registerTension();
                    break;
                case 1:
                    this.registerTensionFrame();
                    break;
            }
        };
        smashthepigTension.Tension.prototype.registerTension = function() {
            var cfg = smashthepigTension.ExternalService.loadedAssets.get("tension-assets/tension_definition_config");
            var container = this.view.getComponentById("TENSION");
            var vba = smashthepigTension.ExternalService.loadedAssets.get("tension-assets/TENSION_SPIN_VB");
            this.tensionAnim = new smashthepigTension.TensionAnim(container, cfg, vba);
        };
        smashthepigTension.Tension.prototype.registerTensionFrame = function() {
            var cfg = smashthepigTension.ExternalService.loadedAssets.get("tension-assets/tension_frame_definition_config");
            var vbaFrame = smashthepigTension.ExternalService.loadedAssets.get("tension-assets/TENSION_SPIN_AFRIKA_VB");
            var tensionFrameContainer = this.view.getComponentById("TENSION_FRAME");
            this.tensionFrameAnim = new smashthepigTension.TensionFrameAnim(tensionFrameContainer, cfg, vbaFrame);
        };
        smashthepigTension.Tension.prototype.__class__ = smashthepigTension.Tension;
        smashthepigTension.TensionFactory = function(vbf, context) {
            this.context = context;
            this.vbf = vbf;
        };
        smashthepigTension.TensionFactory = ck_implements(smashthepigTension.TensionFactory, clientkernelModulesApi.IService);
        smashthepigTension.TensionFactory = ck_implements(smashthepigTension.TensionFactory, componentmodelComponentApi.IComponentFactory);
        smashthepigTension.TensionFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        smashthepigTension.TensionFactory.__name__ = ["smashthepigTension", "TensionFactory"];
        smashthepigTension.TensionFactory.prototype.vbf = null;
        smashthepigTension.TensionFactory.prototype.context = null;
        smashthepigTension.TensionFactory.prototype.getComponentDeclaration = function() {
            return smashThePigComponentsTensionDeclaration.TensionDeclaration;
        };
        smashthepigTension.TensionFactory.prototype.createComponent = function(context) {
            var cfgId = context.getConfiguration();
            new smashthepigTension.Tension(context, this.vbf, cfgId);
        };
        smashthepigTension.TensionFactory.prototype.__class__ = smashthepigTension.TensionFactory;
        smashthepigTension.TensionAnim = function(container, cfg, vba) {
            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 = vba;
                if (vbAsset != null) {
                    var vbAnimView = smashthepigTension.ExternalService.viewBuilderFactory.createView(vbAsset);
                    this.vbAnimationHolder = vbAnimView.createContainerFromStoredConfig("ANIMATION_HOLDER");
                    var vbAnimationComponent;
                    vbAnimationComponent = _hcmn_.js_Boot.__cast(this.vbAnimationHolder.getComponentById("ANIMATION_CONTENT"), viewBuilderApi.IVBAnimationComponent);
                    this.vbAnimationHolder.setX((this.cfg.width + this.cfg.gap) * col);
                    this.vbAnimationHolder.setY(0);
                    this.vbAnimationHolder.getDisplayObject().setScaleX(this.cfg.width / vbAnimationComponent.getDisplayObject().getWidth());
                    vbAnimationComponent.toOffScreen();
                    container.addChildComponent(this.vbAnimationHolder, "TENSION_SPIN_VB_" + col);
                    this.animatonComponents.push(vbAnimationComponent);
                }
            }
        };
        smashthepigTension.TensionAnim.__name__ = ["smashthepigTension", "TensionAnim"];
        smashthepigTension.TensionAnim.prototype.container = null;
        smashthepigTension.TensionAnim.prototype.animatonComponents = null;
        smashthepigTension.TensionAnim.prototype.cfg = null;
        smashthepigTension.TensionAnim.prototype.active = null;
        smashthepigTension.TensionAnim.prototype.tensionMask = null;
        smashthepigTension.TensionAnim.prototype.vbAnimationHolder = null;
        smashthepigTension.TensionAnim.prototype.init = function(tensionReels) {
            haxe.Log.trace("[dex] tension reels=", {
                fileName: "TensionAnim.hx",
                lineNumber: 53,
                className: "smashthepig.components.tension.components.TensionAnim",
                methodName: "init",
                customParams: [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;
        };
        smashthepigTension.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();
                }
            }
        };
        smashthepigTension.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();
                }
            }
        };
        smashthepigTension.TensionAnim.prototype.__class__ = smashthepigTension.TensionAnim;
        smashthepigTension.TensionFrameAnim = function(container, cfg, vba) {
            this.active = false;
            this.cfg = cfg;
            this.container = container;
            this.vba = vba;
            container.show();
            this.animatonComponents = [];
            var _g1 = 0;
            var _g = cfg.numReels;
            while (_g1 < _g) {
                var j = _g1++;
                if (vba != null) {
                    var vbAnimView = smashthepigTension.ExternalService.viewBuilderFactory.createView(vba);
                    this.vbAnimationHolder = vbAnimView.createContainerFromStoredConfig("ANIMATION_HOLDER");
                    this.vbAnimationComponent = _hcmn_.js_Boot.__cast(this.vbAnimationHolder.getComponentById("ANIMATION_CONTENT"), viewBuilderApi.IVBAnimationComponent);
                    this.vbAnimationHolder.setX((this.cfg.width + this.cfg.gap) * j);
                    this.vbAnimationHolder.getDisplayObject().setScaleX(this.cfg.width / this.vbAnimationComponent.getDisplayObject().getWidth());
                    this.vbAnimationComponent.toOffScreen();
                    container.addChildComponent(this.vbAnimationHolder, "TENSION_FRAME_SPIN_VB_" + j);
                    this.animatonComponents.push(this.vbAnimationComponent);
                }
            }
        };
        smashthepigTension.TensionFrameAnim.__name__ = ["smashthepigTension", "TensionFrameAnim"];
        smashthepigTension.TensionFrameAnim.prototype.container = null;
        smashthepigTension.TensionFrameAnim.prototype.animatonComponents = null;
        smashthepigTension.TensionFrameAnim.prototype.cfg = null;
        smashthepigTension.TensionFrameAnim.prototype.vba = null;
        smashthepigTension.TensionFrameAnim.prototype.active = null;
        smashthepigTension.TensionFrameAnim.prototype.tensionMask = null;
        smashthepigTension.TensionFrameAnim.prototype.tensionReels = null;
        smashthepigTension.TensionFrameAnim.prototype.vbAnimationHolder = null;
        smashthepigTension.TensionFrameAnim.prototype.vbAnimationComponent = null;
        smashthepigTension.TensionFrameAnim.prototype.showAnimation = function(reelId, tensionPositions) {
            haxe.Log.trace("[mg]TensionAnimFrame.showAnimation() " + _hcmn_.Std.string(tensionPositions), {
                fileName: "TensionFrameAnim.hx",
                lineNumber: 52,
                className: "smashthepig.components.tension.components.TensionFrameAnim",
                methodName: "showAnimation"
            });
            var _g1 = 0;
            var _g = reelId + 1;
            while (_g1 < _g) {
                var i = _g1++;
                if (tensionPositions[i] > -1) {
                    this.container.getComponentById("TENSION_FRAME_SPIN_VB_" + i).setY(this.cfg.height * tensionPositions[i]);
                    this.animatonComponents[i].show();
                    this.animatonComponents[i].gotoAndPlay(true, "2");
                } else this.animatonComponents[i].hide();
            }
        };
        smashthepigTension.TensionFrameAnim.prototype.hideFrames = function() {
            haxe.Log.trace("[mg]TensionFrameAnim.hideFrames()", {
                fileName: "TensionFrameAnim.hx",
                lineNumber: 122,
                className: "smashthepig.components.tension.components.TensionFrameAnim",
                methodName: "hideFrames"
            });
            this.active = false;
            var _g1 = 0;
            var _g = this.cfg.numReels;
            while (_g1 < _g) {
                var i = _g1++;
                this.animatonComponents[i].hide();
            }
        };
        smashthepigTension.TensionFrameAnim.prototype.__class__ = smashthepigTension.TensionFrameAnim;
        smashthepigTension.ComponentsEnum = {
            __ename__: ["smashthepigTension", "ComponentsEnum"],
            __constructs__: ["TENSION", "TENSION_FRAME"]
        };
        smashthepigTension.ComponentsEnum.TENSION_FRAME = ["TENSION_FRAME", 1];
        smashthepigTension.ComponentsEnum.TENSION_FRAME.toString = $estr;
        smashthepigTension.ComponentsEnum.TENSION_FRAME.__enum__ = smashthepigTension.ComponentsEnum;
        smashthepigTension.ComponentsEnum.TENSION = ["TENSION", 0];
        smashthepigTension.ComponentsEnum.TENSION.toString = $estr;
        smashthepigTension.ComponentsEnum.TENSION.__enum__ = smashthepigTension.ComponentsEnum;
        smashthepigTension.ExternalService.loadedAssets = new _hcmn_.haxe_ds_StringMap();;
        smashthepigTension.ExternalService.loading = 0;;
        smashthepigTension.ExternalService.totalLoaded = 0;;
        return {
            exports: smashthepigTension,
            activator: smashthepigTension.Activator
        };
    });
//# sourceURL=smashThePigTension.js