-
Notifications
You must be signed in to change notification settings - Fork 1
/
sound.js
113 lines (103 loc) · 2.77 KB
/
sound.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
/**
* sound.js
*
* functions to play sounds from different elements of the game
*/
/**
* Plays the sound located at soundPath, at the volume "volume".
* The sound loops if loop is true (false by default)
* @param {string} soundPath
* @param {bool} loop
* @param {float} volume
*/
function playSound(SoundPath,loop=false,volume=1.0,audioSound=undefined){
if(SoundPath == ""){
console.log("Sound not defined !");
}
else{
var audio
if(audioSound === undefined){
audio = new Audio(getGameFolderURL() + SoundPath);
}else{
audio = audioSound;
}
audio.loop = loop;
audio.volume = volume;
audio.play();
}
}
/**
* Plays the Ambience sound of the current scene
*/
function playSoundScene(audio=undefined){
let scene = getSceneByID(scene_number);
let SoundPath = scene.Ambience.Path;
let loop = scene.Ambience.Repeat;
let volume = scene.Ambience.Volume;
playSound(SoundPath,loop,volume,audio);
}
/**
* Plays the sound associated to clickZoneId
* @param {Number} clickZoneId
*/
function playSoundClickZone(clickZoneId){
var Scene = getSceneByID(scene_number);
var clickAreas = getClickAreas(Scene);
var clickArea = getClickAreaByID(clickAreas,clickZoneId);
var SoundPath = getSoundPath(clickArea);
playSound(SoundPath);
}
/**
* Plays the sound associated to backClickAreaId
* @param {Number} backClickAreaId
*/
function playSoundBackClickArea(backClickAreaId){
var Scene = getSceneByID(scene_number);
var backClickAreas = getBackClickAreas(Scene);
var backClickArea = getBackClickAreaByID(backClickAreas,backClickAreaId);
var SoundPath = getSoundPath(backClickArea);
playSound(SoundPath);
}
/**
* Plays the sound associated with gifId
* @param {Number} gifId
*/
function playSoundGif(gifId){
var Scene = getSceneByID(scene_number);
var gifs = getGifs(Scene);
var gif = getGifByID(gifs, gifId);
var SoundPath = getSoundPath(gif);
playSound(SoundPath);
}
/**
* Plays the sound associated with objectId
* @param {Number} objectId
*/
function playSoundObject(objectId){
var Scene = getSceneByID(scene_number);
var objects = getObjects(Scene);
var object = getObjectByID(objects, objectId);
var SoundPath = getSoundPath(object);
playSound(SoundPath);
}
/**
* Plays the sound associated to textId
* @param {Number} textId
*/
function playSoundText(textId){
var Scene = getSceneByID(scene_number);
var texts = getTexts(Scene);
var text = getTextByID(texts, textId);
var SoundPath = getSoundPath(text);
playSound(SoundPath);
}
/**
* Plays the sound associated to transitionId
* @param {Number} transitionId
*/
function playSoundTransition(transitionId){
var transitions = getTransitions();
var transition = getTransitionByID(transitions, transitionId);
var SoundPath = getSoundPath(transition);
playSound(SoundPath);
}