mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
New assetManager
This commit is contained in:
@@ -1,27 +1,26 @@
|
|||||||
package org.toop;
|
package org.toop;
|
||||||
|
|
||||||
import org.toop.app.gui.LocalServerSelector;
|
import org.toop.app.gui.LocalServerSelector;
|
||||||
|
import org.toop.framework.audio.AudioFiles;
|
||||||
|
import org.toop.framework.audio.SoundManager;
|
||||||
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.framework.networking.NetworkingClientManager;
|
import org.toop.framework.networking.NetworkingClientManager;
|
||||||
import org.toop.framework.networking.NetworkingInitializationException;
|
import org.toop.framework.networking.NetworkingInitializationException;
|
||||||
import org.toop.framework.audio.AudioFilesManager;
|
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.NotDirectoryException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
static void main(String[] args) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
|
static void main(String[] args) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
|
||||||
AudioFilesManager audioFiles = new AudioFilesManager("app/src/main/resources/audio/");
|
|
||||||
String aFile = audioFiles.getAudioFile("hdchirp_88k_log.wav");
|
|
||||||
AudioInputStream audioStream = AudioSystem.getAudioInputStream(new File(aFile));
|
|
||||||
Clip clip = AudioSystem.getClip();
|
|
||||||
clip.open(audioStream);
|
|
||||||
clip.start();
|
|
||||||
initSystems();
|
initSystems();
|
||||||
|
new EventFlow().addPostEvent(new AudioEvents.PlayAudio("mainmenu", true)).asyncPostEvent();
|
||||||
javax.swing.SwingUtilities.invokeLater(LocalServerSelector::new);
|
javax.swing.SwingUtilities.invokeLater(LocalServerSelector::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initSystems() throws NetworkingInitializationException {
|
private static void initSystems() throws NetworkingInitializationException, NotDirectoryException {
|
||||||
new NetworkingClientManager();
|
new NetworkingClientManager();
|
||||||
|
new SoundManager(new AudioFiles("app/src/main/resources/audio/"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,8 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.toop.app.gui.LocalGameSelector;
|
import org.toop.app.gui.LocalGameSelector;
|
||||||
import org.toop.app.gui.RemoteGameSelector;
|
import org.toop.app.gui.RemoteGameSelector;
|
||||||
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.game.Game;
|
import org.toop.game.Game;
|
||||||
import org.toop.tictactoe.LocalTicTacToe;
|
import org.toop.tictactoe.LocalTicTacToe;
|
||||||
|
|
||||||
@@ -95,6 +97,9 @@ public class UIGameBoard {
|
|||||||
}
|
}
|
||||||
this.localTicTacToe.move(index);
|
this.localTicTacToe.move(index);
|
||||||
cells[index].setText(currentPlayer);
|
cells[index].setText(currentPlayer);
|
||||||
|
new EventFlow().addPostEvent(
|
||||||
|
new AudioEvents.PlayAudio("hitsound0", false)
|
||||||
|
).asyncPostEvent();
|
||||||
} else {
|
} else {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Player "
|
"Player "
|
||||||
@@ -123,10 +128,19 @@ public class UIGameBoard {
|
|||||||
Color color;
|
Color color;
|
||||||
if (state == Game.State.WIN && playerMove.equals(currentPlayer)) {
|
if (state == Game.State.WIN && playerMove.equals(currentPlayer)) {
|
||||||
color = new Color(160, 220, 160);
|
color = new Color(160, 220, 160);
|
||||||
|
new EventFlow().addPostEvent(
|
||||||
|
new AudioEvents.PlayAudio("winsound", false)
|
||||||
|
).asyncPostEvent();
|
||||||
} else if (state == Game.State.WIN) {
|
} else if (state == Game.State.WIN) {
|
||||||
color = new Color(220, 160, 160);
|
color = new Color(220, 160, 160);
|
||||||
|
new EventFlow().addPostEvent(
|
||||||
|
new AudioEvents.PlayAudio("sadtrombone", false)
|
||||||
|
).asyncPostEvent();
|
||||||
} else if (state == Game.State.DRAW) {
|
} else if (state == Game.State.DRAW) {
|
||||||
color = new Color(220, 220, 160);
|
color = new Color(220, 220, 160);
|
||||||
|
new EventFlow().addPostEvent(
|
||||||
|
new AudioEvents.PlayAudio("dramatic", false)
|
||||||
|
).asyncPostEvent();
|
||||||
} else {
|
} else {
|
||||||
color = new Color(220, 220, 220);
|
color = new Color(220, 220, 220);
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
app/src/main/resources/audio/sadtrombone.wav
Normal file
BIN
app/src/main/resources/audio/sadtrombone.wav
Normal file
Binary file not shown.
BIN
app/src/main/resources/audio/scawymusic.wav
Normal file
BIN
app/src/main/resources/audio/scawymusic.wav
Normal file
Binary file not shown.
BIN
app/src/main/resources/audio/winsound.wav
Normal file
BIN
app/src/main/resources/audio/winsound.wav
Normal file
Binary file not shown.
24
framework/src/main/java/org/toop/framework/assets/Asset.java
Normal file
24
framework/src/main/java/org/toop/framework/assets/Asset.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.toop.framework.assets;
|
||||||
|
|
||||||
|
import org.toop.framework.SnowflakeGenerator;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class Asset {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Path assetPath;
|
||||||
|
private String asset;
|
||||||
|
|
||||||
|
public Asset(String name, Path assetPath) {
|
||||||
|
this.id = new SnowflakeGenerator().nextId();
|
||||||
|
this.name = name;
|
||||||
|
this.assetPath = assetPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAsset() {
|
||||||
|
java.nio.file.Path
|
||||||
|
this.asset = this.assetPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.toop.framework.assets;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class AssetManager {
|
||||||
|
|
||||||
|
private HashMap<Long, Asset> assets = new HashMap<>();
|
||||||
|
|
||||||
|
public AssetManager() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user