Remove 'color' as a required attribute

This commit is contained in:
Riley Shaw 2014-08-17 02:23:39 -04:00
parent 8caf0fe500
commit 39940355f0
4 changed files with 45 additions and 23 deletions

View File

@ -131,13 +131,8 @@ var creatureFactory = (function () {
register: function (options, init) { register: function (options, init) {
// required attributes // required attributes
var type = options.type; var type = options.type;
var color = options.color;
// only register classes that fulfill the creature contract // only register classes that fulfill the creature contract
if (typeof type === 'string' && if (typeof type === 'string' && typeof types[type] === 'undefined') {
typeof types[type] === 'undefined' &&
typeof color === 'object' &&
color.length === 3) {
// set the constructor, including init if it's defined // set the constructor, including init if it's defined
if (typeof init === 'function') { if (typeof init === 'function') {
types[type] = function () { types[type] = function () {
@ -150,6 +145,12 @@ var creatureFactory = (function () {
}; };
} }
var color = options.color;
// set the color randomly if none is provided
if (typeof color !== 'object' || color.length !== 3) {
options.color = [_.random(255), _.random(255), _.random(255)];
}
types[type].prototype = new baseCreature(); types[type].prototype = new baseCreature();
types[type].prototype.constructor = types[type]; types[type].prototype.constructor = types[type];

13
dist/terra.js vendored
View File

@ -141,13 +141,8 @@ var creatureFactory = (function () {
register: function (options, init) { register: function (options, init) {
// required attributes // required attributes
var type = options.type; var type = options.type;
var color = options.color;
// only register classes that fulfill the creature contract // only register classes that fulfill the creature contract
if (typeof type === 'string' && if (typeof type === 'string' && typeof types[type] === 'undefined') {
typeof types[type] === 'undefined' &&
typeof color === 'object' &&
color.length === 3) {
// set the constructor, including init if it's defined // set the constructor, including init if it's defined
if (typeof init === 'function') { if (typeof init === 'function') {
types[type] = function () { types[type] = function () {
@ -160,6 +155,12 @@ var creatureFactory = (function () {
}; };
} }
var color = options.color;
// set the color randomly if none is provided
if (typeof color !== 'object' || color.length !== 3) {
options.color = [_.random(255), _.random(255), _.random(255)];
}
types[type].prototype = new baseCreature(); types[type].prototype = new baseCreature();
types[type].prototype.constructor = types[type]; types[type].prototype.constructor = types[type];

2
dist/terra.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -14,8 +14,16 @@ var paths = {
demo: { demo: {
entry: './demo/scripts/main.js', entry: './demo/scripts/main.js',
scripts: './demo/scripts/**/*.js', scripts: './demo/scripts/**/*.js',
stylesheets: ['./demo/stylesheets/**/*.css', './demo/stylesheets/**/*.sass'], extraScripts: [
extras: './*.{png,ico,txt,xml}' './bower_components/smooth-scroll.js/dist/js/bind-polyfill.min.js',
'./bower_components/smooth-scroll.js/dist/js/smooth-scroll.min.js',
'./demo/scripts/prism.js'
],
stylesheets: {
css: './demo/stylesheets/**/*.css',
sass: './demo/stylesheets/**/*.sass'
},
temp: './demo/temp'
}, },
dist: { dist: {
scripts: './dist', scripts: './dist',
@ -53,23 +61,35 @@ gulp.task('demo', function() {
debug: argv.debug debug: argv.debug
}) })
.bundle() .bundle()
.pipe(source('terra.demo.min.js')) .pipe(source('temp.js'))
.pipe(gulp.dest(paths.demo.temp))
});
gulp.task('sass', function () {
return gulp.src(paths.demo.stylesheets.sass)
.pipe($.rubySass())
.pipe($.autoprefixer())
.pipe(gulp.dest(paths.demo.temp))
});
gulp.task('js_concat', ['demo'], function () {
return gulp.src(paths.demo.extraScripts.concat(paths.demo.temp + '/*.js'))
.pipe($.concat('terra.demo.min.js'))
.pipe($.streamify( $.uglify() )) .pipe($.streamify( $.uglify() ))
.pipe(gulp.dest(paths.dist.demo)) .pipe(gulp.dest(paths.dist.demo))
}); });
gulp.task('sass', function () { gulp.task('css_concat', ['sass'], function () {
return gulp.src(paths.demo.stylesheets) return gulp.src([paths.demo.stylesheets.css, paths.demo.temp + '/*.css'])
.pipe($.rubySass()) .pipe($.concat('main.css'))
.pipe($.autoprefixer())
.pipe($.minifyCss()) .pipe($.minifyCss())
.pipe(gulp.dest(paths.dist.demo)) .pipe(gulp.dest(paths.dist.demo))
}); });
gulp.task('watch', function() { gulp.task('watch', function() {
gulp.watch([paths.app.all, paths.app.ext], ['lint', 'scripts']); gulp.watch([paths.app.all, paths.app.ext], ['lint', 'scripts']);
gulp.watch(paths.demo.scripts, ['demo']); gulp.watch(paths.demo.scripts, ['demo','js_concat']);
gulp.watch(paths.demo.stylesheets, ['sass']); gulp.watch([paths.demo.stylesheets.sass, paths.demo.stylesheets.css], ['sass', 'css_concat']);
}); });
gulp.task('deploy', function () { gulp.task('deploy', function () {
@ -86,4 +106,4 @@ gulp.task('webserver', function() {
})); }));
}); });
gulp.task( 'default', [ 'lint', 'scripts', 'demo', 'sass', 'webserver', 'watch' ] ); gulp.task( 'default', [ 'lint', 'scripts', 'demo', 'js_concat', 'sass', 'css_concat', 'webserver', 'watch' ] );