New assetManager

This commit is contained in:
Bas de Jong
2025-09-30 11:48:53 +02:00
parent 9131803044
commit d1da49ad1d
7 changed files with 59 additions and 10 deletions

View File

@@ -1,27 +1,26 @@
package org.toop;
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.NetworkingInitializationException;
import org.toop.framework.audio.AudioFilesManager;
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.NotDirectoryException;
public class Main {
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();
new EventFlow().addPostEvent(new AudioEvents.PlayAudio("mainmenu", true)).asyncPostEvent();
javax.swing.SwingUtilities.invokeLater(LocalServerSelector::new);
}
private static void initSystems() throws NetworkingInitializationException {
private static void initSystems() throws NetworkingInitializationException, NotDirectoryException {
new NetworkingClientManager();
new SoundManager(new AudioFiles("app/src/main/resources/audio/"));
}
}
}

View File

@@ -8,6 +8,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.toop.app.gui.LocalGameSelector;
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.tictactoe.LocalTicTacToe;
@@ -95,6 +97,9 @@ public class UIGameBoard {
}
this.localTicTacToe.move(index);
cells[index].setText(currentPlayer);
new EventFlow().addPostEvent(
new AudioEvents.PlayAudio("hitsound0", false)
).asyncPostEvent();
} else {
logger.info(
"Player "
@@ -123,10 +128,19 @@ public class UIGameBoard {
Color color;
if (state == Game.State.WIN && playerMove.equals(currentPlayer)) {
color = new Color(160, 220, 160);
new EventFlow().addPostEvent(
new AudioEvents.PlayAudio("winsound", false)
).asyncPostEvent();
} else if (state == Game.State.WIN) {
color = new Color(220, 160, 160);
new EventFlow().addPostEvent(
new AudioEvents.PlayAudio("sadtrombone", false)
).asyncPostEvent();
} else if (state == Game.State.DRAW) {
color = new Color(220, 220, 160);
new EventFlow().addPostEvent(
new AudioEvents.PlayAudio("dramatic", false)
).asyncPostEvent();
} else {
color = new Color(220, 220, 220);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View 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;
}
}

View File

@@ -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() {
}
}