Compare commits
34 Commits
0.8.0
...
99015f5838
Author | SHA1 | Date | |
---|---|---|---|
99015f5838 | |||
cdaf0dfd2f | |||
38421b7a53 | |||
e0362bbb58 | |||
a02885704d | |||
0a223af698 | |||
283783954f | |||
d71bf7d4a5 | |||
4274bfa1b7 | |||
b3fe4de0d4 | |||
e9e6d7002a | |||
662cbf0827 | |||
9bfa7f2048 | |||
45d80522eb | |||
77f92f9294 | |||
5241490590 | |||
8bb2a01c8e | |||
85bbe43827 | |||
a532a9f4c1 | |||
c66b7da63b | |||
e1bb874943 | |||
365a8992cd | |||
cd3aae7201 | |||
aa84fb8544 | |||
4dd4c5f20d | |||
30b3114bc1 | |||
58be497903 | |||
50879a1f3f | |||
55dd38fb2c | |||
b7f5dbc4da | |||
81d458f7de | |||
58091ad534 | |||
6783d39571 | |||
e2c8c92279 |
@@ -20,13 +20,13 @@ namespace Cryville.Common {
|
|||||||
/// <param name="succeeded">Whether the task has succeeded.</param>
|
/// <param name="succeeded">Whether the task has succeeded.</param>
|
||||||
/// <param name="result">The result.</param>
|
/// <param name="result">The result.</param>
|
||||||
public void Deliver(bool succeeded, T result) {
|
public void Deliver(bool succeeded, T result) {
|
||||||
if (Destination != null) Destination(succeeded, result);
|
Destination?.Invoke(succeeded, result);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cancels the task.
|
/// Cancels the task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Cancel() {
|
public void Cancel() {
|
||||||
if (CancelSource != null) CancelSource();
|
CancelSource?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,8 +35,8 @@ namespace Cryville.Common {
|
|||||||
return null;
|
return null;
|
||||||
else if (type.IsAssignableFrom(value.GetType()))
|
else if (type.IsAssignableFrom(value.GetType()))
|
||||||
return value;
|
return value;
|
||||||
else if (type.IsEnum && value is string) {
|
else if (type.IsEnum && value is string strValue) {
|
||||||
return Enum.Parse(type, (string)value);
|
return Enum.Parse(type, strValue);
|
||||||
}
|
}
|
||||||
throw new InvalidCastException(string.Format("Cannot cast {0} to {1}", value.GetType(), type));
|
throw new InvalidCastException(string.Format("Cannot cast {0} to {1}", value.GetType(), type));
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ using System.Diagnostics;
|
|||||||
namespace Cryville.Common {
|
namespace Cryville.Common {
|
||||||
public class Coroutine {
|
public class Coroutine {
|
||||||
readonly IEnumerator<float> _enumerator;
|
readonly IEnumerator<float> _enumerator;
|
||||||
readonly Stopwatch _stopwatch = new Stopwatch();
|
readonly Stopwatch _stopwatch = new();
|
||||||
public float Progress { get; private set; }
|
public float Progress { get; private set; }
|
||||||
public Coroutine(IEnumerator<float> enumerator) {
|
public Coroutine(IEnumerator<float> enumerator) {
|
||||||
_enumerator = enumerator;
|
_enumerator = enumerator;
|
||||||
|
@@ -16,13 +16,11 @@ namespace Cryville.Common.Font {
|
|||||||
}
|
}
|
||||||
public void Close() { Reader.Close(); }
|
public void Close() { Reader.Close(); }
|
||||||
|
|
||||||
public static FontFile Create(FileInfo file) {
|
public static FontFile Create(FileInfo file) => file.Extension switch {
|
||||||
switch (file.Extension) {
|
".ttf" or ".otf" => new FontFileTTF(file),
|
||||||
case ".ttf": case ".otf": return new FontFileTTF(file);
|
".ttc" or ".otc" => new FontFileTTC(file),
|
||||||
case ".ttc": case ".otc": return new FontFileTTC(file);
|
_ => null,
|
||||||
default: return null;
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Enumerator GetEnumerator() {
|
public Enumerator GetEnumerator() {
|
||||||
return new Enumerator(this);
|
return new Enumerator(this);
|
||||||
@@ -42,7 +40,7 @@ namespace Cryville.Common.Font {
|
|||||||
_index = -1;
|
_index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Typeface Current {
|
public readonly Typeface Current {
|
||||||
get {
|
get {
|
||||||
if (_index < 0)
|
if (_index < 0)
|
||||||
throw new InvalidOperationException(_index == -1 ? "Enum not started" : "Enum ended");
|
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() {
|
public void Dispose() {
|
||||||
_index = -2;
|
_index = -2;
|
||||||
|
@@ -17,8 +17,7 @@ namespace Cryville.Common.Font {
|
|||||||
Shared.Logger.Log(3, "UI", "Discarding a font with a duplicate full name {0}", f.FullName);
|
Shared.Logger.Log(3, "UI", "Discarding a font with a duplicate full name {0}", f.FullName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<Typeface> set2;
|
if (!map2.TryGetValue(f.FamilyName, out List<Typeface> set2)) {
|
||||||
if (!map2.TryGetValue(f.FamilyName, out set2)) {
|
|
||||||
map2.Add(f.FamilyName, set2 = new List<Typeface>());
|
map2.Add(f.FamilyName, set2 = new List<Typeface>());
|
||||||
}
|
}
|
||||||
set2.Add(f);
|
set2.Add(f);
|
||||||
|
@@ -12,7 +12,7 @@ namespace Cryville.Common.Font {
|
|||||||
public class FallbackListFontMatcher : FontMatcher {
|
public class FallbackListFontMatcher : FontMatcher {
|
||||||
readonly LanguageMatching _matcher;
|
readonly LanguageMatching _matcher;
|
||||||
static readonly string UltimateFallbackScript = "zzzz";
|
static readonly string UltimateFallbackScript = "zzzz";
|
||||||
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
|
public Dictionary<string, List<string>> MapScriptToTypefaces = new();
|
||||||
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
|
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
|
||||||
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
var map = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||||
FillKeysWithScripts(map, () => new List<string>());
|
FillKeysWithScripts(map, () => new List<string>());
|
||||||
@@ -57,6 +57,7 @@ namespace Cryville.Common.Font {
|
|||||||
map["cher"].Insert(0, "Plantagenet");
|
map["cher"].Insert(0, "Plantagenet");
|
||||||
map["ethi"].Insert(0, "Nyala");
|
map["ethi"].Insert(0, "Nyala");
|
||||||
map["khmr"].Insert(0, "DaunPenh MoolBoran");
|
map["khmr"].Insert(0, "DaunPenh MoolBoran");
|
||||||
|
map["kore"].Insert(0, "Malgun Gothic"); // Reference: https://en.wikipedia.org/wiki/List_of_typefaces_included_with_Microsoft_Windows
|
||||||
map["laoo"].Insert(0, "DokChampa");
|
map["laoo"].Insert(0, "DokChampa");
|
||||||
map["mong"].Insert(0, "Mongolian Baiti");
|
map["mong"].Insert(0, "Mongolian Baiti");
|
||||||
map["orya"].Insert(0, "Kalinga");
|
map["orya"].Insert(0, "Kalinga");
|
||||||
@@ -332,8 +333,7 @@ namespace Cryville.Common.Font {
|
|||||||
yield return typeface1;
|
yield return typeface1;
|
||||||
}
|
}
|
||||||
if (distinctFamily) continue;
|
if (distinctFamily) continue;
|
||||||
IReadOnlyCollection<Typeface> typefaces2;
|
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out IReadOnlyCollection<Typeface> typefaces2)) {
|
||||||
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
|
|
||||||
foreach (var typeface in typefaces2) {
|
foreach (var typeface in typefaces2) {
|
||||||
if (typeface1 == typeface) continue;
|
if (typeface1 == typeface) continue;
|
||||||
yield return typeface;
|
yield return typeface;
|
||||||
|
@@ -25,7 +25,7 @@ namespace Cryville.Common.Font {
|
|||||||
readonly UInt16 majorVersion;
|
readonly UInt16 majorVersion;
|
||||||
readonly UInt16 minorVersion;
|
readonly UInt16 minorVersion;
|
||||||
readonly UInt32 numFonts;
|
readonly UInt32 numFonts;
|
||||||
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
|
readonly List<UInt32> tableDirectoryOffsets = new();
|
||||||
#pragma warning disable IDE0052 // Reserved
|
#pragma warning disable IDE0052 // Reserved
|
||||||
readonly String dsigTag;
|
readonly String dsigTag;
|
||||||
readonly UInt32 dsigLength;
|
readonly UInt32 dsigLength;
|
||||||
@@ -61,7 +61,7 @@ namespace Cryville.Common.Font {
|
|||||||
readonly UInt16 entrySelector;
|
readonly UInt16 entrySelector;
|
||||||
readonly UInt16 rangeShift;
|
readonly UInt16 rangeShift;
|
||||||
#pragma warning restore IDE0052 // Reserved
|
#pragma warning restore IDE0052 // Reserved
|
||||||
readonly List<TableRecord> tableRecords = new List<TableRecord>();
|
readonly List<TableRecord> tableRecords = new();
|
||||||
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
sfntVersion = reader.ReadUInt32();
|
sfntVersion = reader.ReadUInt32();
|
||||||
if (sfntVersion != 0x00010000 && sfntVersion != 0x4F54544F &&
|
if (sfntVersion != 0x00010000 && sfntVersion != 0x4F54544F &&
|
||||||
@@ -81,13 +81,11 @@ namespace Cryville.Common.Font {
|
|||||||
public override IReadOnlyList<TableRecord> GetItems() {
|
public override IReadOnlyList<TableRecord> GetItems() {
|
||||||
return tableRecords;
|
return tableRecords;
|
||||||
}
|
}
|
||||||
public override object GetSubTable(TableRecord item) {
|
public override object GetSubTable(TableRecord item) => item.tableTag switch {
|
||||||
switch (item.tableTag) {
|
"name" => new NameTable(Reader, item.offset),
|
||||||
case "name": return new NameTable(Reader, item.offset);
|
"meta" => new MetaTable(Reader, item.offset),
|
||||||
case "meta": return new MetaTable(Reader, item.offset);
|
_ => throw new NotImplementedException(),
|
||||||
default: throw new NotImplementedException();
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public struct TableRecord {
|
public struct TableRecord {
|
||||||
public string tableTag;
|
public string tableTag;
|
||||||
@@ -99,9 +97,9 @@ namespace Cryville.Common.Font {
|
|||||||
readonly UInt16 version;
|
readonly UInt16 version;
|
||||||
readonly UInt16 count;
|
readonly UInt16 count;
|
||||||
readonly UInt16 storageOffset;
|
readonly UInt16 storageOffset;
|
||||||
readonly List<NameRecord> nameRecord = new List<NameRecord>();
|
readonly List<NameRecord> nameRecord = new();
|
||||||
readonly UInt16 langTagCount;
|
readonly UInt16 langTagCount;
|
||||||
readonly List<LangTagRecord> langTagRecord = new List<LangTagRecord>();
|
readonly List<LangTagRecord> langTagRecord = new();
|
||||||
public NameTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
public NameTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
version = reader.ReadUInt16();
|
version = reader.ReadUInt16();
|
||||||
count = reader.ReadUInt16();
|
count = reader.ReadUInt16();
|
||||||
@@ -213,7 +211,7 @@ namespace Cryville.Common.Font {
|
|||||||
readonly UInt32 flags;
|
readonly UInt32 flags;
|
||||||
#pragma warning restore IDE0052 // Reserved
|
#pragma warning restore IDE0052 // Reserved
|
||||||
readonly UInt32 dataMapCount;
|
readonly UInt32 dataMapCount;
|
||||||
readonly List<DataMap> dataMaps = new List<DataMap>();
|
readonly List<DataMap> dataMaps = new();
|
||||||
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
version = reader.ReadUInt32();
|
version = reader.ReadUInt32();
|
||||||
if (version != 1) throw new NotSupportedException();
|
if (version != 1) throw new NotSupportedException();
|
||||||
|
@@ -25,7 +25,7 @@ namespace Cryville.Common {
|
|||||||
/// <param name="encoding">The encoding of the string.</param>
|
/// <param name="encoding">The encoding of the string.</param>
|
||||||
/// <returns>The string read from the reader.</returns>
|
/// <returns>The string read from the reader.</returns>
|
||||||
public static string ReadUInt16String(this BinaryReader reader, Encoding encoding = null) {
|
public static string ReadUInt16String(this BinaryReader reader, Encoding encoding = null) {
|
||||||
if (encoding == null) encoding = Encoding.UTF8;
|
encoding ??= Encoding.UTF8;
|
||||||
var len = reader.ReadUInt16();
|
var len = reader.ReadUInt16();
|
||||||
byte[] buffer = reader.ReadBytes(len);
|
byte[] buffer = reader.ReadBytes(len);
|
||||||
return encoding.GetString(buffer);
|
return encoding.GetString(buffer);
|
||||||
@@ -38,7 +38,7 @@ namespace Cryville.Common {
|
|||||||
/// <param name="value">The string to write by the writer.</param>
|
/// <param name="value">The string to write by the writer.</param>
|
||||||
/// <param name="encoding">The encoding of the string.</param>
|
/// <param name="encoding">The encoding of the string.</param>
|
||||||
public static void WriteUInt16String(this BinaryWriter writer, string value, Encoding encoding = null) {
|
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);
|
byte[] buffer = encoding.GetBytes(value);
|
||||||
writer.Write((ushort)buffer.Length);
|
writer.Write((ushort)buffer.Length);
|
||||||
writer.Write(buffer);
|
writer.Write(buffer);
|
||||||
|
@@ -2,26 +2,26 @@ using System;
|
|||||||
|
|
||||||
namespace Cryville.Common {
|
namespace Cryville.Common {
|
||||||
public struct Identifier : IEquatable<Identifier> {
|
public struct Identifier : IEquatable<Identifier> {
|
||||||
public static Identifier Empty = new Identifier(0);
|
public static Identifier Empty = new(0);
|
||||||
public int Key { get; private set; }
|
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) {
|
public Identifier(int key) {
|
||||||
Key = key;
|
Key = key;
|
||||||
}
|
}
|
||||||
public Identifier(object name) {
|
public Identifier(object name) {
|
||||||
Key = IdentifierManager.Shared.Request(name);
|
Key = IdentifierManager.Shared.Request(name);
|
||||||
}
|
}
|
||||||
public override bool Equals(object obj) {
|
public override readonly bool Equals(object obj) {
|
||||||
if (obj == null || !(obj is Identifier)) return false;
|
if (obj == null || obj is not Identifier other) return false;
|
||||||
return Equals((Identifier)obj);
|
return Equals(other);
|
||||||
}
|
}
|
||||||
public bool Equals(Identifier other) {
|
public readonly bool Equals(Identifier other) {
|
||||||
return Key == other.Key;
|
return Key == other.Key;
|
||||||
}
|
}
|
||||||
public override int GetHashCode() {
|
public override readonly int GetHashCode() {
|
||||||
return Key;
|
return Key;
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override readonly string ToString() {
|
||||||
if (Key == 0) return "";
|
if (Key == 0) return "";
|
||||||
return Name.ToString();
|
return Name.ToString();
|
||||||
}
|
}
|
||||||
|
@@ -42,13 +42,13 @@ namespace Cryville.Common.Math {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs dot operation with a <see cref="System.Single" /> column vector.
|
/// Performs dot operation with a <see cref="float" /> column vector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="lhs">The lefthand column vector.</param>
|
/// <param name="lhs">The lefthand column vector.</param>
|
||||||
/// <param name="o">The vector operator.</param>
|
/// <param name="o">The vector operator.</param>
|
||||||
/// <returns>The result of the dot operation.</returns>
|
/// <returns>The result of the dot operation.</returns>
|
||||||
public T Dot(ColumnVector<float> lhs, IVectorOperator<T> o) {
|
public T Dot(ColumnVector<float> lhs, IVectorOperator<T> o) {
|
||||||
T res = default(T);
|
T res = default;
|
||||||
for (var i = 0; i < Size; i++)
|
for (var i = 0; i < Size; i++)
|
||||||
res = o.Add(res, o.ScalarMultiply(lhs[i], content[i]));
|
res = o.Add(res, o.ScalarMultiply(lhs[i], content[i]));
|
||||||
return res;
|
return res;
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: f8303a3eeefeacf4ca0c02b5d32e0cff
|
|
||||||
folderAsset: yes
|
|
||||||
timeCreated: 1621071543
|
|
||||||
licenseType: Free
|
|
||||||
DefaultImporter:
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -1,156 +0,0 @@
|
|||||||
using Microsoft.Win32;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Network.Http11 {
|
|
||||||
public class Http11Client : IDisposable {
|
|
||||||
private readonly string _directHost;
|
|
||||||
protected string DirectHost { get { return _directHost; } }
|
|
||||||
|
|
||||||
private readonly int _directPort;
|
|
||||||
protected int DirectPort { get { return _directPort; } }
|
|
||||||
|
|
||||||
readonly Uri _baseUri;
|
|
||||||
readonly int origPort;
|
|
||||||
|
|
||||||
protected const string Version = "HTTP/1.1";
|
|
||||||
protected TcpClient TcpClient { get; private set; }
|
|
||||||
protected Stream RawTcpStream { get { return TcpClient.GetStream(); } }
|
|
||||||
protected virtual Stream Stream { get { return TcpClient.GetStream(); } }
|
|
||||||
protected virtual string WindowsProxyProtocolName { get { return "http"; } }
|
|
||||||
|
|
||||||
private readonly bool _proxied = false;
|
|
||||||
|
|
||||||
public Dictionary<string, string> Headers { get; set; }
|
|
||||||
|
|
||||||
public Http11Client(Uri baseUri, int port = 80) {
|
|
||||||
_directHost = baseUri.Host;
|
|
||||||
_directPort = port;
|
|
||||||
_baseUri = baseUri;
|
|
||||||
origPort = _baseUri.Port;
|
|
||||||
Headers = new Dictionary<string, string>();
|
|
||||||
_proxied = GetProxy(ref _directHost, ref _directPort);
|
|
||||||
Shared.Logger.Log(0, "Network", "Connecting to {0}:{1}", DirectHost, DirectPort);
|
|
||||||
TcpClient = new TcpClient(DirectHost, DirectPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Connect() {
|
|
||||||
if (_proxied) {
|
|
||||||
Request(RawTcpStream, "CONNECT", string.Format(CultureInfo.InvariantCulture, "{0}:{1}", _baseUri.Host, origPort));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Close() {
|
|
||||||
TcpClient.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Dispose(bool disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Http11Response Request(string method, Uri uri, string body = null, Encoding encoding = null) {
|
|
||||||
string struri = GetUri(uri).PathAndQuery;
|
|
||||||
return Request(Stream, method, struri, body, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
Http11Response Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
|
|
||||||
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
foreach (var h in Headers)
|
|
||||||
headers.Add(h.Key, h.Value);
|
|
||||||
headers["Host"] = _baseUri.Host;
|
|
||||||
byte[] payload = null;
|
|
||||||
if (body != null) {
|
|
||||||
if (encoding == null)
|
|
||||||
encoding = Encoding.UTF8;
|
|
||||||
payload = encoding.GetBytes(body);
|
|
||||||
headers.Add("Content-Encoding", encoding.EncodingName);
|
|
||||||
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
|
|
||||||
}
|
|
||||||
using (var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true)) {
|
|
||||||
writer.Write(method);
|
|
||||||
writer.Write(' ');
|
|
||||||
writer.Write(uri);
|
|
||||||
writer.Write(' ');
|
|
||||||
writer.Write(Version);
|
|
||||||
writer.Write("\r\n");
|
|
||||||
foreach (var header in headers) {
|
|
||||||
writer.Write(header.Key);
|
|
||||||
writer.Write(':');
|
|
||||||
writer.Write(header.Value);
|
|
||||||
writer.Write("\r\n");
|
|
||||||
}
|
|
||||||
writer.Write("\r\n");
|
|
||||||
if (payload != null) writer.Write(payload);
|
|
||||||
writer.Flush();
|
|
||||||
}
|
|
||||||
var response = new Http11Response(stream);
|
|
||||||
Shared.Logger.Log(0, "Network", "{0}", response);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool GetProxy(ref string host, ref int port) {
|
|
||||||
// TODO use winhttp.dll
|
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
|
|
||||||
var reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings");
|
|
||||||
var proxyEnable = (int)reg.GetValue("ProxyEnable");
|
|
||||||
if (proxyEnable == 0) return false;
|
|
||||||
var proxyStr = (string)reg.GetValue("ProxyServer");
|
|
||||||
if (!string.IsNullOrEmpty(proxyStr)) {
|
|
||||||
string[] proxies = proxyStr.Split(';');
|
|
||||||
foreach (var p in proxies) {
|
|
||||||
if (!p.Contains('=')) {
|
|
||||||
string[] s = p.Split(':');
|
|
||||||
host = s[0];
|
|
||||||
port = int.Parse(s[1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (p.StartsWith(WindowsProxyProtocolName + "=")) {
|
|
||||||
string[] s = p.Split('=', ':');
|
|
||||||
host = s[1];
|
|
||||||
port = int.Parse(s[2]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Uri GetUri(string path) {
|
|
||||||
Uri address;
|
|
||||||
if (_baseUri != null) {
|
|
||||||
if (!Uri.TryCreate(_baseUri, path, out address)) {
|
|
||||||
return new Uri(Path.GetFullPath(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!Uri.TryCreate(path, UriKind.Absolute, out address)) {
|
|
||||||
return new Uri(Path.GetFullPath(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return GetUri(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Uri GetUri(Uri address) {
|
|
||||||
if (address == null) {
|
|
||||||
throw new ArgumentNullException("address");
|
|
||||||
}
|
|
||||||
Uri uri = address;
|
|
||||||
if (!address.IsAbsoluteUri && _baseUri != null && !Uri.TryCreate(_baseUri, address, out uri)) {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,71 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Network.Http11 {
|
|
||||||
public class Http11Response : IDisposable {
|
|
||||||
static readonly char[] spchar = new char[]{ ' ' };
|
|
||||||
public string HttpVersion { get; private set; }
|
|
||||||
public string StatusCode { get; private set; }
|
|
||||||
public string ReasonPhase { get; private set; }
|
|
||||||
public Dictionary<string, string> Headers { get; private set; }
|
|
||||||
public Http11ResponseStream MessageBody { get; private set; }
|
|
||||||
internal Http11Response(Stream stream) {
|
|
||||||
var reader = new BinaryReader(stream, Encoding.ASCII);
|
|
||||||
var statu_line = ReadLine(reader).Split(spchar, 3);
|
|
||||||
HttpVersion = statu_line[0];
|
|
||||||
StatusCode = statu_line[1];
|
|
||||||
ReasonPhase = statu_line[2];
|
|
||||||
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
while (ParseHeader(reader, Headers)) ;
|
|
||||||
if (Headers.ContainsKey("content-length")) {
|
|
||||||
int length = int.Parse(Headers["content-length"]);
|
|
||||||
MessageBody = new Http11ResponseBlockStream(reader, length);
|
|
||||||
}
|
|
||||||
else if (Headers.ContainsKey("transfer-encoding") && Headers["transfer-encoding"] == "chunked") {
|
|
||||||
MessageBody = new Http11ResponseChunkedStream(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Dispose(bool disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
MessageBody.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString() {
|
|
||||||
return string.Format("<{0} {1} {2}>", HttpVersion, StatusCode, ReasonPhase);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static bool ParseHeader(BinaryReader reader, Dictionary<string, string> headers) {
|
|
||||||
// TODO Multiline header
|
|
||||||
var header = ReadLine(reader);
|
|
||||||
if (header == "") return false;
|
|
||||||
var s = header.Split(':', 2);
|
|
||||||
string field_name = s[0].Trim().ToLower();
|
|
||||||
string field_value = s[1].Trim();
|
|
||||||
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
|
|
||||||
else headers.Add(field_name, field_value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string ReadLine(BinaryReader reader) {
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
char c;
|
|
||||||
while (true) {
|
|
||||||
c = reader.ReadChar();
|
|
||||||
if (c == '\r') break;
|
|
||||||
result.Append(c);
|
|
||||||
}
|
|
||||||
// TODO Unseekable
|
|
||||||
reader.ReadByte();
|
|
||||||
return result.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,130 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Network.Http11 {
|
|
||||||
public abstract class Http11ResponseStream : Stream {
|
|
||||||
public override bool CanRead { get { return true; } }
|
|
||||||
|
|
||||||
public override bool CanSeek { get { return false; } }
|
|
||||||
|
|
||||||
public override bool CanWrite { get { return false; } }
|
|
||||||
|
|
||||||
public override long Length { get { throw new NotSupportedException(); } }
|
|
||||||
|
|
||||||
public override long Position {
|
|
||||||
get { throw new NotSupportedException(); }
|
|
||||||
set { throw new NotSupportedException(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Flush() { }
|
|
||||||
|
|
||||||
public abstract byte[] ReadToEnd();
|
|
||||||
|
|
||||||
public override long Seek(long offset, SeekOrigin origin) {
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetLength(long value) {
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(byte[] buffer, int offset, int count) {
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal sealed class Http11ResponseBlockStream : Http11ResponseStream {
|
|
||||||
readonly BinaryReader _reader;
|
|
||||||
readonly int _length;
|
|
||||||
int _pos = 0;
|
|
||||||
internal Http11ResponseBlockStream(BinaryReader reader, int length) {
|
|
||||||
_reader = reader;
|
|
||||||
_length = length;
|
|
||||||
}
|
|
||||||
public override int Read(byte[] buffer, int offset, int count) {
|
|
||||||
int recv = 0;
|
|
||||||
int recv_len = System.Math.Min(count, _length - _pos);
|
|
||||||
if (recv_len == 0) return 0;
|
|
||||||
while (recv < recv_len) {
|
|
||||||
recv += _reader.Read(buffer, offset + recv, count - recv);
|
|
||||||
}
|
|
||||||
_pos += recv_len;
|
|
||||||
return recv_len;
|
|
||||||
}
|
|
||||||
public override byte[] ReadToEnd() {
|
|
||||||
byte[] buffer = new byte[_length - _pos];
|
|
||||||
Read(buffer, 0, buffer.Length);
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal sealed class Http11ResponseChunkedStream : Http11ResponseStream {
|
|
||||||
readonly BinaryReader _reader;
|
|
||||||
byte[] _chunk = null;
|
|
||||||
int _pos = 0;
|
|
||||||
internal Http11ResponseChunkedStream(BinaryReader reader) {
|
|
||||||
_reader = reader;
|
|
||||||
ReadChunk();
|
|
||||||
}
|
|
||||||
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))
|
|
||||||
throw new IOException("Corrupted chunk received");
|
|
||||||
if (chunkSize == 0) {
|
|
||||||
_chunk = new byte[0];
|
|
||||||
// TODO TE Header, now just discard
|
|
||||||
var headers = new Dictionary<string, string>();
|
|
||||||
while (Http11Response.ParseHeader(_reader, headers)) ;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_chunk = new byte[chunkSize];
|
|
||||||
int recv = 0;
|
|
||||||
while (recv < chunkSize) {
|
|
||||||
recv += _reader.Read(_chunk, recv, chunkSize - recv);
|
|
||||||
}
|
|
||||||
_pos = 0;
|
|
||||||
if (Http11Response.ReadLine(_reader) != "")
|
|
||||||
throw new IOException("Corrupted chunk received");
|
|
||||||
}
|
|
||||||
public override int Read(byte[] buffer, int offset, int count) {
|
|
||||||
if (_chunk.Length == 0) return 0;
|
|
||||||
int recv = 0;
|
|
||||||
while (true) {
|
|
||||||
if (count - recv <= _chunk.Length - _pos) break;
|
|
||||||
Array.Copy(_chunk, _pos, buffer, recv, _chunk.Length - _pos);
|
|
||||||
recv += _chunk.Length - _pos;
|
|
||||||
ReadChunk();
|
|
||||||
if (_chunk.Length == 0) return recv;
|
|
||||||
}
|
|
||||||
Array.Copy(_chunk, _pos, buffer, recv, count - recv);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
public override byte[] ReadToEnd() {
|
|
||||||
if (_chunk.Length == 0) return new byte[0];
|
|
||||||
List<byte[]> segs = new List<byte[]>();
|
|
||||||
while (true) {
|
|
||||||
if (_pos != 0) {
|
|
||||||
var buffer = new byte[_chunk.Length - _pos];
|
|
||||||
Array.Copy(_chunk, _pos, buffer, 0, buffer.Length);
|
|
||||||
segs.Add(buffer);
|
|
||||||
}
|
|
||||||
else segs.Add(_chunk);
|
|
||||||
ReadChunk();
|
|
||||||
if (_chunk.Length == 0) {
|
|
||||||
var result = new byte[segs.Sum(i => i.Length)];
|
|
||||||
int p = 0;
|
|
||||||
foreach (var i in segs) {
|
|
||||||
Array.Copy(i, 0, result, p, i.Length);
|
|
||||||
p += i.Length;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Network.Http11 {
|
|
||||||
public class Https11Client : Http11Client {
|
|
||||||
readonly TlsClient _tlsClient;
|
|
||||||
|
|
||||||
protected override Stream Stream {
|
|
||||||
get {
|
|
||||||
return _tlsClient.Stream;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected override string WindowsProxyProtocolName {
|
|
||||||
get {
|
|
||||||
return "https";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Https11Client(Uri baseUri) : base(baseUri, 443) {
|
|
||||||
_tlsClient = new TlsClient(RawTcpStream, baseUri.Host);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Connect() {
|
|
||||||
base.Connect();
|
|
||||||
_tlsClient.Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Close() {
|
|
||||||
_tlsClient.Close();
|
|
||||||
base.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,96 +0,0 @@
|
|||||||
using Org.BouncyCastle.Security;
|
|
||||||
using Org.BouncyCastle.Tls;
|
|
||||||
using Org.BouncyCastle.Tls.Crypto;
|
|
||||||
using Org.BouncyCastle.Tls.Crypto.Impl.BC;
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Network {
|
|
||||||
public class TlsClient : IDisposable {
|
|
||||||
readonly TlsClientProtocol _protocol;
|
|
||||||
readonly BcTlsClient _tlsClient;
|
|
||||||
public Stream Stream { get; private set; }
|
|
||||||
public TlsClient(Stream baseStream, string hostname) {
|
|
||||||
_protocol = new TlsClientProtocol(baseStream);
|
|
||||||
_tlsClient = new InternalTlsClient(hostname, new BcTlsCrypto(new SecureRandom()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Connect() {
|
|
||||||
_protocol.Connect(_tlsClient);
|
|
||||||
Stream = _protocol.Stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close() {
|
|
||||||
_protocol.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Dispose(bool disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InternalTlsClient : DefaultTlsClient {
|
|
||||||
readonly string _host;
|
|
||||||
|
|
||||||
public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) {
|
|
||||||
_host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override ProtocolVersion[] GetSupportedVersions() {
|
|
||||||
return ProtocolVersion.TLSv13.DownTo(ProtocolVersion.TLSv12);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IList GetProtocolNames() {
|
|
||||||
IList list = new ArrayList {
|
|
||||||
ProtocolName.Http_1_1
|
|
||||||
};
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly int[] supportedCipherSuites = {
|
|
||||||
CipherSuite.TLS_AES_128_GCM_SHA256,
|
|
||||||
CipherSuite.TLS_AES_256_GCM_SHA384,
|
|
||||||
CipherSuite.TLS_CHACHA20_POLY1305_SHA256,
|
|
||||||
CipherSuite.TLS_AES_128_CCM_SHA256,
|
|
||||||
CipherSuite.TLS_AES_128_CCM_8_SHA256,
|
|
||||||
};
|
|
||||||
protected override int[] GetSupportedCipherSuites() {
|
|
||||||
return base.GetSupportedCipherSuites().Union(supportedCipherSuites).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IList GetSupportedSignatureAlgorithms() {
|
|
||||||
var result = base.GetSupportedSignatureAlgorithms();
|
|
||||||
result.Add(SignatureAndHashAlgorithm.ecdsa_brainpoolP256r1tls13_sha256);
|
|
||||||
result.Add(SignatureAndHashAlgorithm.ecdsa_brainpoolP384r1tls13_sha384);
|
|
||||||
result.Add(SignatureAndHashAlgorithm.ecdsa_brainpoolP512r1tls13_sha512);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IList GetSniServerNames() {
|
|
||||||
return new ArrayList { new ServerName(0, Encoding.ASCII.GetBytes(_host)) };
|
|
||||||
}
|
|
||||||
|
|
||||||
public override TlsAuthentication GetAuthentication() {
|
|
||||||
return new NullTlsAuthentication();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class NullTlsAuthentication : TlsAuthentication {
|
|
||||||
public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NotifyServerCertificate(TlsServerCertificate serverCertificate) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c9c242bb90fc1cc479a8df1407f21940
|
|
||||||
timeCreated: 1622021660
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -56,9 +56,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
while (ip != null) {
|
while (ip != null) {
|
||||||
bool nextFlag = false;
|
bool nextFlag = false;
|
||||||
var i = ip.Value;
|
var i = ip.Value;
|
||||||
if (i is PdtInstruction.Operate) {
|
if (i is PdtInstruction.Operate iop) {
|
||||||
int fc0 = _framecount;
|
int fc0 = _framecount;
|
||||||
int fc1 = ((PdtInstruction.Operate)i).Signature.ParamCount;
|
int fc1 = iop.Signature.ParamCount;
|
||||||
try { i.Execute(this, ref ip); } catch (Exception) { }
|
try { i.Execute(this, ref ip); } catch (Exception) { }
|
||||||
if (fc0 - _framecount == fc1) {
|
if (fc0 - _framecount == fc1) {
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -77,8 +77,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (i is PdtInstruction.Collapse) {
|
else if (i is PdtInstruction.Collapse t) {
|
||||||
var t = (PdtInstruction.Collapse)i;
|
|
||||||
try {
|
try {
|
||||||
var pins = ip;
|
var pins = ip;
|
||||||
i.Execute(this, ref ip);
|
i.Execute(this, ref ip);
|
||||||
@@ -133,15 +132,14 @@ namespace Cryville.Common.Pdt {
|
|||||||
exp.IsConstant = true;
|
exp.IsConstant = true;
|
||||||
exp.IsPotentialConstant = true;
|
exp.IsPotentialConstant = true;
|
||||||
for (var ins = il.First; ins != null; ins = ins.Next) {
|
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;
|
exp.IsConstant = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ReplaceIP(LinkedList<PdtInstruction> il, ref LinkedListNode<PdtInstruction> ip, PdtInstruction ins, Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>> cols) {
|
void ReplaceIP(LinkedList<PdtInstruction> il, ref LinkedListNode<PdtInstruction> ip, PdtInstruction ins, Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>> cols) {
|
||||||
List<PdtInstruction.Collapse> cins;
|
if (cols.TryGetValue(ip, out List<PdtInstruction.Collapse> cins)) cols.Remove(ip);
|
||||||
if (cols.TryGetValue(ip, out cins)) cols.Remove(ip);
|
|
||||||
ip = il.AddAfter(ip, ins);
|
ip = il.AddAfter(ip, ins);
|
||||||
il.Remove(ip.Previous);
|
il.Remove(ip.Previous);
|
||||||
if (cins != null) cols.Add(ip, cins);
|
if (cins != null) cols.Add(ip, cins);
|
||||||
@@ -163,8 +161,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
internal unsafe void PushVariable(int name, bool forced) {
|
internal unsafe void PushVariable(int name, bool forced) {
|
||||||
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
||||||
byte[] value;
|
GetVariable(name, forced, out frame->Type, out byte[] value);
|
||||||
GetVariable(name, forced, out frame->Type, out value);
|
|
||||||
frame->Offset = _goffset;
|
frame->Offset = _goffset;
|
||||||
frame->Length = value.Length;
|
frame->Length = value.Length;
|
||||||
Array.Copy(value, 0, _mem, _goffset, value.Length);
|
Array.Copy(value, 0, _mem, _goffset, value.Length);
|
||||||
|
@@ -114,7 +114,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public partial class PdtInterpreter {
|
public partial class PdtInterpreter {
|
||||||
static readonly Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
|
static readonly Dictionary<char, int> OP_PRIORITY = new() {
|
||||||
{ '@', 7 },
|
{ '@', 7 },
|
||||||
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
||||||
{ '+', 5 }, { '-', 5 },
|
{ '+', 5 }, { '-', 5 },
|
||||||
@@ -125,7 +125,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
{ ',', 0 },
|
{ ',', 0 },
|
||||||
{ '$', -1 },
|
{ '$', -1 },
|
||||||
};
|
};
|
||||||
static readonly Dictionary<char, int> OP_TYPE = new Dictionary<char, int> {
|
static readonly Dictionary<char, int> OP_TYPE = new() {
|
||||||
{ '@', 0 },
|
{ '@', 0 },
|
||||||
{ '*', 0 }, { '/', 0 }, { '%', 0 },
|
{ '*', 0 }, { '/', 0 }, { '%', 0 },
|
||||||
{ '+', 0 }, { '-', 0 },
|
{ '+', 0 }, { '-', 0 },
|
||||||
@@ -153,10 +153,10 @@ namespace Cryville.Common.Pdt {
|
|||||||
private struct PdtExpToken {
|
private struct PdtExpToken {
|
||||||
public CharCategory Type { get; set; }
|
public CharCategory Type { get; set; }
|
||||||
public string Value { 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);
|
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,
|
Type = CharCategory.Operator,
|
||||||
Value = "$",
|
Value = "$",
|
||||||
};
|
};
|
||||||
@@ -249,13 +249,12 @@ namespace Cryville.Common.Pdt {
|
|||||||
PdtExpToken? buf = null;
|
PdtExpToken? buf = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (buf != null && t.Type != CharCategory.OpeningBracket) {
|
if (buf != null && t.Type != CharCategory.OpeningBracket) {
|
||||||
PdtExpression def;
|
if (defs.TryGetValue(buf.Value.Value, out PdtExpression def)) {
|
||||||
if (defs.TryGetValue(buf.Value.Value, out def)) {
|
|
||||||
foreach (var i in def.Instructions) ins.AddLast(i);
|
foreach (var i in def.Instructions) ins.AddLast(i);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var name = buf.Value.Value;
|
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));
|
else ins.AddLast(new PdtInstruction.PushVariable(name));
|
||||||
}
|
}
|
||||||
buf = null;
|
buf = null;
|
||||||
|
@@ -65,7 +65,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Position { get; protected set; }
|
public int Position { get; protected set; }
|
||||||
|
|
||||||
readonly StringBuilder _sb = new StringBuilder();
|
readonly StringBuilder _sb = new();
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The character at the current position.
|
/// The character at the current position.
|
||||||
@@ -86,7 +86,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
protected string tokenb(CharCategory flag) {
|
protected string tokenb(CharCategory flag) {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
while ((ct & flag) == 0) Position++;
|
while ((ct & flag) == 0) Position++;
|
||||||
return Source.Substring(sp, Position - sp);
|
return Source[sp..Position];
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a token until a character that is not of type <paramref name="flag" /> is met.
|
/// Reads a token until a character that is not of type <paramref name="flag" /> is met.
|
||||||
@@ -97,7 +97,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
protected string tokenw(CharCategory flag) {
|
protected string tokenw(CharCategory flag) {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
while ((ct & flag) != 0) Position++;
|
while ((ct & flag) != 0) Position++;
|
||||||
return Source.Substring(sp, Position - sp);
|
return Source[sp..Position];
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Skips over whitespaces.
|
/// Skips over whitespaces.
|
||||||
@@ -163,7 +163,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
return new PdtExpression(ins);
|
return new PdtExpression(ins);
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly Dictionary<string, PdtExpression> defs = new Dictionary<string, PdtExpression>();
|
readonly Dictionary<string, PdtExpression> defs = new();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="PdtInterpreter" /> class.
|
/// Creates an instance of the <see cref="PdtInterpreter" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -186,8 +186,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
public object Interpret(Type type) {
|
public object Interpret(Type type) {
|
||||||
try {
|
try {
|
||||||
if (m_formatVersion == null) InterpretDirectives();
|
if (m_formatVersion == null) InterpretDirectives();
|
||||||
if (_binder == null)
|
_binder ??= BinderAttribute.CreateBinderOfType(type);
|
||||||
_binder = BinderAttribute.CreateBinderOfType(type);
|
|
||||||
return InterpretObject(type);
|
return InterpretObject(type);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@@ -256,18 +255,17 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
void InterpretObjectInternal<T>(bool pcflag, Type type, object pkey, object result, Func<Type, object> vfunc) where T : Attribute {
|
void InterpretObjectInternal<T>(bool pcflag, Type type, object pkey, object result, Func<Type, object> vfunc) where T : Attribute {
|
||||||
if (pcflag) {
|
if (pcflag) {
|
||||||
using (var collection = new PairCollection(result)) {
|
using var collection = new PairCollection(result);
|
||||||
var ktype = type.GetGenericArguments()[0];
|
var ktype = type.GetGenericArguments()[0];
|
||||||
var ptype = type.GetGenericArguments()[1];
|
var ptype = type.GetGenericArguments()[1];
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
object value = vfunc(ptype);
|
object value = vfunc(ptype);
|
||||||
collection.Add(key, value);
|
collection.Add(key, value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MemberInfo prop = null;
|
MemberInfo prop = null;
|
||||||
bool flag = false;
|
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) {
|
if (prop == null) {
|
||||||
prop = FieldLikeHelper.FindMemberWithAttribute<T>(type);
|
prop = FieldLikeHelper.FindMemberWithAttribute<T>(type);
|
||||||
flag = true;
|
flag = true;
|
||||||
@@ -279,13 +277,12 @@ namespace Cryville.Common.Pdt {
|
|||||||
if (origCollection == null) {
|
if (origCollection == null) {
|
||||||
FieldLikeHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
|
FieldLikeHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
|
||||||
}
|
}
|
||||||
using (var collection = new PairCollection(origCollection)) {
|
using var collection = new PairCollection(origCollection);
|
||||||
var ktype = ptype.GetGenericArguments()[0];
|
var ktype = ptype.GetGenericArguments()[0];
|
||||||
var vtype = ptype.GetGenericArguments()[1];
|
var vtype = ptype.GetGenericArguments()[1];
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
object value = vfunc(vtype);
|
object value = vfunc(vtype);
|
||||||
collection.Add(key, value);
|
collection.Add(key, value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else FieldLikeHelper.SetValue(prop, result, vfunc(ptype), _binder);
|
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,
|
src.Take(interpreter.Position).Count(c => c == '\n') + 1,
|
||||||
pos - lineStartPos + 1,
|
pos - lineStartPos + 1,
|
||||||
innerException == null ? "Unknown error" : innerException.Message,
|
innerException == null ? "Unknown error" : innerException.Message,
|
||||||
src.Substring(previewStartPos, previewEndPos - previewStartPos)
|
src[previewStartPos..previewEndPos]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -102,17 +102,17 @@ namespace Cryville.Common.Pdt {
|
|||||||
ParamCount = paramCount;
|
ParamCount = paramCount;
|
||||||
_hash = Name ^ ((ParamCount << 16) | (ParamCount >> 16));
|
_hash = Name ^ ((ParamCount << 16) | (ParamCount >> 16));
|
||||||
}
|
}
|
||||||
public override bool Equals(object obj) {
|
public override readonly bool Equals(object obj) {
|
||||||
if (!(obj is PdtOperatorSignature)) return false;
|
if (obj is not PdtOperatorSignature other) return false;
|
||||||
return Equals((PdtOperatorSignature)obj);
|
return Equals(other);
|
||||||
}
|
}
|
||||||
public bool Equals(PdtOperatorSignature other) {
|
public readonly bool Equals(PdtOperatorSignature other) {
|
||||||
return Name == other.Name && ParamCount == other.ParamCount;
|
return Name == other.Name && ParamCount == other.ParamCount;
|
||||||
}
|
}
|
||||||
public override int GetHashCode() {
|
public override readonly int GetHashCode() {
|
||||||
return _hash;
|
return _hash;
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override readonly string ToString() {
|
||||||
return string.Format("{0}({1})", IdentifierManager.Shared.Retrieve(Name), ParamCount);
|
return string.Format("{0}({1})", IdentifierManager.Shared.Retrieve(Name), ParamCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// Copies the memory in the span to another span.
|
/// Copies the memory in the span to another span.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dest">The destination span.</param>
|
/// <param name="dest">The destination span.</param>
|
||||||
public void CopyTo(PdtVariableMemory dest) {
|
public readonly void CopyTo(PdtVariableMemory dest) {
|
||||||
CopyTo(dest._ptr, 0, Length);
|
CopyTo(dest._ptr, 0, Length);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,7 +32,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dest">The destination buffer.</param>
|
/// <param name="dest">The destination buffer.</param>
|
||||||
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
||||||
public void CopyTo(byte[] dest, int destOffset) {
|
public readonly void CopyTo(byte[] dest, int destOffset) {
|
||||||
fixed (byte* ptr = dest) {
|
fixed (byte* ptr = dest) {
|
||||||
CopyTo(ptr, destOffset, Length);
|
CopyTo(ptr, destOffset, Length);
|
||||||
}
|
}
|
||||||
@@ -44,13 +44,13 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
||||||
/// <param name="length">The length to copy.</param>
|
/// <param name="length">The length to copy.</param>
|
||||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is greater than the length of the span.</exception>
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is greater than the length of the span.</exception>
|
||||||
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");
|
if (length > Length) throw new ArgumentOutOfRangeException("length");
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
dest[destOffset + i] = _ptr[i];
|
dest[destOffset + i] = _ptr[i];
|
||||||
}
|
}
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Equals(PdtVariableMemory obj) {
|
public readonly bool Equals(PdtVariableMemory obj) {
|
||||||
if (Type != obj.Type || Length != obj.Length) return false;
|
if (Type != obj.Type || Length != obj.Length) return false;
|
||||||
for (int i = 0; i < Length; i++) {
|
for (int i = 0; i < Length; i++) {
|
||||||
if (*(_ptr + i) != *(obj._ptr + i)) return false;
|
if (*(_ptr + i) != *(obj._ptr + i)) return false;
|
||||||
@@ -63,7 +63,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="offset">The offset on the span to start reading from.</param>
|
/// <param name="offset">The offset on the span to start reading from.</param>
|
||||||
/// <returns>A number.</returns>
|
/// <returns>A number.</returns>
|
||||||
/// <exception cref="InvalidCastException">The span at the offset does not represent a number.</exception>
|
/// <exception cref="InvalidCastException">The span at the offset does not represent a number.</exception>
|
||||||
public float AsNumber(int offset = 0) {
|
public readonly float AsNumber(int offset = 0) {
|
||||||
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
|
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
|
||||||
throw new InvalidCastException("Not a number");
|
throw new InvalidCastException("Not a number");
|
||||||
float value;
|
float value;
|
||||||
@@ -79,7 +79,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="offset">The offset from the start of the span.</param>
|
/// <param name="offset">The offset from the start of the span.</param>
|
||||||
/// <exception cref="InvalidCastException">The span at the offset does not represent a number.</exception>
|
/// <exception cref="InvalidCastException">The span at the offset does not represent a number.</exception>
|
||||||
/// <exception cref="InvalidOperationException">The length of the span is not sufficient.</exception>
|
/// <exception cref="InvalidOperationException">The length of the span is not sufficient.</exception>
|
||||||
public void SetNumber(float value, int offset = 0) {
|
public readonly void SetNumber(float value, int offset = 0) {
|
||||||
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
|
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
|
||||||
throw new InvalidCastException("Not a number");
|
throw new InvalidCastException("Not a number");
|
||||||
if (Length < sizeof(float) + offset)
|
if (Length < sizeof(float) + offset)
|
||||||
@@ -94,7 +94,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="offset">The offset on the span to start reading from.</param>
|
/// <param name="offset">The offset on the span to start reading from.</param>
|
||||||
/// <returns>A string.</returns>
|
/// <returns>A string.</returns>
|
||||||
/// <exception cref="InvalidCastException">The span at the offset does not represent a string.</exception>
|
/// <exception cref="InvalidCastException">The span at the offset does not represent a string.</exception>
|
||||||
public string AsString(int offset = 0) {
|
public readonly string AsString(int offset = 0) {
|
||||||
if (Type != PdtInternalType.String && Type != PdtInternalType.Array)
|
if (Type != PdtInternalType.String && Type != PdtInternalType.Array)
|
||||||
throw new InvalidCastException("Not a string");
|
throw new InvalidCastException("Not a string");
|
||||||
var len = *(int*)(_ptr + offset);
|
var len = *(int*)(_ptr + offset);
|
||||||
@@ -107,7 +107,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="offset">The offset from the start of the span.</param>
|
/// <param name="offset">The offset from the start of the span.</param>
|
||||||
/// <exception cref="InvalidCastException">The span at the offset does not represent a string.</exception>
|
/// <exception cref="InvalidCastException">The span at the offset does not represent a string.</exception>
|
||||||
/// <exception cref="InvalidOperationException">The length of the span is not sufficient.</exception>
|
/// <exception cref="InvalidOperationException">The length of the span is not sufficient.</exception>
|
||||||
public void SetString(string value, int offset = 0) {
|
public readonly void SetString(string value, int offset = 0) {
|
||||||
if (Type != PdtInternalType.String && Type != PdtInternalType.Array)
|
if (Type != PdtInternalType.String && Type != PdtInternalType.Array)
|
||||||
throw new InvalidCastException("Not a string");
|
throw new InvalidCastException("Not a string");
|
||||||
int strlen = value.Length;
|
int strlen = value.Length;
|
||||||
@@ -124,7 +124,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="offset">The offset on the span to start reading from.</param>
|
/// <param name="offset">The offset on the span to start reading from.</param>
|
||||||
/// <returns>The name of an undefined identifier.</returns>
|
/// <returns>The name of an undefined identifier.</returns>
|
||||||
/// <exception cref="InvalidCastException">The span does not represent an undefined identifier.</exception>
|
/// <exception cref="InvalidCastException">The span does not represent an undefined identifier.</exception>
|
||||||
public int AsIdentifier(int offset = 0) {
|
public readonly int AsIdentifier(int offset = 0) {
|
||||||
if (Type != PdtInternalType.Undefined && Type != PdtInternalType.Array)
|
if (Type != PdtInternalType.Undefined && Type != PdtInternalType.Array)
|
||||||
throw new InvalidCastException("Not an identifier");
|
throw new InvalidCastException("Not an identifier");
|
||||||
return *(int*)(_ptr + offset);
|
return *(int*)(_ptr + offset);
|
||||||
@@ -140,7 +140,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>Use <see cref="AsNumber(int)" /> instead while reading an unaligned number.</para>
|
/// <para>Use <see cref="AsNumber(int)" /> instead while reading an unaligned number.</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public T As<T>(int offset = 0) {
|
public readonly T As<T>(int offset = 0) {
|
||||||
var len = Unsafe.SizeOf<T>();
|
var len = Unsafe.SizeOf<T>();
|
||||||
if (offset >= Length)
|
if (offset >= Length)
|
||||||
throw new ArgumentOutOfRangeException("offset");
|
throw new ArgumentOutOfRangeException("offset");
|
||||||
@@ -159,7 +159,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>Use <see cref="SetNumber(float, int)" /> instead while writing an unaligned number.</para>
|
/// <para>Use <see cref="SetNumber(float, int)" /> instead while writing an unaligned number.</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void Set<T>(T value, int offset = 0) {
|
public readonly void Set<T>(T value, int offset = 0) {
|
||||||
var len = Unsafe.SizeOf<T>();
|
var len = Unsafe.SizeOf<T>();
|
||||||
if (offset >= Length)
|
if (offset >= Length)
|
||||||
throw new ArgumentOutOfRangeException("offset");
|
throw new ArgumentOutOfRangeException("offset");
|
||||||
@@ -173,7 +173,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="arrtype">The type of the array.</param>
|
/// <param name="arrtype">The type of the array.</param>
|
||||||
/// <param name="pc">The item count of the array.</param>
|
/// <param name="pc">The item count of the array.</param>
|
||||||
/// <exception cref="InvalidCastException">The span does not represent an array.</exception>
|
/// <exception cref="InvalidCastException">The span does not represent an array.</exception>
|
||||||
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)
|
if (Type != PdtInternalType.Vector && Type != PdtInternalType.Array)
|
||||||
throw new InvalidCastException("Not an array or vector");
|
throw new InvalidCastException("Not an array or vector");
|
||||||
arrtype = *(int*)(_ptr + Length - sizeof(int));
|
arrtype = *(int*)(_ptr + Length - sizeof(int));
|
||||||
@@ -186,7 +186,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="arrtype">The type of the array.</param>
|
/// <param name="arrtype">The type of the array.</param>
|
||||||
/// <param name="pc">The item count of the array.</param>
|
/// <param name="pc">The item count of the array.</param>
|
||||||
/// <exception cref="InvalidCastException">The span does not represent an array.</exception>
|
/// <exception cref="InvalidCastException">The span does not represent an array.</exception>
|
||||||
public void SetArraySuffix(int arrtype, int pc = 0) {
|
public readonly void SetArraySuffix(int arrtype, int pc = 0) {
|
||||||
if (Type != PdtInternalType.Vector && Type != PdtInternalType.Array)
|
if (Type != PdtInternalType.Vector && Type != PdtInternalType.Array)
|
||||||
throw new InvalidCastException("Not an array or vector");
|
throw new InvalidCastException("Not an array or vector");
|
||||||
*(int*)(_ptr + Length - sizeof(int)) = arrtype;
|
*(int*)(_ptr + Length - sizeof(int)) = arrtype;
|
||||||
|
@@ -6,15 +6,15 @@ namespace Cryville.Common {
|
|||||||
public T Value { get; set; }
|
public T Value { get; set; }
|
||||||
public string Unit { 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) {
|
public Qualified(T value, string unit) {
|
||||||
Value = value;
|
Value = value;
|
||||||
Unit = unit;
|
Unit = unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() { return ToString("G3"); }
|
public override readonly string ToString() { return ToString("G3"); }
|
||||||
public string ToString(string format) { return ToString(format, null); }
|
public readonly string ToString(string format) { return ToString(format, null); }
|
||||||
public string ToString(string format, IFormatProvider formatProvider) {
|
public readonly string ToString(string format, IFormatProvider formatProvider) {
|
||||||
double value = Value.ToDouble(formatProvider);
|
double value = Value.ToDouble(formatProvider);
|
||||||
int expIndex = (int)System.Math.Log10(value) / 3;
|
int expIndex = (int)System.Math.Log10(value) / 3;
|
||||||
if (expIndex == 0) {
|
if (expIndex == 0) {
|
||||||
|
@@ -2,6 +2,6 @@ using Cryville.Common.Logging;
|
|||||||
|
|
||||||
namespace Cryville.Common {
|
namespace Cryville.Common {
|
||||||
public static class Shared {
|
public static class Shared {
|
||||||
public static readonly Logger Logger = new Logger();
|
public static readonly Logger Logger = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ namespace Cryville.Common {
|
|||||||
/// <param name="s">The file name or file path.</param>
|
/// <param name="s">The file name or file path.</param>
|
||||||
/// <returns>The file name or file path with the extension removed.</returns>
|
/// <returns>The file name or file path with the extension removed.</returns>
|
||||||
public static string TrimExt(string s) {
|
public static string TrimExt(string s) {
|
||||||
return s.Substring(0, s.LastIndexOf("."));
|
return s[..s.LastIndexOf(".")];
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the value of a <see cref="TimeSpan" /> to a human-readable string.
|
/// Converts the value of a <see cref="TimeSpan" /> to a human-readable string.
|
||||||
@@ -52,12 +52,12 @@ namespace Cryville.Common {
|
|||||||
public static string GetProcessPathFromCommand(string command) {
|
public static string GetProcessPathFromCommand(string command) {
|
||||||
command = command.Trim();
|
command = command.Trim();
|
||||||
if (command[0] == '"') {
|
if (command[0] == '"') {
|
||||||
return command.Substring(1, command.IndexOf('"', 1) - 1);
|
return command[1..command.IndexOf('"', 1)];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int e = command.IndexOf(' ');
|
int e = command.IndexOf(' ');
|
||||||
if (e == -1) return command;
|
if (e == -1) return command;
|
||||||
else return command.Substring(0, e);
|
else return command[..e];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ namespace Cryville.Common.Unity {
|
|||||||
public class NetworkTaskWorker {
|
public class NetworkTaskWorker {
|
||||||
bool suspended;
|
bool suspended;
|
||||||
NetworkTask currentNetworkTask;
|
NetworkTask currentNetworkTask;
|
||||||
readonly Queue<NetworkTask> networkTasks = new Queue<NetworkTask>();
|
readonly Queue<NetworkTask> networkTasks = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current queued task count.
|
/// Current queued task count.
|
||||||
|
@@ -30,13 +30,13 @@ namespace Cryville.Common.Unity {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
public string Attribute;
|
public string Attribute;
|
||||||
|
|
||||||
public bool Equals(AttributeBinding other) {
|
public readonly bool Equals(AttributeBinding other) {
|
||||||
return Component.Equals(other.Component) && Attribute.Equals(other.Attribute);
|
return Component.Equals(other.Component) && Attribute.Equals(other.Attribute);
|
||||||
}
|
}
|
||||||
public override bool Equals(object obj) {
|
public override readonly bool Equals(object obj) {
|
||||||
return obj is AttributeBinding && Equals((AttributeBinding)obj);
|
return obj is AttributeBinding other && Equals(other);
|
||||||
}
|
}
|
||||||
public override int GetHashCode() {
|
public override readonly int GetHashCode() {
|
||||||
return Component.GetHashCode() ^ Attribute.GetHashCode();
|
return Component.GetHashCode() ^ Attribute.GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,10 +44,10 @@ namespace Cryville.Common.Unity {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
StateTweener[] m_children;
|
StateTweener[] m_children;
|
||||||
|
|
||||||
readonly List<string> _statePriority = new List<string>();
|
readonly List<string> _statePriority = new();
|
||||||
readonly Dictionary<AttributeBinding, object> _defaults = new Dictionary<AttributeBinding, object>();
|
readonly Dictionary<AttributeBinding, object> _defaults = new();
|
||||||
readonly Dictionary<AttributeBinding, PropertyTweener<object>> _tweeners = new Dictionary<AttributeBinding, PropertyTweener<object>>();
|
readonly Dictionary<AttributeBinding, PropertyTweener<object>> _tweeners = new();
|
||||||
readonly Dictionary<string, Dictionary<AttributeBinding, object>> _runtimeStates = new Dictionary<string, Dictionary<AttributeBinding, object>>();
|
readonly Dictionary<string, Dictionary<AttributeBinding, object>> _runtimeStates = new();
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
var types = new Dictionary<AttributeBinding, Type>();
|
var types = new Dictionary<AttributeBinding, Type>();
|
||||||
@@ -130,7 +130,7 @@ namespace Cryville.Common.Unity {
|
|||||||
foreach (var tweener in _tweeners) tweener.Value.Advance(Time.deltaTime);
|
foreach (var tweener in _tweeners) tweener.Value.Advance(Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly List<string> m_cState = new List<string>();
|
readonly List<string> m_cState = new();
|
||||||
public IReadOnlyList<string> CurrentState => m_cState;
|
public IReadOnlyList<string> CurrentState => m_cState;
|
||||||
public void ClearState(float transitionDuration = float.Epsilon) {
|
public void ClearState(float transitionDuration = float.Epsilon) {
|
||||||
foreach (var child in m_children) child.ClearState(transitionDuration);
|
foreach (var child in m_children) child.ClearState(transitionDuration);
|
||||||
@@ -161,7 +161,7 @@ namespace Cryville.Common.Unity {
|
|||||||
if (index < 0) return;
|
if (index < 0) return;
|
||||||
m_cState.RemoveAt(index);
|
m_cState.RemoveAt(index);
|
||||||
if (index < m_cState.Count) return;
|
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) {
|
foreach (var tweener in _tweeners) {
|
||||||
tweener.Value.Start(attrs[tweener.Key], transitionDuration);
|
tweener.Value.Start(attrs[tweener.Key], transitionDuration);
|
||||||
}
|
}
|
||||||
|
18
Assets/Cryville/Common/Unity/UI/CanvasRendererColorLinker.cs
Normal file
18
Assets/Cryville/Common/Unity/UI/CanvasRendererColorLinker.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity.UI {
|
||||||
|
[ExecuteAlways]
|
||||||
|
[RequireComponent(typeof(CanvasRenderer))]
|
||||||
|
public class CanvasRendererColorLinker : MonoBehaviour {
|
||||||
|
[SerializeField] CanvasRenderer m_source;
|
||||||
|
CanvasRenderer _target;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
_target = GetComponent<CanvasRenderer>();
|
||||||
|
}
|
||||||
|
void Update() {
|
||||||
|
if (m_source == null) return;
|
||||||
|
_target.SetColor(m_source.GetColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 49a8d5b9869e5bb42bafbe71f84fecc5
|
guid: 5f490a9cc1b652746b3062810e200ec5
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -113,7 +113,7 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
private bool initialized;
|
private bool initialized;
|
||||||
private GameObject[][] lines;
|
private GameObject[][] lines;
|
||||||
private int[] refl;
|
private int[] refl;
|
||||||
Vector2 cpos = new Vector2(0, 1);
|
Vector2 cpos = new(0, 1);
|
||||||
Vector2 pprectsize;
|
Vector2 pprectsize;
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
#pragma warning disable IDE0051
|
||||||
|
@@ -35,8 +35,7 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
if (MaxFallbackCount <= 0) break;
|
if (MaxFallbackCount <= 0) break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_font.fallbackFontAssetTable == null)
|
_font.fallbackFontAssetTable ??= new List<FontAsset>();
|
||||||
_font.fallbackFontAssetTable = new List<FontAsset>();
|
|
||||||
_font.fallbackFontAssetTable.Add(ifont);
|
_font.fallbackFontAssetTable.Add(ifont);
|
||||||
Shared.Logger.Log(1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
|
Shared.Logger.Log(1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
|
||||||
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
|
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
|
||||||
|
@@ -1,8 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Cryville.Common.Unity {
|
namespace Cryville.Common.Unity {
|
||||||
public static class UrlOpener {
|
public static class UrlOpener {
|
||||||
public static void Open(string url) {
|
public static void Open(string url) {
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
System.Diagnostics.Process.Start(url);
|
url += "\0";
|
||||||
|
unsafe {
|
||||||
|
fixed (char* lpFile = url) {
|
||||||
|
var info = new SHELLEXECUTEINFOW {
|
||||||
|
cbSize = (uint)sizeof(SHELLEXECUTEINFOW),
|
||||||
|
fMask = 0x0540,
|
||||||
|
lpFile = lpFile,
|
||||||
|
nShow = 1,
|
||||||
|
};
|
||||||
|
ShellExecuteExW(ref info);
|
||||||
|
}
|
||||||
|
}
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
|
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
|
||||||
clazz.CallStatic("open", url);
|
clazz.CallStatic("open", url);
|
||||||
@@ -22,5 +36,27 @@ namespace Cryville.Common.Unity {
|
|||||||
#error Unknown platform.
|
#error Unknown platform.
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
[DllImport("shell32.dll")]
|
||||||
|
static extern void ShellExecuteExW(ref SHELLEXECUTEINFOW pExecInfo);
|
||||||
|
unsafe struct SHELLEXECUTEINFOW {
|
||||||
|
public uint cbSize;
|
||||||
|
public uint fMask;
|
||||||
|
public IntPtr hwnd;
|
||||||
|
public char* lpVerb;
|
||||||
|
public char* lpFile;
|
||||||
|
public char* lpParameters;
|
||||||
|
public char* lpDirectory;
|
||||||
|
public int nShow;
|
||||||
|
public IntPtr hInstApp;
|
||||||
|
public IntPtr lpIDList;
|
||||||
|
public IntPtr lpClass;
|
||||||
|
public IntPtr hkeyClass;
|
||||||
|
public uint dwHotKey;
|
||||||
|
public IntPtr hIconMonitor;
|
||||||
|
public IntPtr hProcess;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ namespace Cryville.Crtr {
|
|||||||
public int d;
|
public int d;
|
||||||
|
|
||||||
[JsonIgnore]
|
[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) {
|
public int CompareTo(BeatTime other) {
|
||||||
var c = b.CompareTo(other.b);
|
var c = b.CompareTo(other.b);
|
||||||
@@ -34,15 +34,15 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj) {
|
public override bool Equals(object obj) {
|
||||||
if (!(obj is BeatTime)) return false;
|
if (obj is not BeatTime other) return false;
|
||||||
return Equals((BeatTime)obj);
|
return Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(BeatTime other) {
|
public bool Equals(BeatTime other) {
|
||||||
return b.Equals(other.b) && ((double)n / d).Equals((double)other.n / other.d);
|
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();
|
return Decimal.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,54 +4,63 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Browsing.Actions {
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
public class ActionManager {
|
public class ActionManager {
|
||||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new Dictionary<Type, List<IResourceAction>>();
|
readonly Dictionary<Type, List<IResourceAction>> _actions = new();
|
||||||
|
readonly Dictionary<IResourceAction, int> _refCounts = new();
|
||||||
|
|
||||||
public event Action Changed;
|
public event Action Changed;
|
||||||
|
|
||||||
class ActionPriorityComparer : IComparer<IResourceAction> {
|
class ActionPriorityComparer : IComparer<IResourceAction> {
|
||||||
public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
|
public static readonly ActionPriorityComparer Instance = new();
|
||||||
public int Compare(IResourceAction x, IResourceAction y) {
|
public int Compare(IResourceAction x, IResourceAction y) {
|
||||||
return x.Priority.CompareTo(y.Priority);
|
return x.Priority.CompareTo(y.Priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Register(Type type, IResourceAction action) {
|
void Register(Type type, IResourceAction action) {
|
||||||
List<IResourceAction> actions;
|
if (!_actions.TryGetValue(type, out List<IResourceAction> actions)) {
|
||||||
if (!_actions.TryGetValue(type, out actions)) {
|
|
||||||
_actions.Add(type, actions = new List<IResourceAction>());
|
_actions.Add(type, actions = new List<IResourceAction>());
|
||||||
}
|
}
|
||||||
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
||||||
if (index < 0) index = ~index;
|
if (index < 0) index = ~index;
|
||||||
actions.Insert(index, action);
|
actions.Insert(index, action);
|
||||||
|
if (_refCounts.ContainsKey(action)) _refCounts[action]++;
|
||||||
|
else _refCounts[action] = 1;
|
||||||
Changed?.Invoke();
|
Changed?.Invoke();
|
||||||
}
|
}
|
||||||
public void Register(IResourceAction action) {
|
public void Register(IResourceAction action) {
|
||||||
Register(typeof(object), action);
|
Register(typeof(object), action);
|
||||||
}
|
}
|
||||||
public void Register<T>(IResourceAction<T> action) {
|
public void Register<T>(IResourceAction<T> action) where T : IResourceMeta {
|
||||||
Register(typeof(T), action);
|
Register(typeof(T), action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unregister(Type type, IResourceAction action) {
|
public void Unregister(Type type, IResourceAction action) {
|
||||||
List<IResourceAction> actions;
|
if (!_actions.TryGetValue(type, out List<IResourceAction> actions)) return;
|
||||||
if (!_actions.TryGetValue(type, out actions)) return;
|
if (--_refCounts[action] > 0) return;
|
||||||
actions.Remove(action);
|
actions.Remove(action);
|
||||||
Changed?.Invoke();
|
Changed?.Invoke();
|
||||||
}
|
}
|
||||||
public void Unregister(IResourceAction action) {
|
public void Unregister(IResourceAction action) {
|
||||||
Unregister(typeof(object), action);
|
Unregister(typeof(object), action);
|
||||||
}
|
}
|
||||||
public void Unregister<T>(IResourceAction<T> action) {
|
public void Unregister<T>(IResourceAction<T> action) where T : IResourceMeta {
|
||||||
Unregister(typeof(T), action);
|
Unregister(typeof(T), action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IResourceAction> GetActions(Type type) {
|
public IEnumerable<IResourceAction> GetActions(Uri uri, IResourceMeta res) {
|
||||||
List<IResourceAction> actions;
|
return GetActions(uri, res, res.GetType());
|
||||||
if (!_actions.TryGetValue(type, out actions)) {
|
}
|
||||||
actions = new List<IResourceAction>();
|
IEnumerable<IResourceAction> GetActions(Uri uri, IResourceMeta res, Type type) {
|
||||||
}
|
if (type == null) return Enumerable.Empty<IResourceAction>();
|
||||||
IEnumerable<IResourceAction> result = actions;
|
IEnumerable<IResourceAction> result;
|
||||||
if (type != typeof(object)) result = result.Concat(GetActions(type.BaseType));
|
if (_actions.TryGetValue(type, out List<IResourceAction> actions))
|
||||||
|
result = actions.Where(i => i.CanInvoke(uri, res));
|
||||||
|
else
|
||||||
|
result = Enumerable.Empty<IResourceAction>();
|
||||||
|
if (type != typeof(object))
|
||||||
|
result = result
|
||||||
|
.Concat(GetActions(uri, res, type.BaseType))
|
||||||
|
.Concat(type.GetInterfaces().SelectMany(i => GetActions(uri, res, i)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,12 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
public interface IResourceAction {
|
public interface IResourceAction {
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
int Priority { get; }
|
int Priority { get; }
|
||||||
void Invoke(Uri uri, object resource);
|
|
||||||
|
bool CanInvoke(Uri uri, IResourceMeta resource);
|
||||||
|
void Invoke(Uri uri, IResourceMeta resource);
|
||||||
}
|
}
|
||||||
public interface IResourceAction<T> : IResourceAction {
|
public interface IResourceAction<T> : IResourceAction where T : IResourceMeta {
|
||||||
|
bool CanInvoke(Uri uri, T resource);
|
||||||
void Invoke(Uri uri, T resource);
|
void Invoke(Uri uri, T resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,15 +3,18 @@ using System;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Browsing.Actions {
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
internal class ImportResourceAction : IResourceAction {
|
internal class ImportResourceAction : IResourceAction {
|
||||||
readonly IResourceManager _destination;
|
readonly IResourceDestination _destination;
|
||||||
public ImportResourceAction(IResourceManager destination) {
|
public ImportResourceAction(IResourceDestination destination) {
|
||||||
_destination = destination;
|
_destination = destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get { return "Import"; } }
|
public string Name { get { return "Import"; } }
|
||||||
public int Priority { get { return 0; } }
|
public int Priority { get { return 0; } }
|
||||||
|
|
||||||
public void Invoke(Uri uri, object resource) {
|
public bool CanInvoke(Uri uri, IResourceMeta resource) {
|
||||||
|
return _destination.CanImport(uri);
|
||||||
|
}
|
||||||
|
public void Invoke(Uri uri, IResourceMeta resource) {
|
||||||
if (_destination.ImportFrom(uri))
|
if (_destination.ImportFrom(uri))
|
||||||
Popup.Create("Import succeeded");
|
Popup.Create("Import succeeded");
|
||||||
else
|
else
|
||||||
|
@@ -1,34 +1,43 @@
|
|||||||
using Cryville.Crtr.Browsing.UI;
|
using Cryville.Crtr.Browsing.UI;
|
||||||
using Cryville.Crtr.UI;
|
using Cryville.Crtr.Config;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing.Actions {
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
internal class OpenConfigAction : ResourceAction<ChartDetail> {
|
internal class OpenConfigAction : ResourceAction<IChartDetail> {
|
||||||
public override string Name { get { return "Config"; } }
|
public override string Name { get { return "Config"; } }
|
||||||
|
|
||||||
public override int Priority { get { return -50; } }
|
public override int Priority { get { return -50; } }
|
||||||
|
|
||||||
static Dictionary<string, int> _rulesetTabs = new Dictionary<string, int>();
|
static readonly Dictionary<string, int> _rulesetTabs = new();
|
||||||
|
|
||||||
public override void Invoke(Uri uri, ChartDetail resource) {
|
public override bool CanInvoke(Uri uri, IChartDetail resource) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public override void Invoke(Uri uri, IChartDetail resource) {
|
||||||
|
Invoke(resource.RulesetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasTab(string ruleset) {
|
||||||
var master = ResourceBrowserMaster.Instance;
|
var master = ResourceBrowserMaster.Instance;
|
||||||
var ruleset = resource.Meta.ruleset;
|
if (master == null) return false;
|
||||||
int tabId;
|
return _rulesetTabs.TryGetValue(ruleset, out int tabId) && master.HasTab(tabId);
|
||||||
if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
|
}
|
||||||
|
public static void Invoke(string ruleset, Action<RulesetConfig> overrides = null) {
|
||||||
|
var master = ResourceBrowserMaster.Instance;
|
||||||
|
if (_rulesetTabs.TryGetValue(ruleset, out int tabId) && master.TryOpenTab(tabId))
|
||||||
return;
|
return;
|
||||||
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
||||||
try {
|
try {
|
||||||
browser.Load(ruleset);
|
browser.Load(ruleset, overrides);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception) {
|
||||||
Dialog.Show(null, ex.Message);
|
|
||||||
Game.MainLogger.Log(4, "Config", "An error occurred while loading the config: {0}", ex);
|
|
||||||
Object.Destroy(browser.gameObject);
|
Object.Destroy(browser.gameObject);
|
||||||
return;
|
throw;
|
||||||
}
|
}
|
||||||
_rulesetTabs[ruleset] = master.AddAndOpenTab(string.Format("Config: {0}", ruleset), browser);
|
_rulesetTabs[ruleset] = master.AddAndOpenTab(string.Format("{0} (Config)", ruleset), browser);
|
||||||
|
browser.InitAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,13 +4,16 @@ using System.IO;
|
|||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing.Actions {
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
internal class PlayChartAction : ResourceAction<ChartDetail> {
|
internal class PlayChartAction : ResourceAction<IChartDetail> {
|
||||||
public override string Name { get { return "Play"; } }
|
public override string Name { get { return "Play"; } }
|
||||||
public override int Priority { get { return -100; } }
|
public override int Priority { get { return -100; } }
|
||||||
|
|
||||||
public override void Invoke(Uri uri, ChartDetail resource) {
|
public override bool CanInvoke(Uri uri, IChartDetail resource) {
|
||||||
Settings.Default.LoadRuleset = Path.Combine(resource.Meta.ruleset, ".umgr");
|
return true;
|
||||||
Settings.Default.LoadRulesetConfig = resource.Meta.ruleset + ".json";
|
}
|
||||||
|
public override void Invoke(Uri uri, IChartDetail resource) {
|
||||||
|
Settings.Default.LoadRuleset = Path.Combine(resource.RulesetId, ".umgr");
|
||||||
|
Settings.Default.LoadRulesetConfig = resource.RulesetId + ".json";
|
||||||
Settings.Default.LoadChart = uri.LocalPath;
|
Settings.Default.LoadChart = uri.LocalPath;
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
||||||
@@ -19,7 +22,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
|||||||
#endif
|
#endif
|
||||||
Master.Instance.HideMenu();
|
Master.Instance.HideMenu();
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", resource.Meta.song.name, resource.Meta.name), resource.Meta.length);
|
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", resource.SongName, resource.Name), resource.Length.TotalSeconds);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing.Actions {
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
public abstract class ResourceAction<T> : IResourceAction<T> {
|
public abstract class ResourceAction<T> : IResourceAction<T> where T : IResourceMeta {
|
||||||
public abstract string Name { get; }
|
public abstract string Name { get; }
|
||||||
public abstract int Priority { get; }
|
public abstract int Priority { get; }
|
||||||
public abstract void Invoke(Uri uri, T resource);
|
|
||||||
public void Invoke(Uri uri, object resource) {
|
public abstract bool CanInvoke(Uri uri, T resource);
|
||||||
|
public bool CanInvoke(Uri uri, IResourceMeta resource) {
|
||||||
if (resource == null) throw new ArgumentNullException("resource");
|
if (resource == null) throw new ArgumentNullException("resource");
|
||||||
if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
|
if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
|
||||||
Invoke(uri, (T)resource);
|
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 not T res) throw new ArgumentException("Mismatched resource type.");
|
||||||
|
Invoke(uri, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
Assets/Cryville/Crtr/Browsing/Actions/UseSkinAction.cs
Normal file
33
Assets/Cryville/Crtr/Browsing/Actions/UseSkinAction.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using Cryville.Crtr.Browsing.UI;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.Actions {
|
||||||
|
internal class UseSkinAction : ResourceAction<ISkinDetail> {
|
||||||
|
readonly RulesetConfigBrowser _destination;
|
||||||
|
public UseSkinAction() : this(null) { }
|
||||||
|
public UseSkinAction(RulesetConfigBrowser destination) {
|
||||||
|
_destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name { get { return "Use"; } }
|
||||||
|
|
||||||
|
public override int Priority { get { return -100; } }
|
||||||
|
|
||||||
|
public override bool CanInvoke(Uri uri, ISkinDetail resource) {
|
||||||
|
if (_destination == null) {
|
||||||
|
return !OpenConfigAction.HasTab(resource.RulesetId);
|
||||||
|
}
|
||||||
|
return _destination.RulesetName == resource.RulesetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Invoke(Uri uri, ISkinDetail resource) {
|
||||||
|
if (_destination == null) {
|
||||||
|
OpenConfigAction.Invoke(resource.RulesetId, config => config.generic.Skin = resource.Name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_destination.SetSkin(resource.Name);
|
||||||
|
OpenConfigAction.Invoke(resource.RulesetId, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: c5c233e6228ce204fa1a9724c48ac8fe
|
guid: ac898133ecfdb3f42bdade958381cd1a
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -8,23 +8,25 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
internal static class ExtensionManager {
|
internal static class ExtensionManager {
|
||||||
|
static bool _init;
|
||||||
static readonly Dictionary<string, List<ResourceConverter>> _converters
|
static readonly Dictionary<string, List<ResourceConverter>> _converters
|
||||||
= new Dictionary<string, List<ResourceConverter>>();
|
= new();
|
||||||
public static ISet<string> GetSupportedFormats() {
|
public static ISet<string> GetSupportedFormats() {
|
||||||
return new HashSet<string>(_converters.Keys);
|
return new HashSet<string>(_converters.Keys);
|
||||||
}
|
}
|
||||||
public static bool TryGetConverters(string extension, out IEnumerable<ResourceConverter> converters) {
|
public static bool TryGetConverters(string extension, out IEnumerable<ResourceConverter> converters) {
|
||||||
List<ResourceConverter> outResult;
|
bool result = _converters.TryGetValue(extension, out List<ResourceConverter> outResult);
|
||||||
bool result = _converters.TryGetValue(extension, out outResult);
|
|
||||||
converters = outResult;
|
converters = outResult;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
static readonly Dictionary<string, string> _localRes
|
static readonly Dictionary<string, string> _localRes
|
||||||
= new Dictionary<string, string>();
|
= new();
|
||||||
public static IReadOnlyDictionary<string, string> GetLocalResourcePaths() {
|
public static IReadOnlyDictionary<string, string> GetLocalResourcePaths() {
|
||||||
return _localRes;
|
return _localRes;
|
||||||
}
|
}
|
||||||
public static void Init(string rootPath) {
|
public static void Init(string rootPath) {
|
||||||
|
if (_init) return;
|
||||||
|
_init = true;
|
||||||
LoadExtension(typeof(Extensions.Extension));
|
LoadExtension(typeof(Extensions.Extension));
|
||||||
var asms = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToHashSet();
|
var asms = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToHashSet();
|
||||||
var modules = new Queue<ModuleItem>();
|
var modules = new Queue<ModuleItem>();
|
||||||
@@ -59,8 +61,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
var buf = new byte[stream.Length];
|
var buf = new byte[stream.Length];
|
||||||
stream.Read(buf, 0, buf.Length);
|
stream.Read(buf, 0, buf.Length);
|
||||||
var asm = Assembly.Load(buf);
|
var asm = Assembly.Load(buf) ?? throw new TypeLoadException("Failed to load the module");
|
||||||
if (asm == null) throw new TypeLoadException("Failed to load the module");
|
|
||||||
asms.Add(asm.GetName().Name);
|
asms.Add(asm.GetName().Name);
|
||||||
foreach (var type in asm.GetTypes()) {
|
foreach (var type in asm.GetTypes()) {
|
||||||
if (typeof(ExtensionInterface).IsAssignableFrom(type)) {
|
if (typeof(ExtensionInterface).IsAssignableFrom(type)) {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
using Cryville.Crtr.UI;
|
using Cryville.Crtr.UI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -16,7 +17,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
public FileSystemEntry this[int index] { get { return _filteredItems[index]; } }
|
public FileSystemEntry this[int index] { get { return _filteredItems[index]; } }
|
||||||
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
|
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
|
||||||
|
|
||||||
readonly List<string> _dirParts = new List<string>();
|
readonly List<string> _dirParts = new();
|
||||||
readonly IList<string> m_dirParts;
|
readonly IList<string> m_dirParts;
|
||||||
public IList<string> CurrentDirectory { get { return m_dirParts; } }
|
public IList<string> CurrentDirectory { get { return m_dirParts; } }
|
||||||
public int Count { get { return _filteredItems.Length; } }
|
public int Count { get { return _filteredItems.Length; } }
|
||||||
@@ -118,7 +119,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
ItemChanged?.Invoke();
|
ItemChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ImportFrom(Uri uri) { throw new NotSupportedException(); }
|
public IResourceAction GetImportAction() { throw new NotSupportedException(); }
|
||||||
public void RemoveAt(int index) { throw new NotSupportedException(); }
|
public void RemoveAt(int index) { throw new NotSupportedException(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,8 +136,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
public IEnumerable<MetaProperty> Properties {
|
public IEnumerable<MetaProperty> Properties {
|
||||||
get {
|
get {
|
||||||
yield return new MetaProperty("Name", _name);
|
yield return new MetaProperty("Name", _name);
|
||||||
if (FileSystemInfo is FileInfo) {
|
if (FileSystemInfo is FileInfo file) {
|
||||||
var file = (FileInfo)FileSystemInfo;
|
|
||||||
yield return new MetaProperty("Size", new Qualified<long>(file.Length, "B"));
|
yield return new MetaProperty("Size", new Qualified<long>(file.Length, "B"));
|
||||||
}
|
}
|
||||||
yield return new MetaProperty("Write.Time", FileSystemInfo.LastWriteTime);
|
yield return new MetaProperty("Write.Time", FileSystemInfo.LastWriteTime);
|
||||||
|
10
Assets/Cryville/Crtr/Browsing/IChartDetail.cs
Normal file
10
Assets/Cryville/Crtr/Browsing/IChartDetail.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
internal interface IChartDetail : IResourceMeta {
|
||||||
|
string RulesetId { get; }
|
||||||
|
string Name { get; }
|
||||||
|
string SongName { get; }
|
||||||
|
TimeSpan Length { get; }
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 71234dd1c93d47b4893750686b2333a3
|
guid: 117e1aa46a380524096d0b6bea97c3d4
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
8
Assets/Cryville/Crtr/Browsing/IResourceDestination.cs
Normal file
8
Assets/Cryville/Crtr/Browsing/IResourceDestination.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public interface IResourceDestination {
|
||||||
|
bool CanImport(Uri uri);
|
||||||
|
bool ImportFrom(Uri uri);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 5a795e416e54c69418de1a3c27a88932
|
guid: a81bd44e67e24a34782dfda1e6565fab
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,3 +1,4 @@
|
|||||||
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
event Action ItemChanged;
|
event Action ItemChanged;
|
||||||
bool IsReadOnly { get; }
|
bool IsReadOnly { get; }
|
||||||
bool ImportFrom(Uri uri);
|
IResourceAction GetImportAction();
|
||||||
void RemoveAt(int index);
|
void RemoveAt(int index);
|
||||||
|
|
||||||
void Activate();
|
void Activate();
|
||||||
|
6
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs
Normal file
6
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
internal interface ISkinDetail : IResourceMeta {
|
||||||
|
string RulesetId { get; }
|
||||||
|
string Name { get; }
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/ISkinDetail.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 38d9ea3c71d485a44ba9d335ddf95d67
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 1a624371d4108614b9cdc4acca1499e2
|
guid: ee929ca432bd0ff41bee174081ef16df
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
@@ -4,24 +4,29 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
public class ChartDetail : IResourceMeta {
|
internal class LegacyChartDetail : IChartDetail {
|
||||||
public AsyncDelivery<Texture2D> Cover { get; set; }
|
public AsyncDelivery<Texture2D> Cover { get; set; }
|
||||||
public ChartMeta Meta { get; set; }
|
public ChartMeta Meta { get; set; }
|
||||||
|
|
||||||
|
public string RulesetId { get { return Meta.ruleset; } }
|
||||||
|
public string Name { get { return Meta.name; } }
|
||||||
|
public string SongName { get { return Meta.song.name; } }
|
||||||
|
public TimeSpan Length { get { return TimeSpan.FromSeconds(Meta.length); } }
|
||||||
|
|
||||||
public IEnumerable<MetaProperty> Properties {
|
public IEnumerable<MetaProperty> Properties {
|
||||||
get {
|
get {
|
||||||
if (Meta == null) yield break;
|
if (Meta == null) yield break;
|
||||||
yield return new MetaProperty("Name", new Dictionary<string, object> {
|
yield return new MetaProperty("Name", new Dictionary<string, object> {
|
||||||
{ "", string.Format("{0} - {1}", Meta.song.name, Meta.name) },
|
{ "", string.Format("{0} - {1}", SongName, Name) },
|
||||||
{ "short", Meta.name },
|
{ "short", Name },
|
||||||
{ "distinct-primary", Meta.song.name },
|
{ "distinct-primary", SongName },
|
||||||
{ "distinct-secondary", Meta.name },
|
{ "distinct-secondary", Name },
|
||||||
});
|
});
|
||||||
yield return new MetaProperty("Image", Cover);
|
yield return new MetaProperty("Image", Cover);
|
||||||
yield return new MetaProperty("Song.Author", Meta.song.author);
|
yield return new MetaProperty("Song.Author", Meta.song.author);
|
||||||
yield return new MetaProperty("Author", Meta.author);
|
yield return new MetaProperty("Author", Meta.author);
|
||||||
yield return new MetaProperty("Length", TimeSpan.FromSeconds(Meta.length));
|
yield return new MetaProperty("Length", Length);
|
||||||
yield return new MetaProperty("NoteCount", Meta.note_count);
|
yield return new MetaProperty("NoteCount", Meta.note_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
using Cryville.Common;
|
||||||
|
using Cryville.Common.Unity;
|
||||||
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
|
using Cryville.Crtr.Extension;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
|
internal class LegacyChartResourceManager : LegacyResourceManager<LegacyChartDetail> {
|
||||||
|
protected override string Extension { get { return ".umgc"; } }
|
||||||
|
|
||||||
|
public LegacyChartResourceManager(LegacyResourceStore store) : base(store) { }
|
||||||
|
|
||||||
|
protected override string GetSubRootPath(string rootPath) {
|
||||||
|
return Path.Combine(rootPath, "charts");
|
||||||
|
}
|
||||||
|
protected override LegacyChartDetail GetMeta(DirectoryInfo dir) {
|
||||||
|
ChartMeta meta = null;
|
||||||
|
AsyncDelivery<Texture2D> cover = null;
|
||||||
|
var metaFile = new FileInfo(Path.Combine(dir.FullName, Extension));
|
||||||
|
if (metaFile.Exists) {
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
if (meta.cover != null && meta.cover != "") {
|
||||||
|
var coverFile = dir.GetFiles(meta.cover);
|
||||||
|
if (coverFile.Length > 0) {
|
||||||
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
|
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
|
cover.CancelSource = task.Cancel;
|
||||||
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new LegacyChartDetail {
|
||||||
|
Cover = cover,
|
||||||
|
Meta = meta,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IResourceAction GetImportAction() {
|
||||||
|
return _store.ImportAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 44f8b6ac1c92fea45b8acbec25f86e1b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
121
Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs
Normal file
121
Assets/Cryville/Crtr/Browsing/Legacy/LegacyResourceManager.cs
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
|
using Cryville.Crtr.Extension;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
|
internal abstract class LegacyResourceManager<T> : IPathedResourceManager<T> where T : IResourceMeta {
|
||||||
|
protected readonly LegacyResourceStore _store;
|
||||||
|
DirectoryInfo _cd;
|
||||||
|
readonly FileSystemWatcher _watcher = new();
|
||||||
|
DirectoryInfo[] _items = new DirectoryInfo[0];
|
||||||
|
DirectoryInfo[] _filteredItems = new DirectoryInfo[0];
|
||||||
|
string _filter = string.Empty;
|
||||||
|
readonly List<string> _dirParts = new();
|
||||||
|
readonly IList<string> m_dirParts;
|
||||||
|
public IList<string> CurrentDirectory { get { return m_dirParts; } }
|
||||||
|
public int Count { get { return _filteredItems.Length; } }
|
||||||
|
|
||||||
|
public event Action ItemChanged;
|
||||||
|
public event Action DirectoryChanged;
|
||||||
|
|
||||||
|
public LegacyResourceManager(LegacyResourceStore store) {
|
||||||
|
_store = store;
|
||||||
|
_store.ResourceImported += ReloadFiles;
|
||||||
|
m_dirParts = _dirParts.AsReadOnly();
|
||||||
|
_watcher.Changed += OnFileChanged;
|
||||||
|
_watcher.Created += OnFileChanged;
|
||||||
|
_watcher.Deleted += OnFileChanged;
|
||||||
|
_watcher.Renamed += OnFileChanged;
|
||||||
|
_watcher.Error += OnFileWatcherError;
|
||||||
|
OnDirectoryChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnFileWatcherError(object sender, ErrorEventArgs e) {
|
||||||
|
Game.MainLogger.Log(4, "Data", "An error occurred while watching file changes: {0}", e.GetException());
|
||||||
|
}
|
||||||
|
void OnFileChanged(object sender, FileSystemEventArgs e) {
|
||||||
|
ReloadFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Activate() {
|
||||||
|
_watcher.EnableRaisingEvents = !string.IsNullOrEmpty(_watcher.Path);
|
||||||
|
}
|
||||||
|
public void Deactivate() {
|
||||||
|
_watcher.EnableRaisingEvents = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract string GetSubRootPath(string rootPath);
|
||||||
|
protected void ReloadFiles() {
|
||||||
|
_items = _cd.GetDirectories();
|
||||||
|
ApplyFilter();
|
||||||
|
}
|
||||||
|
void OnDirectoryChange() {
|
||||||
|
string path = Path.Combine(GetSubRootPath(_store.RootPath), string.Join(Path.DirectorySeparatorChar, _dirParts));
|
||||||
|
_cd = new DirectoryInfo(path);
|
||||||
|
_watcher.Path = path;
|
||||||
|
_watcher.EnableRaisingEvents = true;
|
||||||
|
ReloadFiles();
|
||||||
|
DirectoryChanged?.Invoke();
|
||||||
|
}
|
||||||
|
public void ChangeDirectory(IEnumerable<string> dir) {
|
||||||
|
_dirParts.Clear();
|
||||||
|
foreach (string dirPart in dir) _dirParts.Add(dirPart);
|
||||||
|
OnDirectoryChange();
|
||||||
|
}
|
||||||
|
public bool IsDirectory(int index) {
|
||||||
|
return _filteredItems[index].GetFiles(Extension).Length == 0;
|
||||||
|
}
|
||||||
|
public void OpenDirectory(int index) {
|
||||||
|
_dirParts.Add(_filteredItems[index].Name);
|
||||||
|
OnDirectoryChange();
|
||||||
|
}
|
||||||
|
public void ReturnToDirectory(int index) {
|
||||||
|
_dirParts.RemoveRange(index + 1, _dirParts.Count - index - 1);
|
||||||
|
OnDirectoryChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyFilter(string filter) {
|
||||||
|
_filter = filter;
|
||||||
|
ApplyFilter();
|
||||||
|
}
|
||||||
|
void ApplyFilter() {
|
||||||
|
IEnumerable<DirectoryInfo> items = _items;
|
||||||
|
foreach (var keyword in _filter.Split(' ', StringSplitOptions.RemoveEmptyEntries)) {
|
||||||
|
items = items.Where(i => i.Name.Contains(keyword, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
_filteredItems = items.ToArray();
|
||||||
|
ItemChanged?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract T GetMeta(DirectoryInfo dir);
|
||||||
|
public T this[int index] {
|
||||||
|
get {
|
||||||
|
var item = _filteredItems[index];
|
||||||
|
return GetMeta(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
|
||||||
|
|
||||||
|
protected abstract string Extension { get; }
|
||||||
|
public Uri GetItemUri(int index) {
|
||||||
|
var item = _filteredItems[index];
|
||||||
|
var meta = new ChartMeta();
|
||||||
|
var metaFile = new FileInfo(Path.Combine(item.FullName, Extension));
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
return new Uri(PlatformConfig.FileProtocolPrefix + Path.Combine(_filteredItems[index].FullName, string.Format("{0}.json", meta.data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsReadOnly { get { return false; } }
|
||||||
|
public void RemoveAt(int index) {
|
||||||
|
_filteredItems[index].Delete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract IResourceAction GetImportAction();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,150 +1,40 @@
|
|||||||
using Cryville.Common;
|
|
||||||
using Cryville.Common.Unity;
|
|
||||||
using Cryville.Crtr.Extension;
|
using Cryville.Crtr.Extension;
|
||||||
using Cryville.Crtr.Extensions;
|
|
||||||
using Cryville.Crtr.Extensions.Umg;
|
using Cryville.Crtr.Extensions.Umg;
|
||||||
|
using Cryville.Crtr.Extensions;
|
||||||
using Cryville.Crtr.UI;
|
using Cryville.Crtr.UI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
internal class LegacyResourceManager : IPathedResourceManager<ChartDetail> {
|
internal class LegacyResourceStore : IResourceDestination {
|
||||||
readonly string _rootPath;
|
public string RootPath { get; private set; }
|
||||||
DirectoryInfo _cd;
|
public IResourceAction ImportAction { get; private set; }
|
||||||
readonly FileSystemWatcher _watcher = new FileSystemWatcher();
|
public event Action ResourceImported;
|
||||||
DirectoryInfo[] _items = new DirectoryInfo[0];
|
|
||||||
DirectoryInfo[] _filteredItems = new DirectoryInfo[0];
|
|
||||||
string _filter = string.Empty;
|
|
||||||
readonly List<string> _dirParts = new List<string>();
|
|
||||||
readonly IList<string> m_dirParts;
|
|
||||||
public IList<string> CurrentDirectory { get { return m_dirParts; } }
|
|
||||||
public int Count { get { return _filteredItems.Length; } }
|
|
||||||
|
|
||||||
static bool _init;
|
static bool _init;
|
||||||
|
public LegacyResourceStore(string rootPath) {
|
||||||
public event Action ItemChanged;
|
RootPath = rootPath;
|
||||||
public event Action DirectoryChanged;
|
ImportAction = new ImportResourceAction(this);
|
||||||
|
|
||||||
public LegacyResourceManager(string rootPath) {
|
|
||||||
_rootPath = rootPath;
|
|
||||||
if (!_init) {
|
if (!_init) {
|
||||||
_init = true;
|
_init = true;
|
||||||
ExtensionManager.Init(rootPath);
|
ExtensionManager.Init(rootPath);
|
||||||
}
|
}
|
||||||
m_dirParts = _dirParts.AsReadOnly();
|
|
||||||
_watcher.Changed += OnFileChanged;
|
|
||||||
_watcher.Created += OnFileChanged;
|
|
||||||
_watcher.Deleted += OnFileChanged;
|
|
||||||
_watcher.Renamed += OnFileChanged;
|
|
||||||
_watcher.Error += OnFileWatcherError;
|
|
||||||
OnDirectoryChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnFileWatcherError(object sender, ErrorEventArgs e) {
|
public bool CanImport(Uri uri) {
|
||||||
Game.MainLogger.Log(4, "Data", "An error occurred while watching file changes: {0}", e.GetException());
|
if (!uri.IsFile) return false;
|
||||||
|
return CanImportFile(new FileInfo(uri.LocalPath));
|
||||||
}
|
}
|
||||||
void OnFileChanged(object sender, FileSystemEventArgs e) {
|
protected bool CanImportFile(FileInfo file) {
|
||||||
ReloadFiles();
|
return !file.FullName.StartsWith(new DirectoryInfo(RootPath).FullName);
|
||||||
}
|
|
||||||
|
|
||||||
public void Activate() {
|
|
||||||
_watcher.EnableRaisingEvents = !string.IsNullOrEmpty(_watcher.Path);
|
|
||||||
}
|
|
||||||
public void Deactivate() {
|
|
||||||
_watcher.EnableRaisingEvents = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReloadFiles() {
|
|
||||||
_items = _cd.GetDirectories();
|
|
||||||
ApplyFilter();
|
|
||||||
}
|
|
||||||
void OnDirectoryChange() {
|
|
||||||
string path = Path.Combine(_rootPath, "charts", string.Join(Path.DirectorySeparatorChar, _dirParts));
|
|
||||||
_cd = new DirectoryInfo(path);
|
|
||||||
_watcher.Path = path;
|
|
||||||
_watcher.EnableRaisingEvents = true;
|
|
||||||
ReloadFiles();
|
|
||||||
DirectoryChanged?.Invoke();
|
|
||||||
}
|
|
||||||
public void ChangeDirectory(IEnumerable<string> dir) {
|
|
||||||
_dirParts.Clear();
|
|
||||||
foreach (string dirPart in dir) _dirParts.Add(dirPart);
|
|
||||||
OnDirectoryChange();
|
|
||||||
}
|
|
||||||
public bool IsDirectory(int index) { return false; }
|
|
||||||
public void OpenDirectory(int index) {
|
|
||||||
_dirParts.Add(_filteredItems[index].Name);
|
|
||||||
OnDirectoryChange();
|
|
||||||
}
|
|
||||||
public void ReturnToDirectory(int index) {
|
|
||||||
_dirParts.RemoveRange(index + 1, _dirParts.Count - index - 1);
|
|
||||||
OnDirectoryChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ApplyFilter(string filter) {
|
|
||||||
_filter = filter;
|
|
||||||
ApplyFilter();
|
|
||||||
}
|
|
||||||
void ApplyFilter() {
|
|
||||||
IEnumerable<DirectoryInfo> items = _items;
|
|
||||||
foreach (var keyword in _filter.Split(' ', StringSplitOptions.RemoveEmptyEntries)) {
|
|
||||||
items = items.Where(i => i.Name.Contains(keyword, StringComparison.CurrentCultureIgnoreCase));
|
|
||||||
}
|
|
||||||
_filteredItems = items.ToArray();
|
|
||||||
ItemChanged?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChartDetail this[int index] {
|
|
||||||
get {
|
|
||||||
var item = _filteredItems[index];
|
|
||||||
ChartMeta meta = null;
|
|
||||||
AsyncDelivery<Texture2D> cover = null;
|
|
||||||
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
|
||||||
if (metaFile.Exists) {
|
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
|
||||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
|
||||||
}
|
|
||||||
if (meta.cover != null && meta.cover != "") {
|
|
||||||
var coverFile = item.GetFiles(meta.cover);
|
|
||||||
if (coverFile.Length > 0) {
|
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
|
||||||
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
|
||||||
cover.CancelSource = task.Cancel;
|
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ChartDetail {
|
|
||||||
Cover = cover,
|
|
||||||
Meta = meta,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
|
|
||||||
|
|
||||||
public Uri GetItemUri(int index) {
|
|
||||||
var item = _filteredItems[index];
|
|
||||||
var meta = new ChartMeta();
|
|
||||||
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
|
||||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
|
||||||
}
|
|
||||||
return new Uri(PlatformConfig.FileProtocolPrefix + Path.Combine(_filteredItems[index].FullName, string.Format("{0}.json", meta.data)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsReadOnly { get { return false; } }
|
|
||||||
public void RemoveAt(int index) {
|
|
||||||
_filteredItems[index].Delete(true);
|
|
||||||
}
|
}
|
||||||
public bool ImportFrom(Uri uri) {
|
public bool ImportFrom(Uri uri) {
|
||||||
if (!uri.IsFile) throw new NotSupportedException();
|
|
||||||
var file = new FileInfo(uri.LocalPath);
|
var file = new FileInfo(uri.LocalPath);
|
||||||
IEnumerable<ResourceConverter> converters;
|
if (!ExtensionManager.TryGetConverters(file.Extension, out IEnumerable<ResourceConverter> converters)) return false;
|
||||||
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
|
|
||||||
foreach (var converter in converters) {
|
foreach (var converter in converters) {
|
||||||
var resources = new List<Resource>();
|
var resources = new List<Resource>();
|
||||||
var ses = new ConversionSession {
|
var ses = new ConversionSession {
|
||||||
@@ -163,7 +53,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
else if (res is RawChartResource) {
|
else if (res is RawChartResource) {
|
||||||
var tres = (RawChartResource)res;
|
var tres = (RawChartResource)res;
|
||||||
var dir = new DirectoryInfo(Path.Combine(_rootPath, "charts", res.Name));
|
var dir = new DirectoryInfo(Path.Combine(RootPath, "charts", res.Name));
|
||||||
if (!dir.Exists) dir.Create();
|
if (!dir.Exists) dir.Create();
|
||||||
using (var writer = new StreamWriter(Path.Combine(dir.FullName, ".json"))) {
|
using (var writer = new StreamWriter(Path.Combine(dir.FullName, ".json"))) {
|
||||||
writer.Write(JsonConvert.SerializeObject(ConvertChartData(tres.Main), Game.GlobalJsonSerializerSettings));
|
writer.Write(JsonConvert.SerializeObject(ConvertChartData(tres.Main), Game.GlobalJsonSerializerSettings));
|
||||||
@@ -178,23 +68,22 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
coverFile.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
coverFile.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (res is FileResource) {
|
else if (res is FileResource tres) {
|
||||||
var tres = (FileResource)res;
|
|
||||||
DirectoryInfo dest;
|
DirectoryInfo dest;
|
||||||
bool singleFileFlag = false;
|
bool singleFileFlag = false;
|
||||||
if (res is ChartResource)
|
if (res is ChartResource)
|
||||||
dest = new DirectoryInfo(Path.Combine(_rootPath, "charts", res.Name));
|
dest = new DirectoryInfo(Path.Combine(RootPath, "charts", res.Name));
|
||||||
else if (res is ExtensionResource) {
|
else if (res is ExtensionResource) {
|
||||||
dest = new DirectoryInfo(Path.Combine(_rootPath, "extensions"));
|
dest = new DirectoryInfo(Path.Combine(RootPath, "extensions"));
|
||||||
singleFileFlag = true;
|
singleFileFlag = true;
|
||||||
Popup.Create("Please restart the game to reload the extensions");
|
Popup.Create("Please restart the game to reload the extensions");
|
||||||
}
|
}
|
||||||
else if (res is RulesetResource)
|
else if (res is RulesetResource)
|
||||||
dest = new DirectoryInfo(Path.Combine(_rootPath, "rulesets", res.Name));
|
dest = new DirectoryInfo(Path.Combine(RootPath, "rulesets", res.Name));
|
||||||
else if (res is SkinResource)
|
else if (res is SkinResource)
|
||||||
dest = new DirectoryInfo(Path.Combine(_rootPath, "skins", (res as SkinResource).RulesetName, res.Name));
|
dest = new DirectoryInfo(Path.Combine(RootPath, "skins", (res as SkinResource).RulesetName, res.Name));
|
||||||
else if (res is SongResource)
|
else if (res is SongResource)
|
||||||
dest = new DirectoryInfo(Path.Combine(_rootPath, "songs", res.Name));
|
dest = new DirectoryInfo(Path.Combine(RootPath, "songs", res.Name));
|
||||||
else {
|
else {
|
||||||
LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res);
|
LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res);
|
||||||
continue;
|
continue;
|
||||||
@@ -213,7 +102,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
LogAndPopup(3, "Attempt to import unsupported resource: {0}", res);
|
LogAndPopup(3, "Attempt to import unsupported resource: {0}", res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReloadFiles();
|
ResourceImported?.Invoke();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: af4d457931ff3e84fa84fc719290be46
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
24
Assets/Cryville/Crtr/Browsing/Legacy/LegacySkinDetail.cs
Normal file
24
Assets/Cryville/Crtr/Browsing/Legacy/LegacySkinDetail.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Cryville.Crtr.Skin;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
|
internal class LegacySkinDetail : ISkinDetail {
|
||||||
|
public string RulesetId { get { return Meta.ruleset; } }
|
||||||
|
public string Name { get { return Meta == null ? OverrideName : Meta.name; } }
|
||||||
|
public string OverrideName { get; internal set; }
|
||||||
|
public SkinDefinition Meta { get; internal set; }
|
||||||
|
|
||||||
|
public IEnumerable<MetaProperty> Properties {
|
||||||
|
get {
|
||||||
|
if (Meta == null) {
|
||||||
|
if (OverrideName != null)
|
||||||
|
yield return new MetaProperty("Name", OverrideName);
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
yield return new MetaProperty("Name", Meta.name);
|
||||||
|
yield return new MetaProperty("Author", Meta.author);
|
||||||
|
yield return new MetaProperty("Ruleset", Meta.ruleset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4ddcc342c96a91942a7807625bdfd227
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -0,0 +1,32 @@
|
|||||||
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
|
using Cryville.Crtr.Skin;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.Legacy {
|
||||||
|
internal class LegacySkinResourceManager : LegacyResourceManager<LegacySkinDetail> {
|
||||||
|
protected override string Extension { get { return ".umgs"; } }
|
||||||
|
|
||||||
|
public LegacySkinResourceManager(LegacyResourceStore store) : base(store) { }
|
||||||
|
|
||||||
|
protected override string GetSubRootPath(string rootPath) {
|
||||||
|
return Path.Combine(rootPath, "skins");
|
||||||
|
}
|
||||||
|
protected override LegacySkinDetail GetMeta(DirectoryInfo dir) {
|
||||||
|
SkinDefinition meta = null;
|
||||||
|
var metaFile = new FileInfo(Path.Combine(dir.FullName, Extension));
|
||||||
|
if (metaFile.Exists) {
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
return new LegacySkinDetail { Meta = meta };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new LegacySkinDetail { OverrideName = dir.Name };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IResourceAction GetImportAction() {
|
||||||
|
return _store.ImportAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 323eaa68e1ba1f04498393c41a85a3ed
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -31,7 +31,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
OnReset();
|
OnReset();
|
||||||
}
|
}
|
||||||
protected override void OnReset() {
|
protected override void OnReset() {
|
||||||
if (_cover != null) _cover.Cancel();
|
_cover?.Cancel();
|
||||||
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
|
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
|
||||||
Destroy(m_icon.sprite.texture);
|
Destroy(m_icon.sprite.texture);
|
||||||
Destroy(m_icon.sprite);
|
Destroy(m_icon.sprite);
|
||||||
@@ -43,19 +43,23 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
m_icon.sprite = m_iconPlaceholder;
|
m_icon.sprite = m_iconPlaceholder;
|
||||||
m_desc.text = string.Empty;
|
m_desc.text = string.Empty;
|
||||||
|
|
||||||
var basicProps = Meta.EnumerateBasicProperties(true).GetEnumerator();
|
bool validFlag = false;
|
||||||
if (basicProps.MoveNext()) {
|
if (Meta != null) {
|
||||||
m_title.text = basicProps.Current.Value.ToString();
|
var basicProps = Meta.EnumerateBasicProperties(true).GetEnumerator();
|
||||||
if (basicProps.MoveNext()) {
|
if (basicProps.MoveNext()) {
|
||||||
m_desc.text = basicProps.Current.Value.ToString();
|
m_title.text = basicProps.Current.Value.ToString();
|
||||||
|
if (basicProps.MoveNext()) {
|
||||||
|
m_desc.text = basicProps.Current.Value.ToString();
|
||||||
|
}
|
||||||
|
validFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cover = Meta.EnumerateProperties<AsyncDelivery<Texture2D>>().FirstOrDefault().Value;
|
||||||
}
|
}
|
||||||
else {
|
if (!validFlag) {
|
||||||
m_title.text = "<color=#ff0000>Invalid resource</color>";
|
m_title.text = "<color=#ff0000>Invalid resource</color>";
|
||||||
}
|
}
|
||||||
|
|
||||||
_cover = Meta.EnumerateProperties<AsyncDelivery<Texture2D>>().FirstOrDefault().Value;
|
|
||||||
|
|
||||||
if (_cover != null) _cover.Destination = DisplayCover;
|
if (_cover != null) _cover.Destination = DisplayCover;
|
||||||
if (IsDir) _tweener.EnterState("Directory");
|
if (IsDir) _tweener.EnterState("Directory");
|
||||||
if (selected) _tweener.EnterState("Selected");
|
if (selected) _tweener.EnterState("Selected");
|
||||||
|
@@ -79,8 +79,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
protected override void OnEnable() {
|
protected override void OnEnable() {
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
m_layoutMinWidth = GetTargetLayoutMinWidth();
|
m_layoutMinWidth = GetTargetLayoutMinWidth();
|
||||||
if (_tweener == null)
|
_tweener ??= new PropertyTweener<float>(
|
||||||
_tweener = new PropertyTweener<float>(
|
|
||||||
() => m_layoutMinWidth,
|
() => m_layoutMinWidth,
|
||||||
v => UpdateLayoutMinWidth(v),
|
v => UpdateLayoutMinWidth(v),
|
||||||
Tweeners.Float.With(EasingFunctions.OutQuad)
|
Tweeners.Float.With(EasingFunctions.OutQuad)
|
||||||
|
@@ -72,7 +72,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DestroyDynamicResources() {
|
void DestroyDynamicResources() {
|
||||||
if (_image != null) _image.Cancel();
|
_image?.Cancel();
|
||||||
if (m_cover.sprite != null && m_cover.sprite != m_coverPlaceholder) {
|
if (m_cover.sprite != null && m_cover.sprite != m_coverPlaceholder) {
|
||||||
Destroy(m_cover.sprite.texture);
|
Destroy(m_cover.sprite.texture);
|
||||||
Destroy(m_cover.sprite);
|
Destroy(m_cover.sprite);
|
||||||
|
@@ -34,13 +34,15 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
IResourceAction _importAction;
|
IResourceAction _importAction;
|
||||||
readonly IResourceAction[] _importActionArray = new IResourceAction[1];
|
readonly IResourceAction[] _importActionArray = new IResourceAction[1];
|
||||||
|
|
||||||
readonly HashSet<int> _selectedItems = new HashSet<int>();
|
readonly HashSet<int> _selectedItems = new();
|
||||||
readonly Dictionary<int, BrowserItem> _items = new Dictionary<int, BrowserItem>();
|
readonly Dictionary<int, BrowserItem> _items = new();
|
||||||
|
|
||||||
|
bool _destroyed;
|
||||||
protected virtual void Start() {
|
protected virtual void Start() {
|
||||||
m_itemContainer.LoadItem = LoadItem;
|
m_itemContainer.LoadItem = LoadItem;
|
||||||
}
|
}
|
||||||
void OnDestroy() {
|
void OnDestroy() {
|
||||||
|
_destroyed = true;
|
||||||
UnregisterManager();
|
UnregisterManager();
|
||||||
}
|
}
|
||||||
void UnregisterManager() {
|
void UnregisterManager() {
|
||||||
@@ -50,10 +52,10 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
if (_manager != null) _manager.Activate();
|
_manager?.Activate();
|
||||||
}
|
}
|
||||||
void OnDisable() {
|
void OnDisable() {
|
||||||
if (_manager != null) _manager.Deactivate();
|
_manager?.Deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(IPathedResourceManager<IResourceMeta> manager) {
|
public void Init(IPathedResourceManager<IResourceMeta> manager) {
|
||||||
@@ -65,7 +67,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
_manager.ItemChanged += OnItemChanged;
|
_manager.ItemChanged += OnItemChanged;
|
||||||
_manager.DirectoryChanged += OnDirectoryChanged;
|
_manager.DirectoryChanged += OnDirectoryChanged;
|
||||||
if (!_manager.IsReadOnly) {
|
if (!_manager.IsReadOnly) {
|
||||||
Master.Actions.Register(_importAction = new ImportResourceAction(_manager));
|
Master.Actions.Register(_importAction = _manager.GetImportAction());
|
||||||
_importActionArray[0] = _importAction;
|
_importActionArray[0] = _importAction;
|
||||||
}
|
}
|
||||||
foreach (var tool in m_writeTools) tool.interactable = !_manager.IsReadOnly;
|
foreach (var tool in m_writeTools) tool.interactable = !_manager.IsReadOnly;
|
||||||
@@ -116,20 +118,27 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
_selectedItems.Clear();
|
_selectedItems.Clear();
|
||||||
_items[id].OnSelect();
|
_items[id].OnSelect();
|
||||||
_selectedItems.Add(id);
|
_selectedItems.Add(id);
|
||||||
var res = _manager[id];
|
try {
|
||||||
m_detailPanel.Load(res);
|
var res = _manager[id];
|
||||||
if (_selectedItems.Count == 1) {
|
m_detailPanel.Load(res);
|
||||||
LoadActions(res);
|
if (_selectedItems.Count == 1) {
|
||||||
|
LoadActions(_manager.GetItemUri(id), res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Popup.CreateException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal override void OnActionsChanged() {
|
internal override void OnActionsChanged() {
|
||||||
|
if (_destroyed) return;
|
||||||
if (_selectedItems.Count == 1) {
|
if (_selectedItems.Count == 1) {
|
||||||
LoadActions(_manager[_selectedItems.Single()]);
|
int id = _selectedItems.Single();
|
||||||
|
LoadActions(_manager.GetItemUri(id), _manager[id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void LoadActions(IResourceMeta res) {
|
void LoadActions(Uri uri, IResourceMeta res) {
|
||||||
m_actionBar.Load(this, Master.Actions.GetActions(res.GetType()).Except(_importActionArray));
|
m_actionBar.Load(this, Master.Actions.GetActions(uri, res).Except(_importActionArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPathClicked(int index) {
|
public void OnPathClicked(int index) {
|
||||||
@@ -169,7 +178,13 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach (var i in _selectedItems) {
|
foreach (var i in _selectedItems) {
|
||||||
action.Invoke(_manager.GetItemUri(i), _manager[i]);
|
try {
|
||||||
|
action.Invoke(_manager.GetItemUri(i), _manager[i]);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Dialog.Show(null, ex.Message);
|
||||||
|
Game.MainLogger.Log(4, "Config", "An error occurred while running the action: {0}", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common.Unity;
|
using Cryville.Common.Unity;
|
||||||
using Cryville.Crtr.Browsing.Actions;
|
using Cryville.Crtr.Browsing.Actions;
|
||||||
|
using Cryville.Crtr.Browsing.Legacy;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -20,8 +21,8 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
internal GameObject m_configBrowserPrefab;
|
internal GameObject m_configBrowserPrefab;
|
||||||
|
|
||||||
BrowserTab _currentTab;
|
BrowserTab _currentTab;
|
||||||
readonly Dictionary<int, BrowserTab> _tabMap = new Dictionary<int, BrowserTab>();
|
readonly Dictionary<int, BrowserTab> _tabMap = new();
|
||||||
readonly Dictionary<BrowserTab, ResourceBrowser> _tabs = new Dictionary<BrowserTab, ResourceBrowser>();
|
readonly Dictionary<BrowserTab, ResourceBrowser> _tabs = new();
|
||||||
|
|
||||||
public ActionManager Actions { get; private set; }
|
public ActionManager Actions { get; private set; }
|
||||||
|
|
||||||
@@ -32,11 +33,18 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
Actions.Changed += OnActionsChanged;
|
Actions.Changed += OnActionsChanged;
|
||||||
Actions.Register(new PlayChartAction());
|
Actions.Register(new PlayChartAction());
|
||||||
Actions.Register(new OpenConfigAction());
|
Actions.Register(new OpenConfigAction());
|
||||||
|
Actions.Register(new UseSkinAction());
|
||||||
|
|
||||||
OnTabClicked(AddPathedBrowserTab("Local", new LegacyResourceManager(Settings.Default.GameDataPath)));
|
var legacyStore = new LegacyResourceStore(Settings.Default.GameDataPath);
|
||||||
|
OnTabClicked(AddPathedBrowserTab("Local Charts", new LegacyChartResourceManager(legacyStore)));
|
||||||
|
AddPathedBrowserTab("Local Skins", new LegacySkinResourceManager(legacyStore));
|
||||||
AddPathedBrowserTab("Files", new FileSystemResourceManager());
|
AddPathedBrowserTab("Files", new FileSystemResourceManager());
|
||||||
AddTab("Settings", InitBrowser(m_settingsBrowser), _tabs.Count, false);
|
AddTab("Settings", InitBrowser(m_settingsBrowser), _tabs.Count, false);
|
||||||
}
|
}
|
||||||
|
protected override void OnDestroy() {
|
||||||
|
base.OnDestroy();
|
||||||
|
Actions.Changed -= OnActionsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
BrowserTab AddPathedBrowserTab(string name, IPathedResourceManager<IResourceMeta> manager) {
|
BrowserTab AddPathedBrowserTab(string name, IPathedResourceManager<IResourceMeta> manager) {
|
||||||
var browser = InitBrowser(Instantiate(m_pathedBrowserPrefab, m_browserContainer, false).GetComponent<PathedResourceBrowser>());
|
var browser = InitBrowser(Instantiate(m_pathedBrowserPrefab, m_browserContainer, false).GetComponent<PathedResourceBrowser>());
|
||||||
@@ -65,9 +73,11 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
OnTabClicked(tab);
|
OnTabClicked(tab);
|
||||||
return tab.GetHashCode();
|
return tab.GetHashCode();
|
||||||
}
|
}
|
||||||
|
public bool HasTab(int id) {
|
||||||
|
return _tabMap.ContainsKey(id);
|
||||||
|
}
|
||||||
public bool TryOpenTab(int id) {
|
public bool TryOpenTab(int id) {
|
||||||
BrowserTab tab;
|
if (_tabMap.TryGetValue(id, out BrowserTab tab)) {
|
||||||
if (_tabMap.TryGetValue(id, out tab)) {
|
|
||||||
OnTabClicked(tab);
|
OnTabClicked(tab);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -22,29 +22,30 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
InputConfigPanel m_inputConfigPanel;
|
InputConfigPanel m_inputConfigPanel;
|
||||||
|
|
||||||
public RulesetDefinition ruleset;
|
RulesetDefinition _ruleset;
|
||||||
RulesetConfig _rscfg;
|
RulesetConfig _rscfg;
|
||||||
|
|
||||||
string _rulesetName;
|
public string RulesetName { get; private set; }
|
||||||
|
UseSkinAction _useSkinAction;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
|
|
||||||
public void Load(string rulesetName) {
|
public void Load(string rulesetName, Action<RulesetConfig> overrides = null) {
|
||||||
_rulesetName = rulesetName;
|
RulesetName = rulesetName;
|
||||||
FileInfo file = new FileInfo(Path.Combine(
|
FileInfo file = new(Path.Combine(
|
||||||
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
||||||
));
|
));
|
||||||
if (!file.Exists) {
|
if (!file.Exists) {
|
||||||
throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
throw new FileNotFoundException("Ruleset for the resource not found\nMake sure you have imported the ruleset");
|
||||||
}
|
}
|
||||||
DirectoryInfo dir = file.Directory;
|
DirectoryInfo dir = file.Directory;
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
using (StreamReader reader = new(file.FullName, Encoding.UTF8)) {
|
||||||
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
_ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
if (_ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||||
ruleset.LoadPdt(dir);
|
_ruleset.LoadPdt(dir);
|
||||||
}
|
}
|
||||||
FileInfo cfgfile = new FileInfo(Path.Combine(
|
FileInfo cfgfile = new(Path.Combine(
|
||||||
Game.GameDataPath, "config", "rulesets", rulesetName + ".json"
|
Game.GameDataPath, "config", "rulesets", rulesetName + ".json"
|
||||||
));
|
));
|
||||||
if (!cfgfile.Exists) {
|
if (!cfgfile.Exists) {
|
||||||
@@ -52,19 +53,30 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
_rscfg = new RulesetConfig();
|
_rscfg = new RulesetConfig();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
using StreamReader cfgreader = new(cfgfile.FullName, Encoding.UTF8);
|
||||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
overrides?.Invoke(_rscfg);
|
||||||
|
|
||||||
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
||||||
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(_ruleset.Root.configs, _rscfg.configs);
|
||||||
m_inputConfigPanel.Load(ruleset.Root, _rscfg);
|
m_inputConfigPanel.Load(_ruleset.Root, _rscfg);
|
||||||
|
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
}
|
}
|
||||||
|
public void InitAction() {
|
||||||
|
Master.Actions.Register(_useSkinAction = new UseSkinAction(this));
|
||||||
|
}
|
||||||
|
void OnDestroy() {
|
||||||
|
if (_loaded) Master.Actions.Unregister(_useSkinAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetSkin(string skin) {
|
||||||
|
_rscfg.generic.Skin = skin;
|
||||||
|
}
|
||||||
|
|
||||||
public void SwitchCategory(GameObject cat) {
|
public void SwitchCategory(GameObject cat) {
|
||||||
foreach (Transform c in m_content) {
|
foreach (Transform c in m_content) {
|
||||||
@@ -73,15 +85,17 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
cat.SetActive(true);
|
cat.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnEnable() {
|
||||||
|
m_genericConfigPanel.InvalidatePropertyValues();
|
||||||
|
}
|
||||||
void OnDisable() {
|
void OnDisable() {
|
||||||
if (_loaded) {
|
if (_loaded) {
|
||||||
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
||||||
FileInfo cfgFile = new FileInfo(Path.Combine(
|
FileInfo cfgFile = new(Path.Combine(
|
||||||
Game.GameDataPath, "config", "rulesets", _rulesetName + ".json"
|
Game.GameDataPath, "config", "rulesets", RulesetName + ".json"
|
||||||
));
|
));
|
||||||
using (StreamWriter cfgWriter = new StreamWriter(cfgFile.FullName, false, Encoding.UTF8)) {
|
using StreamWriter cfgWriter = new(cfgFile.FullName, false, Encoding.UTF8);
|
||||||
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,13 +6,13 @@ using UnityEngine;
|
|||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public static class BuiltinResources {
|
public static class BuiltinResources {
|
||||||
public static Dictionary<string, Type> Components
|
public static Dictionary<string, Type> Components
|
||||||
= new Dictionary<string, Type>();
|
= new();
|
||||||
public static Dictionary<string, Shader> Shaders
|
public static Dictionary<string, Shader> Shaders
|
||||||
= new Dictionary<string, Shader>();
|
= new();
|
||||||
public static Dictionary<string, Mesh> Meshes
|
public static Dictionary<string, Mesh> Meshes
|
||||||
= new Dictionary<string, Mesh>();
|
= new();
|
||||||
public static Dictionary<string, Material> Materials
|
public static Dictionary<string, Material> Materials
|
||||||
= new Dictionary<string, Material>();
|
= new();
|
||||||
|
|
||||||
static bool loaded;
|
static bool loaded;
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
public abstract class ChartEvent {
|
public abstract class ChartEvent {
|
||||||
public BeatTime? time;
|
public BeatTime? time;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public float BeatPosition {
|
public float BeatPosition {
|
||||||
get {
|
get {
|
||||||
@@ -27,7 +27,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BeatTime? endtime;
|
public BeatTime? endtime;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public float EndBeatPosition {
|
public float EndBeatPosition {
|
||||||
get {
|
get {
|
||||||
@@ -35,10 +35,10 @@ namespace Cryville.Crtr {
|
|||||||
return (float)endtime.Value.Decimal + BeatOffset;
|
return (float)endtime.Value.Decimal + BeatOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public float BeatOffset;
|
public float BeatOffset;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public abstract int Priority { get; }
|
public abstract int Priority { get; }
|
||||||
|
|
||||||
@@ -66,8 +66,7 @@ namespace Cryville.Crtr {
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public ReleaseEvent ReleaseEvent {
|
public ReleaseEvent ReleaseEvent {
|
||||||
get {
|
get {
|
||||||
if (relev == null) relev = new ReleaseEvent(this);
|
return relev ??= new ReleaseEvent(this);
|
||||||
return relev;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,15 +95,15 @@ namespace Cryville.Crtr {
|
|||||||
SubmitPropOp("endtime", new PropOp.BeatTime(v => endtime = v));
|
SubmitPropOp("endtime", new PropOp.BeatTime(v => endtime = v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReleaseEvent : ChartEvent {
|
public class ReleaseEvent : ChartEvent {
|
||||||
public readonly ChartEvent Original;
|
public readonly ChartEvent Original;
|
||||||
|
|
||||||
public ReleaseEvent(ChartEvent orig) {
|
public ReleaseEvent(ChartEvent orig) {
|
||||||
Original = orig;
|
Original = orig;
|
||||||
time = orig.endtime;
|
time = orig.endtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority {
|
||||||
get {
|
get {
|
||||||
return Original.Priority + 1;
|
return Original.Priority + 1;
|
||||||
@@ -112,7 +111,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public abstract class EventContainer : ChartEvent {
|
public abstract class EventContainer : ChartEvent {
|
||||||
public List<Chart.Motion> motions = new List<Chart.Motion>();
|
public List<Chart.Motion> motions = new();
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Clip Clip { get; private set; }
|
public Clip Clip { get; private set; }
|
||||||
@@ -120,7 +119,7 @@ namespace Cryville.Crtr {
|
|||||||
public EventContainer() {
|
public EventContainer() {
|
||||||
SubmitPropOp("clip", new PropOp.Clip(v => Clip = v));
|
SubmitPropOp("clip", new PropOp.Clip(v => Clip = v));
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public virtual IEnumerable<ChartEvent> Events {
|
public virtual IEnumerable<ChartEvent> Events {
|
||||||
get {
|
get {
|
||||||
@@ -128,12 +127,10 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual EventList GetEventsOfType(string type) {
|
public virtual EventList GetEventsOfType(string type) => type switch {
|
||||||
switch (type) {
|
"motions" => new EventList<Chart.Motion>(motions),
|
||||||
case "motions": return new EventList<Chart.Motion>(motions);
|
_ => throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type)),
|
||||||
default: throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type));
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public abstract class EventList : ChartEvent {
|
public abstract class EventList : ChartEvent {
|
||||||
public IList<ChartEvent> Events { get; private set; }
|
public IList<ChartEvent> Events { get; private set; }
|
||||||
@@ -178,8 +175,8 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
public string ruleset;
|
public string ruleset;
|
||||||
|
|
||||||
public List<Group> groups = new List<Group>();
|
public List<Group> groups = new();
|
||||||
|
|
||||||
public override IEnumerable<ChartEvent> Events {
|
public override IEnumerable<ChartEvent> Events {
|
||||||
get {
|
get {
|
||||||
return base.Events
|
return base.Events
|
||||||
@@ -189,33 +186,29 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override EventList GetEventsOfType(string type) {
|
public override EventList GetEventsOfType(string type) => type switch {
|
||||||
switch (type) {
|
"groups" => new EventList<Group>(groups),
|
||||||
case "groups": return new EventList<Group>(groups);
|
_ => base.GetEventsOfType(type),
|
||||||
default: return base.GetEventsOfType(type);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Priority { get { return 10; } }
|
public override int Priority { get { return 10; } }
|
||||||
|
|
||||||
public class Group : EventContainer {
|
public class Group : EventContainer {
|
||||||
public List<Track> tracks = new List<Track>();
|
public List<Track> tracks = new();
|
||||||
public List<Note> notes = new List<Note>();
|
public List<Note> notes = new();
|
||||||
public override IEnumerable<ChartEvent> Events {
|
public override IEnumerable<ChartEvent> Events {
|
||||||
get {
|
get {
|
||||||
return base.Events
|
return base.Events
|
||||||
.Concat(notes.Cast<ChartEvent>()
|
.Concat(notes.Cast<ChartEvent>()
|
||||||
.Concat(tracks.Cast<ChartEvent>()
|
.Concat(tracks.Cast<ChartEvent>()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override EventList GetEventsOfType(string type) {
|
public override EventList GetEventsOfType(string type) => type switch {
|
||||||
switch (type) {
|
"tracks" => new EventList<Track>(tracks),
|
||||||
case "tracks": return new EventList<Track>(tracks);
|
"notes" => new EventList<Note>(notes),
|
||||||
case "notes": return new EventList<Note>(notes);
|
_ => base.GetEventsOfType(type),
|
||||||
default: return base.GetEventsOfType(type);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
public override int Priority { get { return 12; } }
|
public override int Priority { get { return 12; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,8 +221,8 @@ namespace Cryville.Crtr {
|
|||||||
string m_motion;
|
string m_motion;
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public string motion {
|
public string motion {
|
||||||
get { return m_motion == null ? ToString() : m_motion; }
|
get => m_motion ?? ToString();
|
||||||
set { LoadFromString(value); }
|
set => LoadFromString(value);
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
private void LoadFromString(string s) {
|
private void LoadFromString(string s) {
|
||||||
@@ -264,12 +257,11 @@ namespace Cryville.Crtr {
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Identifier Name {
|
public Identifier Name {
|
||||||
get {
|
get {
|
||||||
if (name == default(Identifier)) throw new InvalidOperationException("Motion name not set");
|
if (name == default) throw new InvalidOperationException("Motion name not set");
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
private set {
|
private set {
|
||||||
MotionRegistry reg;
|
if (!ChartPlayer.motionRegistry.TryGetValue(value, out MotionRegistry reg))
|
||||||
if (!ChartPlayer.motionRegistry.TryGetValue(value, out reg))
|
|
||||||
throw new ArgumentException("Invalid motion name");
|
throw new ArgumentException("Invalid motion name");
|
||||||
Node = new MotionNode { Value = reg.InitValue };
|
Node = new MotionNode { Value = reg.InitValue };
|
||||||
name = value;
|
name = value;
|
||||||
@@ -293,7 +285,7 @@ namespace Cryville.Crtr {
|
|||||||
SubmitPropOp("name", new PropOp.Identifier(v => {
|
SubmitPropOp("name", new PropOp.Identifier(v => {
|
||||||
var n = new Identifier(v);
|
var n = new Identifier(v);
|
||||||
if (name == n) { }
|
if (name == n) { }
|
||||||
else if (name == default(Identifier)) Name = n;
|
else if (name == default) Name = n;
|
||||||
else throw new RulesetViolationException(string.Format(
|
else throw new RulesetViolationException(string.Format(
|
||||||
"Motion name not matched, expected {0}, got {1}", n, Name
|
"Motion name not matched, expected {0}, got {1}", n, Name
|
||||||
));
|
));
|
||||||
@@ -306,7 +298,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Note : EventContainer {
|
public class Note : EventContainer {
|
||||||
public List<Judge> judges = new List<Judge>();
|
public List<Judge> judges = new();
|
||||||
public override IEnumerable<ChartEvent> Events {
|
public override IEnumerable<ChartEvent> Events {
|
||||||
get {
|
get {
|
||||||
return base.Events
|
return base.Events
|
||||||
@@ -315,12 +307,10 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override EventList GetEventsOfType(string type) {
|
public override EventList GetEventsOfType(string type) => type switch {
|
||||||
switch (type) {
|
"judges" => new EventList<Judge>(judges),
|
||||||
case "judges": return new EventList<Judge>(judges);
|
_ => base.GetEventsOfType(type),
|
||||||
default: return base.GetEventsOfType(type);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
public override int Priority { get { return 20; } }
|
public override int Priority { get { return 20; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +335,7 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
// TODO [Obsolete]
|
// TODO [Obsolete]
|
||||||
public List<Signature> sigs; // Signatures
|
public List<Signature> sigs; // Signatures
|
||||||
// TODO [Obsolete]
|
// TODO [Obsolete]
|
||||||
public class Signature : ChartEvent {
|
public class Signature : ChartEvent {
|
||||||
public float? tempo;
|
public float? tempo;
|
||||||
|
|
||||||
|
@@ -11,11 +11,11 @@ namespace Cryville.Crtr {
|
|||||||
public static IMotionStringParser MotionStringParser { get; private set; }
|
public static IMotionStringParser MotionStringParser { get; private set; }
|
||||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||||
var obj = JToken.ReadFrom(reader);
|
var obj = JToken.ReadFrom(reader);
|
||||||
switch (obj["format"].ToObject<int>()) {
|
MotionStringParser = obj["format"].ToObject<int>() switch {
|
||||||
case 2: MotionStringParser = MotionStringParser2.Instance; break;
|
2 => MotionStringParser2.Instance,
|
||||||
case 3: MotionStringParser = MotionStringParser3.Instance; break;
|
3 => MotionStringParser3.Instance,
|
||||||
default: throw new FormatException("Unsupported chart format");
|
_ => throw new FormatException("Unsupported chart format"),
|
||||||
}
|
};
|
||||||
return base.ReadJson(obj.CreateReader(), objectType, existingValue, serializer);
|
return base.ReadJson(obj.CreateReader(), objectType, existingValue, serializer);
|
||||||
}
|
}
|
||||||
public override Chart Create(Type objectType) {
|
public override Chart Create(Type objectType) {
|
||||||
@@ -28,12 +28,11 @@ namespace Cryville.Crtr {
|
|||||||
static MotionStringParser2 _instance;
|
static MotionStringParser2 _instance;
|
||||||
public static MotionStringParser2 Instance {
|
public static MotionStringParser2 Instance {
|
||||||
get {
|
get {
|
||||||
if (_instance == null)
|
_instance ??= new MotionStringParser2();
|
||||||
_instance = new MotionStringParser2();
|
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
|
static readonly PdtFragmentInterpreter _itor = new();
|
||||||
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
|
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
|
||||||
static float[] _vecbuf;
|
static float[] _vecbuf;
|
||||||
public void Parse(string str, out Identifier name, out MotionNode node) {
|
public void Parse(string str, out Identifier name, out MotionNode node) {
|
||||||
@@ -74,12 +73,11 @@ namespace Cryville.Crtr {
|
|||||||
static MotionStringParser3 _instance;
|
static MotionStringParser3 _instance;
|
||||||
public static MotionStringParser3 Instance {
|
public static MotionStringParser3 Instance {
|
||||||
get {
|
get {
|
||||||
if (_instance == null)
|
_instance ??= new MotionStringParser3();
|
||||||
_instance = new MotionStringParser3();
|
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
|
static readonly PdtFragmentInterpreter _itor = new();
|
||||||
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
|
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
|
||||||
static float[] _vecbuf;
|
static float[] _vecbuf;
|
||||||
public void Parse(string str, out Identifier name, out MotionNode node) {
|
public void Parse(string str, out Identifier name, out MotionNode node) {
|
||||||
|
@@ -84,6 +84,8 @@ namespace Cryville.Crtr {
|
|||||||
loggerListener = new BufferedLoggerListener();
|
loggerListener = new BufferedLoggerListener();
|
||||||
Game.MainLogger.AddListener(loggerListener);
|
Game.MainLogger.AddListener(loggerListener);
|
||||||
|
|
||||||
|
Game.SuspendBackgroundTasks();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Play();
|
Play();
|
||||||
}
|
}
|
||||||
@@ -95,12 +97,12 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnDestroy() {
|
void OnDestroy() {
|
||||||
if (cbus != null) cbus.Dispose();
|
cbus?.Dispose();
|
||||||
if (bbus != null) bbus.Dispose();
|
bbus?.Dispose();
|
||||||
if (tbus != null) tbus.Dispose();
|
tbus?.Dispose();
|
||||||
if (nbus != null) nbus.Dispose();
|
nbus?.Dispose();
|
||||||
if (loadThread != null) loadThread.Abort();
|
loadThread?.Abort();
|
||||||
if (inputProxy != null) inputProxy.Dispose();
|
inputProxy?.Dispose();
|
||||||
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
||||||
Game.MainLogger.RemoveListener(loggerListener);
|
Game.MainLogger.RemoveListener(loggerListener);
|
||||||
loggerListener.Dispose();
|
loggerListener.Dispose();
|
||||||
@@ -198,24 +200,22 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readonly TargetString statusstr = new TargetString();
|
readonly StringBuffer statusbuf = new();
|
||||||
readonly StringBuffer statusbuf = new StringBuffer();
|
readonly StringBuffer logsbuf = new();
|
||||||
readonly TargetString logsstr = new TargetString();
|
readonly List<string> logEntries = new();
|
||||||
readonly StringBuffer logsbuf = new StringBuffer();
|
readonly ArrayPool<char> logBufferPool = new();
|
||||||
readonly List<string> logEntries = new List<string>();
|
|
||||||
int logsLength = 0;
|
int logsLength = 0;
|
||||||
LogHandler d_addLogEntry;
|
LogHandler d_addLogEntry;
|
||||||
void AddLogEntry(int level, string module, string msg) {
|
void AddLogEntry(int level, string module, string msg) {
|
||||||
string color;
|
string color = level switch {
|
||||||
switch (level) {
|
0 => "#888888",
|
||||||
case 0: color = "#888888"; break;
|
1 => "#bbbbbb",
|
||||||
case 1: color = "#bbbbbb"; break;
|
2 => "#0088ff",
|
||||||
case 2: color = "#0088ff"; break;
|
3 => "#ffff00",
|
||||||
case 3: color = "#ffff00"; break;
|
4 => "#ff0000",
|
||||||
case 4: color = "#ff0000"; break;
|
5 => "#bb0000",
|
||||||
case 5: color = "#bb0000"; break;
|
_ => "#ff00ff",
|
||||||
default: color = "#ff00ff"; break;
|
};
|
||||||
}
|
|
||||||
var l = string.Format(
|
var l = string.Format(
|
||||||
"\n<color={1}bb><{2}> {3}</color>",
|
"\n<color={1}bb><{2}> {3}</color>",
|
||||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||||
@@ -233,10 +233,10 @@ namespace Cryville.Crtr {
|
|||||||
foreach (var l in logEntries) {
|
foreach (var l in logEntries) {
|
||||||
logsbuf.Append(l);
|
logsbuf.Append(l);
|
||||||
}
|
}
|
||||||
logsstr.Length = logsbuf.Count;
|
var lbuf = logBufferPool.Rent(logsbuf.Count);
|
||||||
var larr = logsstr.TrustedAsArray();
|
logsbuf.CopyTo(0, lbuf, 0, logsbuf.Count);
|
||||||
logsbuf.CopyTo(0, larr, 0, logsbuf.Count);
|
logs.SetText(lbuf, 0, logsbuf.Count);
|
||||||
logs.SetText(larr, 0, logsbuf.Count);
|
logBufferPool.Return(lbuf);
|
||||||
|
|
||||||
statusbuf.Clear();
|
statusbuf.Clear();
|
||||||
statusbuf.AppendFormat(
|
statusbuf.AppendFormat(
|
||||||
@@ -284,14 +284,15 @@ namespace Cryville.Crtr {
|
|||||||
);
|
);
|
||||||
if (judge != null) {
|
if (judge != null) {
|
||||||
statusbuf.Append("\n== Scores ==\n");
|
statusbuf.Append("\n== Scores ==\n");
|
||||||
var fullScoreStr = judge.GetFullFormattedScoreString();
|
var fullScoreStrLen = judge.GetFullFormattedScoreString(logBufferPool, out char[] fullScoreStr);
|
||||||
statusbuf.Append(fullScoreStr.TrustedAsArray(), 0, fullScoreStr.Length);
|
statusbuf.Append(fullScoreStr, 0, fullScoreStrLen);
|
||||||
|
logBufferPool.Return(fullScoreStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statusstr.Length = statusbuf.Count;
|
var buf = logBufferPool.Rent(statusbuf.Count);
|
||||||
var sarr = statusstr.TrustedAsArray();
|
statusbuf.CopyTo(0, buf, 0, statusbuf.Count);
|
||||||
statusbuf.CopyTo(0, sarr, 0, statusbuf.Count);
|
status.SetText(buf, 0, statusbuf.Count);
|
||||||
status.SetText(sarr, 0, statusbuf.Count);
|
logBufferPool.Return(buf);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -307,6 +308,7 @@ namespace Cryville.Crtr {
|
|||||||
private void ReturnToMenuImpl() {
|
private void ReturnToMenuImpl() {
|
||||||
Master.Instance.ShowMenu();
|
Master.Instance.ShowMenu();
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
|
Game.ResumeBackgroundTasks();
|
||||||
#if UNITY_5_5_OR_NEWER
|
#if UNITY_5_5_OR_NEWER
|
||||||
SceneManager.UnloadSceneAsync("Play");
|
SceneManager.UnloadSceneAsync("Play");
|
||||||
#elif UNITY_5_3_OR_NEWER
|
#elif UNITY_5_3_OR_NEWER
|
||||||
@@ -379,13 +381,11 @@ namespace Cryville.Crtr {
|
|||||||
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
|
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
|
||||||
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||||
texloaddone = false;
|
texloaddone = false;
|
||||||
Game.SuspendBackgroundTasks();
|
|
||||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||||
|
|
||||||
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
||||||
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
||||||
float dist;
|
hitPlane.Raycast(r0, out float dist);
|
||||||
hitPlane.Raycast(r0, out dist);
|
|
||||||
var p0 = r0.GetPoint(dist);
|
var p0 = r0.GetPoint(dist);
|
||||||
var r1 = Camera.main.ViewportPointToRay(new Vector3(1, 1, 1));
|
var r1 = Camera.main.ViewportPointToRay(new Vector3(1, 1, 1));
|
||||||
hitPlane.Raycast(r1, out dist);
|
hitPlane.Raycast(r1, out dist);
|
||||||
@@ -395,18 +395,18 @@ namespace Cryville.Crtr {
|
|||||||
screenSize = new Vector2(Screen.width, Screen.height);
|
screenSize = new Vector2(Screen.width, Screen.height);
|
||||||
frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
|
frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
|
||||||
|
|
||||||
FileInfo chartFile = new FileInfo(Settings.Default.LoadChart);
|
FileInfo chartFile = new(Settings.Default.LoadChart);
|
||||||
|
|
||||||
FileInfo rulesetFile = new FileInfo(Path.Combine(
|
FileInfo rulesetFile = new(Path.Combine(
|
||||||
Game.GameDataPath, "rulesets", Settings.Default.LoadRuleset
|
Game.GameDataPath, "rulesets", Settings.Default.LoadRuleset
|
||||||
));
|
));
|
||||||
if (!rulesetFile.Exists) throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
if (!rulesetFile.Exists) throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||||
|
|
||||||
FileInfo rulesetConfigFile = new FileInfo(Path.Combine(
|
FileInfo rulesetConfigFile = new(Path.Combine(
|
||||||
Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
||||||
));
|
));
|
||||||
if (!rulesetConfigFile.Exists) throw new FileNotFoundException("Ruleset config not found\nPlease open the config to generate");
|
if (!rulesetConfigFile.Exists) throw new FileNotFoundException("Ruleset config not found\nPlease open the config to generate");
|
||||||
using (StreamReader cfgreader = new StreamReader(rulesetConfigFile.FullName, Encoding.UTF8)) {
|
using (StreamReader cfgreader = new(rulesetConfigFile.FullName, Encoding.UTF8)) {
|
||||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
@@ -414,11 +414,11 @@ namespace Cryville.Crtr {
|
|||||||
sv = _rscfg.generic.ScrollVelocity;
|
sv = _rscfg.generic.ScrollVelocity;
|
||||||
soundOffset += _rscfg.generic.SoundOffset;
|
soundOffset += _rscfg.generic.SoundOffset;
|
||||||
|
|
||||||
FileInfo skinFile = new FileInfo(Path.Combine(
|
FileInfo skinFile = new(Path.Combine(
|
||||||
Game.GameDataPath, "skins", rulesetFile.Directory.Name, _rscfg.generic.Skin, ".umgs"
|
Game.GameDataPath, "skins", rulesetFile.Directory.Name, _rscfg.generic.Skin, ".umgs"
|
||||||
));
|
));
|
||||||
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
|
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
|
||||||
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
|
using (StreamReader reader = new(skinFile.FullName, Encoding.UTF8)) {
|
||||||
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
@@ -444,7 +444,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator<float> LoadTextures(List<string> queue) {
|
IEnumerator<float> LoadTextures(List<string> queue) {
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
#if UNITY_5_4_OR_NEWER
|
#if UNITY_5_4_OR_NEWER
|
||||||
DownloadHandlerTexture texHandler = null;
|
DownloadHandlerTexture texHandler = null;
|
||||||
@@ -497,7 +497,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator<float> Prehandle() {
|
IEnumerator<float> Prehandle() {
|
||||||
Stopwatch timer = new Stopwatch();
|
Stopwatch timer = new();
|
||||||
timer.Reset(); timer.Start();
|
timer.Reset(); timer.Start();
|
||||||
Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
|
Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
|
||||||
cbus.BroadcastPreInit();
|
cbus.BroadcastPreInit();
|
||||||
@@ -568,7 +568,6 @@ namespace Cryville.Crtr {
|
|||||||
started = false;
|
started = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Game.ResumeBackgroundTasks();
|
|
||||||
ReturnToMenu();
|
ReturnToMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,73 +616,72 @@ namespace Cryville.Crtr {
|
|||||||
{ new Identifier("track") , new MotionRegistry(typeof(Vec1)) },
|
{ new Identifier("track") , new MotionRegistry(typeof(Vec1)) },
|
||||||
};
|
};
|
||||||
|
|
||||||
using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) {
|
using StreamReader reader = new(info.chartFile.FullName, Encoding.UTF8);
|
||||||
PdtEvaluator.Instance.Reset();
|
PdtEvaluator.Instance.Reset();
|
||||||
|
|
||||||
LoadRuleset(info.rulesetFile); loadPregress = .05f;
|
LoadRuleset(info.rulesetFile); loadPregress = .05f;
|
||||||
|
|
||||||
chart = JsonConvert.DeserializeObject<Chart>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
chart = JsonConvert.DeserializeObject<Chart>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
|
||||||
pruleset.PrePatch(chart);
|
pruleset.PrePatch(chart);
|
||||||
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
|
||||||
var batcher = new EventBatcher(chart);
|
var batcher = new EventBatcher(chart);
|
||||||
batcher.Forward();
|
batcher.Forward();
|
||||||
cbus = batcher.Batch(); loadPregress = .30f;
|
cbus = batcher.Batch(); loadPregress = .30f;
|
||||||
|
|
||||||
LoadSkin(info.skinFile);
|
LoadSkin(info.skinFile);
|
||||||
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
||||||
judge = new Judge(this, pruleset);
|
judge = new Judge(this, pruleset);
|
||||||
PdtEvaluator.Instance.ContextJudge = judge;
|
PdtEvaluator.Instance.ContextJudge = judge;
|
||||||
|
|
||||||
inputProxy = new InputProxy(pruleset, judge, screenSize);
|
inputProxy = new InputProxy(pruleset, judge, screenSize);
|
||||||
inputProxy.LoadFrom(_rscfg.inputs);
|
inputProxy.LoadFrom(_rscfg.inputs);
|
||||||
if (!inputProxy.IsCompleted()) {
|
if (!inputProxy.IsCompleted()) {
|
||||||
Game.MainLogger.Log(2, "Game", "Input config not completed. Input disabled");
|
Game.MainLogger.Log(2, "Game", "Input config not completed. Input disabled");
|
||||||
inputProxy.Clear();
|
inputProxy.Clear();
|
||||||
}
|
|
||||||
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
|
||||||
var ch = new ChartHandler(chart);
|
|
||||||
cbus.RootState.AttachHandler(ch);
|
|
||||||
foreach (var gs in cbus.RootState.Children) {
|
|
||||||
var gh = new GroupHandler((Chart.Group)gs.Key, ch);
|
|
||||||
gs.Value.AttachHandler(gh);
|
|
||||||
foreach (var ts in gs.Value.Children) {
|
|
||||||
ContainerHandler th;
|
|
||||||
if (ts.Key is Chart.Note) {
|
|
||||||
th = new NoteHandler((Chart.Note)ts.Key, gh);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
th = new TrackHandler((Chart.Track)ts.Key, gh);
|
|
||||||
}
|
|
||||||
ts.Value.AttachHandler(th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cbus.AttachSystems(pskin, judge);
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
|
|
||||||
using (var pbus = cbus.Clone(16)) {
|
|
||||||
pbus.Forward();
|
|
||||||
}
|
|
||||||
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
|
|
||||||
bbus = cbus.Clone(1, -clippingDist);
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
|
|
||||||
tbus = bbus.Clone(2);
|
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
|
|
||||||
nbus = bbus.Clone(3);
|
|
||||||
loadPregress = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
||||||
|
var ch = new ChartHandler(chart);
|
||||||
|
cbus.RootState.AttachHandler(ch);
|
||||||
|
foreach (var gs in cbus.RootState.Children) {
|
||||||
|
var gh = new GroupHandler((Chart.Group)gs.Key, ch);
|
||||||
|
gs.Value.AttachHandler(gh);
|
||||||
|
foreach (var ts in gs.Value.Children) {
|
||||||
|
ContainerHandler th;
|
||||||
|
if (ts.Key is Chart.Note) {
|
||||||
|
th = new NoteHandler((Chart.Note)ts.Key, gh);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
th = new TrackHandler((Chart.Track)ts.Key, gh);
|
||||||
|
}
|
||||||
|
ts.Value.AttachHandler(th);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cbus.AttachSystems(pskin, judge);
|
||||||
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
|
||||||
|
using (var pbus = cbus.Clone(16)) {
|
||||||
|
pbus.Forward();
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
|
||||||
|
bbus = cbus.Clone(1, -clippingDist);
|
||||||
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
|
||||||
|
tbus = bbus.Clone(2);
|
||||||
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
|
||||||
|
nbus = bbus.Clone(3);
|
||||||
|
loadPregress = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadRuleset(FileInfo file) {
|
void LoadRuleset(FileInfo file) {
|
||||||
DirectoryInfo dir = file.Directory;
|
DirectoryInfo dir = file.Directory;
|
||||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Loading ruleset: {0}", file);
|
Game.MainLogger.Log(0, "Load/WorkerThread", "Loading ruleset: {0}", file);
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
using (StreamReader reader = new(file.FullName, Encoding.UTF8)) {
|
||||||
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
});
|
});
|
||||||
|
@@ -14,6 +14,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
object GetValue();
|
object GetValue();
|
||||||
void SetValue(object value);
|
void SetValue(object value);
|
||||||
event Action ValueChanged;
|
event Action ValueChanged;
|
||||||
|
void Invalidate();
|
||||||
object MapValue(object value);
|
object MapValue(object value);
|
||||||
bool SetMapped { get; }
|
bool SetMapped { get; }
|
||||||
object MapValueInverse(object value);
|
object MapValueInverse(object value);
|
||||||
@@ -38,7 +39,10 @@ namespace Cryville.Crtr.Config {
|
|||||||
public object GetValue() { return _prop.GetValue(_target, null); }
|
public object GetValue() { return _prop.GetValue(_target, null); }
|
||||||
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
|
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
|
||||||
|
|
||||||
public event Action ValueChanged { add { } remove { } }
|
public event Action ValueChanged;
|
||||||
|
public void Invalidate() {
|
||||||
|
ValueChanged?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
readonly double _precision;
|
readonly double _precision;
|
||||||
readonly double _step;
|
readonly double _step;
|
||||||
|
@@ -12,8 +12,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
readonly object _target;
|
readonly object _target;
|
||||||
|
|
||||||
public DefaultPropertyMasterAdapter(object target) {
|
public DefaultPropertyMasterAdapter(object target) {
|
||||||
if (target == null) throw new ArgumentNullException("target");
|
_target = target ?? throw new ArgumentNullException("target");
|
||||||
_target = target;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DefaultCategory { get { return "miscellaneous"; } }
|
public string DefaultCategory { get { return "miscellaneous"; } }
|
||||||
|
@@ -6,7 +6,7 @@ using System.ComponentModel;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class RulesetConfig {
|
public class RulesetConfig {
|
||||||
public Generic generic = new Generic();
|
public Generic generic = new();
|
||||||
public class Generic {
|
public class Generic {
|
||||||
[Category("basic")]
|
[Category("basic")]
|
||||||
[JsonProperty("skin")]
|
[JsonProperty("skin")]
|
||||||
@@ -30,9 +30,9 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Dictionary<string, object> configs
|
public Dictionary<string, object> configs
|
||||||
= new Dictionary<string, object>();
|
= new();
|
||||||
public Dictionary<string, InputEntry> inputs
|
public Dictionary<string, InputEntry> inputs
|
||||||
= new Dictionary<string, InputEntry>();
|
= new();
|
||||||
public class InputEntry {
|
public class InputEntry {
|
||||||
public string handler;
|
public string handler;
|
||||||
public int type;
|
public int type;
|
||||||
|
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
internal class RulesetConfigPropertyMasterAdapter : IPropertyMasterAdapter {
|
internal class RulesetConfigPropertyMasterAdapter : IPropertyMasterAdapter {
|
||||||
readonly List<RulesetConfigPropertyAdapter> _props = new List<RulesetConfigPropertyAdapter>();
|
readonly List<RulesetConfigPropertyAdapter> _props = new();
|
||||||
readonly RulesetConfigStore _store;
|
readonly RulesetConfigStore _store;
|
||||||
public PdtEvaluator Evaluator { get; private set; }
|
public PdtEvaluator Evaluator { get; private set; }
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
public void SetValue(string key, object value) {
|
public void SetValue(string key, object value) {
|
||||||
_store[key] = value;
|
_store[key] = value;
|
||||||
foreach (var prop in _props) {
|
foreach (var prop in _props) {
|
||||||
prop.OnValueChanged();
|
prop.Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,11 @@ namespace Cryville.Crtr.Config {
|
|||||||
_master = master;
|
_master = master;
|
||||||
_def = def;
|
_def = def;
|
||||||
Name = (string)key.Name;
|
Name = (string)key.Name;
|
||||||
switch (_def.type) {
|
Type = _def.type switch {
|
||||||
case ConfigType.number: Type = PropertyType.Number; break;
|
ConfigType.number => PropertyType.Number,
|
||||||
case ConfigType.number_stepped: Type = PropertyType.NumberStepped; break;
|
ConfigType.number_stepped => PropertyType.NumberStepped,
|
||||||
default: Type = PropertyType.Unknown; break;
|
_ => PropertyType.Unknown,
|
||||||
}
|
};
|
||||||
_rangeOp = new PropOp.Clip(v => {
|
_rangeOp = new PropOp.Clip(v => {
|
||||||
m_range[0] = (double)v.Behind;
|
m_range[0] = (double)v.Behind;
|
||||||
m_range[1] = (double)v.Ahead;
|
m_range[1] = (double)v.Ahead;
|
||||||
@@ -79,14 +79,13 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public event Action ValueChanged;
|
public event Action ValueChanged;
|
||||||
public void OnValueChanged() {
|
public void Invalidate() {
|
||||||
var ev = ValueChanged;
|
ValueChanged?.Invoke();
|
||||||
if (ev != null) ev();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetMapped { get { return false; } }
|
public bool SetMapped { get { return false; } }
|
||||||
|
|
||||||
readonly PropStores.Float _numst = new PropStores.Float();
|
readonly PropStores.Float _numst = new();
|
||||||
public object MapValue(object value) {
|
public object MapValue(object value) {
|
||||||
_numst.Value = (float)(double)value;
|
_numst.Value = (float)(double)value;
|
||||||
if (_def.value == null) return _numst.Value;
|
if (_def.value == null) return _numst.Value;
|
||||||
|
@@ -6,8 +6,8 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class RulesetConfigStore {
|
public class RulesetConfigStore {
|
||||||
readonly IntKeyedDictionary<PropSrc> _srcs = new IntKeyedDictionary<PropSrc>();
|
readonly IntKeyedDictionary<PropSrc> _srcs = new();
|
||||||
readonly Dictionary<string, int> _revMap = new Dictionary<string, int>();
|
readonly Dictionary<string, int> _revMap = new();
|
||||||
readonly Dictionary<string, object> _values;
|
readonly Dictionary<string, object> _values;
|
||||||
public RulesetConfigStore(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
|
public RulesetConfigStore(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
|
||||||
_values = values;
|
_values = values;
|
||||||
|
@@ -15,7 +15,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
|
|
||||||
PdtRuleset _ruleset;
|
PdtRuleset _ruleset;
|
||||||
InputProxy _proxy;
|
InputProxy _proxy;
|
||||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new();
|
||||||
|
|
||||||
public void Load(PdtRuleset ruleset, RulesetConfig rulesetConfig) {
|
public void Load(PdtRuleset ruleset, RulesetConfig rulesetConfig) {
|
||||||
_ruleset = ruleset;
|
_ruleset = ruleset;
|
||||||
|
@@ -29,7 +29,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
int _targetDim;
|
int _targetDim;
|
||||||
PhysicalDimension? _targetPDim;
|
PhysicalDimension? _targetPDim;
|
||||||
bool _targetNotNull;
|
bool _targetNotNull;
|
||||||
readonly Dictionary<InputSource, InputDialogEntry> _recvsrcs = new Dictionary<InputSource, InputDialogEntry>();
|
readonly Dictionary<InputSource, InputDialogEntry> _recvsrcs = new();
|
||||||
void ShowInternal(Action<InputSource?> callback, string message, InputDefinition def, InputProxy proxy) {
|
void ShowInternal(Action<InputSource?> callback, string message, InputDefinition def, InputProxy proxy) {
|
||||||
_active = true;
|
_active = true;
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
@@ -56,7 +56,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
var result = new PhysicalDimension();
|
var result = new PhysicalDimension();
|
||||||
foreach (var comp in comps) {
|
foreach (var comp in comps) {
|
||||||
int dim = 1;
|
int dim = 1;
|
||||||
if (comp.Length > 1) dim = int.Parse(comp.Substring(1));
|
if (comp.Length > 1) dim = int.Parse(comp[1..]);
|
||||||
switch (comp[0]) {
|
switch (comp[0]) {
|
||||||
case 'T': result.Time += dim; break;
|
case 'T': result.Time += dim; break;
|
||||||
case 'L': result.Length += dim; break;
|
case 'L': result.Length += dim; break;
|
||||||
@@ -98,8 +98,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
Action<InputEvent> _d_HandleInputEvent;
|
Action<InputEvent> _d_HandleInputEvent;
|
||||||
void HandleInputEvent(InputEvent ev) {
|
void HandleInputEvent(InputEvent ev) {
|
||||||
InputSource src = ev.Identifier.Source;
|
InputSource src = ev.Identifier.Source;
|
||||||
InputDialogEntry entry;
|
if (!_recvsrcs.TryGetValue(src, out InputDialogEntry entry)) {
|
||||||
if (!_recvsrcs.TryGetValue(src, out entry)) {
|
|
||||||
_recvsrcs.Add(src, entry = AddSourceItem(src));
|
_recvsrcs.Add(src, entry = AddSourceItem(src));
|
||||||
if (_proxy.IsUsed(src)) {
|
if (_proxy.IsUsed(src)) {
|
||||||
entry.Status |= InputDeviceStatus.Used;
|
entry.Status |= InputDeviceStatus.Used;
|
||||||
|
@@ -74,8 +74,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
Dictionary<int, InputVector> _activeInputs;
|
Dictionary<int, InputVector> _activeInputs;
|
||||||
public void OnInputEvent(InputEvent ev) {
|
public void OnInputEvent(InputEvent ev) {
|
||||||
var id = ev.Identifier.Id;
|
var id = ev.Identifier.Id;
|
||||||
InputVector lastVec;
|
if (!_activeInputs.TryGetValue(id, out InputVector lastVec)) {
|
||||||
if (!_activeInputs.TryGetValue(id, out lastVec)) {
|
|
||||||
if (ev.To.IsNull) return;
|
if (ev.To.IsNull) return;
|
||||||
_activeInputs.Add(id, lastVec = ev.To.Vector);
|
_activeInputs.Add(id, lastVec = ev.To.Vector);
|
||||||
}
|
}
|
||||||
|
@@ -111,9 +111,8 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float GetRatioFromPos(Vector2 pos) {
|
float GetRatioFromPos(Vector2 pos) {
|
||||||
Vector2 lp;
|
|
||||||
RectTransform handleArea = parent.m_handleArea;
|
RectTransform handleArea = parent.m_handleArea;
|
||||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(handleArea, pos, cam, out lp)) {
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(handleArea, pos, cam, out Vector2 lp)) {
|
||||||
lp -= handleArea.rect.position;
|
lp -= handleArea.rect.position;
|
||||||
return Mathf.Clamp01(lp.x / handleArea.rect.width);
|
return Mathf.Clamp01(lp.x / handleArea.rect.width);
|
||||||
}
|
}
|
||||||
@@ -121,8 +120,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetValueFromPos(Vector2 pos) {
|
void SetValueFromPos(Vector2 pos) {
|
||||||
double min, max;
|
parent.GetRange(out double min, out double max);
|
||||||
parent.GetRange(out min, out max);
|
|
||||||
double ratio = GetRatioFromPos(pos);
|
double ratio = GetRatioFromPos(pos);
|
||||||
double result = parent.GetValue(ratio, Time.deltaTime, min, max);
|
double result = parent.GetValue(ratio, Time.deltaTime, min, max);
|
||||||
if (result < min) result = min;
|
if (result < min) result = min;
|
||||||
|
@@ -34,18 +34,25 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new Dictionary<string, List<IPropertyAdapter>>();
|
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new();
|
||||||
public void LoadProperties() {
|
public void LoadProperties() {
|
||||||
_categories.Clear();
|
_categories.Clear();
|
||||||
_invalidated = false;
|
_invalidated = false;
|
||||||
if (Adapter == null) return;
|
if (Adapter == null) return;
|
||||||
foreach (var p in Adapter.GetProperties()) {
|
foreach (var p in Adapter.GetProperties()) {
|
||||||
string category = p.Category;
|
string category = p.Category ?? Adapter.DefaultCategory;
|
||||||
if (category == null) category = Adapter.DefaultCategory;
|
|
||||||
if (!_categories.ContainsKey(category))
|
if (!_categories.ContainsKey(category))
|
||||||
_categories.Add(category, new List<IPropertyAdapter>());
|
_categories.Add(category, new List<IPropertyAdapter>());
|
||||||
_categories[category].Add(p);
|
_categories[category].Add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InvalidatePropertyValues() {
|
||||||
|
foreach (var category in _categories) {
|
||||||
|
foreach (var property in category.Value) {
|
||||||
|
property.Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
protected override TransformHandler Parent { get { return null; } }
|
protected override TransformHandler Parent { get { return null; } }
|
||||||
|
|
||||||
readonly Chart chart;
|
readonly Chart chart;
|
||||||
readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>();
|
readonly List<LibavFileAudioSource> sounds = new();
|
||||||
|
|
||||||
public ChartHandler(Chart _chart) {
|
public ChartHandler(Chart _chart) {
|
||||||
chart = _chart;
|
chart = _chart;
|
||||||
@@ -25,8 +25,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
if (s.CloneType == 16) {
|
if (s.CloneType == 16) {
|
||||||
if (ev == null) { }
|
if (ev == null) { }
|
||||||
else if (ev.Unstamped == null) { }
|
else if (ev.Unstamped == null) { }
|
||||||
else if (ev.Unstamped is Chart.Sound) {
|
else if (ev.Unstamped is Chart.Sound tev) {
|
||||||
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
|
||||||
var dir = new DirectoryInfo(Path.Combine(Game.GameDataPath, "songs", StringUtils.EscapeFileName(tev.id)));
|
var dir = new DirectoryInfo(Path.Combine(Game.GameDataPath, "songs", StringUtils.EscapeFileName(tev.id)));
|
||||||
var files = dir.GetFiles();
|
var files = dir.GetFiles();
|
||||||
var source = new LibavFileAudioSource(files[0].FullName);
|
var source = new LibavFileAudioSource(files[0].FullName);
|
||||||
|
@@ -41,7 +41,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
protected Transform RootTransform;
|
protected Transform RootTransform;
|
||||||
|
|
||||||
readonly List<SkinComponent> _comps = new List<SkinComponent>();
|
readonly List<SkinComponent> _comps = new();
|
||||||
protected IEnumerable<SkinComponent> Components { get { return _comps; } }
|
protected IEnumerable<SkinComponent> Components { get { return _comps; } }
|
||||||
|
|
||||||
public Vector3 Position { get; protected set; }
|
public Vector3 Position { get; protected set; }
|
||||||
@@ -68,7 +68,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
static readonly int _var_current_time = IdentifierManager.Shared.Request("current_time");
|
static readonly int _var_current_time = IdentifierManager.Shared.Request("current_time");
|
||||||
static readonly int _var_invisible_bounds = IdentifierManager.Shared.Request("invisible_bounds");
|
static readonly int _var_invisible_bounds = IdentifierManager.Shared.Request("invisible_bounds");
|
||||||
public readonly IntKeyedDictionary<PropSrc> PropSrcs = new IntKeyedDictionary<PropSrc>();
|
public readonly IntKeyedDictionary<PropSrc> PropSrcs = new();
|
||||||
SkinContainer skinContainer;
|
SkinContainer skinContainer;
|
||||||
protected Judge judge;
|
protected Judge judge;
|
||||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||||
@@ -76,9 +76,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
this.judge = judge;
|
this.judge = judge;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly IntKeyedDictionary<List<Anchor>> Anchors = new IntKeyedDictionary<List<Anchor>>();
|
public readonly IntKeyedDictionary<List<Anchor>> Anchors = new();
|
||||||
public readonly IntKeyedDictionary<Anchor> DynamicAnchors = new IntKeyedDictionary<Anchor>();
|
public readonly IntKeyedDictionary<Anchor> DynamicAnchors = new();
|
||||||
public readonly IntKeyedDictionary<double> DynamicAnchorSetTime = new IntKeyedDictionary<double>();
|
public readonly IntKeyedDictionary<double> DynamicAnchorSetTime = new();
|
||||||
Anchor a_cur;
|
Anchor a_cur;
|
||||||
Anchor a_head;
|
Anchor a_head;
|
||||||
Anchor a_tail;
|
Anchor a_tail;
|
||||||
@@ -98,8 +98,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
DynamicAnchors.Add(name, result);
|
DynamicAnchors.Add(name, result);
|
||||||
DynamicAnchorSetTime.Add(name, double.NaN);
|
DynamicAnchorSetTime.Add(name, double.NaN);
|
||||||
}
|
}
|
||||||
List<Anchor> list;
|
if (!Anchors.TryGetValue(name, out List<Anchor> list))
|
||||||
if (!Anchors.TryGetValue(name, out list))
|
|
||||||
Anchors.Add(name, list = new List<Anchor>());
|
Anchors.Add(name, list = new List<Anchor>());
|
||||||
list.Add(result);
|
list.Add(result);
|
||||||
return result;
|
return result;
|
||||||
@@ -158,8 +157,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||||
if (ev is StampedEvent.Anchor) {
|
if (ev is StampedEvent.Anchor tev) {
|
||||||
var tev = (StampedEvent.Anchor)ev;
|
|
||||||
if (tev.Target == a_head) {
|
if (tev.Target == a_head) {
|
||||||
if (s.CloneType == 2) SetGraphicalActive(true, s);
|
if (s.CloneType == 2) SetGraphicalActive(true, s);
|
||||||
else SetPreGraphicalActive(true, s);
|
else SetPreGraphicalActive(true, s);
|
||||||
@@ -234,7 +232,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
= new(1024);
|
||||||
void PushAnchorEvent(ContainerState state, double time, Anchor anchor, int priority = 0, bool forced = false) {
|
void PushAnchorEvent(ContainerState state, double time, Anchor anchor, int priority = 0, bool forced = false) {
|
||||||
var tev = anchorEvPool.Rent();
|
var tev = anchorEvPool.Rent();
|
||||||
tev.Time = time;
|
tev.Time = time;
|
||||||
@@ -245,8 +243,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
state.Bus.PushTempEvent(tev);
|
state.Bus.PushTempEvent(tev);
|
||||||
}
|
}
|
||||||
public virtual void Discard(ContainerState s, StampedEvent ev) {
|
public virtual void Discard(ContainerState s, StampedEvent ev) {
|
||||||
if (ev is StampedEvent.Anchor) {
|
if (ev is StampedEvent.Anchor anchor) {
|
||||||
ReturnAnchorEvent((StampedEvent.Anchor)ev);
|
ReturnAnchorEvent(anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ReturnAnchorEvent(StampedEvent.Anchor ev) {
|
void ReturnAnchorEvent(StampedEvent.Anchor ev) {
|
||||||
@@ -264,8 +262,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
Anchor _openedAnchor;
|
Anchor _openedAnchor;
|
||||||
public int OpenedAnchorName { get { return _openedAnchor == null ? 0 : _openedAnchor.Name; } }
|
public int OpenedAnchorName { get { return _openedAnchor == null ? 0 : _openedAnchor.Name; } }
|
||||||
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
|
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
|
||||||
List<Anchor> anchors;
|
var ret = Anchors.TryGetValue(name, out List<Anchor> anchors);
|
||||||
var ret = Anchors.TryGetValue(name, out anchors);
|
|
||||||
result = anchors;
|
result = anchors;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -19,11 +19,11 @@ namespace Cryville.Crtr.Event {
|
|||||||
public ushort Depth;
|
public ushort Depth;
|
||||||
|
|
||||||
public Dictionary<EventContainer, ContainerState> Children
|
public Dictionary<EventContainer, ContainerState> Children
|
||||||
= new Dictionary<EventContainer, ContainerState>();
|
= new();
|
||||||
HashSet<EventContainer> ActiveChildren
|
HashSet<EventContainer> ActiveChildren
|
||||||
= new HashSet<EventContainer>();
|
= new();
|
||||||
public Dictionary<Type, List<ContainerState>> TypedChildren
|
public Dictionary<Type, List<ContainerState>> TypedChildren
|
||||||
= new Dictionary<Type, List<ContainerState>>();
|
= new();
|
||||||
|
|
||||||
public ContainerState GetChild(int index, Type handlerType) {
|
public ContainerState GetChild(int index, Type handlerType) {
|
||||||
var list = TypedChildren[handlerType];
|
var list = TypedChildren[handlerType];
|
||||||
@@ -110,8 +110,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
void AddChild(EventContainer c, ContainerState parent) {
|
void AddChild(EventContainer c, ContainerState parent) {
|
||||||
parent.Children.Add(c, this);
|
parent.Children.Add(c, this);
|
||||||
Type t = c.GetType();
|
Type t = c.GetType();
|
||||||
List<ContainerState> tc;
|
if (!parent.TypedChildren.TryGetValue(t, out List<ContainerState> tc))
|
||||||
if (!parent.TypedChildren.TryGetValue(t, out tc))
|
|
||||||
parent.TypedChildren.Add(t, tc = new List<ContainerState>());
|
parent.TypedChildren.Add(t, tc = new List<ContainerState>());
|
||||||
tc.Add(this);
|
tc.Add(this);
|
||||||
}
|
}
|
||||||
@@ -159,15 +158,13 @@ namespace Cryville.Crtr.Event {
|
|||||||
if (dest.m_active) dest.Bus.NotifyActiveChanged(dest);
|
if (dest.m_active) dest.Bus.NotifyActiveChanged(dest);
|
||||||
|
|
||||||
foreach (var mv in Values) {
|
foreach (var mv in Values) {
|
||||||
RealtimeMotionValue dv;
|
if (dest.Values.TryGetValue(mv.Key, out RealtimeMotionValue dv)) mv.Value.CopyTo(dv, false);
|
||||||
if (dest.Values.TryGetValue(mv.Key, out dv)) mv.Value.CopyTo(dv, false);
|
|
||||||
else dest.Values.Add(mv.Key, mv.Value.Clone());
|
else dest.Values.Add(mv.Key, mv.Value.Clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
|
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
|
||||||
foreach (var cv in CachedValues) {
|
foreach (var cv in CachedValues) {
|
||||||
MotionCache dv;
|
if (!dest.CachedValues.TryGetValue(cv.Key, out MotionCache dv)) {
|
||||||
if (!dest.CachedValues.TryGetValue(cv.Key, out dv)) {
|
|
||||||
dest.CachedValues.Add(cv.Key, dv = dest._mcpa.Rent(cv.Key));
|
dest.CachedValues.Add(cv.Key, dv = dest._mcpa.Rent(cv.Key));
|
||||||
}
|
}
|
||||||
cv.Value.CopyTo(dv);
|
cv.Value.CopyTo(dv);
|
||||||
@@ -229,13 +226,12 @@ namespace Cryville.Crtr.Event {
|
|||||||
#region Motion
|
#region Motion
|
||||||
readonly CategorizedPoolAccessor<int, RealtimeMotionValue> _rmvpa;
|
readonly CategorizedPoolAccessor<int, RealtimeMotionValue> _rmvpa;
|
||||||
readonly CategorizedPoolAccessor<int, MotionCache> _mcpa;
|
readonly CategorizedPoolAccessor<int, MotionCache> _mcpa;
|
||||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new(4);
|
||||||
IntKeyedDictionary<RealtimeMotionValue> Values;
|
IntKeyedDictionary<RealtimeMotionValue> Values;
|
||||||
IntKeyedDictionary<MotionCache> CachedValues;
|
IntKeyedDictionary<MotionCache> CachedValues;
|
||||||
|
|
||||||
void InvalidateMotion(int name) {
|
void InvalidateMotion(int name) {
|
||||||
MotionCache cache;
|
if (!CachedValues.TryGetValue(name, out MotionCache cache))
|
||||||
if (!CachedValues.TryGetValue(name, out cache))
|
|
||||||
CachedValues.Add(name, cache = _mcpa.Rent(name));
|
CachedValues.Add(name, cache = _mcpa.Rent(name));
|
||||||
cache.Valid = false;
|
cache.Valid = false;
|
||||||
foreach (var c in ActiveChildren)
|
foreach (var c in ActiveChildren)
|
||||||
@@ -243,8 +239,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector GetComputedValue(int key) {
|
public Vector GetComputedValue(int key) {
|
||||||
MotionCache tr;
|
if (!CachedValues.TryGetValue(key, out MotionCache tr))
|
||||||
if (!CachedValues.TryGetValue(key, out tr))
|
|
||||||
CachedValues.Add(key, tr = _mcpa.Rent(key));
|
CachedValues.Add(key, tr = _mcpa.Rent(key));
|
||||||
Vector r = tr.Value;
|
Vector r = tr.Value;
|
||||||
if (tr.Valid) return r;
|
if (tr.Valid) return r;
|
||||||
@@ -322,8 +317,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
public void Discard(StampedEvent ev) {
|
public void Discard(StampedEvent ev) {
|
||||||
Handler.Discard(this, ev);
|
Handler.Discard(this, ev);
|
||||||
if (ev is StampedEvent.RelativeMotion) {
|
if (ev is StampedEvent.RelativeMotion motion) {
|
||||||
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)ev);
|
ReturnRelativeMotionEvent(motion);
|
||||||
}
|
}
|
||||||
else if (ev.Origin is StampedEvent.RelativeMotion) {
|
else if (ev.Origin is StampedEvent.RelativeMotion) {
|
||||||
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
|
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
|
||||||
@@ -345,8 +340,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
_rmvpa.Return(mv);
|
_rmvpa.Return(mv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ev is StampedEvent.RelativeMotion) {
|
else if (ev is StampedEvent.RelativeMotion tev) {
|
||||||
var tev = (StampedEvent.RelativeMotion)ev;
|
|
||||||
var mv = _rmvpa.Rent(tev.Name);
|
var mv = _rmvpa.Rent(tev.Name);
|
||||||
mv.CloneTypeFlag = CloneType;
|
mv.CloneTypeFlag = CloneType;
|
||||||
Values[tev.Name].CopyTo(mv, true);
|
Values[tev.Name].CopyTo(mv, true);
|
||||||
@@ -369,13 +363,13 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
else if (ev.Origin != null) {
|
else if (ev.Origin != null) {
|
||||||
var oev = ev.Origin;
|
var oev = ev.Origin;
|
||||||
if (oev is StampedEvent.RelativeMotion) {
|
if (oev is StampedEvent.RelativeMotion motion) {
|
||||||
Update(ev);
|
Update(ev);
|
||||||
var mv = PlayingMotions[oev];
|
var mv = PlayingMotions[oev];
|
||||||
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
|
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
|
||||||
PlayingMotions.Remove(oev);
|
PlayingMotions.Remove(oev);
|
||||||
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
|
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
|
||||||
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)oev);
|
ReturnRelativeMotionEvent(motion);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var nev = oev.Unstamped;
|
var nev = oev.Unstamped;
|
||||||
@@ -385,8 +379,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
|
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
|
||||||
PlayingMotions.Remove(oev);
|
PlayingMotions.Remove(oev);
|
||||||
}
|
}
|
||||||
else if (nev is EventContainer) {
|
else if (nev is EventContainer cev) {
|
||||||
var cev = (EventContainer)nev;
|
|
||||||
var ccs = Children[cev];
|
var ccs = Children[cev];
|
||||||
UpdateMotions();
|
UpdateMotions();
|
||||||
ccs.LogicalActive = false;
|
ccs.LogicalActive = false;
|
||||||
@@ -455,8 +448,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static readonly PropStores.Float _ttimest = new PropStores.Float();
|
static readonly PropStores.Float _ttimest = new();
|
||||||
static readonly PropStores.Vector4 _transst = new PropStores.Vector4();
|
static readonly PropStores.Vector4 _transst = new();
|
||||||
Vector4 GetTransition(float time, PdtExpression transition) {
|
Vector4 GetTransition(float time, PdtExpression transition) {
|
||||||
if (time >= 1) return Vector4.one;
|
if (time >= 1) return Vector4.one;
|
||||||
if (transition == null) return new Vector4(time, time, time, time);
|
if (transition == null) return new Vector4(time, time, time, time);
|
||||||
@@ -495,9 +488,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static readonly SimpleObjectPool<StampedEvent.RelativeMotion> relmEvPool
|
static readonly SimpleObjectPool<StampedEvent.RelativeMotion> relmEvPool
|
||||||
= new SimpleObjectPool<StampedEvent.RelativeMotion>(1024);
|
= new(1024);
|
||||||
static readonly SimpleObjectPool<StampedEvent.Temporary> erelmEvPool
|
static readonly SimpleObjectPool<StampedEvent.Temporary> erelmEvPool
|
||||||
= new SimpleObjectPool<StampedEvent.Temporary>(1024);
|
= new(1024);
|
||||||
public void PreAnchor() {
|
public void PreAnchor() {
|
||||||
PushRelativeMotions(Handler.ns.Bus);
|
PushRelativeMotions(Handler.ns.Bus);
|
||||||
Handler.PreAnchor();
|
Handler.PreAnchor();
|
||||||
|
@@ -9,7 +9,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly List<StampedEvent> queue = new List<StampedEvent>();
|
readonly List<StampedEvent> queue = new();
|
||||||
public int Count {
|
public int Count {
|
||||||
get { return queue.Count; }
|
get { return queue.Count; }
|
||||||
}
|
}
|
||||||
|
@@ -12,16 +12,16 @@ namespace Cryville.Crtr.Event {
|
|||||||
readonly Chart chart;
|
readonly Chart chart;
|
||||||
ContainerState rootState;
|
ContainerState rootState;
|
||||||
readonly Dictionary<ChartEvent, ContainerState> containerMap
|
readonly Dictionary<ChartEvent, ContainerState> containerMap
|
||||||
= new Dictionary<ChartEvent, ContainerState>();
|
= new();
|
||||||
readonly Dictionary<EventContainer, ContainerState> stateMap
|
readonly Dictionary<EventContainer, ContainerState> stateMap
|
||||||
= new Dictionary<EventContainer, ContainerState>();
|
= new();
|
||||||
readonly Dictionary<ChartEvent, StampedEvent> map
|
readonly Dictionary<ChartEvent, StampedEvent> map
|
||||||
= new Dictionary<ChartEvent, StampedEvent>();
|
= new();
|
||||||
readonly Dictionary<EventContainer, List<StampedEvent>> coeventMap
|
readonly Dictionary<EventContainer, List<StampedEvent>> coeventMap
|
||||||
= new Dictionary<EventContainer, List<StampedEvent>>();
|
= new();
|
||||||
readonly HashSet<ChartEvent> coevents = new HashSet<ChartEvent>();
|
readonly HashSet<ChartEvent> coevents = new();
|
||||||
readonly List<StampedEvent> stampedEvents = new List<StampedEvent>();
|
readonly List<StampedEvent> stampedEvents = new();
|
||||||
readonly List<EventBatch> batches = new List<EventBatch>();
|
readonly List<EventBatch> batches = new();
|
||||||
|
|
||||||
double beat;
|
double beat;
|
||||||
float tempo;
|
float tempo;
|
||||||
@@ -58,8 +58,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
Events.Add(ev);
|
Events.Add(ev);
|
||||||
containerMap.Add(ev, cs);
|
containerMap.Add(ev, cs);
|
||||||
if (ev is EventContainer)
|
if (ev is EventContainer container)
|
||||||
AddEventContainer((EventContainer)ev, cs);
|
AddEventContainer(container, cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,17 +104,16 @@ namespace Cryville.Crtr.Event {
|
|||||||
var pev = map[oev];
|
var pev = map[oev];
|
||||||
pev.ReleaseEvent = sev;
|
pev.ReleaseEvent = sev;
|
||||||
sev.Origin = pev;
|
sev.Origin = pev;
|
||||||
if (oev is EventContainer) {
|
if (oev is EventContainer container) {
|
||||||
stampedEvents.Add(new StampedEvent.ClipAhead {
|
stampedEvents.Add(new StampedEvent.ClipAhead {
|
||||||
Container = con,
|
Container = con,
|
||||||
Origin = pev,
|
Origin = pev,
|
||||||
Time = etime + ((EventContainer)oev).Clip.Ahead,
|
Time = etime + container.Clip.Ahead,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (con != null && coevents.Contains(ev)) {
|
if (con != null && coevents.Contains(ev)) {
|
||||||
List<StampedEvent> cevs;
|
if (!coeventMap.TryGetValue(con, out List<StampedEvent> cevs)) {
|
||||||
if (!coeventMap.TryGetValue(con, out cevs)) {
|
|
||||||
coeventMap.Add(con, cevs = new List<StampedEvent>());
|
coeventMap.Add(con, cevs = new List<StampedEvent>());
|
||||||
}
|
}
|
||||||
cevs.Add(sev);
|
cevs.Add(sev);
|
||||||
@@ -168,9 +167,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BatchCoevents(StampedEvent ev, List<StampedEvent> ocevs = null) {
|
void BatchCoevents(StampedEvent ev, List<StampedEvent> ocevs = null) {
|
||||||
if (!(ev.Unstamped is EventContainer)) return;
|
if (ev.Unstamped is not EventContainer container) return;
|
||||||
List<StampedEvent> cevs;
|
if (coeventMap.TryGetValue(container, out List<StampedEvent> cevs)) {
|
||||||
if (coeventMap.TryGetValue((EventContainer)ev.Unstamped, out cevs)) {
|
|
||||||
var rootFlag = ocevs == null;
|
var rootFlag = ocevs == null;
|
||||||
if (rootFlag) ev.Coevents = ocevs = new List<StampedEvent>();
|
if (rootFlag) ev.Coevents = ocevs = new List<StampedEvent>();
|
||||||
foreach (var cev in cevs) {
|
foreach (var cev in cevs) {
|
||||||
|
@@ -12,11 +12,11 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<EventContainer, ContainerState> states
|
Dictionary<EventContainer, ContainerState> states
|
||||||
= new Dictionary<EventContainer, ContainerState>();
|
= new();
|
||||||
HashSet<ContainerState> activeStates
|
HashSet<ContainerState> activeStates
|
||||||
= new HashSet<ContainerState>();
|
= new();
|
||||||
HashSet<ContainerState> invalidatedStates
|
HashSet<ContainerState> invalidatedStates
|
||||||
= new HashSet<ContainerState>();
|
= new();
|
||||||
public int ActiveStateCount { get { return activeStates.Count; } }
|
public int ActiveStateCount { get { return activeStates.Count; } }
|
||||||
|
|
||||||
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
||||||
@@ -84,14 +84,14 @@ namespace Cryville.Crtr.Event {
|
|||||||
s.Value.AttachSystems(skin, judge);
|
s.Value.AttachSystems(skin, judge);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>();
|
List<StampedEvent.Temporary> tempEvents = new();
|
||||||
public void PushTempEvent(StampedEvent.Temporary ev) {
|
public void PushTempEvent(StampedEvent.Temporary ev) {
|
||||||
var index = tempEvents.BinarySearch(ev);
|
var index = tempEvents.BinarySearch(ev);
|
||||||
if (index < 0) index = ~index;
|
if (index < 0) index = ~index;
|
||||||
tempEvents.Insert(index, ev);
|
tempEvents.Insert(index, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly StampedEvent.Temporary _dummyEvent = new StampedEvent.Temporary();
|
readonly StampedEvent.Temporary _dummyEvent = new();
|
||||||
public void StripTempEvents() {
|
public void StripTempEvents() {
|
||||||
_dummyEvent.Time = Time;
|
_dummyEvent.Time = Time;
|
||||||
var index = tempEvents.BinarySearch(_dummyEvent);
|
var index = tempEvents.BinarySearch(_dummyEvent);
|
||||||
|
@@ -39,7 +39,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Vector3Operator : IVectorOperator<Vector3> {
|
class Vector3Operator : IVectorOperator<Vector3> {
|
||||||
public static Vector3Operator Instance = new Vector3Operator();
|
public static Vector3Operator Instance = new();
|
||||||
|
|
||||||
public Vector3 Add(Vector3 lhs, Vector3 rhs) {
|
public Vector3 Add(Vector3 lhs, Vector3 rhs) {
|
||||||
return lhs + rhs;
|
return lhs + rhs;
|
||||||
|
@@ -21,8 +21,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
_reg = ChartPlayer.motionRegistry[name];
|
_reg = ChartPlayer.motionRegistry[name];
|
||||||
}
|
}
|
||||||
protected override MotionCache Construct() {
|
protected override MotionCache Construct() {
|
||||||
var result = new MotionCache();
|
var result = new MotionCache {
|
||||||
result.Value = (Vector)Activator.CreateInstance(_reg.Type);
|
Value = (Vector)Activator.CreateInstance(_reg.Type)
|
||||||
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
protected override void Reset(MotionCache obj) {
|
protected override void Reset(MotionCache obj) {
|
||||||
|
@@ -17,15 +17,15 @@ namespace Cryville.Crtr.Event {
|
|||||||
public override string TypeName { get { return "note"; } }
|
public override string TypeName { get { return "note"; } }
|
||||||
|
|
||||||
SectionalGameObject[] sgos;
|
SectionalGameObject[] sgos;
|
||||||
readonly Dictionary<Chart.Judge, JudgeState> judges = new Dictionary<Chart.Judge, JudgeState>();
|
readonly Dictionary<Chart.Judge, JudgeState> judges = new();
|
||||||
class JudgeState {
|
class JudgeState {
|
||||||
static readonly int _var_judge_result = IdentifierManager.Shared.Request("judge_result");
|
static readonly int _var_judge_result = IdentifierManager.Shared.Request("judge_result");
|
||||||
static readonly int _var_judge_time_absolute = IdentifierManager.Shared.Request("judge_time_absolute");
|
static readonly int _var_judge_time_absolute = IdentifierManager.Shared.Request("judge_time_absolute");
|
||||||
static readonly int _var_judge_time_relative = IdentifierManager.Shared.Request("judge_time_relative");
|
static readonly int _var_judge_time_relative = IdentifierManager.Shared.Request("judge_time_relative");
|
||||||
public Anchor StaticAnchor { get; private set; }
|
public Anchor StaticAnchor { get; private set; }
|
||||||
readonly PropStores.Float _jtabsst = new PropStores.Float();
|
readonly PropStores.Float _jtabsst = new();
|
||||||
readonly PropStores.Float _jtrelst = new PropStores.Float();
|
readonly PropStores.Float _jtrelst = new();
|
||||||
readonly PropStores.Identifier _resultst = new PropStores.Identifier();
|
readonly PropStores.Identifier _resultst = new();
|
||||||
public JudgeState(NoteHandler handler, int name) {
|
public JudgeState(NoteHandler handler, int name) {
|
||||||
StaticAnchor = handler.RegisterAnchor(handler.judge.judgeMap[name], false, 3);
|
StaticAnchor = handler.RegisterAnchor(handler.judge.judgeMap[name], false, 3);
|
||||||
}
|
}
|
||||||
@@ -147,8 +147,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void ReportJudge(JudgeEvent ev, float time, Identifier result) {
|
internal void ReportJudge(JudgeEvent ev, float time, Identifier result) {
|
||||||
JudgeState state;
|
if (!judges.TryGetValue(ev.BaseEvent, out JudgeState state)) return;
|
||||||
if (!judges.TryGetValue(ev.BaseEvent, out state)) return;
|
|
||||||
state.MarkJudged(time, (float)(ev.StartTime - time), result.Key);
|
state.MarkJudged(time, (float)(ev.StartTime - time), result.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,21 +48,19 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MotionNode GetRelativeNode(short id) {
|
public MotionNode GetRelativeNode(short id) {
|
||||||
MotionNode result;
|
RelativeNodes.TryGetValue(id, out MotionNode result);
|
||||||
RelativeNodes.TryGetValue(id, out result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRelativeNode(MotionNode node) {
|
public void SetRelativeNode(MotionNode node) {
|
||||||
MotionNode cnode;
|
if (!RelativeNodes.TryGetValue(node.Id, out MotionNode cnode)) {
|
||||||
if (!RelativeNodes.TryGetValue(node.Id, out cnode)) {
|
|
||||||
cnode = MotionNodePool.Shared.Rent(_type);
|
cnode = MotionNodePool.Shared.Rent(_type);
|
||||||
cnode.Id = node.Id;
|
cnode.Id = node.Id;
|
||||||
RelativeNodes.Add(node.Id, cnode);
|
RelativeNodes.Add(node.Id, cnode);
|
||||||
}
|
}
|
||||||
if (node.Time != null) node.Time.CopyTo(cnode.Time);
|
node.Time?.CopyTo(cnode.Time);
|
||||||
if (node.EndTime != null) node.EndTime.CopyTo(cnode.EndTime);
|
node.EndTime?.CopyTo(cnode.EndTime);
|
||||||
if (node.Value != null) node.Value.CopyTo(cnode.Value);
|
node.Value?.CopyTo(cnode.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -7,7 +7,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
protected abstract TransformHandler Parent { get; }
|
protected abstract TransformHandler Parent { get; }
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
base.Init();
|
base.Init();
|
||||||
sgos = Components.Where(c => c is SectionalGameObject).Cast<SectionalGameObject>().ToArray();
|
sgos = Components.OfType<SectionalGameObject>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionalGameObject[] sgos;
|
SectionalGameObject[] sgos;
|
||||||
|
@@ -12,9 +12,8 @@ namespace Cryville.Crtr.Extensions {
|
|||||||
|
|
||||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||||
try {
|
try {
|
||||||
using (var stream = file.OpenRead()) {
|
using var stream = file.OpenRead();
|
||||||
ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate));
|
ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (BadImageFormatException ex) {
|
catch (BadImageFormatException ex) {
|
||||||
throw new FormatException("Invalid extension.", ex);
|
throw new FormatException("Invalid extension.", ex);
|
||||||
|
@@ -13,19 +13,17 @@ namespace Cryville.Crtr.Extensions.Umg {
|
|||||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||||
var meta = Path.Combine(file.Directory.FullName, "meta.json");
|
var meta = Path.Combine(file.Directory.FullName, "meta.json");
|
||||||
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
|
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
|
||||||
using (StreamReader reader = new StreamReader(meta, Encoding.UTF8)) {
|
using StreamReader reader = new(meta, Encoding.UTF8);
|
||||||
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
ses.AddResource(new ChartResource(data.name, file));
|
ses.AddResource(new ChartResource(data.name, file));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class ChartResource : FileResource {
|
public class ChartResource : FileResource {
|
||||||
public ChartResource(string name, FileInfo master) : base(name, master) {
|
public ChartResource(string name, FileInfo master) : base(name, master) {
|
||||||
using (var reader = new StreamReader(master.FullName)) {
|
using var reader = new StreamReader(master.FullName);
|
||||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
|
||||||
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,18 +12,16 @@ namespace Cryville.Crtr.Extensions.Umg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
using StreamReader reader = new(file.FullName, Encoding.UTF8);
|
||||||
var data = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
var data = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
||||||
ses.AddResource(new RulesetResource(data.name, file));
|
ses.AddResource(new RulesetResource(data.name, file));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class RulesetResource : FileResource {
|
public class RulesetResource : FileResource {
|
||||||
public RulesetResource(string name, FileInfo master) : base(name, master) {
|
public RulesetResource(string name, FileInfo master) : base(name, master) {
|
||||||
using (var reader = new StreamReader(master.FullName)) {
|
using var reader = new StreamReader(master.FullName);
|
||||||
var meta = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
var meta = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
||||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,22 +12,20 @@ namespace Cryville.Crtr.Extensions.Umg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
using StreamReader reader = new(file.FullName, Encoding.UTF8);
|
||||||
var data = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
var data = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||||
ses.AddResource(new SkinResource(data.name, file));
|
ses.AddResource(new SkinResource(data.name, file));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SkinResource : FileResource {
|
public class SkinResource : FileResource {
|
||||||
public string RulesetName { get; private set; }
|
public string RulesetName { get; private set; }
|
||||||
public SkinResource(string name, FileInfo master) : base(name, master) {
|
public SkinResource(string name, FileInfo master) : base(name, master) {
|
||||||
using (var reader = new StreamReader(master.FullName)) {
|
using var reader = new StreamReader(master.FullName);
|
||||||
var meta = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
var meta = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||||
RulesetName = meta.ruleset;
|
RulesetName = meta.ruleset;
|
||||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||||
foreach (var frame in meta.frames) {
|
foreach (var frame in meta.frames) {
|
||||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ using Newtonsoft.Json;
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@@ -36,10 +37,10 @@ namespace Cryville.Crtr {
|
|||||||
public static SimpleSequencerSource AudioSequencer;
|
public static SimpleSequencerSource AudioSequencer;
|
||||||
public static SimpleSequencerSession AudioSession;
|
public static SimpleSequencerSession AudioSession;
|
||||||
public static InputManager InputManager;
|
public static InputManager InputManager;
|
||||||
public static readonly NetworkTaskWorker NetworkTaskWorker = new NetworkTaskWorker();
|
public static readonly NetworkTaskWorker NetworkTaskWorker = new();
|
||||||
|
|
||||||
public static readonly JsonSerializerSettings GlobalJsonSerializerSettings
|
public static readonly JsonSerializerSettings GlobalJsonSerializerSettings
|
||||||
= new JsonSerializerSettings() {
|
= new() {
|
||||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ namespace Cryville.Crtr {
|
|||||||
static FileStream _logFileStream;
|
static FileStream _logFileStream;
|
||||||
static StreamLoggerListener _logWriter;
|
static StreamLoggerListener _logWriter;
|
||||||
|
|
||||||
|
public static string UnityUserAgent { get; private set; }
|
||||||
|
|
||||||
static bool _init;
|
static bool _init;
|
||||||
public static void Init() {
|
public static void Init() {
|
||||||
if (_init) return;
|
if (_init) return;
|
||||||
@@ -124,18 +127,19 @@ namespace Cryville.Crtr {
|
|||||||
#error No FFmpeg search path.
|
#error No FFmpeg search path.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
var audioEngineBuilder = new EngineBuilder();
|
||||||
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
||||||
EngineBuilder.Engines.Add(typeof(Audio.Wasapi.MMDeviceEnumeratorWrapper));
|
audioEngineBuilder.Engines.Add(typeof(Audio.Wasapi.MMDeviceEnumeratorWrapper));
|
||||||
EngineBuilder.Engines.Add(typeof(Audio.WaveformAudio.WaveDeviceManager));
|
audioEngineBuilder.Engines.Add(typeof(Audio.WaveformAudio.WaveDeviceManager));
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
EngineBuilder.Engines.Add(typeof(Audio.AAudio.AAudioManager));
|
audioEngineBuilder.Engines.Add(typeof(Audio.AAudio.AAudioManager));
|
||||||
EngineBuilder.Engines.Add(typeof(Audio.OpenSLES.Engine));
|
audioEngineBuilder.Engines.Add(typeof(Audio.OpenSLES.Engine));
|
||||||
#else
|
#else
|
||||||
#error No audio engine defined.
|
#error No audio engine defined.
|
||||||
#endif
|
#endif
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
AudioManager = EngineBuilder.Create();
|
AudioManager = audioEngineBuilder.Create();
|
||||||
if (AudioManager == null) {
|
if (AudioManager == null) {
|
||||||
Dialog.Show(null, "Fatal error: Cannot initialize audio engine");
|
Dialog.Show(null, "Fatal error: Cannot initialize audio engine");
|
||||||
MainLogger.Log(5, "Audio", "Cannot initialize audio engine");
|
MainLogger.Log(5, "Audio", "Cannot initialize audio engine");
|
||||||
@@ -160,7 +164,7 @@ namespace Cryville.Crtr {
|
|||||||
Dialog.Show(null, "An error occurred while trying to initialize the recommended audio engine\nTrying to use fallback audio engines");
|
Dialog.Show(null, "An error occurred while trying to initialize the recommended audio engine\nTrying to use fallback audio engines");
|
||||||
MainLogger.Log(4, "Audio", "An error occurred when initializing the audio engine: {0}", ex);
|
MainLogger.Log(4, "Audio", "An error occurred when initializing the audio engine: {0}", ex);
|
||||||
MainLogger.Log(2, "Audio", "Trying to use fallback audio engines");
|
MainLogger.Log(2, "Audio", "Trying to use fallback audio engines");
|
||||||
EngineBuilder.Engines.Remove(AudioManager.GetType());
|
audioEngineBuilder.Engines.Remove(AudioManager.GetType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,15 +172,40 @@ namespace Cryville.Crtr {
|
|||||||
if (!dir.Exists || Settings.Default.LastRunVersion != Application.version) {
|
if (!dir.Exists || Settings.Default.LastRunVersion != Application.version) {
|
||||||
Directory.CreateDirectory(dir.FullName);
|
Directory.CreateDirectory(dir.FullName);
|
||||||
var defaultData = Resources.Load<TextAsset>("default");
|
var defaultData = Resources.Load<TextAsset>("default");
|
||||||
using (var zip = ZipFile.Read(defaultData.bytes)) {
|
using var zip = ZipFile.Read(defaultData.bytes);
|
||||||
zip.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
|
zip.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
|
||||||
zip.ExtractAll(Settings.Default.GameDataPath);
|
zip.ExtractAll(Settings.Default.GameDataPath);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.Default.LastRunVersion = Application.version;
|
Settings.Default.LastRunVersion = Application.version;
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
|
|
||||||
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
||||||
|
UnityUserAgent = string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"CosmoResona/{0} (Windows NT {1}; {2})",
|
||||||
|
Application.version,
|
||||||
|
Environment.OSVersion.Version,
|
||||||
|
RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant()
|
||||||
|
);
|
||||||
|
#elif UNITY_ANDROID
|
||||||
|
var androidClassBuildVersion = AndroidJNI.FindClass("android/os/Build$VERSION");
|
||||||
|
var androidRelease = AndroidJNI.GetStaticStringField(androidClassBuildVersion, AndroidJNI.GetStaticFieldID(androidClassBuildVersion, "RELEASE", "Ljava/lang/String;"));
|
||||||
|
var androidClassBuild = AndroidJNI.FindClass("android/os/Build");
|
||||||
|
var androidModel = AndroidJNI.GetStaticStringField(androidClassBuild, AndroidJNI.GetStaticFieldID(androidClassBuild, "MODEL", "Ljava/lang/String;"));
|
||||||
|
var androidID = AndroidJNI.GetStaticStringField(androidClassBuild, AndroidJNI.GetStaticFieldID(androidClassBuild, "ID", "Ljava/lang/String;"));
|
||||||
|
UnityUserAgent = string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"CosmoResona/{0} (Linux; Android {1}; {2} Build/{3})",
|
||||||
|
Application.version,
|
||||||
|
androidRelease ?? "12.0.99",
|
||||||
|
androidModel,
|
||||||
|
androidID
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
#error No Unity User Agent
|
||||||
|
#endif
|
||||||
|
|
||||||
MainLogger.Log(1, "UI", "Initializing font manager");
|
MainLogger.Log(1, "UI", "Initializing font manager");
|
||||||
foreach (var res in Resources.LoadAll<TextAsset>("cldr/common/validity")) {
|
foreach (var res in Resources.LoadAll<TextAsset>("cldr/common/validity")) {
|
||||||
IdValidity.Load(LoadXmlDocument(res));
|
IdValidity.Load(LoadXmlDocument(res));
|
||||||
@@ -193,18 +222,16 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static readonly Encoding _encoding = new UTF8Encoding(false, true);
|
static readonly Encoding _encoding = new UTF8Encoding(false, true);
|
||||||
static readonly XmlReaderSettings _xmlSettings = new XmlReaderSettings {
|
static readonly XmlReaderSettings _xmlSettings = new() {
|
||||||
DtdProcessing = DtdProcessing.Ignore,
|
DtdProcessing = DtdProcessing.Ignore,
|
||||||
};
|
};
|
||||||
static XDocument LoadXmlDocument(string path) {
|
static XDocument LoadXmlDocument(string path) {
|
||||||
return LoadXmlDocument(Resources.Load<TextAsset>(path));
|
return LoadXmlDocument(Resources.Load<TextAsset>(path));
|
||||||
}
|
}
|
||||||
static XDocument LoadXmlDocument(TextAsset asset) {
|
static XDocument LoadXmlDocument(TextAsset asset) {
|
||||||
using (var stream = new MemoryStream(_encoding.GetBytes(asset.text))) {
|
using var stream = new MemoryStream(_encoding.GetBytes(asset.text));
|
||||||
using (var reader = XmlReader.Create(stream, _xmlSettings)) {
|
using var reader = XmlReader.Create(stream, _xmlSettings);
|
||||||
return XDocument.Load(reader);
|
return XDocument.Load(reader);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _shutdown;
|
static bool _shutdown;
|
||||||
@@ -233,15 +260,13 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void OnInternalLog(string condition, string stackTrace, LogType type) {
|
static void OnInternalLog(string condition, string stackTrace, LogType type) {
|
||||||
int l;
|
var l = type switch {
|
||||||
switch (type) {
|
LogType.Log => 1,
|
||||||
case LogType.Log: l = 1; break;
|
LogType.Assert => 2,
|
||||||
case LogType.Assert: l = 2; break;
|
LogType.Warning => 3,
|
||||||
case LogType.Warning: l = 3; break;
|
LogType.Error or LogType.Exception => 4,
|
||||||
case LogType.Error:
|
_ => 1,
|
||||||
case LogType.Exception: l = 4; break;
|
};
|
||||||
default: l = 1; break;
|
|
||||||
}
|
|
||||||
MainLogger.Log(l, "Internal", "{0}\n{1}", condition, stackTrace);
|
MainLogger.Log(l, "Internal", "{0}\n{1}", condition, stackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ using System;
|
|||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class JsonPdtExpConverter : JsonConverter<PdtExpression> {
|
public class JsonPdtExpConverter : JsonConverter<PdtExpression> {
|
||||||
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
|
static readonly PdtFragmentInterpreter _itor = new();
|
||||||
public override PdtExpression ReadJson(JsonReader reader, Type objectType, PdtExpression existingValue, bool hasExistingValue, JsonSerializer serializer) {
|
public override PdtExpression ReadJson(JsonReader reader, Type objectType, PdtExpression existingValue, bool hasExistingValue, JsonSerializer serializer) {
|
||||||
_itor.SetSource((string)reader.Value);
|
_itor.SetSource((string)reader.Value);
|
||||||
return _itor.GetExp();
|
return _itor.GetExp();
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user