Working through SM flow

This commit is contained in:
Richard Davey 2018-10-10 10:47:04 +01:00
parent b4dfa49750
commit f32df230d6

View file

@ -153,6 +153,8 @@ var ScaleManager = new Class({
boot: function () boot: function ()
{ {
console.log('SM boot');
// Configure device-dependent compatibility // Configure device-dependent compatibility
var game = this.game; var game = this.game;
@ -228,6 +230,23 @@ var ScaleManager = new Class({
document.addEventListener('MSFullscreenError', this._fullScreenError, false); document.addEventListener('MSFullscreenError', this._fullScreenError, false);
} }
this.setupScale(game.config.width, game.config.height);
// Same as calling setGameSize:
this._gameSize.setTo(0, 0, game.config.width, game.config.height);
game.events.once('ready', this.start, this);
},
// Called once added to the DOM, not before
start: function ()
{
console.log('SM.start', this.width, this.height);
var game = this.game;
var os = game.device.os;
var compat = this.compatibility;
game.events.on('resume', this.gameResumed, this); game.events.on('resume', this.gameResumed, this);
// Initialize core bounds // Initialize core bounds
@ -242,10 +261,6 @@ var ScaleManager = new Class({
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height); this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
console.log(this.offset.x, this.offset.y, this.width, this.height);
this.setGameSize(game.config.width, game.config.height);
// Don't use updateOrientationState so events are not fired // Don't use updateOrientationState so events are not fired
this.screenOrientation = GetScreenOrientation(compat.orientationFallback); this.screenOrientation = GetScreenOrientation(compat.orientationFallback);
@ -258,9 +273,11 @@ var ScaleManager = new Class({
this._pendingScaleMode = null; this._pendingScaleMode = null;
} }
game.events.on('prestep', this.step, this); this.updateLayout();
this.setupScale(game.config.width, game.config.height); this.signalSizeChange();
// game.events.on('prestep', this.step, this);
}, },
setupScale: function (width, height) setupScale: function (width, height)
@ -343,16 +360,16 @@ var ScaleManager = new Class({
this.updateDimensions(newWidth, newHeight, false); this.updateDimensions(newWidth, newHeight, false);
console.log('setupscale', this._parentBounds); console.log('setupScale', this._gameSize);
}, console.log('pn', this.parentNode);
console.log('pw', this.parentIsWindow);
gameResumed: function () console.log('pb', this._parentBounds);
{
this.queueUpdate(true);
}, },
setGameSize: function (width, height) setGameSize: function (width, height)
{ {
console.log('setGameSize', width, height);
this._gameSize.setTo(0, 0, width, height); this._gameSize.setTo(0, 0, width, height);
if (this.currentScaleMode !== CONST.RESIZE) if (this.currentScaleMode !== CONST.RESIZE)
@ -379,6 +396,11 @@ var ScaleManager = new Class({
} }
}, },
gameResumed: function ()
{
this.queueUpdate(true);
},
setResizeCallback: function (callback, context) setResizeCallback: function (callback, context)
{ {
this.onResize = callback; this.onResize = callback;
@ -682,6 +704,8 @@ var ScaleManager = new Class({
getParentBounds: function (bounds, parentNode) getParentBounds: function (bounds, parentNode)
{ {
console.log('getParentBounds');
if (bounds === undefined) { bounds = new Rectangle(); } if (bounds === undefined) { bounds = new Rectangle(); }
if (parentNode === undefined) { parentNode = this.boundingParent; } if (parentNode === undefined) { parentNode = this.boundingParent; }
@ -691,6 +715,7 @@ var ScaleManager = new Class({
if (!parentNode) if (!parentNode)
{ {
bounds.setTo(0, 0, visualBounds.width, visualBounds.height); bounds.setTo(0, 0, visualBounds.width, visualBounds.height);
console.log('b1');
} }
else else
{ {
@ -714,12 +739,16 @@ var ScaleManager = new Class({
windowBounds = (wc.bottom === 'layout') ? layoutBounds : visualBounds; windowBounds = (wc.bottom === 'layout') ? layoutBounds : visualBounds;
bounds.bottom = Math.min(bounds.bottom, windowBounds.height); bounds.bottom = Math.min(bounds.bottom, windowBounds.height);
} }
console.log('b2');
} }
bounds.setTo( bounds.setTo(
Math.round(bounds.x), Math.round(bounds.y), Math.round(bounds.x), Math.round(bounds.y),
Math.round(bounds.width), Math.round(bounds.height)); Math.round(bounds.width), Math.round(bounds.height));
console.log(bounds);
return bounds; return bounds;
}, },