- CheckStyle.

This commit is contained in:
Chris
2012-12-01 22:17:32 +00:00
parent 6ac18eb140
commit f9848822be
8 changed files with 72 additions and 56 deletions

View File

@@ -431,10 +431,10 @@ public class QuestDataIO {
}
GameFormatQuest res = new GameFormatQuest(name, allowedSets, bannedCards);
try {
if ( StringUtils.isNotEmpty(unlocksUsed)) {
if (StringUtils.isNotEmpty(unlocksUsed)) {
setFinalField(GameFormatQuest.class, "unlocksUsed", res, Integer.parseInt(unlocksUsed));
}
setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock);
setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock);
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
@@ -442,7 +442,7 @@ public class QuestDataIO {
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return res;
}
}
@@ -462,7 +462,7 @@ public class QuestDataIO {
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final String value = reader.getValue();
return GameType.smartValueOf(value, GameType.Quest);
return GameType.smartValueOf(value, GameType.Quest);
}
}

View File

@@ -77,14 +77,17 @@ public class ReadPriceList {
private HashMap<String, Integer> readFile(final File file) {
final HashMap<String, Integer> map = new HashMap<String, Integer>();
final Random r = MyRandom.getRandom();
List<String> lines = FileUtil.readFile(file);
for (String line : lines) {
if ( line.trim().length() == 0 ) break;
if (line.startsWith(ReadPriceList.COMMENT))
continue;
if (line.trim().length() == 0) {
break;
}
if (line.startsWith(ReadPriceList.COMMENT)) {
continue;
}
final String[] s = line.split("=");
final String name = s[0].trim();
final String price = s[1].trim();
@@ -120,7 +123,7 @@ public class ReadPriceList {
} catch (final NumberFormatException nfe) {
Log.warn("NumberFormatException: " + nfe.getMessage());
}
}
}
return map;
} // readFile()

View File

@@ -39,22 +39,23 @@ import javax.sound.sampled.UnsupportedAudioFileException;
*
* @author Agetian
*/
public class AudioClip implements IAudioClip{
public class AudioClip implements IAudioClip {
private final Clip clip;
private final int SOUND_SYSTEM_DELAY = 30;
private final static String PathToSound = "res/sound";
public static boolean fileExists(String fileName) {
private static final String PathToSound = "res/sound";
public static boolean fileExists(String fileName) {
File fSound = new File(PathToSound, fileName);
return fSound.exists();
}
public AudioClip(final String filename) {
File fSound = new File(PathToSound, filename);
if ( !fSound.exists() )
if (!fSound.exists()) {
throw new IllegalArgumentException("Sound file " + fSound.toString() + " does not exist, cannot make a clip of it");
}
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(fSound);
AudioFormat format = stream.getFormat();
@@ -74,8 +75,9 @@ public class AudioClip implements IAudioClip{
}
public final void play() {
if (null == clip)
if (null == clip) {
return;
}
clip.setMicrosecondPosition(0);
try {
Thread.sleep(SOUND_SYSTEM_DELAY);
@@ -86,8 +88,9 @@ public class AudioClip implements IAudioClip{
}
public final void loop() {
if (null == clip)
if (null == clip) {
return;
}
clip.setMicrosecondPosition(0);
try {
Thread.sleep(SOUND_SYSTEM_DELAY);
@@ -98,14 +101,16 @@ public class AudioClip implements IAudioClip{
}
public final void stop() {
if (null == clip)
if (null == clip) {
return;
}
clip.stop();
}
public final boolean isDone() {
if (null == clip)
if (null == clip) {
return false;
}
return !clip.isRunning();
}
}

View File

@@ -30,14 +30,14 @@ import forge.game.event.SpellResolvedEvent;
import forge.game.event.TokenCreatedEvent;
/**
* This class is in charge of converting any forge.game.event.Event to a SoundEffectType
* This class is in charge of converting any forge.game.event.Event to a SoundEffectType.
*
*/
public class EventVisualizer {
final static Map<Class<?>, SoundEffectType> matchTable = new HashMap<Class<?>, SoundEffectType>();
public EventVisualizer() {
static final Map<Class<?>, SoundEffectType> matchTable = new HashMap<Class<?>, SoundEffectType>();
public EventVisualizer() {
matchTable.put(CounterAddedEvent.class, SoundEffectType.AddCounter);
matchTable.put(BlockerAssignedEvent.class, SoundEffectType.Block);
matchTable.put(CardDamagedEvent.class, SoundEffectType.Damage);
@@ -55,8 +55,8 @@ public class EventVisualizer {
matchTable.put(ShuffleEvent.class, SoundEffectType.Shuffle);
matchTable.put(TokenCreatedEvent.class, SoundEffectType.Token);
}
public final SoundEffectType getSoundForEvent(Event evt) {
SoundEffectType fromMap = matchTable.get(evt.getClass());
@@ -86,7 +86,7 @@ public class EventVisualizer {
return fromMap;
}
/**
* Plays the sound corresponding to the outcome of the duel.
*
@@ -113,7 +113,9 @@ public class EventVisualizer {
// if there's a specific effect for this particular card, play it and
// we're done.
SoundEffectType specialEffect = getSpecificCardEffect(source);
if( specialEffect != null ) return specialEffect;
if (specialEffect != null) {
return specialEffect;
}
if (source.isCreature() && source.isArtifact()) {
return SoundEffectType.ArtifactCreature;
@@ -145,7 +147,7 @@ public class EventVisualizer {
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.
*
@@ -160,7 +162,9 @@ public class EventVisualizer {
// if there's a specific effect for this particular card, play it and
// we're done.
SoundEffectType specialEffect = getSpecificCardEffect(land);
if( specialEffect != null ) return specialEffect;
if (specialEffect != null) {
return specialEffect;
}
final List<SpellAbility> manaProduced = land.getManaAbility();
@@ -209,6 +213,6 @@ public class EventVisualizer {
public boolean isSyncSound(SoundEffectType effect) {
return effect.getIsSynced();
}
}
}

View File

@@ -1,8 +1,8 @@
package forge.sound;
public interface IAudioClip {
public interface IAudioClip {
public void play();
public boolean isDone();
public void stop();
public void loop();
}
}

View File

@@ -4,15 +4,15 @@ package forge.sound;
public class NoSoundClip implements IAudioClip {
@Override
public void play() {}
public void play() { }
@Override
public boolean isDone() { return false; }
@Override
public void stop() {}
public void stop() { }
@Override
public void loop() {}
}
public void loop() { }
}

View File

@@ -43,11 +43,11 @@ public enum SoundEffectType {
Block("block.wav", false),
BlueLand("blue_land.wav", false),
Creature("creature.wav", false),
Damage("damage.wav", true),
Damage("damage.wav", true),
Destroy("destroy.wav", true),
Discard("discard.wav", false),
Draw("draw.wav", false),
Enchantment("enchant.wav", false),
Enchantment("enchant.wav", false),
EndOfTurn("end_of_turn.wav", false),
Equip("equip.wav", false),
FlipCoin("flip_coin.wav", false),
@@ -71,7 +71,7 @@ public enum SoundEffectType {
WhiteLand("white_land.wav", false),
WinDuel("win_duel.wav", false);
private final String resourceFileName;
private final boolean isSynced;
@@ -82,7 +82,7 @@ public enum SoundEffectType {
return resourceFileName;
}
/**
* @param filename
* @param filename
* name of the sound file associated with the entry.
* @param isSoundSynced
* determines if only one instance of the sound can be played

View File

@@ -15,26 +15,27 @@ import forge.properties.ForgePreferences.FPref;
*/
public class SoundSystem {
private final static IAudioClip emptySound = new NoSoundClip();
private final static Map<SoundEffectType, IAudioClip> loadedClips = new EnumMap<SoundEffectType, IAudioClip>(SoundEffectType.class);
private static final IAudioClip emptySound = new NoSoundClip();
private static final Map<SoundEffectType, IAudioClip> loadedClips = new EnumMap<SoundEffectType, IAudioClip>(SoundEffectType.class);
private final EventVisualizer visualizer = new EventVisualizer();
protected IAudioClip fetchResource(SoundEffectType type) {
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS))
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ENABLE_SOUNDS)) {
return emptySound;
}
IAudioClip clip = loadedClips.get(type);
if ( null == clip ) { // cache miss
if (null == clip) { // cache miss
String resource = type.getResourceFileName();
clip = AudioClip.fileExists(resource) ? new AudioClip(resource) : emptySound;
loadedClips.put(type, clip);
}
return clip;
}
/**
* Play the sound associated with the Sounds enumeration element.
*/
@@ -67,16 +68,19 @@ public class SoundSystem {
public void stop(SoundEffectType type) {
fetchResource(type).stop();
}
@Subscribe
public void receiveEvent(Event evt) {
SoundEffectType effect = visualizer.getSoundForEvent(evt);
if ( null == effect ) return;
if (null == effect) {
return;
}
boolean isSync = visualizer.isSyncSound(effect);
if ( isSync )
if (isSync) {
playSync(effect);
else
} else {
play(effect);
}
}
}