<commit_before>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.badlogic.gdx.assets.loaders.resolvers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.files.FileHandle;

public class ResolutionFileResolver implements FileHandleResolver {
	public static class Resolution {
		int portraitWidth;
		int portraitHeight;
		String suffix;
		
		public Resolution(int portraitWidth, int portraitHeight, String suffix) {
			this.portraitWidth = portraitWidth;
			this.portraitHeight = portraitHeight;
			this.suffix = suffix;
		}
	}
	
	final FileHandleResolver baseResolver;
	final Resolution[] descriptors;
	
	public ResolutionFileResolver(FileHandleResolver baseResolver, Resolution ... descriptors) {
		this.baseResolver = baseResolver;
		this.descriptors = descriptors;
	}
	
	@Override
	public FileHandle resolve (String fileName) {
		int width = 0;
		int height = 0;
		if(Gdx.graphics.getWidth() > Gdx.graphics.getHeight()) {
			width = Gdx.graphics.getHeight();
			height = Gdx.graphics.getWidth();
		} else {
			width = Gdx.graphics.getWidth();
			height = Gdx.graphics.getHeight();
		}
		
		Resolution bestDesc = null;
		int bestDistance = Integer.MAX_VALUE;
		for(int i = 0, n = descriptors.length; i < n; i++) {
			int distance = Math.abs(width - descriptors[i].portraitWidth) + Math.abs(height - descriptors[i].portraitHeight);
			if(distance < bestDistance) {
				bestDistance = distance;
				bestDesc = descriptors[i];
			}
		}
		
		FileHandle handle = baseResolver.resolve(fileName + bestDesc.suffix);
		if(!handle.exists()) handle = baseResolver.resolve(fileName);
		return handle;
	}
}<commit_msg>[fixed] ResolutionFileResolver now wants images to be grouped in directories instead of appending a suffix per resolution. <commit_after>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.badlogic.gdx.assets.loaders.resolvers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.files.FileHandle;

public class ResolutionFileResolver implements FileHandleResolver {
	public static class Resolution {
		int portraitWidth;
		int portraitHeight;
		String suffix;
		
		public Resolution(int portraitWidth, int portraitHeight, String suffix) {
			this.portraitWidth = portraitWidth;
			this.portraitHeight = portraitHeight;
			this.suffix = suffix;
		}
	}
	
	final FileHandleResolver baseResolver;
	final Resolution[] descriptors;
	
	public ResolutionFileResolver(FileHandleResolver baseResolver, Resolution ... descriptors) {
		this.baseResolver = baseResolver;
		this.descriptors = descriptors;
	}
	
	@Override
	public FileHandle resolve (String fileName) {
		int width = 0;
		int height = 0;
		if(Gdx.graphics.getWidth() > Gdx.graphics.getHeight()) {
			width = Gdx.graphics.getHeight();
			height = Gdx.graphics.getWidth();
		} else {
			width = Gdx.graphics.getWidth();
			height = Gdx.graphics.getHeight();
		}
		
		Resolution bestDesc = null;
		int bestDistance = Integer.MAX_VALUE;
		for(int i = 0, n = descriptors.length; i < n; i++) {
			int distance = Math.abs(width - descriptors[i].portraitWidth) + Math.abs(height - descriptors[i].portraitHeight);
			if(distance < bestDistance) {
				bestDistance = distance;
				bestDesc = descriptors[i];
			}
		}
		
		FileHandle originalHandle = new FileHandle(fileName);
		FileHandle handle = baseResolver.resolve(originalHandle.parent() + "/" + bestDesc.suffix + "/" + originalHandle.name());
		if(!handle.exists()) handle = baseResolver.resolve(fileName);
		return handle;
	}
}
{'fraction_non_alphanumeric': 0.15421590226316845, 'fraction_numerical': 0.004406168636090527, 'mean_word_length': 4.487912087912088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4672761', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1312, 'n_words': 408}