Moved two apps to seperate bundle and chains.

This commit is contained in:
Willem Cazander 2022-03-03 23:20:19 +01:00
parent 812e80fa5e
commit c47d626eef
57 changed files with 1011 additions and 305 deletions

View file

@ -0,0 +1,34 @@
package love.distributedrebirth.gdxapp4d.app.tosamp;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs;
import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
@Component
public class TosAmpComponent {
@Reference
private SystemGdxLog log;
@Reference
private VrGem4DeskAppService deskAppService;
@Reference
private SystemGdxBootArgs bootArgs;
@Activate
void open() {
log.info(this, "Activated TosAmpComponent");
deskAppService.registrateDeskApp(new DeskAppLauncher("TosAmp", () -> new TosAmpDeskApp(bootArgs.getFileChooser())));
}
@Deactivate
void close() {
}
}

View file

@ -0,0 +1,130 @@
package love.distributedrebirth.gdxapp4d.app.tosamp;
import java.util.function.Consumer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import imgui.ImGui;
import imgui.flag.ImGuiSelectableFlags;
import imgui.flag.ImGuiTableColumnFlags;
import imgui.flag.ImGuiTableFlags;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.app.tosamp.music.MusicManager;
import love.distributedrebirth.gdxapp4d.app.tosamp.music.MusicSong;
import love.distributedrebirth.gdxapp4d.vrgem4.FontAwesomeIcons;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer;
import net.spookygames.gdx.nativefilechooser.NativeFileChooser;
import net.spookygames.gdx.nativefilechooser.NativeFileChooserCallback;
import net.spookygames.gdx.nativefilechooser.NativeFileChooserConfiguration;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer {
private final MusicManager music;
private final NativeFileChooser fileChooser;
private NativeFileChooserConfiguration fileChooserConfig;
public TosAmpDeskApp(NativeFileChooser fileChooser) {
this.fileChooser = fileChooser;
this.music = new MusicManager();
}
public void create() {
getContours().setTitle("\uf001 TosAmp");
getContours().registrateContour(DeskAppContourSection.MAIN, this);
getContours().registrateContour(DeskAppContourSection.FILE_NEW, new DeskAppRenderer() {
@Override
public void render() {
if (ImGui.menuItem(FontAwesomeIcons.Plus + " Add")) {
fileChooser.chooseFile(fileChooserConfig,
NativeFileChooserCallbackAdapter.onFileChosen(v -> music.addBackgroundMusic(v)));
}
}
});
fileChooserConfig = new NativeFileChooserConfiguration();
fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home"));
fileChooserConfig.mimeFilter = "audio/*";
fileChooserConfig.title = "Choose audio file";
}
@Override
public void render() {
ImGui.text("Current Song:");
MusicSong currentSong = music.getCurrentSong();
if (currentSong != null) {
ImGui.sameLine();
ImGui.text(currentSong.getName());
}
ImGui.separator();
if (currentSong != null) {
if (ImGui.button("Play")) {
music.play(currentSong);
}
} else {
ImGui.text("Play");
}
ImGui.sameLine();
if (ImGui.button("<")) {
music.prev();
}
ImGui.sameLine();
if (ImGui.button(">")) {
music.next();
}
ImGui.sameLine();
if (ImGui.button("Stop")) {
music.stop();
}
int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV;
ImGui.beginTable("playlist", 3, flags);
ImGui.tableSetupColumn("#", ImGuiTableColumnFlags.NoHide);
ImGui.tableSetupColumn("Play");
ImGui.tableSetupColumn("Name");
ImGui.tableHeadersRow();
int i=1;
for (MusicSong song:music.getBackgroundSongs()) {
ImGui.pushID(i);
ImGui.tableNextRow();
ImGui.tableNextColumn();
ImGui.selectable(""+i, song.isPlaying(), ImGuiSelectableFlags.None);
ImGui.tableNextColumn();
if (ImGui.smallButton(">")) {
music.play(song);
}
ImGui.tableNextColumn();
ImGui.selectable(song.getName(), song.isPlaying(), ImGuiSelectableFlags.None);
ImGui.popID();
i++;
}
ImGui.endTable();
}
static class NativeFileChooserCallbackAdapter implements NativeFileChooserCallback {
@Override
public void onFileChosen(FileHandle file) {
}
@Override
public void onCancellation() {
}
@Override
public void onError(Exception exception) {
}
static NativeFileChooserCallbackAdapter onFileChosen(Consumer<FileHandle> eater) {
return new NativeFileChooserCallbackAdapter() {
@Override
public void onFileChosen(FileHandle file) {
eater.accept(file);
}
};
}
}
}

View file

@ -0,0 +1,38 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class M3UParser {
private static final String M3U_HEADER = "#EXTM3U";
public class M3UPlaylist {
private List<M3UTrack> tracks = new ArrayList<>();
}
public class M3UTrack {
}
public M3UPlaylist parse(InputStream stream) throws IOException {
M3UPlaylist result = new M3UPlaylist();
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
String line = buffer.readLine();
if (!line.startsWith(M3U_HEADER)) {
throw new IOException("Missing header");
}
while ((line = buffer.readLine()) != null) {
}
return result;
}
}

View file

@ -0,0 +1,143 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Music.OnCompletionListener;
import com.badlogic.gdx.files.FileHandle;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
/**
* Manages the background and others songs.
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class MusicManager {
// private final MusicSong introSong;
// private final MusicSong creditsSong;
private final List<MusicSong> backgroundSongs;
private final NextSongListener nextSongListener;
private MusicSong currentSong = null;
private boolean noMusic = false;
public MusicManager() {
backgroundSongs = new ArrayList<>();
// introSong = new MusicSong(Gdx.audio.newMusic(Gdx.files.internal("music/panoramacircle-waterfowl.mp3")),"panoramacircle-waterfowl");
// creditsSong = new MusicSong(Gdx.audio.newMusic(Gdx.files.internal("music/idtech-doom-sigil.mp3")), "idtech-doom-sigil");
nextSongListener = new NextSongListener();
}
public void addBackgroundMusic(FileHandle file) {
Music music = Gdx.audio.newMusic(file);
music.setOnCompletionListener(nextSongListener);
backgroundSongs.add(new MusicSong(music, file.name()));
}
public void init(boolean noMusic) {
this.noMusic = noMusic;
/*
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-risen.mp3"));
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-devine-intellect.mp3"));
addBackgroundMusic(Gdx.files.internal("music/theselfhelpgroup-temple-os.mp3"));
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-nightwalk.mp3"));
addBackgroundMusic(Gdx.files.internal("music/beeble-i-used-temple-os-to-write.mp3"));
addBackgroundMusic(Gdx.files.internal("music/ryanfarran-risen-temple-os.mp3"));
*/
}
public void dispose() {
// introSong.music.dispose();
// creditsSong.music.dispose();
for (MusicSong song:backgroundSongs) {
song.music.dispose();
}
}
public List<MusicSong> getBackgroundSongs() {
return backgroundSongs;
}
public MusicSong getCurrentSong() {
return currentSong;
}
public void stop() {
if (currentSong != null) {
currentSong.music.stop();
}
}
public void play(MusicSongType type) {
MusicSong nextSong = null;
if (MusicSongType.INTRO.equals(type)) {
// nextSong = introSong;
// play(nextSong);
} else if (MusicSongType.CREDITS.equals(type)) {
// nextSong = creditsSong;
// play(nextSong);
} else {
int currentBackground = backgroundSongs.indexOf(currentSong);
if (currentBackground == -1 && !backgroundSongs.isEmpty()) {
nextSong = backgroundSongs.get(0);
} else {
nextSong = currentSong;
}
if (!noMusic && nextSong!=null) {
play(nextSong);
}
}
}
public void play(MusicSong song) {
if (song == null) {
return;
}
stop();
currentSong = song;
currentSong.music.play();
}
class NextSongListener implements OnCompletionListener {
@Override
public void onCompletion(Music music) {
next();
play(currentSong);
}
}
public void next() {
int currentBackground = backgroundSongs.indexOf(currentSong);
if (currentBackground == -1) {
return; // some other
}
if (currentBackground == backgroundSongs.size()-1) {
currentBackground = -1; // loop to start
}
boolean play = currentSong.music.isPlaying();
currentSong.music.stop();
currentSong = backgroundSongs.get(currentBackground+1);
if (play) {
currentSong.music.play();
}
}
public void prev() {
int currentBackground = backgroundSongs.indexOf(currentSong);
if (currentBackground == -1) {
return; // some other
}
if (currentBackground == 0) {
currentBackground = backgroundSongs.size(); // loop to end
}
boolean play = currentSong.music.isPlaying();
currentSong.music.stop();
currentSong = backgroundSongs.get(currentBackground-1);
if (play) {
currentSong.music.play();
}
}
}

View file

@ -0,0 +1,27 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import com.badlogic.gdx.audio.Music;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
/**
* The music with the (file) name.
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class MusicSong {
protected final Music music;
private final String name;
public MusicSong(Music music, String name) {
this.music = music;
this.name = name;
}
public String getName() {
return name;
}
public boolean isPlaying() {
return music.isPlaying();
}
}

View file

@ -0,0 +1,13 @@
package love.distributedrebirth.gdxapp4d.app.tosamp.music;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
/**
* The song types.
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public enum MusicSongType {
INTRO,
CREDITS,
BACKGROUND
}