Merge branch 'custom-sound-fx' into 'master'

Auto-detect custom sound files for cards if they exist

See merge request core-developers/forge!5468
This commit is contained in:
Michael Kamensky
2021-09-29 11:01:14 +00:00

View File

@@ -315,14 +315,18 @@ public class EventVisualizer extends IGameEventVisitor.Base<SoundEffectType> imp
// Implement sound effects for specific cards here, if necessary.
String effect = "";
if (null != c) {
if (c.hasSVar("SoundEffect")) {
effect = c.getSVar("SoundEffect");
} else {
effect = TextUtil.fastReplace(TextUtil.fastReplace(
TextUtil.fastReplace(c.getName(), ",", ""),
" ", "_"), "'", "").toLowerCase() + ".mp3";
}
if (!effect.isEmpty()) {
// Only proceed if the file actually exists
return new File(ForgeConstants.SOUND_DIR, effect).exists();
}
return false;
// Only proceed if the file actually exists
return new File(ForgeConstants.SOUND_DIR, effect).exists();
}
@@ -339,11 +343,24 @@ public class EventVisualizer extends IGameEventVisitor.Base<SoundEffectType> imp
if (evt instanceof GameEventSpellResolved) {
c = ((GameEventSpellResolved) evt).spell.getHostCard();
} else if (evt instanceof GameEventLandPlayed) {
c = ((GameEventLandPlayed) evt).land;
} else if (evt instanceof GameEventZone) {
GameEventZone evZone = (GameEventZone)evt;
if (evZone.zoneType == ZoneType.Battlefield && evZone.mode == EventValueChangeType.Added && evZone.card.isLand()) {
c = evZone.card; // assuming a land is played or otherwise put on the battlefield
}
}
return c != null ? c.getSVar("SoundEffect") : "";
if (c == null) {
return "";
} else {
if (c.hasSVar("SoundEffect")) {
return c.getSVar("SoundEffect");
} else {
return TextUtil.fastReplace(TextUtil.fastReplace(
TextUtil.fastReplace(c.getName(), ",", ""),
" ", "_"), "'", "").toLowerCase() + ".mp3";
}
}
}