mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
- CheckStyle.
This commit is contained in:
@@ -431,10 +431,10 @@ public class QuestDataIO {
|
|||||||
}
|
}
|
||||||
GameFormatQuest res = new GameFormatQuest(name, allowedSets, bannedCards);
|
GameFormatQuest res = new GameFormatQuest(name, allowedSets, bannedCards);
|
||||||
try {
|
try {
|
||||||
if ( StringUtils.isNotEmpty(unlocksUsed)) {
|
if (StringUtils.isNotEmpty(unlocksUsed)) {
|
||||||
setFinalField(GameFormatQuest.class, "unlocksUsed", res, Integer.parseInt(unlocksUsed));
|
setFinalField(GameFormatQuest.class, "unlocksUsed", res, Integer.parseInt(unlocksUsed));
|
||||||
}
|
}
|
||||||
setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock);
|
setFinalField(GameFormatQuest.class, "allowUnlocks", res, canUnlock);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
@@ -442,7 +442,7 @@ public class QuestDataIO {
|
|||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,7 +462,7 @@ public class QuestDataIO {
|
|||||||
@Override
|
@Override
|
||||||
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
|
||||||
final String value = reader.getValue();
|
final String value = reader.getValue();
|
||||||
return GameType.smartValueOf(value, GameType.Quest);
|
return GameType.smartValueOf(value, GameType.Quest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,14 +77,17 @@ public class ReadPriceList {
|
|||||||
private HashMap<String, Integer> readFile(final File file) {
|
private HashMap<String, Integer> readFile(final File file) {
|
||||||
final HashMap<String, Integer> map = new HashMap<String, Integer>();
|
final HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||||
final Random r = MyRandom.getRandom();
|
final Random r = MyRandom.getRandom();
|
||||||
|
|
||||||
List<String> lines = FileUtil.readFile(file);
|
List<String> lines = FileUtil.readFile(file);
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
if ( line.trim().length() == 0 ) break;
|
if (line.trim().length() == 0) {
|
||||||
|
break;
|
||||||
if (line.startsWith(ReadPriceList.COMMENT))
|
}
|
||||||
continue;
|
|
||||||
|
if (line.startsWith(ReadPriceList.COMMENT)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
final String[] s = line.split("=");
|
final String[] s = line.split("=");
|
||||||
final String name = s[0].trim();
|
final String name = s[0].trim();
|
||||||
final String price = s[1].trim();
|
final String price = s[1].trim();
|
||||||
@@ -120,7 +123,7 @@ public class ReadPriceList {
|
|||||||
} catch (final NumberFormatException nfe) {
|
} catch (final NumberFormatException nfe) {
|
||||||
Log.warn("NumberFormatException: " + nfe.getMessage());
|
Log.warn("NumberFormatException: " + nfe.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
} // readFile()
|
} // readFile()
|
||||||
|
|
||||||
|
|||||||
@@ -39,22 +39,23 @@ import javax.sound.sampled.UnsupportedAudioFileException;
|
|||||||
*
|
*
|
||||||
* @author Agetian
|
* @author Agetian
|
||||||
*/
|
*/
|
||||||
public class AudioClip implements IAudioClip{
|
public class AudioClip implements IAudioClip {
|
||||||
private final Clip clip;
|
private final Clip clip;
|
||||||
private final int SOUND_SYSTEM_DELAY = 30;
|
private final int SOUND_SYSTEM_DELAY = 30;
|
||||||
|
|
||||||
private final static String PathToSound = "res/sound";
|
private static final String PathToSound = "res/sound";
|
||||||
|
|
||||||
public static boolean fileExists(String fileName) {
|
public static boolean fileExists(String fileName) {
|
||||||
File fSound = new File(PathToSound, fileName);
|
File fSound = new File(PathToSound, fileName);
|
||||||
return fSound.exists();
|
return fSound.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AudioClip(final String filename) {
|
public AudioClip(final String filename) {
|
||||||
File fSound = new File(PathToSound, 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");
|
throw new IllegalArgumentException("Sound file " + fSound.toString() + " does not exist, cannot make a clip of it");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AudioInputStream stream = AudioSystem.getAudioInputStream(fSound);
|
AudioInputStream stream = AudioSystem.getAudioInputStream(fSound);
|
||||||
AudioFormat format = stream.getFormat();
|
AudioFormat format = stream.getFormat();
|
||||||
@@ -74,8 +75,9 @@ public class AudioClip implements IAudioClip{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void play() {
|
public final void play() {
|
||||||
if (null == clip)
|
if (null == clip) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
clip.setMicrosecondPosition(0);
|
clip.setMicrosecondPosition(0);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(SOUND_SYSTEM_DELAY);
|
Thread.sleep(SOUND_SYSTEM_DELAY);
|
||||||
@@ -86,8 +88,9 @@ public class AudioClip implements IAudioClip{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void loop() {
|
public final void loop() {
|
||||||
if (null == clip)
|
if (null == clip) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
clip.setMicrosecondPosition(0);
|
clip.setMicrosecondPosition(0);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(SOUND_SYSTEM_DELAY);
|
Thread.sleep(SOUND_SYSTEM_DELAY);
|
||||||
@@ -98,14 +101,16 @@ public class AudioClip implements IAudioClip{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void stop() {
|
public final void stop() {
|
||||||
if (null == clip)
|
if (null == clip) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
clip.stop();
|
clip.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isDone() {
|
public final boolean isDone() {
|
||||||
if (null == clip)
|
if (null == clip) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return !clip.isRunning();
|
return !clip.isRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ import forge.game.event.SpellResolvedEvent;
|
|||||||
import forge.game.event.TokenCreatedEvent;
|
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 {
|
public class EventVisualizer {
|
||||||
|
|
||||||
final static Map<Class<?>, SoundEffectType> matchTable = new HashMap<Class<?>, SoundEffectType>();
|
static final Map<Class<?>, SoundEffectType> matchTable = new HashMap<Class<?>, SoundEffectType>();
|
||||||
|
|
||||||
public EventVisualizer() {
|
public EventVisualizer() {
|
||||||
matchTable.put(CounterAddedEvent.class, SoundEffectType.AddCounter);
|
matchTable.put(CounterAddedEvent.class, SoundEffectType.AddCounter);
|
||||||
matchTable.put(BlockerAssignedEvent.class, SoundEffectType.Block);
|
matchTable.put(BlockerAssignedEvent.class, SoundEffectType.Block);
|
||||||
matchTable.put(CardDamagedEvent.class, SoundEffectType.Damage);
|
matchTable.put(CardDamagedEvent.class, SoundEffectType.Damage);
|
||||||
@@ -55,8 +55,8 @@ public class EventVisualizer {
|
|||||||
matchTable.put(ShuffleEvent.class, SoundEffectType.Shuffle);
|
matchTable.put(ShuffleEvent.class, SoundEffectType.Shuffle);
|
||||||
matchTable.put(TokenCreatedEvent.class, SoundEffectType.Token);
|
matchTable.put(TokenCreatedEvent.class, SoundEffectType.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final SoundEffectType getSoundForEvent(Event evt) {
|
public final SoundEffectType getSoundForEvent(Event evt) {
|
||||||
SoundEffectType fromMap = matchTable.get(evt.getClass());
|
SoundEffectType fromMap = matchTable.get(evt.getClass());
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class EventVisualizer {
|
|||||||
|
|
||||||
return fromMap;
|
return fromMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the sound corresponding to the outcome of the duel.
|
* 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
|
// if there's a specific effect for this particular card, play it and
|
||||||
// we're done.
|
// we're done.
|
||||||
SoundEffectType specialEffect = getSpecificCardEffect(source);
|
SoundEffectType specialEffect = getSpecificCardEffect(source);
|
||||||
if( specialEffect != null ) return specialEffect;
|
if (specialEffect != null) {
|
||||||
|
return specialEffect;
|
||||||
|
}
|
||||||
|
|
||||||
if (source.isCreature() && source.isArtifact()) {
|
if (source.isCreature() && source.isArtifact()) {
|
||||||
return SoundEffectType.ArtifactCreature;
|
return SoundEffectType.ArtifactCreature;
|
||||||
@@ -145,7 +147,7 @@ public class EventVisualizer {
|
|||||||
public static SoundEffectType getSoundEffectForTapState(boolean tapped_state) {
|
public static SoundEffectType getSoundEffectForTapState(boolean tapped_state) {
|
||||||
return tapped_state ? SoundEffectType.Tap : SoundEffectType.Untap;
|
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.
|
||||||
*
|
*
|
||||||
@@ -160,7 +162,9 @@ public class EventVisualizer {
|
|||||||
// if there's a specific effect for this particular card, play it and
|
// if there's a specific effect for this particular card, play it and
|
||||||
// we're done.
|
// we're done.
|
||||||
SoundEffectType specialEffect = getSpecificCardEffect(land);
|
SoundEffectType specialEffect = getSpecificCardEffect(land);
|
||||||
if( specialEffect != null ) return specialEffect;
|
if (specialEffect != null) {
|
||||||
|
return specialEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final List<SpellAbility> manaProduced = land.getManaAbility();
|
final List<SpellAbility> manaProduced = land.getManaAbility();
|
||||||
@@ -209,6 +213,6 @@ public class EventVisualizer {
|
|||||||
public boolean isSyncSound(SoundEffectType effect) {
|
public boolean isSyncSound(SoundEffectType effect) {
|
||||||
|
|
||||||
return effect.getIsSynced();
|
return effect.getIsSynced();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package forge.sound;
|
package forge.sound;
|
||||||
|
|
||||||
public interface IAudioClip {
|
public interface IAudioClip {
|
||||||
public void play();
|
public void play();
|
||||||
public boolean isDone();
|
public boolean isDone();
|
||||||
public void stop();
|
public void stop();
|
||||||
public void loop();
|
public void loop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ package forge.sound;
|
|||||||
public class NoSoundClip implements IAudioClip {
|
public class NoSoundClip implements IAudioClip {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void play() {}
|
public void play() { }
|
||||||
@Override
|
@Override
|
||||||
public boolean isDone() { return false; }
|
public boolean isDone() { return false; }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {}
|
public void stop() { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loop() {}
|
public void loop() { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ public enum SoundEffectType {
|
|||||||
Block("block.wav", false),
|
Block("block.wav", false),
|
||||||
BlueLand("blue_land.wav", false),
|
BlueLand("blue_land.wav", false),
|
||||||
Creature("creature.wav", false),
|
Creature("creature.wav", false),
|
||||||
Damage("damage.wav", true),
|
Damage("damage.wav", true),
|
||||||
Destroy("destroy.wav", true),
|
Destroy("destroy.wav", true),
|
||||||
Discard("discard.wav", false),
|
Discard("discard.wav", false),
|
||||||
Draw("draw.wav", false),
|
Draw("draw.wav", false),
|
||||||
Enchantment("enchant.wav", false),
|
Enchantment("enchant.wav", false),
|
||||||
EndOfTurn("end_of_turn.wav", false),
|
EndOfTurn("end_of_turn.wav", false),
|
||||||
Equip("equip.wav", false),
|
Equip("equip.wav", false),
|
||||||
FlipCoin("flip_coin.wav", false),
|
FlipCoin("flip_coin.wav", false),
|
||||||
@@ -71,7 +71,7 @@ public enum SoundEffectType {
|
|||||||
WhiteLand("white_land.wav", false),
|
WhiteLand("white_land.wav", false),
|
||||||
WinDuel("win_duel.wav", false);
|
WinDuel("win_duel.wav", false);
|
||||||
|
|
||||||
|
|
||||||
private final String resourceFileName;
|
private final String resourceFileName;
|
||||||
private final boolean isSynced;
|
private final boolean isSynced;
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public enum SoundEffectType {
|
|||||||
return resourceFileName;
|
return resourceFileName;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param filename
|
* @param filename
|
||||||
* name of the sound file associated with the entry.
|
* name of the sound file associated with the entry.
|
||||||
* @param isSoundSynced
|
* @param isSoundSynced
|
||||||
* determines if only one instance of the sound can be played
|
* determines if only one instance of the sound can be played
|
||||||
|
|||||||
@@ -15,26 +15,27 @@ import forge.properties.ForgePreferences.FPref;
|
|||||||
*/
|
*/
|
||||||
public class SoundSystem {
|
public class SoundSystem {
|
||||||
|
|
||||||
private final static IAudioClip emptySound = new NoSoundClip();
|
private static final IAudioClip emptySound = new NoSoundClip();
|
||||||
private final static Map<SoundEffectType, IAudioClip> loadedClips = new EnumMap<SoundEffectType, IAudioClip>(SoundEffectType.class);
|
private static final Map<SoundEffectType, IAudioClip> loadedClips = new EnumMap<SoundEffectType, IAudioClip>(SoundEffectType.class);
|
||||||
|
|
||||||
private final EventVisualizer visualizer = new EventVisualizer();
|
private final EventVisualizer visualizer = new EventVisualizer();
|
||||||
|
|
||||||
protected IAudioClip fetchResource(SoundEffectType type) {
|
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;
|
return emptySound;
|
||||||
|
}
|
||||||
|
|
||||||
IAudioClip clip = loadedClips.get(type);
|
IAudioClip clip = loadedClips.get(type);
|
||||||
if ( null == clip ) { // cache miss
|
if (null == clip) { // cache miss
|
||||||
String resource = type.getResourceFileName();
|
String resource = type.getResourceFileName();
|
||||||
clip = AudioClip.fileExists(resource) ? new AudioClip(resource) : emptySound;
|
clip = AudioClip.fileExists(resource) ? new AudioClip(resource) : emptySound;
|
||||||
loadedClips.put(type, clip);
|
loadedClips.put(type, clip);
|
||||||
}
|
}
|
||||||
return clip;
|
return clip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play the sound associated with the Sounds enumeration element.
|
* Play the sound associated with the Sounds enumeration element.
|
||||||
*/
|
*/
|
||||||
@@ -67,16 +68,19 @@ public class SoundSystem {
|
|||||||
public void stop(SoundEffectType type) {
|
public void stop(SoundEffectType type) {
|
||||||
fetchResource(type).stop();
|
fetchResource(type).stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void receiveEvent(Event evt) {
|
public void receiveEvent(Event evt) {
|
||||||
SoundEffectType effect = visualizer.getSoundForEvent(evt);
|
SoundEffectType effect = visualizer.getSoundForEvent(evt);
|
||||||
if ( null == effect ) return;
|
if (null == effect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean isSync = visualizer.isSyncSound(effect);
|
boolean isSync = visualizer.isSyncSound(effect);
|
||||||
if ( isSync )
|
if (isSync) {
|
||||||
playSync(effect);
|
playSync(effect);
|
||||||
else
|
} else {
|
||||||
play(effect);
|
play(effect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user