playable game
This commit is contained in:
+21
-7
@@ -1,13 +1,13 @@
|
||||
package model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import main.Window;
|
||||
import audio.AudioPlayer;
|
||||
import audio.Song;
|
||||
import audio.SongInstance;
|
||||
import audio.io.DirScanner;
|
||||
|
||||
public class SongHandler {
|
||||
@@ -15,6 +15,7 @@ public class SongHandler {
|
||||
private List<Song> songs;
|
||||
|
||||
private Song currentSong;
|
||||
private SongInstance currentSongInstance;
|
||||
private int currentIndex;
|
||||
|
||||
private File dir;
|
||||
@@ -26,16 +27,19 @@ public class SongHandler {
|
||||
songs = new ArrayList<Song>();
|
||||
|
||||
currentSong = null;
|
||||
currentIndex = -1;
|
||||
currentSongInstance = null;
|
||||
currentIndex = 0;
|
||||
|
||||
p = new AudioPlayer();
|
||||
|
||||
if(Window.ON_RASP)
|
||||
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs");
|
||||
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs/");
|
||||
else
|
||||
dir = new File("Songs");
|
||||
dir = new File(System.getProperty( "user.home" ) + "/Documents/songs/");
|
||||
|
||||
songs = DirScanner.scanDirectories(dir);
|
||||
System.out.println(songs.size());
|
||||
updatePlayer();
|
||||
}
|
||||
|
||||
public void next()
|
||||
@@ -56,15 +60,21 @@ public class SongHandler {
|
||||
updatePlayer();
|
||||
}
|
||||
}
|
||||
public void set(SongInstance si)
|
||||
{
|
||||
currentSongInstance = si;
|
||||
}
|
||||
|
||||
|
||||
private void updatePlayer()
|
||||
{
|
||||
if(currentIndex < 0)
|
||||
currentIndex = songs.size() + currentIndex;
|
||||
|
||||
currentIndex%=songs.size();
|
||||
if(currentIndex >= songs.size())
|
||||
currentIndex = currentIndex - songs.size();
|
||||
|
||||
currentSong = songs.get(currentIndex);
|
||||
currentSongInstance = currentSong.getSongs().get(0);
|
||||
|
||||
p.stop();
|
||||
p.setClip(currentSong);
|
||||
@@ -83,6 +93,10 @@ public class SongHandler {
|
||||
{
|
||||
return currentSong;
|
||||
}
|
||||
public SongInstance getCurrentSongInstance()
|
||||
{
|
||||
return currentSongInstance;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
@@ -102,7 +116,7 @@ public class SongHandler {
|
||||
{
|
||||
if(b)
|
||||
{
|
||||
p.play((int)currentSong.getSampleStart()*10000);
|
||||
p.play((int)currentSong.getSampleStart()*10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user