<commit_before>package de.eternity.support.tiled;

class TiledTileset {

	int firstgid, tilecount;
	String name;
}<commit_msg>converts Tiled export tileset to single gamel tiles<commit_after>package de.eternity.support.tiled;

import java.util.Map;

import de.eternity.gfx.Animation;
import de.eternity.gfx.Animation.AnimationTimer;
import de.eternity.gfx.TextureStorage;
import de.eternity.map.Tile;
import de.eternity.map.TileStorage;

class TiledTileset {

	int firstgid, tilecount;
	String name;
	
	private Map<String, TiledTile> tiles;
	
	/**
	 * Makes a game tile for every texture tile in the tileset and loads the animations.
	 * @param tileStorage
	 * @param textureStorage
	 * @param tileset
	 */
	void initialize(TileStorage tileStorage, TextureStorage textureStorage){
		
		//TODO: load lua file
		
		//add all tiles with their animations
		for(int i = 0; i < tilecount; i++){
			//-1 because the tile id 0 is empty in the editor
			int globalId = textureStorage.translateToGlobalTextureId(name, firstgid + i) -1;
			
			boolean isPresent = tiles.containsKey("" + i);
			Animation tileAnimation;
			if(isPresent && tiles.get("" + i).hasAnimation()){
				
				//repackage the loaded information
				TiledTile loadedTile = tiles.get("" + i);
				
				int[] animationFrameTimesMillis = new int[loadedTile.animation.length];
				int[] translatedAnimationTextures = new int[animationFrameTimesMillis.length];
				
				for(int n = 0; n < animationFrameTimesMillis.length; n++){
					animationFrameTimesMillis[n] = loadedTile.animation[n].duration;
					translatedAnimationTextures[n] = textureStorage.translateToGlobalTextureId(name, firstgid + loadedTile.animation[n].tileid -1);
				}
				
				tileAnimation = new Animation(translatedAnimationTextures, animationFrameTimesMillis);
			}else{
				//make a single frame animation that does not update
				tileAnimation = new Animation(new int[]{globalId}, new int[]{-1});
			}
			//store the tile at the index for the start texture
			tileStorage.addTile(new Tile(tileAnimation), globalId);
		}
	}
}
{'fraction_non_alphanumeric': 0.10223953261927946, 'fraction_numerical': 0.0034079844206426485, 'mean_word_length': 4.1375, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '6337856', 'n_tokens_mistral': 710, 'n_tokens_neox': 608, 'n_words': 171}