define("smashThePigAnimation", ["viewBuilderApi", "componentmodelComponentApi", "clientkernelLoaderApi", "displayEngineApi", "gameLayoutApi", "clientkernelEventbusApi", "clientkernelModulesApi", "smashthepigComponentsAnimationDeclaration", "smashThePigComponentsAnimationPort"],
    function(viewBuilderApi, componentmodelComponentApi, clientkernelLoaderApi, displayEngineApi, gameLayoutApi, clientkernelEventbusApi, clientkernelModulesApi, smashthepigComponentsAnimationDeclaration, smashThePigComponentsAnimationPort) {
        "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 smashThePigAnimation == 'undefined') {
            var smashThePigAnimation = {};
        };
        smashThePigAnimation.Activator = function(context) {};
        smashThePigAnimation.Activator = ck_implements(smashThePigAnimation.Activator, clientkernelModulesApi.IModuleActivator);
        smashThePigAnimation.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        smashThePigAnimation.Activator.__name__ = ["smashThePigAnimation", "Activator"];
        smashThePigAnimation.Activator.prototype.start = function(context) {
            context.getServiceTracker([viewBuilderApi.IViewBuilderFactory, clientkernelLoaderApi.IAssetRegistry, displayEngineApi.IDisplayProvider]).then(function(context1) {
                smashThePigAnimation.ExternalService.initialize(context1);
                var vbf = context1.getAnyService(viewBuilderApi.IViewBuilderFactory, null);
                smashThePigAnimation.ExternalService.viewBuilderFactory = vbf;
                context1.registerService(new smashThePigAnimation.AnimationFactory(vbf, context1), smashthepigComponentsAnimationDeclaration.AnimationDeclaration, null);
            });
        };
        smashThePigAnimation.Activator.prototype.stop = function(context) {};
        smashThePigAnimation.Activator.main = function() {};
        smashThePigAnimation.Activator.prototype.__class__ = smashThePigAnimation.Activator;
        smashThePigAnimation.Animation = function(context, vbf, cfgId) {
            this.initialized = false;
            this.layoutPayload = null;
            this.vba = null;
            var _g = this;
            this.vbf = vbf;
            this.cfgId = cfgId;
            this.context = context;
            this.port = context.getImplementedPort(smashThePigComponentsAnimationPort.IAnimationImplementationPort);
            this.layoutPort = context.getUsedPort(gameLayoutApi.IGameLayoutPort);
            this.layoutPort.getUpdateComponentLayout().subscribe($bind(this, this.updateLayout));
            smashThePigAnimation.ExternalService.assetRegistry.getAsset(cfgId).getContent().then(function(vba) {
                _g.vba = vba;
                _g.initialize();
            });
        };
        smashThePigAnimation.Animation.__name__ = ["smashThePigAnimation", "Animation"];
        smashThePigAnimation.Animation.prototype.view = null;
        smashThePigAnimation.Animation.prototype.component = null;
        smashThePigAnimation.Animation.prototype.componentId = null;
        smashThePigAnimation.Animation.prototype.cfgId = null;
        smashThePigAnimation.Animation.prototype.context = null;
        smashThePigAnimation.Animation.prototype.vba = null;
        smashThePigAnimation.Animation.prototype.vbf = null;
        smashThePigAnimation.Animation.prototype.controller = null;
        smashThePigAnimation.Animation.prototype.layoutPayload = null;
        smashThePigAnimation.Animation.prototype.initialized = null;
        smashThePigAnimation.Animation.prototype.port = null;
        smashThePigAnimation.Animation.prototype.layoutPort = null;
        smashThePigAnimation.Animation.prototype.loadMainAsset = function() {
            var _g = this;
            smashThePigAnimation.ExternalService.assetRegistry.getAsset(this.cfgId).getContent().then(function(vba) {
                _g.vba = vba;
                if (!_g.initialized) _g.initialize();
            });
        };
        smashThePigAnimation.Animation.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());
            }
        };
        smashThePigAnimation.Animation.prototype.initialize = function() {
            if (!this.initialized && this.vba != null && this.layoutPayload != null) {
                this.controller = new smashThePigAnimation.AnimationController(this);
                this.view = this.vbf.createView(this.vba);
                this.registerAllComponents();
                this.controller.init();
                this.controller.updateLayout(this.layoutPayload);
                this.layoutPort.getComponentLayoutUpdated().publish(this.context.getInstance());
                this.initialized = true;
            }
        };
        smashThePigAnimation.Animation.prototype.registerAllComponents = function() {
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.view.getChildComponents();
                $r = this1.keys();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var compId = $it0.next();
                var constructorIndex;
                var _this = _hcmn_.Type.getEnumConstructs(smashThePigAnimation.ComponentsEnum);
                constructorIndex = _hcmn_.HxOverrides.indexOf(_this, compId, 0);
                if (constructorIndex < 0) continue;
                var componentEnum = _hcmn_.Type.createEnum(smashThePigAnimation.ComponentsEnum, compId, null);
                this.registerComponent(componentEnum);
            }
        };
        smashThePigAnimation.Animation.prototype.registerComponent = function(componentEnum) {
            this.component = null;
            switch (componentEnum[1]) {
                case 1:
                    this.registerContainerComponent(smashThePigAnimation.ComponentsEnum.reel_foreground, smashThePigAnimation.ReelForeground);
                    break;
                case 0:
                    this.registerContainerComponent(smashThePigAnimation.ComponentsEnum.reel_background, smashThePigAnimation.ReelBackground);
                    break;
                case 2:
                    this.registerContainerComponent(smashThePigAnimation.ComponentsEnum.win_cap_pop_up, smashThePigAnimation.WinCapPopUp);
                    break;
                default:
                    return false;
            }
            return true;
        };
        smashThePigAnimation.Animation.prototype.registerContainerComponent = function(componentEnum, componentClass) {
            var container = this.view.getComponentById(componentEnum[0]);
            if (container == null) return;
            this.component = _hcmn_.Type.createInstance(componentClass, [container]);
            this.componentId = componentEnum;
        };
        smashThePigAnimation.Animation.prototype.hide = function(e) {
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.view.getChildComponents();
                $r = this1.keys();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var key = $it0.next();
                this.view.getComponentById(key).hide();
            }
        };
        smashThePigAnimation.Animation.prototype.show = function(e) {
            var $it0 = (function($this) {
                var $r;
                var this1 = $this.view.getChildComponents();
                $r = this1.keys();
                return $r;
            }(this));
            while ($it0.hasNext()) {
                var key = $it0.next();
                this.view.getComponentById(key).show();
            }
        };
        smashThePigAnimation.Animation.prototype.getComponent = function() {
            return this.component;
        };
        smashThePigAnimation.Animation.prototype.__class__ = smashThePigAnimation.Animation;
        smashThePigAnimation.AnimationController = function(animation) {
            this.flag_addedToStage = false;
            this.animation = animation;
        };
        smashThePigAnimation.AnimationController.__name__ = ["smashThePigAnimation", "AnimationController"];
        smashThePigAnimation.AnimationController.prototype.flag_addedToStage = null;
        smashThePigAnimation.AnimationController.prototype.animation = null;
        smashThePigAnimation.AnimationController.prototype.init = function() {
            this.animation.port.getShow().subscribe($bind(this, this.handleShow));
            this.animation.port.getHide().subscribe($bind(this, this.handleHide));
        };
        smashThePigAnimation.AnimationController.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 = smashThePigAnimation.ExternalService.displayProvider.getStages();
                stage = this1.get(layerPayload.stage);
                var container;
                container = (function($this) {
                    var $r;
                    var this2 = $this.animation.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) continue;
                this.animation.getComponent().configure(cfg);
            }
            if (!this.flag_addedToStage) this.flag_addedToStage = true;
        };
        smashThePigAnimation.AnimationController.prototype.handleHide = function(e) {
            this.animation.getComponent().hide();
        };
        smashThePigAnimation.AnimationController.prototype.handleShow = function(e) {
            this.animation.getComponent().show(e.getPayload());
        };
        smashThePigAnimation.AnimationController.prototype.__class__ = smashThePigAnimation.AnimationController;
        smashThePigAnimation.AnimationFactory = function(vbf, context) {
            this.context = context;
            this.vbf = vbf;
        };
        smashThePigAnimation.AnimationFactory = ck_implements(smashThePigAnimation.AnimationFactory, clientkernelModulesApi.IService);
        smashThePigAnimation.AnimationFactory = ck_implements(smashThePigAnimation.AnimationFactory, componentmodelComponentApi.IComponentFactory);
        smashThePigAnimation.AnimationFactory.__interfaces__ = [clientkernelModulesApi.IService, componentmodelComponentApi.IComponentFactory];
        smashThePigAnimation.AnimationFactory.__name__ = ["smashThePigAnimation", "AnimationFactory"];
        smashThePigAnimation.AnimationFactory.prototype.vbf = null;
        smashThePigAnimation.AnimationFactory.prototype.context = null;
        smashThePigAnimation.AnimationFactory.prototype.getComponentDeclaration = function() {
            return smashthepigComponentsAnimationDeclaration.AnimationDeclaration;
        };
        smashThePigAnimation.AnimationFactory.prototype.createComponent = function(context) {
            var cfgId = context.getConfiguration();
            new smashThePigAnimation.Animation(context, this.vbf, cfgId);
        };
        smashThePigAnimation.AnimationFactory.prototype.__class__ = smashThePigAnimation.AnimationFactory;
        smashThePigAnimation.ExternalService = function() {};
        smashThePigAnimation.ExternalService.__name__ = ["smashThePigAnimation", "ExternalService"];
        smashThePigAnimation.ExternalService.displayProvider = null;
        smashThePigAnimation.ExternalService.assetRegistry = null;
        smashThePigAnimation.ExternalService.viewBuilderFactory = null;
        smashThePigAnimation.ExternalService.loadedCallback = null;
        smashThePigAnimation.ExternalService.initialize = function(context) {
            smashThePigAnimation.ExternalService.displayProvider = context.getAnyService(displayEngineApi.IDisplayProvider, null);
            smashThePigAnimation.ExternalService.assetRegistry = context.getAnyService(clientkernelLoaderApi.IAssetRegistry, null);
        };
        smashThePigAnimation.ExternalService.loadVBAssets = function(id, loadedCallback) {
            smashThePigAnimation.ExternalService.loadedCallback = loadedCallback;
            smashThePigAnimation.ExternalService.loading++;
            smashThePigAnimation.ExternalService.assetRegistry.getAsset(id).getContent().then(function(vba) {
                smashThePigAnimation.ExternalService.loadedAssets.set(id, vba);
                smashThePigAnimation.ExternalService.checkLoaded();
            });
        };
        smashThePigAnimation.ExternalService.checkLoaded = function() {
            smashThePigAnimation.ExternalService.totalLoaded++;
            if (smashThePigAnimation.ExternalService.totalLoaded == smashThePigAnimation.ExternalService.loading) smashThePigAnimation.ExternalService.loadedCallback();
        };
        smashThePigAnimation.ExternalService.prototype.__class__ = smashThePigAnimation.ExternalService;

        smashThePigAnimation.IAnimationComponent = function() {}
        smashThePigAnimation.IAnimationComponent.prototype = {

            show: function(state) {
                return {
                    arguments: ["*"],
                    returns: "void"
                };
            },
            hide: function() {
                return {
                    arguments: [],
                    returns: "void"
                };
            },
            configure: function(cfg) {
                return {
                    arguments: ["*"],
                    returns: "void"
                };
            }
        };
        smashThePigAnimation.ReelBackground = function(container) {
            this.container = container;
        };
        smashThePigAnimation.ReelBackground = ck_implements(smashThePigAnimation.ReelBackground, smashThePigAnimation.IAnimationComponent);
        smashThePigAnimation.ReelBackground.__interfaces__ = [smashThePigAnimation.IAnimationComponent];
        smashThePigAnimation.ReelBackground.__name__ = ["smashThePigAnimation", "ReelBackground"];
        smashThePigAnimation.ReelBackground.prototype.container = null;
        smashThePigAnimation.ReelBackground.prototype.show = function(payload) {
            this.container.show();
        };
        smashThePigAnimation.ReelBackground.prototype.hide = function() {
            this.container.hide();
        };
        smashThePigAnimation.ReelBackground.prototype.configure = function(config) {};
        smashThePigAnimation.ReelBackground.prototype.__class__ = smashThePigAnimation.ReelBackground;
        smashThePigAnimation.ReelForeground = function(container) {
            this.container = container;
            container.show();
            container.getDisplayObject().setCacheAsBitmap(true);
        };
        smashThePigAnimation.ReelForeground = ck_implements(smashThePigAnimation.ReelForeground, smashThePigAnimation.IAnimationComponent);
        smashThePigAnimation.ReelForeground.__interfaces__ = [smashThePigAnimation.IAnimationComponent];
        smashThePigAnimation.ReelForeground.__name__ = ["smashThePigAnimation", "ReelForeground"];
        smashThePigAnimation.ReelForeground.prototype.container = null;
        smashThePigAnimation.ReelForeground.prototype.show = function(payload) {
            this.container.show();
            this.container.getDisplayObject().setCacheAsBitmap(true);
        };
        smashThePigAnimation.ReelForeground.prototype.hide = function() {
            this.container.hide();
            this.container.getDisplayObject().setCacheAsBitmap(false);
        };
        smashThePigAnimation.ReelForeground.prototype.configure = function(config) {};
        smashThePigAnimation.ReelForeground.prototype.__class__ = smashThePigAnimation.ReelForeground;
        smashThePigAnimation.WinCapPopUp = function(container) {
            this.container = container;
            container.hide();
        };
        smashThePigAnimation.WinCapPopUp = ck_implements(smashThePigAnimation.WinCapPopUp, smashThePigAnimation.IAnimationComponent);
        smashThePigAnimation.WinCapPopUp.__interfaces__ = [smashThePigAnimation.IAnimationComponent];
        smashThePigAnimation.WinCapPopUp.__name__ = ["smashThePigAnimation", "WinCapPopUp"];
        smashThePigAnimation.WinCapPopUp.prototype.container = null;
        smashThePigAnimation.WinCapPopUp.prototype.show = function(payload) {
            this.container.show();
            var labelsContainer = this.container.createContainerFromStoredConfig("labels");
            this.container.addChildComponent(labelsContainer, "labels");
            var label = labelsContainer.getComponentById("WinCapPopUpMessage_2");
            var labelShadow = labelsContainer.getComponentById("WinCapPopUpMessage_2_SHADOW");
            var text = payload.data;
            label.setText(text);
            labelShadow.setText(text);
        };
        smashThePigAnimation.WinCapPopUp.prototype.hide = function() {
            this.container.hide();
            if (this.container.getComponentById("labels") != null) {
                var labelsContainer = this.container.getComponentById("labels");
                var $it0 = (function($this) {
                    var $r;
                    var this1 = labelsContainer.getChildComponents();
                    $r = this1.keys();
                    return $r;
                }(this));
                while ($it0.hasNext()) {
                    var key = $it0.next();
                    labelsContainer.disposeChildComponent(key);
                }
                labelsContainer.dispose();
                this.container.disposeChildComponent("labels");
            }
        };
        smashThePigAnimation.WinCapPopUp.prototype.configure = function(config) {};
        smashThePigAnimation.WinCapPopUp.prototype.__class__ = smashThePigAnimation.WinCapPopUp;
        smashThePigAnimation.ComponentsEnum = {
            __ename__: ["smashThePigAnimation", "ComponentsEnum"],
            __constructs__: ["reel_background", "reel_foreground", "win_cap_pop_up", "COMPANY_LOGO"]
        };
        smashThePigAnimation.ComponentsEnum.win_cap_pop_up = ["win_cap_pop_up", 2];
        smashThePigAnimation.ComponentsEnum.win_cap_pop_up.toString = $estr;
        smashThePigAnimation.ComponentsEnum.win_cap_pop_up.__enum__ = smashThePigAnimation.ComponentsEnum;
        smashThePigAnimation.ComponentsEnum.reel_background = ["reel_background", 0];
        smashThePigAnimation.ComponentsEnum.reel_background.toString = $estr;
        smashThePigAnimation.ComponentsEnum.reel_background.__enum__ = smashThePigAnimation.ComponentsEnum;
        smashThePigAnimation.ComponentsEnum.reel_foreground = ["reel_foreground", 1];
        smashThePigAnimation.ComponentsEnum.reel_foreground.toString = $estr;
        smashThePigAnimation.ComponentsEnum.reel_foreground.__enum__ = smashThePigAnimation.ComponentsEnum;
        smashThePigAnimation.ComponentsEnum.COMPANY_LOGO = ["COMPANY_LOGO", 3];
        smashThePigAnimation.ComponentsEnum.COMPANY_LOGO.toString = $estr;
        smashThePigAnimation.ComponentsEnum.COMPANY_LOGO.__enum__ = smashThePigAnimation.ComponentsEnum;
        smashThePigAnimation.ExternalService.loadedAssets = new _hcmn_.haxe_ds_StringMap();;
        smashThePigAnimation.ExternalService.loading = 0;;
        smashThePigAnimation.ExternalService.totalLoaded = 0;;
        return {
            exports: smashThePigAnimation,
            activator: smashThePigAnimation.Activator
        };
    });
//# sourceURL=smashThePigAnimation.js