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. // Implement sound effects for specific cards here, if necessary.
String effect = ""; String effect = "";
if (null != c) { if (null != c) {
effect = c.getSVar("SoundEffect"); if (c.hasSVar("SoundEffect")) {
} effect = c.getSVar("SoundEffect");
if (!effect.isEmpty()) { } else {
// Only proceed if the file actually exists effect = TextUtil.fastReplace(TextUtil.fastReplace(
return new File(ForgeConstants.SOUND_DIR, effect).exists(); TextUtil.fastReplace(c.getName(), ",", ""),
" ", "_"), "'", "").toLowerCase() + ".mp3";
}
} }
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) { if (evt instanceof GameEventSpellResolved) {
c = ((GameEventSpellResolved) evt).spell.getHostCard(); c = ((GameEventSpellResolved) evt).spell.getHostCard();
} else if (evt instanceof GameEventLandPlayed) { } else if (evt instanceof GameEventZone) {
c = ((GameEventLandPlayed) evt).land; 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";
}
}
} }