diff --git a/src/main/java/net/opencraft/client/Game.java b/src/main/java/net/opencraft/client/Game.java index 71e72f2..f4ced21 100644 --- a/src/main/java/net/opencraft/client/Game.java +++ b/src/main/java/net/opencraft/client/Game.java @@ -16,8 +16,7 @@ import net.opencraft.data.packs.Pack; import net.opencraft.renderer.RenderDragon; import net.opencraft.renderer.Screen; -import net.opencraft.renderer.scenes.LoadScene; -import net.opencraft.renderer.scenes.Scenes; +import net.opencraft.renderer.scenes.Scene; import net.opencraft.sound.SoundManager; public class Game implements Runnable { @@ -76,7 +75,7 @@ public void run() { public void render() { Graphics g = this.screen.getGraphics(); - Scenes.renderCurrent(g); + Scene.renderCurrent(g); RenderDragon.update(); } @@ -99,7 +98,7 @@ public void init() { RenderDragon.init(); screen = RenderDragon.getScreen(); - Scenes.setCurrent(LoadScene.SCENE); + Scene.setCurrent(Scene.LOAD_SCENE); running = true; } @@ -125,7 +124,7 @@ public static void disableUnicode() { } public static void skipIntro() { - Scenes.setCurrent(Scenes.TITLE_SCENE); + Scene.setCurrent(Scene.TITLE_SCENE); } public static void selectPack(Pack pack) { diff --git a/src/main/java/net/opencraft/renderer/scenes/LoadScene.java b/src/main/java/net/opencraft/renderer/scenes/LoadScene.java index 5b5fe16..5b690de 100644 --- a/src/main/java/net/opencraft/renderer/scenes/LoadScene.java +++ b/src/main/java/net/opencraft/renderer/scenes/LoadScene.java @@ -10,13 +10,14 @@ import net.opencraft.config.GameExperiments; import net.opencraft.renderer.display.Display; +import net.opencraft.sound.Sound; import net.opencraft.util.Assets; import net.opencraft.util.Resource; public class LoadScene extends Scene { public static final Resource RESOURCE = Resource.format("opencraft.scene:load"); - public static final Scenes SCENE = Scenes.LOAD_SCREEN; + public static final Sound SOUND = Sound.NONE; private static final Logger logger = Logger.getLogger("loadscene"); private static final int I_MAX = Display.HEIGHT / 2; @@ -30,6 +31,10 @@ public class LoadScene extends Scene { handle(logger); } + public LoadScene() { + super(RESOURCE, SOUND); + } + public void render(Graphics g) { if (GameExperiments.SKIP_LOAD_SCENE) { changeScreen(0); @@ -84,7 +89,7 @@ public void changeScreen(long time) { } } - Scenes.setCurrent(Scenes.TITLE_SCENE); + Scene.setCurrent(Scene.TITLE_SCENE); } public static LoadScene renewInstance() { diff --git a/src/main/java/net/opencraft/renderer/scenes/Scene.java b/src/main/java/net/opencraft/renderer/scenes/Scene.java index 3ae8dcd..36b3db2 100644 --- a/src/main/java/net/opencraft/renderer/scenes/Scene.java +++ b/src/main/java/net/opencraft/renderer/scenes/Scene.java @@ -1,7 +1,66 @@ package net.opencraft.renderer.scenes; +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +import net.opencraft.config.GameExperiments; import net.opencraft.renderer.Renderizable; +import net.opencraft.sound.Sound; +import net.opencraft.sound.SoundManager; +import net.opencraft.util.Resource; public abstract class Scene implements Renderizable { + public static final Scene LOAD_SCENE = LoadScene.getInstance(); + public static final Scene TITLE_SCENE = TitleScene.getInstance(); + +// LOAD_SCREEN(LoadScene.RESOURCE, Sound.NONE), +// TITLE_SCENE(TitleScene.RESOURCE, Sound.MOOG_CITY); + + protected static Scene current = TITLE_SCENE; + protected final Resource res; + protected final Sound snd; + + public Scene(Resource res, Sound snd) { + this.res = res; + this.snd = snd; + } + + public Sound getSound() { + return this.snd; + } + + public static void renderCurrent(BufferedImage bi) { + getCurrent().render(bi); + } + + public static void renderCurrent(Graphics g, int width, int height) { + getCurrent().render(g, width, height); + } + + public static void renderCurrent(Graphics g) { + getCurrent().render(g); + } + + public static Scene getCurrent() { + return current; + } + + public void setCurrent() { + setCurrent(this); + } + + public static Scene setCurrent(Scene scn) { + current = scn; + + if (GameExperiments.PLAY_SOUND_ONCE) + SoundManager.update(); + + return current; + } + + public Resource getResource() { + return res; + } + } diff --git a/src/main/java/net/opencraft/renderer/scenes/Scenes.java b/src/main/java/net/opencraft/renderer/scenes/Scenes.java deleted file mode 100644 index 6f5b2ff..0000000 --- a/src/main/java/net/opencraft/renderer/scenes/Scenes.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.opencraft.renderer.scenes; - -import java.awt.Graphics; -import java.awt.image.BufferedImage; - -import net.opencraft.config.GameExperiments; -import net.opencraft.renderer.Renderizable; -import net.opencraft.sound.SoundManager; -import net.opencraft.sound.Sounds; -import net.opencraft.util.Resource; - -public enum Scenes { - - LOAD_SCREEN(LoadScene.RESOURCE, Sounds.NONE), - TITLE_SCENE(TitleScene.RESOURCE, Sounds.MOOG_CITY); - - private static Scenes current = TITLE_SCENE; - private final Resource res; - private final Sounds snd; - - Scenes(Resource res, Sounds snd) { - this.res = res; - this.snd = snd; - } - - public Renderizable getScene(Scenes sc) { - return switch (sc) { - case TITLE_SCENE -> TitleScene.getInstance(); - case LOAD_SCREEN -> LoadScene.getInstance(); - default -> null; - }; - } - - public Renderizable getScene() { - return getScene(this); - } - - public Sounds getSound() { - return this.snd; - } - - public static void renderCurrent(BufferedImage bi) { - getCurrent().getScene().render(bi); - } - - public static void renderCurrent(Graphics g, int width, int height) { - getCurrent().getScene().render(g, width, height); - } - - public static void renderCurrent(Graphics g) { - getCurrent().getScene().render(g); - } - - public static Scenes getCurrent() { - return current; - } - - public void setCurrent() { - setCurrent(this); - } - - public static Scenes setCurrent(Scenes scn) { - current = scn; - - if (GameExperiments.PLAY_SOUND_ONCE) - SoundManager.update(); - - return current; - } - - public Resource getResource() { - return res; - } - -} diff --git a/src/main/java/net/opencraft/renderer/scenes/TitleScene.java b/src/main/java/net/opencraft/renderer/scenes/TitleScene.java index 1f3ad9e..a126868 100644 --- a/src/main/java/net/opencraft/renderer/scenes/TitleScene.java +++ b/src/main/java/net/opencraft/renderer/scenes/TitleScene.java @@ -9,25 +9,25 @@ import net.opencraft.client.Game; import net.opencraft.language.Translator; -import net.opencraft.renderer.Renderizable; import net.opencraft.renderer.display.Display; +import net.opencraft.sound.Sound; import net.opencraft.util.Assets; import net.opencraft.util.Fonts; import net.opencraft.util.Resource; import net.opencraft.util.coords.Coordinates; import net.opencraft.util.coords.Vec2; -public class TitleScene implements Renderizable { +public class TitleScene extends Scene { public static final Resource RESOURCE = Resource.format("opencraft.scene:title"); - - /** - * Don't use it, it's bugged for some reason - */ - public static final Scenes SCENE = Scenes.TITLE_SCENE; + public static final Sound SOUND = Sound.MOOG_CITY; private static TitleScene instance = new TitleScene(); + public TitleScene() { + super(RESOURCE, SOUND); + } + @Override public void render(Graphics g) { diff --git a/src/main/java/net/opencraft/sound/Sounds.java b/src/main/java/net/opencraft/sound/Sound.java similarity index 84% rename from src/main/java/net/opencraft/sound/Sounds.java rename to src/main/java/net/opencraft/sound/Sound.java index 6bd73e0..0d5c5bb 100644 --- a/src/main/java/net/opencraft/sound/Sounds.java +++ b/src/main/java/net/opencraft/sound/Sound.java @@ -15,24 +15,24 @@ import net.opencraft.config.Workspace; import net.opencraft.util.Resource; -public enum Sounds { +public enum Sound { NONE("opencraft.sounds", "none", null), MOOG_CITY("opencraft.sound", "title.moog_city", "MoogCity.wav"), ARIA_MATH("opencraft.sound", "ambient.aria_math", "AriaMath.wav"); - public static Sounds PLAYING = null; + public static Sound PLAYING = null; final String origin; final String soundId; final String path; - Sounds(String origin, String soundTitle, String name) { + Sound(String origin, String soundTitle, String name) { this.origin = origin; this.soundId = soundTitle; this.path = name; } - public static void setCurrent(Sounds aures) { + public static void setCurrent(Sound aures) { PLAYING = aures; } @@ -55,11 +55,11 @@ public String getPath() { return Workspace.ASSETS_DIR + "/opencraft/sounds/" + path; } - public static Sounds getCurrent() { + public static Sound getCurrent() { return PLAYING; } - public Sounds fromResource(Resource res) { + public Sound fromResource(Resource res) { return switch (res.toString()) { case "opencraft.sound:title.moog_city" -> MOOG_CITY; case "opencraft.sound:ambient.aria_math" -> ARIA_MATH; @@ -67,7 +67,7 @@ public Sounds fromResource(Resource res) { }; } - public static void play(Clip player, Sounds sound) + public static void play(Clip player, Sound sound) throws LineUnavailableException, IOException, UnsupportedAudioFileException { if (player == null) return; @@ -81,7 +81,7 @@ public void play(Clip player) throws LineUnavailableException, IOException, Unsu play(player, this); } - public static InputStream getSound(Sounds snd) throws IOException { + public static InputStream getSound(Sound snd) throws IOException { return new BufferedInputStream(new FileInputStream(snd.getPath())); } diff --git a/src/main/java/net/opencraft/sound/SoundManager.java b/src/main/java/net/opencraft/sound/SoundManager.java index 2f7ea33..e7f4528 100644 --- a/src/main/java/net/opencraft/sound/SoundManager.java +++ b/src/main/java/net/opencraft/sound/SoundManager.java @@ -2,8 +2,8 @@ import static net.opencraft.LoggerConfig.LOG_FORMAT; import static net.opencraft.LoggerConfig.handle; -import static net.opencraft.sound.Sounds.getCurrent; -import static net.opencraft.sound.Sounds.setCurrent; +import static net.opencraft.sound.Sound.getCurrent; +import static net.opencraft.sound.Sound.setCurrent; import java.util.Objects; import java.util.logging.Logger; @@ -11,7 +11,7 @@ import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; -import net.opencraft.renderer.scenes.Scenes; +import net.opencraft.renderer.scenes.Scene; public class SoundManager { @@ -42,14 +42,14 @@ private SoundManager() { } public static void update() { - Sounds sound = Scenes.getCurrent().getSound(); + Sound sound = Scene.getCurrent().getSound(); if (!isSupported() || Objects.isNull(sound.getPath())) return; if (getCurrent() != sound) { resetPlayer(); try { - Sounds.play(player, sound); + Sound.play(player, sound); } catch (Exception e) { logger.severe(e.getMessage()); }