var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var fl;
(function (fl) {
    var FlashObject = (function (_super) {
        __extends(FlashObject, _super);
        function FlashObject() {
            _super.apply(this, arguments);
        }
        return FlashObject;
    }(PIXI.Container));
    fl.FlashObject = FlashObject;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var FrameLabel = (function () {
        function FrameLabel() {
        }
        return FrameLabel;
    }());
    fl.FrameLabel = FrameLabel;
    var FrameObject = (function (_super) {
        __extends(FrameObject, _super);
        function FrameObject() {
            _super.apply(this, arguments);
        }
        FrameObject.prototype.gotoLabel = function (label) {
            var n = this.labels.length;
            for (var i = 0; i < n; i++) {
                if (this.labels[i].name == label) {
                    this.currentFrame = this.labels[i].frame;
                    return true;
                }
            }
            return false;
        };
        FrameObject.prototype.stepForward = function () {
            if (this.currentFrame + 1 < this.totalFrames)
                this.currentFrame = this.currentFrame + 1;
            else
                this.currentFrame = 0;
            return this;
        };
        FrameObject.prototype.stepBackward = function () {
            if (this.currentFrame > 0)
                this.currentFrame = this.currentFrame - 1;
            else
                this.currentFrame = this.totalFrames - 1;
            return this;
        };
        FrameObject.prototype.gotoNextFrame = function () {
            if (this.currentFrame + 1 < this.totalFrames)
                this.currentFrame = this.currentFrame + 1;
            return this;
        };
        FrameObject.prototype.gotoPrevFrame = function () {
            if (this.currentFrame > 0)
                this.currentFrame = this.currentFrame - 1;
            return this;
        };
        FrameObject.prototype.gotoFirstFrame = function () {
            this.currentFrame = 0;
            return this;
        };
        FrameObject.prototype.gotoLastFrame = function () {
            this.currentFrame = this.totalFrames - 1;
            return this;
        };
        FrameObject.prototype.gotoRandomFrame = function () {
            this.currentFrame = (Math.random() * this.totalFrames) | 0;
            return this;
        };
        FrameObject.prototype.isFirstFrame = function () {
            return this.currentFrame == 0;
        };
        FrameObject.prototype.isLastFrame = function () {
            return this.currentFrame == this.totalFrames - 1;
        };
        return FrameObject;
    }(fl.FlashObject));
    fl.FrameObject = FrameObject;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Animation = (function () {
        function Animation(target) {
            this.ticksPerFrame = Animation.defaultTicksPerFrame;
            this.isActive = false;
            this._innerActive = true;
            this._innerJump = undefined;
            this._innerCond = undefined;
            this._target = target;
        }
        Animation.prototype.parseCondition = function (raw) {
            if (this._innerCond === undefined) {
                this._innerCond = Number(raw);
                if (isNaN(this._innerCond)) {
                    this._innerCond = raw;
                    Animation.signals[this._innerCond] = undefined;
                }
            }
        };
        Animation.prototype.parseJump = function (raw) {
            this._innerJump = Number(raw) - 1;
            if (isNaN(this._innerJump))
                this._innerJump = raw;
        };
        Animation.prototype.applyControlLabel = function (label) {
            if (label === "#stop") {
                this._innerActive = false;
                this.isActive = false;
            }
            else if (label.indexOf("#loop") == 0) {
                var params = label.split("_");
                this.parseJump(params[1]);
                this.parseCondition(params[2]);
            }
            else if (label.indexOf("#wait") == 0) {
                var params = label.split("_");
                this._innerJump = this._target.currentFrame;
                this.parseCondition(params[1]);
            }
            else if (label.indexOf("#send") == 0) {
                var signal = label.split("_")[1];
                Animation.signals[signal] = 1;
            }
        };
        Animation.prototype.updateByParent = function () {
            if (!this._innerActive)
                return;
            if (this._innerJump === undefined) {
                this._target.stepForward();
                return;
            }
            var isLoopExit = (this._innerCond == 0)
                || Animation.signals[this._innerCond] == 1;
            if (isLoopExit) {
                this._target.stepForward();
                this._innerCond = undefined;
                this._innerJump = undefined;
                return;
            }
            var isWaiting = this._innerJump === this._target.currentFrame;
            if (!isWaiting) {
                if (typeof (this._innerJump) == "string")
                    this._target.gotoLabel(this._innerJump);
                else
                    this._target.currentFrame = this._innerJump;
                this._innerJump = undefined;
            }
            if (this._innerCond > 0)
                this._innerCond = this._innerCond - 1;
        };
        Animation.prototype.update = function () {
            if (++this._tickCounter < this.ticksPerFrame)
                return;
            this._tickCounter = 0;
            if (this._innerJump !== undefined) {
                this.updateByParent();
            }
            else {
                var currentFrame = this._target.currentFrame;
                if (!this._looping && currentFrame == this._endFrame) {
                    this.stop();
                    if (this._completeHandler)
                        this._completeHandler(this);
                    return;
                }
                var nextFrame = currentFrame + this._step;
                if (nextFrame < 0)
                    nextFrame = this._target.totalFrames - 1;
                else if (nextFrame >= this._target.totalFrames)
                    nextFrame = 0;
                this._target.currentFrame = nextFrame;
            }
        };
        Animation.prototype.playTo = function (endFrame) {
            this._looping = false;
            this._endFrame = fl.Internal.clampRange(endFrame, 0, this._target.totalFrames - 1);
            this._step = this._endFrame > this._target.currentFrame ? 1 : -1;
            this.isActive = true;
        };
        Animation.prototype.playLoop = function (step) {
            this._looping = true;
            this._step = step;
            this.isActive = true;
        };
        Animation.prototype.stop = function () {
            this.isActive = false;
        };
        Animation.prototype.play = function () {
            this.playLoop(1);
        };
        Animation.prototype.playReverse = function () {
            this.playLoop(-1);
        };
        Animation.prototype.playToBegin = function () {
            this.playTo(0);
        };
        Animation.prototype.playToEnd = function () {
            this.playTo(this._target.totalFrames - 1);
        };
        Animation.prototype.playFromBeginToEnd = function () {
            this._target.currentFrame = 0;
            this.playToEnd();
        };
        Animation.prototype.playFromEndToBegin = function () {
            this._target.currentFrame = this._target.totalFrames - 1;
            this.playToBegin();
        };
        Animation.prototype.gotoAndStop = function (frameNum) {
            this._target.currentFrame = frameNum;
            this.stop();
        };
        Animation.prototype.gotoAndPlay = function (frameNum) {
            this._target.currentFrame = frameNum;
            this.play();
        };
        Animation.prototype.onComplete = function (handler) {
            this._completeHandler = handler;
            return this;
        };
        Animation.defaultTicksPerFrame = 1;
        Animation.signals = {};
        return Animation;
    }());
    fl.Animation = Animation;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Resource = (function () {
        function Resource(id) {
            this._id = id;
        }
        Resource.prototype.createInstance = function () {
            throw new Error("Not implemented");
        };
        Resource.prototype.dispose = function () {
            throw new Error("Not implemented");
        };
        Object.defineProperty(Resource.prototype, "id", {
            get: function () {
                return this._id;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Resource.prototype, "name", {
            get: function () {
                var id = this._id;
                return id.substr(id.lastIndexOf("/") + 1);
            },
            enumerable: true,
            configurable: true
        });
        return Resource;
    }());
    fl.Resource = Resource;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var PlaceholderResource = (function (_super) {
        __extends(PlaceholderResource, _super);
        function PlaceholderResource(id) {
            _super.call(this, id);
        }
        PlaceholderResource.prototype.createInstance = function () {
            return new fl.Placeholder();
        };
        PlaceholderResource.prototype.dispose = function () {
        };
        return PlaceholderResource;
    }(fl.Resource));
    fl.PlaceholderResource = PlaceholderResource;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Bundle = (function () {
        function Bundle(name) {
            this.textures = {};
            this.resources = {};
            this.name = name;
        }
        Bundle.createPlaceholders = function () {
            var bundle = new Bundle("placeholders");
            bundle.resources["placeholders/empty"] = new fl.PlaceholderResource("placeholders/empty");
            return bundle;
        };
        Bundle.load = function (bundleName, onComplete) {
            console.log("Bundle.load: " + bundleName);
            var bundle = Bundle._bundles[bundleName];
            if (bundle)
                throw new Error("Bundle is already loaded: " + bundleName);
            bundle = new Bundle(bundleName);
            Bundle._bundles[bundleName] = bundle;
            bundle.load(onComplete);
        };
        Bundle.unload = function (bundleName) {
            console.log("Bundle.unload: " + bundleName);
            var bundle = Bundle._bundles[bundleName];
            if (!bundle)
                return;
            Bundle._bundles[bundleName] = null;
            bundle.unload();
        };
        Bundle.getResource = function (resourceId) {
            var bundleId = resourceId.substr(0, resourceId.indexOf('/'));
            var bundle = Bundle._bundles[bundleId];
            if (!bundle)
                throw new Error('Bundle is not loaded: ' + resourceId);
            var res = bundle.resources[resourceId];
            if (res == null)
                throw new Error('Resource not found: ' + resourceId);
            return res;
        };
        Bundle.createFlashObject = function (id) {
            var res = Bundle.getResource(id);
            if (res instanceof fl.SpriteResource)
                return new fl.Sprite(res);
            else if (res instanceof fl.ClipResource)
                new fl.Clip(res);
            else
                throw new Error('Unknown resource type: ' + id);
        };
        Bundle.createSprite = function (id) {
            var res = Bundle.getResource(id);
            if (!(res instanceof fl.SpriteResource))
                throw new Error('Resource is not a Sprite: ' + id);
            return new fl.Sprite(res);
        };
        Bundle.createClip = function (id) {
            var res = Bundle.getResource(id);
            if (!(res instanceof fl.ClipResource))
                throw new Error('Resource is not a Clip: ' + id);
            return new fl.Clip(res);
        };
        Bundle.prototype.load = function (onComplete) {
            this.completeHandler = onComplete;
            this.loadResources();
        };
        Bundle.prototype.unload = function () {
            var _this = this;
            Object.keys(this.resources)
                .forEach(function (key) { return _this.resources[key].dispose(); });
            Object.keys(this.textures)
                .forEach(function (key) { return _this.textures[key].destroy(true); });
            this.resources = {};
            this.textures = {};
        };
        Bundle.prototype.loadResources = function () {
            var _this = this;
            var url = this.getUrl('bundle.json');
            this.verboseLog('loading: ' + url);
            new PIXI.loaders.Loader().add('json', url).load(function (loader, resources) {
                _this.verboseLog('OK: ' + url);
                _this.rawData = resources['json'].data;
                if (_this.rawData)
                    _this.loadTextures();
            });
        };
        Bundle.prototype.loadTextures = function () {
            var _this = this;
            this.textures = {};
            var names = this.rawData["textures"];
            var loader = new PIXI.loaders.Loader;
            var _loop_1 = function(textureName) {
                url = this_1.getUrl(textureName + Bundle.textureExt);
                this_1.verboseLog('loading: ' + url);
                loader.add(textureName, url, function () {
                    _this.textures[textureName] = loader.resources[textureName].texture;
                    _this.verboseLog("OK: " + textureName);
                });
            };
            var this_1 = this;
            var url;
            for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
                var textureName = names_1[_i];
                _loop_1(textureName);
            }
            loader.load(function () {
                _this.createResources();
                _this.complete();
            });
        };
        Bundle.prototype.complete = function () {
            this.rawData = null;
            if (this.completeHandler != null)
                this.completeHandler();
        };
        Bundle.prototype.createResources = function () {
            for (var _i = 0, _a = this.rawData['symbols']; _i < _a.length; _i++) {
                var symbol = _a[_i];
                var id = symbol.path;
                this.resources[id] = this.createResource(symbol);
            }
        };
        Bundle.prototype.createResource = function (json) {
            var type = json.type;
            if (type == "sprite") {
                var textureName = json.texture;
                var texture = this.textures[textureName];
                if (!texture)
                    throw new Error("Unknown texture: " + textureName);
                return fl.SpriteResource.fromJson(json, texture);
            }
            if (type == "clip")
                return fl.ClipResource.fromJson(json);
            throw new Error("Unknown resource type: " + type);
        };
        Bundle.prototype.verboseLog = function (message) {
            if (Bundle.verboseLog)
                console.log("| " + message);
        };
        Bundle.prototype.getUrl = function (assetName) {
            return Bundle.rootPath + "/" + this.name + "/" + assetName + "?v=" + Bundle.version;
        };
        Bundle.version = "0";
        Bundle.rootPath = "assets";
        Bundle.textureExt = ".png";
        Bundle.verboseLog = true;
        Bundle._bundles = {
            "placeholders": Bundle.createPlaceholders()
        };
        return Bundle;
    }());
    fl.Bundle = Bundle;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Container = (function (_super) {
        __extends(Container, _super);
        function Container() {
            _super.apply(this, arguments);
            this.timelineIndex = -1;
            this.labels = fl.Internal.EMPTY_ARRAY;
            this.color = new fl.Color(1, 1, 1, 1);
            this.isFlashObject = true;
            this.isFrameObject = false;
            this.scaleMultiplier = 1;
            this.globalColor = {};
        }
        Object.defineProperty(Container.prototype, "scaleX", {
            get: function () { return this.scale.x * this.scaleMultiplier; },
            set: function (value) { this.scale.x = value / this.scaleMultiplier; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Container.prototype, "scaleY", {
            get: function () { return this.scale.y * this.scaleMultiplier; },
            set: function (value) { this.scale.y = value / this.scaleMultiplier; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Container.prototype, "scaleXY", {
            get: function () { return 0.5 * (this.scaleX + this.scaleY); },
            set: function (value) { this.scaleX = value; this.scaleY = value; },
            enumerable: true,
            configurable: true
        });
        Container.prototype.handleFrameChange = function () {
        };
        Container.prototype.updateTransform = function () {
            if (!this.visible)
                return;
            var animable = this;
            if (animable.isFlashObject && animable.animation && animable.animation.isActive)
                animable.animation.update();
            this.updateColor();
            if (this.matrix) {
                var pt = this.parent.worldTransform;
                var wt = this.worldTransform;
                var m = this.matrix;
                wt.a = m.a * pt.a + m.b * pt.c;
                wt.b = m.a * pt.b + m.b * pt.d;
                wt.c = m.c * pt.a + m.d * pt.c;
                wt.d = m.c * pt.b + m.d * pt.d;
                wt.tx = m.tx * pt.a + m.ty * pt.c + pt.tx;
                wt.ty = m.tx * pt.b + m.ty * pt.d + pt.ty;
                for (var i = 0, j = this.children.length; i < j; ++i) {
                    this.children[i].updateTransform();
                }
                this.worldAlpha = this.alpha * this.parent.worldAlpha;
                this._currentBounds = null;
            }
            else {
                _super.prototype.updateTransform.call(this);
            }
        };
        Container.prototype.updateColor = function () {
            var lc = this.color;
            var gc = this.globalColor;
            var parentObject = this.parent;
            if (parentObject && parentObject.isFlashObject) {
                var pc = parentObject.globalColor;
                gc.r = lc.r * pc.r;
                gc.g = lc.g * pc.g;
                gc.b = lc.b * pc.b;
                gc.a = lc.a * pc.a;
            }
            else {
                gc.r = lc.r;
                gc.g = lc.g;
                gc.b = lc.b;
                gc.a = lc.a;
            }
        };
        return Container;
    }(PIXI.Container));
    fl.Container = Container;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Clip = (function (_super) {
        __extends(Clip, _super);
        function Clip(resource) {
            _super.call(this);
            this.isFrameObject = true;
            this._currentFrame = 0;
            this._totalFrames = 1;
            this.autoPlayChildren = true;
            this._instances = [];
            this._resource = resource;
            this._totalFrames = resource.frames.length;
            this.labels = resource.labels;
            this.constructChildren();
            this.handleFrameChange();
        }
        Object.defineProperty(Clip.prototype, "totalFrames", {
            get: function () { return this._totalFrames; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Clip.prototype, "currentFrame", {
            get: function () { return this._currentFrame; },
            set: function (value) {
                if (this._currentFrame != value) {
                    this._currentFrame = fl.Internal.clampRange(value, 0, this._totalFrames - 1);
                    this.handleFrameChange();
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Clip.prototype, "animation", {
            get: function () {
                return this._animation
                    || (this._animation = new fl.Animation(this));
            },
            enumerable: true,
            configurable: true
        });
        Clip.prototype.constructChildren = function () {
            var count = this._resource.instances.length;
            for (var i = 0; i < count; i++) {
                var childName = this._resource.instances[i].name;
                var resource = this._resource.getChildResource(i);
                var child;
                if (typeof resource == "string") {
                    child = fl.Bundle
                        .getResource(resource)
                        .createInstance();
                }
                else if (resource.hasOwnProperty("text")) {
                    child = fl.Text.fromData(resource["text"]);
                }
                child.name = childName;
                this._instances[i] = child;
            }
        };
        Clip.prototype.handleFrameChange = function () {
            this.updateChildren();
            fl.Internal.dispatchLabels(this);
        };
        Clip.prototype.updateChildren = function () {
            var frame = this._resource.frames[this._currentFrame];
            var childIndex = 0;
            var propsIndex = 0;
            var propsCount = frame.instances.length;
            while (childIndex < this.children.length && propsIndex < propsCount) {
                var child = this.children[childIndex];
                if (!child.isFlashObject) {
                    childIndex++;
                    continue;
                }
                var childProps = frame.instances[propsIndex];
                if (child.timelineIndex == childProps.id) {
                    childProps.applyTo(child);
                    if (this.autoPlayChildren
                        && child.isFrameObject
                        && child.totalFrames > 1) {
                        child.animation.updateByParent();
                    }
                    propsIndex++;
                    childIndex++;
                }
                else if (frame.containsIndex(child.timelineIndex)) {
                    var newItem = this.getTimeLineItem(childProps.id);
                    childProps.applyTo(newItem);
                    this.addChildAt(newItem, this.getChildIndex(child));
                    propsIndex++;
                    childIndex++;
                }
                else {
                    if (child.timelineIndex >= 0)
                        this.removeChildAt(childIndex);
                    else
                        childIndex++;
                }
            }
            while (propsIndex < propsCount) {
                var childProps = frame.instances[propsIndex];
                var newItem = this.getTimeLineItem(childProps.id);
                childProps.applyTo(newItem);
                this.addChild(newItem);
                propsIndex++;
                childIndex++;
            }
            while (childIndex < this.children.length) {
                var item = this.children[childIndex];
                if (!item.isFlashObject) {
                    childIndex++;
                    continue;
                }
                if (item.timelineIndex >= 0)
                    this.removeChildAt(childIndex);
                else
                    childIndex++;
            }
        };
        Clip.prototype.getTimeLineItem = function (instanceId) {
            var instance = this._instances[instanceId];
            instance.timelineIndex = instanceId;
            if (instance.isFrameObject) {
                var frameObj = instance;
                frameObj.currentFrame = 0;
            }
            return instance;
        };
        Object.defineProperty(Clip.prototype, "resource", {
            get: function () {
                return this._resource;
            },
            enumerable: true,
            configurable: true
        });
        Clip.prototype.toString = function () {
            return 'Clip[' + this._resource.id + ']';
        };
        Clip.prototype.tryGetElement = function (name) {
            var n = this._instances.length;
            for (var i = 0; i < n; i++) {
                var inst = this._instances[i];
                if (inst.name == name)
                    return inst;
            }
            return null;
        };
        Clip.prototype.getElement = function (name) {
            var element = this.tryGetElement(name);
            if (element)
                return element;
            else
                throw new Error("Instance not found: " + name);
        };
        Object.defineProperty(Clip.prototype, "instances", {
            get: function () {
                return this._instances;
            },
            enumerable: true,
            configurable: true
        });
        return Clip;
    }(fl.Container));
    fl.Clip = Clip;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var ClipResource = (function (_super) {
        __extends(ClipResource, _super);
        function ClipResource() {
            _super.apply(this, arguments);
        }
        ClipResource.fromJson = function (data) {
            var id = data.path;
            var r = new ClipResource(id);
            r.resources = data.resources;
            r.instances = ClipResource.readInstances(data.instances);
            r.frames = ClipResource.readFrames(data.frames, r.instances.length);
            r.labels = data.labels;
            return r;
        };
        ClipResource.readInstances = function (data) {
            var instances = [];
            for (var i = 0; i < data.length; i++) {
                var props = data[i];
                var inst = new ChildInfo();
                inst.resIndex = props[0];
                inst.name = props[1];
                instances[i] = inst;
            }
            return instances;
        };
        ClipResource.readFrames = function (data, totalInstCount) {
            var framesCount = data.length;
            var frames = [];
            for (var i = 0; i < framesCount; i++) {
                frames[i] = ClipResource.readFrame(data[i], totalInstCount);
            }
            return frames;
        };
        ClipResource.readFrame = function (data, totalInstCount) {
            var frame = new FrameData();
            frame.existingInstancesBits = [];
            for (var i = 0; i < totalInstCount; i++) {
                frame.existingInstancesBits[i] = false;
            }
            var instCount = data.length;
            frame.instances = [];
            for (var i = 0; i < instCount; i++) {
                var instance = ClipResource.readInstance(data[i]);
                frame.instances[i] = instance;
                frame.existingInstancesBits[instance.id] = true;
            }
            return frame;
        };
        ClipResource.readInstance = function (data) {
            var props = new ChildProps();
            props.id = data[0];
            props.position = new PIXI.Point(data[1], data[2]);
            props.rotation = data[3];
            props.scale = new PIXI.Point(data[4], data[5]);
            props.color = new fl.Color(data[6], data[7], data[8], data[9]);
            var matrixData = data[10];
            if (matrixData) {
                props.matrix = new PIXI.Matrix();
                props.matrix.a = matrixData[0];
                props.matrix.b = matrixData[1];
                props.matrix.c = matrixData[2];
                props.matrix.d = matrixData[3];
                props.matrix.tx = matrixData[4];
                props.matrix.ty = matrixData[5];
            }
            return props;
        };
        ClipResource.prototype.createInstance = function () {
            return new fl.Clip(this);
        };
        ClipResource.prototype.getChildResource = function (childIndex) {
            var resIndex = this.instances[childIndex].resIndex;
            return this.resources[resIndex];
        };
        ClipResource.prototype.dispose = function () {
            this.resources = null;
            this.instances = null;
            this.frames = null;
            this.labels = null;
        };
        return ClipResource;
    }(fl.Resource));
    fl.ClipResource = ClipResource;
    var FrameData = (function () {
        function FrameData() {
        }
        FrameData.prototype.containsIndex = function (id) {
            return id >= 0
                && id < this.existingInstancesBits.length
                && this.existingInstancesBits[id];
        };
        FrameData.EMPTY_LABELS = [];
        return FrameData;
    }());
    var ChildInfo = (function () {
        function ChildInfo() {
        }
        return ChildInfo;
    }());
    var ChildProps = (function () {
        function ChildProps() {
            this.matrixChecked = false;
        }
        ChildProps.prototype.applyTo = function (target) {
            target.position.x = this.position.x;
            target.position.y = this.position.y;
            target.rotation = this.rotation;
            target.scaleX = this.scale.x;
            target.scaleY = this.scale.y;
            target.color.r = this.color.r;
            target.color.g = this.color.g;
            target.color.b = this.color.b;
            target.color.a = this.color.a;
            if (!this.matrixChecked) {
                if (this.matrix && target.scaleMultiplier > 0 && target.scaleMultiplier != 1)
                    this.matrix = null;
                this.matrixChecked = true;
            }
            target.matrix = this.matrix;
        };
        return ChildProps;
    }());
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Sprite = (function (_super) {
        __extends(Sprite, _super);
        function Sprite(resource) {
            _super.call(this, null);
            this.timelineIndex = -1;
            this.color = new fl.Color(1, 1, 1, 1);
            this.isFlashObject = true;
            this.isFrameObject = true;
            this.scaleMultiplier = 1;
            this._currentFrame = 0;
            this._totalFrames = 1;
            this.labels = fl.Internal.EMPTY_ARRAY;
            this.setResourceInternal(resource);
            this.scaleMultiplier = resource.scale;
            this.scaleXY = 1;
        }
        Object.defineProperty(Sprite.prototype, "scaleX", {
            get: function () { return this.scale.x * this.scaleMultiplier; },
            set: function (value) { this.scale.x = value / this.scaleMultiplier; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Sprite.prototype, "scaleY", {
            get: function () { return this.scale.y * this.scaleMultiplier; },
            set: function (value) { this.scale.y = value / this.scaleMultiplier; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Sprite.prototype, "scaleXY", {
            get: function () { return 0.5 * (this.scaleX + this.scaleY); },
            set: function (value) { this.scaleX = value; this.scaleY = value; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Sprite.prototype, "totalFrames", {
            get: function () { return this._totalFrames; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Sprite.prototype, "currentFrame", {
            get: function () { return this._currentFrame; },
            set: function (value) {
                if (this._currentFrame != value) {
                    this._currentFrame = fl.Internal.clampRange(value, 0, this._totalFrames - 1);
                    this.handleFrameChange();
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Sprite.prototype, "animation", {
            get: function () {
                return this._animation
                    || (this._animation = new fl.Animation(this));
            },
            enumerable: true,
            configurable: true
        });
        Sprite.prototype.updateTransform = function () {
            if (this._animation && this._animation.isActive)
                this.animation.update();
            fl.Internal.applyColor(this);
            if (this.matrix) {
                var pt = this.parent.worldTransform;
                var wt = this.worldTransform;
                var m = this.matrix;
                wt.a = m.a * pt.a + m.b * pt.c;
                wt.b = m.a * pt.b + m.b * pt.d;
                wt.c = m.c * pt.a + m.d * pt.c;
                wt.d = m.c * pt.b + m.d * pt.d;
                wt.tx = m.tx * pt.a + m.ty * pt.c + pt.tx;
                wt.ty = m.tx * pt.b + m.ty * pt.d + pt.ty;
                this.worldAlpha = this.alpha * this.parent.worldAlpha;
                this._currentBounds = null;
            }
            else {
                _super.prototype.updateTransform.call(this);
            }
        };
        Sprite.prototype.handleFrameChange = function () {
            var frame = this._resource.frames[this._currentFrame];
            this.anchor.set(frame.anchor.x, frame.anchor.y);
            this.texture = frame.texture;
            fl.Internal.dispatchLabels(this);
        };
        Object.defineProperty(Sprite.prototype, "resource", {
            get: function () {
                return this._resource;
            },
            set: function (value) {
                this.setResourceInternal(value);
                this.currentFrame = 0;
            },
            enumerable: true,
            configurable: true
        });
        Sprite.prototype.setResourceInternal = function (value) {
            this._resource = value;
            this._totalFrames = value.frames.length;
            this._currentFrame = 0;
            this.labels = value.labels;
            this.handleFrameChange();
        };
        Sprite.prototype.toString = function () {
            return 'Sprite[' + this._resource.id + ']';
        };
        return Sprite;
    }(PIXI.Sprite));
    fl.Sprite = Sprite;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var SpriteFrame = (function () {
        function SpriteFrame() {
        }
        return SpriteFrame;
    }());
    fl.SpriteFrame = SpriteFrame;
    var SpriteResource = (function (_super) {
        __extends(SpriteResource, _super);
        function SpriteResource() {
            _super.apply(this, arguments);
        }
        SpriteResource.fromJson = function (data, texture) {
            var id = data.path;
            var res = new SpriteResource(id);
            res.texture = texture;
            res.scale = data.scale;
            res.labels = data.labels;
            res.frames = [];
            for (var i = 0; i < data.frames.length; i++) {
                var props = data.frames[i];
                var bounds = new PIXI.Rectangle(props[0], props[1], props[2], props[3]);
                var anchor = (bounds.width > 0 && bounds.height > 0)
                    ? new PIXI.Point(props[4] / bounds.width, props[5] / bounds.height)
                    : new PIXI.Point();
                var frame = {
                    texture: new PIXI.Texture(texture.baseTexture, bounds),
                    anchor: anchor,
                    labels: props[6],
                };
                res.frames.push(frame);
            }
            return res;
        };
        SpriteResource.prototype.createInstance = function () {
            return new fl.Sprite(this);
        };
        SpriteResource.prototype.dispose = function () {
            this.texture.destroy(false);
            this.texture = null;
            this.frames = null;
            this.labels = null;
        };
        return SpriteResource;
    }(fl.Resource));
    fl.SpriteResource = SpriteResource;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Placeholder = (function (_super) {
        __extends(Placeholder, _super);
        function Placeholder() {
            _super.apply(this, arguments);
        }
        Placeholder.prototype.getBounds = function (matrix) {
            if (!this._currentBounds) {
                var bounds = Placeholder.predefinedBounds;
                var w0 = bounds.x;
                var w1 = bounds.width + bounds.x;
                var h0 = bounds.y;
                var h1 = bounds.height + bounds.y;
                var worldTransform = matrix || this.worldTransform;
                var a = worldTransform.a;
                var b = worldTransform.b;
                var c = worldTransform.c;
                var d = worldTransform.d;
                var tx = worldTransform.tx;
                var ty = worldTransform.ty;
                var x1 = a * w1 + c * h1 + tx;
                var y1 = d * h1 + b * w1 + ty;
                var x2 = a * w0 + c * h1 + tx;
                var y2 = d * h1 + b * w0 + ty;
                var x3 = a * w0 + c * h0 + tx;
                var y3 = d * h0 + b * w0 + ty;
                var x4 = a * w1 + c * h0 + tx;
                var y4 = d * h0 + b * w1 + ty;
                var maxX = x1;
                var maxY = y1;
                var minX = x1;
                var minY = y1;
                minX = x2 < minX ? x2 : minX;
                minX = x3 < minX ? x3 : minX;
                minX = x4 < minX ? x4 : minX;
                minY = y2 < minY ? y2 : minY;
                minY = y3 < minY ? y3 : minY;
                minY = y4 < minY ? y4 : minY;
                maxX = x2 > maxX ? x2 : maxX;
                maxX = x3 > maxX ? x3 : maxX;
                maxX = x4 > maxX ? x4 : maxX;
                maxY = y2 > maxY ? y2 : maxY;
                maxY = y3 > maxY ? y3 : maxY;
                maxY = y4 > maxY ? y4 : maxY;
                bounds = this._bounds;
                bounds.x = minX;
                bounds.width = maxX - minX;
                bounds.y = minY;
                bounds.height = maxY - minY;
                this._currentBounds = bounds;
            }
            return this._currentBounds;
        };
        Placeholder.prototype.getLoaclBounds = function () {
            return Placeholder.predefinedBounds;
        };
        Placeholder.predefinedBounds = new PIXI.Rectangle(0, 0, 100, 100);
        return Placeholder;
    }(fl.Container));
    fl.Placeholder = Placeholder;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Button = (function () {
        function Button(target, action) {
            var _this = this;
            this._enabled = true;
            fl.assertPresent(target, "targetCell");
            this.content = target;
            this.onRelease = action;
            this.content.on("mousedown", function (e) {
                _this.setDownState();
                if (_this.onPress)
                    _this.onPress(_this, e);
            });
            this.content.on("mouseup", function (e) {
                _this.setUpState();
                if (_this.onRelease)
                    _this.onRelease(_this, e);
            });
            this.content.on("mouseupoutside", function () {
                _this.setUpState();
            });
            this.content.on("touchstart", function (e) {
                _this.setDownState();
                if (_this.onPress)
                    _this.onPress(_this, e);
            });
            this.content.on("touchend", function (e) {
                _this.setUpState();
                if (_this.onRelease)
                    _this.onRelease(_this, e);
            });
            this.content.on("touchendoutside", function () {
                _this.setUpState();
            });
            this.refreshEnabledState();
        }
        Object.defineProperty(Button.prototype, "enabled", {
            get: function () { return this._enabled; },
            set: function (value) {
                if (this._enabled != value) {
                    this._enabled = value;
                    this.refreshEnabledState();
                }
            },
            enumerable: true,
            configurable: true
        });
        Button.prototype.refreshEnabledState = function () {
            this.content.interactive = this._enabled;
            this.content.buttonMode = this._enabled;
        };
        Button.prototype.setDownState = function () {
            var states = this.content;
            if (states.isFlashObject) {
                states.currentFrame = 1;
                states.updateTransform();
            }
        };
        Button.prototype.setUpState = function () {
            var states = this.content;
            if (states.isFlashObject) {
                states.currentFrame = 0;
                states.updateTransform();
            }
        };
        return Button;
    }());
    fl.Button = Button;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Anchor = (function () {
        function Anchor(source, sourceProperty, target, targetProperty, multiplier) {
            if (multiplier === void 0) { multiplier = 1.0; }
            this._target = target;
            this._targetProperty = targetProperty;
            this._source = source;
            this._sourceProperty = sourceProperty;
            this._multiplier = multiplier;
            this._distance = source[sourceProperty] * multiplier - target[targetProperty];
        }
        Anchor.prototype.apply = function () {
            this._target[this._targetProperty] = this._source[this._sourceProperty] * this._multiplier - this._distance;
        };
        return Anchor;
    }());
    fl.Anchor = Anchor;
})(fl || (fl = {}));
var fl;
(function (fl) {
    applyMixins(fl.Container, fl.FlashObject);
    applyMixins(fl.Clip, fl.FrameObject);
    applyMixins(fl.Sprite, fl.FlashObject);
    applyMixins(fl.Sprite, fl.FrameObject);
    function applyMixins(derived, base) {
        Object.getOwnPropertyNames(base.prototype).forEach(function (name) {
            derived.prototype[name] = base.prototype[name];
        });
    }
    fl.applyMixins = applyMixins;
    function assertPresent(value, name) {
        if (!value)
            throw new Error("Value not present: " + name);
    }
    fl.assertPresent = assertPresent;
})(fl || (fl = {}));
var dressup_game;
(function (dressup_game) {
    var PartConfig = (function () {
        function PartConfig() {
        }
        return PartConfig;
    }());
    dressup_game.PartConfig = PartConfig;
    var Config = (function () {
        function Config() {
        }
        Config.width = 1024;
        Config.height = 768;
        Config.links = {
            'btn_logo': 'https://girlieroom.com/?HEDs410logo',
            'btn_more_seasons': 'https://girlieroom.com/?HEDs410ms',
            'btn_fb': 'https://facebook.com/EmilyDiary',
            'btn_fr': 'https://girlieroom.com/pages/story-french/?HEDs410stfr',
            'btn_eng': 'https://girlieroom.com/pages/story-english/?HEDs410steng',
        };
        Config.parts = {
            'btn_m1_opt1': { 'path': ['model_1/opt_1'], 'exclude': [], 'allowHide': false },
            'btn_m1_opt2': { 'path': ['model_1/opt_2'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt3': { 'path': ['model_1/opt_3'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt4': { 'path': ['model_1/opt_4'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt5': { 'path': ['model_1/opt_5'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt6': { 'path': ['model_1/opt_6'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt7': { 'path': ['model_1/opt_7'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt8': { 'path': ['model_1/opt_8'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt9': { 'path': ['model_1/opt_9'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt10': { 'path': ['model_1/opt_10'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt11': { 'path': ['model_1/opt_11'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt12': { 'path': ['model_1/opt_12'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt13': { 'path': ['model_1/opt_13'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt14': { 'path': ['model_1/opt_14'], 'exclude': [], 'allowHide': true },
            'btn_m1_opt15': { 'path': ['model_1/opt_15'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt1': { 'path': ['model_2/opt_1'], 'exclude': [], 'allowHide': false },
            'btn_m2_opt2': { 'path': ['model_2/opt_2'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt3': { 'path': ['model_2/opt_3'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt4': { 'path': ['model_2/opt_4'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt5': { 'path': ['model_2/opt_5'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt6': { 'path': ['model_2/opt_6'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt7': { 'path': ['model_2/opt_7'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt8': { 'path': ['model_2/opt_8'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt9': { 'path': ['model_2/opt_9'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt10': { 'path': ['model_2/opt_10'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt11': { 'path': ['model_2/opt_11'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt12': { 'path': ['model_2/opt_12'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt13': { 'path': ['model_2/opt_13'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt14': { 'path': ['model_2/opt_14'], 'exclude': [], 'allowHide': true },
            'btn_m2_opt15': { 'path': ['model_2/opt_15'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt1': { 'path': ['model_3/opt_1'], 'exclude': [], 'allowHide': false },
            'btn_m3_opt2': { 'path': ['model_3/opt_2'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt3': { 'path': ['model_3/opt_3'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt4': { 'path': ['model_3/opt_4'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt5': { 'path': ['model_3/opt_5'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt6': { 'path': ['model_3/opt_6'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt7': { 'path': ['model_3/opt_7'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt8': { 'path': ['model_3/opt_8'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt9': { 'path': ['model_3/opt_9'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt10': { 'path': ['model_3/opt_10'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt11': { 'path': ['model_3/opt_11'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt12': { 'path': ['model_3/opt_12'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt13': { 'path': ['model_3/opt_13'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt14': { 'path': ['model_3/opt_14'], 'exclude': [], 'allowHide': true },
            'btn_m3_opt15': { 'path': ['model_3/opt_15'], 'exclude': [], 'allowHide': true },
        };
        return Config;
    }());
    dressup_game.Config = Config;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    var AppScreen = (function () {
        function AppScreen(name) {
            this.name = "AppScreen";
            this._size = new PIXI.Point();
            this._anchors = [];
            this._bindings = {};
            this.name = name;
        }
        AppScreen.prototype.initialize = function () {
            this.bindSoundButton();
            this.onInitialize();
        };
        AppScreen.prototype.onInitialize = function () { };
        AppScreen.prototype.bindItem = function (prefix, action) {
            this._bindings[prefix] = action;
        };
        AppScreen.prototype.bindButton = function (name, action) {
            this._bindings[name] = function (it) { return new fl.Button(it, action); };
        };
        AppScreen.prototype.bindSoundButton = function () {
            this._bindings["btn_sound"] = function (it) { return new dressup_game.SoundButton(it, function () { return dressup_game.App.toggleSound(); }); };
        };
        AppScreen.prototype.configureBindings = function () {
            var _this = this;
            this.content.forEachRecursive(function (it) {
                if (_this.isInitialized(it))
                    return;
                else
                    _this.setInitialized(it);
                if (_this.configureUrl(it))
                    return;
                if (_this.applyBinding(it))
                    return;
            });
        };
        AppScreen.prototype.applyBinding = function (item) {
            if (!item.isFrameObject || !item.name)
                return false;
            for (var key in this._bindings) {
                if (item.name.indexOf(key) == 0) {
                    this._bindings[key](item);
                    return true;
                }
            }
            return false;
        };
        AppScreen.prototype.createContent = function (path) {
            this.content = fl.Bundle.createClip(path);
            this._size.x = dressup_game.Config.width;
            this._size.y = dressup_game.Config.height;
            this._reserve = Math.abs(this.content.getChildAt(0).x);
            this.configureLayout();
            this.configureContent();
        };
        AppScreen.prototype.configureContent = function () {
            this.configureBindings();
            this.configureAutoPlay(this.content);
        };
        AppScreen.prototype.configureLayout = function () {
            this.resetLayout();
            this.configureAnchors();
            this.restoreLayout();
        };
        AppScreen.prototype.configureAutoPlay = function (container) {
            var _this = this;
            container.children.forEach(function (it) {
                var frameObj = it;
                if (!frameObj.name && frameObj.totalFrames > 1)
                    frameObj.animation.play();
                else if (it instanceof fl.Container)
                    _this.configureAutoPlay(it);
            });
        };
        AppScreen.prototype.configureUrl = function (item) {
            if (!item.name)
                return false;
            var url = dressup_game.Config.links[item.name];
            if (url)
                new fl.Button(item, function () { return window.open(url, '_blank'); });
            return Boolean(url);
        };
        AppScreen.prototype.configureAnchors = function () {
            var _this = this;
            this._anchors = [];
            var leftGuid = this.content.getChildByName("guid_left");
            var left = leftGuid ? leftGuid.x : Number.MIN_VALUE;
            if (leftGuid)
                leftGuid.visible = false;
            var rightGuid = this.content.getChildByName("guid_right");
            var right = rightGuid ? rightGuid.x : Number.MAX_VALUE;
            if (rightGuid)
                rightGuid.visible = false;
            var ignores = ["back", "model", "guid"];
            this.content.children.forEach(function (it) {
                if (it.name) {
                    for (var _i = 0, ignores_1 = ignores; _i < ignores_1.length; _i++) {
                        var ignore = ignores_1[_i];
                        if (it.name.indexOf(ignore) == 0)
                            return;
                    }
                }
                if (it.x <= left)
                    _this.addAnchor(_this, "contentLeft", it, "x");
                else if (it.x >= right)
                    _this.addAnchor(_this, "contentRight", it, "x");
            });
        };
        AppScreen.prototype.addAnchor = function (source, sourceProp, target, targetProp, multiplier) {
            if (multiplier === void 0) { multiplier = 1.0; }
            this._anchors.push(new fl.Anchor(source, sourceProp, target, targetProp, multiplier));
        };
        AppScreen.prototype.resetLayout = function () {
            this._savedWidth = this._size.x;
            this._savedHeight = this._size.y;
            this._size.x = dressup_game.Config.width;
            this._size.y = dressup_game.Config.height;
            this.content.position.x = 0;
            this.content.position.y = 0;
            this.content.scale.y = 1;
            this.content.scale.x = 1;
        };
        AppScreen.prototype.restoreLayout = function () {
            this._size.x = this._savedWidth;
            this._size.y = this._savedHeight;
            this.validateLayout();
        };
        AppScreen.prototype.validateLayout = function () {
            var scaleY = this.height / dressup_game.Config.height;
            var scaleX = this.width / dressup_game.Config.width;
            var scale = Math.min(scaleX, scaleY);
            this.content.scale.x = scale;
            this.content.scale.y = scale;
            this.content.x = 0.5 * (this.width - dressup_game.Config.width * scale);
            for (var _i = 0, _a = this._anchors; _i < _a.length; _i++) {
                var a = _a[_i];
                a.apply();
            }
            this.onLayoutChanged();
        };
        AppScreen.prototype.onLayoutChanged = function () {
        };
        ;
        Object.defineProperty(AppScreen.prototype, "contentLeft", {
            get: function () {
                var left = (-this.content.x) / this.content.scale.x;
                return Math.max(-this._reserve, left);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AppScreen.prototype, "contentRight", {
            get: function () {
                var right = (this.width - this.content.x) / this.content.scale.x;
                return Math.min(right, dressup_game.Config.width + this._reserve);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AppScreen.prototype, "width", {
            get: function () {
                return this._size.x;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AppScreen.prototype, "height", {
            get: function () {
                return this._size.y;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AppScreen.prototype, "size", {
            get: function () {
                return this._size;
            },
            enumerable: true,
            configurable: true
        });
        AppScreen.prototype.resize = function (x, y) {
            this._size.x = x;
            this._size.y = y;
            this.validateLayout();
        };
        AppScreen.prototype.isInitialized = function (item) {
            return item.hasOwnProperty("__INITIALIZED__");
        };
        AppScreen.prototype.setInitialized = function (item) {
            item["__INITIALIZED__"] = true;
        };
        return AppScreen;
    }());
    dressup_game.AppScreen = AppScreen;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    var IntroScreen = (function (_super) {
        __extends(IntroScreen, _super);
        function IntroScreen() {
            _super.call(this, 'IntroScreen');
            this.isAnimComplete = false;
            this.isLoadComplete = false;
        }
        IntroScreen.prototype.onInitialize = function () {
            var _this = this;
            this.bindItem('btn_play', function (it) { return _this.playButton = new fl.Button(it, function () { return _this.onPlayClick(); }); });
            this.bindItem('loading', function (it) { return _this.loadingClip = it; });
            this.bindItem('intro_anim', function (it) {
                it.animation
                    .onComplete(function () { return _this.onAnimComplete(); })
                    .playToEnd();
            });
            this.createContent('intro/intro_screen');
            this.loadSceneBundle();
        };
        IntroScreen.prototype.onPlayClick = function () {
            dressup_game.App.changeScreen(new dressup_game.SceneScreen());
        };
        IntroScreen.prototype.loadSceneBundle = function () {
            var _this = this;
            this.playButton.content.visible = false;
            this.loadingClip.animation.play();
            fl.Bundle.load('scene', function () { return _this.onLoadComplete(); });
        };
        IntroScreen.prototype.onLoadComplete = function () {
            this.isLoadComplete = true;
            this.checkReady();
        };
        IntroScreen.prototype.onAnimComplete = function () {
            this.isAnimComplete = true;
            this.checkReady();
        };
        IntroScreen.prototype.checkReady = function () {
            if (this.isLoadComplete && this.isAnimComplete) {
                this.loadingClip.animation.stop();
                this.loadingClip.visible = false;
                this.playButton.content.visible = true;
                this.playButton.content.scale.x = .9;
                this.playButton.content.scale.y = .9;
                createjs.Tween.get(this.playButton.content)
                    .to({ scaleX: 1, scaleY: 1 }, 1000, createjs.Ease.elasticOut);
            }
        };
        return IntroScreen;
    }(dressup_game.AppScreen));
    dressup_game.IntroScreen = IntroScreen;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    var SceneScreen = (function (_super) {
        __extends(SceneScreen, _super);
        function SceneScreen() {
            _super.call(this, 'SceneScreen');
            this._banners = [];
            this._states = {};
        }
        SceneScreen.prototype.onInitialize = function () {
            var _this = this;
            fl.Bundle.unload('intro');
            this.bindItem(SceneScreen.EXT_BANNER_PREFIX, function (it) { return _this.initExtBanner(it); });
            this.bindItem(SceneScreen.FRAME_BTN_PREFIX, function (it) { return _this.initFrameButton(it); });
            this.bindItem(SceneScreen.PART_PREFIX, function (it) { return _this.initModelPart(it); });
            this.bindButton(SceneScreen.PART_BTN_PREFIX, function (it) { return _this.onPartButtonClick(it); });
            this.bindButton(SceneScreen.BG_BUTTON, function () { return _this.toggleBackground(); });
            this.bindItem("btn_save", function (it) { return it.visible = false; });
            this.bindButton("btn_prev", function () { return _this.gotoBack(); });
            this.bindButton("btn_next", function () { return _this.gotoNext(); });
            this.bindButton("btn_reset", function () { return _this.reset(); });
            this.bindButton("btn_photo", function () { return _this.setPhotoMode(true); });
            this.bindButton("btn_back", function () { return _this.setPhotoMode(false); });
            this.createContent('scene/scene_screen');
            this.content.autoPlayChildren = false;
            this.initFrame();
            dressup_game.App.music.play(dressup_game.App.musicName);
            dressup_game.App.bannerService.onBannerLoaded = function () { return _this.refreshBanners(); };
            dressup_game.App.bannerService.downloadBanners();
        };
        SceneScreen.prototype.initExtBanner = function (clip) {
            clip.visible = false;
            var bannerNum = Number(clip.name.split("_").pop()) - 1;
            if (isNaN(bannerNum))
                return;
            this._banners[bannerNum] = clip;
            this.refreshBanners();
        };
        SceneScreen.prototype.refreshBanners = function () {
            var banners = dressup_game.App.bannerService.banners;
            var _loop_2 = function() {
                var clip = this_2._banners[i];
                var banner = banners[i];
                if (clip && !clip.visible && banner.isLoaded) {
                    rect = clip.getChildAt(0);
                    scale = Math.min(rect.width / banner.texture.width, rect.height / banner.texture.height);
                    sprite = new PIXI.Sprite(banner.texture);
                    sprite.scale.x = scale / rect.scaleX;
                    sprite.scale.y = scale / rect.scaleY;
                    rect.addChildAt(sprite, 0);
                    clip.visible = true;
                    new fl.Button(clip, function () { return window.open(banner.url, '_blank'); });
                }
            };
            var this_2 = this;
            var rect, scale, sprite;
            for (var i = 0; i < banners.length; i++) {
                _loop_2();
            }
        };
        SceneScreen.prototype.initFrame = function () {
            this._backgrounds = this.content
                .findAllByPrefix(SceneScreen.BG_PREFIX);
            this._models = this.content
                .findAllByPrefix(SceneScreen.MODEL_PREFIX);
            this._btnBack = this.content
                .getChildByName("btn_back");
            if (this._btnBack)
                this._btnBack.visible = false;
        };
        SceneScreen.prototype.initFrameButton = function (item) {
            var _this = this;
            var frameNum = Number(item.name.split("_").pop()) - 1;
            new fl.Button(item, function () {
                _this.framesNavOrder = [];
                _this.framesNavOrder.push(0);
                _this.framesNavOrder.push(frameNum);
                for (var i = 1; i < _this.content.totalFrames; i++) {
                    if (i != frameNum)
                        _this.framesNavOrder.push(i);
                }
                _this.gotoFrame(frameNum);
            });
        };
        SceneScreen.prototype.gotoBack = function () {
            var order = this.framesNavOrder.indexOf(this.content.currentFrame);
            this.gotoFrame(this.framesNavOrder[order - 1]);
        };
        SceneScreen.prototype.gotoNext = function () {
            var order = this.framesNavOrder.indexOf(this.content.currentFrame);
            this.gotoFrame(this.framesNavOrder[order + 1]);
            if (order == dressup_game.AD_FRAME) {
                console.log("calling ad...");
                dressup_game.AD_CALL();
            }
        };
        SceneScreen.prototype.reset = function () {
            if (this.content.currentFrame != 0)
                this.gotoFrame(0);
            else
                this.resetModels();
        };
        SceneScreen.prototype.gotoFrame = function (num) {
            var _this = this;
            this.saveState();
            var action = function () {
                if (num != _this.content.currentFrame) {
                    _this.content.currentFrame = num;
                    _this.configureLayout();
                }
                _this.initFrame();
                _this.configureContent();
                _this.restoreState();
            };
            if (this.content.currentFrame == 0 || num == 0)
                dressup_game.App.beginTransition(action);
            else
                setTimeout(action);
        };
        SceneScreen.prototype.initModelPart = function (part) {
            var cfg = this.getPartConfig(part);
            if (cfg.allowHide) {
                part.interactive = true;
                part.buttonMode = true;
                part.on('mousedown', function (it) { return part.visible = false; });
                part.on('touchstart', function (it) { return part.visible = false; });
            }
            part.visible = part.gotoLabel('default_frame');
        };
        SceneScreen.prototype.onPartButtonClick = function (btn) {
            var _this = this;
            var btnName = btn.content.name;
            var btnConfig = dressup_game.Config.parts[btnName];
            if (!btnConfig)
                throw new Error("Config not found for button: " + btnName);
            btnConfig.path.forEach(function (it) { return _this.toggleModelPart(it); });
            btnConfig.exclude.forEach(function (it) { return _this.hideModelPart(it); });
        };
        SceneScreen.prototype.toggleModelPart = function (path) {
            var clip = this.getModelPart(path);
            if (!clip.visible)
                clip.visible = true;
            else
                clip.stepForward();
        };
        SceneScreen.prototype.hideModelPart = function (path) {
            this.getModelPart(path).visible = false;
        };
        SceneScreen.prototype.getModelPart = function (path) {
            var result = this.content.findByPath(path);
            if (!result)
                throw new Error("Content not found: " + path);
            return result;
        };
        SceneScreen.prototype.getPartConfig = function (part) {
            var model = part.parent;
            var modelNum = model.name.replace(/\D+/, "");
            var optionNum = part.name.replace(/\D+/, "");
            var optionId = "btn_m" + modelNum + "_opt" + optionNum;
            var config = dressup_game.Config.parts[optionId];
            if (config)
                return config;
            else
                throw new Error("Config not found: " + optionId);
        };
        SceneScreen.prototype.resetModels = function () {
            var _this = this;
            this._models.forEach(function (model) {
                model.findAllByPrefix(SceneScreen.PART_PREFIX).forEach(function (part) {
                    var info = _this.getPartConfig(part);
                    if (info.allowHide)
                        part.visible = false;
                });
            });
        };
        SceneScreen.prototype.toggleBackground = function () {
            for (var _i = 0, _a = this._backgrounds; _i < _a.length; _i++) {
                var bg = _a[_i];
                bg.stepBackward();
                if (bg instanceof fl.Clip)
                    this.configureAutoPlay(bg);
            }
        };
        SceneScreen.prototype.saveState = function () {
            var _this = this;
            var _loop_3 = function(model) {
                model.forEachFrameObject(function (it) {
                    var path = model.name + "/" + it.name;
                    _this._states[path] = { frame: it.currentFrame, visible: it.visible };
                });
            };
            for (var _i = 0, _a = this._models; _i < _a.length; _i++) {
                var model = _a[_i];
                _loop_3(model);
            }
        };
        SceneScreen.prototype.restoreState = function () {
            for (var path in this._states) {
                var item = this.content.findByPath(path);
                if (item) {
                    var state = this._states[path];
                    item.currentFrame = state.frame;
                    item.visible = state.visible;
                }
            }
        };
        SceneScreen.prototype.setPhotoMode = function (photoMode) {
            this.content.findAllByPrefix("btn").forEach(function (it) { return it.visible = !photoMode; });
            this._btnBack.visible = photoMode;
        };
        SceneScreen.EXT_BANNER_PREFIX = "ext_banner";
        SceneScreen.FRAME_BTN_PREFIX = "btn_frame";
        SceneScreen.BG_PREFIX = "back";
        SceneScreen.BG_BUTTON = "btn_bg";
        SceneScreen.MODEL_PREFIX = "model";
        SceneScreen.PART_PREFIX = "opt";
        SceneScreen.PART_BTN_PREFIX = "btn_m";
        return SceneScreen;
    }(dressup_game.AppScreen));
    dressup_game.SceneScreen = SceneScreen;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    dressup_game.STAGE_COLOR = 0x000000;
    dressup_game.FORCE_USE_CANVAS = false;
    dressup_game.SKIP_INTRO = false;
    dressup_game.BANNER_URL = "mobilerandom.xml";
    dressup_game.AD_FRAME = 2;
    dressup_game.AD_CALL = function () { };
    function initialize(elementOrId) {
        console.log("STAGE_COLOR: " + dressup_game.STAGE_COLOR);
        console.log("FORCE_USE_CANVAS: " + dressup_game.FORCE_USE_CANVAS);
        console.log("SKIP_INTRO: " + dressup_game.SKIP_INTRO);
        console.log("BANNER_URL: " + dressup_game.BANNER_URL);
        console.log("AD_FRAME: " + dressup_game.AD_FRAME);
        console.log("AD_CALL: " + dressup_game.AD_CALL);
        var container = (typeof elementOrId === "string")
            ? document.getElementById(elementOrId)
            : elementOrId;
        App.initialize(container || document.body);
    }
    dressup_game.initialize = initialize;
    var App = (function () {
        function App() {
        }
        App.initialize = function (container) {
            this._container = container;
            requestAnimationFrame(App.createGame);
        };
        App.createGame = function () {
            fl.Animation.defaultTicksPerFrame = 2;
            App.music = new dressup_game.AppMusic();
            App.bannerService = new dressup_game.BannerService();
            App.initRenderer();
            App.validateLayout();
            App.loadFirstScreen();
            requestAnimationFrame(App.animate);
        };
        App.initRenderer = function () {
            PIXI.DEFAULT_RENDER_OPTIONS.clearBeforeRender = true;
            PIXI.DEFAULT_RENDER_OPTIONS.backgroundColor = dressup_game.STAGE_COLOR;
            App.stage = new PIXI.Container();
            App.renderer = dressup_game.FORCE_USE_CANVAS
                ? new PIXI.CanvasRenderer(dressup_game.Config.width, dressup_game.Config.height)
                : PIXI.autoDetectRenderer(dressup_game.Config.width, dressup_game.Config.height);
            App._container.appendChild(App.renderer.view);
        };
        App.validateLayout = function () {
            var w0 = window.innerWidth;
            var h0 = window.innerHeight;
            if (w0 == App._prevWidth && h0 == App._prevHeight)
                return;
            App._prevWidth = w0;
            App._prevHeight = h0;
            var appPropMin = dressup_game.Config.width / dressup_game.Config.height;
            var appPropMax = (dressup_game.Config.width + 2 * App.widthExtra) / dressup_game.Config.height;
            var canvasWidth;
            var canvasHeight;
            var canvasMinWidth = h0 * appPropMin;
            var canvasMaxWidth = h0 * appPropMax;
            if (w0 < canvasMinWidth) {
                canvasWidth = w0;
                canvasHeight = w0 / appPropMin;
            }
            else if (w0 > canvasMaxWidth) {
                canvasWidth = canvasMaxWidth;
                canvasHeight = h0;
            }
            else {
                canvasWidth = w0;
                canvasHeight = h0;
            }
            canvasWidth = Math.floor(canvasWidth);
            canvasHeight = Math.floor(canvasHeight);
            var canvasX = Math.round(0.5 * (w0 - canvasWidth));
            var canvasY = Math.round(0.5 * (h0 - canvasHeight));
            var canvas = App.renderer.view;
            canvas.style.marginLeft = canvasX + "px";
            canvas.style.marginTop = canvasY + "px";
            canvas.style.width = canvasWidth + "px";
            canvas.style.height = canvasHeight + "px";
            App.adjustResolution(canvasWidth, canvasHeight);
            App.adjustScreenSize();
        };
        App.adjustResolution = function (width, height) {
            var max_w = 2048;
            var max_h = 1536;
            var res = Math.min(window.devicePixelRatio, 2);
            var w = width * res;
            var h = height * res;
            var k = Math.max(w / max_w, h / max_h);
            if (k > 1) {
                w /= k;
                h /= k;
            }
            App.renderer.resize(w, h);
        };
        App.animate = function () {
            requestAnimationFrame(App.animate);
            App.validateLayout();
            App.renderer.render(App.stage);
        };
        App.toggleSound = function () {
            App.muted = !App.muted;
            if (App.muted)
                App.music.stop();
            else
                App.music.play(App.musicName);
        };
        App.loadFirstScreen = function () {
            if (!dressup_game.SKIP_INTRO)
                fl.Bundle.load('intro', function () { return App.changeScreen(new dressup_game.IntroScreen()); });
            else
                fl.Bundle.load('scene', function () { return App.changeScreen(new dressup_game.SceneScreen()); });
        };
        App.changeScreen = function (screen) {
            console.log("App.changeScreen: " + screen.name);
            if (!App._screen) {
                App.attachScreen(screen);
            }
            else {
                App._screen.content.cacheAsBitmap = true;
                App.beginTransition(function () {
                    App.stage.removeChild(App._screen.content);
                    App.attachScreen(screen);
                });
            }
        };
        App.attachScreen = function (screen) {
            screen.initialize();
            App._screen = screen;
            App.stage.addChildAt(App._screen.content, 0);
            App.adjustScreenSize();
            if (dressup_game.onScreenChanged)
                dressup_game.onScreenChanged(screen);
        };
        App.adjustScreenSize = function () {
            if (App._screen)
                App._screen.resize(App.renderer.width, App.renderer.height);
        };
        App.beginTransition = function (action) {
            var graphics = new PIXI.Graphics();
            graphics.beginFill(0xFFFFFF);
            graphics.drawRect(0, 0, App.renderer.width, App.renderer.height);
            App.stage.addChild(graphics);
            graphics.alpha = 0;
            graphics.cacheAsBitmap = true;
            graphics.interactive = true;
            createjs.Tween.get(graphics)
                .to({ alpha: 1 }, 250)
                .call(function (it) { return action(); })
                .to({ alpha: 0 }, 250)
                .call(function (it) { return App.stage.removeChild(graphics); });
        };
        App.gotoFullScreen = function () {
            var el = App.renderer.view;
            if (el.webkitRequestFullScreen)
                el.webkitRequestFullScreen();
            else if (el.mozRequestFullScreen)
                el.mozRequestFullScreen();
        };
        App.exitFullScreen = function () {
            var doc = document;
            if (doc.webkitCancelFullScreen)
                doc.webkitCancelFullScreen();
            else if (doc.mozCancelFullScreen)
                doc.mozCancelFullScreen();
        };
        Object.defineProperty(App, "screen", {
            get: function () {
                return this._screen;
            },
            enumerable: true,
            configurable: true
        });
        App.musicName = "music";
        App.muted = false;
        App.widthExtra = 170;
        App._prevWidth = -1;
        App._prevHeight = -1;
        return App;
    }());
    dressup_game.App = App;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    var AppMusic = (function () {
        function AppMusic() {
            this._volume = AppMusic.defaultMusicVol;
        }
        AppMusic.prototype.play = function (name) {
            this.stop();
            var url = AppMusic.rootPath + "/" + name + "." + AppMusic.defaultExt;
            this._currentMusic = new Howl({
                urls: [url],
                autoplay: true,
                loop: true,
                volume: this._volume,
            });
        };
        AppMusic.prototype.stop = function () {
            if (!this._currentMusic)
                return;
            var current = this._currentMusic;
            current.fade(current.volume(), 0, AppMusic.fadeDuration, function () { return current.unload(); });
            this._currentMusic = null;
        };
        Object.defineProperty(AppMusic.prototype, "currentName", {
            get: function () {
                return this._currentName;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AppMusic.prototype, "volume", {
            get: function () {
                return this._volume;
            },
            set: function (value) {
                if (this._volume != value) {
                    this._volume = value;
                    if (this._currentMusic)
                        this._currentMusic.volume(value);
                }
            },
            enumerable: true,
            configurable: true
        });
        AppMusic.rootPath = "assets/sounds";
        AppMusic.defaultExt = "mp3";
        AppMusic.defaultMusicVol = 0.5;
        AppMusic.fadeDuration = 800;
        return AppMusic;
    }());
    dressup_game.AppMusic = AppMusic;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    var BannerService = (function () {
        function BannerService() {
            this.banners = [];
        }
        BannerService.prototype.downloadBanners = function () {
            var _this = this;
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200)
                    _this.processXml(xhttp);
            };
            xhttp.open("GET", dressup_game.BANNER_URL, true);
            xhttp.send();
        };
        BannerService.prototype.processXml = function (xhttp) {
            console.log("banners data raceived:");
            var xml = xhttp.responseXML;
            var thumbnails = xml.getElementsByTagName("thumbnail");
            for (var i = 0; i < thumbnails.length; i++) {
                var image = thumbnails[i].getElementsByTagName("image")[0].childNodes[0].nodeValue;
                var url = thumbnails[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
                var banner = { image: image, url: url };
                this.banners.push(banner);
                this.loadBannerImage(banner);
            }
        };
        BannerService.prototype.loadBannerImage = function (banner) {
            var _this = this;
            var img = new Image();
            var base = new PIXI.BaseTexture(img);
            banner.texture = new PIXI.Texture(base);
            base.on("loaded", function () {
                console.log("banner loaded: " + banner.image);
                banner.isLoaded = true;
                if (_this.onBannerLoaded)
                    _this.onBannerLoaded();
            });
            img.src = banner.image;
        };
        return BannerService;
    }());
    dressup_game.BannerService = BannerService;
})(dressup_game || (dressup_game = {}));
var dressup_game;
(function (dressup_game) {
    var SoundButton = (function (_super) {
        __extends(SoundButton, _super);
        function SoundButton(target, action) {
            var _this = this;
            _super.call(this, target, function (it) {
                action(it);
                _this.refreshSoundState();
            });
            this.refreshSoundState();
        }
        SoundButton.prototype.refreshSoundState = function () {
            var clip = this.content;
            if (clip instanceof fl.Clip) {
                var stick = clip.getChildAt(clip.children.length - 1);
                stick.visible = dressup_game.App.muted;
            }
        };
        return SoundButton;
    }(fl.Button));
    dressup_game.SoundButton = SoundButton;
})(dressup_game || (dressup_game = {}));
var fl;
(function (fl) {
    var Color = (function () {
        function Color(r, g, b, a) {
            this.r = r;
            this.g = g;
            this.b = b;
            this.a = a;
        }
        Color.fromNum = function (value) {
            var r = (value & 0xFF0000) >> 16;
            var g = (value & 0x00FF00) >> 8;
            var b = (value & 0x0000FF);
            return new Color(r / 255.0, g / 255.0, b / 255.0, 1);
        };
        Color.prototype.clone = function () {
            return new Color(this.r, this.g, this.b, this.a);
        };
        Color.prototype.setTo = function (value) {
            value.r = this.r;
            value.g = this.g;
            value.b = this.b;
            value.a = this.a;
        };
        Color.prototype.setFrom = function (value) {
            this.r = value.r;
            this.g = value.g;
            this.b = value.b;
            this.a = value.a;
        };
        return Color;
    }());
    fl.Color = Color;
})(fl || (fl = {}));
var fl;
(function (fl) {
    var Internal = (function () {
        function Internal() {
        }
        Internal.dispatchLabels = function (target) {
            var n = target.labels.length;
            if (n == 0)
                return;
            var frame = target.currentFrame;
            for (var i = 0; i < n; i++) {
                if (target.labels[i].frame == frame) {
                    var label = target.labels[i].name;
                    if (label[0] == "#")
                        target.animation.applyControlLabel(label);
                    if (fl.onFrameLabel)
                        fl.onFrameLabel(target, label);
                }
            }
        };
        Internal.applyColor = function (target) {
            var lc = target.color;
            var parent = target.parent;
            if (parent && parent.isFlashObject) {
                var gc = parent.globalColor;
                var r = lc.r * gc.r;
                var g = lc.g * gc.g;
                var b = lc.b * gc.b;
                var a = lc.a * gc.a;
            }
            else {
                var r = lc.r;
                var g = lc.g;
                var b = lc.b;
                var a = lc.a;
            }
            target.tint = 255 * r << 16 | 255 * g << 8 | 255 * b;
            target.alpha = a;
        };
        Internal.clampRange = function (value, min, max) {
            if (value < min)
                return min;
            else if (value > max)
                return max;
            else
                return value;
        };
        Internal.EMPTY_ARRAY = [];
        return Internal;
    }());
    fl.Internal = Internal;
})(fl || (fl = {}));
var PIXI;
(function (PIXI) {
    PIXI.DisplayObject.prototype.detach = function () {
        if (this.parent)
            this.parent.removeChild(this);
    };
    PIXI.Container.prototype.forEachRecursive = function (action) {
        var n = this.children.length;
        for (var i = 0; i < n; i++) {
            var child = this.children[i];
            if (child.isFlashObject)
                action(child);
            if (child instanceof PIXI.Container)
                child.forEachRecursive(action);
        }
    };
    PIXI.Container.prototype.forEachFrameObject = function (action) {
        var n = this.children.length;
        for (var i = 0; i < n; i++) {
            var child = this.children[i];
            if (child.isFrameObject)
                action(child);
        }
    };
    PIXI.Container.prototype.findAll = function (predicate) {
        var result = [];
        var n = this.children.length;
        for (var i = 0; i < n; i++) {
            var child = this.children[i];
            if (predicate(child))
                result.push(child);
        }
        return result;
    };
    PIXI.Container.prototype.findAllByPrefix = function (prefix) {
        return this.findAll(function (it) {
            return it.name && it.name.indexOf(prefix) == 0;
        });
    };
    PIXI.Container.prototype.findByPath = function (path) {
        var parts = path.split('/');
        var target = this;
        for (var i = 0; i < parts.length; i++) {
            var child = target.getChildByName(parts[i]);
            if (!child)
                return null;
            if (i + 1 == parts.length)
                return child;
            if (!(child instanceof PIXI.Container))
                return null;
            target = child;
        }
        return null;
    };
    PIXI.Container.prototype.playAllChildren = function () {
        this.children.forEach(function (it) {
            var animable = it;
            if (animable.totalFrames > 1)
                animable.animation.play();
        });
    };
    PIXI.Container.prototype.stopAllChildren = function () {
        this.children.forEach(function (it) {
            var animable = it;
            if (animable.totalFrames > 1)
                animable.animation.stop();
        });
    };
})(PIXI || (PIXI = {}));
var fl;
(function (fl) {
    var Text = (function (_super) {
        __extends(Text, _super);
        function Text(text, style) {
            _super.call(this, text, style);
            this.timelineIndex = -1;
            this.color = new fl.Color(1, 1, 1, 1);
            this.isFlashObject = true;
            this.isFrameObject = false;
            this.scaleMultiplier = 1;
        }
        Text.fromData = function (data) {
            var text = data.text || "";
            var style = {};
            style.font = (data.bold ? "bold " : "")
                + (data.italic ? "italic " : "")
                + (data.fontSize + "px ")
                + data.fontName;
            style.fill = data.color;
            style.align = data.align;
            style.padding = 20;
            style.wordWrap = data.multiline;
            style.wordWrapWidth = data.textWidth;
            style.lineHeight = Math.floor(data.fontSize * 1.15) + data.lineSpacing;
            if (data.shadowColor) {
                style.dropShadow = true;
                style.dropShadowColor = data.shadowColor;
                style.dropShadowAngle = data.shadowAngle;
                style.dropShadowDistance = data.shadowDistance;
            }
            if (data.strokeColor) {
                style.stroke = data.strokeColor;
                style.strokeThickness = data.strokeThickness;
                style.lineHeight -= Math.max(1, Math.floor(0.25 * data.strokeThickness));
                style.lineJoin = "round";
            }
            var field = new fl.Text(text, style);
            if (data.align == "center")
                field.anchor.x = 0.5;
            else if (data.align == "right")
                field.anchor.x = 1;
            return field;
        };
        Object.defineProperty(Text.prototype, "scaleX", {
            get: function () { return this.scale.x * this.scaleMultiplier; },
            set: function (value) { this.scale.x = value / this.scaleMultiplier; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Text.prototype, "scaleY", {
            get: function () { return this.scale.y * this.scaleMultiplier; },
            set: function (value) { this.scale.y = value / this.scaleMultiplier; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Text.prototype, "scaleXY", {
            get: function () { return 0.5 * (this.scaleX + this.scaleY); },
            set: function (value) { this.scaleX = value; this.scaleY = value; },
            enumerable: true,
            configurable: true
        });
        Text.prototype.updateTransform = function () {
            fl.Internal.applyColor(this);
            _super.prototype.updateTransform.call(this);
        };
        return Text;
    }(PIXI.Text));
    fl.Text = Text;
})(fl || (fl = {}));
//# sourceMappingURL=dressup.js.map