Skip to content

Commit 6bbafa2

Browse files
committed
4.0.0
1 parent 17e2281 commit 6bbafa2

File tree

4 files changed

+139
-209
lines changed

4 files changed

+139
-209
lines changed
Lines changed: 67 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,92 @@
1-
var ref = Phaser.Scale;
2-
var ScaleModes = ref.ScaleModes;
3-
var MAX_VALUE = Number.MAX_VALUE;
1+
const { ScaleModes } = Phaser.Scale;
2+
const { MAX_VALUE } = Number;
43

5-
var aspectModeNames = {};
4+
const aspectModeNames = {};
65

7-
for (var name in ScaleModes) {
6+
for (const name in ScaleModes) {
87
aspectModeNames[ScaleModes[name]] = name;
98
}
109

11-
var orientationNames = {};
12-
orientationNames[Phaser.Scale.Orientation.LANDSCAPE] = 'landscape';
13-
orientationNames[Phaser.Scale.Orientation.PORTRAIT] = 'portrait';
10+
const orientationNames = {
11+
[Phaser.Scale.Orientation.LANDSCAPE]: 'landscape',
12+
[Phaser.Scale.Orientation.PORTRAIT]: 'portrait'
13+
};
1414

15-
var getSizeMaxString = function (size) {
16-
return (size.maxWidth < MAX_VALUE || size.maxHeight < MAX_VALUE) ? (" max=" + (size.maxWidth) + "×" + (size.maxHeight)) : ''
15+
const getSizeMaxString = function (size) {
16+
return (size.maxWidth < MAX_VALUE || size.maxHeight < MAX_VALUE) ? ` max=${size.maxWidth}×${size.maxHeight}` : ''
1717
};
1818

19-
var getSizeMinString = function (size) {
20-
return (size.minWidth > 0 || size.minHeight > 0) ? (" min=" + (size.minWidth) + "×" + (size.minHeight)) : ''
19+
const getSizeMinString = function (size) {
20+
return (size.minWidth > 0 || size.minHeight > 0) ? ` min=${size.minWidth}×${size.minHeight}` : ''
2121
};
2222

23-
var getSizeSnapString = function (size, precision) {
24-
var ref = size.snapTo;
25-
var x = ref.x;
26-
var y = ref.y;
23+
const getSizeSnapString = function (size, precision) {
24+
const { x, y } = size.snapTo;
2725

28-
return (x === 0 && y === 0) ? '' : (" snap=" + (vectorToString(size.snapTo, precision)))
26+
return (x === 0 && y === 0) ? '' : ` snap=${vectorToString(size.snapTo, precision)}`
2927
};
3028

31-
var aspectModeToString = function (mode) {
29+
const aspectModeToString = function (mode) {
3230
return aspectModeNames[mode]
3331
};
3432

35-
var vectorToString = function (vec, precision) {
36-
if ( precision === void 0 ) precision = 3;
37-
38-
return ("(" + (vec.x.toFixed(precision)) + ", " + (vec.y.toFixed(precision)) + ")")
33+
const vectorToString = function (vec, precision = 3) {
34+
return `(${vec.x.toFixed(precision)}, ${vec.y.toFixed(precision)})`
3935
};
4036

41-
var xyToString = function (x, y, precision) {
42-
if ( precision === void 0 ) precision = 3;
43-
44-
return ("(" + (x.toFixed(precision)) + ", " + (y.toFixed(precision)) + ")")
37+
const xyToString = function (x, y, precision = 3) {
38+
return `(${x.toFixed(precision)}, ${y.toFixed(precision)})`
4539
};
4640

47-
var sizeToString = function (size) {
48-
return ((size.width.toFixed(1)) + "×" + (size.height.toFixed(1)) + " [" + (size.aspectRatio.toFixed(3)) + "] mode=" + (aspectModeToString(size.aspectMode)) + (getSizeMaxString(size)) + (getSizeMinString(size)) + (getSizeSnapString(size, 1)) + (size._parent ? ('' + sizeToString(size._parent)) : ''))
41+
const sizeToString = function (size) {
42+
return `${size.width.toFixed(1)}×${size.height.toFixed(1)} [${size.aspectRatio.toFixed(3)}] mode=${aspectModeToString(size.aspectMode)}${getSizeMaxString(size)}${getSizeMinString(size)}${getSizeSnapString(size, 1)}${size._parent ? (`${sizeToString(size._parent)}`) : ''}`
4943
};
5044

51-
var rectToString = function (rect, precision) {
52-
if ( precision === void 0 ) precision = 1;
53-
54-
return ("x=" + (rect.x.toFixed(precision)) + " y=" + (rect.y.toFixed(precision)) + " w=" + (rect.width.toFixed(precision)) + " h=" + (rect.height.toFixed(precision)))
45+
const rectToString = function (rect, precision = 1) {
46+
return `x=${rect.x.toFixed(precision)} y=${rect.y.toFixed(precision)} w=${rect.width.toFixed(precision)} h=${rect.height.toFixed(precision)}`
5547
};
5648

57-
var logEnterFullscreen = function () {
49+
const logEnterFullscreen = function () {
5850
console.info('enter fullscreen');
5951
};
6052

61-
var logFullscreenFailed = function () {
53+
const logFullscreenFailed = function () {
6254
console.info('fullscreen failed');
6355
};
6456

65-
var logFullscreenUnsupported = function () {
57+
const logFullscreenUnsupported = function () {
6658
console.info('fullscreen unsupported');
6759
};
6860

69-
var logLeaveFullscreen = function () {
61+
const logLeaveFullscreen = function () {
7062
console.info('leave fullscreen');
7163
};
7264

73-
var logOrientationChange = function (orientation) {
65+
const logOrientationChange = function (orientation) {
7466
console.info('orientation change', orientationNames[orientation]);
7567
};
7668

77-
var logResize = function (game, base, display, prevWidth, prevHeight) {
69+
const logResize = function (game, base, display, prevWidth, prevHeight) {
7870
console.debug('resize', sizeToString(display));
7971
};
8072

81-
var ref$1 = Phaser.Core.Events;
82-
var POST_RENDER = ref$1.POST_RENDER;
83-
84-
var ref$1$1 = Phaser.Scale.Events;
85-
var ENTER_FULLSCREEN = ref$1$1.ENTER_FULLSCREEN;
86-
var FULLSCREEN_FAILED = ref$1$1.FULLSCREEN_FAILED;
87-
var FULLSCREEN_UNSUPPORTED = ref$1$1.FULLSCREEN_UNSUPPORTED;
88-
var LEAVE_FULLSCREEN = ref$1$1.LEAVE_FULLSCREEN;
89-
var ORIENTATION_CHANGE = ref$1$1.ORIENTATION_CHANGE;
90-
var RESIZE = ref$1$1.RESIZE;
91-
92-
var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
93-
function DebugGameScalePlugin () {
94-
superclass.apply(this, arguments);
95-
}
73+
const { POST_RENDER } = Phaser.Core.Events;
9674

97-
if ( superclass ) DebugGameScalePlugin.__proto__ = superclass;
98-
DebugGameScalePlugin.prototype = Object.create( superclass && superclass.prototype );
99-
DebugGameScalePlugin.prototype.constructor = DebugGameScalePlugin;
75+
const { ENTER_FULLSCREEN, FULLSCREEN_FAILED, FULLSCREEN_UNSUPPORTED, LEAVE_FULLSCREEN, ORIENTATION_CHANGE, RESIZE } = Phaser.Scale.Events;
10076

101-
DebugGameScalePlugin.prototype.init = function init (data) {
77+
class DebugGameScalePlugin extends Phaser.Plugins.BasePlugin {
78+
init (data) {
10279
if (!this.game.renderer.gameCanvas) {
10380
throw new Error('CANVAS renderer only')
10481
}
10582

10683
console.info('device.fullscreen.available', this.game.device.fullscreen.available);
107-
};
84+
}
10885

109-
DebugGameScalePlugin.prototype.start = function start () {
86+
start () {
11087
this.game.events.on(POST_RENDER, this.render, this);
11188

112-
var ref = this.game.scale;
113-
var parent = ref.parent;
89+
const { parent } = this.game.scale;
11490

11591
if (parent) {
11692
parent.style.outline = 'thick solid rgba(255,0,0,0.5)';
@@ -123,13 +99,12 @@ var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
12399
.on(LEAVE_FULLSCREEN, logLeaveFullscreen)
124100
.on(ORIENTATION_CHANGE, logOrientationChange)
125101
.on(RESIZE, logResize);
126-
};
102+
}
127103

128-
DebugGameScalePlugin.prototype.stop = function stop () {
104+
stop () {
129105
this.game.events.off(POST_RENDER, this.render, this);
130106

131-
var ref = this.game.scale;
132-
var parent = ref.parent;
107+
const { parent } = this.game.scale;
133108

134109
if (parent) {
135110
parent.style.outline = '';
@@ -142,25 +117,21 @@ var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
142117
.off(LEAVE_FULLSCREEN, logLeaveFullscreen)
143118
.off(ORIENTATION_CHANGE, logOrientationChange)
144119
.off(RESIZE, logResize);
145-
};
146-
147-
DebugGameScalePlugin.prototype.render = function render () {
148-
var ref = this.game;
149-
var scale = ref.scale;
150-
var devicePixelRatio = window.devicePixelRatio;
151-
var screen = window.screen;
152-
var visualViewport = window.visualViewport;
153-
var ref$1 = this.game.renderer;
154-
var c = ref$1.gameContext;
155-
var cx = 0.5 * scale.width;
156-
var cy = 0.5 * scale.height;
157-
var w = 512;
158-
var h = 128;
159-
var x = ~~Math.max(0, cx - 0.5 * w);
160-
var y = ~~Math.max(0, cy - 0.5 * h);
161-
var dy = 15;
162-
var sx = 1 / scale.displayScale.x;
163-
var sy = 1 / scale.displayScale.y;
120+
}
121+
122+
render () {
123+
const { scale } = this.game;
124+
const { devicePixelRatio, screen, visualViewport } = window;
125+
const { gameContext: c } = this.game.renderer;
126+
const cx = 0.5 * scale.width;
127+
const cy = 0.5 * scale.height;
128+
const w = 512;
129+
const h = 128;
130+
let x = ~~Math.max(0, cx - 0.5 * w);
131+
let y = ~~Math.max(0, cy - 0.5 * h);
132+
const dy = 15;
133+
const sx = 1 / scale.displayScale.x;
134+
const sy = 1 / scale.displayScale.y;
164135

165136
c.strokeStyle = 'white';
166137
c.beginPath();
@@ -178,27 +149,21 @@ var DebugGameScalePlugin = /*@__PURE__*/(function (superclass) {
178149

179150
x += 8;
180151

181-
c.fillText(((scale.width) + "×" + (scale.height) + " @ " + (xyToString(sx, sy, 3)) + " mode=" + (aspectModeToString(scale.scaleMode)) + " zoom=" + (scale.zoom)), x, (y += dy));
182-
c.fillText(("game: " + (sizeToString(scale.gameSize))), x, (y += dy));
183-
c.fillText(("display: " + (sizeToString(scale.displaySize))), x, (y += dy));
184-
c.fillText(("parent: " + (sizeToString(scale.parentSize)) + " " + (scale.parent)), x, (y += dy));
185-
c.fillText(("canvas: " + (rectToString(scale.canvasBounds))), x, (y += dy));
186-
c.fillText(("orientation: " + (scale.orientation)), x, (y += dy));
152+
c.fillText(`${scale.width}×${scale.height} @ ${xyToString(sx, sy, 3)} mode=${aspectModeToString(scale.scaleMode)} zoom=${scale.zoom}`, x, (y += dy));
153+
c.fillText(`game: ${sizeToString(scale.gameSize)}`, x, (y += dy));
154+
c.fillText(`display: ${sizeToString(scale.displaySize)}`, x, (y += dy));
155+
c.fillText(`parent: ${sizeToString(scale.parentSize)} ${scale.parent}`, x, (y += dy));
156+
c.fillText(`canvas: ${rectToString(scale.canvasBounds)}`, x, (y += dy));
157+
c.fillText(`orientation: ${scale.orientation}`, x, (y += dy));
187158
if (screen) {
188-
c.fillText(("screen: " + (screen.width) + "×" + (screen.height) + " [" + ((screen.width / screen.height).toFixed(3)) + "] DPR=" + devicePixelRatio), x, (y += dy));
159+
c.fillText(`screen: ${screen.width}×${screen.height} [${(screen.width / screen.height).toFixed(3)}] DPR=${devicePixelRatio}`, x, (y += dy));
189160
}
190161
if (visualViewport) {
191-
var offsetLeft = visualViewport.offsetLeft;
192-
var offsetTop = visualViewport.offsetTop;
193-
var width = visualViewport.width;
194-
var height = visualViewport.height;
195-
var scale$1 = visualViewport.scale;
162+
const { offsetLeft, offsetTop, width, height, scale } = visualViewport;
196163

197-
c.fillText(("visualViewport: offsetLeft=" + offsetLeft + " offsetTop=" + offsetTop + " width=" + width + ", height=" + height + " scale=" + scale$1), x, (y += dy));
164+
c.fillText(`visualViewport: offsetLeft=${offsetLeft} offsetTop=${offsetTop} width=${width}, height=${height} scale=${scale}`, x, (y += dy));
198165
}
199-
};
200-
201-
return DebugGameScalePlugin;
202-
}(Phaser.Plugins.BasePlugin));
166+
}
167+
}
203168

204-
export default DebugGameScalePlugin;
169+
export { DebugGameScalePlugin as default };

0 commit comments

Comments
 (0)