UNPKG

1.49 kBJavaScriptView Raw
1"use strict";
2
3/**
4 * Provides a way to switch between {@link Splat.Scene}s. An instance of SceneManager is available as {@link Splat.Game#scenes}.
5 * @constructor
6 */
7function SceneManager() {
8 /**
9 * A key-value list of all the named scenes.
10 * @member {object}
11 * @private
12 */
13 this.scenes = {};
14}
15/**
16 * Begin tracking a {@link Splat.Scene}.
17 * @param {string} name The name of the {@link Splat.Scene} to be used later when you call {@link SceneManager#switchTo}.
18 * @param {Splat.Scene} scene The Scene to track.
19 */
20SceneManager.prototype.add = function(name, scene) {
21 this.scenes[name] = scene;
22};
23/**
24 * Fetch a {@link Splat.Scene} that was previously stored with {@link SceneManager#add}.
25 * @param {string} name The name that was provided when the {@link Splat.Scene} was stored during {@link SceneManager#add}.
26 * @returns {Splat.Scene}
27 */
28SceneManager.prototype.get = function(name) {
29 return this.scenes[name];
30};
31/**
32 * Stop running the current {@link Splat.Scene}, and start running the named Scene.
33 * @param {string} name The name that was providded when the {@link Splat.Scene} was stored during {@link SceneManager#add}.
34 */
35SceneManager.prototype.switchTo = function(name) {
36 if (this.currentScene === this.scenes[name]) {
37 this.currentScene.reset();
38 return;
39 }
40 if (this.currentScene !== undefined) {
41 this.currentScene.stop();
42 }
43 this.currentScene = this.scenes[name];
44 this.currentScene.reset();
45 this.currentScene.start();
46};
47
48module.exports = SceneManager;