define("viewBuilderLoader", ["viewBuilderApi", "clientkernelLoaderApi", "clientkernelLoaderApiPlugins", "clientkernelEventbusApi", "clientkernelModulesApi"],
    function(viewBuilderApi, 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 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 viewBuilderLoader == 'undefined') {
            var viewBuilderLoader = {};
        };
        viewBuilderLoader.Activator = function(context) {};
        viewBuilderLoader.Activator = ck_implements(viewBuilderLoader.Activator, clientkernelModulesApi.IModuleActivator);
        viewBuilderLoader.Activator.__interfaces__ = [clientkernelModulesApi.IModuleActivator];
        viewBuilderLoader.Activator.__name__ = ["viewBuilderLoader", "Activator"];
        viewBuilderLoader.Activator.prototype.start = function(context) {
            context.registerService(new viewBuilderLoader.ViewBuilderLoaderPlugin(), clientkernelLoaderApiPlugins.IAssetPlugin, null);
        };
        viewBuilderLoader.Activator.prototype.stop = function(context) {};
        viewBuilderLoader.Activator.main = function() {};
        viewBuilderLoader.Activator.prototype.__class__ = viewBuilderLoader.Activator;
        viewBuilderLoader.ViewBuilderAssets = function(lc) {
            this.lc = lc;
            this.spritesheetJSONs = new _hcmn_.haxe_ds_StringMap();
            this.spritesheetImages = new _hcmn_.haxe_ds_StringMap();
            this.particlesJSONs = new _hcmn_.haxe_ds_StringMap();
            this.particlesAnimationJSONs = new _hcmn_.haxe_ds_StringMap();
            this.customJSONs = new _hcmn_.haxe_ds_StringMap();
            this.customJSONs.get("1");
        };
        viewBuilderLoader.ViewBuilderAssets = ck_implements(viewBuilderLoader.ViewBuilderAssets, viewBuilderApi.IViewBuilderAssets);
        viewBuilderLoader.ViewBuilderAssets.__interfaces__ = [viewBuilderApi.IViewBuilderAssets];
        viewBuilderLoader.ViewBuilderAssets.__name__ = ["viewBuilderLoader", "ViewBuilderAssets"];
        viewBuilderLoader.ViewBuilderAssets.prototype.lc = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.config = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.assets = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.spritesheetJSONs = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.spritesheetImages = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.particlesJSONs = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.particlesAnimationJSONs = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.customJSONs = null;
        viewBuilderLoader.ViewBuilderAssets.prototype.setup = function(id) {
            var _g = this;
            return this.lc.getAssets().getAsset(id).getAllContent().then(function(assets) {
                _g.config = _hcmn_.__map_reserved.viewbuilder != null ? assets.getReserved("viewbuilder") : assets.h["viewbuilder"];
                _g.assets = assets;
                _g.loadViewBuilderSpritesheets(_g.config);
                _g.loadParticles(_g.config);
            });
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.loadViewBuilderSpritesheets = function(cfg) {
            if (cfg != null && cfg.spritesheets != null) {
                var len = _hcmn_.Lambda.count(_hcmn_.js_Boot.__cast(cfg.spritesheets, Array));
                var _g = 0;
                while (_g < len) {
                    var k = _g++;
                    var ssId = cfg.spritesheets[k];
                    var value = this.assets.get(ssId + "_spritesheet" + "_img");
                    this.spritesheetImages.set(ssId, value);
                    var value1 = this.assets.get(ssId + "_spritesheet" + "_json");
                    this.spritesheetJSONs.set(ssId, value1);
                }
            }
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.loadParticles = function(cfg) {
            if (cfg != null && cfg.particles != null) {
                var len = _hcmn_.Lambda.count(_hcmn_.js_Boot.__cast(cfg.particles, Array));
                var _g = 0;
                while (_g < len) {
                    var k = _g++;
                    var paId = cfg.particles[k];
                    var value = this.assets.get(paId + "_json");
                    this.particlesJSONs.set(paId, value);
                    var value1 = this.assets.get(paId + "_animation" + "_json");
                    this.particlesAnimationJSONs.set(paId, value1);
                }
            }
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.getConfiguration = function() {
            return this.config;
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.getSpritesheetImages = function() {
            return this.spritesheetImages;
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.getSpritesheetJSONs = function() {
            return this.spritesheetJSONs;
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.getCustomJSONs = function() {
            return this.customJSONs;
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.getParticlesAnimationJSONs = function() {
            return this.particlesAnimationJSONs;
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.getParticlesJSONs = function() {
            return this.particlesJSONs;
        };
        viewBuilderLoader.ViewBuilderAssets.prototype.__class__ = viewBuilderLoader.ViewBuilderAssets;
        viewBuilderLoader.ViewBuilderLoader = function() {
            this.isLoaded = false;
        };
        viewBuilderLoader.ViewBuilderLoader = ck_implements(viewBuilderLoader.ViewBuilderLoader, clientkernelLoaderApiPlugins.IAssetLoader);
        viewBuilderLoader.ViewBuilderLoader.__interfaces__ = [clientkernelLoaderApiPlugins.IAssetLoader];
        viewBuilderLoader.ViewBuilderLoader.__name__ = ["viewBuilderLoader", "ViewBuilderLoader"];
        viewBuilderLoader.ViewBuilderLoader.prototype.lc = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.id = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.type = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.url = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.config = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.onrequest = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.onfinish = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.isLoaded = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.asset = null;
        viewBuilderLoader.ViewBuilderLoader.prototype.setup = function(lc, id, type, url, config, onrequest) {
            this.lc = lc;
            this.id = id;
            this.type = type;
            this.url = url;
            this.config = config;
            this.asset = lc.getAssets().add(id, url, type, onrequest, 0);
            var vbId = url.substring(url.lastIndexOf("/") + 1);
            var vbIdStripped = _hcmn_.StringTools.replace(vbId, ".viewbuilder.json", "");
            if (config == null) {
                config = {};
                config.loader = [];
                config.loader.push({
                    id: vbIdStripped + "_spritesheet" + "_img",
                    type: "preload-asset",
                    url: vbIdStripped + "_spritesheet" + ".png"
                });
                config.loader.push({
                    id: vbIdStripped + "_spritesheet" + "_json",
                    type: "preload-asset",
                    url: vbIdStripped + "_spritesheet" + ".json"
                });
                this.config = config;
            }
            this.config.loader.splice(0, 0, {
                id: "viewbuilder",
                type: "preload-asset",
                url: vbId
            });
            this.onrequest = onrequest;
        };
        viewBuilderLoader.ViewBuilderLoader.prototype.simpleId = function(id) {
            if (id.indexOf("/") == -1) return id;
            else return id.substring(id.lastIndexOf("/") + 1);
        };
        viewBuilderLoader.ViewBuilderLoader.prototype.load = function(onfinish) {
            this.onfinish = onfinish;
            this.lc.getLoader().addQueue(this.id, this.config.loader, this.url.substring(0, this.url.lastIndexOf("/")), $bind(this, this.onFinished));
        };
        viewBuilderLoader.ViewBuilderLoader.prototype.unload = function() {
            this.lc.getAssets().remove(this.id);
        };
        viewBuilderLoader.ViewBuilderLoader.prototype.onFinished = function() {
            var _g = this;
            if (this.onfinish != null) {
                this.isLoaded = true;
                var vba = new viewBuilderLoader.ViewBuilderAssets(this.lc);
                vba.setup(this.id).then(function(data) {
                    _g.asset.setContent(vba);
                    _g.onfinish();
                });
            }
        };
        viewBuilderLoader.ViewBuilderLoader.prototype.__class__ = viewBuilderLoader.ViewBuilderLoader;
        viewBuilderLoader.ViewBuilderLoaderPlugin = function() {
            this.loaders = [];
        };
        viewBuilderLoader.ViewBuilderLoaderPlugin = ck_implements(viewBuilderLoader.ViewBuilderLoaderPlugin, clientkernelModulesApi.IService);
        viewBuilderLoader.ViewBuilderLoaderPlugin = ck_implements(viewBuilderLoader.ViewBuilderLoaderPlugin, clientkernelLoaderApiPlugins.IAssetPlugin);
        viewBuilderLoader.ViewBuilderLoaderPlugin.__interfaces__ = [clientkernelModulesApi.IService, clientkernelLoaderApiPlugins.IAssetPlugin];
        viewBuilderLoader.ViewBuilderLoaderPlugin.__name__ = ["viewBuilderLoader", "ViewBuilderLoaderPlugin"];
        viewBuilderLoader.ViewBuilderLoaderPlugin.prototype.loaders = null;
        viewBuilderLoader.ViewBuilderLoaderPlugin.prototype.getAssetTypes = function() {
            return ["viewbuilder"];
        };
        viewBuilderLoader.ViewBuilderLoaderPlugin.prototype.createLoader = function() {
            var loader = new viewBuilderLoader.ViewBuilderLoader();
            this.loaders.push(loader);
            return loader;
        };
        viewBuilderLoader.ViewBuilderLoaderPlugin.prototype.__class__ = viewBuilderLoader.ViewBuilderLoaderPlugin;
        viewBuilderLoader.ViewBuilderAssets.SKELETON_SUFIX = "_skeleton";;
        viewBuilderLoader.ViewBuilderAssets.JSON_SUFIX = "_json";;
        viewBuilderLoader.ViewBuilderAssets.IMG_SUFIX = "_img";;
        viewBuilderLoader.ViewBuilderAssets.SPRITESHEET_SUFIX = "_spritesheet";;
        viewBuilderLoader.ViewBuilderAssets.PARTICLES_SUFIX = "_particles";;
        viewBuilderLoader.ViewBuilderAssets.CUSTOM_SUFIX = "_custom";;
        viewBuilderLoader.ViewBuilderLoader.JSON_EXTENSION = ".json";;
        viewBuilderLoader.ViewBuilderLoader.IMG_EXTENSION = ".png";;
        return {
            exports: viewBuilderLoader,
            activator: viewBuilderLoader.Activator
        };
    });