forked from google/santa-tracker-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene_tutorial.js
More file actions
104 lines (91 loc) · 3.01 KB
/
Copy pathscene_tutorial.js
File metadata and controls
104 lines (91 loc) · 3.01 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
/*
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
goog.provide('app.SceneTutorial');
/**
* Manages the display of a tutorial animation for the game.
* @param {Element} el the .tutorial element.
* @constructor
*/
app.SceneTutorial = function(el) {
this.el = el;
this.visible_ = false;
this.scheduleTimeout_ = null;
this.hasBeenShown = false;
this.boundOnClick_ = this.onClick_.bind(this);
this.boundOnBlocklyChange_ = this.onBlocklyChange_.bind(this);
this.boundOnBlocklyClickBlock_ = this.onBlocklyClickBlock_.bind(this);
this.el.addEventListener('click', this.boundOnClick_, false);
document.body.addEventListener('blocklyDragBlock',
this.boundOnBlocklyChange_, false);
document.body.addEventListener('blocklyClickFlyoutBlock',
this.boundOnBlocklyClickBlock_, false);
};
/**
* Dispose of this SceneTutorial.
*/
app.SceneTutorial.prototype.dispose = function() {
this.el.removeEventListener('click', this.boundOnClick_, false);
document.body.removeEventListener('blocklyDragBlock',
this.boundOnBlocklyChange_, false);
document.body.removeEventListener('blocklyClickFlyoutBlock',
this.boundOnBlocklyClickBlock_, false);
};
/**
* Schedules displaying the tutorial. Only happens max once, some time after the
* first time requested.
*/
app.SceneTutorial.prototype.schedule = function(force) {
if (this.hasBeenShown && !force) { return; }
// Blockly does some non-user initiated workspace changes on timeout, so we wait for
// them to finish.
this.scheduleTimeout_ = window.setTimeout(this.toggle.bind(this, true), 4000);
};
/**
* Shows or hides the tutorial.
* @param {boolean} visible is true to show the tutorial, otherwise false.
*/
app.SceneTutorial.prototype.toggle = function(visible) {
if (this.scheduleTimeout_) {
window.clearTimeout(this.scheduleTimeout_);
this.scheduleTimeout_ = null;
}
this.hasBeenShown = this.hasBeenShown || visible;
this.visible_ = visible;
this.el.style.display = visible ? 'block' : 'none';
};
/**
* Hide the tutorial on tap/click.
* @private
*/
app.SceneTutorial.prototype.onClick_ = function() {
this.toggle(false);
};
/**
* Hide the tutorial on edit blockly workspace.
* @private
*/
app.SceneTutorial.prototype.onBlocklyChange_ = function() {
if (this.visible_ || this.scheduleTimeout_) {
this.toggle(false);
}
};
/**
* Show the tutorial on click toolbar block.
* @private
*/
app.SceneTutorial.prototype.onBlocklyClickBlock_ = function() {
this.toggle(true);
};