forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugHeader.js
More file actions
125 lines (100 loc) · 4.08 KB
/
Copy pathDebugHeader.js
File metadata and controls
125 lines (100 loc) · 4.08 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2026 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var CONST = require('../const');
/**
* Called automatically by Phaser.Game during initialization to output a styled banner to the browser
* console. The banner displays the Phaser version number, the active renderer (WebGL, Canvas, or
* Headless), the audio system in use (Web Audio, HTML5 Audio, or No Audio), and optionally the
* game title, version, and URL as configured. In browsers that support CSS console styling the
* banner is rendered with the colors defined in the Game Config; in IE it falls back to a plain
* text log. The banner is skipped entirely when `config.hideBanner` is `true`.
*
* You can customize or disable the header via the Game Config object.
*
* @function Phaser.Core.DebugHeader
* @since 3.0.0
*
* @param {Phaser.Game} game - The Phaser.Game instance which will output this debug header.
*/
var DebugHeader = function (game)
{
var config = game.config;
if (config.hideBanner)
{
return;
}
var renderType = 'WebGL';
if (config.renderType === CONST.CANVAS)
{
renderType = 'Canvas';
}
else if (config.renderType === CONST.HEADLESS)
{
renderType = 'Headless';
}
var audioConfig = config.audio;
var deviceAudio = game.device.audio;
var audioType;
if (deviceAudio.webAudio && !audioConfig.disableWebAudio)
{
audioType = 'Web Audio';
}
else if (audioConfig.noAudio || (!deviceAudio.webAudio && !deviceAudio.audioData))
{
audioType = 'No Audio';
}
else
{
audioType = 'HTML5 Audio';
}
if (!game.device.browser.ie)
{
var logoDataURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAYAAAAmL5yKAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAARBJREFUeNpi/P//P0OHsPB/BiCoePuWkYFEwALSXJElzMBgLwE2CNkQxgWr/yMr/p8QimlBu5DQ//+8vBBco/ofzAe6imH+qv/53/6jYJAYSA4ZoxoANYTPKhiuCQZwGcJU+e4dqpMmvsDq14krV2MPAxDha2CMKvoXoiE/PBQUDgQD8j82UFae9B9bOIC8B9UD9gIjjIMN7Ns6lWHn4XMoYu62RgxO3tkMjIyMII2MYAOAtmFVhA+ADHf2ycGMRhANjUq8YO+WKWCvgAORIV8CkpDCrzIwsLIymC1qAtuAD4Bsh3sBmqAY3qcGwL2AC4DCpKtzHlgzOLWihwEuzTCN0GhDJHeYC4gByBphACDAAH2dDIxdjr+VAAAAAElFTkSuQmCC';
var mainStyle = 'color: ' + config.bannerTextColor + ';';
var bannerBackgroundColor = Array.isArray(config.bannerBackgroundColor)
? config.bannerBackgroundColor
: [ config.bannerBackgroundColor ];
// linear-gradient requires at least two color stops, so duplicate if there's only one
if (bannerBackgroundColor.length === 1)
{
bannerBackgroundColor = [ bannerBackgroundColor[0], bannerBackgroundColor[0] ];
}
var gradient = 'linear-gradient(to bottom, ' + bannerBackgroundColor.join(', ') + ')';
mainStyle += ' background-image: url("' + logoDataURI + '"), ' + gradient + ';';
mainStyle += ' background-repeat: no-repeat;';
mainStyle += ' background-position: 4px center, 0 0;';
mainStyle += ' padding: 2px 6px 2px 24px;';
var c = '%c';
var args = [ null, mainStyle ];
// URL link background color (always transparent to support different browser themes)
args.push('background: transparent');
if (config.gameTitle)
{
c = c.concat(config.gameTitle);
if (config.gameVersion)
{
c = c.concat(' v' + config.gameVersion);
}
if (!config.hidePhaser)
{
c = c.concat(' / ');
}
}
if (!config.hidePhaser)
{
c = c.concat('Phaser v' + CONST.VERSION + ' (' + renderType + ' | ' + audioType + ')');
}
c = c.concat('%c ' + config.gameURL);
// Inject the new string back into the args array
args[0] = c;
console.log.apply(console, args);
}
else if (window['console'])
{
console.log('Phaser v' + CONST.VERSION + ' / https://phaser.io');
}
};
module.exports = DebugHeader;