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);
        };
        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) {
            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);
            if (config != null) {
                if (Object.prototype.hasOwnProperty.call(config, "types")) this.types = _hcmn_.Reflect.field(config, "types");
            }
        };
        soundManagerLoader.SoundLoader.prototype.load = function(onfinish) {
            this.onfinish = onfinish;
            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));
        };
        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.handleComplete = function() {
            this.asset.setContent(this.howl);
            if (this.onfinish != null) this.onfinish();
        };
        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;
        return {
            exports: soundManagerLoader,
            activator: soundManagerLoader.Activator
        };
    });
//# sourceURL=soundManagerLoader.js