This repository has been archived by the owner on Aug 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TAG_audio.js
106 lines (90 loc) · 3.98 KB
/
TAG_audio.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
// Text Island audio playback module
// (c) Sv443 / Sven Fehler 2018 - licensed under MIT license
var muteelem;var mutedstate;var audiovolume;
function playaudio(name, volume) {
if(volume >= max_volume || volume === undefined || volume === null || volume == ""){
volume = 0.2;
}
if(dbg){sendmsg("playing audio " + name + " with volume " + volume, "orange");}
console.log("playing audio " + name + " with volume " + volume);
muteelem = document.getElementById("muteelem");
mutedstate = muteelem.dataset.muted;
if(mutedstate != 1){
switch(name){
case "ambient_0":
document.getElementById("audio0elem").volume=volume;document.getElementById("audio0elem").play();
break;
case "ambient_1":
document.getElementById("audio1elem").volume=volume;document.getElementById("audio1elem").play();
break;
case "ambient_2":
document.getElementById("audio7elem").volume=volume;document.getElementById("audio7elem").play();
break;
case "ambient_3":
document.getElementById("audio8elem").volume=volume;document.getElementById("audio8elem").play();
break;
case "item_knife":
document.getElementById("audio2elem").volume=volume;document.getElementById("audio2elem").play();
break;
case "crafting":
document.getElementById("audio3elem").volume=volume;document.getElementById("audio3elem").play();
break;
case "eating":
document.getElementById("audio4elem").volume=volume;document.getElementById("audio4elem").play();
break;
case "starving":
document.getElementById("audio5elem").volume=volume+0.3;document.getElementById("audio5elem").play(); //stomach rumbling is turned up a bit so it's a bit more noticable
break;
case "tree_falling":
document.getElementById("audio6elem").volume=volume+0.1;document.getElementById("audio6elem").play();
break;
default:break;
}
}
}
function togglemute() {
muteelem = document.getElementById("muteelem");
mutedstate = muteelem.dataset.muted;
if(dbg){sendmsg(mutedstate, "orange");}
if(mutedstate == 0){
muteelem.src="https://raw.githubusercontent.com/Sv443/TextAdventureGame/master/mute_1_128x128.png";
muteelem.dataset.muted=1;
mutedstate = 1;
}
else if (mutedstate == 1){
muteelem.src="https://raw.githubusercontent.com/Sv443/TextAdventureGame/master/mute_0_128x128.png";
muteelem.dataset.muted=0;
mutedstate = 0;
}
mutedstate = parseInt(muteelem.dataset.muted);
if(mutedstate == 0){
sendmsg("You unmuted the game.");
volume = max_volume;
}
else if(mutedstate == 1) {
sendmsg("You muted the game.");
document.title = document.title + " 🔇";
volume = 0;
}
document.getElementById("audio0elem").volume=volume;document.getElementById("audio1elem").volume=volume;document.getElementById("audio2elem").volume=volume;document.getElementById("audio3elem").volume=volume;document.getElementById("audio4elem").volume=volume;document.getElementById("audio5elem").volume=volume;document.getElementById("audio6elem").volume=volume;document.getElementById("audio7elem").volume=volume;document.getElementById("audio8elem").volume=volume;
}
function ambientsounds() {
var delay = Math.floor(Math.random()*120000); //120000
if(delay < 60000){delay+=60000;}
if(dbg){sendmsg("ambient sound interval: " + delay, "orange");}
console.log("ambient sound interval: " + Math.floor(delay/1000));
setInterval(function (){
if(document.getElementById().dataset.nbr >= 4 && document.getElementById().dataset.nbr <= 8){
var anbr = Math.floor(Math.random()*2) + 2;
playaudio("ambient_" + anbr, 1); //play ambient nighttime sound at a random interval between 1 and 2 minutes
}
else {
playaudio("ambient_" + Math.floor(Math.random()*2), 1); //play ambient daytime sound at a random interval between 1 and 2 minutes
}
}, delay);
}
document.addEventListener("DOMContentLoaded", function (){ambientsounds();});
setTimeout(function () {playaudio("ambient_" + Math.floor(Math.random()*2), 1);}, 1500);
console.log("initialized TAG_audio.js");
modulecount += 1;
modules_displayname += ", TAG_audio";