-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathengine.js
119 lines (108 loc) · 3.09 KB
/
engine.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
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
/*jslint browser: true, devel: true, nomen: true, sloppy: true, indent: 2 */
function GraphicsElement(domElementName, classname, visible, state) {
this._name = domElementName;
this._image = document.getElementById(domElementName);
this._visible = visible;
this._state = state;
this._classname = classname || "";
this.updateClassName();
}
GraphicsElement.prototype.setContent = function (content) {
if (this._image) {
this._image.innerHTML = content;
}
};
GraphicsElement.prototype.setVisible = function (visible) {
this._visible = visible;
this.updateClassName();
};
GraphicsElement.prototype.isVisible = function () {
return this._visible;
};
GraphicsElement.prototype.setState = function (state) {
this._state = state;
this.updateClassName();
};
GraphicsElement.prototype.getState = function () {
return this._state;
};
GraphicsElement.prototype.updateClassName = function () {
if (this._image) {
this._image.className = "image " + (this._state || "") + " " + this._classname + " " + (this._visible ? "visible" : "hidden");
}
};
function animateElement(graphicsElement, states) {
if (graphicsElement && states[0]) {
if (states[0].func !== undefined) {
states[0].func();
}
if (states[0].state !== undefined) {
graphicsElement.setState(states[0].state);
}
if (states[0].visible !== undefined) {
graphicsElement.setVisible(states[0].visible);
}
if (states[0].time !== undefined) {
setTimeout(
function () {
animateElement(graphicsElement, states.slice(1));
},
states[0].time
);
}
}
}
var infoscreenheader,
infoscreencontent,
alertsplash,
infoscreen,
infoscreenbuttonfunction;
function displayInfoscreen(header, content, callback) {
if (!infoscreen || !infoscreenheader || !infoscreencontent) {
infoscreen = new GraphicsElement("infoscreen");
infoscreencontent = document.getElementById("infoscreencontent");
infoscreenheader = document.getElementById("infoscreenheader");
}
if (callback) {
infoscreenbuttonfunction = function () {
infoscreenbuttonfunction = false;
infoscreen.setState("hide");
setTimeout(callback, 200);
setTimeout(function () {
infoscreen.setState("");
}, 1000);
};
document.getElementById("infoscreenbutton").onclick = infoscreenbuttonfunction;
}
document.getElementById("infoscreenbutton").className = (callback ? "visible" : "hidden");
infoscreenheader.innerHTML = header;
infoscreencontent.className = header ? "" : "noheader";
infoscreencontent.innerHTML = content.join("<br><br>");
infoscreen.setVisible(true);
infoscreen.setState("display");
}
function alertSplash(flashes) {
if (!alertsplash) {
alertsplash = new GraphicsElement("alertsplash", "", true);
}
animateElement(
alertsplash,
[{
state: "intro",
time: 0.2 * 1000
}, {
state: "outro",
time: 0.2 * 1000
}]
);
setTimeout(
function () {
if (flashes > 1) {
alertSplash(flashes - 1);
} else {
alertsplash.setState("hidden");
}
},
0.4 * 1000
);
}