-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathScene.js
More file actions
123 lines (107 loc) · 4.13 KB
/
Scene.js
File metadata and controls
123 lines (107 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Famous Industries Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
'use strict';
var Node = require('./Node');
var Dispatch = require('./Dispatch');
var Commands = require('./Commands');
var TransformSystem = require('./TransformSystem');
var SizeSystem = require('./SizeSystem');
/**
* Scene is the bottom of the scene graph. It is its own
* parent and provides the global updater to the scene graph.
*
* @class Scene
* @constructor
* @extends Node
*/
function Scene () {
Node.call(this);
}
Scene.prototype = Object.create(Node.prototype);
Scene.prototype.constructor = Scene;
/**
* Returns the selector that the context was instantiated with
*
* @return {String} dom selector
* @deprecated
*/
Scene.prototype.getSelector = function getSelector () {
console.warn('Scene#getSelector is deprecated, use Scene#getLocation or Scene#getId instead');
return this._id;
};
/**
* Returns the dispatcher of the context. Used to send events
* to the nodes in the scene graph.
*
* @return {Dispatch} the Scene's Dispatch
* @deprecated
*/
Scene.prototype.getDispatch = function getDispatch () {
console.warn('Scene#getDispatch is deprecated, require the dispatch directly');
return Dispatch;
};
/**
* Receives an event. If the event is 'CONTEXT_RESIZE' it sets the size of the scene
* graph to the payload, which must be an array of numbers of at least
* length three representing the pixel size in 3 dimensions.
*
* @param {String} event the name of the event being received
* @param {*} payload the object being sent
*
* @return {undefined} undefined
*/
Scene.prototype.onReceive = function onReceive (event, payload) {
// TODO: In the future the dom element that the context is attached to
// should have a representation as a component. It would be render sized
// and the context would receive its size the same way that any render size
// component receives its size.
if (event === 'CONTEXT_RESIZE') {
if (payload.length < 2)
throw new Error(
'CONTEXT_RESIZE\'s payload needs to be at least a pair' +
' of pixel sizes'
);
this.setSizeMode('absolute', 'absolute', 'absolute');
this.setAbsoluteSize(payload[0],
payload[1],
payload[2] ? payload[2] : 0);
this._updater.message(Commands.WITH).message(this._id).message(Commands.READY);
}
};
Scene.prototype.mount = function mount (path) {
if (this.isMounted())
throw new Error('Scene is already mounted at: ' + this.getLocation());
Dispatch.mount(path, this);
this._updater // message a request for the dom
.message(Commands.NEED_SIZE_FOR) // size of the context so that
.message(path); // the scene graph has a total size
this._id = path;
this._mounted = true;
this._parent = this;
TransformSystem.registerTransformAtPath(path);
SizeSystem.registerSizeAtPath(path);
// the context begins shown (it's already present in the dom)
this.show();
};
module.exports = Scene;