Code cleanup.

This commit is contained in:
2022-11-23 12:02:25 +08:00
parent d9f6dd33d4
commit e370e1937c
15 changed files with 41 additions and 29 deletions

View File

@@ -84,7 +84,7 @@ namespace Cryville.Common.Buffers {
} }
class Enumerator : IEnumerator<char> { class Enumerator : IEnumerator<char> {
TargetString _self; readonly TargetString _self;
int _index = -1; int _index = -1;
public Enumerator(TargetString self) { _self = self; } public Enumerator(TargetString self) { _self = self; }

View File

@@ -10,10 +10,10 @@ namespace Cryville.Common {
/// </summary> /// </summary>
public static IdentifierManager SharedInstance = new IdentifierManager(); public static IdentifierManager SharedInstance = new IdentifierManager();
Dictionary<object, int> _idents = new Dictionary<object, int>(); readonly Dictionary<object, int> _idents = new Dictionary<object, int>();
List<object> _ids = new List<object>(); readonly List<object> _ids = new List<object>();
object _syncRoot = new object(); readonly object _syncRoot = new object();
/// <summary> /// <summary>
/// Creates an instance of the <see cref="IdentifierManager" /> class. /// Creates an instance of the <see cref="IdentifierManager" /> class.

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
namespace Cryville.Common { namespace Cryville.Common {
@@ -40,7 +41,7 @@ namespace Cryville.Common {
public static void Create(string key, Logger logger) { public static void Create(string key, Logger logger) {
Instances[key] = logger; Instances[key] = logger;
if (logPath != null) { 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 AutoFlush = true
}; };
} }

View File

@@ -77,7 +77,7 @@ namespace Cryville.Common.Network {
encoding = Encoding.UTF8; encoding = Encoding.UTF8;
payload = encoding.GetBytes(body); payload = encoding.GetBytes(body);
headers.Add("Content-Encoding", encoding.EncodingName); 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( string request_line = string.Format(
"{0} {1} {2}\r\n", method, uri, Version "{0} {1} {2}\r\n", method, uri, Version

View File

@@ -28,7 +28,7 @@ namespace Cryville.Common.Network {
} }
private class InternalTlsClient : DefaultTlsClient { private class InternalTlsClient : DefaultTlsClient {
string _host; readonly string _host;
public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) { public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) {
_host = host; _host = host;

View File

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@@ -303,7 +304,7 @@ namespace Cryville.Crtr {
var node = RelativeNode; var node = RelativeNode;
result += "#" + node.Id; result += "#" + node.Id;
if (node.Time != null) result += "@" + node.Time.ToString(); 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.Rate != null) result += "*" + node.Rate.ToString();
if (node.Value != null) result += ":" + node.Value.ToString(); if (node.Value != null) result += ":" + node.Value.ToString();
} }
@@ -391,10 +392,12 @@ namespace Cryville.Crtr {
public class Judge : ChartEvent { public class Judge : ChartEvent {
[JsonIgnore] [JsonIgnore]
public Identifier Id; public Identifier Id;
#pragma warning disable IDE1006
public string name { public string name {
get { return Id.ToString(); } get { return Id.ToString(); }
set { Id = new Identifier(value); } set { Id = new Identifier(value); }
} }
#pragma warning restore IDE1006
public override int Priority { public override int Priority {
get { return 0; } get { return 0; }

View File

@@ -25,7 +25,7 @@ namespace Cryville.Crtr.Config {
GameObject m_prefabInputConfigEntry; GameObject m_prefabInputConfigEntry;
public InputProxy proxy; public InputProxy proxy;
Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>(); readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
string _sel; string _sel;
public void OpenDialog(string entry) { public void OpenDialog(string entry) {

View File

@@ -1,6 +1,7 @@
using Cryville.Crtr.Components; using Cryville.Crtr.Components;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Event { namespace Cryville.Crtr.Event {
@@ -75,7 +76,7 @@ namespace Cryville.Crtr.Event {
get; get;
} }
public virtual void PreInit() { 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) if (cs.Parent != null)
gogroup.SetParent(cs.Parent.Handler.gogroup, false); gogroup.SetParent(cs.Parent.Handler.gogroup, false);
a_head = new GameObject("::head").transform; a_head = new GameObject("::head").transform;

View File

@@ -6,6 +6,7 @@ using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
namespace Cryville.Crtr.Extensions.Bestdori { namespace Cryville.Crtr.Extensions.Bestdori {
@@ -62,7 +63,7 @@ namespace Cryville.Crtr.Extensions.Bestdori {
group.notes.Add(new Chart.Note { group.notes.Add(new Chart.Note {
time = ToBeatTime(tev.beat), time = ToBeatTime(tev.beat),
judges = new List<Chart.Judge> { new Chart.Judge { name = tev.flick ? "single_flick" : "single" } }, judges = new List<Chart.Judge> { new Chart.Judge { name = tev.flick ? "single_flick" : "single" } },
motions = new List<Chart.Motion> { new Chart.Motion { motion = "track:" + tev.lane.ToString() } }, motions = new List<Chart.Motion> { new Chart.Motion { motion = "track:" + tev.lane.ToString(CultureInfo.InvariantCulture) } },
}); });
} }
else if (ev is BestdoriChartEvent.Long) { else if (ev is BestdoriChartEvent.Long) {
@@ -75,7 +76,7 @@ namespace Cryville.Crtr.Extensions.Bestdori {
}; };
for (int i = 0; i < tev.connections.Count; i++) { for (int i = 0; i < tev.connections.Count; i++) {
BestdoriChartEvent.Connection c = tev.connections[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) if (i == 0)
note.judges.Add(new Chart.Judge { name = "single" }); note.judges.Add(new Chart.Judge { name = "single" });
else if (i == tev.connections.Count - 1) else if (i == tev.connections.Count - 1)

View File

@@ -91,14 +91,14 @@ namespace Cryville.Crtr.Extensions.Malody {
}); });
chart.motions.Add(new Chart.Motion { chart.motions.Add(new Chart.Motion {
time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]), 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) { else if (ev is MalodyChart.Effect) {
var tev = (MalodyChart.Effect)ev; var tev = (MalodyChart.Effect)ev;
if (tev.scroll != null) group.motions.Add(new Chart.Motion { if (tev.scroll != null) group.motions.Add(new Chart.Motion {
time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]), 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) { else if (ev is MalodyChart.Note) {
@@ -120,7 +120,7 @@ namespace Cryville.Crtr.Extensions.Malody {
var rn = new Chart.Note() { var rn = new Chart.Note() {
time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]), time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]),
motions = new List<Chart.Motion> { motions = new List<Chart.Motion> {
new Chart.Motion() { motion = "track:" + tev.column.ToString() } new Chart.Motion() { motion = "track:" + tev.column.ToString(CultureInfo.InvariantCulture) }
}, },
}; };
if (tev.endbeat != null) { if (tev.endbeat != null) {

View File

@@ -2,6 +2,7 @@ using Cryville.Common;
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
@@ -433,7 +434,7 @@ namespace Cryville.Crtr {
} }
public override string ToString() { public override string ToString() {
return Value.ToString(); return Value.ToString(CultureInfo.InvariantCulture);
} }
public override float[] ToArray() { public override float[] ToArray() {
@@ -493,7 +494,7 @@ namespace Cryville.Crtr {
} }
public override string ToString() { public override string ToString() {
return Value.ToString(); return Value.ToString(CultureInfo.InvariantCulture);
} }
public override float[] ToArray() { public override float[] ToArray() {
@@ -553,7 +554,7 @@ namespace Cryville.Crtr {
} }
public override string ToString() { public override string ToString() {
return Value.ToString(); return Value.ToString(CultureInfo.InvariantCulture);
} }
public override float[] ToArray() { public override float[] ToArray() {
@@ -648,8 +649,8 @@ namespace Cryville.Crtr {
public static string ToString(float? w, float? h) { public static string ToString(float? w, float? h) {
List<string> list = new List<string>(); List<string> list = new List<string>();
if (w != null) list.Add(w.ToString() + "w"); if (w != null) list.Add(w.Value.ToString(CultureInfo.InvariantCulture) + "w");
if (h != null) list.Add(h.ToString() + "h"); if (h != null) list.Add(h.Value.ToString(CultureInfo.InvariantCulture) + "h");
return string.Join("+", list.ToArray()); return string.Join("+", list.ToArray());
} }
@@ -744,9 +745,9 @@ namespace Cryville.Crtr {
public override string ToString() { public override string ToString() {
return string.Format("{0},{1},{2}", return string.Format("{0},{1},{2}",
x != null ? x.ToString() : "", x != null ? x.Value.ToString(CultureInfo.InvariantCulture) : "",
y != null ? y.ToString() : "", y != null ? y.Value.ToString(CultureInfo.InvariantCulture) : "",
z != null ? z.ToString() : "" z != null ? z.Value.ToString(CultureInfo.InvariantCulture) : ""
); );
} }
@@ -915,7 +916,7 @@ namespace Cryville.Crtr {
} }
public override string ToString() { 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() { public override float[] ToArray() {

View File

@@ -3,6 +3,7 @@ using Cryville.Common.Pdt;
using Cryville.Crtr.Event; using Cryville.Crtr.Event;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
@@ -298,7 +299,7 @@ namespace Cryville.Crtr {
ret.SetArraySuffix(PdtInternalType.String, fc); ret.SetArraySuffix(PdtInternalType.String, fc);
int o = 0; int o = 0;
for (int i = f; i <= t; i++) { for (int i = f; i <= t; i++) {
var s = pf + i.ToString(); var s = pf + i.ToString(CultureInfo.InvariantCulture);
ret.SetString(s, o); ret.SetString(s, o);
o += sizeof(int) + s.Length * sizeof(char); o += sizeof(int) + s.Length * sizeof(char);
} }

View File

@@ -36,7 +36,7 @@ namespace Cryville.Crtr {
} }
} }
Dictionary<string, List<PropertyInfo>> _categories = new Dictionary<string, List<PropertyInfo>>(); readonly Dictionary<string, List<PropertyInfo>> _categories = new Dictionary<string, List<PropertyInfo>>();
public void LoadProperties() { public void LoadProperties() {
_categories.Clear(); _categories.Clear();
_invalidated = false; _invalidated = false;

View File

@@ -43,7 +43,7 @@ namespace Cryville.Crtr {
public override int Priority { public override int Priority {
get { return StartEvent == null ? 4 : 6; } get { return StartEvent == null ? 4 : 6; }
} }
protected override int cmpExtra(StampedEvent other) { protected override int CompareExtra(StampedEvent other) {
return Equals(StartEvent, other) ? 1 : 0; return Equals(StartEvent, other) ? 1 : 0;
} }
} }
@@ -75,12 +75,12 @@ namespace Cryville.Crtr {
if (u != 0) return u; if (u != 0) return u;
u = this.Duration.CompareTo(other.Duration); u = this.Duration.CompareTo(other.Duration);
if (u != 0) return u; if (u != 0) return u;
u = cmpExtra(other); u = CompareExtra(other);
if (u != 0) return u; if (u != 0) return u;
return GetHashCode().CompareTo(other.GetHashCode()); return GetHashCode().CompareTo(other.GetHashCode());
} }
protected virtual int cmpExtra(StampedEvent other) { protected virtual int CompareExtra(StampedEvent other) {
return 0; return 0;
} }
} }

View File

@@ -9,6 +9,7 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0020")] [assembly: SuppressMessage("Style", "IDE0020")]
[assembly: SuppressMessage("Style", "IDE0038")] [assembly: SuppressMessage("Style", "IDE0038")]
[assembly: SuppressMessage("Style", "IDE0018")] [assembly: SuppressMessage("Style", "IDE0018")]
[assembly: SuppressMessage("Style", "IDE0019")]
// Null operators not supported // Null operators not supported
[assembly: SuppressMessage("Style", "IDE0016")] [assembly: SuppressMessage("Style", "IDE0016")]
@@ -40,3 +41,6 @@ using System.Diagnostics.CodeAnalysis;
// Local function not supported // Local function not supported
[assembly: SuppressMessage("Style", "IDE0039")] [assembly: SuppressMessage("Style", "IDE0039")]
// Readonly struct not supported
[assembly: SuppressMessage("Style", "IDE0250")]