Skip to content

Commit

Permalink
First pass at #386, fallback message may need work
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Aug 15, 2015
1 parent 475d660 commit 6a0c23a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .settings/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.tabSize": 3
"editor.tabSize": 3,
"editor.insertSpaces": true
}
9 changes: 9 additions & 0 deletions GruntFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ module.exports = function (grunt) {
// Shell Commands
//
shell: {

//
// Execute a small server
//
server: {
command: 'python -m SimpleHTTPServer 8089'
},

//
// Execute TypeScript compiler against Excalibur core
Expand Down Expand Up @@ -214,6 +221,8 @@ module.exports = function (grunt) {

grunt.registerTask('compile', ['shell:tsc', 'minified', 'concat', 'copy', 'shell:nuget'])

grunt.registerTask('server', [])

// Travis task - for Travis CI
grunt.registerTask('travis', 'default');
};
29 changes: 27 additions & 2 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// <reference path="Loader.ts" />
/// <reference path="Promises.ts" />
/// <reference path="Util/Util.ts" />
/// <reference path="Util/Detector.ts" />
/// <reference path="Binding.ts" />
/// <reference path="TileMap.ts" />
/// <reference path="Label.ts" />
Expand Down Expand Up @@ -402,6 +403,9 @@ module ex {

// this is a reference to the current requestAnimationFrame return value
private _requestId: number;

// this determines whether excalibur is compatible with your browser
private _compatible: boolean;

// loading
private _loader: ILoadable;
Expand Down Expand Up @@ -449,8 +453,24 @@ module ex {
displayMode = options.displayMode;
}

// Check compatibility
if(!(this._compatible = (new ex.Detector()).compatible())) {
var message = document.createElement('div');
message.innerText = 'Sorry, your browser does not support all the features needed for Excalibur';
document.body.appendChild(message);

if(canvasElementId) {
var canvas = document.getElementById(canvasElementId);
if(canvas) {
canvas.parentElement.removeChild(canvas);
}
}

return;
}

this._logger = Logger.getInstance();

this._logger.info('Powered by Excalibur.js visit", "http://excaliburjs.com", "for more information.');

this._logger.debug('Building engine...');
Expand Down Expand Up @@ -478,7 +498,7 @@ module ex {
this._logger.debug('Engine viewport is fullscreen');
this.displayMode = DisplayMode.FullScreen;
}


this._loader = new Loader();

Expand Down Expand Up @@ -1015,6 +1035,11 @@ module ex {
* [[Sound]], or [[Texture]].
*/
public start(loader?: ILoadable) : Promise<any> {
if(!this._compatible) {
var promise = new Promise();
return promise.reject('Excalibur is incompatible with your browser');
}

var loadingComplete: Promise<any>;
if (loader) {
loader.wireEngine(this);
Expand Down
84 changes: 84 additions & 0 deletions src/engine/Util/Detector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/// <reference path="Log.ts" />
module ex {

export class Detector {

// critical browser features required for ex to run
private _criticalTests = {
// Test canvas/2d context support
canvasSupport: function() {
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
},

// Test array buffer support ex uses for downloading binary data
arrayBufferSupport: function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/');
try {
xhr.responseType = 'arraybuffer';
} catch (e) {
return false;
}
return xhr.responseType === 'arraybuffer';
},

// Test data urls ex uses for sprites
dataUrlSupport: function() {
var canvas = document.createElement('canvas');
return canvas.toDataURL('image/png').indexOf('data:image/png') === 0;
},

// Test object url support for loading
objectUrlSupport: function() {
return 'URL' in window && 'revokeObjectURL' in URL && 'createObjectURL' in URL;
},

// RGBA support for colors
rgbaSupport: function() {
var style = document.createElement('a').style;
style.cssText = 'background-color:rgba(150,255,150,.5)';

return ('' + style.backgroundColor).indexOf('rgba') > -1;
}
};

// warnings excalibur performance will be degraded
private _warningTest = {
webAudioSupport: function() {
return !!((<any>window).AudioContext ||
(<any>window).webkitAudioContext ||
(<any>window).mozAudioContext ||
(<any>window).msAudioContext ||
(<any>window).oAudioContext);
},
webglSupport: function() {
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('webgl'));
}
};

public compatible(): boolean {
// Critical test will for ex not to run
for(var test in this._criticalTests) {
if(!this._criticalTests[test]()) {
ex.Logger.getInstance().error('Critical browser feature test for Excalibur failed:',
test, 'Excalibur cannot run!');
return false;
}
}

// Warning tests do not for ex to return false to compatibility
for(var warning in this._warningTest) {
if(!this._warningTest[warning]()) {
ex.Logger.getInstance().warn('Warning browser feature test for Excalibur failed:',
warning, 'Excalibur performance will be degraded');
}
}

return true;
}

}

}

0 comments on commit 6a0c23a

Please sign in to comment.