define("soundManagerLoader", ["clientkernelLoaderApi", "clientkernelLoaderApiPlugins", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(clientkernelLoaderApi, clientkernelLoaderApiPlugins, 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 = {

        };
        if (typeof soundManagerLoader == 'undefined') {
            var soundManagerLoader = {};
        };
        soundManagerLoader.Activator = function(context) {};
        soundManagerLoader.Activator = ck_implements(soundManagerLoader.Activator, clientkernelModulesApi.IModuleActivator);
        soundManagerLoader.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        soundManagerLoader.Activator.__name__ = ["soundManagerLoader", "Activator"];
        soundManagerLoader.Activator.prototype.start = function(context) {
            context.registerService(new soundManagerLoader.SoundLoaderPlugin(), clientkernelLoaderApiPlugins.IAssetPlugin, null);
            context.registerService(new soundManagerLoader.SoundPackLoaderPlugin(), clientkernelLoaderApiPlugins.IAssetPlugin, null);
        };
        soundManagerLoader.Activator.prototype.stop = function(context) {};
        soundManagerLoader.Activator.main = function() {};
        soundManagerLoader.Activator.prototype.__class__ = soundManagerLoader.Activator;
        soundManagerLoader.SoundLoader = function() {
            this.types = ["mp3", "ogg"];
        };
        soundManagerLoader.SoundLoader = ck_implements(soundManagerLoader.SoundLoader, clientkernelLoaderApiPlugins.IAssetLoader);
        soundManagerLoader.SoundLoader.__interfaces__ = [clientkernelLoaderApiPlugins.IAssetLoader];
        soundManagerLoader.SoundLoader.__name__ = ["soundManagerLoader", "SoundLoader"];
        soundManagerLoader.SoundLoader.prototype.lc = null;
        soundManagerLoader.SoundLoader.prototype.id = null;
        soundManagerLoader.SoundLoader.prototype.onfinish = null;
        soundManagerLoader.SoundLoader.prototype.url = null;
        soundManagerLoader.SoundLoader.prototype.asset = null;
        soundManagerLoader.SoundLoader.prototype.types = null;
        soundManagerLoader.SoundLoader.prototype.howl = null;
        soundManagerLoader.SoundLoader.prototype.setup = function(lc, id, type, url, config, onrequest) {
            lc.getVars().set("browserIE", this.checkIsIE());
            this.url = url;
            this.lc = lc;
            this.id = id;
            lc.getAssets().add("soundmaps", url, "pack", null);
            this.asset = lc.getAssets().add(id, url, type, onrequest, 0);
            if (config != null) {
                if (Object.prototype.hasOwnProperty.call(config, "types")) this.types = _hcmn_.Reflect.field(config, "types");
            }
        };
        soundManagerLoader.SoundLoader.prototype.load = function(onfinish) {
            var _g = this;
            this.onfinish = onfinish;
            if (!this.checkIsIE()) this.lc.getLoader().addQueue("soundmaps", [{
                id: "soundmap",
                type: "preload-asset",
                url: this.url.substring(this.url.lastIndexOf("/") + 1) + ".soundmap.json"
            }], this.url.substring(0, this.url.lastIndexOf("/")), $bind(this, this.finishedMap));
            else _hcmn_.haxe_Timer.delay(function() {
                _g.howlCreateIE();
            }, 100);
        };
        soundManagerLoader.SoundLoader.prototype.unload = function() {
            this.lc.getAssets().remove(this.id);
        };
        soundManagerLoader.SoundLoader.prototype.finishedMap = function() {
            var _g = this;
            this.lc.getAssets().getAsset("soundmap").getContent().then(function(map) {
                var urls = [];
                var _g1 = 0;
                var _g2 = _g.types;
                while (_g1 < _g2.length) {
                    var t = _g2[_g1];
                    ++_g1;
                    urls.push(_g.url + "." + t);
                }
                _g.howl = new Howl({
                    src: urls,
                    sprite: map,
                    onload: $bind(_g, _g.handleComplete)
                });
            });
        };
        soundManagerLoader.SoundLoader.prototype.howlCreateIE = function() {
            var urls = [];
            var _g = 0;
            var _g1 = this.types;
            while (_g < _g1.length) {
                var t = _g1[_g];
                ++_g;
                urls.push(this.url + "." + t);
            }
            this.howl = new Howl({
                src: urls,
                onload: $bind(this, this.handleComplete)
            });
        };
        soundManagerLoader.SoundLoader.prototype.handleComplete = function() {
            this.asset.setContent(this.howl);
            if (this.onfinish != null) this.onfinish();
        };
        soundManagerLoader.SoundLoader.prototype.checkIsIE = function() {
            var ua = window.navigator.userAgent;
            var trident = ua.indexOf("Trident/");
            if (trident > -1) return true;
            else return false;
        };
        soundManagerLoader.SoundLoader.prototype.__class__ = soundManagerLoader.SoundLoader;
        soundManagerLoader.SoundLoaderPlugin = function() {};
        soundManagerLoader.SoundLoaderPlugin = ck_implements(soundManagerLoader.SoundLoaderPlugin, clientkernelModulesApi.IService);
        soundManagerLoader.SoundLoaderPlugin = ck_implements(soundManagerLoader.SoundLoaderPlugin, clientkernelLoaderApiPlugins.IAssetPlugin);
        soundManagerLoader.SoundLoaderPlugin.__interfaces__ = [clientkernelModulesApi.IService, clientkernelLoaderApiPlugins.IAssetPlugin];
        soundManagerLoader.SoundLoaderPlugin.__name__ = ["soundManagerLoader", "SoundLoaderPlugin"];
        soundManagerLoader.SoundLoaderPlugin.prototype.getAssetTypes = function() {
            return ["sound"];
        };
        soundManagerLoader.SoundLoaderPlugin.prototype.createLoader = function() {
            return new soundManagerLoader.SoundLoader();
        };
        soundManagerLoader.SoundLoaderPlugin.prototype.__class__ = soundManagerLoader.SoundLoaderPlugin;
        soundManagerLoader.SoundPackLoader = function() {};
        soundManagerLoader.SoundPackLoader = ck_implements(soundManagerLoader.SoundPackLoader, clientkernelLoaderApiPlugins.IAssetLoader);
        soundManagerLoader.SoundPackLoader.__interfaces__ = [clientkernelLoaderApiPlugins.IAssetLoader];
        soundManagerLoader.SoundPackLoader.__name__ = ["soundManagerLoader", "SoundPackLoader"];
        soundManagerLoader.SoundPackLoader.prototype.lc = null;
        soundManagerLoader.SoundPackLoader.prototype.id = null;
        soundManagerLoader.SoundPackLoader.prototype.url = null;
        soundManagerLoader.SoundPackLoader.prototype.config = null;
        soundManagerLoader.SoundPackLoader.prototype.onfinish = null;
        soundManagerLoader.SoundPackLoader.prototype.asset = null;
        soundManagerLoader.SoundPackLoader.prototype.soundMap = null;
        soundManagerLoader.SoundPackLoader.prototype.setup = function(lc, id, type, url, config, onrequest) {
            lc.getVars().set("browserIE", this.checkIsIE());
            this.lc = lc;
            this.id = id;
            this.url = url;
            this.config = config;
            this.soundMap = new _hcmn_.haxe_ds_StringMap();
            this.asset = lc.getAssets().add(id, url, type, onrequest, 0);
            this.addSounds();
        };
        soundManagerLoader.SoundPackLoader.prototype.addSounds = function() {
            var _g = this;
            if (!this.config.loader.length) this.complete();
            else this.lc.getAssets().getAsset(this.config.loader[0].id).getContent().then(function(sound) {
                _g.soundMap.set(_g.config.loader[0].id, sound);
                _g.config.loader.shift();
                _g.addSounds();
            });
        };
        soundManagerLoader.SoundPackLoader.prototype.load = function(onfinish) {
            this.onfinish = onfinish;
            this.lc.getLoader().addQueue(this.id, this.config.loader, this.url, $bind(this, this.onFinished));
        };
        soundManagerLoader.SoundPackLoader.prototype.unload = function() {
            this.lc.getAssets().remove(this.id);
        };
        soundManagerLoader.SoundPackLoader.prototype.onFinished = function() {
            null;
        };
        soundManagerLoader.SoundPackLoader.prototype.complete = function() {
            this.asset.setContent(this.soundMap);
            this.onfinish();
        };
        soundManagerLoader.SoundPackLoader.prototype.checkIsIE = function() {
            var ua = window.navigator.userAgent;
            var trident = ua.indexOf("Trident/");
            if (trident > -1) return true;
            else return false;
        };
        soundManagerLoader.SoundPackLoader.prototype.__class__ = soundManagerLoader.SoundPackLoader;
        soundManagerLoader.SoundPackLoaderPlugin = function() {};
        soundManagerLoader.SoundPackLoaderPlugin = ck_implements(soundManagerLoader.SoundPackLoaderPlugin, clientkernelModulesApi.IService);
        soundManagerLoader.SoundPackLoaderPlugin = ck_implements(soundManagerLoader.SoundPackLoaderPlugin, clientkernelLoaderApiPlugins.IAssetPlugin);
        soundManagerLoader.SoundPackLoaderPlugin.__interfaces__ = [clientkernelModulesApi.IService, clientkernelLoaderApiPlugins.IAssetPlugin];
        soundManagerLoader.SoundPackLoaderPlugin.__name__ = ["soundManagerLoader", "SoundPackLoaderPlugin"];
        soundManagerLoader.SoundPackLoaderPlugin.prototype.getAssetTypes = function() {
            return ["sound-pack"];
        };
        soundManagerLoader.SoundPackLoaderPlugin.prototype.createLoader = function() {
            return new soundManagerLoader.SoundPackLoader();
        };
        soundManagerLoader.SoundPackLoaderPlugin.prototype.__class__ = soundManagerLoader.SoundPackLoaderPlugin;
        return {
            exports: soundManagerLoader,
            activator: soundManagerLoader.Activator
        };
    });
//# sourceURL=soundManagerLoader.js