Code cleanup.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Cryville.Crtr.Config.UI;
|
||||
using Cryville.Crtr.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
@@ -76,7 +77,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
#else
|
||||
Application.LoadLevelAdditive("Play");
|
||||
#endif
|
||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||
Master.Instance.HideMenu();
|
||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
|
||||
#endif
|
||||
@@ -87,7 +88,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
}
|
||||
|
||||
void SetDataSettings(int id, ChartDetail detail) {
|
||||
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
||||
Settings.Default.LoadRuleset = Path.Combine(detail.Meta.ruleset, ".umgr");
|
||||
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
||||
Settings.Default.LoadChart = m_mainBrowser.ResourceManager.GetItemUri(id).LocalPath;
|
||||
}
|
||||
|
@@ -92,8 +92,6 @@ namespace Cryville.Crtr {
|
||||
Popup.CreateException(ex);
|
||||
ReturnToMenu();
|
||||
}
|
||||
|
||||
// Camera.main.RenderToCubemap();
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
@@ -300,16 +298,15 @@ namespace Cryville.Crtr {
|
||||
#region Triggers
|
||||
private void ReturnToMenu() {
|
||||
#if UNITY_EDITOR
|
||||
Invoke(nameof(_returnToMenu), 4);
|
||||
Invoke(nameof(ReturnToMenuImpl), 4);
|
||||
#else
|
||||
_returnToMenu();
|
||||
ReturnToMenuImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
private void _returnToMenu() {
|
||||
GameObject.Find("Master").GetComponent<Master>().ShowMenu();
|
||||
GameObject.Destroy(gameObject);
|
||||
private void ReturnToMenuImpl() {
|
||||
Master.Instance.ShowMenu();
|
||||
Destroy(gameObject);
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
SceneManager.UnloadSceneAsync("Play");
|
||||
#elif UNITY_5_3_OR_NEWER
|
||||
@@ -319,7 +316,6 @@ namespace Cryville.Crtr {
|
||||
DiscordController.Instance.SetIdle();
|
||||
#endif
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
bool logEnabled = true;
|
||||
public void ToggleLogs() {
|
||||
@@ -401,14 +397,14 @@ namespace Cryville.Crtr {
|
||||
|
||||
FileInfo chartFile = new FileInfo(Settings.Default.LoadChart);
|
||||
|
||||
FileInfo rulesetFile = new FileInfo(
|
||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||
);
|
||||
FileInfo rulesetFile = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "rulesets", Settings.Default.LoadRuleset
|
||||
));
|
||||
if (!rulesetFile.Exists) throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||
|
||||
FileInfo rulesetConfigFile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
FileInfo rulesetConfigFile = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
||||
));
|
||||
if (!rulesetConfigFile.Exists) throw new FileNotFoundException("Ruleset config not found\nPlease open the config to generate");
|
||||
using (StreamReader cfgreader = new StreamReader(rulesetConfigFile.FullName, Encoding.UTF8)) {
|
||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
@@ -418,9 +414,9 @@ namespace Cryville.Crtr {
|
||||
sv = _rscfg.generic.ScrollVelocity;
|
||||
soundOffset += _rscfg.generic.SoundOffset;
|
||||
|
||||
FileInfo skinFile = new FileInfo(
|
||||
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
|
||||
);
|
||||
FileInfo skinFile = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "skins", rulesetFile.Directory.Name, _rscfg.generic.Skin, ".umgs"
|
||||
));
|
||||
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
|
||||
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
|
||||
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
|
@@ -31,9 +31,9 @@ namespace Cryville.Crtr.Config.UI {
|
||||
void OnEnable() {
|
||||
try {
|
||||
PdtEvaluator.Instance.Reset();
|
||||
FileInfo file = new FileInfo(
|
||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||
);
|
||||
FileInfo file = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "rulesets", Settings.Default.LoadRuleset
|
||||
));
|
||||
if (!file.Exists) {
|
||||
throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||
}
|
||||
@@ -45,9 +45,9 @@ namespace Cryville.Crtr.Config.UI {
|
||||
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
}
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
FileInfo cfgfile = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
||||
));
|
||||
if (!cfgfile.Exists) {
|
||||
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
|
||||
_rscfg = new RulesetConfig();
|
||||
@@ -90,9 +90,9 @@ namespace Cryville.Crtr.Config.UI {
|
||||
_loaded = false;
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
FileInfo cfgfile = new FileInfo(Path.Combine(
|
||||
Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
||||
));
|
||||
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ namespace Cryville.Crtr.Event {
|
||||
else if (ev.Unstamped == null) { }
|
||||
else if (ev.Unstamped is Chart.Sound) {
|
||||
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
||||
var dir = new DirectoryInfo(Game.GameDataPath + "/songs/" + tev.id);
|
||||
var dir = new DirectoryInfo(Path.Combine(Game.GameDataPath, "songs", tev.id));
|
||||
var files = dir.GetFiles();
|
||||
var source = new LibavFileAudioSource(files[0].FullName);
|
||||
source.SelectStream();
|
||||
|
@@ -115,9 +115,9 @@ namespace Cryville.Crtr {
|
||||
InputManager = new InputManager();
|
||||
|
||||
#if UNITY_EDITOR_WIN
|
||||
ffmpeg.RootPath = Application.dataPath + "/Plugins/Windows";
|
||||
ffmpeg.RootPath = Path.Combine(Application.dataPath, "Plugins", "Windows");
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
ffmpeg.RootPath = Application.dataPath + "/Plugins/x86_64";
|
||||
ffmpeg.RootPath = Path.Combine(Application.dataPath, "Plugins", "x86_64");
|
||||
#elif UNITY_ANDROID
|
||||
ffmpeg.RootPath = "";
|
||||
#else
|
||||
@@ -164,7 +164,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
var dir = new DirectoryInfo(Settings.Default.GameDataPath + "/charts");
|
||||
var dir = new DirectoryInfo(Path.Combine(Settings.Default.GameDataPath, "charts"));
|
||||
if (!dir.Exists || Settings.Default.LastRunVersion != Application.version) {
|
||||
Directory.CreateDirectory(dir.FullName);
|
||||
var defaultData = Resources.Load<TextAsset>("default");
|
||||
|
@@ -23,7 +23,7 @@ namespace Cryville.Crtr.Ruleset {
|
||||
public PdtRuleset Root { get; private set; }
|
||||
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
using (StreamReader pdtreader = new StreamReader(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
Root = (PdtRuleset)new RulesetInterpreter(src, null).Interpret(typeof(PdtRuleset));
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ namespace Cryville.Crtr.Ruleset {
|
||||
public PdtVirtualPlayerStrategy Root { get; private set; }
|
||||
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
using (StreamReader pdtreader = new StreamReader(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
Root = (PdtVirtualPlayerStrategy)new RulesetInterpreter(src, null).Interpret(typeof(PdtVirtualPlayerStrategy));
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ namespace Cryville.Crtr.Skin {
|
||||
public PdtSkin Root { get; private set; }
|
||||
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
using (StreamReader pdtreader = new StreamReader(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
var interpreter = new SkinInterpreter(src, null);
|
||||
var format = interpreter.GetFormatVersion();
|
||||
|
@@ -1,12 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.UI {
|
||||
internal class Master : MonoBehaviour {
|
||||
static Master s_instance;
|
||||
public static Master Instance { get { return s_instance; } }
|
||||
|
||||
#pragma warning disable IDE0044
|
||||
[SerializeField]
|
||||
private GameObject m_menu;
|
||||
#pragma warning restore IDE0044
|
||||
|
||||
void Awake() {
|
||||
if (s_instance != null) {
|
||||
Destroy(gameObject);
|
||||
throw new InvalidOperationException("Attempted to initialize a singleton twice.");
|
||||
}
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
internal void ShowMenu() { m_menu.SetActive(true); }
|
||||
internal void HideMenu() { m_menu.SetActive(false); }
|
||||
|
||||
|
Reference in New Issue
Block a user