Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
CiroZDP committed Mar 16, 2024
1 parent 6cb068c commit bbd65b6
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 102 deletions.
9 changes: 4 additions & 5 deletions src/main/java/net/opencraft/client/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -76,7 +75,7 @@ public void run() {

public void render() {
Graphics g = this.screen.getGraphics();
Scenes.renderCurrent(g);
Scene.renderCurrent(g);
RenderDragon.update();
}

Expand All @@ -99,7 +98,7 @@ public void init() {

RenderDragon.init();
screen = RenderDragon.getScreen();
Scenes.setCurrent(LoadScene.SCENE);
Scene.setCurrent(Scene.LOAD_SCENE);

running = true;
}
Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/net/opencraft/renderer/scenes/LoadScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -84,7 +89,7 @@ public void changeScreen(long time) {
}
}

Scenes.setCurrent(Scenes.TITLE_SCENE);
Scene.setCurrent(Scene.TITLE_SCENE);
}

public static LoadScene renewInstance() {
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/net/opencraft/renderer/scenes/Scene.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
75 changes: 0 additions & 75 deletions src/main/java/net/opencraft/renderer/scenes/Scenes.java

This file was deleted.

14 changes: 7 additions & 7 deletions src/main/java/net/opencraft/renderer/scenes/TitleScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -55,19 +55,19 @@ 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;
default -> null;
};
}

public static void play(Clip player, Sounds sound)
public static void play(Clip player, Sound sound)
throws LineUnavailableException, IOException, UnsupportedAudioFileException {
if (player == null)
return;
Expand All @@ -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()));
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/opencraft/sound/SoundManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

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;

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 {

Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit bbd65b6

Please sign in to comment.