Skip to content

Commit

Permalink
add(LabMusic): Dropdown now includes all the possible musicThemeInsta…
Browse files Browse the repository at this point in the history
…nces.
  • Loading branch information
JaXt0r committed Mar 6, 2024
1 parent 31f759c commit d79267e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Assets/GothicVR-Lab/Scenes/Lab.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4120,11 +4120,11 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 464842610}
- component: {fileID: 464842615}
- component: {fileID: 464842609}
- component: {fileID: 464842612}
- component: {fileID: 464842613}
- component: {fileID: 464842614}
- component: {fileID: 464842615}
- component: {fileID: 464842616}
- component: {fileID: 464842617}
m_Layer: 0
Expand Down
30 changes: 19 additions & 11 deletions Assets/GothicVR-Lab/Scripts/Handler/LabMusicHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GVR.Caches;
using GVR.Debugging;
using GVR.Globals;
using GVR.Manager;
using TMPro;
using UnityEngine;
using ZenKit.Daedalus;

namespace GVR.Lab.Handler
{
Expand All @@ -12,17 +16,22 @@ public class LabMusicHandler : MonoBehaviour, ILabHandler
public TMP_Dropdown fileSelector;
public TMP_Dropdown themeSelector;

private Dictionary<string, List<string>> musicMapping = new()
{
{ "ow_day_std.sgt", new(){ "DEF_DAY_STD" } },
{ "ban_day_std.sgt", new(){ "STA_DAY_STD" } },
{ "oc_day_std.sgt", new(){ "" } },
};
private List<MusicThemeInstance> _musicInstances;

public void Bootstrap()
{
fileSelector.options = musicMapping.Select(dict => new TMP_Dropdown.OptionData(dict.Key)).ToList();
themeSelector.options = musicMapping.First().Value.Select(i => new TMP_Dropdown.OptionData(i)).ToList();
var prototype = GameData.MusicVm.GetSymbolByName("C_MUSICTHEME_DEF");

_musicInstances = GameData.MusicVm.Symbols
.Where(s => s.Parent == prototype.Index)
.Select(s => AssetCache.TryGetMusic(s.Name))
.GroupBy(instance => instance.File, StringComparer.InvariantCultureIgnoreCase)
.Select(group => group.First())
.OrderBy(instance => instance.File)
.ToList();

fileSelector.options = _musicInstances.Select(i => new TMP_Dropdown.OptionData(i.File)).ToList();
// themeSelector.options = musicMapping.First().Value.Select(i => new TMP_Dropdown.OptionData(i)).ToList();
}

public void MusicPlayClick()
Expand All @@ -31,10 +40,9 @@ public void MusicPlayClick()
FeatureFlags.I.enableMusic = true;
FeatureFlags.I.showMusicLogs = true;

var fileSelect = fileSelector.options[fileSelector.value].text;
var themeSelect = fileSelector.options[fileSelector.value].text;
var item = _musicInstances[fileSelector.value];

MusicManager.I.SetMusic(fileSelect, themeSelect);
MusicManager.I.SetMusic(item);
}
}
}
18 changes: 8 additions & 10 deletions Assets/GothicVR/Scripts/Manager/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,40 +191,38 @@ public void SetMusic(string zone, Tags tags)
if ((tags & Tags.Thr) != 0)
musicTag = "THR";

var musicName = $"{result}_{(isDay ? "DAY" : "NGT")}_{musicTag}";
var musicThemeInstanceName = $"{result}_{(isDay ? "DAY" : "NGT")}_{musicTag}";

var theme = AssetCache.TryGetMusic(musicName);
var theme = AssetCache.TryGetMusic(musicThemeInstanceName);

reloadTheme = pendingTheme.File != theme.File;
pendingTheme = theme;
pendingTags = tags;
hasPending = true;

if (FeatureFlags.I.showMusicLogs)
Debug.Log($"Playing music: theme >{musicName}< from file >{theme.File}<");
Debug.Log($"Playing music: MusicThemeInstance >{musicThemeInstanceName}< from file >{theme.File}<");
}

public void SetMusic(string segment, string themeName)
public void SetMusic(MusicThemeInstance theme)
{
var theme = AssetCache.TryGetMusic(themeName);

reloadTheme = true;
pendingTheme = theme;
hasPending = true;

if (FeatureFlags.I.showMusicLogs)
Debug.Log($"Playing music: theme >{themeName}< from file >{theme.File}<");
Debug.Log($"[Music] Playing music from file >{theme.File}<.");
}

public void SetMusic(string musicName)
public void SetMusic(string musicThemeInstanceName)
{
var theme = AssetCache.TryGetMusic(musicName);
var theme = AssetCache.TryGetMusic(musicThemeInstanceName);
reloadTheme = true;
pendingTheme = theme;
hasPending = true;

if (FeatureFlags.I.showMusicLogs)
Debug.Log($"[Music] Playing music: theme >{musicName}< from file >{theme.File}<");
Debug.Log($"[Music] Playing music: MusicThemeInstance >{musicThemeInstanceName}< from file >{theme.File}<");
}

private void StopMusic()
Expand Down

0 comments on commit d79267e

Please sign in to comment.