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