Add ambience
This commit is contained in:
parent
4e5444f97d
commit
5337b544a9
@ -325,6 +325,7 @@ Parser.prototype.playSound = function() {
|
||||
Parser.prototype.playAmbience = function() {
|
||||
var name = this.consumeMusicName();
|
||||
var fade = this.matchFade();
|
||||
ViewActivity.getInstance().ambience(name, fade);
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -357,7 +358,7 @@ Parser.prototype.stop = function() {
|
||||
}
|
||||
if (this.match(TokenType.AMBIENCE)) {
|
||||
var fade = this.matchFade();
|
||||
// ViewActivity.getInstance().stopAmbience(fade);
|
||||
ViewActivity.getInstance().stopAmbience(fade);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
@ -68,7 +68,17 @@ var PathResolver = new function () {
|
||||
this.music = function (name) {
|
||||
return baseResDir + "music/" + name + ".ogg";
|
||||
};
|
||||
this.ambience = function (name) {
|
||||
var path = baseResDir + "ambience/";
|
||||
if (name.startsWith("ambience_")) path += name.substring(9);
|
||||
else path += name;
|
||||
path += ".ogg";
|
||||
return path;
|
||||
};
|
||||
this.sound = function (name) {
|
||||
if (name.startsWith("ambience_")) {
|
||||
return this.ambience(name);
|
||||
}
|
||||
var path = baseResDir + "sfx/";
|
||||
if (name.startsWith("sfx_")) path += name.substring(4);
|
||||
else path += name;
|
||||
|
@ -10,6 +10,7 @@ function Views(parser) {
|
||||
|
||||
this.musicPlayerAudio = new Audio();
|
||||
this.soundPlayerAudio = new Audio();
|
||||
this.ambiencePlayerAudio = new Audio();
|
||||
this.musicQueue = new Array();
|
||||
this.soundQueue = new Array();
|
||||
|
||||
@ -444,3 +445,35 @@ Views.prototype.stopSound = function (fade) {
|
||||
this.soundPlayerAudio.pause();
|
||||
}
|
||||
};
|
||||
|
||||
Views.prototype.ambience = function (name, fade) {
|
||||
try {
|
||||
this.stopAmbience(this.ambiencePlayerAudio.fade);
|
||||
this.ambiencePlayerAudio.src = PathResolver.ambience(name);
|
||||
this.ambiencePlayerAudio.fade = fade;
|
||||
var views = this;
|
||||
this.ambiencePlayerAudio.addEventListener('ended', function () {
|
||||
this.currentTime = 0;
|
||||
this.play();
|
||||
});
|
||||
this.ambiencePlayerAudio.play();
|
||||
if (fade.fadeIn) {
|
||||
$(this.ambiencePlayerAudio).prop("volume", 0.0);
|
||||
$(this.ambiencePlayerAudio).animate({volume: 1.0}, fade.duration * 1000);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("ambience: " + name + " " + e);
|
||||
}
|
||||
};
|
||||
|
||||
Views.prototype.stopAmbience = function (fade) {
|
||||
if (this.ambiencePlayerAudio.paused) return;
|
||||
|
||||
if (fade.fadeOut) {
|
||||
$(this.ambiencePlayerAudio).animate({volume: 0.0}, fade.duration * 1000, function() {
|
||||
this.pause();
|
||||
});
|
||||
} else {
|
||||
this.ambiencePlayerAudio.pause();
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user