<commit_before>package de.eternity.gfx;

public class Animation {
	
	private class AnimationTimer{
		
		private int currentTexture;
		private double[] frameTimesSeconds;
		
		private transient double unaccountedTimeSeconds;
		
		private void update(double delta){
			
			//only if there are more than 1 frames in the animation
			if(Animation.this.textureCount > 1){
				//add delta to unaccounted time
				unaccountedTimeSeconds += delta;
				
				boolean isSkipping = true;
				int skippedFrames = 0;
				//calculate how many frames are to be skipped
				while(isSkipping){
					
					//calculate if the next frame has been reached
					double timeForNextFrame = frameTimesSeconds[(currentTexture + skippedFrames) % Animation.this.textureCount];
					if(unaccountedTimeSeconds > timeForNextFrame){
						skippedFrames++;
						unaccountedTimeSeconds -= timeForNextFrame;
					}
				}
				
				//update current texture id
				currentTexture = (currentTexture + skippedFrames) % Animation.this.textureCount;
			}
		}
	}
	
	//non saved variables
	private transient boolean isInitialized = false;
	private transient int textureCount;

	//saved and loaded variables
	private String tileset;
	private int[] textureIds;
	
	private AnimationTimer animationTimer;
	
	/**
	 * Initializes the animation.
	 * @param textureStorage
	 */
	public synchronized void init(TextureStorage textureStorage){
		//only initialize once
		if(!isInitialized){
			isInitialized = true;
			
			textureCount = textureIds.length;
			
			//translate the texture ids
			for(int i = 0; i < textureIds.length; i++)
				textureIds[i] = textureStorage.translateToGlobalTextureId(tileset, i);
		}
	}
	
	public void update(double delta){
		animationTimer.update(delta);
	}
	
	public Texture getCurrentTexture(TextureStorage textureStorage){
		return textureStorage.getTexture(animationTimer.currentTexture);
	}
}<commit_msg>fixed bug where the animation would not use the correct textures<commit_after>package de.eternity.gfx;

public class Animation {
	
	public class AnimationTimer{
		
		private double[] frameTimesSeconds;

		private transient int currentTexture = 0;
		private transient double unaccountedTimeSeconds = 0;
		
		public AnimationTimer(int[] animationFrameTimesMillis){
			
			frameTimesSeconds = new double[animationFrameTimesMillis.length];
			for(int i = 0; i < frameTimesSeconds.length; i++)
				frameTimesSeconds[i] = animationFrameTimesMillis[i] / 1000d;
		}
		
		private void update(double delta){
			
			//only if there are more than 1 frames in the animation
			if(Animation.this.textureCount > 1){
				//add delta to unaccounted time
				unaccountedTimeSeconds += delta;
				
				boolean isSkipping = true;
				int skippedFrames = 0;
				//calculate how many frames are to be skipped
				while(isSkipping){
					
					//calculate if the next frame has been reached
					double timeForNextFrame = frameTimesSeconds[(currentTexture + skippedFrames) % Animation.this.textureCount];
					if(unaccountedTimeSeconds > timeForNextFrame){
						skippedFrames++;
						unaccountedTimeSeconds -= timeForNextFrame;
					}
				}
				
				//update current texture id
				currentTexture = (currentTexture + skippedFrames) % Animation.this.textureCount;
			}
		}
	}
	
	//non saved variables
//	private transient boolean isInitialized = false;
	private transient int textureCount;

	//saved and loaded variables
	private int[] textureIds;
	
	private AnimationTimer animationTimer;
	
	public Animation(int[] textureIds, AnimationTimer animationTimer){
		this.textureIds = textureIds;
		textureCount = textureIds.length;
	}

	//	/**
//	 * Initializes the animation.
//	 * @param textureStorage
//	 */
//	public synchronized void init(TextureStorage textureStorage){
//		//only initialize once
//		if(!isInitialized){
//			isInitialized = true;
//			
//			textureCount = textureIds.length;
//			
//			//translate the texture ids
//			for(int i = 0; i < textureIds.length; i++)
//				textureIds[i] = textureStorage.translateToGlobalTextureId(tileset, i);
//		}
//	}
	
	public void update(double delta){
		animationTimer.update(delta);
	}
	
	public Texture getCurrentTexture(TextureStorage textureStorage){
		return textureStorage.getTexture(textureIds[animationTimer.currentTexture]);
	}
}
{'fraction_non_alphanumeric': 0.0880281690140845, 'fraction_numerical': 0.0035211267605633804, 'mean_word_length': 3.6365614798694232, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '4534951', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1152, 'n_words': 334}