diff --git a/Assets/Cryville/Common/AsyncDelivery.cs b/Assets/Cryville/Common/AsyncDelivery.cs
index 8663745..4772a20 100644
--- a/Assets/Cryville/Common/AsyncDelivery.cs
+++ b/Assets/Cryville/Common/AsyncDelivery.cs
@@ -20,13 +20,13 @@ namespace Cryville.Common {
/// Whether the task has succeeded.
/// The result.
public void Deliver(bool succeeded, T result) {
- if (Destination != null) Destination(succeeded, result);
+ Destination?.Invoke(succeeded, result);
}
///
/// Cancels the task.
///
public void Cancel() {
- if (CancelSource != null) CancelSource();
+ CancelSource?.Invoke();
}
}
}
diff --git a/Assets/Cryville/Common/BinderAttribute.cs b/Assets/Cryville/Common/BinderAttribute.cs
index 7330dc5..406939f 100644
--- a/Assets/Cryville/Common/BinderAttribute.cs
+++ b/Assets/Cryville/Common/BinderAttribute.cs
@@ -35,8 +35,8 @@ namespace Cryville.Common {
return null;
else if (type.IsAssignableFrom(value.GetType()))
return value;
- else if (type.IsEnum && value is string) {
- return Enum.Parse(type, (string)value);
+ else if (type.IsEnum && value is string strValue) {
+ return Enum.Parse(type, strValue);
}
throw new InvalidCastException(string.Format("Cannot cast {0} to {1}", value.GetType(), type));
}
diff --git a/Assets/Cryville/Common/Coroutine.cs b/Assets/Cryville/Common/Coroutine.cs
index 6a58281..dd18dc5 100644
--- a/Assets/Cryville/Common/Coroutine.cs
+++ b/Assets/Cryville/Common/Coroutine.cs
@@ -4,7 +4,7 @@ using System.Diagnostics;
namespace Cryville.Common {
public class Coroutine {
readonly IEnumerator _enumerator;
- readonly Stopwatch _stopwatch = new Stopwatch();
+ readonly Stopwatch _stopwatch = new();
public float Progress { get; private set; }
public Coroutine(IEnumerator enumerator) {
_enumerator = enumerator;
diff --git a/Assets/Cryville/Common/Font/FontFile.cs b/Assets/Cryville/Common/Font/FontFile.cs
index 0e2ac51..a4f5e1f 100644
--- a/Assets/Cryville/Common/Font/FontFile.cs
+++ b/Assets/Cryville/Common/Font/FontFile.cs
@@ -16,13 +16,11 @@ namespace Cryville.Common.Font {
}
public void Close() { Reader.Close(); }
- public static FontFile Create(FileInfo file) {
- switch (file.Extension) {
- case ".ttf": case ".otf": return new FontFileTTF(file);
- case ".ttc": case ".otc": return new FontFileTTC(file);
- default: return null;
- }
- }
+ public static FontFile Create(FileInfo file) => file.Extension switch {
+ ".ttf" or ".otf" => new FontFileTTF(file),
+ ".ttc" or ".otc" => new FontFileTTC(file),
+ _ => null,
+ };
public Enumerator GetEnumerator() {
return new Enumerator(this);
@@ -42,7 +40,7 @@ namespace Cryville.Common.Font {
_index = -1;
}
- public Typeface Current {
+ public readonly Typeface Current {
get {
if (_index < 0)
throw new InvalidOperationException(_index == -1 ? "Enum not started" : "Enum ended");
@@ -50,7 +48,7 @@ namespace Cryville.Common.Font {
}
}
- object IEnumerator.Current { get { return Current; } }
+ readonly object IEnumerator.Current => Current;
public void Dispose() {
_index = -2;
diff --git a/Assets/Cryville/Common/Font/FontManager.cs b/Assets/Cryville/Common/Font/FontManager.cs
index e421c56..61d24e3 100644
--- a/Assets/Cryville/Common/Font/FontManager.cs
+++ b/Assets/Cryville/Common/Font/FontManager.cs
@@ -17,8 +17,7 @@ namespace Cryville.Common.Font {
Shared.Logger.Log(3, "UI", "Discarding a font with a duplicate full name {0}", f.FullName);
continue;
}
- List set2;
- if (!map2.TryGetValue(f.FamilyName, out set2)) {
+ if (!map2.TryGetValue(f.FamilyName, out List set2)) {
map2.Add(f.FamilyName, set2 = new List());
}
set2.Add(f);
diff --git a/Assets/Cryville/Common/Font/FontMatcher.cs b/Assets/Cryville/Common/Font/FontMatcher.cs
index d6d02fb..e738eff 100644
--- a/Assets/Cryville/Common/Font/FontMatcher.cs
+++ b/Assets/Cryville/Common/Font/FontMatcher.cs
@@ -12,7 +12,7 @@ namespace Cryville.Common.Font {
public class FallbackListFontMatcher : FontMatcher {
readonly LanguageMatching _matcher;
static readonly string UltimateFallbackScript = "zzzz";
- public Dictionary> MapScriptToTypefaces = new Dictionary>();
+ public Dictionary> MapScriptToTypefaces = new();
public static Dictionary> GetDefaultWindowsFallbackMap() {
var map = new Dictionary>(StringComparer.OrdinalIgnoreCase);
FillKeysWithScripts(map, () => new List());
@@ -333,8 +333,7 @@ namespace Cryville.Common.Font {
yield return typeface1;
}
if (distinctFamily) continue;
- IReadOnlyCollection typefaces2;
- if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
+ if (Manager.MapNameToTypefaces.TryGetValue(candidate, out IReadOnlyCollection typefaces2)) {
foreach (var typeface in typefaces2) {
if (typeface1 == typeface) continue;
yield return typeface;
diff --git a/Assets/Cryville/Common/Font/FontTable.cs b/Assets/Cryville/Common/Font/FontTable.cs
index af359cc..954c0ec 100644
--- a/Assets/Cryville/Common/Font/FontTable.cs
+++ b/Assets/Cryville/Common/Font/FontTable.cs
@@ -25,7 +25,7 @@ namespace Cryville.Common.Font {
readonly UInt16 majorVersion;
readonly UInt16 minorVersion;
readonly UInt32 numFonts;
- readonly List tableDirectoryOffsets = new List();
+ readonly List tableDirectoryOffsets = new();
#pragma warning disable IDE0052 // Reserved
readonly String dsigTag;
readonly UInt32 dsigLength;
@@ -61,7 +61,7 @@ namespace Cryville.Common.Font {
readonly UInt16 entrySelector;
readonly UInt16 rangeShift;
#pragma warning restore IDE0052 // Reserved
- readonly List tableRecords = new List();
+ readonly List tableRecords = new();
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
sfntVersion = reader.ReadUInt32();
if (sfntVersion != 0x00010000 && sfntVersion != 0x4F54544F &&
@@ -81,13 +81,11 @@ namespace Cryville.Common.Font {
public override IReadOnlyList GetItems() {
return tableRecords;
}
- public override object GetSubTable(TableRecord item) {
- switch (item.tableTag) {
- case "name": return new NameTable(Reader, item.offset);
- case "meta": return new MetaTable(Reader, item.offset);
- default: throw new NotImplementedException();
- }
- }
+ public override object GetSubTable(TableRecord item) => item.tableTag switch {
+ "name" => new NameTable(Reader, item.offset),
+ "meta" => new MetaTable(Reader, item.offset),
+ _ => throw new NotImplementedException(),
+ };
}
public struct TableRecord {
public string tableTag;
@@ -99,9 +97,9 @@ namespace Cryville.Common.Font {
readonly UInt16 version;
readonly UInt16 count;
readonly UInt16 storageOffset;
- readonly List nameRecord = new List();
+ readonly List nameRecord = new();
readonly UInt16 langTagCount;
- readonly List langTagRecord = new List();
+ readonly List langTagRecord = new();
public NameTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
version = reader.ReadUInt16();
count = reader.ReadUInt16();
@@ -213,7 +211,7 @@ namespace Cryville.Common.Font {
readonly UInt32 flags;
#pragma warning restore IDE0052 // Reserved
readonly UInt32 dataMapCount;
- readonly List dataMaps = new List();
+ readonly List dataMaps = new();
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
version = reader.ReadUInt32();
if (version != 1) throw new NotSupportedException();
diff --git a/Assets/Cryville/Common/IOExtensions.cs b/Assets/Cryville/Common/IOExtensions.cs
index 1ec8857..9089948 100644
--- a/Assets/Cryville/Common/IOExtensions.cs
+++ b/Assets/Cryville/Common/IOExtensions.cs
@@ -25,7 +25,7 @@ namespace Cryville.Common {
/// The encoding of the string.
/// The string read from the reader.
public static string ReadUInt16String(this BinaryReader reader, Encoding encoding = null) {
- if (encoding == null) encoding = Encoding.UTF8;
+ encoding ??= Encoding.UTF8;
var len = reader.ReadUInt16();
byte[] buffer = reader.ReadBytes(len);
return encoding.GetString(buffer);
@@ -38,7 +38,7 @@ namespace Cryville.Common {
/// The string to write by the writer.
/// The encoding of the string.
public static void WriteUInt16String(this BinaryWriter writer, string value, Encoding encoding = null) {
- if (encoding == null) encoding = Encoding.UTF8;
+ encoding ??= Encoding.UTF8;
byte[] buffer = encoding.GetBytes(value);
writer.Write((ushort)buffer.Length);
writer.Write(buffer);
diff --git a/Assets/Cryville/Common/Identifier.cs b/Assets/Cryville/Common/Identifier.cs
index 1127c87..e3fd0e1 100644
--- a/Assets/Cryville/Common/Identifier.cs
+++ b/Assets/Cryville/Common/Identifier.cs
@@ -2,26 +2,26 @@ using System;
namespace Cryville.Common {
public struct Identifier : IEquatable {
- public static Identifier Empty = new Identifier(0);
+ public static Identifier Empty = new(0);
public int Key { get; private set; }
- public object Name { get { return IdentifierManager.Shared.Retrieve(Key); } }
+ public readonly object Name => IdentifierManager.Shared.Retrieve(Key);
public Identifier(int key) {
Key = key;
}
public Identifier(object name) {
Key = IdentifierManager.Shared.Request(name);
}
- public override bool Equals(object obj) {
- if (obj == null || !(obj is Identifier)) return false;
- return Equals((Identifier)obj);
+ public override readonly bool Equals(object obj) {
+ if (obj == null || obj is not Identifier other) return false;
+ return Equals(other);
}
- public bool Equals(Identifier other) {
+ public readonly bool Equals(Identifier other) {
return Key == other.Key;
}
- public override int GetHashCode() {
+ public override readonly int GetHashCode() {
return Key;
}
- public override string ToString() {
+ public override readonly string ToString() {
if (Key == 0) return "";
return Name.ToString();
}
diff --git a/Assets/Cryville/Common/Math/ColumnVector.cs b/Assets/Cryville/Common/Math/ColumnVector.cs
index 6517667..d8e4b13 100644
--- a/Assets/Cryville/Common/Math/ColumnVector.cs
+++ b/Assets/Cryville/Common/Math/ColumnVector.cs
@@ -42,13 +42,13 @@ namespace Cryville.Common.Math {
}
}
///
- /// Performs dot operation with a column vector.
+ /// Performs dot operation with a column vector.
///
/// The lefthand column vector.
/// The vector operator.
/// The result of the dot operation.
public T Dot(ColumnVector lhs, IVectorOperator o) {
- T res = default(T);
+ T res = default;
for (var i = 0; i < Size; i++)
res = o.Add(res, o.ScalarMultiply(lhs[i], content[i]));
return res;
diff --git a/Assets/Cryville/Common/Network/Http11/Http11Client.cs b/Assets/Cryville/Common/Network/Http11/Http11Client.cs
index d59df8e..0373453 100644
--- a/Assets/Cryville/Common/Network/Http11/Http11Client.cs
+++ b/Assets/Cryville/Common/Network/Http11/Http11Client.cs
@@ -71,8 +71,7 @@ namespace Cryville.Common.Network.Http11 {
headers["Host"] = _baseUri.Host;
byte[] payload = null;
if (body != null) {
- if (encoding == null)
- encoding = Encoding.UTF8;
+ encoding ??= Encoding.UTF8;
payload = encoding.GetBytes(body);
headers.Add("Content-Encoding", encoding.EncodingName);
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
diff --git a/Assets/Cryville/Common/Network/Http11/Http11Response.cs b/Assets/Cryville/Common/Network/Http11/Http11Response.cs
index 94a56d8..7d8d74b 100644
--- a/Assets/Cryville/Common/Network/Http11/Http11Response.cs
+++ b/Assets/Cryville/Common/Network/Http11/Http11Response.cs
@@ -56,7 +56,7 @@ namespace Cryville.Common.Network.Http11 {
}
internal static string ReadLine(BinaryReader reader) {
- StringBuilder result = new StringBuilder();
+ StringBuilder result = new();
char c;
while (true) {
c = reader.ReadChar();
diff --git a/Assets/Cryville/Common/Network/Http11/Http11ResponseStream.cs b/Assets/Cryville/Common/Network/Http11/Http11ResponseStream.cs
index 6753b53..8d61bd9 100644
--- a/Assets/Cryville/Common/Network/Http11/Http11ResponseStream.cs
+++ b/Assets/Cryville/Common/Network/Http11/Http11ResponseStream.cs
@@ -72,8 +72,7 @@ namespace Cryville.Common.Network.Http11 {
public void ReadChunk() {
if (_chunk != null && _chunk.Length == 0) return;
string[] chunkHeader = Http11Response.ReadLine(_reader).Split(';');
- int chunkSize;
- if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out chunkSize))
+ if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int chunkSize))
throw new IOException("Corrupted chunk received");
if (chunkSize == 0) {
_chunk = new byte[0];
@@ -106,7 +105,7 @@ namespace Cryville.Common.Network.Http11 {
}
public override byte[] ReadToEnd() {
if (_chunk.Length == 0) return new byte[0];
- List segs = new List();
+ List segs = new();
while (true) {
if (_pos != 0) {
var buffer = new byte[_chunk.Length - _pos];
diff --git a/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs b/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs
index fb71f3b..0fa5890 100644
--- a/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs
+++ b/Assets/Cryville/Common/Pdt/PdtEvaluatorBase.cs
@@ -56,9 +56,9 @@ namespace Cryville.Common.Pdt {
while (ip != null) {
bool nextFlag = false;
var i = ip.Value;
- if (i is PdtInstruction.Operate) {
+ if (i is PdtInstruction.Operate iop) {
int fc0 = _framecount;
- int fc1 = ((PdtInstruction.Operate)i).Signature.ParamCount;
+ int fc1 = iop.Signature.ParamCount;
try { i.Execute(this, ref ip); } catch (Exception) { }
if (fc0 - _framecount == fc1) {
unsafe {
@@ -77,8 +77,7 @@ namespace Cryville.Common.Pdt {
}
}
}
- else if (i is PdtInstruction.Collapse) {
- var t = (PdtInstruction.Collapse)i;
+ else if (i is PdtInstruction.Collapse t) {
try {
var pins = ip;
i.Execute(this, ref ip);
@@ -133,15 +132,14 @@ namespace Cryville.Common.Pdt {
exp.IsConstant = true;
exp.IsPotentialConstant = true;
for (var ins = il.First; ins != null; ins = ins.Next) {
- if (!(ins.Value is PdtInstruction.PushConstant)) {
+ if (ins.Value is not PdtInstruction.PushConstant) {
exp.IsConstant = false;
break;
}
}
}
void ReplaceIP(LinkedList il, ref LinkedListNode ip, PdtInstruction ins, Dictionary, List> cols) {
- List cins;
- if (cols.TryGetValue(ip, out cins)) cols.Remove(ip);
+ if (cols.TryGetValue(ip, out List cins)) cols.Remove(ip);
ip = il.AddAfter(ip, ins);
il.Remove(ip.Previous);
if (cins != null) cols.Add(ip, cins);
@@ -163,8 +161,7 @@ namespace Cryville.Common.Pdt {
}
internal unsafe void PushVariable(int name, bool forced) {
fixed (StackFrame* frame = &_stack[_framecount++]) {
- byte[] value;
- GetVariable(name, forced, out frame->Type, out value);
+ GetVariable(name, forced, out frame->Type, out byte[] value);
frame->Offset = _goffset;
frame->Length = value.Length;
Array.Copy(value, 0, _mem, _goffset, value.Length);
diff --git a/Assets/Cryville/Common/Pdt/PdtExpression.cs b/Assets/Cryville/Common/Pdt/PdtExpression.cs
index b25cda5..99452a6 100644
--- a/Assets/Cryville/Common/Pdt/PdtExpression.cs
+++ b/Assets/Cryville/Common/Pdt/PdtExpression.cs
@@ -114,7 +114,7 @@ namespace Cryville.Common.Pdt {
}
}
public partial class PdtInterpreter {
- static readonly Dictionary OP_PRIORITY = new Dictionary {
+ static readonly Dictionary OP_PRIORITY = new() {
{ '@', 7 },
{ '*', 6 }, { '/', 6 }, { '%', 6 },
{ '+', 5 }, { '-', 5 },
@@ -125,7 +125,7 @@ namespace Cryville.Common.Pdt {
{ ',', 0 },
{ '$', -1 },
};
- static readonly Dictionary OP_TYPE = new Dictionary {
+ static readonly Dictionary OP_TYPE = new() {
{ '@', 0 },
{ '*', 0 }, { '/', 0 }, { '%', 0 },
{ '+', 0 }, { '-', 0 },
@@ -153,10 +153,10 @@ namespace Cryville.Common.Pdt {
private struct PdtExpToken {
public CharCategory Type { get; set; }
public string Value { get; set; }
- public override string ToString() {
+ public override readonly string ToString() {
return string.Format("0x{0:x4}: {1}", Type, Value);
}
- public static readonly PdtExpToken EmptyOperator = new PdtExpToken {
+ public static readonly PdtExpToken EmptyOperator = new() {
Type = CharCategory.Operator,
Value = "$",
};
@@ -249,13 +249,12 @@ namespace Cryville.Common.Pdt {
PdtExpToken? buf = null;
while (true) {
if (buf != null && t.Type != CharCategory.OpeningBracket) {
- PdtExpression def;
- if (defs.TryGetValue(buf.Value.Value, out def)) {
+ if (defs.TryGetValue(buf.Value.Value, out PdtExpression def)) {
foreach (var i in def.Instructions) ins.AddLast(i);
}
else {
var name = buf.Value.Value;
- if (name[0] == '?') ins.AddLast(new PdtInstruction.PushVariable(name.Substring(1), true));
+ if (name[0] == '?') ins.AddLast(new PdtInstruction.PushVariable(name[1..], true));
else ins.AddLast(new PdtInstruction.PushVariable(name));
}
buf = null;
diff --git a/Assets/Cryville/Common/Pdt/PdtInterpreter.cs b/Assets/Cryville/Common/Pdt/PdtInterpreter.cs
index 958035b..907bfd0 100644
--- a/Assets/Cryville/Common/Pdt/PdtInterpreter.cs
+++ b/Assets/Cryville/Common/Pdt/PdtInterpreter.cs
@@ -65,7 +65,7 @@ namespace Cryville.Common.Pdt {
///
public int Position { get; protected set; }
- readonly StringBuilder _sb = new StringBuilder();
+ readonly StringBuilder _sb = new();
#pragma warning disable IDE1006
///
/// The character at the current position.
@@ -86,7 +86,7 @@ namespace Cryville.Common.Pdt {
protected string tokenb(CharCategory flag) {
int sp = Position;
while ((ct & flag) == 0) Position++;
- return Source.Substring(sp, Position - sp);
+ return Source[sp..Position];
}
///
/// Reads a token until a character that is not of type is met.
@@ -97,7 +97,7 @@ namespace Cryville.Common.Pdt {
protected string tokenw(CharCategory flag) {
int sp = Position;
while ((ct & flag) != 0) Position++;
- return Source.Substring(sp, Position - sp);
+ return Source[sp..Position];
}
///
/// Skips over whitespaces.
@@ -163,7 +163,7 @@ namespace Cryville.Common.Pdt {
return new PdtExpression(ins);
}
- readonly Dictionary defs = new Dictionary();
+ readonly Dictionary defs = new();
///
/// Creates an instance of the class.
///
@@ -186,8 +186,7 @@ namespace Cryville.Common.Pdt {
public object Interpret(Type type) {
try {
if (m_formatVersion == null) InterpretDirectives();
- if (_binder == null)
- _binder = BinderAttribute.CreateBinderOfType(type);
+ _binder ??= BinderAttribute.CreateBinderOfType(type);
return InterpretObject(type);
}
catch (Exception ex) {
@@ -256,18 +255,17 @@ namespace Cryville.Common.Pdt {
}
void InterpretObjectInternal(bool pcflag, Type type, object pkey, object result, Func vfunc) where T : Attribute {
if (pcflag) {
- using (var collection = new PairCollection(result)) {
- var ktype = type.GetGenericArguments()[0];
- var ptype = type.GetGenericArguments()[1];
- object key = _binder.ChangeType(pkey, ktype, null);
- object value = vfunc(ptype);
- collection.Add(key, value);
- }
+ using var collection = new PairCollection(result);
+ var ktype = type.GetGenericArguments()[0];
+ var ptype = type.GetGenericArguments()[1];
+ object key = _binder.ChangeType(pkey, ktype, null);
+ object value = vfunc(ptype);
+ collection.Add(key, value);
}
else {
MemberInfo prop = null;
bool flag = false;
- if (pkey is string) prop = FieldLikeHelper.GetMember(type, (string)pkey);
+ if (pkey is string pname) prop = FieldLikeHelper.GetMember(type, pname);
if (prop == null) {
prop = FieldLikeHelper.FindMemberWithAttribute(type);
flag = true;
@@ -279,13 +277,12 @@ namespace Cryville.Common.Pdt {
if (origCollection == null) {
FieldLikeHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
}
- using (var collection = new PairCollection(origCollection)) {
- var ktype = ptype.GetGenericArguments()[0];
- var vtype = ptype.GetGenericArguments()[1];
- object key = _binder.ChangeType(pkey, ktype, null);
- object value = vfunc(vtype);
- collection.Add(key, value);
- }
+ using var collection = new PairCollection(origCollection);
+ var ktype = ptype.GetGenericArguments()[0];
+ var vtype = ptype.GetGenericArguments()[1];
+ object key = _binder.ChangeType(pkey, ktype, null);
+ object value = vfunc(vtype);
+ collection.Add(key, value);
}
else FieldLikeHelper.SetValue(prop, result, vfunc(ptype), _binder);
}
@@ -326,7 +323,7 @@ namespace Cryville.Common.Pdt {
src.Take(interpreter.Position).Count(c => c == '\n') + 1,
pos - lineStartPos + 1,
innerException == null ? "Unknown error" : innerException.Message,
- src.Substring(previewStartPos, previewEndPos - previewStartPos)
+ src[previewStartPos..previewEndPos]
);
}
}
diff --git a/Assets/Cryville/Common/Pdt/PdtOperator.cs b/Assets/Cryville/Common/Pdt/PdtOperator.cs
index 4ec0446..e7f119c 100644
--- a/Assets/Cryville/Common/Pdt/PdtOperator.cs
+++ b/Assets/Cryville/Common/Pdt/PdtOperator.cs
@@ -102,17 +102,17 @@ namespace Cryville.Common.Pdt {
ParamCount = paramCount;
_hash = Name ^ ((ParamCount << 16) | (ParamCount >> 16));
}
- public override bool Equals(object obj) {
- if (!(obj is PdtOperatorSignature)) return false;
- return Equals((PdtOperatorSignature)obj);
+ public override readonly bool Equals(object obj) {
+ if (obj is not PdtOperatorSignature other) return false;
+ return Equals(other);
}
- public bool Equals(PdtOperatorSignature other) {
+ public readonly bool Equals(PdtOperatorSignature other) {
return Name == other.Name && ParamCount == other.ParamCount;
}
- public override int GetHashCode() {
+ public override readonly int GetHashCode() {
return _hash;
}
- public override string ToString() {
+ public override readonly string ToString() {
return string.Format("{0}({1})", IdentifierManager.Shared.Retrieve(Name), ParamCount);
}
}
diff --git a/Assets/Cryville/Common/Pdt/PdtVariableMemory.cs b/Assets/Cryville/Common/Pdt/PdtVariableMemory.cs
index 19ee6c6..a898683 100644
--- a/Assets/Cryville/Common/Pdt/PdtVariableMemory.cs
+++ b/Assets/Cryville/Common/Pdt/PdtVariableMemory.cs
@@ -24,7 +24,7 @@ namespace Cryville.Common.Pdt {
/// Copies the memory in the span to another span.
///
/// The destination span.
- public void CopyTo(PdtVariableMemory dest) {
+ public readonly void CopyTo(PdtVariableMemory dest) {
CopyTo(dest._ptr, 0, Length);
}
///
@@ -32,7 +32,7 @@ namespace Cryville.Common.Pdt {
///
/// The destination buffer.
/// The offset on the destination buffer to start copying to.
- public void CopyTo(byte[] dest, int destOffset) {
+ public readonly void CopyTo(byte[] dest, int destOffset) {
fixed (byte* ptr = dest) {
CopyTo(ptr, destOffset, Length);
}
@@ -44,13 +44,13 @@ namespace Cryville.Common.Pdt {
/// The offset on the destination buffer to start copying to.
/// The length to copy.
/// is greater than the length of the span.
- public void CopyTo(byte* dest, int destOffset, int length) {
+ public readonly void CopyTo(byte* dest, int destOffset, int length) {
if (length > Length) throw new ArgumentOutOfRangeException("length");
for (int i = 0; i < length; i++)
dest[destOffset + i] = _ptr[i];
}
///
- public bool Equals(PdtVariableMemory obj) {
+ public readonly bool Equals(PdtVariableMemory obj) {
if (Type != obj.Type || Length != obj.Length) return false;
for (int i = 0; i < Length; i++) {
if (*(_ptr + i) != *(obj._ptr + i)) return false;
@@ -63,7 +63,7 @@ namespace Cryville.Common.Pdt {
/// The offset on the span to start reading from.
/// A number.
/// The span at the offset does not represent a number.
- public float AsNumber(int offset = 0) {
+ public readonly float AsNumber(int offset = 0) {
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
throw new InvalidCastException("Not a number");
float value;
@@ -79,7 +79,7 @@ namespace Cryville.Common.Pdt {
/// The offset from the start of the span.
/// The span at the offset does not represent a number.
/// The length of the span is not sufficient.
- public void SetNumber(float value, int offset = 0) {
+ public readonly void SetNumber(float value, int offset = 0) {
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
throw new InvalidCastException("Not a number");
if (Length < sizeof(float) + offset)
@@ -94,7 +94,7 @@ namespace Cryville.Common.Pdt {
/// The offset on the span to start reading from.
/// A string.
/// The span at the offset does not represent a string.
- public string AsString(int offset = 0) {
+ public readonly string AsString(int offset = 0) {
if (Type != PdtInternalType.String && Type != PdtInternalType.Array)
throw new InvalidCastException("Not a string");
var len = *(int*)(_ptr + offset);
@@ -107,7 +107,7 @@ namespace Cryville.Common.Pdt {
/// The offset from the start of the span.
/// The span at the offset does not represent a string.
/// The length of the span is not sufficient.
- public void SetString(string value, int offset = 0) {
+ public readonly void SetString(string value, int offset = 0) {
if (Type != PdtInternalType.String && Type != PdtInternalType.Array)
throw new InvalidCastException("Not a string");
int strlen = value.Length;
@@ -124,7 +124,7 @@ namespace Cryville.Common.Pdt {
/// The offset on the span to start reading from.
/// The name of an undefined identifier.
/// The span does not represent an undefined identifier.
- public int AsIdentifier(int offset = 0) {
+ public readonly int AsIdentifier(int offset = 0) {
if (Type != PdtInternalType.Undefined && Type != PdtInternalType.Array)
throw new InvalidCastException("Not an identifier");
return *(int*)(_ptr + offset);
@@ -140,7 +140,7 @@ namespace Cryville.Common.Pdt {
///
/// Use instead while reading an unaligned number.
///
- public T As(int offset = 0) {
+ public readonly T As(int offset = 0) {
var len = Unsafe.SizeOf();
if (offset >= Length)
throw new ArgumentOutOfRangeException("offset");
@@ -159,7 +159,7 @@ namespace Cryville.Common.Pdt {
///
/// Use instead while writing an unaligned number.
///
- public void Set(T value, int offset = 0) {
+ public readonly void Set(T value, int offset = 0) {
var len = Unsafe.SizeOf();
if (offset >= Length)
throw new ArgumentOutOfRangeException("offset");
@@ -173,7 +173,7 @@ namespace Cryville.Common.Pdt {
/// The type of the array.
/// The item count of the array.
/// The span does not represent an array.
- public void GetArraySuffix(out int arrtype, out int pc) {
+ public readonly void GetArraySuffix(out int arrtype, out int pc) {
if (Type != PdtInternalType.Vector && Type != PdtInternalType.Array)
throw new InvalidCastException("Not an array or vector");
arrtype = *(int*)(_ptr + Length - sizeof(int));
@@ -186,7 +186,7 @@ namespace Cryville.Common.Pdt {
/// The type of the array.
/// The item count of the array.
/// The span does not represent an array.
- public void SetArraySuffix(int arrtype, int pc = 0) {
+ public readonly void SetArraySuffix(int arrtype, int pc = 0) {
if (Type != PdtInternalType.Vector && Type != PdtInternalType.Array)
throw new InvalidCastException("Not an array or vector");
*(int*)(_ptr + Length - sizeof(int)) = arrtype;
diff --git a/Assets/Cryville/Common/Qualified.cs b/Assets/Cryville/Common/Qualified.cs
index 6ac769a..2ab8e3d 100644
--- a/Assets/Cryville/Common/Qualified.cs
+++ b/Assets/Cryville/Common/Qualified.cs
@@ -6,15 +6,15 @@ namespace Cryville.Common {
public T Value { get; set; }
public string Unit { get; set; }
- public Qualified(string unit) : this(default(T), unit) { }
+ public Qualified(string unit) : this(default, unit) { }
public Qualified(T value, string unit) {
Value = value;
Unit = unit;
}
- public override string ToString() { return ToString("G3"); }
- public string ToString(string format) { return ToString(format, null); }
- public string ToString(string format, IFormatProvider formatProvider) {
+ public override readonly string ToString() { return ToString("G3"); }
+ public readonly string ToString(string format) { return ToString(format, null); }
+ public readonly string ToString(string format, IFormatProvider formatProvider) {
double value = Value.ToDouble(formatProvider);
int expIndex = (int)System.Math.Log10(value) / 3;
if (expIndex == 0) {
diff --git a/Assets/Cryville/Common/Shared.cs b/Assets/Cryville/Common/Shared.cs
index 58597d9..5aec54e 100644
--- a/Assets/Cryville/Common/Shared.cs
+++ b/Assets/Cryville/Common/Shared.cs
@@ -2,6 +2,6 @@ using Cryville.Common.Logging;
namespace Cryville.Common {
public static class Shared {
- public static readonly Logger Logger = new Logger();
+ public static readonly Logger Logger = new();
}
}
diff --git a/Assets/Cryville/Common/StringUtils.cs b/Assets/Cryville/Common/StringUtils.cs
index 32dc129..a6d469f 100644
--- a/Assets/Cryville/Common/StringUtils.cs
+++ b/Assets/Cryville/Common/StringUtils.cs
@@ -13,7 +13,7 @@ namespace Cryville.Common {
/// The file name or file path.
/// The file name or file path with the extension removed.
public static string TrimExt(string s) {
- return s.Substring(0, s.LastIndexOf("."));
+ return s[..s.LastIndexOf(".")];
}
///
/// Converts the value of a to a human-readable string.
@@ -52,12 +52,12 @@ namespace Cryville.Common {
public static string GetProcessPathFromCommand(string command) {
command = command.Trim();
if (command[0] == '"') {
- return command.Substring(1, command.IndexOf('"', 1) - 1);
+ return command[1..command.IndexOf('"', 1)];
}
else {
int e = command.IndexOf(' ');
if (e == -1) return command;
- else return command.Substring(0, e);
+ else return command[..e];
}
}
}
diff --git a/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs b/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs
index 5c8576c..9db712f 100644
--- a/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs
+++ b/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs
@@ -16,7 +16,7 @@ namespace Cryville.Common.Unity {
public class NetworkTaskWorker {
bool suspended;
NetworkTask currentNetworkTask;
- readonly Queue networkTasks = new Queue();
+ readonly Queue networkTasks = new();
///
/// Current queued task count.
diff --git a/Assets/Cryville/Common/Unity/StateTweener.cs b/Assets/Cryville/Common/Unity/StateTweener.cs
index c75af96..f0da9c2 100644
--- a/Assets/Cryville/Common/Unity/StateTweener.cs
+++ b/Assets/Cryville/Common/Unity/StateTweener.cs
@@ -30,13 +30,13 @@ namespace Cryville.Common.Unity {
[SerializeField]
public string Attribute;
- public bool Equals(AttributeBinding other) {
+ public readonly bool Equals(AttributeBinding other) {
return Component.Equals(other.Component) && Attribute.Equals(other.Attribute);
}
- public override bool Equals(object obj) {
- return obj is AttributeBinding && Equals((AttributeBinding)obj);
+ public override readonly bool Equals(object obj) {
+ return obj is AttributeBinding other && Equals(other);
}
- public override int GetHashCode() {
+ public override readonly int GetHashCode() {
return Component.GetHashCode() ^ Attribute.GetHashCode();
}
}
@@ -44,10 +44,10 @@ namespace Cryville.Common.Unity {
[SerializeField]
StateTweener[] m_children;
- readonly List _statePriority = new List();
- readonly Dictionary _defaults = new Dictionary();
- readonly Dictionary> _tweeners = new Dictionary>();
- readonly Dictionary> _runtimeStates = new Dictionary>();
+ readonly List _statePriority = new();
+ readonly Dictionary _defaults = new();
+ readonly Dictionary> _tweeners = new();
+ readonly Dictionary> _runtimeStates = new();
void Awake() {
var types = new Dictionary();
@@ -130,7 +130,7 @@ namespace Cryville.Common.Unity {
foreach (var tweener in _tweeners) tweener.Value.Advance(Time.deltaTime);
}
- readonly List m_cState = new List();
+ readonly List m_cState = new();
public IReadOnlyList CurrentState => m_cState;
public void ClearState(float transitionDuration = float.Epsilon) {
foreach (var child in m_children) child.ClearState(transitionDuration);
@@ -161,7 +161,7 @@ namespace Cryville.Common.Unity {
if (index < 0) return;
m_cState.RemoveAt(index);
if (index < m_cState.Count) return;
- var attrs = m_cState.Count == 0 ? _defaults : _runtimeStates[m_cState[m_cState.Count - 1]];
+ var attrs = m_cState.Count == 0 ? _defaults : _runtimeStates[m_cState[^1]];
foreach (var tweener in _tweeners) {
tweener.Value.Start(attrs[tweener.Key], transitionDuration);
}
diff --git a/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs b/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs
index 48dae17..b45c4d3 100644
--- a/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs
+++ b/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs
@@ -113,7 +113,7 @@ namespace Cryville.Common.Unity.UI {
private bool initialized;
private GameObject[][] lines;
private int[] refl;
- Vector2 cpos = new Vector2(0, 1);
+ Vector2 cpos = new(0, 1);
Vector2 pprectsize;
#pragma warning disable IDE0051
diff --git a/Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs b/Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
index 1c6ae0b..b2e2553 100644
--- a/Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
+++ b/Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
@@ -35,8 +35,7 @@ namespace Cryville.Common.Unity.UI {
if (MaxFallbackCount <= 0) break;
}
else {
- if (_font.fallbackFontAssetTable == null)
- _font.fallbackFontAssetTable = new List();
+ _font.fallbackFontAssetTable ??= new List();
_font.fallbackFontAssetTable.Add(ifont);
Shared.Logger.Log(1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
diff --git a/Assets/Cryville/Crtr/BeatTime.cs b/Assets/Cryville/Crtr/BeatTime.cs
index fdee411..4e2b518 100644
--- a/Assets/Cryville/Crtr/BeatTime.cs
+++ b/Assets/Cryville/Crtr/BeatTime.cs
@@ -25,7 +25,7 @@ namespace Cryville.Crtr {
public int d;
[JsonIgnore]
- public double Decimal { get { return b + (double)n / d; } }
+ public readonly double Decimal { get { return b + (double)n / d; } }
public int CompareTo(BeatTime other) {
var c = b.CompareTo(other.b);
@@ -34,15 +34,15 @@ namespace Cryville.Crtr {
}
public override bool Equals(object obj) {
- if (!(obj is BeatTime)) return false;
- return Equals((BeatTime)obj);
+ if (obj is not BeatTime other) return false;
+ return Equals(other);
}
public bool Equals(BeatTime other) {
return b.Equals(other.b) && ((double)n / d).Equals((double)other.n / other.d);
}
- public override int GetHashCode() {
+ public override readonly int GetHashCode() {
return Decimal.GetHashCode();
}
diff --git a/Assets/Cryville/Crtr/Browsing/Actions/ActionManager.cs b/Assets/Cryville/Crtr/Browsing/Actions/ActionManager.cs
index d3f58cf..b419b4a 100644
--- a/Assets/Cryville/Crtr/Browsing/Actions/ActionManager.cs
+++ b/Assets/Cryville/Crtr/Browsing/Actions/ActionManager.cs
@@ -4,28 +4,27 @@ using System.Linq;
namespace Cryville.Crtr.Browsing.Actions {
public class ActionManager {
- readonly Dictionary> _actions = new Dictionary>();
- readonly Dictionary _refCounts = new Dictionary();
+ readonly Dictionary> _actions = new();
+ readonly Dictionary _refCounts = new();
public event Action Changed;
class ActionPriorityComparer : IComparer {
- public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
+ public static readonly ActionPriorityComparer Instance = new();
public int Compare(IResourceAction x, IResourceAction y) {
return x.Priority.CompareTo(y.Priority);
}
}
void Register(Type type, IResourceAction action) {
- List actions;
- if (!_actions.TryGetValue(type, out actions)) {
+ if (!_actions.TryGetValue(type, out List actions)) {
_actions.Add(type, actions = new List());
}
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
if (index < 0) index = ~index;
actions.Insert(index, action);
if (_refCounts.ContainsKey(action)) _refCounts[action]++;
- else _refCounts[action] = 0;
+ else _refCounts[action] = 1;
Changed?.Invoke();
}
public void Register(IResourceAction action) {
@@ -36,8 +35,7 @@ namespace Cryville.Crtr.Browsing.Actions {
}
public void Unregister(Type type, IResourceAction action) {
- List actions;
- if (!_actions.TryGetValue(type, out actions)) return;
+ if (!_actions.TryGetValue(type, out List actions)) return;
if (--_refCounts[action] > 0) return;
actions.Remove(action);
Changed?.Invoke();
@@ -54,9 +52,8 @@ namespace Cryville.Crtr.Browsing.Actions {
}
IEnumerable GetActions(Uri uri, IResourceMeta res, Type type) {
if (type == null) return Enumerable.Empty();
- List actions;
IEnumerable result;
- if (_actions.TryGetValue(type, out actions))
+ if (_actions.TryGetValue(type, out List actions))
result = actions.Where(i => i.CanInvoke(uri, res));
else
result = Enumerable.Empty();
diff --git a/Assets/Cryville/Crtr/Browsing/Actions/OpenConfigAction.cs b/Assets/Cryville/Crtr/Browsing/Actions/OpenConfigAction.cs
index 592092f..52eb840 100644
--- a/Assets/Cryville/Crtr/Browsing/Actions/OpenConfigAction.cs
+++ b/Assets/Cryville/Crtr/Browsing/Actions/OpenConfigAction.cs
@@ -10,7 +10,7 @@ namespace Cryville.Crtr.Browsing.Actions {
public override int Priority { get { return -50; } }
- static readonly Dictionary _rulesetTabs = new Dictionary();
+ static readonly Dictionary _rulesetTabs = new();
public override bool CanInvoke(Uri uri, IChartDetail resource) {
return true;
@@ -20,15 +20,13 @@ namespace Cryville.Crtr.Browsing.Actions {
}
public static bool HasTab(string ruleset) {
- int tabId;
var master = ResourceBrowserMaster.Instance;
if (master == null) return false;
- return _rulesetTabs.TryGetValue(ruleset, out tabId) && master.HasTab(tabId);
+ return _rulesetTabs.TryGetValue(ruleset, out int tabId) && master.HasTab(tabId);
}
public static void Invoke(string ruleset, Action overrides = null) {
var master = ResourceBrowserMaster.Instance;
- int tabId;
- if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
+ if (_rulesetTabs.TryGetValue(ruleset, out int tabId) && master.TryOpenTab(tabId))
return;
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent();
try {
diff --git a/Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs b/Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs
index 3a29476..df02f29 100644
--- a/Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs
+++ b/Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs
@@ -8,15 +8,15 @@ namespace Cryville.Crtr.Browsing.Actions {
public abstract bool CanInvoke(Uri uri, T resource);
public bool CanInvoke(Uri uri, IResourceMeta resource) {
if (resource == null) throw new ArgumentNullException("resource");
- if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
- return CanInvoke(uri, (T)resource);
+ if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
+ return CanInvoke(uri, res);
}
public abstract void Invoke(Uri uri, T resource);
public void Invoke(Uri uri, IResourceMeta resource) {
if (resource == null) throw new ArgumentNullException("resource");
- if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
- Invoke(uri, (T)resource);
+ if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
+ Invoke(uri, res);
}
}
}
diff --git a/Assets/Cryville/Crtr/Browsing/ExtensionManager.cs b/Assets/Cryville/Crtr/Browsing/ExtensionManager.cs
index db8b284..9a70d1e 100644
--- a/Assets/Cryville/Crtr/Browsing/ExtensionManager.cs
+++ b/Assets/Cryville/Crtr/Browsing/ExtensionManager.cs
@@ -10,18 +10,17 @@ namespace Cryville.Crtr.Browsing {
internal static class ExtensionManager {
static bool _init;
static readonly Dictionary> _converters
- = new Dictionary>();
+ = new();
public static ISet GetSupportedFormats() {
return new HashSet(_converters.Keys);
}
public static bool TryGetConverters(string extension, out IEnumerable converters) {
- List outResult;
- bool result = _converters.TryGetValue(extension, out outResult);
+ bool result = _converters.TryGetValue(extension, out List outResult);
converters = outResult;
return result;
}
static readonly Dictionary _localRes
- = new Dictionary();
+ = new();
public static IReadOnlyDictionary GetLocalResourcePaths() {
return _localRes;
}
@@ -62,8 +61,7 @@ namespace Cryville.Crtr.Browsing {
stream.Seek(0, SeekOrigin.Begin);
var buf = new byte[stream.Length];
stream.Read(buf, 0, buf.Length);
- var asm = Assembly.Load(buf);
- if (asm == null) throw new TypeLoadException("Failed to load the module");
+ var asm = Assembly.Load(buf) ?? throw new TypeLoadException("Failed to load the module");
asms.Add(asm.GetName().Name);
foreach (var type in asm.GetTypes()) {
if (typeof(ExtensionInterface).IsAssignableFrom(type)) {
diff --git a/Assets/Cryville/Crtr/Browsing/FileSystemResourceManager.cs b/Assets/Cryville/Crtr/Browsing/FileSystemResourceManager.cs
index 1043df8..9b77ad3 100644
--- a/Assets/Cryville/Crtr/Browsing/FileSystemResourceManager.cs
+++ b/Assets/Cryville/Crtr/Browsing/FileSystemResourceManager.cs
@@ -17,7 +17,7 @@ namespace Cryville.Crtr.Browsing {
public FileSystemEntry this[int index] { get { return _filteredItems[index]; } }
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
- readonly List _dirParts = new List();
+ readonly List _dirParts = new();
readonly IList m_dirParts;
public IList CurrentDirectory { get { return m_dirParts; } }
public int Count { get { return _filteredItems.Length; } }
@@ -136,8 +136,7 @@ namespace Cryville.Crtr.Browsing {
public IEnumerable Properties {
get {
yield return new MetaProperty("Name", _name);
- if (FileSystemInfo is FileInfo) {
- var file = (FileInfo)FileSystemInfo;
+ if (FileSystemInfo is FileInfo file) {
yield return new MetaProperty("Size", new Qualified(file.Length, "B"));
}
yield return new MetaProperty("Write.Time", FileSystemInfo.LastWriteTime);
diff --git a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs
index 8bd9980..205318a 100644
--- a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs
+++ b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs
@@ -10,11 +10,11 @@ namespace Cryville.Crtr.Browsing.Legacy {
internal abstract class LegacyResourceManager : IPathedResourceManager where T : IResourceMeta {
protected readonly LegacyResourceStore _store;
DirectoryInfo _cd;
- readonly FileSystemWatcher _watcher = new FileSystemWatcher();
+ readonly FileSystemWatcher _watcher = new();
DirectoryInfo[] _items = new DirectoryInfo[0];
DirectoryInfo[] _filteredItems = new DirectoryInfo[0];
string _filter = string.Empty;
- readonly List _dirParts = new List();
+ readonly List _dirParts = new();
readonly IList m_dirParts;
public IList CurrentDirectory { get { return m_dirParts; } }
public int Count { get { return _filteredItems.Length; } }
diff --git a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceStore.cs b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceStore.cs
index 3cf7012..0b12818 100644
--- a/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceStore.cs
+++ b/Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceStore.cs
@@ -34,8 +34,7 @@ namespace Cryville.Crtr.Browsing.Legacy {
}
public bool ImportFrom(Uri uri) {
var file = new FileInfo(uri.LocalPath);
- IEnumerable converters;
- if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
+ if (!ExtensionManager.TryGetConverters(file.Extension, out IEnumerable converters)) return false;
foreach (var converter in converters) {
var resources = new List();
var ses = new ConversionSession {
@@ -69,8 +68,7 @@ namespace Cryville.Crtr.Browsing.Legacy {
coverFile.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
}
}
- else if (res is FileResource) {
- var tres = (FileResource)res;
+ else if (res is FileResource tres) {
DirectoryInfo dest;
bool singleFileFlag = false;
if (res is ChartResource)
diff --git a/Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs b/Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs
index 0b52b03..fcabaac 100644
--- a/Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs
+++ b/Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs
@@ -31,7 +31,7 @@ namespace Cryville.Crtr.Browsing.UI {
OnReset();
}
protected override void OnReset() {
- if (_cover != null) _cover.Cancel();
+ _cover?.Cancel();
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
Destroy(m_icon.sprite.texture);
Destroy(m_icon.sprite);
diff --git a/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs b/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
index ba52a4c..a1098d5 100644
--- a/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
+++ b/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
@@ -79,8 +79,7 @@ namespace Cryville.Crtr.Browsing.UI {
protected override void OnEnable() {
base.OnEnable();
m_layoutMinWidth = GetTargetLayoutMinWidth();
- if (_tweener == null)
- _tweener = new PropertyTweener(
+ _tweener ??= new PropertyTweener(
() => m_layoutMinWidth,
v => UpdateLayoutMinWidth(v),
Tweeners.Float.With(EasingFunctions.OutQuad)
diff --git a/Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs b/Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs
index b665b9d..e7fcf7e 100644
--- a/Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs
+++ b/Assets/Cryville/Crtr/Browsing/UI/DetailPanel.cs
@@ -72,7 +72,7 @@ namespace Cryville.Crtr.Browsing.UI {
}
void DestroyDynamicResources() {
- if (_image != null) _image.Cancel();
+ _image?.Cancel();
if (m_cover.sprite != null && m_cover.sprite != m_coverPlaceholder) {
Destroy(m_cover.sprite.texture);
Destroy(m_cover.sprite);
diff --git a/Assets/Cryville/Crtr/Browsing/UI/PathedResourceBrowser.cs b/Assets/Cryville/Crtr/Browsing/UI/PathedResourceBrowser.cs
index b90feeb..5d371e8 100644
--- a/Assets/Cryville/Crtr/Browsing/UI/PathedResourceBrowser.cs
+++ b/Assets/Cryville/Crtr/Browsing/UI/PathedResourceBrowser.cs
@@ -34,8 +34,8 @@ namespace Cryville.Crtr.Browsing.UI {
IResourceAction _importAction;
readonly IResourceAction[] _importActionArray = new IResourceAction[1];
- readonly HashSet _selectedItems = new HashSet();
- readonly Dictionary _items = new Dictionary();
+ readonly HashSet _selectedItems = new();
+ readonly Dictionary _items = new();
bool _destroyed;
protected virtual void Start() {
@@ -52,10 +52,10 @@ namespace Cryville.Crtr.Browsing.UI {
}
void OnEnable() {
- if (_manager != null) _manager.Activate();
+ _manager?.Activate();
}
void OnDisable() {
- if (_manager != null) _manager.Deactivate();
+ _manager?.Deactivate();
}
public void Init(IPathedResourceManager manager) {
diff --git a/Assets/Cryville/Crtr/Browsing/UI/ResourceBrowserMaster.cs b/Assets/Cryville/Crtr/Browsing/UI/ResourceBrowserMaster.cs
index 366c066..2cd17d0 100644
--- a/Assets/Cryville/Crtr/Browsing/UI/ResourceBrowserMaster.cs
+++ b/Assets/Cryville/Crtr/Browsing/UI/ResourceBrowserMaster.cs
@@ -21,8 +21,8 @@ namespace Cryville.Crtr.Browsing.UI {
internal GameObject m_configBrowserPrefab;
BrowserTab _currentTab;
- readonly Dictionary _tabMap = new Dictionary();
- readonly Dictionary _tabs = new Dictionary();
+ readonly Dictionary _tabMap = new();
+ readonly Dictionary _tabs = new();
public ActionManager Actions { get; private set; }
@@ -77,8 +77,7 @@ namespace Cryville.Crtr.Browsing.UI {
return _tabMap.ContainsKey(id);
}
public bool TryOpenTab(int id) {
- BrowserTab tab;
- if (_tabMap.TryGetValue(id, out tab)) {
+ if (_tabMap.TryGetValue(id, out BrowserTab tab)) {
OnTabClicked(tab);
return true;
}
diff --git a/Assets/Cryville/Crtr/Browsing/UI/RulesetConfigBrowser.cs b/Assets/Cryville/Crtr/Browsing/UI/RulesetConfigBrowser.cs
index c40d9ef..e262a3f 100644
--- a/Assets/Cryville/Crtr/Browsing/UI/RulesetConfigBrowser.cs
+++ b/Assets/Cryville/Crtr/Browsing/UI/RulesetConfigBrowser.cs
@@ -31,21 +31,21 @@ namespace Cryville.Crtr.Browsing.UI {
public void Load(string rulesetName, Action overrides = null) {
RulesetName = rulesetName;
- FileInfo file = new FileInfo(Path.Combine(
+ FileInfo file = new(Path.Combine(
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
));
if (!file.Exists) {
throw new FileNotFoundException("Ruleset for the resource not found\nMake sure you have imported the ruleset");
}
DirectoryInfo dir = file.Directory;
- using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
+ using (StreamReader reader = new(file.FullName, Encoding.UTF8)) {
_ruleset = JsonConvert.DeserializeObject(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (_ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
_ruleset.LoadPdt(dir);
}
- FileInfo cfgfile = new FileInfo(Path.Combine(
+ FileInfo cfgfile = new(Path.Combine(
Game.GameDataPath, "config", "rulesets", rulesetName + ".json"
));
if (!cfgfile.Exists) {
@@ -53,11 +53,10 @@ namespace Cryville.Crtr.Browsing.UI {
_rscfg = new RulesetConfig();
}
else {
- using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
- _rscfg = JsonConvert.DeserializeObject(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
- MissingMemberHandling = MissingMemberHandling.Error
- });
- }
+ using StreamReader cfgreader = new(cfgfile.FullName, Encoding.UTF8);
+ _rscfg = JsonConvert.DeserializeObject(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
+ MissingMemberHandling = MissingMemberHandling.Error
+ });
}
overrides?.Invoke(_rscfg);
@@ -92,12 +91,11 @@ namespace Cryville.Crtr.Browsing.UI {
void OnDisable() {
if (_loaded) {
m_inputConfigPanel.SaveTo(_rscfg.inputs);
- FileInfo cfgFile = new FileInfo(Path.Combine(
+ FileInfo cfgFile = new(Path.Combine(
Game.GameDataPath, "config", "rulesets", RulesetName + ".json"
));
- using (StreamWriter cfgWriter = new StreamWriter(cfgFile.FullName, false, Encoding.UTF8)) {
- cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
- }
+ using StreamWriter cfgWriter = new(cfgFile.FullName, false, Encoding.UTF8);
+ cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
}
}
diff --git a/Assets/Cryville/Crtr/BuiltinResources.cs b/Assets/Cryville/Crtr/BuiltinResources.cs
index d4f8016..1c0f6c8 100644
--- a/Assets/Cryville/Crtr/BuiltinResources.cs
+++ b/Assets/Cryville/Crtr/BuiltinResources.cs
@@ -6,13 +6,13 @@ using UnityEngine;
namespace Cryville.Crtr {
public static class BuiltinResources {
public static Dictionary Components
- = new Dictionary();
+ = new();
public static Dictionary Shaders
- = new Dictionary();
+ = new();
public static Dictionary Meshes
- = new Dictionary();
+ = new();
public static Dictionary Materials
- = new Dictionary();
+ = new();
static bool loaded;
diff --git a/Assets/Cryville/Crtr/Chart.cs b/Assets/Cryville/Crtr/Chart.cs
index 4077987..525ba99 100644
--- a/Assets/Cryville/Crtr/Chart.cs
+++ b/Assets/Cryville/Crtr/Chart.cs
@@ -18,7 +18,7 @@ namespace Cryville.Crtr {
}
public abstract class ChartEvent {
public BeatTime? time;
-
+
[JsonIgnore]
public float BeatPosition {
get {
@@ -27,7 +27,7 @@ namespace Cryville.Crtr {
}
public BeatTime? endtime;
-
+
[JsonIgnore]
public float EndBeatPosition {
get {
@@ -35,10 +35,10 @@ namespace Cryville.Crtr {
return (float)endtime.Value.Decimal + BeatOffset;
}
}
-
+
[JsonIgnore]
public float BeatOffset;
-
+
[JsonIgnore]
public abstract int Priority { get; }
@@ -66,8 +66,7 @@ namespace Cryville.Crtr {
[JsonIgnore]
public ReleaseEvent ReleaseEvent {
get {
- if (relev == null) relev = new ReleaseEvent(this);
- return relev;
+ return relev ??= new ReleaseEvent(this);
}
}
@@ -96,15 +95,15 @@ namespace Cryville.Crtr {
SubmitPropOp("endtime", new PropOp.BeatTime(v => endtime = v));
}
}
-
+
public class ReleaseEvent : ChartEvent {
public readonly ChartEvent Original;
-
+
public ReleaseEvent(ChartEvent orig) {
Original = orig;
time = orig.endtime;
}
-
+
public override int Priority {
get {
return Original.Priority + 1;
@@ -112,7 +111,7 @@ namespace Cryville.Crtr {
}
}
public abstract class EventContainer : ChartEvent {
- public List motions = new List();
+ public List motions = new();
[JsonIgnore]
public Clip Clip { get; private set; }
@@ -120,7 +119,7 @@ namespace Cryville.Crtr {
public EventContainer() {
SubmitPropOp("clip", new PropOp.Clip(v => Clip = v));
}
-
+
[JsonIgnore]
public virtual IEnumerable Events {
get {
@@ -128,12 +127,10 @@ namespace Cryville.Crtr {
}
}
- public virtual EventList GetEventsOfType(string type) {
- switch (type) {
- case "motions": return new EventList(motions);
- default: throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type));
- }
- }
+ public virtual EventList GetEventsOfType(string type) => type switch {
+ "motions" => new EventList(motions),
+ _ => throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type)),
+ };
}
public abstract class EventList : ChartEvent {
public IList Events { get; private set; }
@@ -178,8 +175,8 @@ namespace Cryville.Crtr {
public string ruleset;
- public List groups = new List();
-
+ public List groups = new();
+
public override IEnumerable Events {
get {
return base.Events
@@ -189,33 +186,29 @@ namespace Cryville.Crtr {
}
}
- public override EventList GetEventsOfType(string type) {
- switch (type) {
- case "groups": return new EventList(groups);
- default: return base.GetEventsOfType(type);
- }
- }
+ public override EventList GetEventsOfType(string type) => type switch {
+ "groups" => new EventList(groups),
+ _ => base.GetEventsOfType(type),
+ };
public override int Priority { get { return 10; } }
public class Group : EventContainer {
- public List