<commit_before>package com.ezardlabs.dethsquare;

public final class Animator extends Script {
	private Animation[] animations;
	private int index = -1;
	private int frame = 0;
	private long nextFrameTime = 0;
	private boolean onAnimationFinishedCalled = false;
	private int direction = 1;

	public Animator(Animation... animations) {
		this.animations = animations;
	}

	public void setAnimations(Animation... animations) {
		this.animations = animations;
	}

	public void update() {
		int startFrame = frame;
		if (index == -1) return;
		if (System.currentTimeMillis() >= nextFrameTime) {
			nextFrameTime += animations[index].frameDuration;
			switch (animations[index].type) {
				case LOOP:
					frame += direction;
					if (frame == animations[index].frames.length) {
						frame = 0;
					}
					break;
				case ONE_SHOT:
					if (frame < animations[index].frames.length - 1) {
						frame += direction;
					} else {
						if (!onAnimationFinishedCalled && animations[index].listener != null) {
							animations[index].listener.onAnimationFinished(this);
							onAnimationFinishedCalled = true;
						}
						return;
					}
					break;
				case OSCILLATE:
					frame += direction;
					if (frame == 0 || frame == animations[index].frames.length - 1) {
						direction *= -1;
					}
					break;
			}
			gameObject.renderer.sprite = animations[index].frames[frame];
		}
		if (frame != startFrame && animations[index].listener != null) {
			animations[index].listener.onFrame(frame);
		}
	}

	public void play(String animationName) {
		if (index != -1 && animations[index].name.equals(animationName)) return;
		for (int i = 0; i < animations.length; i++) {
			if (i != index && animations[i].name.equals(animationName)) {
				index = i;
				frame = 0;
				direction = 1;
				nextFrameTime = System.currentTimeMillis() + animations[index].frameDuration;
				onAnimationFinishedCalled = false;
				gameObject.renderer.sprite = animations[index].frames[frame];
				if (animations[index].listener != null) animations[index].listener.onAnimatedStarted(this);
				break;
			}
		}
	}
}<commit_msg>Animations can now be added to an Animator after initialisation<commit_after>package com.ezardlabs.dethsquare;

public final class Animator extends Script {
	private Animation[] animations;
	private int index = -1;
	private int frame = 0;
	private long nextFrameTime = 0;
	private boolean onAnimationFinishedCalled = false;
	private int direction = 1;

	public Animator(Animation... animations) {
		this.animations = animations;
	}

	public void setAnimations(Animation... animations) {
		this.animations = animations;
	}

	public void addAnimations(Animation... animations) {
		Animation[] newAnimations = new Animation[this.animations.length + animations.length];
		System.arraycopy(this.animations, 0, newAnimations, 0, this.animations.length);
		System.arraycopy(animations, 0, newAnimations, this.animations.length, animations.length);
		this.animations = newAnimations;
	}

	public void update() {
		int startFrame = frame;
		if (index == -1) return;
		if (System.currentTimeMillis() >= nextFrameTime) {
			nextFrameTime += animations[index].frameDuration;
			switch (animations[index].type) {
				case LOOP:
					frame += direction;
					if (frame == animations[index].frames.length) {
						frame = 0;
					}
					break;
				case ONE_SHOT:
					if (frame < animations[index].frames.length - 1) {
						frame += direction;
					} else {
						if (!onAnimationFinishedCalled && animations[index].listener != null) {
							animations[index].listener.onAnimationFinished(this);
							onAnimationFinishedCalled = true;
						}
						return;
					}
					break;
				case OSCILLATE:
					frame += direction;
					if (frame == 0 || frame == animations[index].frames.length - 1) {
						direction *= -1;
					}
					break;
			}
			gameObject.renderer.sprite = animations[index].frames[frame];
		}
		if (frame != startFrame && animations[index].listener != null) {
			animations[index].listener.onFrame(frame);
		}
	}

	public void play(String animationName) {
		if (index != -1 && animations[index].name.equals(animationName)) return;
		for (int i = 0; i < animations.length; i++) {
			if (i != index && animations[i].name.equals(animationName)) {
				index = i;
				frame = 0;
				direction = 1;
				nextFrameTime = System.currentTimeMillis() + animations[index].frameDuration;
				onAnimationFinishedCalled = false;
				gameObject.renderer.sprite = animations[index].frames[frame];
				if (animations[index].listener != null)
					animations[index].listener.onAnimatedStarted(this);
				break;
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.12592270950933565, 'fraction_numerical': 0.006730351715154147, 'mean_word_length': 3.4684772065955385, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '352150', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1386, 'n_words': 322}