-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at #386, fallback message may need work
- Loading branch information
Showing
4 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
} |