forked from github/game-off-2013
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.js
94 lines (86 loc) · 2.96 KB
/
ui.js
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
"use strict";
define(['keys','utility'], function( keys, utility ) {
var keyEventListeners = {};
function addKeyEventListener(event, callback) {
if( !keyEventListeners[event] ) {
keyEventListeners[event] = [];
}
keyEventListeners[event].push(callback);
}
keys.fireEvent = function(event, isDown) {
if( isDown && keyEventListeners[event] ) {
keyEventListeners[event].forEach( function(callback) {
callback();
});
}
};
function addToolListener( callback ) {
addKeyEventListener("TOOL", callback);
}
function addPlaceNextListener( callback ) {
addKeyEventListener("RIGHT", callback);
}
function addPlacePreviousListener( callback ) {
addKeyEventListener("LEFT", callback);
}
function shake() {
var element = document.getElementById("scene");
var timeoutID = window.setTimeout(shiftScene, utility.random(5));
var times = 30;
function shiftScene() {
element.style.left = utility.random(times)+"px";
element.style.bottom = utility.random(times)+"px";
if( --times >= 0 ){
timeoutID = window.setTimeout(shiftScene, utility.random(5));
}
}
}
function flash( message, color ) {
var element = document.getElementById("message");
element.innerHTML = message;
new TWEEN.Tween( {opacity:0} )
.to( {opacity:1.0}, 750 )
.easing( TWEEN.Easing.Circular.Out )
.onStart( function() {
element.style.background = color.background;
element.style.color = color.foreground;
element.style.display = "block";
})
.onComplete( function() {
element.style.display = "none";
})
.onUpdate( function() {
element.style.opacity = this.opacity;
})
.start();
}
function theEnd( ) {
var element = document.getElementById("message");
element.innerHTML = "completed #disheveledmind";
new TWEEN.Tween( {opacity:0} )
.repeat( Infinity )
.yoyo( true )
.to( {opacity:1.0}, 2000 )
.easing( TWEEN.Easing.Circular.Out )
.onStart( function() {
element.style.background = "#FFFFFF";
element.style.color = "#000000";
element.style.display = "block";
})
.onComplete( function() {
element.style.display = "none";
})
.onUpdate( function() {
element.style.opacity = this.opacity;
})
.start();
}
return {
addToolListener: addToolListener,
addPlaceNextListener: addPlaceNextListener,
addPlacePreviousListener: addPlacePreviousListener,
shake:shake,
flash:flash,
theEnd:theEnd,
};
});