Skip to content

Commit 5ca567c

Browse files
committed
Adding more Device tests.
1 parent 36ca61d commit 5ca567c

7 files changed

Lines changed: 624 additions & 4 deletions

File tree

v3/src/boot/Game.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var CHECKSUM = require('../checksum');
88

9+
var Device = require('../device');
910
var Config = require('./Config');
1011
var DebugHeader = require('./DebugHeader');
1112
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
@@ -64,12 +65,10 @@ var Game = function (config)
6465
/**
6566
* @property {Phaser.Device} device - Contains device information and capabilities.
6667
*/
67-
// this.device = Phaser.Device;
68+
this.device = Device;
6869

6970
// this.rnd = new Phaser.RandomDataGenerator([ (Date.now() * Math.random()).toString() ]);
7071

71-
// this.device.whenReady(this.boot, this);
72-
7372
DOMContentLoaded(this.boot.bind(this));
7473

7574
};

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '8fd01380-b2b2-11e6-b621-1f12dc04eec3'
2+
build: 'bd4a1fd0-b2c2-11e6-ab9c-65bb17d312a9'
33
};
44
module.exports = CHECKSUM;

v3/src/device/Browser.js

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
var Browser = {
2+
3+
/**
4+
* @property {boolean} arora - Set to true if running in Arora.
5+
* @default
6+
*/
7+
arora: false,
8+
9+
/**
10+
* @property {boolean} chrome - Set to true if running in Chrome.
11+
* @default
12+
*/
13+
chrome: false,
14+
15+
/**
16+
* @property {number} chromeVersion - If running in Chrome this will contain the major version number.
17+
* @default
18+
*/
19+
chromeVersion: 0,
20+
21+
/**
22+
* @property {boolean} epiphany - Set to true if running in Epiphany.
23+
* @default
24+
*/
25+
epiphany: false,
26+
27+
/**
28+
* @property {boolean} firefox - Set to true if running in Firefox.
29+
* @default
30+
*/
31+
firefox: false,
32+
33+
/**
34+
* @property {number} firefoxVersion - If running in Firefox this will contain the major version number.
35+
* @default
36+
*/
37+
firefoxVersion: 0,
38+
39+
/**
40+
* @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
41+
* @default
42+
*/
43+
mobileSafari: false,
44+
45+
/**
46+
* @property {boolean} ie - Set to true if running in Internet Explorer.
47+
* @default
48+
*/
49+
ie: false,
50+
51+
/**
52+
* @property {number} ieVersion - If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion.
53+
* @default
54+
*/
55+
ieVersion: 0,
56+
57+
/**
58+
* @property {boolean} midori - Set to true if running in Midori.
59+
* @default
60+
*/
61+
midori: false,
62+
63+
/**
64+
* @property {boolean} opera - Set to true if running in Opera.
65+
* @default
66+
*/
67+
opera: false,
68+
69+
/**
70+
* @property {boolean} safari - Set to true if running in Safari.
71+
* @default
72+
*/
73+
safari: false,
74+
75+
/**
76+
* @property {number} safariVersion - If running in Safari this will contain the major version number.
77+
* @default
78+
*/
79+
safariVersion: 0,
80+
81+
/**
82+
* @property {boolean} trident - Set to true if running a Trident version of Internet Explorer (IE11+)
83+
* @default
84+
*/
85+
trident: false,
86+
87+
/**
88+
* @property {number} tridentVersion - If running in Internet Explorer 11 this will contain the major version number. See {@link http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx}
89+
* @default
90+
*/
91+
tridentVersion: 0,
92+
93+
/**
94+
* @property {boolean} edge - Set to true if running in Microsoft Edge browser.
95+
* @default
96+
*/
97+
// edge: false,
98+
99+
/**
100+
* @property {boolean} silk - Set to true if running in the Silk browser (as used on the Amazon Kindle)
101+
* @default
102+
*/
103+
silk: false
104+
105+
};
106+
107+
function init (OS)
108+
{
109+
var ua = navigator.userAgent;
110+
111+
if ((/Arora/).test(ua))
112+
{
113+
Browser.arora = true;
114+
}
115+
else if ((/Chrome\/(\d+)/).test(ua) && !OS.windowsPhone)
116+
{
117+
Browser.chrome = true;
118+
Browser.chromeVersion = parseInt(RegExp.$1, 10);
119+
}
120+
else if ((/Epiphany/).test(ua))
121+
{
122+
Browser.epiphany = true;
123+
}
124+
else if ((/Firefox\D+(\d+)/).test(ua))
125+
{
126+
Browser.firefox = true;
127+
Browser.firefoxVersion = parseInt(RegExp.$1, 10);
128+
}
129+
else if ((/AppleWebKit/).test(ua) && OS.iOS)
130+
{
131+
Browser.mobileSafari = true;
132+
}
133+
else if ((/MSIE (\d+\.\d+);/).test(ua))
134+
{
135+
Browser.ie = true;
136+
Browser.ieVersion = parseInt(RegExp.$1, 10);
137+
}
138+
else if ((/Midori/).test(ua))
139+
{
140+
Browser.midori = true;
141+
}
142+
else if ((/Opera/).test(ua))
143+
{
144+
Browser.opera = true;
145+
}
146+
else if ((/Safari/).test(ua) && !OS.windowsPhone)
147+
{
148+
Browser.safari = true;
149+
}
150+
else if ((/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/).test(ua))
151+
{
152+
Browser.ie = true;
153+
Browser.trident = true;
154+
Browser.tridentVersion = parseInt(RegExp.$1, 10);
155+
Browser.ieVersion = parseInt(RegExp.$3, 10);
156+
}
157+
158+
// Silk gets its own if clause because its ua also contains 'Safari'
159+
if ((/Silk/).test(ua))
160+
{
161+
Browser.silk = true;
162+
}
163+
164+
return Browser;
165+
}
166+
167+
module.exports = init;

v3/src/device/Features.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
var Features = {
2+
3+
/**
4+
* @property {boolean} canvas - Is canvas available?
5+
* @default
6+
*/
7+
canvas: false,
8+
9+
/**
10+
* @property {?boolean} canvasBitBltShift - True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap.
11+
* @default
12+
*/
13+
canvasBitBltShift: null,
14+
15+
/**
16+
* @property {boolean} webGL - Is webGL available?
17+
* @default
18+
*/
19+
webGL: false,
20+
21+
/**
22+
* @property {boolean} file - Is file available?
23+
* @default
24+
*/
25+
file: false,
26+
27+
/**
28+
* @property {boolean} fileSystem - Is fileSystem available?
29+
* @default
30+
*/
31+
fileSystem: false,
32+
33+
/**
34+
* @property {boolean} localStorage - Is localStorage available?
35+
* @default
36+
*/
37+
localStorage: false,
38+
39+
/**
40+
* @property {boolean} worker - Is worker available?
41+
* @default
42+
*/
43+
worker: false,
44+
45+
/**
46+
* @property {boolean} pointerLock - Is Pointer Lock available?
47+
* @default
48+
*/
49+
pointerLock: false,
50+
51+
/**
52+
* @property {boolean} vibration - Does the device support the Vibration API?
53+
* @default
54+
*/
55+
vibration: false,
56+
57+
/**
58+
* @property {boolean} getUserMedia - Does the device support the getUserMedia API?
59+
* @default
60+
*/
61+
getUserMedia: true
62+
63+
};
64+
65+
function init (OS, Browser)
66+
{
67+
Features.canvas = !!window['CanvasRenderingContext2D'] || OS.cocoonJS;
68+
69+
try
70+
{
71+
Features.localStorage = !!localStorage.getItem;
72+
}
73+
catch (error)
74+
{
75+
Features.localStorage = false;
76+
}
77+
78+
Features.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
79+
Features.fileSystem = !!window['requestFileSystem'];
80+
81+
var testWebGL = function ()
82+
{
83+
if (window['WebGLRenderingContext'])
84+
{
85+
try
86+
{
87+
var canvas = document.createElement('canvas');
88+
89+
// cocoon ...
90+
canvas.screencanvas = false;
91+
92+
var ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
93+
94+
return (ctx !== null);
95+
}
96+
catch (e)
97+
{
98+
return false;
99+
}
100+
}
101+
102+
return false;
103+
};
104+
105+
Features.webGL = testWebGL();
106+
107+
Features.worker = !!window['Worker'];
108+
109+
Features.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
110+
111+
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
112+
113+
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
114+
115+
Features.getUserMedia = Features.getUserMedia && !!navigator.getUserMedia && !!window.URL;
116+
117+
// Older versions of firefox (< 21) apparently claim support but user media does not actually work
118+
if (Browser.firefox && Browser.firefoxVersion < 21)
119+
{
120+
Features.getUserMedia = false;
121+
}
122+
123+
// Excludes iOS versions as they generally wrap UIWebView (eg. Safari WebKit) and it
124+
// is safer to not try and use the fast copy-over method.
125+
if (!OS.iOS && (Browser.ie || Browser.firefox || Browser.chrome))
126+
{
127+
Features.canvasBitBltShift = true;
128+
}
129+
130+
// Known not to work
131+
if (Browser.safari || Browser.mobileSafari)
132+
{
133+
Features.canvasBitBltShift = false;
134+
}
135+
136+
return Features;
137+
}
138+
139+
module.exports = init;

v3/src/device/Input.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var Input = {
2+
3+
/**
4+
* @property {boolean} touch - Is touch available?
5+
* @default
6+
*/
7+
touch: false,
8+
9+
/**
10+
* @property {boolean} mspointer - Is mspointer available?
11+
* @default
12+
*/
13+
mspointer: false,
14+
15+
/**
16+
* @property {?string} wheelType - The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll'
17+
* @default
18+
* @protected
19+
*/
20+
wheelEvent: null
21+
22+
};
23+
24+
function init (OS, Browser)
25+
{
26+
if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1))
27+
{
28+
Input.touch = true;
29+
}
30+
31+
if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled)
32+
{
33+
Input.mspointer = true;
34+
}
35+
36+
if (!OS.cocoonJS)
37+
{
38+
// See https://developer.mozilla.org/en-US/docs/Web/Events/wheel
39+
if ('onwheel' in window || (Browser.ie && 'WheelEvent' in window))
40+
{
41+
// DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+
42+
Input.wheelEvent = 'wheel';
43+
}
44+
else if ('onmousewheel' in window)
45+
{
46+
// Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7.
47+
Input.wheelEvent = 'mousewheel';
48+
}
49+
else if (Browser.firefox && 'MouseScrollEvent' in window)
50+
{
51+
// FF prior to 17. This should probably be scrubbed.
52+
Input.wheelEvent = 'DOMMouseScroll';
53+
}
54+
}
55+
56+
return Input;
57+
}
58+
59+
module.exports = init;

0 commit comments

Comments
 (0)