- 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/PoisonCounterEvent.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/package-info.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.game.GlobalRuleChange;
import forge.game.event.AddCounterEvent;
import forge.game.event.SetTappedEvent;
import forge.game.phase.Combat;
import forge.game.player.ComputerUtil;
import forge.game.player.Player;
@@ -4901,7 +4902,7 @@ public class Card extends GameEntity implements Comparable<Card> {
this.setTapped(true);
// 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);
// Play the Untap sound
Singletons.getControl().getSoundSystem().play(SoundEffectType.Untap);
Singletons.getModel().getGame().getEvents().post(new SetTappedEvent(false));
}
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.PoisonCounterEvent;
import forge.game.event.RemoveCounterEvent;
import forge.game.event.SetTappedEvent;
import forge.game.event.SpellResolvedEvent;
/**
@@ -49,6 +50,9 @@ public class EventVisualizer {
return null;
}
}
if (evt instanceof SetTappedEvent) {
return getSoundEffectForTapState(((SetTappedEvent) evt).Tapped);
}
return fromMap;
}
@@ -90,10 +94,23 @@ public class EventVisualizer {
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.
*
* @param land the land card that was played
* @return the sound effect type
*/
public static SoundEffectType getSoundEffectForLand(final Card land) {
if (land == null) {
@@ -136,9 +153,7 @@ public class EventVisualizer {
* Play a specific sound effect based on card's name.
*
* @param c the card to play the sound effect for.
* @return true if the special effect was found and played, otherwise
* false (in which case the type-based FX will be played, if
* applicable).
* @return the sound effect type
*/
private static SoundEffectType getSpecificCardEffect(final Card c) {
// 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
* declared, the sound can be played from anywhere in the code using
* Sounds.soundName.play(). The sounds are only preloaded once, so there is no
* memory overhead for playing the sound multiple times.
* loaded, the sound can be played from the code by posting the appropriate
* event to the event bus via Singletons.getModel().getGame().getEvents().post.
*
* 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
* played in that case, a simple message is generated on the debug console
@@ -33,41 +36,43 @@ package forge.sound;
public enum SoundEffectType {
// Sounds must be listed in alphabetic order.
AddCounter("add_counter.wav"),
Artifact("artifact.wav"),
ArtifactCreature("artifact_creature.wav"),
BlackLand("black_land.wav"),
BlueLand("blue_land.wav"),
Creature("creature.wav"),
Damage("damage.wav"),
Destroy("destroy.wav"),
Discard("discard.wav"),
Draw("draw.wav"),
Enchantment("enchant.wav"),
EndOfTurn("end_of_turn.wav"),
Equip("equip.wav"),
FlipCoin("flip_coin.wav"),
GreenLand("green_land.wav"),
Instant("instant.wav"),
LifeLoss("life_loss.wav"),
LoseDuel("lose_duel.wav"),
ManaBurn("mana_burn.wav"),
OtherLand("other_land.wav"),
Planeswalker("planeswalker.wav"),
Poison("poison.wav"),
RedLand("red_land.wav"),
Regen("regeneration.wav"),
RemoveCounter("remove_counter.wav"),
Sacrifice("sacrifice.wav"),
Sorcery("sorcery.wav"),
Shuffle("shuffle.wav"),
Tap("tap.wav"),
Untap("untap.wav"),
WhiteLand("white_land.wav"),
WinDuel("win_duel.wav");
AddCounter("add_counter.wav", false),
Artifact("artifact.wav", false),
ArtifactCreature("artifact_creature.wav", false),
BlackLand("black_land.wav", false),
BlueLand("blue_land.wav", false),
Creature("creature.wav", false),
Damage("damage.wav", true),
Destroy("destroy.wav", true),
Discard("discard.wav", false),
Draw("draw.wav", false),
Enchantment("enchant.wav", false),
EndOfTurn("end_of_turn.wav", false),
Equip("equip.wav", false),
FlipCoin("flip_coin.wav", false),
GreenLand("green_land.wav", false),
Instant("instant.wav", false),
LifeLoss("life_loss.wav", true),
LoseDuel("lose_duel.wav", false),
ManaBurn("mana_burn.wav", false),
OtherLand("other_land.wav", false),
Planeswalker("planeswalker.wav", false),
Poison("poison.wav", false),
RedLand("red_land.wav", false),
Regen("regeneration.wav", false),
RemoveCounter("remove_counter.wav", false),
Sacrifice("sacrifice.wav", false),
Sorcery("sorcery.wav", false),
Shuffle("shuffle.wav", false),
Tap("tap.wav", false),
Untap("untap.wav", false),
WhiteLand("white_land.wav", false),
WinDuel("win_duel.wav", false);
private final String resourceFileName;
private final boolean isSynced;
/**
* @return the resourceFileName
*/
@@ -77,8 +82,13 @@ public enum SoundEffectType {
/**
* @param filename
* 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;
isSynced = isSoundSynced;
}
}