- Sound System: converted tap/untap sound playback to an event, preliminary support for synced sounds using the event model.

This commit is contained in:
Agetian
2012-11-23 14:43:47 +00:00
parent 60908da462
commit 55f1693fb6
5 changed files with 85 additions and 41 deletions

1
.gitattributes vendored
View File

@@ -12952,6 +12952,7 @@ src/main/java/forge/game/event/Event.java -text
src/main/java/forge/game/event/LandPlayedEvent.java -text src/main/java/forge/game/event/LandPlayedEvent.java -text
src/main/java/forge/game/event/PoisonCounterEvent.java -text src/main/java/forge/game/event/PoisonCounterEvent.java -text
src/main/java/forge/game/event/RemoveCounterEvent.java -text src/main/java/forge/game/event/RemoveCounterEvent.java -text
src/main/java/forge/game/event/SetTappedEvent.java -text
src/main/java/forge/game/event/SpellResolvedEvent.java -text src/main/java/forge/game/event/SpellResolvedEvent.java -text
src/main/java/forge/game/event/package-info.java -text src/main/java/forge/game/event/package-info.java -text
src/main/java/forge/game/limited/BoosterDeck.java -text src/main/java/forge/game/limited/BoosterDeck.java -text

View File

@@ -56,6 +56,7 @@ import forge.card.trigger.TriggerType;
import forge.card.trigger.ZCTrigger; import forge.card.trigger.ZCTrigger;
import forge.game.GlobalRuleChange; import forge.game.GlobalRuleChange;
import forge.game.event.AddCounterEvent; import forge.game.event.AddCounterEvent;
import forge.game.event.SetTappedEvent;
import forge.game.phase.Combat; import forge.game.phase.Combat;
import forge.game.player.ComputerUtil; import forge.game.player.ComputerUtil;
import forge.game.player.Player; import forge.game.player.Player;
@@ -4901,7 +4902,7 @@ public class Card extends GameEntity implements Comparable<Card> {
this.setTapped(true); this.setTapped(true);
// Play the Tap sound // Play the Tap sound
Singletons.getControl().getSoundSystem().play(SoundEffectType.Tap); Singletons.getModel().getGame().getEvents().post(new SetTappedEvent(true));
} }
/** /**
@@ -4917,7 +4918,7 @@ public class Card extends GameEntity implements Comparable<Card> {
Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Untaps, runParams); Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.Untaps, runParams);
// Play the Untap sound // Play the Untap sound
Singletons.getControl().getSoundSystem().play(SoundEffectType.Untap); Singletons.getModel().getGame().getEvents().post(new SetTappedEvent(false));
} }
for (final Command var : this.untapCommandList) { for (final Command var : this.untapCommandList) {

View File

@@ -0,0 +1,17 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package forge.game.event;
/**
*
* @author Agetian
*/
public class SetTappedEvent extends Event {
public final boolean Tapped;
public SetTappedEvent(boolean tapped) {
Tapped = tapped;
}
}

View File

@@ -12,6 +12,7 @@ import forge.game.event.Event;
import forge.game.event.LandPlayedEvent; import forge.game.event.LandPlayedEvent;
import forge.game.event.PoisonCounterEvent; import forge.game.event.PoisonCounterEvent;
import forge.game.event.RemoveCounterEvent; import forge.game.event.RemoveCounterEvent;
import forge.game.event.SetTappedEvent;
import forge.game.event.SpellResolvedEvent; import forge.game.event.SpellResolvedEvent;
/** /**
@@ -49,6 +50,9 @@ public class EventVisualizer {
return null; return null;
} }
} }
if (evt instanceof SetTappedEvent) {
return getSoundEffectForTapState(((SetTappedEvent) evt).Tapped);
}
return fromMap; return fromMap;
} }
@@ -90,10 +94,23 @@ public class EventVisualizer {
return null; return null;
} }
/**
* Plays the sound corresponding to the change of the card's tapped state
* (when a card is tapped or untapped).
*
* @param tapped_state if true, the "tap" sound is played; otherwise, the
* "untap" sound is played
* @return the sound effect type
*/
public static SoundEffectType getSoundEffectForTapState(boolean tapped_state) {
return tapped_state ? SoundEffectType.Tap : SoundEffectType.Untap;
}
/** /**
* Plays the sound corresponding to the land type when the land is played. * Plays the sound corresponding to the land type when the land is played.
* *
* @param land the land card that was played * @param land the land card that was played
* @return the sound effect type
*/ */
public static SoundEffectType getSoundEffectForLand(final Card land) { public static SoundEffectType getSoundEffectForLand(final Card land) {
if (land == null) { if (land == null) {
@@ -136,9 +153,7 @@ public class EventVisualizer {
* Play a specific sound effect based on card's name. * Play a specific sound effect based on card's name.
* *
* @param c the card to play the sound effect for. * @param c the card to play the sound effect for.
* @return true if the special effect was found and played, otherwise * @return the sound effect type
* false (in which case the type-based FX will be played, if
* applicable).
*/ */
private static SoundEffectType getSpecificCardEffect(final Card c) { private static SoundEffectType getSpecificCardEffect(final Card c) {
// Implement sound effects for specific cards here, if necessary. // Implement sound effects for specific cards here, if necessary.

View File

@@ -20,9 +20,12 @@ package forge.sound;
/** /**
* Sounds (enumeration) - all sounds in the game must be declared here. Once * Sounds (enumeration) - all sounds in the game must be declared here. Once
* declared, the sound can be played from anywhere in the code using * loaded, the sound can be played from the code by posting the appropriate
* Sounds.soundName.play(). The sounds are only preloaded once, so there is no * event to the event bus via Singletons.getModel().getGame().getEvents().post.
* memory overhead for playing the sound multiple times. *
* The second parameter specifies whether a sound needs to be synced with other
* similar sounds (when there's a chance of multiple instances of the same sound
* generated in quick succession, so that the slowdown can be avoided) or not.
* *
* Currently, if the file does not exist, it is not a fatal error. No sound is * Currently, if the file does not exist, it is not a fatal error. No sound is
* played in that case, a simple message is generated on the debug console * played in that case, a simple message is generated on the debug console
@@ -33,41 +36,43 @@ package forge.sound;
public enum SoundEffectType { public enum SoundEffectType {
// Sounds must be listed in alphabetic order. // Sounds must be listed in alphabetic order.
AddCounter("add_counter.wav"), AddCounter("add_counter.wav", false),
Artifact("artifact.wav"), Artifact("artifact.wav", false),
ArtifactCreature("artifact_creature.wav"), ArtifactCreature("artifact_creature.wav", false),
BlackLand("black_land.wav"), BlackLand("black_land.wav", false),
BlueLand("blue_land.wav"), BlueLand("blue_land.wav", false),
Creature("creature.wav"), Creature("creature.wav", false),
Damage("damage.wav"), Damage("damage.wav", true),
Destroy("destroy.wav"), Destroy("destroy.wav", true),
Discard("discard.wav"), Discard("discard.wav", false),
Draw("draw.wav"), Draw("draw.wav", false),
Enchantment("enchant.wav"), Enchantment("enchant.wav", false),
EndOfTurn("end_of_turn.wav"), EndOfTurn("end_of_turn.wav", false),
Equip("equip.wav"), Equip("equip.wav", false),
FlipCoin("flip_coin.wav"), FlipCoin("flip_coin.wav", false),
GreenLand("green_land.wav"), GreenLand("green_land.wav", false),
Instant("instant.wav"), Instant("instant.wav", false),
LifeLoss("life_loss.wav"), LifeLoss("life_loss.wav", true),
LoseDuel("lose_duel.wav"), LoseDuel("lose_duel.wav", false),
ManaBurn("mana_burn.wav"), ManaBurn("mana_burn.wav", false),
OtherLand("other_land.wav"), OtherLand("other_land.wav", false),
Planeswalker("planeswalker.wav"), Planeswalker("planeswalker.wav", false),
Poison("poison.wav"), Poison("poison.wav", false),
RedLand("red_land.wav"), RedLand("red_land.wav", false),
Regen("regeneration.wav"), Regen("regeneration.wav", false),
RemoveCounter("remove_counter.wav"), RemoveCounter("remove_counter.wav", false),
Sacrifice("sacrifice.wav"), Sacrifice("sacrifice.wav", false),
Sorcery("sorcery.wav"), Sorcery("sorcery.wav", false),
Shuffle("shuffle.wav"), Shuffle("shuffle.wav", false),
Tap("tap.wav"), Tap("tap.wav", false),
Untap("untap.wav"), Untap("untap.wav", false),
WhiteLand("white_land.wav"), WhiteLand("white_land.wav", false),
WinDuel("win_duel.wav"); WinDuel("win_duel.wav", false);
private final String resourceFileName; private final String resourceFileName;
private final boolean isSynced;
/** /**
* @return the resourceFileName * @return the resourceFileName
*/ */
@@ -77,8 +82,13 @@ public enum SoundEffectType {
/** /**
* @param filename * @param filename
* name of the sound file associated with the entry. * name of the sound file associated with the entry.
* @param isSoundSynced
* determines if only one instance of the sound can be played
* at a time (the sound is synced with the other sounds of the
* same kind).
*/ */
SoundEffectType(final String filename) { SoundEffectType(final String filename, final boolean isSoundSynced) {
resourceFileName = filename; resourceFileName = filename;
isSynced = isSoundSynced;
} }
} }