phaser/src/scene/Systems.js

226 lines
5 KiB
JavaScript
Raw Normal View History

2018-01-16 19:49:13 +00:00
var Class = require('../utils/Class');
var Settings = require('./Settings');
2018-01-16 19:49:13 +00:00
var EventEmitter = require('eventemitter3');
var ScenePlugin = require('./ScenePlugin');
2018-01-16 19:49:13 +00:00
// var Data = require('../../data/Data');
// var DataStore = require('../../data/DataStore');
// var PhysicsManager = require('../plugins/PhysicsManager');
var Systems = new Class({
initialize:
function Systems (scene, config)
{
this.scene = scene;
this.game;
this.config = config;
this.settings = Settings.create(config);
// Set by the SceneManager - a reference to the Scene canvas / context
this.canvas;
this.context;
// Global Systems - these are global managers (belonging to Game)
this.anims;
this.cache;
this.registry;
2018-01-11 14:48:43 +00:00
this.sound;
this.textures;
// These are core Scene plugins, needed by lots of the global systems (and each other)
2018-01-16 02:08:22 +00:00
this.add;
this.cameras;
this.displayList;
this.events;
2018-01-16 02:08:22 +00:00
this.make;
this.sceneManager;
this.time;
this.updateList;
},
init: function (game)
{
var scene = this.scene;
this.game = game;
// Global Systems - these are global managers (belonging to Game)
this.anims = game.anims;
this.cache = game.cache;
this.registry = game.registry;
2018-01-11 14:48:43 +00:00
this.sound = game.sound;
this.textures = game.textures;
// These are core Scene plugins, needed by lots of the global systems (and each other)
this.events = new EventEmitter();
2018-01-16 02:08:22 +00:00
game.plugins.install(scene,
[ 'anims', 'cache', 'registry', 'sound', 'textures' ],
[ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make', 'load', 'tweens', 'input' ]
);
// Optional Scene plugins - not referenced by core systems, can be overridden with user code
2018-01-16 19:49:13 +00:00
// this.data = new Data(scene);
// this.dataStore = new DataStore(scene);
// this.physicsManager = new PhysicsManager(scene);
2018-01-16 02:08:22 +00:00
this.events.emit('boot', this);
},
inject: function (plugin)
{
var map = this.settings.map;
if (plugin.mapping && map.hasOwnProperty(plugin.mapping))
{
this.scene[plugin.mapping] = plugin;
}
},
step: function (time, delta)
{
this.events.emit('preupdate', time, delta);
2017-06-30 03:09:19 +00:00
if (!this.settings.active)
{
return;
}
2018-01-16 02:08:22 +00:00
this.events.emit('update', time, delta);
2018-01-16 19:49:13 +00:00
// this.physicsManager.update(time, delta);
this.scene.update.call(this.scene, time, delta);
2017-11-08 17:18:10 +00:00
2018-01-16 02:08:22 +00:00
this.events.emit('postupdate', time, delta);
2018-01-16 19:49:13 +00:00
// this.physicsManager.postUpdate();
},
render: function (interpolation, renderer)
{
if (!this.settings.visible)
{
return;
}
var displayList = this.displayList;
2017-12-15 04:07:32 +00:00
displayList.process();
this.cameras.render(renderer, displayList, interpolation);
},
// Force a sort of the display list on the next render
queueDepthSort: function ()
{
this.displayList.queueDepthSort();
},
// Immediately sorts the display list if the flag is set
depthSort: function ()
{
this.displayList.depthSort();
},
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
pause: function ()
{
// Was paused by the SceneManager
this.settings.active = false;
if (this.scene.pause)
2017-06-30 03:06:53 +00:00
{
this.scene.pause.call(this.scene);
2017-06-30 03:06:53 +00:00
}
},
resume: function ()
{
// Was resumed by the SceneManager
this.settings.active = true;
if (this.scene.resume)
2017-06-30 03:06:53 +00:00
{
this.scene.resume.call(this.scene);
2017-06-30 03:06:53 +00:00
}
},
sleep: function ()
{
// Was sent to sleep by the SceneManager
this.settings.active = false;
this.settings.visible = false;
if (this.scene.sleep)
2017-06-30 03:06:53 +00:00
{
this.scene.sleep.call(this.scene);
2017-06-30 03:06:53 +00:00
}
},
wake: function ()
{
// Was woken up by the SceneManager
this.settings.active = true;
this.settings.visible = true;
if (this.scene.wake)
2017-06-30 03:06:53 +00:00
{
this.scene.wake.call(this.scene);
2017-06-30 03:06:53 +00:00
}
},
start: function (data)
{
// Was started by the SceneManager
2017-06-30 03:06:53 +00:00
this.settings.data = data;
this.settings.active = true;
this.settings.visible = true;
},
shutdown: function ()
{
// Was stopped by the SceneManager
this.settings.active = false;
2017-06-30 03:06:53 +00:00
this.settings.visible = false;
2018-01-16 02:08:22 +00:00
this.events.emit('shutdown', this);
if (this.scene.shutdown)
2017-06-30 03:06:53 +00:00
{
this.scene.shutdown.call(this.scene);
2017-06-30 03:06:53 +00:00
}
},
destroy: function ()
{
2018-01-16 02:08:22 +00:00
this.events.emit('destroy', this);
if (this.scene.destroy)
2017-06-30 03:06:53 +00:00
{
this.scene.destroy.call(this.scene);
2017-06-30 03:06:53 +00:00
}
2017-02-08 00:08:09 +00:00
}
});
module.exports = Systems;