<commit_before>//TODO deal with update image assets without making children

include("assets/asset.js", true);
include("assets/imageasset.js", true);
include("assets/assetmanager.js", true);
include("timing/timer.js", true);

var floor = Math.floor;
var Vec = EN.Vector;
var Timer = EN.Timer;

function AnimationAsset(sFileName)
{
    var self = this;

    //Super constructor
    this._Asset(sFileName);

    this.m_cAnimationInfo = null;
    this.m_cBaseImage = null;
    this.m_nOrigWidth = 0;
    this.m_nOrigHeight = 0;
    
    this.m_sAnimation = "";
    this.m_cCurrentAnimation = null;
    this.CurrentFrame = 0;
    this.m_nPreviousFramesElapsed = 0;
    this.m_bAnimationRunning = false;

    this.m_cOffset = new EN.Vector();
    this.m_cOffset.OnChange(function(nNewX, nOldX, nNewY, nOldY){
        self.__OffsetChanged(nNewX, nNewY);
    });
};

inherits(AnimationAsset, EN.Asset);

Object.defineProperty(AnimationAsset.prototype, "Offset", {
    get: function(){
        return this.m_cOffset;
    },
    set: function(cOffset){
        this.m_cOffset.Set(cOffset);
    }
});

AnimationAsset.prototype.__OffsetChanged = function(x, y){
    if (this.m_cCurrentAnimation)
    {
        this.m_cBaseImage.Pos.x = -this.m_cCurrentAnimation.width * x;
        this.m_cBaseImage.Pos.y = -this.m_cCurrentAnimation.height * y;
    }
};

AnimationAsset.prototype.__SetFrame = function() {
    var nOffsetX = (this.CurrentFrame * this.m_cCurrentAnimation.width) % this.m_nOrigWidth;
    var nOffsetY = floor((this.CurrentFrame * this.m_cCurrentAnimation.width) / this.m_nOrigWidth) * this.m_cCurrentAnimation.height + this.m_cCurrentAnimation.rowOffset;

    this.m_cBaseImage.Offset = new Vec(nOffsetX, nOffsetY);
};

AnimationAsset.prototype.Load = function(fOnLoad){
    var self = this;

    //TODO gen file name once
    EN.AssetManager.LoadFile("animations/" + this.m_sFileName + ".json", function(cErr, sSprite){
        if (!cErr)
        {
            var cSprite = JSON.parse(sSprite);

            self.m_cAnimationInfo = cSprite;
            self.m_cBaseImage = new EN.ImageAsset(cSprite.spriteSheet);

            EN.Loader.Load([
                self.m_cBaseImage
            ], function(){
                self.m_nOrigWidth = self.m_cBaseImage.Width;
                self.m_nOrigHeight = self.m_cBaseImage.Height;

                fOnLoad();
            });
        }
        else
        {
            throw cErr;
        }
    });
};

AnimationAsset.prototype.Init = function(){
    this._Init_Asset();<commit_msg>animation asset now uses more effecient file format<commit_after>//TODO deal with update image assets without making children

include("assets/asset.js", true);
include("assets/imageasset.js", true);
include("assets/assetmanager.js", true);
include("timing/timer.js", true);

var floor = Math.floor;
var Vec = EN.Vector;
var Timer = EN.Timer;

function AnimationAsset(sFileName)
{
    var self = this;

    //Super constructor
    this._Asset(sFileName);

    this.m_cAnimationInfo = null;
    this.m_cBaseImage = null;
    this.m_nOrigWidth = 0;
    this.m_nOrigHeight = 0;
    
    this.m_sAnimation = "";
    this.m_cCurrentAnimation = null;
    this.CurrentFrame = 0;
    this.m_nPreviousFramesElapsed = 0;
    this.m_bAnimationRunning = false;

    this.m_cOffset = new EN.Vector();
    this.m_cOffset.OnChange(function(nNewX, nOldX, nNewY, nOldY){
        self.__OffsetChanged(nNewX, nNewY);
    });
};

inherits(AnimationAsset, EN.Asset);

Object.defineProperty(AnimationAsset.prototype, "Offset", {
    get: function(){
        return this.m_cOffset;
    },
    set: function(cOffset){
        this.m_cOffset.Set(cOffset);
    }
});

AnimationAsset.prototype.__OffsetChanged = function(x, y){
    if (this.m_cCurrentAnimation)
    {
        this.m_cBaseImage.Pos.x = -this.m_cCurrentAnimation.width * x;
        this.m_cBaseImage.Pos.y = -this.m_cCurrentAnimation.height * y;
    }
};

AnimationAsset.prototype.__SetFrame = function() {
    var nOffsetX = (this.CurrentFrame * this.m_cCurrentAnimation.width) % this.m_nOrigWidth;
    var nOffsetY = floor((this.CurrentFrame * this.m_cCurrentAnimation.width) / this.m_nOrigWidth) * this.m_cCurrentAnimation.height + this.m_cCurrentAnimation.rowOffset;

    this.m_cBaseImage.Offset = new Vec(nOffsetX, nOffsetY);
};

AnimationAsset.prototype.Load = function(fOnLoad){
    var self = this;

    //TODO gen file name once
    EN.AssetManager.LoadFile("animations/" + this.m_sFileName + ".json", function(cErr, sSprite){
        if (!cErr)
        {
            var cSprite = JSON.parse(sSprite);

            for (var sAnimation in cSprite.animations)
            {
                cSprite.animations[sAnimation] = extend({}, cSprite.baseInfo, cSprite.animations[sAnimation]);
            }

            self.m_cAnimationInfo = cSprite;
            self.m_cBaseImage = new EN.ImageAsset(cSprite.spriteSheet);

            EN.Loader.Load([
                self.m_cBaseImage
            ], function(){
                self.m_nOrigWidth = self.m_cBaseImage.Width;
                self.m_nOrigHeight = self.m_cBaseImage.Height;

                fOnLoad();
            });
        }
        else
        {
            throw cErr;
        }
    });
};

AnimationAsset.prototype.Init = function(){
    this._Init_Asset();
{'fraction_non_alphanumeric': 0.12101790763430725, 'fraction_numerical': 0.0015080113100848257, 'mean_word_length': 2.744530698659139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7533775', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1725, 'n_words': 293}