-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
36 lines (23 loc) · 852 Bytes
/
models.js
File metadata and controls
36 lines (23 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var path = require( 'path' );
exports.rooms = [];
exports.initialize = function( dir ) {
/*
Autoload each model and make it local to models. This allows models to be
accessed simply through models instead of requiring each model one by one.
*/
var glob = require( 'glob' );
files = glob.sync( dir + '/**.js', {} );
files.forEach(function( file ) {
var model_name = path.basename( file, path.extname( file ) ).camelize();
exports[ model_name ] = require( file )[ model_name ]
console.log( 'Autoloading model: ' + model_name );
} );
/*
Autocreate rooms that can be joined by players
*/
var room_count = 5;
for( var i = 0; i < room_count; i ++ ) {
console.log( 'Creating room #' + i );
exports.rooms.push( new exports.Room() );
}
}