<commit_before>"use strict";

/**
 * Cache for 2d object definitions
 */
function Object2DDefCache()
{
	/// The cache itself, mapping file name to definition
	this._cache = {};
	/// Whether all currently known 2d objects have been loaded yet
	this._preloaded = false;
	/// callbacks waiting to be executed
	this._callbacks = [];

	// preload all 2d0 objects
	var this_obj = this;
	$.ajax("__all__.2d0", {
		dataType: "json",
		error: function() {
			logError("Failed to initialize 2d object cache");
		},
		success: function(defs) { this_obj.fill(defs); }
	});
}

/**
 * Enumeration for the different types of 2d object. It seems that in practice
 * only type GROUND is used anymore, though.
 */
Object2DDefCache.Type = {
	GROUND: 0,
	PLANT: 1,
	FENCE: 2,
	INVALID: 3
};

/// Fill the cache with objects from the server
Object2DDefCache.prototype.fill = function(defs)
{
	if ("error" in defs)
	{
		logError(defs.error);
	}
	else
	{
		for (var fname in defs)
		{
			var def = defs[fname];
			if (def.texture_fname)
				def.texture = texture_cache.get(def.texture_fname);
			this._cache[fname] = def;
		}

		for (var i = 0; i < this._callbacks.length; ++i)
		{
			var cb = this._callbacks[i];
			cb.callback(this._cache[cb.fname]);
		}
		this._callbacks = [];

		this._preloaded = true;
	}

};

/**
 * Get a 2d object definition
 *
 * Get a 2d object definition from file name @a fname. If the definition is not
 * in the cache yet, it is requested from the server.
 * @param fname    File name of the definition to retrieve
 * @param callback optional callback function to execute once definition is loaded
 */
Object2DDefCache.prototype.get = function(fname, callback)
{
	fname = fname.toLowerCase();
	if (fname.substr(0, 2) == './')
		fname = fname.substr(2);
<commit_msg>When a 2d object def requested before the cache is loaded is not available after tehe load, complain<commit_after>"use strict";

/**
 * Cache for 2d object definitions
 */
function Object2DDefCache()
{
	/// The cache itself, mapping file name to definition
	this._cache = {};
	/// Whether all currently known 2d objects have been loaded yet
	this._preloaded = false;
	/// callbacks waiting to be executed
	this._callbacks = [];

	// preload all 2d0 objects
	var this_obj = this;
	$.ajax("__all__.2d0", {
		dataType: "json",
		error: function() {
			logError("Failed to initialize 2d object cache");
		},
		success: function(defs) { this_obj.fill(defs); }
	});
}

/**
 * Enumeration for the different types of 2d object. It seems that in practice
 * only type GROUND is used anymore, though.
 */
Object2DDefCache.Type = {
	GROUND: 0,
	PLANT: 1,
	FENCE: 2,
	INVALID: 3
};

/// Fill the cache with objects from the server
Object2DDefCache.prototype.fill = function(defs)
{
	if ("error" in defs)
	{
		logError(defs.error);
	}
	else
	{
		for (var fname in defs)
		{
			var def = defs[fname];
			if (def.texture_fname)
				def.texture = texture_cache.get(def.texture_fname);
			this._cache[fname] = def;
		}
		this._preloaded = true;

		// Now try to textures requested before preload completed
		for (var i = 0; i < this._callbacks.length; ++i)
		{
			var cb = this._callbacks[i];
			this.get(cb.fname, cb.callback);
		}
		this._callbacks = [];
	}

};

/**
 * Get a 2d object definition
 *
 * Get a 2d object definition from file name @a fname. If the definition is not
 * in the cache yet, it is requested from the server.
 * @param fname    File name of the definition to retrieve
 * @param callback optional callback function to execute once definition is loaded
 */
Object2DDefCache.prototype.get = function(fname, callback)
{
	fname = fname.toLowerCase();
	if (fname.substr(0, 2) == './')
		fname = fname.substr(2);

{'fraction_non_alphanumeric': 0.12252642992680943, 'fraction_numerical': 0.012198427758200054, 'mean_word_length': 3.4191616766467066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1260518', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1236, 'n_words': 406}