Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/common/music.js
Show All 18 Lines | |||||
{ | { | ||||
this.reference = this; | this.reference = this; | ||||
this.RELATIVE_MUSIC_PATH = "audio/music/"; | this.RELATIVE_MUSIC_PATH = "audio/music/"; | ||||
this.MUSIC = { | this.MUSIC = { | ||||
"PEACE": "peace", | "PEACE": "peace", | ||||
"BATTLE": "battle", | "BATTLE": "battle", | ||||
"VICTORY": "victory", | "VICTORY": "victory", | ||||
"DEFEAT": "defeat" | "DEFEAT": "defeat", | ||||
"CUSTOM": "custom" | |||||
}; | }; | ||||
this.resetTracks(); | this.resetTracks(); | ||||
this.states = { | this.states = { | ||||
"OFF": 0, | "OFF": 0, | ||||
"MENU": 1, | "MENU": 1, | ||||
"PEACE": 2, | "PEACE": 2, | ||||
"BATTLE": 3, | "BATTLE": 3, | ||||
"VICTORY": 4, | "VICTORY": 4, | ||||
"DEFEAT": 5 | "DEFEAT": 5, | ||||
"CUSTOM": 6 | |||||
}; | }; | ||||
this.musicGain = 0.3; | this.musicGain = 0.3; | ||||
this.locked = false; | |||||
this.currentState = 0; | this.currentState = 0; | ||||
this.oldState = 0; | this.oldState = 0; | ||||
// timer for delay between tracks | // timer for delay between tracks | ||||
this.timer = []; | this.timer = []; | ||||
this.time = Date.now(); | this.time = Date.now(); | ||||
} | } | ||||
Music.prototype.resetTracks = function() | Music.prototype.resetTracks = function() | ||||
{ | { | ||||
this.tracks = { | this.tracks = { | ||||
"MENU": ["Honor_Bound.ogg"].concat(shuffleArray([ | "MENU": ["Honor_Bound.ogg"].concat(shuffleArray([ | ||||
"An_old_Warhorse_goes_to_Pasture.ogg", | "An_old_Warhorse_goes_to_Pasture.ogg", | ||||
"Calm_Before_the_Storm.ogg", | "Calm_Before_the_Storm.ogg", | ||||
"Juno_Protect_You.ogg" | "Juno_Protect_You.ogg" | ||||
])), | ])), | ||||
"PEACE": [ | "PEACE": [ | ||||
"Tale_of_Warriors.ogg", | "Tale_of_Warriors.ogg", | ||||
"Tavern_in_the_Mist.ogg", | "Tavern_in_the_Mist.ogg", | ||||
"The_Road_Ahead.ogg" | "The_Road_Ahead.ogg" | ||||
], | ], | ||||
"BATTLE": ["Taiko_1.ogg", "Taiko_2.ogg"], | "BATTLE": ["Taiko_1.ogg", "Taiko_2.ogg"], | ||||
"VICTORY": ["You_are_Victorious!.ogg"], | "VICTORY": ["You_are_Victorious!.ogg"], | ||||
"DEFEAT": ["Dried_Tears.ogg"] | "DEFEAT": ["Dried_Tears.ogg"], | ||||
"CUSTOM": [] | |||||
}; | }; | ||||
}; | }; | ||||
// "reference" refers to this instance of Music (needed if called from the timer) | // "reference" refers to this instance of Music (needed if called from the timer) | ||||
Music.prototype.setState = function(state) | Music.prototype.setState = function(state) | ||||
{ | { | ||||
if (this.locked) | |||||
return; | |||||
this.reference.currentState = state; | this.reference.currentState = state; | ||||
this.updateState(); | this.updateState(); | ||||
}; | }; | ||||
Music.prototype.updateState = function() | Music.prototype.updateState = function() | ||||
{ | { | ||||
if (this.currentState != this.oldState) | if (this.currentState != this.oldState) | ||||
{ | { | ||||
Show All 20 Lines | if (this.currentState != this.oldState) | ||||
case this.states.VICTORY: | case this.states.VICTORY: | ||||
this.startPlayList(shuffleArray(this.tracks.VICTORY), 2.0, true); | this.startPlayList(shuffleArray(this.tracks.VICTORY), 2.0, true); | ||||
break; | break; | ||||
case this.states.DEFEAT: | case this.states.DEFEAT: | ||||
this.startPlayList(shuffleArray(this.tracks.DEFEAT), 2.0, true); | this.startPlayList(shuffleArray(this.tracks.DEFEAT), 2.0, true); | ||||
break; | break; | ||||
case this.states.CUSTOM: | |||||
this.startPlayList(shuffleArray(this.tracks.CUSTOM), 2.0, true); | |||||
break; | |||||
default: | default: | ||||
warn(sprintf("%(functionName)s: Unknown music state: %(state)s", { "functionName": "Music.updateState()", "state": this.currentState })); | warn(sprintf("%(functionName)s: Unknown music state: %(state)s", { "functionName": "Music.updateState()", "state": this.currentState })); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
Music.prototype.storeTracks = function(civMusic) | Music.prototype.storeTracks = function(civMusic) | ||||
Show All 38 Lines | Music.prototype.start = function() | ||||
Engine.StartMusic(); | Engine.StartMusic(); | ||||
this.setState(this.states.PEACE); | this.setState(this.states.PEACE); | ||||
}; | }; | ||||
Music.prototype.stop = function() | Music.prototype.stop = function() | ||||
{ | { | ||||
this.setState(this.states.OFF); | this.setState(this.states.OFF); | ||||
}; | }; | ||||
/** | |||||
* Play the custom playlist when locked, otherwise plays the civ music according to the battle state. | |||||
*/ | |||||
Music.prototype.setLocked = function(locked) | |||||
{ | |||||
this.locked = locked; | |||||
}; |
Wildfire Games · Phabricator