From e370e1937c94d72da731a6b0fdeb512061013adf Mon Sep 17 00:00:00 2001 From: PopSlime Date: Wed, 23 Nov 2022 12:02:25 +0800 Subject: [PATCH] Code cleanup. --- .../Cryville/Common/Buffers/TargetString.cs | 2 +- Assets/Cryville/Common/IdentifierManager.cs | 6 +++--- Assets/Cryville/Common/Logger.cs | 3 ++- Assets/Cryville/Common/Network/HttpClient.cs | 2 +- Assets/Cryville/Common/Network/TlsClient.cs | 2 +- Assets/Cryville/Crtr/Chart.cs | 5 ++++- .../Cryville/Crtr/Config/InputConfigPanel.cs | 2 +- .../Cryville/Crtr/Event/ContainerHandler.cs | 3 ++- .../Bestdori/BestdoriChartConverter.cs | 5 +++-- .../Extensions/Malody/MalodyChartConverter.cs | 6 +++--- Assets/Cryville/Crtr/Motion.cs | 19 ++++++++++--------- Assets/Cryville/Crtr/PdtEvaluator.cs | 3 ++- Assets/Cryville/Crtr/SettingsPanel.cs | 2 +- Assets/Cryville/Crtr/StampedEvent.cs | 6 +++--- Assets/GlobalSuppressions.cs | 4 ++++ 15 files changed, 41 insertions(+), 29 deletions(-) diff --git a/Assets/Cryville/Common/Buffers/TargetString.cs b/Assets/Cryville/Common/Buffers/TargetString.cs index 2e3e48a..78690f9 100644 --- a/Assets/Cryville/Common/Buffers/TargetString.cs +++ b/Assets/Cryville/Common/Buffers/TargetString.cs @@ -84,7 +84,7 @@ namespace Cryville.Common.Buffers { } class Enumerator : IEnumerator { - TargetString _self; + readonly TargetString _self; int _index = -1; public Enumerator(TargetString self) { _self = self; } diff --git a/Assets/Cryville/Common/IdentifierManager.cs b/Assets/Cryville/Common/IdentifierManager.cs index 74e719b..dd9448b 100644 --- a/Assets/Cryville/Common/IdentifierManager.cs +++ b/Assets/Cryville/Common/IdentifierManager.cs @@ -10,10 +10,10 @@ namespace Cryville.Common { /// public static IdentifierManager SharedInstance = new IdentifierManager(); - Dictionary _idents = new Dictionary(); - List _ids = new List(); + readonly Dictionary _idents = new Dictionary(); + readonly List _ids = new List(); - object _syncRoot = new object(); + readonly object _syncRoot = new object(); /// /// Creates an instance of the class. diff --git a/Assets/Cryville/Common/Logger.cs b/Assets/Cryville/Common/Logger.cs index ac68d9f..560f54c 100644 --- a/Assets/Cryville/Common/Logger.cs +++ b/Assets/Cryville/Common/Logger.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; namespace Cryville.Common { @@ -40,7 +41,7 @@ namespace Cryville.Common { public static void Create(string key, Logger logger) { Instances[key] = logger; if (logPath != null) { - Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString() + "-" + key + ".log") { + Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture) + "-" + key + ".log") { AutoFlush = true }; } diff --git a/Assets/Cryville/Common/Network/HttpClient.cs b/Assets/Cryville/Common/Network/HttpClient.cs index dc18611..d60170a 100644 --- a/Assets/Cryville/Common/Network/HttpClient.cs +++ b/Assets/Cryville/Common/Network/HttpClient.cs @@ -77,7 +77,7 @@ namespace Cryville.Common.Network { encoding = Encoding.UTF8; payload = encoding.GetBytes(body); headers.Add("Content-Encoding", encoding.EncodingName); - headers.Add("Content-Length", payload.Length.ToString()); + headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture)); } string request_line = string.Format( "{0} {1} {2}\r\n", method, uri, Version diff --git a/Assets/Cryville/Common/Network/TlsClient.cs b/Assets/Cryville/Common/Network/TlsClient.cs index 90743bf..7199fec 100644 --- a/Assets/Cryville/Common/Network/TlsClient.cs +++ b/Assets/Cryville/Common/Network/TlsClient.cs @@ -28,7 +28,7 @@ namespace Cryville.Common.Network { } private class InternalTlsClient : DefaultTlsClient { - string _host; + readonly string _host; public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) { _host = host; diff --git a/Assets/Cryville/Crtr/Chart.cs b/Assets/Cryville/Crtr/Chart.cs index 4f316cf..aabf40d 100644 --- a/Assets/Cryville/Crtr/Chart.cs +++ b/Assets/Cryville/Crtr/Chart.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; using System.Linq; using System.Text.RegularExpressions; @@ -303,7 +304,7 @@ namespace Cryville.Crtr { var node = RelativeNode; result += "#" + node.Id; if (node.Time != null) result += "@" + node.Time.ToString(); - if (node.Transition != null) result = "^" + node.Transition.ToString(); + if (node.Transition != null) result = "^" + ((byte)node.Transition).ToString(CultureInfo.InvariantCulture); if (node.Rate != null) result += "*" + node.Rate.ToString(); if (node.Value != null) result += ":" + node.Value.ToString(); } @@ -391,10 +392,12 @@ namespace Cryville.Crtr { public class Judge : ChartEvent { [JsonIgnore] public Identifier Id; +#pragma warning disable IDE1006 public string name { get { return Id.ToString(); } set { Id = new Identifier(value); } } +#pragma warning restore IDE1006 public override int Priority { get { return 0; } diff --git a/Assets/Cryville/Crtr/Config/InputConfigPanel.cs b/Assets/Cryville/Crtr/Config/InputConfigPanel.cs index c94f1fa..2c80578 100644 --- a/Assets/Cryville/Crtr/Config/InputConfigPanel.cs +++ b/Assets/Cryville/Crtr/Config/InputConfigPanel.cs @@ -25,7 +25,7 @@ namespace Cryville.Crtr.Config { GameObject m_prefabInputConfigEntry; public InputProxy proxy; - Dictionary _entries = new Dictionary(); + readonly Dictionary _entries = new Dictionary(); string _sel; public void OpenDialog(string entry) { diff --git a/Assets/Cryville/Crtr/Event/ContainerHandler.cs b/Assets/Cryville/Crtr/Event/ContainerHandler.cs index c238603..389da17 100644 --- a/Assets/Cryville/Crtr/Event/ContainerHandler.cs +++ b/Assets/Cryville/Crtr/Event/ContainerHandler.cs @@ -1,6 +1,7 @@ using Cryville.Crtr.Components; using System; using System.Collections.Generic; +using System.Globalization; using UnityEngine; namespace Cryville.Crtr.Event { @@ -75,7 +76,7 @@ namespace Cryville.Crtr.Event { get; } public virtual void PreInit() { - gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString()).transform; + gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform; if (cs.Parent != null) gogroup.SetParent(cs.Parent.Handler.gogroup, false); a_head = new GameObject("::head").transform; diff --git a/Assets/Cryville/Crtr/Extensions/Bestdori/BestdoriChartConverter.cs b/Assets/Cryville/Crtr/Extensions/Bestdori/BestdoriChartConverter.cs index 6b574ba..d1005c1 100644 --- a/Assets/Cryville/Crtr/Extensions/Bestdori/BestdoriChartConverter.cs +++ b/Assets/Cryville/Crtr/Extensions/Bestdori/BestdoriChartConverter.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; namespace Cryville.Crtr.Extensions.Bestdori { @@ -62,7 +63,7 @@ namespace Cryville.Crtr.Extensions.Bestdori { group.notes.Add(new Chart.Note { time = ToBeatTime(tev.beat), judges = new List { new Chart.Judge { name = tev.flick ? "single_flick" : "single" } }, - motions = new List { new Chart.Motion { motion = "track:" + tev.lane.ToString() } }, + motions = new List { new Chart.Motion { motion = "track:" + tev.lane.ToString(CultureInfo.InvariantCulture) } }, }); } else if (ev is BestdoriChartEvent.Long) { @@ -75,7 +76,7 @@ namespace Cryville.Crtr.Extensions.Bestdori { }; for (int i = 0; i < tev.connections.Count; i++) { BestdoriChartEvent.Connection c = tev.connections[i]; - note.motions.Add(new Chart.Motion { motion = "track:" + c.lane.ToString() }); + note.motions.Add(new Chart.Motion { motion = "track:" + c.lane.ToString(CultureInfo.InvariantCulture) }); if (i == 0) note.judges.Add(new Chart.Judge { name = "single" }); else if (i == tev.connections.Count - 1) diff --git a/Assets/Cryville/Crtr/Extensions/Malody/MalodyChartConverter.cs b/Assets/Cryville/Crtr/Extensions/Malody/MalodyChartConverter.cs index 094d99e..9ace362 100644 --- a/Assets/Cryville/Crtr/Extensions/Malody/MalodyChartConverter.cs +++ b/Assets/Cryville/Crtr/Extensions/Malody/MalodyChartConverter.cs @@ -91,14 +91,14 @@ namespace Cryville.Crtr.Extensions.Malody { }); chart.motions.Add(new Chart.Motion { time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]), - motion = "svm:" + (tev.bpm / baseBpm).ToString() + motion = "svm:" + (tev.bpm / baseBpm.Value).ToString(CultureInfo.InvariantCulture) }); } else if (ev is MalodyChart.Effect) { var tev = (MalodyChart.Effect)ev; if (tev.scroll != null) group.motions.Add(new Chart.Motion { time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]), - motion = "svm:" + tev.scroll.ToString() + motion = "svm:" + tev.scroll.Value.ToString(CultureInfo.InvariantCulture) }); } else if (ev is MalodyChart.Note) { @@ -120,7 +120,7 @@ namespace Cryville.Crtr.Extensions.Malody { var rn = new Chart.Note() { time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]), motions = new List { - new Chart.Motion() { motion = "track:" + tev.column.ToString() } + new Chart.Motion() { motion = "track:" + tev.column.ToString(CultureInfo.InvariantCulture) } }, }; if (tev.endbeat != null) { diff --git a/Assets/Cryville/Crtr/Motion.cs b/Assets/Cryville/Crtr/Motion.cs index 78457e7..5e6dd27 100644 --- a/Assets/Cryville/Crtr/Motion.cs +++ b/Assets/Cryville/Crtr/Motion.cs @@ -2,6 +2,7 @@ using Cryville.Common; using Cryville.Common.Pdt; using System; using System.Collections.Generic; +using System.Globalization; using System.Text.RegularExpressions; using UnityEngine; @@ -433,7 +434,7 @@ namespace Cryville.Crtr { } public override string ToString() { - return Value.ToString(); + return Value.ToString(CultureInfo.InvariantCulture); } public override float[] ToArray() { @@ -493,7 +494,7 @@ namespace Cryville.Crtr { } public override string ToString() { - return Value.ToString(); + return Value.ToString(CultureInfo.InvariantCulture); } public override float[] ToArray() { @@ -553,7 +554,7 @@ namespace Cryville.Crtr { } public override string ToString() { - return Value.ToString(); + return Value.ToString(CultureInfo.InvariantCulture); } public override float[] ToArray() { @@ -648,8 +649,8 @@ namespace Cryville.Crtr { public static string ToString(float? w, float? h) { List list = new List(); - if (w != null) list.Add(w.ToString() + "w"); - if (h != null) list.Add(h.ToString() + "h"); + if (w != null) list.Add(w.Value.ToString(CultureInfo.InvariantCulture) + "w"); + if (h != null) list.Add(h.Value.ToString(CultureInfo.InvariantCulture) + "h"); return string.Join("+", list.ToArray()); } @@ -744,9 +745,9 @@ namespace Cryville.Crtr { public override string ToString() { return string.Format("{0},{1},{2}", - x != null ? x.ToString() : "", - y != null ? y.ToString() : "", - z != null ? z.ToString() : "" + x != null ? x.Value.ToString(CultureInfo.InvariantCulture) : "", + y != null ? y.Value.ToString(CultureInfo.InvariantCulture) : "", + z != null ? z.Value.ToString(CultureInfo.InvariantCulture) : "" ); } @@ -915,7 +916,7 @@ namespace Cryville.Crtr { } public override string ToString() { - return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh) + "," + (z != null ? z.ToString() : ""); + return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh) + "," + (z != null ? z.Value.ToString(CultureInfo.InvariantCulture) : ""); } public override float[] ToArray() { diff --git a/Assets/Cryville/Crtr/PdtEvaluator.cs b/Assets/Cryville/Crtr/PdtEvaluator.cs index df4512d..0a05161 100644 --- a/Assets/Cryville/Crtr/PdtEvaluator.cs +++ b/Assets/Cryville/Crtr/PdtEvaluator.cs @@ -3,6 +3,7 @@ using Cryville.Common.Pdt; using Cryville.Crtr.Event; using System; using System.Collections.Generic; +using System.Globalization; using UnityEngine; namespace Cryville.Crtr { @@ -298,7 +299,7 @@ namespace Cryville.Crtr { ret.SetArraySuffix(PdtInternalType.String, fc); int o = 0; for (int i = f; i <= t; i++) { - var s = pf + i.ToString(); + var s = pf + i.ToString(CultureInfo.InvariantCulture); ret.SetString(s, o); o += sizeof(int) + s.Length * sizeof(char); } diff --git a/Assets/Cryville/Crtr/SettingsPanel.cs b/Assets/Cryville/Crtr/SettingsPanel.cs index 396ed2f..6d86d2d 100644 --- a/Assets/Cryville/Crtr/SettingsPanel.cs +++ b/Assets/Cryville/Crtr/SettingsPanel.cs @@ -36,7 +36,7 @@ namespace Cryville.Crtr { } } - Dictionary> _categories = new Dictionary>(); + readonly Dictionary> _categories = new Dictionary>(); public void LoadProperties() { _categories.Clear(); _invalidated = false; diff --git a/Assets/Cryville/Crtr/StampedEvent.cs b/Assets/Cryville/Crtr/StampedEvent.cs index d3ca61d..e8bfccd 100644 --- a/Assets/Cryville/Crtr/StampedEvent.cs +++ b/Assets/Cryville/Crtr/StampedEvent.cs @@ -43,7 +43,7 @@ namespace Cryville.Crtr { public override int Priority { get { return StartEvent == null ? 4 : 6; } } - protected override int cmpExtra(StampedEvent other) { + protected override int CompareExtra(StampedEvent other) { return Equals(StartEvent, other) ? 1 : 0; } } @@ -75,12 +75,12 @@ namespace Cryville.Crtr { if (u != 0) return u; u = this.Duration.CompareTo(other.Duration); if (u != 0) return u; - u = cmpExtra(other); + u = CompareExtra(other); if (u != 0) return u; return GetHashCode().CompareTo(other.GetHashCode()); } - protected virtual int cmpExtra(StampedEvent other) { + protected virtual int CompareExtra(StampedEvent other) { return 0; } } diff --git a/Assets/GlobalSuppressions.cs b/Assets/GlobalSuppressions.cs index 5c351e6..6b15d08 100644 --- a/Assets/GlobalSuppressions.cs +++ b/Assets/GlobalSuppressions.cs @@ -9,6 +9,7 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Style", "IDE0020")] [assembly: SuppressMessage("Style", "IDE0038")] [assembly: SuppressMessage("Style", "IDE0018")] +[assembly: SuppressMessage("Style", "IDE0019")] // Null operators not supported [assembly: SuppressMessage("Style", "IDE0016")] @@ -40,3 +41,6 @@ using System.Diagnostics.CodeAnalysis; // Local function not supported [assembly: SuppressMessage("Style", "IDE0039")] + +// Readonly struct not supported +[assembly: SuppressMessage("Style", "IDE0250")]