Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostSong Takes User to Song Selection & Last Song Played #303

Merged
merged 2 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assets/Scenes/MenuScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -12427,7 +12427,7 @@ MonoBehaviour:
m_Calls:
- m_Target: {fileID: 874813134}
m_TargetAssemblyTypeName: YARG.UI.MainMenu, Assembly-CSharp
m_MethodName: ShowMainMenu
m_MethodName: ShowSongSelect
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
Expand Down Expand Up @@ -16964,7 +16964,7 @@ MonoBehaviour:
m_Calls:
- m_Target: {fileID: 874813134}
m_TargetAssemblyTypeName: YARG.UI.MainMenu, Assembly-CSharp
m_MethodName: ShowMainMenu
m_MethodName: ShowSongSelect
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
Expand Down
2 changes: 2 additions & 0 deletions Assets/Script/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class GameManager : MonoBehaviour {
private AudioMixerGroup vocalGroup;

public SceneIndex CurrentScene { get; private set; } = SceneIndex.PERSISTANT;

public SongEntry SelectedSong { get; set; }

private void Awake() {
Instance = this;
Expand Down
129 changes: 38 additions & 91 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using YARG.Settings;
using YARG.Song;
using YARG.UI;
using YARG.Util;
using YARG.Venue;

namespace YARG.PlayMode {
Expand All @@ -28,8 +27,6 @@ public static Play Instance {

public const float SONG_START_OFFSET = -2f;

public static SongEntry song = null;

public delegate void BeatAction();
public static event BeatAction BeatEvent;

Expand All @@ -41,7 +38,7 @@ public static Play Instance {
public static event PauseStateChangeAction OnPauseToggle;

[SerializeField]
private RenderTexture backgroundRenderTexture;
private GameObject soundAudioPrefab;

public bool SongStarted {
get;
Expand Down Expand Up @@ -89,20 +86,12 @@ public bool Paused {

GameManager.AudioManager.Pause();

if (GameUI.Instance.videoPlayer.enabled) {
GameUI.Instance.videoPlayer.Pause();
}
} else {
Time.timeScale = 1f;

GameManager.AudioManager.Play();

if (GameUI.Instance.videoPlayer.enabled) {
GameUI.Instance.videoPlayer.Play();
}
}

OnPauseToggle?.Invoke(_paused);
OnPauseToggle(_paused);
}
}

Expand All @@ -114,8 +103,6 @@ private void Awake() {
ScoreKeeper.Reset();
StarScoreKeeper.Reset();

backgroundRenderTexture.ClearTexture();

// Song
StartSong();
}
Expand All @@ -127,10 +114,10 @@ private void StartSong() {
bool isSpeedUp = Math.Abs(speed - 1) > float.Epsilon;

// Load MOGG if CON, otherwise load stems
if (song is ExtractedConSongEntry rawConSongEntry) {
if (GameManager.Instance.SelectedSong is ExtractedConSongEntry rawConSongEntry) {
GameManager.AudioManager.LoadMogg(rawConSongEntry, isSpeedUp);
} else {
var stems = AudioHelpers.GetSupportedStems(song.Location);
var stems = AudioHelpers.GetSupportedStems(GameManager.Instance.SelectedSong.Location);

GameManager.AudioManager.LoadSong(stems, isSpeedUp);
}
Expand Down Expand Up @@ -172,8 +159,32 @@ private void StartSong() {
i++;
}

// Load background (venue, video, image, etc.)
LoadBackground();
// Load Background
string backgroundPath = Path.Combine(GameManager.Instance.SelectedSong.Location, "bg.yarground");
string mp4Path = Path.Combine(GameManager.Instance.SelectedSong.Location, "bg.mp4");
string pngPath = Path.Combine(GameManager.Instance.SelectedSong.Location, "bg.png");

if (File.Exists(backgroundPath)) {
// First check for a yarground
var bundle = AssetBundle.LoadFromFile(backgroundPath);
var bg = bundle.LoadAsset<GameObject>("Assets/_Background.prefab");
var bgInstance = Instantiate(bg);

bgInstance.GetComponent<BundleBackgroundManager>().Bundle = bundle;
} else if (File.Exists(mp4Path)) {
// If not, check for a video
GameUI.Instance.videoPlayer.url = mp4Path;
GameUI.Instance.videoPlayer.enabled = true;
GameUI.Instance.videoPlayer.Play();
} else if (File.Exists(pngPath)) {
// Otherwise, load an image
var png = ImageHelper.LoadTextureFromFile(pngPath);

GameUI.Instance.background.texture = png;
} else {
// No background file, we load a random video
// TODO: Add custom videos folder, load here
}

SongStarted = true;

Expand All @@ -192,74 +203,16 @@ private void StartSong() {
break;
}
}

OnSongStart?.Invoke(song);
}

private void LoadBackground() {
// Try a yarground first

string backgroundPath = Path.Combine(song.Location, "bg.yarground");
if (File.Exists(backgroundPath)) {
var bundle = AssetBundle.LoadFromFile(backgroundPath);

// KEEP THIS PATH LOWERCASE
// Breaks things for other platforms, because Unity
var bg = bundle.LoadAsset<GameObject>("assets/_background.prefab");

var bgInstance = Instantiate(bg);

bgInstance.GetComponent<BundleBackgroundManager>().Bundle = bundle;
return;
}

// Next, a video

string[] videoPaths = {
"bg.mp4",
"bg.mov",
"bg.webm",
};

foreach (var file in videoPaths) {
var path = Path.Combine(song.Location, file);

if (File.Exists(path)) {
GameUI.Instance.videoPlayer.url = path;
GameUI.Instance.videoPlayer.enabled = true;

return;
}
}

// Finally, an image

string[] imagePaths = {
"bg.png",
"bg.jpg",
"bg.jpeg",
};

foreach (var file in imagePaths) {
var path = Path.Combine(song.Location, file);

if (File.Exists(path)) {
var png = ImageHelper.LoadTextureFromFile(path);

GameUI.Instance.background.texture = png;
return;
}
}
}

private void LoadChart() {
// Add main file
var files = new List<string> {
Path.Combine(song.Location, song.NotesFile)
Path.Combine(GameManager.Instance.SelectedSong.Location, GameManager.Instance.SelectedSong.NotesFile)
};

// Look for upgrades and add
// var upgradeFolder = new DirectoryInfo(Path.Combine(song.RootFolder, "yarg_upgrade"));
// var upgradeFolder = new DirectoryInfo(Path.Combine(GameManager.Instance.ChosenSong.RootFolder, "yarg_upgrade"));
// if (upgradeFolder.Exists) {
// foreach (var midi in upgradeFolder.GetFiles("*.mid")) {
// files.Add(midi.FullName);
Expand All @@ -269,18 +222,18 @@ private void LoadChart() {
// Parse

MoonSong moonSong = null;
if (song.NotesFile.EndsWith(".chart")) {
if (GameManager.Instance.SelectedSong.NotesFile.EndsWith(".chart")) {
Debug.Log("Reading .chart file");
moonSong = ChartReader.ReadChart(files[0]);
}

chart = new YargChart(moonSong);
if (song.NotesFile.EndsWith(".mid")) {
if (GameManager.Instance.SelectedSong.NotesFile.EndsWith(".mid")) {
// Parse
var parser = new MidiParser(song, files.ToArray());
var parser = new MidiParser(GameManager.Instance.SelectedSong, files.ToArray());
chart.InitializeArrays();
parser.Parse(chart);
} else if (song.NotesFile.EndsWith(".chart")) {
} else if (GameManager.Instance.SelectedSong.NotesFile.EndsWith(".chart")) {
var handler = new BeatHandler(moonSong);
handler.GenerateBeats();
chart.beats = handler.Beats;
Expand All @@ -298,10 +251,6 @@ private IEnumerator StartAudio() {
yield return null;
}

if (GameUI.Instance.videoPlayer.enabled) {
GameUI.Instance.videoPlayer.Play();
}

GameManager.AudioManager.Play();
audioStarted = true;
}
Expand Down Expand Up @@ -427,7 +376,7 @@ private void Update() {
}
}

// End song
// End GameManager.Instance.ChosenSong
if (realSongTime >= SongLength) {
MainMenu.isPostSong = true;
Exit();
Expand Down Expand Up @@ -491,15 +440,13 @@ public void Exit() {
GameManager.AudioManager.UnloadSong();

// Call events
OnSongEnd?.Invoke(song);
OnSongEnd?.Invoke(GameManager.Instance.SelectedSong);

// Unpause just in case
Time.timeScale = 1f;

backgroundRenderTexture.ClearTexture();
_tracks.Clear();

OnSongEnd?.Invoke(song);
GameManager.Instance.LoadScene(SceneIndex.MENU);
}

Expand Down
22 changes: 7 additions & 15 deletions Assets/Script/UI/DifficultySelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ private void IncreasePlayerIndex() {
}

// Play song
Play.song = MainMenu.Instance.chosenSong;
GameManager.Instance.LoadScene(SceneIndex.PLAY);
} else {
UpdateInstrument();
Expand All @@ -224,7 +223,9 @@ private void UpdateInstrument() {

// Get available instruments
var availableInstruments = allInstruments
.Where(instrument => MainMenu.Instance.chosenSong.HasInstrument(instrument)).ToList();
.Where(instrument => GameManager.Instance.SelectedSong.HasInstrument(instrument)).ToList();

Debug.Log(GameManager.Instance.SelectedSong.AvailableParts);

// Force add pro drums and five lane
if (availableInstruments.Contains(Instrument.DRUMS)) {
Expand All @@ -242,25 +243,16 @@ private void UpdateInstrument() {
// Filter out to only allowed instruments
availableInstruments.RemoveAll(i => !player.inputStrategy.GetAllowedInstruments().Contains(i));

bool showSitOut = availableInstruments.Count <= 0 || PlayerManager.players.Count > 1;

optionCount = availableInstruments.Count + (showSitOut ? 1 : 0);
if (showSitOut) {
optionCount++;
}
optionCount = availableInstruments.Count + 1;

// Add to options
var ops = new string[optionCount];
var ops = new string[availableInstruments.Count + 1];
instruments = new string[availableInstruments.Count];
for (int i = 0; i < instruments.Length; i++) {
instruments[i] = availableInstruments[i].ToStringName();
ops[i] = availableInstruments[i].ToLocalizedName();
}

// Add sit out (only if there are more than 1 player)
if (showSitOut) {
ops[^1] = "Sit Out";
}
ops[^1] = "Sit Out";

// Set text and sprites
for (int i = 0; i < 6; i++) {
Expand Down Expand Up @@ -294,7 +286,7 @@ private void UpdateDifficulty(string chosenInstrument, bool showExpertPlus) {
// Get the available difficulties
var availableDifficulties = new List<Difficulty>();
for (int i = 0; i < (int) Difficulty.EXPERT_PLUS; i++) {
if (!MainMenu.Instance.chosenSong.HasPart(instrument, (Difficulty) i)) {
if (!GameManager.Instance.SelectedSong.HasPart(instrument, (Difficulty) i)) {
continue;
}
availableDifficulties.Add((Difficulty) i);
Expand Down
8 changes: 4 additions & 4 deletions Assets/Script/UI/GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ private void Awake() {

private void Start() {
if (Play.speed == 1f) {
songTitle.text = $"{Play.song.Name}";
bandName.text = $"{Play.song.Artist}";
songTitle.text = $"{GameManager.Instance.SelectedSong.Name}";
bandName.text = $"{GameManager.Instance.SelectedSong.Artist}";
} else {
songTitle.text = $"{Play.song.Name} ({Play.speed * 100}%)";
bandName.text = $"{Play.song.Artist}";
songTitle.text = $"{GameManager.Instance.SelectedSong.Name} ({Play.speed * 100}%)";
bandName.text = $"{GameManager.Instance.SelectedSong.Artist}";
}
}

Expand Down
2 changes: 0 additions & 2 deletions Assets/Script/UI/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ private enum ButtonIndex {
EXIT
}

public SongEntry chosenSong = null;

[SerializeField]
private Canvas mainMenu;
[SerializeField]
Expand Down
16 changes: 15 additions & 1 deletion Assets/Script/UI/MusicLibrary/SongSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ private set {
_selectedIndex -= _songs.Count;
}

if (_songs[value] is SongViewType song) {
GameManager.Instance.SelectedSong = song.SongEntry;
}

UpdateScrollbar();
UpdateSongViews();
}
Expand Down Expand Up @@ -301,7 +305,17 @@ public void UpdateSearch() {
_songs.Clear();
}

SelectedIndex = 1;
if (GameManager.Instance.SelectedSong == null) {
SelectedIndex = 1;
} else {
var index = _songs.FindIndex(song => {
var songType = song as SongViewType;
return songType != null && songType.SongEntry == GameManager.Instance.SelectedSong;
});

SelectedIndex = Mathf.Max(1, index);
}

UpdateSongViews();
UpdateScrollbar();
}
Expand Down
1 change: 0 additions & 1 deletion Assets/Script/UI/MusicLibrary/ViewTypes/SongViewType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public override void SecondaryTextClick() {
public override void PrimaryButtonClick() {
base.PrimaryButtonClick();

MainMenu.Instance.chosenSong = SongEntry;
MainMenu.Instance.ShowPreSong();
}

Expand Down
Loading