- cleanup ingame music patch. Let's not use this patch until we fix issue 144 maybe?
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-11-29 06:11:02 +00:00
parent ec553ddfb8
commit 5af8d83c03
2 changed files with 44 additions and 41 deletions
+1 -11
View File
@@ -34,17 +34,7 @@ class GameStateDuel: public GameState, public JGuiListener
int OpponentsDeckid; int OpponentsDeckid;
string musictrack; string musictrack;
bool MusicExist(string FileName){ bool MusicExist(string FileName);
string filepath = RESPATH;
filepath = filepath + "/" + resources.musicFile(FileName);
std::ifstream file(filepath.c_str());
if (file) {
file.close();
return true;
}
else
return false;
}
void loadPlayer(int playerId, int decknb = 0, int isAI = 0); void loadPlayer(int playerId, int decknb = 0, int isAI = 0);
void loadPlayerMomir(int playerId, int isAI); void loadPlayerMomir(int playerId, int isAI);
void loadPlayerRandom(int playerId, int isAI, int mode); void loadPlayerRandom(int playerId, int isAI, int mode);
+31 -18
View File
@@ -68,11 +68,7 @@ void GameStateDuel::Start()
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
renderer->EnableVSync(true); renderer->EnableVSync(true);
OpponentsDeckid=0; OpponentsDeckid=0;
//stop menu music
if (GameApp::music){
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
SAFE_DELETE(GameApp::music);
}
#ifdef TESTSUITE #ifdef TESTSUITE
SAFE_DELETE(testSuite); SAFE_DELETE(testSuite);
@@ -251,7 +247,18 @@ void GameStateDuel::End()
} }
//TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that?
bool GameStateDuel::MusicExist(string FileName){
string filepath = RESPATH;
filepath = filepath + "/" + resources.musicFile(FileName);
std::ifstream file(filepath.c_str());
if (file) {
file.close();
return true;
}
else
return false;
}
void GameStateDuel::Update(float dt) void GameStateDuel::Update(float dt)
{ {
@@ -338,7 +345,23 @@ void GameStateDuel::Update(float dt)
} }
break; break;
case DUEL_STATE_PLAY: case DUEL_STATE_PLAY:
if (!game){
GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance();
game->startGame();
if (mParent->gameType == GAME_TYPE_MOMIR){
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
for (int i = 0; i < 2; i++){
game->players[i]->life+=4;
}
}
//stop menu music
if (GameApp::music){
JSoundSystem::GetInstance()->StopMusic(GameApp::music);
SAFE_DELETE(GameApp::music);
}
//start of in game music code //start of in game music code
if (GameApp::HasMusic && options[Options::MUSICVOLUME].number > 0){
musictrack = ""; musictrack = "";
//check opponent id and choose the music track based on it //check opponent id and choose the music track based on it
if(OpponentsDeckid) { if(OpponentsDeckid) {
@@ -356,22 +379,12 @@ void GameStateDuel::Update(float dt)
if(!MusicExist(musictrack)) if(!MusicExist(musictrack))
musictrack = "ai_baka_music.mp3"; musictrack = "ai_baka_music.mp3";
//play the music if (MusicExist(musictrack)){
if (GameApp::HasMusic && !GameApp::music && options[Options::MUSICVOLUME].number > 0 && MusicExist(musictrack)){
GameApp::music = resources.ssLoadMusic(musictrack.c_str()); GameApp::music = resources.ssLoadMusic(musictrack.c_str());
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true); JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
} }
}
//end of music code //end of music code
if (!game){
GameObserver::Init(mPlayers, 2);
game = GameObserver::GetInstance();
game->startGame();
if (mParent->gameType == GAME_TYPE_MOMIR){
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
for (int i = 0; i < 2; i++){
game->players[i]->life+=4;
}
}
} }
// mParent->effect->UpdateSmall(dt); // mParent->effect->UpdateSmall(dt);
game->Update(dt); game->Update(dt);