<commit_before>/// <reference path="Interface.ts" />

module TameGame {
    /**
     * Basic implementation of a frame-based animation function
     */
    export class FrameAnimation<TFrameData> implements AnimationWithCallback<TFrameData> {
        constructor(frames: TFrameData[], properties?: AnimationProperties) {
            var startTime: number                   = 0;
            var finishFns: AnimationAction[]        = [];
            var transitionFns: AnimationAction[]    = [];
            var frameFns: FrameAction<TFrameData>[] = [];
            var finished: boolean                   = false;
            var lastTime: number                    = 0;
            var lastProgress: number                = 0;
            var lastFrame: number                   = -1;

            // Copying the frames array ensures that nothing external can modify it underneath us
            frames = frames.slice(0);

            // Fill in missing properties (and create a new properties object to replace the original)
            properties = properties || {};
            properties = {
                duration: properties.duration || 1000.0,
                repeat: properties.repeat || false
            };

            // Specifies the start time for this animation
            var start = (milliseconds: number) => {
                startTime = milliseconds;
                lastTime = milliseconds;
            };

            // Updates the various action functions
            var onTransition = (action: AnimationAction) => {
                transitionFns.push(action);
                return this;
            }
            var onFinish = (action: AnimationAction) => {
                finishFns.push(action);
                return this;
            }
            var onFrame = (action: FrameAction<TFrameData>) => {
                frameFns.push(action);
                return this;
            }

            // Calls the various action functions
            var callTransitions = (progress, timeMillis) => transitionFns.forEach((transition) => transition(progress, timeMillis));
            var callFinish      = (progress, timeMillis) => finishFns.forEach((finish) => finish(progress, timeMillis));
            var callFrame       = (frame, progress, timeMillis) => frameFns.forEach((frameFn) => frameFn(frame, progress, timeMillis));

            // Aborts the animation early
            var finish  = () => {
                finished = true;
                callFinish(lastTime, lastProgress);
            }

            // Performs a tick
            var tick = (milliseconds: number) => {
                // Nothing to do if we're already finished
                if (finished) {
                    return;
                }

                var endTime     = startTime + properties.duration;

                if (milliseconds >= endTime) {
                    // If repeating, then reset the animation to the beginning again<commit_msg>Animations shouldn't do anything before their start time is hit<commit_after>/// <reference path="Interface.ts" />

module TameGame {
    /**
     * Basic implementation of a frame-based animation function
     */
    export class FrameAnimation<TFrameData> implements AnimationWithCallback<TFrameData> {
        constructor(frames: TFrameData[], properties?: AnimationProperties) {
            var startTime: number                   = 0;
            var finishFns: AnimationAction[]        = [];
            var transitionFns: AnimationAction[]    = [];
            var frameFns: FrameAction<TFrameData>[] = [];
            var finished: boolean                   = false;
            var lastTime: number                    = 0;
            var lastProgress: number                = 0;
            var lastFrame: number                   = -1;

            // Copying the frames array ensures that nothing external can modify it underneath us
            frames = frames.slice(0);

            // Fill in missing properties (and create a new properties object to replace the original)
            properties = properties || {};
            properties = {
                duration: properties.duration || 1000.0,
                repeat: properties.repeat || false
            };

            // Specifies the start time for this animation
            var start = (milliseconds: number) => {
                startTime = milliseconds;
                lastTime = milliseconds;
            };

            // Updates the various action functions
            var onTransition = (action: AnimationAction) => {
                transitionFns.push(action);
                return this;
            }
            var onFinish = (action: AnimationAction) => {
                finishFns.push(action);
                return this;
            }
            var onFrame = (action: FrameAction<TFrameData>) => {
                frameFns.push(action);
                return this;
            }

            // Calls the various action functions
            var callTransitions = (progress, timeMillis) => transitionFns.forEach((transition) => transition(progress, timeMillis));
            var callFinish      = (progress, timeMillis) => finishFns.forEach((finish) => finish(progress, timeMillis));
            var callFrame       = (frame, progress, timeMillis) => frameFns.forEach((frameFn) => frameFn(frame, progress, timeMillis));

            // Aborts the animation early
            var finish  = () => {
                finished = true;
                callFinish(lastTime, lastProgress);
            }

            // Performs a tick
            var tick = (milliseconds: number) => {
                // Nothing to do if we're already finished
                if (finished) {
                    return;
                }

                // Do not do any animation before the start time is hit
                if (milliseconds < startTime) {
                    return;
                }

                var endTime     = startTime + properties.duration;

                if (milliseconds >= endTime) {
                    // If repeating, then reset the animation to the beginning again
{'fraction_non_alphanumeric': 0.08662441085649276, 'fraction_numerical': 0.0032504469364537623, 'mean_word_length': 1.5138888888888888, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 39, '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': '6701834', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1329, 'n_words': 425}