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> {
TargetString _self;
readonly TargetString _self;
int _index = -1;
public Enumerator(TargetString self) { _self = self; }

View File

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

View File

@@ -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
};
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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; }

View File

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

View File

@@ -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;

View File

@@ -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<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) {
@@ -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)

View File

@@ -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<Chart.Motion> {
new Chart.Motion() { motion = "track:" + tev.column.ToString() }
new Chart.Motion() { motion = "track:" + tev.column.ToString(CultureInfo.InvariantCulture) }
},
};
if (tev.endbeat != null) {

View File

@@ -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<string> list = new List<string>();
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() {

View File

@@ -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);
}

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() {
_categories.Clear();
_invalidated = false;

View File

@@ -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;
}
}

View File

@@ -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")]