Skip to content

Commit b2d2547

Browse files
committed
Merge branch 'logging'
2 parents e7a9be8 + d08a2b2 commit b2d2547

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/DebugGameScalePlugin.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { aspectModeToString, rectToString, sizeToString, xyToString } from './util'
1+
import { aspectModeToString, rectToString, sizeToString, xyToString, logEnterFullscreen, logFullscreenFailed, logFullscreenUnsupported, logLeaveFullscreen, logOrientationChange, logResize } from './util'
22

33
const { POST_RENDER } = Phaser.Core.Events
44

5+
const { ENTER_FULLSCREEN, FULLSCREEN_FAILED, FULLSCREEN_UNSUPPORTED, LEAVE_FULLSCREEN, ORIENTATION_CHANGE, RESIZE } = Phaser.Scale.Events
6+
57
export default class DebugGameScalePlugin extends Phaser.Plugins.BasePlugin {
68
init (data) {
79
if (!this.game.renderer.gameCanvas) {
@@ -19,6 +21,14 @@ export default class DebugGameScalePlugin extends Phaser.Plugins.BasePlugin {
1921
if (parent) {
2022
parent.style.outline = 'thick solid rgba(255,0,0,0.5)'
2123
}
24+
25+
this.game.scale
26+
.on(ENTER_FULLSCREEN, logEnterFullscreen)
27+
.on(FULLSCREEN_FAILED, logFullscreenFailed)
28+
.on(FULLSCREEN_UNSUPPORTED, logFullscreenUnsupported)
29+
.on(LEAVE_FULLSCREEN, logLeaveFullscreen)
30+
.on(ORIENTATION_CHANGE, logOrientationChange)
31+
.on(RESIZE, logResize)
2232
}
2333

2434
stop () {
@@ -29,6 +39,14 @@ export default class DebugGameScalePlugin extends Phaser.Plugins.BasePlugin {
2939
if (parent) {
3040
parent.style.outline = ''
3141
}
42+
43+
this.game.scale
44+
.off(ENTER_FULLSCREEN, logEnterFullscreen)
45+
.off(FULLSCREEN_FAILED, logFullscreenFailed)
46+
.off(FULLSCREEN_UNSUPPORTED, logFullscreenUnsupported)
47+
.off(LEAVE_FULLSCREEN, logLeaveFullscreen)
48+
.off(ORIENTATION_CHANGE, logOrientationChange)
49+
.off(RESIZE, logResize)
3250
}
3351

3452
render () {

src/util.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ for (const name in ScaleModes) {
77
aspectModeNames[ScaleModes[name]] = name
88
}
99

10+
const orientationNames = {
11+
[Phaser.Scale.Orientation.LANDSCAPE]: 'landscape',
12+
[Phaser.Scale.Orientation.PORTRAIT]: 'portrait'
13+
}
14+
1015
const getSizeMaxString = function (size) {
1116
return (size.maxWidth < MAX_VALUE || size.maxHeight < MAX_VALUE) ? ` max=${size.maxWidth}×${size.maxHeight}` : ''
1217
}
@@ -40,3 +45,27 @@ export const sizeToString = function (size) {
4045
export const rectToString = function (rect, precision = 1) {
4146
return `x=${rect.x.toFixed(precision)} y=${rect.y.toFixed(precision)} w=${rect.width.toFixed(precision)} h=${rect.height.toFixed(precision)}`
4247
}
48+
49+
export const logEnterFullscreen = function () {
50+
console.info('enter fullscreen')
51+
}
52+
53+
export const logFullscreenFailed = function () {
54+
console.info('fullscreen failed')
55+
}
56+
57+
export const logFullscreenUnsupported = function () {
58+
console.info('fullscreen unsupported')
59+
}
60+
61+
export const logLeaveFullscreen = function () {
62+
console.info('leave fullscreen')
63+
}
64+
65+
export const logOrientationChange = function (orientation) {
66+
console.info('orientation change', orientationNames[orientation])
67+
}
68+
69+
export const logResize = function (game, base, display, prevWidth, prevHeight) {
70+
console.debug('resize', sizeToString(display))
71+
}

0 commit comments

Comments
 (0)