Skip to content

Commit

Permalink
Merge branch 'mod' into matsuri-mod
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Nov 5, 2022
2 parents 2fc3a95 + d4d5aa1 commit b1a65de
Show file tree
Hide file tree
Showing 11 changed files with 714 additions and 34 deletions.
1 change: 1 addition & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
<Compile Include="Linear.cs" />
<Compile Include="Localization.cs" />
<Compile Include="MenuUIController.cs" />
<Compile Include="MOD.Scripts.Core.Audio\MODBGMInfo.cs" />
<Compile Include="MOD.Scripts.Core.Config\MODConfig.cs" />
<Compile Include="MOD.Scripts.Core.Config\MODConfigManager.cs" />
<Compile Include="MOD.Scripts.Core.Movie\AVProMovieRenderer.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Assets.Scripts.Core.Audio/AudioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,10 @@ public void MODPlayVoiceLS(string filename, int channel, float volume, int chara
});
}
}

public Dictionary<int, AudioInfo> GetCurrrentBGM()
{
return currentAudio[AudioType.BGM];
}
}
}
9 changes: 8 additions & 1 deletion Assets.Scripts.Core.Buriko/BurikoScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3103,7 +3103,14 @@ public BurikoVariable OperationMODAddArtset()
public BurikoVariable OperationMODAddBGMset()
{
SetOperationType("MODAddBGMset");
MODAudioSet.Instance.AddBGMSet(ReadPathCascadeFromArgs());
PathCascadeList cascadeList = ReadPathCascadeFromArgs();

MODAudioSet.Instance.AddBGMSet(cascadeList);
foreach (string path in cascadeList.paths)
{
MODBGMInfo.LoadFromJSON(path);
}

return BurikoVariable.Null;
}

Expand Down
27 changes: 20 additions & 7 deletions Assets.Scripts.Core/GameSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public class GameSystem : MonoBehaviour
public readonly List<Wait> WaitList = new List<Wait>();

private MenuUIController menuUIController;
public MenuUIController MenuUIController() => menuUIController;

private HistoryWindow historyWindow;

Expand Down Expand Up @@ -205,6 +206,8 @@ public bool IsFullscreen
private set => _isFullscreen = value;
}

private bool hasBrokenWindowResize;

private float _configMenuFontSize = 0;
public float ConfigMenuFontSize
{
Expand Down Expand Up @@ -259,6 +262,7 @@ private void Initialize()
IGameState obj = curStateObj;
inputHandler = obj.InputHandler;
MessageBoxVisible = false;
hasBrokenWindowResize = MODUtility.HasBrokenWindowResize() && MODUtility.PatchWindowResizeFunction();
if (!PlayerPrefs.HasKey("width"))
{
PlayerPrefs.SetInt("width", 1280);
Expand All @@ -282,18 +286,18 @@ private void Initialize()

if (IsFullscreen)
{
Screen.SetResolution(fullscreenResolution.width, fullscreenResolution.height, fullscreen: true);
SetResolution(fullscreenResolution.width, fullscreenResolution.height, fullscreen: true);
}
else if (PlayerPrefs.HasKey("height") && PlayerPrefs.HasKey("width"))
{
int width = PlayerPrefs.GetInt("width");
int height = PlayerPrefs.GetInt("height");
Debug.Log("Requesting window size " + width + "x" + height + " based on config file");
Screen.SetResolution(width, height, fullscreen: false);
SetResolution(width, height, fullscreen: false);
}
if ((Screen.width < 640 || Screen.height < 480) && !IsFullscreen)
{
Screen.SetResolution(640, 480, fullscreen: false);
SetResolution(640, 480, fullscreen: false);
}
Debug.Log("Starting compile thread...");
CompileThread = new Thread(CompileScripts)
Expand All @@ -307,6 +311,15 @@ private void Initialize()
}
}

public void SetResolution(int width, int height, bool fullscreen)
{
Screen.SetResolution(width, height, fullscreen);
if (hasBrokenWindowResize)
{
MODUtility.X11ManualSetWindowSize(width, height);
}
}

public void StartScriptSystem()
{
Logger.Log("GameSystem: Starting ScriptInterpreter");
Expand Down Expand Up @@ -351,7 +364,7 @@ public void UpdateAspectRatio(float newratio)
if (!IsFullscreen)
{
int width = Mathf.RoundToInt((float)Screen.height * AspectRatio);
Screen.SetResolution(width, Screen.height, fullscreen: false);
SetResolution(width, Screen.height, fullscreen: false);
}
PlayerPrefs.SetInt("width", Mathf.RoundToInt(PlayerPrefs.GetInt("height") * AspectRatio));
MainUIController.UpdateBlackBars();
Expand Down Expand Up @@ -874,7 +887,7 @@ public IEnumerator FrameWaitForFullscreen(int width, int height, bool fullscreen
yield return new WaitForFixedUpdate();
IsFullscreen = fullscreen;
PlayerPrefs.SetInt("is_fullscreen", fullscreen ? 1 : 0);
Screen.SetResolution(width, height, fullscreen);
SetResolution(width, height, fullscreen);
while (Screen.width != width || Screen.height != height)
{
yield return null;
Expand All @@ -887,7 +900,7 @@ public void GoFullscreen()
IsFullscreen = true;
PlayerPrefs.SetInt("is_fullscreen", 1);
Resolution resolution = GetFullscreenResolution();
Screen.SetResolution(resolution.width, resolution.height, fullscreen: true);
SetResolution(resolution.width, resolution.height, fullscreen: true);
Debug.Log(resolution.width + " , " + resolution.height);
PlayerPrefs.SetInt("fullscreen_width", resolution.width);
PlayerPrefs.SetInt("fullscreen_height", resolution.height);
Expand All @@ -897,7 +910,7 @@ public void DeFullscreen(int width, int height)
{
IsFullscreen = false;
PlayerPrefs.SetInt("is_fullscreen", 0);
Screen.SetResolution(width, height, fullscreen: false);
SetResolution(width, height, fullscreen: false);
}

private void OnApplicationFocus(bool focusStatus)
Expand Down
118 changes: 118 additions & 0 deletions MOD.Scripts.Core.Audio/MODBGMInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using MOD.Scripts.UI;
using Assets.Scripts.Core;

namespace MOD.Scripts.Core
{
public class BGMInfo
{
/// <summary>
/// A comment to store misc info about the BGM (any errata, or changes made to the BGM)
/// </summary>
public string comment;
/// <summary>
/// The English/Japanese name of the song
/// </summary>
public string name;
public string source;
public string url;

public BGMInfo()
{
comment = "";
name = "";
source = "";
url = "";
}

public BGMInfo SetName(string name)
{
this.name = name;
return this;
}
}

public class BGMInfoDict
{
public Dictionary<string, BGMInfo> bgmList;

public BGMInfoDict()
{
bgmList = new Dictionary<string, BGMInfo>();
}
}

public class MODBGMInfo
{
/// <summary>
/// Dictionary of (filepath without extension relative to streamingassets) -> BGMInfo
/// </summary>
private static Dictionary<string, BGMInfo> bgmDictionary;
private static Dictionary<string, bool> loadedFolders;

static MODBGMInfo()
{
bgmDictionary = new Dictionary<string, BGMInfo>();
loadedFolders = new Dictionary<string, bool>();
}

public static BGMInfo GetBGMName(string streamingAssetsRelativePath)
{
string pathWithoutExtension = Path.Combine(Path.GetDirectoryName(streamingAssetsRelativePath), Path.GetFileNameWithoutExtension(streamingAssetsRelativePath));
if(bgmDictionary.TryGetValue(pathWithoutExtension, out BGMInfo info))
{
return info;
}
else
{
return new BGMInfo().SetName(GameSystem.Instance.ChooseJapaneseEnglish("不明 BGM", "Unknown BGM"));
}
}

// Load the bgm information from the bgmInfo.json in a given BGM Folder (located in the StreamingAssets folder)
public static void LoadFromJSON(string BGMFolder)
{
// Skip already loaded folders
if(loadedFolders.ContainsKey(BGMFolder))
{
return;
}
loadedFolders[BGMFolder] = true;

string path = Path.Combine(Application.streamingAssetsPath, Path.Combine(BGMFolder, "bgmInfo.json"));

if (!File.Exists(path))
{
Debug.Log($"MODBGMInfo(): No bgmInfo.json at [{path}] - BGM will just show as filenames");
return;
}

try
{
using (var reader = new JsonTextReader(new StreamReader(path)))
{
BGMInfoDict bgmInfoDict = JsonSerializer.Create(new JsonSerializerSettings()).Deserialize<BGMInfoDict>(reader);
foreach(KeyValuePair<string, BGMInfo> kvp in bgmInfoDict.bgmList)
{
// Allow missing comment in JSON
if(kvp.Value.comment == null)
{
kvp.Value.comment = "";
}

string relativePathWithoutExtension = Path.Combine(BGMFolder, kvp.Key);
bgmDictionary[relativePathWithoutExtension] = kvp.Value;
}
}
}
catch (System.Exception e)
{
Debug.LogError($"MODBGMInfo(): Failed to read bgm info file at [{path}]: {e.Message}");
MODToaster.Show("bgmInfo.json fail - check logs");
}
}
}
}
Loading

0 comments on commit b1a65de

Please sign in to comment.