phaser/v3/src/state/Settings.js

77 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-01-20 02:28:55 +00:00
var CONST = require('./const');
2017-01-18 14:48:02 +00:00
var ScaleModes = require('../renderer/ScaleModes');
2017-02-04 05:39:37 +00:00
var GetObjectValue = require('../utils/object/GetObjectValue');
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
var Settings = {
create: function (config)
2016-11-29 13:01:16 +00:00
{
2017-02-06 23:59:15 +00:00
if (typeof config === 'string')
{
config = { key: config };
}
else if (config === undefined)
{
// Pass the 'hasOwnProperty' checks
config = {};
}
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
return {
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
status: CONST.PENDING,
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
op: CONST.BOOT,
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
key: GetObjectValue(config, 'key', ''),
active: GetObjectValue(config, 'active', false),
visible: GetObjectValue(config, 'visible', true),
// Loader payload array
2017-02-17 02:07:56 +00:00
data: {},
files: GetObjectValue(config, 'files', false),
2016-11-29 13:01:16 +00:00
2017-02-06 23:59:15 +00:00
// -1 means the State Manager will set it to be the Game dimensions
2017-02-06 23:59:15 +00:00
x: GetObjectValue(config, 'x', 0),
y: GetObjectValue(config, 'y', 0),
rotation: GetObjectValue(config, 'rotation', 0),
2017-02-06 23:59:15 +00:00
width: GetObjectValue(config, 'width', -1),
height: GetObjectValue(config, 'height', -1),
2017-01-20 02:28:55 +00:00
// State Render Settings (applies only to this State)
2017-01-20 02:28:55 +00:00
scaleMode: GetObjectValue(config, 'scaleMode', ScaleModes.DEFAULT),
2017-02-06 23:59:15 +00:00
roundPixels: GetObjectValue(config, 'roundPixels', false),
dirtyRender: GetObjectValue(config, 'dirtyRender', false),
renderToTexture: GetObjectValue(config, 'renderToTexture', false),
// The following only apply if renderToTexture is true
autoResize: GetObjectValue(config, 'autoResize', false),
transparent: GetObjectValue(config, 'transparent', false),
clearBeforeRender: GetObjectValue(config, 'clearBeforeRender', true),
backgroundColor: GetObjectValue(config, 'backgroundColor', false)
2017-02-06 23:59:15 +00:00
};
},
init: function (config, gameConfig)
{
if (config.width === -1)
{
config.width = gameConfig.width;
}
if (config.height === -1)
{
config.height = gameConfig.height;
}
}
2017-01-20 02:28:55 +00:00
2016-11-29 13:01:16 +00:00
};
module.exports = Settings;