From 0a29485586012ae00548997c262ea16f3820a823 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 10 Nov 2024 20:45:32 +0500 Subject: upd: kotlin has been a disaster for maxon source code --- core/src/kz/ilotterytea/maxon/audio/Playlist.java | 57 +++++++++++++++++++++++ core/src/kz/ilotterytea/maxon/audio/Playlist.kt | 40 ---------------- 2 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 core/src/kz/ilotterytea/maxon/audio/Playlist.java delete mode 100644 core/src/kz/ilotterytea/maxon/audio/Playlist.kt (limited to 'core/src/kz/ilotterytea/maxon/audio') diff --git a/core/src/kz/ilotterytea/maxon/audio/Playlist.java b/core/src/kz/ilotterytea/maxon/audio/Playlist.java new file mode 100644 index 0000000..62e8d14 --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/audio/Playlist.java @@ -0,0 +1,57 @@ +package kz.ilotterytea.maxon.audio; + +import com.badlogic.gdx.audio.Music; +import kz.ilotterytea.maxon.utils.math.Math; + +import java.util.Arrays; +import java.util.List; + +public class Playlist { + private List music; + private Music playingNow; + private int index; + + private boolean shuffleMode; + private float volume; + + public Playlist(Music... music) { + this.music = Arrays.asList(music); + + this.playingNow = this.music.get(0); + this.index = 0; + this.shuffleMode = false; + this.volume = 1f; + + this.playingNow.setVolume(this.volume); + } + + public void next() { + if (playingNow.isPlaying()) playingNow.stop(); + + if (shuffleMode) { + index = Math.getRandomNumber(0, music.size() - 1); + playingNow = music.get(index); + } else { + index++; + if (index > music.size() - 1) index = 0; + + playingNow = music.get(index); + } + + playingNow.setVolume(volume); + playingNow.play(); + } + + public void setVolume(float volume) { + this.volume = volume; + playingNow.setVolume(volume); + } + + public void setShuffleMode(boolean shuffleMode) { + this.shuffleMode = shuffleMode; + } + + public Music getPlayingNow() { + return playingNow; + } +} diff --git a/core/src/kz/ilotterytea/maxon/audio/Playlist.kt b/core/src/kz/ilotterytea/maxon/audio/Playlist.kt deleted file mode 100644 index 2e79f37..0000000 --- a/core/src/kz/ilotterytea/maxon/audio/Playlist.kt +++ /dev/null @@ -1,40 +0,0 @@ -package kz.ilotterytea.maxon.audio - -import com.badlogic.gdx.audio.Music -import kz.ilotterytea.maxon.utils.math.Math - -/** - * Playlist. - */ -class Playlist(vararg musics: Music) { - private val playlist: Array = musics - var playingNow: Music = playlist[0] - private var index = 0 - - var shuffleMode = false - var volume = 1f - set(value) { - playingNow.volume = value - field = value - } - - /** - * Play next music. - */ - fun next() { - if (playingNow.isPlaying) playingNow.stop() - - if (shuffleMode) { - index = Math.getRandomNumber(0, playlist.size - 1) - playingNow = playlist[index] - } else { - index++ - if (index > playlist.size - 1) index = 0 - - playingNow = playlist[index] - } - - playingNow.volume = volume - playingNow.play() - } -} \ No newline at end of file -- cgit v1.2.3