-
Notifications
You must be signed in to change notification settings - Fork 0
/
assetHandler.js
136 lines (122 loc) · 2.7 KB
/
assetHandler.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var IMAGES = [];
var imagesLoaded = 0;
var soundLoaded=0;
var finishedLoading = false;
function imageLoaded()
{
imagesLoaded++;
if(imagesLoaded==imagesToLoad.length)
{
finishedLoading=true;
loadComplete();
}
}
function soundLoaded()
{
soundsLoaded++;
}
function loadImages(names)
{
result = {};
for(var i=0;i<names.length;i++)
{
var image = new Image();
image.i = i;
image.onload = imageLoaded;
image.src = "./imagesContrast/"+names[i]+".png";
image.alt = "image not loaded";
result[names[i]]=image;
}
return result;
}
var Oldersound = false;
// function getInternetExplorerVersion()
// {
// var rv = -1; // Return value assumes failure.
// if (navigator.appName == 'Microsoft Internet Explorer') {
// var ua = navigator.userAgent;
// var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
// if (re.exec(ua) != null)
// rv = parseFloat(RegExp.$1);
// }
// return rv;
// }
// var browserVer = getInternetExplorerVersion();
// if (browserVer > -1 && browserVer < 9) {
// Oldersound=true;
// console.log("using embed for sound");
// }
function loadSounds(names)
{
result = {};
for(var i=0;i<names.length;i++)
{
if(Oldersound)
{
var em = document.createElement("EMBED");
em.src = "./sounds/"+names[i];
em.autostart= false;
em.width=2;
result[names[i]]=em;
}
else
{
var sound = new Audio();
sound.i = i;
sound.onload = soundLoaded;
sound.src = "./sounds/"+names[i];
sound.alt = "sound not loaded";
result[names[i]]=sound;
}
}
return result;
}
function loadSound(name,auto,loop)
{
var result;
if(Oldersound)
{
var em = document.createElement("EMBED");
em.src = "./sounds/"+name;
em.autostart= false;
em.width=2;
result=em;
}
else
{
var sound = new Audio();
sound.i = i;
sound.onload = soundLoaded;
sound.src = "./sounds/"+name;
sound.alt = "sound not loaded";
result=sound;
}
if(auto)result.autoplay = true;
if(loop)
{
if (typeof result.loop == 'boolean')
{
result.loop = true;
}
else
{
result.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
}
}
return result;
}
// var hitsound = new Audio();
// hitsound.src = "./sounds/strike hit2.wav";
function playSound(sound)
{
if(!soundsEnabled)return;
if(sound.currentTime)
{
sound.currentTime=0;
}
sound.play();
}
var loadComplete = function(){};