<commit_before>import {
	TextureLoader,
	ImageLoader
} from 'three';

import AssetsManager from '../base/AssetsManager';

export class ImagesEngine {

	constructor() {
		this.defaults = {
			//"waterNormal": "assets/images/waternormals.jpg",
			//"water": "assets/images/water.jpg",
			//'smokeparticle': 'assets/images/smokeparticle.png'
		};

		this.imagesDefault = {
			//"skybox": "assets/images/skybox_1.png"
		};

		this.map = {};
		this.images = [];
		this.numImages = 0;
		this.loader = new TextureLoader();
		this.imageLoader = new ImageLoader();

	}

	load = () => {
		// extending assets images with our defaults
		Object.assign(AssetsManager.textures(), this.defaults);
		Object.assign(AssetsManager.images(), this.imagesDefault);

		if (!(Object.keys(AssetsManager.textures()).length + Object.keys(AssetsManager.images()).length)) {
			return Promise.resolve('images');
		}

		const promises = Object
			.keys(AssetsManager.textures())
			.map(this.loadSingleTexture)
			.concat(Object.keys(AssetsManager.images())
			.map(this.loadSingleImage));

		return Promise.all(promises);
	}

	get(key) {
		return this.map[key] || false;
	}

	loadSingleImage = (id, imagePath) => {
		const path = imagePath || AssetsManager.images()[id];
		return new Promise(resolve => {
			try {
				this.imageLoader.load(path, (image) => {
					this.add(id, image);
					resolve(image);
				},
				() => {},  // displaying progress
				() => {
					resolve();
				});
			} catch (e) {
				console.log('[MAGE] error loading image ' + id + ' at path ' + path);
				reject();
			}
		})
	}

	loadSingleTexture = (id, imagePath) => {
		const existingTexture = this.get(id);
		if (existingTexture) {
			return Promise.resolve(existingTexture);
		}

		const path = imagePath || AssetsManager.textures()[id];
		return new Promise(resolve => {
			try {
				this.loader.load(path, (texture) => {
					this.add(id, texture);
					resolve(texture);
				},
				() => {},  // displaying progress
				() => {
					console.log('[Mage] error loading texture ' + id + ' at path ' + path);
					resolve();
				});
			} catch (e) {
				console.log('[MAGE] error loading texture ' + id + ' at path ' + path);<commit_msg>MS-5tqc fixed bug in imagesengine<commit_after>import {
	TextureLoader,
	ImageLoader
} from 'three';

import AssetsManager from '../base/AssetsManager';

export class ImagesEngine {

	constructor() {
		this.defaults = {
			//"waterNormal": "assets/images/waternormals.jpg",
			//"water": "assets/images/water.jpg",
			//'smokeparticle': 'assets/images/smokeparticle.png'
		};

		this.imagesDefault = {
			//"skybox": "assets/images/skybox_1.png"
		};

		this.map = {};
		this.images = [];
		this.numImages = 0;
		this.loader = new TextureLoader();
		this.imageLoader = new ImageLoader();

	}

	load = () => {
		// extending assets images with our defaults
		Object.assign(AssetsManager.textures(), this.defaults);
		Object.assign(AssetsManager.images(), this.imagesDefault);

		if (!(Object.keys(AssetsManager.textures()).length + Object.keys(AssetsManager.images()).length)) {
			return Promise.resolve('images');
		}

		const promises = Object
			.keys(AssetsManager.textures())
			.map(path => this.loadSingleTexture(path))
			.concat(Object.keys(AssetsManager.images())
			.map(path => this.loadSingleImage(path)));

		return Promise.all(promises);
	}

	get(key) {
		return this.map[key] || false;
	}

	loadSingleImage = (id, imagePath) => {
		const path = imagePath || AssetsManager.images()[id];
		return new Promise((resolve, reject) => {
			try {
				this.imageLoader.load(path, (image) => {
					this.add(id, image);
					resolve(image);
				},
				() => {},  // displaying progress
				() => {
					resolve();
				});
			} catch (e) {
				console.log('[MAGE] error loading image ' + id + ' at path ' + path);
				reject();
			}
		})
	}

	loadSingleTexture = (id, imagePath) => {
		const existingTexture = this.get(id);
		if (existingTexture) {
			return Promise.resolve(existingTexture);
		}

		const path = imagePath || AssetsManager.textures()[id];
		return new Promise((resolve, reject) => {
			try {
				this.loader.load(path, (texture) => {
					this.add(id, texture);
					resolve(texture);
				},
				() => {},  // displaying progress
				() => {
					console.log('[Mage] error loading texture ' + id + ' at path ' + path);
					resolve();
				});
			} catch (e) {
				console.log('[MAGE] error loading texture ' + id + ' at path ' + path);
{'fraction_non_alphanumeric': 0.17296446243814664, 'fraction_numerical': 0.0011246063877642825, 'mean_word_length': 3.267754318618042, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 27, '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': '6929579', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1433, 'n_words': 279}