Compare commits
199 Commits
0.5.0-rc0
...
a7608bcd7e
1
.gitignore
vendored
1
.gitignore
vendored
@@ -61,6 +61,7 @@ crashlytics-build.properties
|
|||||||
#
|
#
|
||||||
/Docs
|
/Docs
|
||||||
/Issues
|
/Issues
|
||||||
|
/Local
|
||||||
/Obsolete
|
/Obsolete
|
||||||
/Snapshots
|
/Snapshots
|
||||||
/UI
|
/UI
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
|
|
||||||
[assembly: AssemblyCompany("Cryville")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © Cryville 2020-2022")]
|
|
||||||
[assembly: AssemblyDefaultAlias("Cosmo Resona")]
|
|
||||||
[assembly: AssemblyProduct("Cosmo Resona")]
|
|
||||||
[assembly: AssemblyTitle("Cosmo Resona")]
|
|
||||||
[assembly: AssemblyVersion("0.5.0")]
|
|
||||||
Binary file not shown.
120
Assets/Cryville/Common/Buffers/TargetString.cs
Normal file
120
Assets/Cryville/Common/Buffers/TargetString.cs
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Buffers {
|
||||||
|
/// <summary>
|
||||||
|
/// An auto-resized <see cref="char" /> array as a variable-length string used as a target that is modified frequently.
|
||||||
|
/// </summary>
|
||||||
|
public class TargetString : IEnumerable<char> {
|
||||||
|
public event Action OnUpdate;
|
||||||
|
char[] _arr;
|
||||||
|
bool _invalidated;
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an instance of the <see cref="TargetString" /> class with a capacity of 16.
|
||||||
|
/// </summary>
|
||||||
|
public TargetString() : this(16) { }
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an instance of the <see cref="TargetString" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="capacity">The initial capacity of the string.</param>
|
||||||
|
public TargetString(int capacity) {
|
||||||
|
_arr = new char[capacity];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets one of the characters in the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">The zero-based index of the character.</param>
|
||||||
|
/// <returns>The character at the given index.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> is less than 0 or not less than <see cref="Length" />.</exception>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>Set <see cref="Length" /> to a desired value before updating the characters.</para>
|
||||||
|
/// <para>Call <see cref=" Validate" /> after all the characters are updated.</para>
|
||||||
|
/// </remarks>
|
||||||
|
public char this[int index] {
|
||||||
|
get {
|
||||||
|
if (index < 0 || index >= m_length)
|
||||||
|
throw new ArgumentOutOfRangeException("index");
|
||||||
|
return _arr[index];
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (index < 0 || index >= m_length)
|
||||||
|
throw new ArgumentOutOfRangeException("index");
|
||||||
|
if (_arr[index] == value) return;
|
||||||
|
_arr[index] = value;
|
||||||
|
_invalidated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int m_length;
|
||||||
|
/// <summary>
|
||||||
|
/// The length of the string.
|
||||||
|
/// </summary>
|
||||||
|
public int Length {
|
||||||
|
get {
|
||||||
|
return m_length;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (m_length == value) return;
|
||||||
|
if (_arr.Length < value) {
|
||||||
|
var len = m_length;
|
||||||
|
while (len < value) len *= 2;
|
||||||
|
var arr2 = new char[len];
|
||||||
|
Array.Copy(_arr, arr2, m_length);
|
||||||
|
_arr = arr2;
|
||||||
|
}
|
||||||
|
m_length = value;
|
||||||
|
_invalidated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the string.
|
||||||
|
/// </summary>
|
||||||
|
public void Validate() {
|
||||||
|
if (!_invalidated) return;
|
||||||
|
_invalidated = false;
|
||||||
|
var ev = OnUpdate;
|
||||||
|
if (ev != null) ev.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() {
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
public IEnumerator<char> GetEnumerator() {
|
||||||
|
return new Enumerator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Enumerator : IEnumerator<char> {
|
||||||
|
readonly TargetString _self;
|
||||||
|
int _index = -1;
|
||||||
|
public Enumerator(TargetString self) { _self = self; }
|
||||||
|
|
||||||
|
public char Current {
|
||||||
|
get {
|
||||||
|
if (_index < 0)
|
||||||
|
throw new InvalidOperationException(_index == -1 ? "Enum not started" : "Enum ended");
|
||||||
|
return _self[_index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object IEnumerator.Current { get { return Current; } }
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
_index = -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveNext() {
|
||||||
|
if (_index == -2) return false;
|
||||||
|
_index++;
|
||||||
|
if (_index >= _self.Length) {
|
||||||
|
_index = -2;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
_index = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d6a3a023271b82a4985d1bbcc86e6fa8
|
guid: f0fc34ac257793d4883a9cfcdb6941b9
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -10,10 +10,10 @@ namespace Cryville.Common {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static IdentifierManager SharedInstance = new IdentifierManager();
|
public static IdentifierManager SharedInstance = new IdentifierManager();
|
||||||
|
|
||||||
Dictionary<object, int> _idents = new Dictionary<object, int>();
|
readonly Dictionary<object, int> _idents = new Dictionary<object, int>();
|
||||||
List<object> _ids = new List<object>();
|
readonly List<object> _ids = new List<object>();
|
||||||
|
|
||||||
object _syncRoot = new object();
|
readonly object _syncRoot = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="IdentifierManager" /> class.
|
/// Creates an instance of the <see cref="IdentifierManager" /> class.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Cryville.Common {
|
namespace Cryville.Common {
|
||||||
@@ -17,7 +18,7 @@ namespace Cryville.Common {
|
|||||||
public static void SetLogPath(string path) {
|
public static void SetLogPath(string path) {
|
||||||
logPath = path;
|
logPath = path;
|
||||||
var dir = new DirectoryInfo(path);
|
var dir = new DirectoryInfo(path);
|
||||||
if (!dir.Exists) Directory.CreateDirectory(dir.FullName);
|
if (!dir.Exists) dir.Create();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs to the specified logger.
|
/// Logs to the specified logger.
|
||||||
@@ -40,7 +41,7 @@ namespace Cryville.Common {
|
|||||||
public static void Create(string key, Logger logger) {
|
public static void Create(string key, Logger logger) {
|
||||||
Instances[key] = logger;
|
Instances[key] = logger;
|
||||||
if (logPath != null) {
|
if (logPath != null) {
|
||||||
Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString() + "-" + key + ".log") {
|
Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture) + "-" + key + ".log") {
|
||||||
AutoFlush = true
|
AutoFlush = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
78
Assets/Cryville/Common/Math/FractionUtils.cs
Normal file
78
Assets/Cryville/Common/Math/FractionUtils.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Math {
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a set of <see langword="static" /> methods related to fractions.
|
||||||
|
/// </summary>
|
||||||
|
public static class FractionUtils {
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a <see cref="double" /> decimal to a fraction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The decimal.</param>
|
||||||
|
/// <param name="error">The error.</param>
|
||||||
|
/// <param name="n">The numerator.</param>
|
||||||
|
/// <param name="d">The denominator.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is less than 0 or <paramref name="error" /> is not greater than 0 or not less than 1.</exception>
|
||||||
|
public static void ToFraction(double value, double error, out int n, out int d) {
|
||||||
|
if (value < 0.0)
|
||||||
|
throw new ArgumentOutOfRangeException("value", "Must be >= 0.");
|
||||||
|
if (error <= 0.0 || error >= 1.0)
|
||||||
|
throw new ArgumentOutOfRangeException("accuracy", "Must be > 0 and < 1.");
|
||||||
|
|
||||||
|
int num = (int)System.Math.Floor(value);
|
||||||
|
value -= num;
|
||||||
|
|
||||||
|
if (value < error) { n = num; d = 1; return; }
|
||||||
|
if (1 - error < value) { n = num + 1; d = 1; return; }
|
||||||
|
|
||||||
|
int lower_n = 0;
|
||||||
|
int lower_d = 1;
|
||||||
|
int upper_n = 1;
|
||||||
|
int upper_d = 1;
|
||||||
|
while (true) {
|
||||||
|
int middle_n = lower_n + upper_n;
|
||||||
|
int middle_d = lower_d + upper_d;
|
||||||
|
|
||||||
|
if (middle_d * (value + error) < middle_n) {
|
||||||
|
upper_n = middle_n;
|
||||||
|
upper_d = middle_d;
|
||||||
|
}
|
||||||
|
else if (middle_n < (value - error) * middle_d) {
|
||||||
|
lower_n = middle_n;
|
||||||
|
lower_d = middle_d;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
n = num * middle_d + middle_n;
|
||||||
|
d = middle_d;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the greatest common divisor (GCD) of two integers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="n">The first integer.</param>
|
||||||
|
/// <param name="d">The second integer.</param>
|
||||||
|
/// <returns>The greatest common divisor (GCD) of the two integers.</returns>
|
||||||
|
public static int GreatestCommonDivisor(int n, int d) {
|
||||||
|
while (d != 0) {
|
||||||
|
int t = d;
|
||||||
|
d = n % d;
|
||||||
|
n = t;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Simplifies a fraction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="n">The numerator.</param>
|
||||||
|
/// <param name="d">The denominator.</param>
|
||||||
|
public static void Simplify(ref int n, ref int d) {
|
||||||
|
var gcd = GreatestCommonDivisor(n, d);
|
||||||
|
n /= gcd;
|
||||||
|
d /= gcd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: a69a6c726b01961419c4835bba37a218
|
guid: 6829ada596979a545a935785eeea2972
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
namespace Cryville.Common.Math {
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Math {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a square matrix.
|
/// Represents a square matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SquareMatrix {
|
public class SquareMatrix {
|
||||||
readonly float[,] content;
|
readonly float[,] content;
|
||||||
|
readonly float[,] buffer;
|
||||||
|
readonly int[] refl;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The size of the matrix.
|
/// The size of the matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -17,6 +21,8 @@
|
|||||||
/// <param name="size">The size of the matrix.</param>
|
/// <param name="size">The size of the matrix.</param>
|
||||||
public SquareMatrix(int size) {
|
public SquareMatrix(int size) {
|
||||||
content = new float[size, size];
|
content = new float[size, size];
|
||||||
|
buffer = new float[size, size];
|
||||||
|
refl = new int[size];
|
||||||
Size = size;
|
Size = size;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -38,38 +44,36 @@
|
|||||||
/// <returns>The column vector eliminated.</returns>
|
/// <returns>The column vector eliminated.</returns>
|
||||||
public ColumnVector<T> Eliminate<T>(ColumnVector<T> v, IVectorOperator<T> o) {
|
public ColumnVector<T> Eliminate<T>(ColumnVector<T> v, IVectorOperator<T> o) {
|
||||||
int s = Size;
|
int s = Size;
|
||||||
float[,] d = (float[,])content.Clone();
|
Array.Copy(content, buffer, Size * Size);
|
||||||
int[] refl = new int[s];
|
for (int i = 0; i < s; i++) refl[i] = i;
|
||||||
for (int i = 0; i < s; i++)
|
|
||||||
refl[i] = i;
|
|
||||||
for (int r = 0; r < s; r++) {
|
for (int r = 0; r < s; r++) {
|
||||||
for (int r0 = r; r0 < s; r0++)
|
for (int r0 = r; r0 < s; r0++)
|
||||||
if (d[refl[r0], r] != 0) {
|
if (buffer[refl[r0], r] != 0) {
|
||||||
refl[r] = r0;
|
refl[r] = r0;
|
||||||
refl[r0] = r;
|
refl[r0] = r;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int or = refl[r];
|
int or = refl[r];
|
||||||
float sf0 = d[or, r];
|
float sf0 = buffer[or, r];
|
||||||
for (int c0 = r; c0 < s; c0++)
|
for (int c0 = r; c0 < s; c0++)
|
||||||
d[or, c0] /= sf0;
|
buffer[or, c0] /= sf0;
|
||||||
v[or] = o.ScalarMultiply(1 / sf0, v[or]);
|
v[or] = o.ScalarMultiply(1 / sf0, v[or]);
|
||||||
for (int r1 = r + 1; r1 < s; r1++) {
|
for (int r1 = r + 1; r1 < s; r1++) {
|
||||||
int or1 = refl[r1];
|
int or1 = refl[r1];
|
||||||
float sf1 = d[or1, r];
|
float sf1 = buffer[or1, r];
|
||||||
for (int c1 = r; c1 < s; c1++)
|
for (int c1 = r; c1 < s; c1++)
|
||||||
d[or1, c1] -= d[or, c1] * sf1;
|
buffer[or1, c1] -= buffer[or, c1] * sf1;
|
||||||
v[or1] = o.Add(v[or1], o.ScalarMultiply(-sf1, v[or]));
|
v[or1] = o.Add(v[or1], o.ScalarMultiply(-sf1, v[or]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
T[] res = new T[s];
|
ColumnVector<T> res = new ColumnVector<T>(s);
|
||||||
for (int r2 = s - 1; r2 >= 0; r2--) {
|
for (int r2 = s - 1; r2 >= 0; r2--) {
|
||||||
var v2 = v[refl[r2]];
|
var v2 = v[refl[r2]];
|
||||||
for (int c2 = r2 + 1; c2 < s; c2++)
|
for (int c2 = r2 + 1; c2 < s; c2++)
|
||||||
v2 = o.Add(v2, o.ScalarMultiply(-d[refl[r2], c2], res[refl[c2]]));
|
v2 = o.Add(v2, o.ScalarMultiply(-buffer[refl[r2], c2], res[refl[c2]]));
|
||||||
res[refl[r2]] = v2;
|
res[refl[r2]] = v2;
|
||||||
}
|
}
|
||||||
return new ColumnVector<T>(res);
|
return res;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a square matrix and fills it with polynomial coefficients.
|
/// Creates a square matrix and fills it with polynomial coefficients.
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Cryville.Common.Network {
|
|||||||
encoding = Encoding.UTF8;
|
encoding = Encoding.UTF8;
|
||||||
payload = encoding.GetBytes(body);
|
payload = encoding.GetBytes(body);
|
||||||
headers.Add("Content-Encoding", encoding.EncodingName);
|
headers.Add("Content-Encoding", encoding.EncodingName);
|
||||||
headers.Add("Content-Length", payload.Length.ToString());
|
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
|
||||||
}
|
}
|
||||||
string request_line = string.Format(
|
string request_line = string.Format(
|
||||||
"{0} {1} {2}\r\n", method, uri, Version
|
"{0} {1} {2}\r\n", method, uri, Version
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ namespace Cryville.Common.Network {
|
|||||||
set { throw new NotSupportedException(); }
|
set { throw new NotSupportedException(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Flush() {
|
public override void Flush() { }
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract byte[] ReadToEnd();
|
public abstract byte[] ReadToEnd();
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Cryville.Common.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class InternalTlsClient : DefaultTlsClient {
|
private class InternalTlsClient : DefaultTlsClient {
|
||||||
string _host;
|
readonly string _host;
|
||||||
|
|
||||||
public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) {
|
public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) {
|
||||||
_host = host;
|
_host = host;
|
||||||
@@ -92,9 +92,7 @@ namespace Cryville.Common.Network {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyServerCertificate(TlsServerCertificate serverCertificate) {
|
public void NotifyServerCertificate(TlsServerCertificate serverCertificate) { }
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace Cryville.Common.Pdt {
|
namespace Cryville.Common.Pdt {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -104,7 +105,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
else if (i is PdtInstruction.PushVariable) {
|
else if (i is PdtInstruction.PushVariable) {
|
||||||
i.Execute(this);
|
i.Execute(this);
|
||||||
var frame = _stack[_framecount - 1];
|
var frame = _stack[_framecount - 1];
|
||||||
if (frame.Type != PdtInternalType.Undefined) {
|
if (frame.Type != PdtInternalType.Undefined && frame.Type != PdtInternalType.Error) {
|
||||||
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
|
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
|
||||||
il.Remove(_rip.Previous);
|
il.Remove(_rip.Previous);
|
||||||
}
|
}
|
||||||
@@ -147,10 +148,10 @@ namespace Cryville.Common.Pdt {
|
|||||||
_goffset += value.Length;
|
_goffset += value.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal unsafe void PushVariable(int name) {
|
internal unsafe void PushVariable(int name, bool forced) {
|
||||||
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
||||||
byte[] value;
|
byte[] value;
|
||||||
GetVariable(name, out frame->Type, out 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);
|
||||||
@@ -161,16 +162,17 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// Gets a variable of the specified name.
|
/// Gets a variable of the specified name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the variable.</param>
|
/// <param name="name">The name of the variable.</param>
|
||||||
|
/// <param name="forced">Whether to produce an error stack instead of an identifier stack if the variable is not found.</param>
|
||||||
/// <param name="type">The type of the variable.</param>
|
/// <param name="type">The type of the variable.</param>
|
||||||
/// <param name="value">The value of the variable.</param>
|
/// <param name="value">The value of the variable.</param>
|
||||||
protected abstract void GetVariable(int name, out int type, out byte[] value);
|
protected abstract void GetVariable(int name, bool forced, out int type, out byte[] value);
|
||||||
internal void Operate(PdtOperatorSignature sig) {
|
internal void Operate(PdtOperatorSignature sig) {
|
||||||
PdtOperator op;
|
PdtOperator op;
|
||||||
try { op = GetOperator(sig); }
|
try { op = GetOperator(sig); }
|
||||||
catch (Exception) {
|
catch (Exception ex) {
|
||||||
for (int i = 0; i < sig.ParamCount; i++)
|
for (int i = 0; i < sig.ParamCount; i++)
|
||||||
DiscardStack();
|
DiscardStack();
|
||||||
throw;
|
throw new EvaluationFailureException(string.Format("Failed to get operator {0}", sig), ex);
|
||||||
}
|
}
|
||||||
Operate(op, sig.ParamCount);
|
Operate(op, sig.ParamCount);
|
||||||
}
|
}
|
||||||
@@ -222,4 +224,18 @@ namespace Cryville.Common.Pdt {
|
|||||||
_goffset -= _stack[--_framecount].Length;
|
_goffset -= _stack[--_framecount].Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The exception that is thrown when the evalution of a <see cref="PdtExpression" /> fails.
|
||||||
|
/// </summary>
|
||||||
|
public class EvaluationFailureException : Exception {
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EvaluationFailureException() : base("Evaluation failed") { }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EvaluationFailureException(string message) : base(message) { }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EvaluationFailureException(string message, Exception innerException) : base(message, innerException) { }
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected EvaluationFailureException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,14 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
public class PushVariable : PdtInstruction {
|
public class PushVariable : PdtInstruction {
|
||||||
public int Name { get; private set; }
|
public int Name { get; private set; }
|
||||||
public PushVariable(int name) { Name = name; }
|
public bool Forced { get; private set; }
|
||||||
public PushVariable(string name) : this(IdentifierManager.SharedInstance.Request(name)) { }
|
public PushVariable(int name, bool forced = false) { Name = name; Forced = forced; }
|
||||||
|
public PushVariable(string name, bool forced = false) : this(IdentifierManager.SharedInstance.Request(name)) { Forced = forced; }
|
||||||
internal override void Execute(PdtEvaluatorBase etor) {
|
internal override void Execute(PdtEvaluatorBase etor) {
|
||||||
etor.PushVariable(Name);
|
etor.PushVariable(Name, Forced);
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("pushv {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
return string.Format(Forced ? "pushv ?{0}" : "pushv {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Operate : PdtInstruction {
|
public class Operate : PdtInstruction {
|
||||||
@@ -239,7 +240,11 @@ namespace Cryville.Common.Pdt {
|
|||||||
if (defs.TryGetValue(buf.Value.Value, out 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 ins.AddLast(new PdtInstruction.PushVariable(buf.Value.Value));
|
else {
|
||||||
|
var name = buf.Value.Value;
|
||||||
|
if (name[0] == '?') ins.AddLast(new PdtInstruction.PushVariable(name.Substring(1), true));
|
||||||
|
else ins.AddLast(new PdtInstruction.PushVariable(name));
|
||||||
|
}
|
||||||
buf = null;
|
buf = null;
|
||||||
TryPushAdjMul(ins, ref flag);
|
TryPushAdjMul(ins, ref flag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
|
||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
||||||
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0000,
|
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0030,
|
||||||
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030,
|
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030,
|
||||||
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>The operand at the specified index.</returns>
|
/// <returns>The operand at the specified index.</returns>
|
||||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> is not less than <see cref="LoadedOperandCount" /> or less than 0.</exception>
|
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> is not less than <see cref="LoadedOperandCount" /> or less than 0.</exception>
|
||||||
protected PdtVariableMemory GetOperand(int index) {
|
protected PdtVariableMemory GetOperand(int index) {
|
||||||
if (index >= LoadedOperandCount || index < 0) throw new IndexOutOfRangeException();
|
if (index >= LoadedOperandCount || index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException("index");
|
||||||
int i = index + _loadindex;
|
int i = index + _loadindex;
|
||||||
return _operands[i];
|
return _operands[i];
|
||||||
}
|
}
|
||||||
@@ -33,11 +34,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
_operands = new PdtVariableMemory[pc];
|
_operands = new PdtVariableMemory[pc];
|
||||||
}
|
}
|
||||||
PdtEvaluatorBase _etor;
|
PdtEvaluatorBase _etor;
|
||||||
bool _failure = false;
|
|
||||||
bool _rfreq = true;
|
bool _rfreq = true;
|
||||||
internal void Begin(PdtEvaluatorBase etor) {
|
internal void Begin(PdtEvaluatorBase etor) {
|
||||||
_etor = etor;
|
_etor = etor;
|
||||||
_failure = false;
|
|
||||||
_loadindex = ParamCount;
|
_loadindex = ParamCount;
|
||||||
}
|
}
|
||||||
internal void LoadOperand(PdtVariableMemory mem) {
|
internal void LoadOperand(PdtVariableMemory mem) {
|
||||||
@@ -49,13 +48,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
_rfreq = false;
|
_rfreq = false;
|
||||||
try { Execute(); } catch (Exception ex) {
|
try { Execute(); } catch (Exception ex) {
|
||||||
if (_rfreq) _etor.DiscardStack();
|
if (_rfreq) _etor.DiscardStack();
|
||||||
throw new InvalidOperationException("Evaluation failed", ex);
|
throw new EvaluationFailureException("Evaluation failed", ex);
|
||||||
}
|
}
|
||||||
if (_failure) {
|
if (!_rfreq && !noset) throw new EvaluationFailureException("Return frame not set");
|
||||||
if (_rfreq) _etor.DiscardStack();
|
|
||||||
throw new InvalidOperationException("Evaluation failed");
|
|
||||||
}
|
|
||||||
if (!_rfreq && !noset) throw new InvalidOperationException("Return frame not set");
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the operator.
|
/// Executes the operator.
|
||||||
@@ -69,10 +64,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>The return frame.</returns>
|
/// <returns>The return frame.</returns>
|
||||||
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
|
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
|
||||||
protected PdtVariableMemory GetReturnFrame(int type, int len) {
|
protected PdtVariableMemory GetReturnFrame(int type, int len) {
|
||||||
if (_rfreq) {
|
if (_rfreq) throw new InvalidOperationException("Return frame requested twice");
|
||||||
_failure = true;
|
|
||||||
throw new InvalidOperationException("Return frame already requested");
|
|
||||||
}
|
|
||||||
_rfreq = true;
|
_rfreq = true;
|
||||||
return _etor.StackAlloc(type, _prmem, len);
|
return _etor.StackAlloc(type, _prmem, len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Span on the memory of a <see cref="PdtEvaluatorBase" />.
|
/// Span on the memory of a <see cref="PdtEvaluatorBase" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public unsafe struct PdtVariableMemory {
|
public unsafe struct PdtVariableMemory : IEquatable<PdtVariableMemory> {
|
||||||
readonly byte* _ptr;
|
readonly byte* _ptr;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The length of the span.
|
/// The length of the span.
|
||||||
@@ -46,6 +46,14 @@ namespace Cryville.Common.Pdt {
|
|||||||
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 />
|
||||||
|
public bool Equals(PdtVariableMemory obj) {
|
||||||
|
if (Type != obj.Type || Length != obj.Length) return false;
|
||||||
|
for (int i = 0; i < Length; i++) {
|
||||||
|
if (*(_ptr + i) != *(obj._ptr + i)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the memory of the span as a number.
|
/// Gets the memory of the span as a number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Plist {
|
|
||||||
public class PlistConvert {
|
|
||||||
public static T Deserialize<T>(string file) {
|
|
||||||
return (T)Deserialize(typeof(T), PlistCS.Plist.readPlist(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static object Deserialize(Type type, object obj, Binder binder = null) {
|
|
||||||
if (binder == null)
|
|
||||||
binder = BinderAttribute.CreateBinderOfType(type);
|
|
||||||
if (obj is IList) {
|
|
||||||
var lobj = (List<object>)obj;
|
|
||||||
foreach (var i in lobj) {
|
|
||||||
throw new NotImplementedException(); // TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (obj is IDictionary) {
|
|
||||||
var dobj = (Dictionary<string, object>)obj;
|
|
||||||
if (typeof(IDictionary).IsAssignableFrom(type)) {
|
|
||||||
var result = (IDictionary)ReflectionHelper.InvokeEmptyConstructor(type);
|
|
||||||
var it = type.GetGenericArguments()[1];
|
|
||||||
foreach (var i in dobj) {
|
|
||||||
var value = Deserialize(it, i.Value, binder);
|
|
||||||
result.Add(i.Key, value);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
|
||||||
foreach (var i in dobj) {
|
|
||||||
var imis = type.GetMember(i.Key);
|
|
||||||
if (imis.Length == 0) continue;
|
|
||||||
var imi = imis[0];
|
|
||||||
var it = ReflectionHelper.GetMemberType(imi);
|
|
||||||
var value = Deserialize(it, i.Value, binder);
|
|
||||||
ReflectionHelper.SetValue(imi, result, value, binder);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else return obj;
|
|
||||||
throw new Exception(); // TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -168,5 +168,19 @@ namespace Cryville.Common {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the namespace qualified name of a type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The type.</param>
|
||||||
|
/// <returns>The namespace qualified name of the class.</returns>
|
||||||
|
public static string GetNamespaceQualifiedName(Type type) {
|
||||||
|
string result = type.Namespace + "." + type.Name;
|
||||||
|
var typeargs = type.GetGenericArguments();
|
||||||
|
if (typeargs.Length > 0) {
|
||||||
|
result = string.Format("{0}[{1}]", result, string.Join(",", from a in typeargs select GetNamespaceQualifiedName(a)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,25 @@ namespace Cryville.Common {
|
|||||||
/// <param name="name">The file name excluding the extension.</param>
|
/// <param name="name">The file name excluding the extension.</param>
|
||||||
/// <returns>The escaped file name.</returns>
|
/// <returns>The escaped file name.</returns>
|
||||||
public static string EscapeFileName(string name) {
|
public static string EscapeFileName(string name) {
|
||||||
return Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}\.\s]", "_");
|
var result = Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}]", "_").TrimEnd(' ', '.');
|
||||||
|
if (result.Length == 0) return "_";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the process path from a command.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">The command.</param>
|
||||||
|
/// <returns>The process path.</returns>
|
||||||
|
public static string GetProcessPathFromCommand(string command) {
|
||||||
|
command = command.Trim();
|
||||||
|
if (command[0] == '"') {
|
||||||
|
return command.Substring(1, command.IndexOf('"', 1) - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int e = command.IndexOf(' ');
|
||||||
|
if (e == -1) return command;
|
||||||
|
else return command.Substring(0, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,6 @@ namespace Cryville.Common.Unity {
|
|||||||
return (num2 & num) == num;
|
return (num2 & num) == num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowException(Exception ex) {
|
|
||||||
ShowMessageBox(ex.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ShowMessageBox(string message) {
|
|
||||||
GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Popup")).GetComponent<Popup>().Message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Purge(Transform obj) {
|
public static void Purge(Transform obj) {
|
||||||
foreach (Transform i in obj)
|
foreach (Transform i in obj)
|
||||||
GameObject.Destroy(i.gameObject);
|
GameObject.Destroy(i.gameObject);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -11,13 +12,13 @@ namespace Cryville.Common.Unity {
|
|||||||
Transform dirs;
|
Transform dirs;
|
||||||
Transform files;
|
Transform files;
|
||||||
|
|
||||||
public Action Callback { private get; set; }
|
public event Action OnClose;
|
||||||
|
|
||||||
#if UNITY_ANDROID && !UNITY_EDITOR_WIN
|
#if UNITY_ANDROID && !UNITY_EDITOR_WIN
|
||||||
string androidStorage = "";
|
string androidStorage = "";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
string fileName = "";
|
string fileName = null;
|
||||||
public string FileName {
|
public string FileName {
|
||||||
get { return fileName; }
|
get { return fileName; }
|
||||||
}
|
}
|
||||||
@@ -27,8 +28,16 @@ namespace Cryville.Common.Unity {
|
|||||||
set { m_filter = value; }
|
set { m_filter = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
public Dictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||||
|
public Dictionary<string, string> PresetPaths {
|
||||||
|
get { return m_presetPaths; }
|
||||||
|
set { m_presetPaths = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObject prefabButton;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
|
prefabButton = Resources.Load<GameObject>("Common/Button");
|
||||||
panel = gameObject.transform.Find("Panel");
|
panel = gameObject.transform.Find("Panel");
|
||||||
title = panel.Find("Title/Text");
|
title = panel.Find("Title/Text");
|
||||||
drives = panel.Find("Drives/DrivesInner");
|
drives = panel.Find("Drives/DrivesInner");
|
||||||
@@ -38,8 +47,8 @@ namespace Cryville.Common.Unity {
|
|||||||
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
||||||
CurrentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
CurrentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
using (AndroidJavaClass ajc=new AndroidJavaClass("android.os.Environment"))
|
using (AndroidJavaClass ajc = new AndroidJavaClass("android.os.Environment"))
|
||||||
using (AndroidJavaObject file=ajc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory")) {
|
using (AndroidJavaObject file = ajc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory")) {
|
||||||
androidStorage = file.Call<string>("getAbsolutePath");
|
androidStorage = file.Call<string>("getAbsolutePath");
|
||||||
CurrentDirectory = new DirectoryInfo(androidStorage);
|
CurrentDirectory = new DirectoryInfo(androidStorage);
|
||||||
}
|
}
|
||||||
@@ -47,9 +56,8 @@ namespace Cryville.Common.Unity {
|
|||||||
#error No default directory
|
#error No default directory
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
UpdateGUI();
|
UpdateGUI(0);
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE0051
|
|
||||||
|
|
||||||
public void Show() {
|
public void Show() {
|
||||||
fileName = null;
|
fileName = null;
|
||||||
@@ -57,85 +65,82 @@ namespace Cryville.Common.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Close() {
|
public void Close() {
|
||||||
if (Callback != null) Callback.Invoke();
|
var ev = OnClose;
|
||||||
|
if (ev != null) ev.Invoke();
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectoryInfo CurrentDirectory;
|
public DirectoryInfo CurrentDirectory;
|
||||||
|
|
||||||
void OnDriveChanged(string s) {
|
void ChangeDirectory(DirectoryInfo s) {
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
CurrentDirectory = s;
|
||||||
CurrentDirectory = new DirectoryInfo(s);
|
UpdateGUI(1);
|
||||||
#elif UNITY_ANDROID
|
|
||||||
switch (s) {
|
|
||||||
case "?storage":
|
|
||||||
CurrentDirectory = new DirectoryInfo(androidStorage);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error No change drive logic
|
|
||||||
#endif
|
|
||||||
UpdateGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDirectoryChanged(string s) {
|
void SelectFile(string s) {
|
||||||
CurrentDirectory = new DirectoryInfo(CurrentDirectory.FullName + "/" + s);
|
|
||||||
UpdateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnFileChanged(string s) {
|
|
||||||
fileName = s;
|
fileName = s;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateGUI() {
|
void UpdateGUI(int depth) {
|
||||||
title.GetComponent<Text>().text = CurrentDirectory.FullName;
|
title.GetComponent<Text>().text = CurrentDirectory.FullName;
|
||||||
|
|
||||||
|
if (depth <= 0) {
|
||||||
CallHelper.Purge(drives);
|
CallHelper.Purge(drives);
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
var dl = Directory.GetLogicalDrives();
|
var dl = Directory.GetLogicalDrives();
|
||||||
foreach (string d in dl) {
|
foreach (string d in dl) {
|
||||||
GameObject btn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject btn = Instantiate(prefabButton);
|
||||||
btn.GetComponentInChildren<Text>().text = d;
|
btn.GetComponentInChildren<Text>().text = d;
|
||||||
var ts = d;
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(d)));
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDriveChanged(ts));
|
|
||||||
btn.transform.SetParent(drives, false);
|
btn.transform.SetParent(drives, false);
|
||||||
}
|
}
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
GameObject sbtn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject sbtn = GameObject.Instantiate<GameObject>(prefabButton);
|
||||||
sbtn.GetComponentInChildren<Text>().text = "Storage";
|
sbtn.GetComponentInChildren<Text>().text = "Storage";
|
||||||
sbtn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDriveChanged("?storage"));
|
sbtn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(androidStorage)));
|
||||||
sbtn.transform.SetParent(drives, false);
|
sbtn.transform.SetParent(drives, false);
|
||||||
#else
|
#else
|
||||||
#error No update GUI logic
|
#error No update GUI logic
|
||||||
#endif
|
#endif
|
||||||
|
foreach (var p in m_presetPaths) {
|
||||||
|
var d = new DirectoryInfo(p.Value);
|
||||||
|
if (d.Exists) {
|
||||||
|
GameObject btn = Instantiate(prefabButton);
|
||||||
|
btn.GetComponentInChildren<Text>().text = p.Key;
|
||||||
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(d));
|
||||||
|
btn.transform.SetParent(drives, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CallHelper.Purge(dirs);
|
CallHelper.Purge(dirs);
|
||||||
DirectoryInfo[] subdirs = CurrentDirectory.GetDirectories();
|
DirectoryInfo[] subdirs = CurrentDirectory.GetDirectories();
|
||||||
GameObject pbtn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject pbtn = Instantiate(prefabButton);
|
||||||
pbtn.GetComponentInChildren<Text>().text = "..";
|
pbtn.GetComponentInChildren<Text>().text = "..";
|
||||||
pbtn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDirectoryChanged(".."));
|
pbtn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(Path.Combine(CurrentDirectory.FullName, ".."))));
|
||||||
pbtn.transform.SetParent(dirs, false);
|
pbtn.transform.SetParent(dirs, false);
|
||||||
foreach (DirectoryInfo d in subdirs) {
|
foreach (DirectoryInfo d in subdirs) {
|
||||||
GameObject btn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject btn = Instantiate(prefabButton);
|
||||||
btn.GetComponentInChildren<Text>().text = d.Name;
|
btn.GetComponentInChildren<Text>().text = d.Name;
|
||||||
var ts = d.Name;
|
var ts = d;
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDirectoryChanged(ts));
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(ts));
|
||||||
btn.transform.SetParent(dirs, false);
|
btn.transform.SetParent(dirs, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallHelper.Purge(files);
|
CallHelper.Purge(files);
|
||||||
FileInfo[] fl = CurrentDirectory.GetFiles();
|
FileInfo[] fl = CurrentDirectory.GetFiles();
|
||||||
foreach (FileInfo d in fl) {
|
foreach (FileInfo d in fl) {
|
||||||
foreach (string ext in m_filter)
|
foreach (string ext in m_filter) {
|
||||||
if (d.Extension == ext) goto ext_matched;
|
if (d.Extension == ext) {
|
||||||
continue;
|
GameObject btn = Instantiate(prefabButton);
|
||||||
ext_matched:
|
|
||||||
GameObject btn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
|
||||||
btn.GetComponentInChildren<Text>().text = d.Name + " / " + (d.Length / 1024.0).ToString("0.0 KiB");
|
btn.GetComponentInChildren<Text>().text = d.Name + " / " + (d.Length / 1024.0).ToString("0.0 KiB");
|
||||||
var ts = d.FullName;
|
var ts = d.FullName;
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => OnFileChanged(ts));
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => SelectFile(ts));
|
||||||
btn.transform.SetParent(files, false);
|
btn.transform.SetParent(files, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
typeof(UnityMouseHandler),
|
typeof(UnityMouseHandler),
|
||||||
typeof(UnityTouchHandler),
|
typeof(UnityTouchHandler),
|
||||||
};
|
};
|
||||||
// TODO set private
|
readonly List<InputHandler> _handlers = new List<InputHandler>();
|
||||||
public readonly List<InputHandler> _handlers = new List<InputHandler>();
|
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
||||||
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
||||||
readonly object _lock = new object();
|
readonly object _lock = new object();
|
||||||
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
||||||
@@ -22,6 +22,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
try {
|
try {
|
||||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||||
|
_typemap.Add(t, h);
|
||||||
h.OnInput += OnInput;
|
h.OnInput += OnInput;
|
||||||
_handlers.Add(h);
|
_handlers.Add(h);
|
||||||
_timeOrigins.Add(h, 0);
|
_timeOrigins.Add(h, 0);
|
||||||
@@ -32,6 +33,9 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public InputHandler GetHandler(string name) {
|
||||||
|
return _typemap[Type.GetType(name)];
|
||||||
|
}
|
||||||
public void Activate() {
|
public void Activate() {
|
||||||
lock (_lock) {
|
lock (_lock) {
|
||||||
_events.Clear();
|
_events.Clear();
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
Callback = h;
|
Callback = h;
|
||||||
}
|
}
|
||||||
public abstract string GetKeyName(int type);
|
public abstract string GetKeyName(int type);
|
||||||
|
void Awake() {
|
||||||
|
useGUILayout = false;
|
||||||
|
}
|
||||||
void Update() {
|
void Update() {
|
||||||
double time = Time.realtimeSinceStartupAsDouble;
|
double time = Time.realtimeSinceStartupAsDouble;
|
||||||
foreach (var k in Keys) {
|
foreach (var k in Keys) {
|
||||||
|
|||||||
@@ -28,19 +28,19 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsNullable(int type) {
|
public override bool IsNullable(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte GetDimension(int type) {
|
public override byte GetDimension(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetTypeName(int type) {
|
public override string GetTypeName(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: return "Mouse Position";
|
case 0: return "Mouse Position";
|
||||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
default: throw new ArgumentOutOfRangeException("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,19 +28,19 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsNullable(int type) {
|
public override bool IsNullable(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte GetDimension(int type) {
|
public override byte GetDimension(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetTypeName(int type) {
|
public override string GetTypeName(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: return "Touch";
|
case 0: return "Touch";
|
||||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
default: throw new ArgumentOutOfRangeException("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Unity {
|
|
||||||
public class Popup : MonoBehaviour {
|
|
||||||
|
|
||||||
public string Message = "";
|
|
||||||
|
|
||||||
LayoutElement layout;
|
|
||||||
|
|
||||||
float timer = 0;
|
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
|
||||||
void Start() {
|
|
||||||
layout = GetComponent<LayoutElement>();
|
|
||||||
GetComponentInChildren<Text>().text = Message;
|
|
||||||
transform.SetParent(GameObject.Find("PopupList").transform);
|
|
||||||
layout.minHeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update() {
|
|
||||||
if (timer <= 0.8f) layout.minHeight = timer * 50;
|
|
||||||
else if (timer >= 5f) GameObject.Destroy(gameObject);
|
|
||||||
else if (timer >= 4.2f) layout.minHeight = (300 - timer) * 50;
|
|
||||||
timer += Time.deltaTime;
|
|
||||||
}
|
|
||||||
#pragma warning restore IDE0051
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -118,7 +118,7 @@ namespace Cryville.Common.Unity {
|
|||||||
fdialog = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
fdialog = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||||
fdialog.Filter = filter;
|
fdialog.Filter = filter;
|
||||||
fdialog.CurrentDirectory = ContextPath;
|
fdialog.CurrentDirectory = ContextPath;
|
||||||
fdialog.Callback = () => OnFileDialogClosed();
|
fdialog.OnClose += OnFileDialogClosed;
|
||||||
}
|
}
|
||||||
editor.SetDescription(PropertyName, desc);
|
editor.SetDescription(PropertyName, desc);
|
||||||
UpdateValue();
|
UpdateValue();
|
||||||
@@ -133,10 +133,10 @@ namespace Cryville.Common.Unity {
|
|||||||
prop.SetValue(Target, v, new object[]{ });
|
prop.SetValue(Target, v, new object[]{ });
|
||||||
}
|
}
|
||||||
catch (TargetInvocationException ex) {
|
catch (TargetInvocationException ex) {
|
||||||
CallHelper.ShowMessageBox(ex.InnerException.Message);
|
// CallHelper.ShowMessageBox(ex.InnerException.Message);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
CallHelper.ShowMessageBox(ex.Message);
|
// CallHelper.ShowMessageBox(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateValue();
|
UpdateValue();
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
void Update() {
|
void Update() {
|
||||||
Vector2 cprectsize = ((RectTransform)transform.parent).rect.size;
|
Vector2 cprectsize = ((RectTransform)transform.parent).rect.size;
|
||||||
if (cprectsize != pprectsize) {
|
if (cprectsize != pprectsize) {
|
||||||
OnFrameUpdate();
|
|
||||||
pprectsize = cprectsize;
|
pprectsize = cprectsize;
|
||||||
|
OnFrameUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
@@ -200,8 +200,7 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
|
|
||||||
void GenerateLine(int index, int line) {
|
void GenerateLine(int index, int line) {
|
||||||
for (int j = 0; j < LineItemCount; j++) {
|
for (int j = 0; j < LineItemCount; j++) {
|
||||||
var child = GameObject.Instantiate(m_itemTemplate);
|
var child = GameObject.Instantiate(m_itemTemplate, transform, false);
|
||||||
child.transform.SetParent(transform, false);
|
|
||||||
lines[index][j] = child;
|
lines[index][j] = child;
|
||||||
}
|
}
|
||||||
LoadLine(index, line);
|
LoadLine(index, line);
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
using UnityEngine;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Anchor {
|
public class Anchor {
|
||||||
bool _opened;
|
public int Name { get; private set; }
|
||||||
public bool Opened { get { return _opened; } }
|
public Transform Transform { get; private set; }
|
||||||
public Transform Transform { get; set; }
|
public SkinContext SkinContext { get; private set; }
|
||||||
public void Open() {
|
public Dictionary<int, PropSrc> PropSrcs { get; private set; }
|
||||||
_opened = true;
|
public Anchor(int name, Transform transform, bool hasProps = false) {
|
||||||
}
|
Name = name;
|
||||||
public void Close() {
|
Transform = transform;
|
||||||
_opened = false;
|
if (hasProps) PropSrcs = new Dictionary<int, PropSrc>();
|
||||||
|
SkinContext = new SkinContext(transform, PropSrcs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
22
Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs
Normal file
22
Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public class ChartResourceImporter : ResourceConverter {
|
||||||
|
static readonly string[] SUPPORTED_FORMATS = { ".umgc" };
|
||||||
|
public override string[] GetSupportedFormats() {
|
||||||
|
return SUPPORTED_FORMATS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||||
|
var meta = Path.Combine(file.Directory.FullName, "meta.json");
|
||||||
|
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
|
||||||
|
using (StreamReader reader = new StreamReader(meta, Encoding.UTF8)) {
|
||||||
|
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
return new Resource[] { new ChartResource(data.name, file) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 62489f8e495a805478e5b45c0f53ca4e
|
guid: 168366bb891392b42a1d0a6bfa068ff3
|
||||||
timeCreated: 1623583546
|
|
||||||
licenseType: Pro
|
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
||||||
@@ -47,11 +47,11 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
_cover.sprite = m_coverPlaceholder;
|
_cover.sprite = m_coverPlaceholder;
|
||||||
if (data.Cover != null) data.Cover.Destination = DisplayCover;
|
if (data.Cover != null) data.Cover.Destination = DisplayCover;
|
||||||
var meta = data.Meta;
|
var meta = data.Meta;
|
||||||
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.chart.name);
|
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.name);
|
||||||
_desc.text = string.Format(
|
_desc.text = string.Format(
|
||||||
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
|
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
|
||||||
meta.song.author, meta.chart.author,
|
meta.song.author, meta.author,
|
||||||
TimeSpan.FromSeconds(meta.chart.length).ToString(3), meta.note_count
|
TimeSpan.FromSeconds(meta.length).ToString(3), meta.note_count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||||
@@ -60,10 +60,10 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void OnPlay() {
|
public void OnPlay() {
|
||||||
Master.Open(_id);
|
Master.Open(_id, _data);
|
||||||
}
|
}
|
||||||
public void OnConfig() {
|
public void OnConfig() {
|
||||||
Master.OpenConfig(_id);
|
Master.OpenConfig(_id, _data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
9
Assets/Cryville/Crtr/Browsing/ExtensionInterface.cs
Normal file
9
Assets/Cryville/Crtr/Browsing/ExtensionInterface.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public abstract class ExtensionInterface {
|
||||||
|
public abstract IEnumerable<ResourceConverter> GetResourceConverters();
|
||||||
|
public abstract IEnumerable<LocalResourceFinder> GetResourceFinders();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 58e01e1e11af164408a19c1086709bd7
|
guid: 4ffe72fef6ebb9e4da3571b4117f0d6d
|
||||||
timeCreated: 1638411495
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Cryville.Crtr.Browsing {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
public interface IResourceManager<T> {
|
public interface IResourceManager<T> {
|
||||||
string[] CurrentDirectory { get; }
|
string[] CurrentDirectory { get; }
|
||||||
int ChangeDirectory(string[] dir);
|
int ChangeDirectory(string[] dir);
|
||||||
@@ -10,5 +12,6 @@
|
|||||||
|
|
||||||
bool ImportItemFrom(string path);
|
bool ImportItemFrom(string path);
|
||||||
string[] GetSupportedFormats();
|
string[] GetSupportedFormats();
|
||||||
|
Dictionary<string, string> GetPresetPaths();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
|
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
|
||||||
@@ -16,6 +17,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
static readonly Dictionary<string, List<ResourceConverter>> converters
|
static readonly Dictionary<string, List<ResourceConverter>> converters
|
||||||
= new Dictionary<string, List<ResourceConverter>>();
|
= new Dictionary<string, List<ResourceConverter>>();
|
||||||
|
static readonly Dictionary<string, string> localRes
|
||||||
|
= new Dictionary<string, string>();
|
||||||
|
|
||||||
public LegacyResourceManager(string rootPath) {
|
public LegacyResourceManager(string rootPath) {
|
||||||
_rootPath = rootPath;
|
_rootPath = rootPath;
|
||||||
@@ -24,15 +27,37 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
static LegacyResourceManager() {
|
static LegacyResourceManager() {
|
||||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) {
|
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) {
|
||||||
foreach (var type in asm.GetTypes()) {
|
foreach (var type in asm.GetTypes()) {
|
||||||
if (type.IsSubclassOf(typeof(ResourceConverter))) {
|
if (!type.IsSubclassOf(typeof(ExtensionInterface))) continue;
|
||||||
var converter = (ResourceConverter)Activator.CreateInstance(type);
|
var ext = (ExtensionInterface)Activator.CreateInstance(type);
|
||||||
foreach (var f in converter.GetSupportedFormats()) {
|
try {
|
||||||
|
var cs = ext.GetResourceConverters();
|
||||||
|
if (cs != null) {
|
||||||
|
foreach (var c in cs) {
|
||||||
|
var fs = c.GetSupportedFormats();
|
||||||
|
if (fs == null) continue;
|
||||||
|
foreach (var f in fs) {
|
||||||
|
if (f == null) continue;
|
||||||
if (!converters.ContainsKey(f))
|
if (!converters.ContainsKey(f))
|
||||||
converters.Add(f, new List<ResourceConverter> { converter });
|
converters.Add(f, new List<ResourceConverter> { c });
|
||||||
else converters[f].Add(converter);
|
else converters[f].Add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var fs2 = ext.GetResourceFinders();
|
||||||
|
if (fs2 != null) {
|
||||||
|
foreach (var f in fs2) {
|
||||||
|
var name = f.Name;
|
||||||
|
var path = f.GetRootPath();
|
||||||
|
if (name != null && path != null)
|
||||||
|
localRes.Add(name, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logger.Log("main", 1, "Resource", "Loaded extension {0}", ReflectionHelper.GetNamespaceQualifiedName(type));
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Logger.Log("main", 4, "Resource", "Failed to initialize extension {0}: {1}", ReflectionHelper.GetNamespaceQualifiedName(type), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,23 +83,26 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
public ResourceItemMeta GetItemMeta(int id) {
|
public ResourceItemMeta GetItemMeta(int id) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
|
var meta = new ChartMeta();
|
||||||
|
string name = item.Name;
|
||||||
|
string desc = "(Unknown)";
|
||||||
|
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||||
|
if (metaFile.Exists) {
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
name = meta.song.name;
|
||||||
|
desc = meta.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
AsyncDelivery<Texture2D> cover = null;
|
AsyncDelivery<Texture2D> cover = null;
|
||||||
var coverFile = item.GetFiles("cover.*");
|
if (meta.cover != null && meta.cover != "") {
|
||||||
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
if (coverFile.Length > 0) {
|
if (coverFile.Length > 0) {
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
cover.CancelSource = task.Cancel;
|
cover.CancelSource = task.Cancel;
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
}
|
}
|
||||||
string name = item.Name;
|
|
||||||
string desc = "(Unknown)";
|
|
||||||
var metaFile = new FileInfo(item.FullName + "/meta.json");
|
|
||||||
if (metaFile.Exists) {
|
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
|
||||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
|
||||||
name = meta.song.name;
|
|
||||||
desc = meta.chart.name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new ResourceItemMeta {
|
return new ResourceItemMeta {
|
||||||
IsDirectory = false,
|
IsDirectory = false,
|
||||||
@@ -86,20 +114,22 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
public ChartDetail GetItemDetail(int id) {
|
public ChartDetail GetItemDetail(int id) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
|
var meta = new ChartMeta();
|
||||||
|
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||||
|
if (metaFile.Exists) {
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
}
|
||||||
AsyncDelivery<Texture2D> cover = null;
|
AsyncDelivery<Texture2D> cover = null;
|
||||||
var coverFile = item.GetFiles("cover.*");
|
if (meta.cover != null && meta.cover != "") {
|
||||||
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
if (coverFile.Length > 0) {
|
if (coverFile.Length > 0) {
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
cover.CancelSource = task.Cancel;
|
cover.CancelSource = task.Cancel;
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
}
|
}
|
||||||
ChartMeta meta = new ChartMeta();
|
|
||||||
var metaFile = new FileInfo(item.FullName + "/meta.json");
|
|
||||||
if (metaFile.Exists) {
|
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
|
||||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new ChartDetail {
|
return new ChartDetail {
|
||||||
Cover = cover,
|
Cover = cover,
|
||||||
@@ -108,39 +138,74 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string GetItemPath(int id) {
|
public string GetItemPath(int id) {
|
||||||
return items[id].Name + "/.umgc";
|
var item = items[id];
|
||||||
|
var meta = new ChartMeta();
|
||||||
|
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
return string.Format("{0}/{1}.json", items[id].Name, meta.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ImportItemFrom(string path) {
|
public bool ImportItemFrom(string path) {
|
||||||
var file = new FileInfo(path);
|
var file = new FileInfo(path);
|
||||||
if (!converters.ContainsKey(file.Extension)) return false;
|
if (!converters.ContainsKey(file.Extension)) return false;
|
||||||
foreach (var converter in converters[file.Extension]) {
|
foreach (var converter in converters[file.Extension]) {
|
||||||
var resources = converter.ConvertFrom(file);
|
IEnumerable<Resource> resources = null;
|
||||||
|
try {
|
||||||
|
resources = converter.ConvertFrom(file);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
LogAndPopup(4, ex.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
foreach (var res in resources) {
|
foreach (var res in resources) {
|
||||||
if (res is ChartResource) {
|
if (!res.Valid) {
|
||||||
var tres = (ChartResource)res;
|
LogAndPopup(3, "Attempt to import invalid resource: {0}", res);
|
||||||
|
}
|
||||||
|
else if (res is RawChartResource) {
|
||||||
|
var tres = (RawChartResource)res;
|
||||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||||
if (!dir.Exists) dir.Create();
|
if (!dir.Exists) dir.Create();
|
||||||
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
using (var writer = new StreamWriter(dir.FullName + "/.json")) {
|
||||||
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings));
|
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings));
|
||||||
}
|
}
|
||||||
using (var writer = new StreamWriter(dir.FullName + "/meta.json")) {
|
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
||||||
|
tres.Meta.data = "";
|
||||||
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
||||||
}
|
}
|
||||||
|
if (tres.Meta.cover != null) {
|
||||||
|
var coverFile = new FileInfo(Path.Combine(file.Directory.FullName, tres.Meta.cover));
|
||||||
|
if (coverFile.Exists)
|
||||||
|
coverFile.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
||||||
}
|
}
|
||||||
else if (res is CoverResource) {
|
|
||||||
var tres = (CoverResource)res;
|
|
||||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
|
||||||
if (!dir.Exists) dir.Create();
|
|
||||||
var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/cover" + tres.Source.Extension);
|
|
||||||
if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
|
|
||||||
}
|
}
|
||||||
else if (res is SongResource) {
|
else if (res is FileResource) {
|
||||||
var tres = (SongResource)res;
|
var tres = (FileResource)res;
|
||||||
var dir = new DirectoryInfo(_rootPath + "/songs/" + res.Name);
|
DirectoryInfo dest;
|
||||||
if (!dir.Exists) dir.Create();
|
if (res is ChartResource)
|
||||||
var dest = new FileInfo(_rootPath + "/songs/" + res.Name + "/.ogg");
|
dest = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||||
if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
|
else if (res is RulesetResource)
|
||||||
|
dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name);
|
||||||
|
else if (res is SkinResource)
|
||||||
|
dest = new DirectoryInfo(_rootPath + "/skins/" + (res as SkinResource).RulesetName + "/" + res.Name);
|
||||||
|
else if (res is SongResource)
|
||||||
|
dest = new DirectoryInfo(_rootPath + "/songs/" + res.Name);
|
||||||
|
else {
|
||||||
|
LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!dest.Exists) {
|
||||||
|
dest.Create();
|
||||||
|
tres.Master.CopyTo(Path.Combine(dest.FullName, tres.Master.Extension));
|
||||||
|
foreach (var attachment in tres.Attachments) {
|
||||||
|
attachment.CopyTo(Path.Combine(dest.FullName, attachment.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else LogAndPopup(1, "Resource already exists: {0}", res);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogAndPopup(3, "Attempt to import unsupported resource: {0}", res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -148,8 +213,18 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogAndPopup(int level, string format, params object[] args) {
|
||||||
|
var msg = string.Format(format, args);
|
||||||
|
Logger.Log("main", level, "Resource", msg);
|
||||||
|
Popup.Create(msg);
|
||||||
|
}
|
||||||
|
|
||||||
public string[] GetSupportedFormats() {
|
public string[] GetSupportedFormats() {
|
||||||
return converters.Keys.ToArray();
|
return converters.Keys.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, string> GetPresetPaths() {
|
||||||
|
return localRes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs
Normal file
6
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public abstract class LocalResourceFinder {
|
||||||
|
public abstract string Name { get; }
|
||||||
|
public abstract string GetRootPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f5b3f3294f679f14f8ec1195b0def630
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -24,10 +24,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
const float SPEED = 8;
|
const float SPEED = 8;
|
||||||
float _ratio;
|
float _ratio;
|
||||||
#pragma warning disable IDE0051
|
#pragma warning disable IDE0051
|
||||||
void Start() {
|
|
||||||
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (_value && _ratio != 1) {
|
if (_value && _ratio != 1) {
|
||||||
_ratio += SPEED * Time.deltaTime;
|
_ratio += SPEED * Time.deltaTime;
|
||||||
@@ -40,6 +36,10 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
UpdateGraphics();
|
UpdateGraphics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnRectTransformDimensionsChange() {
|
||||||
|
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
||||||
|
}
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
|
|
||||||
void UpdateGraphics() {
|
void UpdateGraphics() {
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
|
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
|
||||||
m_ctn.triggers.Add(ev);
|
m_ctn.triggers.Add(ev);
|
||||||
|
|
||||||
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
|
||||||
if (MaxStep != 0) SetRatio(0.5f);
|
if (MaxStep != 0) SetRatio(0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +69,10 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
SetValueFromPos(pp);
|
SetValueFromPos(pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnRectTransformDimensionsChange() {
|
||||||
|
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
||||||
|
}
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
|
|
||||||
Vector2 pp;
|
Vector2 pp;
|
||||||
|
|||||||
28
Assets/Cryville/Crtr/Browsing/PVPString.cs
Normal file
28
Assets/Cryville/Crtr/Browsing/PVPString.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public class PVPString : PropertyValuePanel {
|
||||||
|
string m_value;
|
||||||
|
public override object Value {
|
||||||
|
get {
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
m_value = (string)value;
|
||||||
|
_inputField.text = m_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InputField _inputField;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
_inputField = GetComponent<InputField>();
|
||||||
|
_inputField.onValueChanged.AddListener(OnValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnValueChanged(string value) {
|
||||||
|
m_value = value;
|
||||||
|
Callback(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Browsing/PVPString.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/PVPString.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aadf11739189bc94e9cb4f702eb7ccd3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -32,8 +32,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
|
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
|
||||||
Name = name.ToUpper();
|
Name = name.ToUpper();
|
||||||
foreach (var prop in props) {
|
foreach (var prop in props) {
|
||||||
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab);
|
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab, transform, false);
|
||||||
obj.transform.SetParent(transform, false);
|
|
||||||
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject m_bool;
|
GameObject m_bool;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_number;
|
GameObject m_number;
|
||||||
|
[SerializeField]
|
||||||
|
GameObject m_string;
|
||||||
|
|
||||||
PropertyInfo _property;
|
PropertyInfo _property;
|
||||||
object _target;
|
object _target;
|
||||||
@@ -32,8 +34,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject vp;
|
GameObject vp;
|
||||||
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
||||||
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
||||||
|
else if (prop.PropertyType == typeof(string)) vp = m_string;
|
||||||
else return;
|
else return;
|
||||||
_value = GameObject.Instantiate(vp, _valueContainer).GetComponent<PropertyValuePanel>();
|
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
||||||
if (_value is PVPNumber) {
|
if (_value is PVPNumber) {
|
||||||
var t = (PVPNumber)_value;
|
var t = (PVPNumber)_value;
|
||||||
t.IntegerMode = prop.PropertyType == typeof(int);
|
t.IntegerMode = prop.PropertyType == typeof(int);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common.Unity;
|
using Cryville.Common.Unity;
|
||||||
using Cryville.Common.Unity.UI;
|
using Cryville.Common.Unity.UI;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -19,6 +20,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||||
_dialog.gameObject.SetActive(false);
|
_dialog.gameObject.SetActive(false);
|
||||||
|
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
||||||
|
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
|
||||||
|
_dialog.OnClose += OnAddDialogClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool LoadPathPart(int id, GameObject obj) {
|
private bool LoadPathPart(int id, GameObject obj) {
|
||||||
@@ -29,8 +33,13 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
private bool LoadItem(int id, GameObject obj) {
|
private bool LoadItem(int id, GameObject obj) {
|
||||||
var bi = obj.GetComponent<BrowserItem>();
|
var bi = obj.GetComponent<BrowserItem>();
|
||||||
|
try {
|
||||||
var item = ResourceManager.GetItemMeta(id);
|
var item = ResourceManager.GetItemMeta(id);
|
||||||
bi.Load(id, item);
|
bi.Load(id, item);
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
bi.Load(id, new ResourceItemMeta { Name = "<color=#ff0000>Invalid resource</color>" });
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,19 +60,17 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnAddButtonClicked() {
|
public void OnAddButtonClicked() {
|
||||||
_dialog.Callback = OnAddDialogClosed;
|
|
||||||
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
|
||||||
_dialog.Show();
|
_dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAddDialogClosed() {
|
private void OnAddDialogClosed() {
|
||||||
if (_dialog.FileName == null) return;
|
if (_dialog.FileName == null) return;
|
||||||
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
|
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
|
||||||
Debug.Log("Import succeeded"); // TODO
|
Popup.Create("Import succeeded");
|
||||||
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Debug.Log("Import failed"); // TODO
|
Popup.Create("Import failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Unity.UI;
|
using Cryville.Common.Unity.UI;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
@@ -64,18 +65,21 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
_units[_slideDest + 1].SlideToRight();
|
_units[_slideDest + 1].SlideToRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open(int id) {
|
public void Open(int id, ChartDetail detail) {
|
||||||
SetDataSettings(id);
|
SetDataSettings(id, detail);
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
||||||
#else
|
#else
|
||||||
Application.LoadLevelAdditive("Play");
|
Application.LoadLevelAdditive("Play");
|
||||||
#endif
|
#endif
|
||||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenConfig(int id) {
|
public void OpenConfig(int id, ChartDetail detail) {
|
||||||
SetDataSettings(id);
|
SetDataSettings(id, detail);
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
SceneManager.LoadScene("Config", LoadSceneMode.Additive);
|
SceneManager.LoadScene("Config", LoadSceneMode.Additive);
|
||||||
#else
|
#else
|
||||||
@@ -84,9 +88,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDataSettings(int id) {
|
void SetDataSettings(int id, ChartDetail detail) {
|
||||||
Settings.Default.LoadRuleset = "key/.umgr";
|
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
||||||
Settings.Default.LoadSkin = "key/0/.umgs";
|
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
||||||
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
|
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,16 +101,22 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
public struct ChartMeta {
|
public class MetaInfo {
|
||||||
public MetaInfo song { get; set; }
|
|
||||||
public MetaInfo chart { get; set; }
|
|
||||||
public struct MetaInfo {
|
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public string author { get; set; }
|
public string author { get; set; }
|
||||||
public float length { get; set; }
|
[JsonRequired]
|
||||||
|
public string data { get; set; }
|
||||||
}
|
}
|
||||||
|
public class SongMetaInfo {
|
||||||
|
public string name { get; set; }
|
||||||
|
public string author { get; set; }
|
||||||
|
}
|
||||||
|
public class ChartMeta : MetaInfo {
|
||||||
|
public SongMetaInfo song { get; set; }
|
||||||
|
public float length { get; set; }
|
||||||
public string ruleset { get; set; }
|
public string ruleset { get; set; }
|
||||||
public int note_count { get; set; }
|
public int note_count { get; set; }
|
||||||
|
public string cover { get; set; }
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
@@ -12,24 +13,67 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
Name = StringUtils.EscapeFileName(name);
|
Name = StringUtils.EscapeFileName(name);
|
||||||
}
|
}
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
public abstract bool Valid { get; }
|
||||||
|
public override string ToString() {
|
||||||
|
return string.Format("{0} ({1})", Name, ReflectionHelper.GetSimpleName(GetType()));
|
||||||
}
|
}
|
||||||
public class ChartResource : Resource {
|
}
|
||||||
public ChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
public class RawChartResource : Resource {
|
||||||
|
public RawChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
||||||
Main = main; Meta = meta;
|
Main = main; Meta = meta;
|
||||||
}
|
}
|
||||||
public Chart Main { get; private set; }
|
public Chart Main { get; private set; }
|
||||||
public ChartMeta Meta { get; private set; }
|
public ChartMeta Meta { get; private set; }
|
||||||
|
public override bool Valid { get { return true; } }
|
||||||
}
|
}
|
||||||
public class CoverResource : Resource {
|
public abstract class FileResource : Resource {
|
||||||
public CoverResource(string name, FileInfo src) : base(name) {
|
public FileResource(string name, FileInfo master) : base(name) {
|
||||||
Source = src;
|
Master = master;
|
||||||
|
Attachments = new List<FileInfo>();
|
||||||
|
}
|
||||||
|
public FileInfo Master { get; private set; }
|
||||||
|
public List<FileInfo> Attachments { get; private set; }
|
||||||
|
public override bool Valid {
|
||||||
|
get {
|
||||||
|
if (!Master.Exists) return false;
|
||||||
|
foreach (var file in Attachments) {
|
||||||
|
if (!file.Exists) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class ChartResource : FileResource {
|
||||||
|
public ChartResource(string name, FileInfo master) : base(name, master) {
|
||||||
|
using (var reader = new StreamReader(master.FullName)) {
|
||||||
|
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class SongResource : FileResource {
|
||||||
|
public SongResource(string name, FileInfo master) : base(name, master) { }
|
||||||
|
}
|
||||||
|
public class RulesetResource : FileResource {
|
||||||
|
public RulesetResource(string name, FileInfo master) : base(name, master) {
|
||||||
|
using (var reader = new StreamReader(master.FullName)) {
|
||||||
|
var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||||
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class SkinResource : FileResource {
|
||||||
|
public string RulesetName { get; private set; }
|
||||||
|
public SkinResource(string name, FileInfo master) : base(name, master) {
|
||||||
|
using (var reader = new StreamReader(master.FullName)) {
|
||||||
|
var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
|
||||||
|
RulesetName = meta.ruleset;
|
||||||
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||||
|
foreach (var frame in meta.frames) {
|
||||||
|
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||||
}
|
}
|
||||||
public FileInfo Source { get; private set; }
|
|
||||||
}
|
}
|
||||||
public class SongResource : Resource {
|
|
||||||
public SongResource(string name, FileInfo src) : base(name) {
|
|
||||||
Source = src;
|
|
||||||
}
|
}
|
||||||
public FileInfo Source { get; private set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
20
Assets/Cryville/Crtr/Browsing/RulesetResourceImporter.cs
Normal file
20
Assets/Cryville/Crtr/Browsing/RulesetResourceImporter.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public class RulesetResourceImporter : ResourceConverter {
|
||||||
|
static readonly string[] SUPPORTED_FORMATS = { ".umgr" };
|
||||||
|
public override string[] GetSupportedFormats() {
|
||||||
|
return SUPPORTED_FORMATS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||||
|
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||||
|
var data = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||||
|
return new Resource[] { new RulesetResource(data.name, file) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user