classes/World.js
function(path, callback, opts) {

		if (!callback) callback = function() { };

		var fallbacks = [];
		if (path.each) {
			if (path.length==0) return;
			fallbacks = path;
			path      = fallbacks.shift()+"";
		}

		//Stuff that will make us not want to load files.
		if (this.failedFiles.contains(path)) return;

		opts = opts || {};
		var file = this.worldPath+path+'.js';
		if (opts.rootPath) file = path+'.js';

		var my = this;
		var err;
		var handleData = function(e,raw) {
			data = false;
			if (!raw) {
				err = e;
				my.failedFiles.push(path);
				/* Continue down our list of fallbacks. */
				if (fallbacks.length>0) {
					my.loadFile(fallbacks, callback, opts);
				} else {
					log_error("File not found: "+file);
				}
			} else {
				try { eval('data='+raw); }
				catch (e) { log_error(e); }
			} callback(err, data);
			return data;
		};

		if (opts.sync) {
			try {
				var data = fs.readFileSync(file);
			} catch (e) {
				this.failedFiles.push(path);
				/* Continue down our list of fallbacks. */
				if (fallbacks.length>0) {
					return this.loadFile(fallbacks, callback, opts);
				} else return e;
			} return handleData(false,data);
		} else {
			fs.readFile(file, handleData);
		}
	}
function(path, callback, opts) {

		if (!callback) callback = function() { };

		var fallbacks = [];
		if (path.each) {
			if (path.length==0) return;
			fallbacks = path;
			path      = fallbacks.shift()+"";
		}

		//Stuff that will make us not want to load files.
		if (this.failedFiles.contains(path)) return;

		opts = opts || {};
		var file = this.worldPath+path+'.js';
		if (opts.rootPath) file = path+'.js';

		var my = this;
		var err;
		var handleData = function(e,raw) {
			data = false;
			if (!raw) {
				err = e;
				my.failedFiles.push(path);
				/* Continue down our list of fallbacks. */
				if (fallbacks.length>0) {
					my.loadFile(fallbacks, callback, opts);
				} else {
					log_error("File not found: "+file);
				}
			} else {
				try { eval('data='+raw); }
				catch (e) { log_error(e); }
			} callback(err, data);
			return data;
		};

		if (opts.sync) {
			try {
				var data = fs.readFileSync(file);
			} catch (e) {
				this.failedFiles.push(path);
				/* Continue down our list of fallbacks. */
				if (fallbacks.length>0) {
					return this.loadFile(fallbacks, callback, opts);
				} else return e;
			} return handleData(false,data);
		} else {
			fs.readFile(file, handleData);
		}
	}
function ( path , callback , opts ) { if ( ! callback ) callback = function ( ) { } ; var fallbacks = [ ] ; if ( path . each ) { if ( path . length == 0 ) return ; fallbacks = path ; path = fallbacks . shift ( ) + "" ; } //Stuff that will make us not want to load files. if ( this . failedFiles . contains ( path ) ) return ; opts = opts || { } ; var file = this . worldPath + path + '.js' ; if ( opts . rootPath ) file = path + '.js' ; var my = this ; var err ; var handleData = function ( e , raw ) { data = false ; if ( ! raw ) { err = e ; my . failedFiles . push ( path ) ; /* Continue down our list of fallbacks. */ if ( fallbacks . length > 0 ) { my . loadFile ( fallbacks , callback , opts ) ; } else { log_error ( "File not found: " + file ) ; } } else { try { eval ( 'data=' + raw ) ; } catch ( e ) { log_error ( e ) ; } } callback ( err , data ) ; return data ; } ; if ( opts . sync ) { try { var data = fs . readFileSync ( file ) ; } catch ( e ) { this . failedFiles . push ( path ) ; /* Continue down our list of fallbacks. */ if ( fallbacks . length > 0 ) { return this . loadFile ( fallbacks , callback , opts ) ; } else return e ; } return handleData ( false , data ) ; } else { fs . readFile ( file , handleData ) ; } }
I'm putting this function last because it's the ugliest.
I m putting this function last because it s the ugliest .