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

Fix various volume issues #117

Draft
wants to merge 2 commits into
base: mod
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions Assets.Scripts.Core.Audio/AudioController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Assets.Scripts.Core.Buriko;
using MOD.Scripts.Core;
using MOD.Scripts.Core.Audio;
using MOD.Scripts.Core.TextWindow;
Expand Down Expand Up @@ -510,8 +511,30 @@ public int GetPriorityByType(AudioType audioType)
}
}

public static bool GlobalFlagAffectsAudio(string globalFlagName)
{
switch(globalFlagName)
{
case "GVoiceVolume":
case "GBGMVolume":
case "GSEVolume":
return true;
}

return false;
}

public void RefreshLayerVolumes()
{
if(BurikoMemory.Instance != null)
{
BurikoMemory memory = BurikoMemory.Instance;
VoiceVolume = (float)memory.GetGlobalFlag("GVoiceVolume").IntValue() / 100f;
BGMVolume = (float)memory.GetGlobalFlag("GBGMVolume").IntValue() / 100f;
SoundVolume = (float)memory.GetGlobalFlag("GSEVolume").IntValue() / 100f;
SystemVolume = (float)memory.GetGlobalFlag("GSEVolume").IntValue() / 100f;
}

for (int i = 0; i < 6; i++)
{
AudioLayerUnity audioLayerUnity = channelDictionary[GetChannelByTypeChannel(AudioType.BGM, i)];
Expand Down
3 changes: 2 additions & 1 deletion Assets.Scripts.Core.Audio/AudioLayerUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ private void OnFinishLoading()
audioSource.clip = audioClip;
audioSource.loop = isLoop;
audioSource.priority = audioController.GetPriorityByType(audioType);
volume = audioController.GetVolumeByType(audioType) * subVolume;
volume = audioController.GetVolumeByType(audioType);
audioSource.volume = volume * subVolume;
audioSource.Play();
isReady = true;
if (onFinishLoad != null)
Expand Down
20 changes: 13 additions & 7 deletions Assets.Scripts.Core.Buriko/BurikoMemory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Assets.Scripts.Core.AssetManagement;
using Assets.Scripts.Core.Audio;
using Assets.Scripts.Core.Buriko.Util;
using Assets.Scripts.Core.Buriko.VarTypes;
using MOD.Scripts.Core.Audio;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void SetGlobalFlag(string flagname, int val)
throw new Exception("Unable to set flag with the name " + flagname + ", flag not found.");
}
SetGlobalFlag(key, val);
MODSyncState();
MODSyncState(flagname);
}

public void SetHighestChapterFlag(int arcNumber, int number)
Expand Down Expand Up @@ -509,6 +510,7 @@ public void LoadGlobals()
string path = Path.Combine(MGHelper.GetSavePath(), "global.dat");
if (!File.Exists(path))
{
// This branch is only executed the first time the game is run (or if you manually delete your global.dat)
SetGlobalFlag("GUsePrompts", 1);
}
else
Expand Down Expand Up @@ -574,21 +576,18 @@ public void LoadGlobals()
GameSystem.Instance.SkipUnreadMessages = GetGlobalFlag("GSkipUnread").BoolValue();
GameSystem.Instance.ClickDuringAuto = GetGlobalFlag("GClickDuringAuto").BoolValue();
GameSystem.Instance.RightClickMenu = GetGlobalFlag("GRightClickMenu").BoolValue();
GameSystem.Instance.AudioController.VoiceVolume = (float)GetGlobalFlag("GVoiceVolume").IntValue() / 100f;
GameSystem.Instance.AudioController.BGMVolume = (float)GetGlobalFlag("GBGMVolume").IntValue() / 100f;
GameSystem.Instance.AudioController.SoundVolume = (float)GetGlobalFlag("GSEVolume").IntValue() / 100f;
GameSystem.Instance.AudioController.SystemVolume = (float)GetGlobalFlag("GSEVolume").IntValue() / 100f;
GameSystem.Instance.StopVoiceOnClick = GetGlobalFlag("GCutVoiceOnClick").BoolValue();
GameSystem.Instance.UseSystemSounds = GetGlobalFlag("GUseSystemSound").BoolValue();
GameSystem.Instance.UseEnglishText = GetGlobalFlag("GLanguage").BoolValue();
AssetManager.Instance.CurrentArtsetIndex = GetGlobalFlag("GArtStyle").IntValue();
GameSystem.Instance.AudioController.RefreshLayerVolumes();
}
catch (Exception message)
{
Debug.LogWarning(message);
}
}

AudioController.Instance.RefreshLayerVolumes();
}

public void SaveGlobals()
Expand Down Expand Up @@ -618,10 +617,17 @@ public void SaveGlobals()
/// <summary>
/// Syncs internal state with global flags. We could technically add all the stuff in LoadGlobals() if we wanted to - just seemed like a lot of overhead.
/// </summary>
public void MODSyncState()
public void MODSyncState(string flagname)
{
// Sync Art Style. This is really set up to support only init.txt initialization
AssetManager.Instance.CurrentArtsetIndex = GetGlobalFlag("GArtStyle").IntValue();

// Sync Audio Volumes. Currently our init.txt sets the global volume flags, which
// which doesn't automatically apply the audio volumes, so the below is needed.
if(AudioController.GlobalFlagAffectsAudio(flagname))
{
AudioController.Instance.RefreshLayerVolumes();
}
}
}
}
3 changes: 3 additions & 0 deletions Assets.Scripts.Core/GameSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ public void CompileScripts()
public void PostLoading()
{
StartScriptSystem();

// At this point in the startup, BurikoMemory is intialized
GameSystem.Instance.AudioController.RefreshLayerVolumes();
MainUIController.InitializeModMenu(this);
}

Expand Down
7 changes: 0 additions & 7 deletions Assets.Scripts.UI.Config/ConfigSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,12 @@ private void Update()
BurikoMemory.Instance.SetGlobalFlag("GWindowOpacity", num);
break;
case "1-AutoSpeed": // Voice Volume
GameSystem.Instance.AudioController.VoiceVolume = laststep;
GameSystem.Instance.AudioController.RefreshLayerVolumes();
BurikoMemory.Instance.SetGlobalFlag("GVoiceVolume", num);
break;
case "2-AutoPageSpeed": // BGM Volume
GameSystem.Instance.AudioController.BGMVolume = laststep;
GameSystem.Instance.AudioController.RefreshLayerVolumes();
BurikoMemory.Instance.SetGlobalFlag("GBGMVolume", num);
break;
case "3-WindowOpacity": // SE Volume
GameSystem.Instance.AudioController.SoundVolume = laststep;
GameSystem.Instance.AudioController.SystemVolume = laststep;
GameSystem.Instance.AudioController.RefreshLayerVolumes();
BurikoMemory.Instance.SetGlobalFlag("GSEVolume", num);
break;
case "4-BGMVolume": // Text / Auto text Speed
Expand Down