Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow triggers to play a sound #10008

Merged
merged 25 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions source/GameAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.

#include "GameAction.h"

#include "Audio.h"
#include "DataNode.h"
#include "DataWriter.h"
#include "Dialog.h"
Expand Down Expand Up @@ -189,6 +190,13 @@ void GameAction::LoadSingle(const DataNode &child)
if(maxDays < minDays)
swap(minDays, maxDays);
events[GameData::Events().Get(child.Token(1))] = make_pair(minDays, maxDays);
} else if (key == "play") {
if (hasValue) {
music = child.Token(1);
playMusic = true;
} else {
child.PrintTrace("Error: play doesn't have a specified file. If you want to stop music, do 'play \"\"'");
}
}
eebop marked this conversation as resolved.
Show resolved Hide resolved
else if(key == "fail" && child.Size() >= 2)
eebop marked this conversation as resolved.
Show resolved Hide resolved
fail.insert(child.Token(1));
Expand Down Expand Up @@ -239,6 +247,8 @@ void GameAction::Save(DataWriter &out) const
out.Write("fail", name);
if(failCaller)
out.Write("fail");
if (playMusic)
out.Write("play", music);
eebop marked this conversation as resolved.
Show resolved Hide resolved
eebop marked this conversation as resolved.
Show resolved Hide resolved

conditions.Save(out);
}
Expand Down Expand Up @@ -364,6 +374,9 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const
}
if(failCaller && caller)
player.FailMission(*caller);

eebop marked this conversation as resolved.
Show resolved Hide resolved
if (playMusic)
Audio::PlayMusic(music);
eebop marked this conversation as resolved.
Show resolved Hide resolved

// Check if applying the conditions changes the player's reputations.
conditions.Apply(player.Conditions());
Expand Down
3 changes: 3 additions & 0 deletions source/GameAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class GameAction {
int64_t paymentMultiplier = 0;
int64_t fine = 0;

bool playMusic = false;
std::string music;
eebop marked this conversation as resolved.
Show resolved Hide resolved

// When this action is performed, the missions with these names fail.
std::set<std::string> fail;
// When this action is performed, the mission that called this action is failed.
Expand Down