Skip to content

Commit

Permalink
Expose and Use Game_System::IsStopFilename()
Browse files Browse the repository at this point in the history
  • Loading branch information
mateofio committed Sep 4, 2019
1 parent b5b4528 commit ea3aee1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 32 deletions.
53 changes: 24 additions & 29 deletions src/game_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,6 @@ namespace {
FileRequestBinding system_request_id;
std::map<std::string, FileRequestBinding> se_request_ids;

/**
* Determines if the requested file is supposed to Stop BGM/SE play.
* For empty string and (OFF) this is always the case.
* Many RPG Maker translation overtranslated the (OFF) reserved string,
* e.g. (Brak) and (Kein Sound).
* A file is detected as "Stop BGM/SE" when the file is missing in the
* filesystem and the name is wrapped in (), otherwise it is a regular
* file.
*
* @param name File to find
* @param find_func Find function to use (FindSound or FindMusic)
* @param found_name Name of the found file to play
* @return true when the file is supposed to Stop playback.
* false otherwise and file to play is returned as found_name
*/
bool isStopFilename(const std::string& name, std::string (*find_func) (const std::string&), std::string& found_name) {
found_name = "";

if (name.empty() || name == "(OFF)") {
return true;
}

found_name = find_func(name);

return found_name.empty() && (Utils::StartsWith(name, "(") && Utils::EndsWith(name, ")"));
}
}

static RPG::SaveSystem& data = Main_Data::game_data.system;
Expand All @@ -73,6 +47,27 @@ void Game_System::Init() {
data.Setup();
}

bool Game_System::IsStopFilename(const std::string& name, std::string (*find_func) (const std::string&), std::string& found_name) {
found_name = "";

if (name.empty() || name == "(OFF)") {
return true;
}

found_name = find_func(name);

return found_name.empty() && (Utils::StartsWith(name, "(") && Utils::EndsWith(name, ")"));
}


bool Game_System::IsStopMusicFilename(const std::string& name, std::string& found_name) {
return IsStopFilename(name, FileFinder::FindMusic, found_name);
}

bool Game_System::IsStopSoundFilename(const std::string& name, std::string& found_name) {
return IsStopFilename(name, FileFinder::FindSound, found_name);
}

int Game_System::GetSaveCount() {
return data.save_count;
}
Expand Down Expand Up @@ -190,7 +185,7 @@ void Game_System::SePlay(const RPG::Sound& se, bool stop_sounds) {
void Game_System::SePlay(const RPG::Animation &animation) {
std::string path;
for (const auto& anim : animation.timings) {
if (!isStopFilename(anim.se.name, FileFinder::FindSound, path)) {
if (!IsStopSoundFilename(anim.se.name, path)) {
SePlay(anim.se);
return;
}
Expand Down Expand Up @@ -439,7 +434,7 @@ void Game_System::OnBgmReady(FileRequestResult* result) {
bgm_pending = false;

std::string path;
if (isStopFilename(result->file, FileFinder::FindMusic, path)) {
if (IsStopMusicFilename(result->file, path)) {
Audio().BGM_Stop();
return;
} else if (path.empty()) {
Expand Down Expand Up @@ -489,7 +484,7 @@ void Game_System::OnSeReady(FileRequestResult* result, int volume, int tempo, bo
}

std::string path;
if (isStopFilename(result->file, FileFinder::FindSound, path)) {
if (IsStopSoundFilename(result->file, path)) {
if (stop_sounds) {
Audio().SE_Stop();
}
Expand Down
31 changes: 31 additions & 0 deletions src/game_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ namespace Game_System {
void OnBgmReady(FileRequestResult* result);
void OnSeReady(FileRequestResult* result, int volume, int tempo, bool stop_sounds);
void ReloadSystemGraphic();

/**
* Determines if the requested file is supposed to Stop BGM/SE play.
* For empty string and (OFF) this is always the case.
* Many RPG Maker translation overtranslated the (OFF) reserved string,
* e.g. (Brak) and (Kein Sound).
* A file is detected as "Stop BGM/SE" when the file is missing in the
* filesystem and the name is wrapped in (), otherwise it is a regular
* file.
*
* @param name File to find
* @param find_func Find function to use (FindSound or FindMusic)
* @param found_name Name of the found file to play
* @return true when the file is supposed to Stop playback.
* false otherwise and file to play is returned as found_name
*/
bool IsStopFilename(const std::string& name, std::string (*find_func) (const std::string&), std::string& found_name);

bool IsStopMusicFilename(const std::string& name, std::string& found_name);
bool IsStopMusicFilename(const std::string& name);
bool IsStopSoundFilename(const std::string& name, std::string& found_name);
bool IsStopSoundFilename(const std::string& name);
}

inline bool Game_System::HasSystemGraphic() {
Expand All @@ -279,4 +301,13 @@ inline bool Game_System::HasSystem2Graphic() {
return !GetSystem2Name().empty();
}

inline bool Game_System::IsStopMusicFilename(const std::string& name) {
std::string s;
return IsStopMusicFilename(name, s);
}
inline bool Game_System::IsStopSoundFilename(const std::string& name) {
std::string s;
return IsStopSoundFilename(name, s);
}

#endif
4 changes: 1 addition & 3 deletions src/scene_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ void Scene_Map::OnAsyncSuspend(F&& f, AsyncOp aop, bool is_preupdate) {

void Scene_Map::StartInn() {
const RPG::Music& bgm_inn = Game_System::GetSystemBGM(Game_System::BGM_Inn);
if (bgm_inn.name.empty() ||
bgm_inn.name == "(OFF)" ||
bgm_inn.name == "(Brak)") {
if (Game_System::IsStopMusicFilename(bgm_inn.name)) {
FinishInn();
return;
}
Expand Down

0 comments on commit ea3aee1

Please sign in to comment.