Compare commits
204 Commits
Author | SHA1 | Date | |
---|---|---|---|
d510fec57b | |||
c5214dd477 | |||
a2391aeb22 | |||
2207c80951 | |||
bf578d7cb9 | |||
0bc57c368f | |||
b64f85aaa2 | |||
93fa2f2d7e | |||
d72216de8b | |||
df5133a91a | |||
88b959a118 | |||
310bf91fbd | |||
699f47f98d | |||
24e881b138 | |||
2eef1b5c4e | |||
c18ceb50d4 | |||
27ca1a7292 | |||
dc59176eac | |||
aec7470ff8 | |||
983cba6843 | |||
871782e73f | |||
9aaa96fe10 | |||
22190a29c1 | |||
613ca467d0 | |||
536a3066b2 | |||
43488cd002 | |||
a11ccbd39c | |||
76df4929a7 | |||
505b826627 | |||
26a8675922 | |||
b89e1f983e | |||
717e77b47e | |||
2f10c79dee | |||
55f7790f89 | |||
ae5f4a8c16 | |||
1851bd3c54 | |||
6d74685cb7 | |||
03fd7f6d01 | |||
28c878f3e5 | |||
7736eba14d | |||
2e54b38d2b | |||
da60dc0903 | |||
215f72b3b5 | |||
a93c081dd8 | |||
456782930a | |||
ba3cbbd64c | |||
dfc3e9ca06 | |||
f567a2b78e | |||
c7e7bd8a77 | |||
67720fd0e1 | |||
1a30149942 | |||
a755cc13bd | |||
9a51cf1b56 | |||
256c656e9c | |||
2ac7f05316 | |||
28d46dbabe | |||
18b3e0bc84 | |||
23f2e7c1f2 | |||
998713b41f | |||
3561354231 | |||
0cccb170c1 | |||
d2480b8a6f | |||
6837d3f7ee | |||
3ecf3b4bfc | |||
1da8647ff1 | |||
2f19e8daad | |||
07f62c7aeb | |||
39db8dfa45 | |||
f04cd370f1 | |||
5c4acd54ce | |||
82dbc5c479 | |||
1f1663d714 | |||
a3c5392caa | |||
6c983cc2cb | |||
3bf3fdac3d | |||
f2f3dba098 | |||
3728360dd2 | |||
887837bb3d | |||
99b4c2dfc1 | |||
e59769158a | |||
ba3238614b | |||
a115999aab | |||
393947db9f | |||
e9b2a7f894 | |||
9c73455761 | |||
59c2210359 | |||
4fab20953a | |||
ee7b0f5081 | |||
33ee7a9a87 | |||
900bd7b77a | |||
6bd32c9aef | |||
13893b2853 | |||
23789c15eb | |||
a1f7418d32 | |||
274a823d02 | |||
ba6239068a | |||
ff8c925f32 | |||
2a6a33e60c | |||
8910b1f4a0 | |||
36dddea4d9 | |||
6a648c2dcd | |||
2d4087dc89 | |||
f91aacd78e | |||
9c08cbf0d2 | |||
88d35e4eaf | |||
675ce68073 | |||
db0165d145 | |||
7015426300 | |||
0d4cc5e208 | |||
e7ce0985fb | |||
eb6dafbd60 | |||
b6e238780e | |||
c7ea6f1d4b | |||
4a5b2a6889 | |||
b84d645aee | |||
67b44db1ae | |||
ee4399109a | |||
87ef534f59 | |||
87362b47c5 | |||
f60ba1088d | |||
abb7ad6f24 | |||
880b475c07 | |||
4707c40e6a | |||
7f87c23da2 | |||
6df10837fe | |||
42cb54de1d | |||
9fd685b8b3 | |||
b364005741 | |||
7d938de409 | |||
bb4ecfcd8c | |||
ff410529b0 | |||
fdc55a8e3b | |||
fc8512ff63 | |||
1b1ed42a1b | |||
b437925f92 | |||
c04e50e959 | |||
314cdb9935 | |||
77c91d015a | |||
291a018c13 | |||
18ff4b8e16 | |||
7714c277fd | |||
d6c2ac6be6 | |||
682fe38d40 | |||
3e525842cb | |||
3dd25b51a8 | |||
041c1e374e | |||
16b1d323dc | |||
c4d5e5f480 | |||
187f07d2c9 | |||
4e9d7e5b87 | |||
7df5b15e2e | |||
4863aa0ae7 | |||
eb53c3465b | |||
f683d61298 | |||
fbd03c8037 | |||
da68c8b877 | |||
c0744a3464 | |||
3ca3746cec | |||
5e76ddf2cd | |||
dca1ba304e | |||
8dd32afb74 | |||
313824b4bb | |||
b166c0f5ef | |||
300e44bd4b | |||
ab6f983392 | |||
596c6395e4 | |||
404a36f9b8 | |||
1711fbadf7 | |||
84b7a6d183 | |||
6d0fd0f9ec | |||
b407ba88c4 | |||
bd256ba1a6 | |||
623c53f79a | |||
969fdc8069 | |||
cbc874dd72 | |||
450bd52095 | |||
5727fcf177 | |||
8ab0c2698b | |||
6c7b52d93c | |||
91f55cd9a3 | |||
a1ce459a0e | |||
9700992c3a | |||
f9a1ea72fe | |||
507b656eab | |||
c16776aee9 | |||
e109e0bd24 | |||
776a615464 | |||
5514b6cf37 | |||
8932d1b8d0 | |||
10988847b3 | |||
c4b139c7a4 | |||
130896df1f | |||
5d5c519a1d | |||
3d1a11f78b | |||
cc985844cd | |||
feffbaa5a6 | |||
d0f0c8ce6d | |||
3fdc236b1d | |||
46870e163a | |||
601f64cc61 | |||
c015b60dc3 | |||
5e01b654bd | |||
2304257201 | |||
02794d88b9 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -68,3 +68,4 @@ crashlytics-build.properties
|
||||
/UserSettings
|
||||
/*.zip
|
||||
*.lnk
|
||||
/HybridCLRData
|
||||
|
Binary file not shown.
BIN
Assets/Animations/IConfig.anim
Normal file
BIN
Assets/Animations/IConfig.anim
Normal file
Binary file not shown.
8
Assets/Animations/IConfig.anim.meta
Normal file
8
Assets/Animations/IConfig.anim.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e0c61e29fd90f04b9e41265d93e2029
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 7400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
BIN
Assets/Animations/TConfig_Main.anim
Normal file
BIN
Assets/Animations/TConfig_Main.anim
Normal file
Binary file not shown.
8
Assets/Animations/TConfig_Main.anim.meta
Normal file
8
Assets/Animations/TConfig_Main.anim.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d815e4d844e6a1c4d849e96e199f8881
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 7400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Animations/TMain_Config.anim
Normal file
BIN
Assets/Animations/TMain_Config.anim
Normal file
Binary file not shown.
8
Assets/Animations/TMain_Config.anim.meta
Normal file
8
Assets/Animations/TMain_Config.anim.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82867c59112ff5a419fbea2ebff2d3b9
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 7400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -33,12 +33,12 @@ namespace Cryville.Common {
|
||||
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
||||
if (value == null)
|
||||
return null;
|
||||
else if (type == value.GetType())
|
||||
else if (type.IsAssignableFrom(value.GetType()))
|
||||
return value;
|
||||
else if (type.IsEnum && value is string) {
|
||||
return Enum.Parse(type, (string)value);
|
||||
}
|
||||
throw new InvalidCastException();
|
||||
throw new InvalidCastException(string.Format("Cannot cast {0} to {1}", value.GetType(), type));
|
||||
}
|
||||
|
||||
public override void ReorderArgumentArray(ref object[] args, object state) {
|
||||
|
90
Assets/Cryville/Common/Buffers/CategorizedPool.cs
Normal file
90
Assets/Cryville/Common/Buffers/CategorizedPool.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A set of resource pools categorized by a category type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCategory">The category type.</typeparam>
|
||||
/// <typeparam name="TObject">The type of the objects in the pool.</typeparam>
|
||||
public abstract class CategorizedPool<TCategory, TObject> where TObject : class {
|
||||
/// <summary>
|
||||
/// The set of underlying pools.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The <see cref="Rent(TCategory)" /> and <see cref="Return(TCategory, TObject)" /> method select an underlying pool directly from this set with the category as the key. When overridden, this set must be available since construction.</para>
|
||||
/// </remarks>
|
||||
protected abstract IReadOnlyDictionary<TCategory, ObjectPool<TObject>> Buckets { get; }
|
||||
/// <summary>
|
||||
/// The count of objects rented from the set of pools.
|
||||
/// </summary>
|
||||
public int RentedCount { get; private set; }
|
||||
/// <summary>
|
||||
/// Rents an object from the pool.
|
||||
/// </summary>
|
||||
/// <param name="category">The category.</param>
|
||||
/// <returns>The rented object.</returns>
|
||||
public TObject Rent(TCategory category) {
|
||||
var obj = Buckets[category].Rent();
|
||||
RentedCount++;
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented object to the pool.
|
||||
/// </summary>
|
||||
/// <param name="category">The category.</param>
|
||||
/// <param name="obj">The object to return.</param>
|
||||
public void Return(TCategory category, TObject obj) {
|
||||
Buckets[category].Return(obj);
|
||||
--RentedCount;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A utility to access a categorized pool, representing a single unit that uses a shared categorized pool.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCategory">The category type.</typeparam>
|
||||
/// <typeparam name="TObject">The type of the objects in the pool.</typeparam>
|
||||
public class CategorizedPoolAccessor<TCategory, TObject> where TObject : class {
|
||||
readonly CategorizedPool<TCategory, TObject> _pool;
|
||||
static readonly SimpleObjectPool<Dictionary<TObject, TCategory>> _dictPool
|
||||
= new SimpleObjectPool<Dictionary<TObject, TCategory>>(1024);
|
||||
Dictionary<TObject, TCategory> _rented;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="CategorizedPoolAccessor{TCategory, TObject}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="pool">The categorized pool.</param>
|
||||
public CategorizedPoolAccessor(CategorizedPool<TCategory, TObject> pool) {
|
||||
_pool = pool;
|
||||
}
|
||||
/// <summary>
|
||||
/// Rents an object from the pool.
|
||||
/// </summary>
|
||||
/// <param name="category">The category.</param>
|
||||
/// <returns>The rented object.</returns>
|
||||
public TObject Rent(TCategory category) {
|
||||
var obj = _pool.Rent(category);
|
||||
if (_rented == null) _rented = _dictPool.Rent();
|
||||
_rented.Add(obj, category);
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented object to the pool.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to return.</param>
|
||||
public void Return(TObject obj) {
|
||||
_pool.Return(_rented[obj], obj);
|
||||
_rented.Remove(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns all objects rented by this accessor to the pool.
|
||||
/// </summary>
|
||||
public void ReturnAll() {
|
||||
if (_rented == null) return;
|
||||
foreach (var obj in _rented) {
|
||||
_pool.Return(obj.Value, obj.Key);
|
||||
}
|
||||
_rented.Clear();
|
||||
_dictPool.Return(_rented);
|
||||
_rented = null;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Buffers/CategorizedPool.cs.meta
Normal file
11
Assets/Cryville/Common/Buffers/CategorizedPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec18f22479042d747b88c093aa90c5c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -14,6 +14,10 @@
|
||||
_objs = new T[capacity];
|
||||
}
|
||||
/// <summary>
|
||||
/// The count of objects rented from the pool.
|
||||
/// </summary>
|
||||
public int RentedCount { get { return _index; } }
|
||||
/// <summary>
|
||||
/// Rents a object from the pool.
|
||||
/// </summary>
|
||||
/// <returns>The rented object.</returns>
|
||||
@@ -24,6 +28,7 @@
|
||||
_objs[_index++] = null;
|
||||
}
|
||||
if (obj == null) obj = Construct();
|
||||
else Reset(obj);
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -38,5 +43,10 @@
|
||||
/// </summary>
|
||||
/// <returns>The new instance.</returns>
|
||||
protected abstract T Construct();
|
||||
/// <summary>
|
||||
/// Resets an object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object.</param>
|
||||
protected virtual void Reset(T obj) { }
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,9 @@ namespace Cryville.Common.Buffers {
|
||||
/// Creates an instance of the <see cref="TargetString" /> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The initial capacity of the string.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity" /> is less than or equal to 0.</exception>
|
||||
public TargetString(int capacity) {
|
||||
if (capacity <= 0) throw new ArgumentOutOfRangeException("capacity");
|
||||
_arr = new char[capacity];
|
||||
}
|
||||
/// <summary>
|
||||
@@ -49,14 +51,16 @@ namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// The length of the string.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentOutOfRangeException">The value specified for a set operation is less than 0.</exception>
|
||||
public int Length {
|
||||
get {
|
||||
return m_length;
|
||||
}
|
||||
set {
|
||||
if (Length < 0) throw new ArgumentOutOfRangeException("length");
|
||||
if (m_length == value) return;
|
||||
if (_arr.Length < value) {
|
||||
var len = m_length;
|
||||
var len = _arr.Length;
|
||||
while (len < value) len *= 2;
|
||||
var arr2 = new char[len];
|
||||
Array.Copy(_arr, arr2, m_length);
|
||||
@@ -75,18 +79,29 @@ namespace Cryville.Common.Buffers {
|
||||
var ev = OnUpdate;
|
||||
if (ev != null) ev.Invoke();
|
||||
}
|
||||
internal char[] TrustedAsArray() { return _arr; }
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
return GetEnumerator();
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the <see cref="TargetString" />.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Enumerator" /> for the <see cref="TargetString" />.</returns>
|
||||
public Enumerator GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
public IEnumerator<char> GetEnumerator() {
|
||||
IEnumerator<char> IEnumerable<char>.GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
class Enumerator : IEnumerator<char> {
|
||||
public struct Enumerator : IEnumerator<char> {
|
||||
readonly TargetString _self;
|
||||
int _index = -1;
|
||||
public Enumerator(TargetString self) { _self = self; }
|
||||
int _index;
|
||||
internal Enumerator(TargetString self) {
|
||||
_self = self;
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
public char Current {
|
||||
get {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 215ebdd4cb9187741a2e24f5e7d8511d
|
||||
guid: c4ef48e4a4983de4e9c31483df2a918e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
8
Assets/Cryville/Common/Collections/Generic.meta
Normal file
8
Assets/Cryville/Common/Collections/Generic.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ec674235c0dd6744af2dab2b58dd53c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Cryville/Common/Collections/Generic/IPairList.cs
Normal file
8
Assets/Cryville/Common/Collections/Generic/IPairList.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Collections.Generic {
|
||||
public interface IPairList<TKey, TValue> : IList<KeyValuePair<TKey, TValue>> {
|
||||
void Add(TKey key, TValue value);
|
||||
void Insert(int index, TKey key, TValue value);
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Collections/Generic/IPairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/Generic/IPairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73fb17b484b343242bcce27c15ed7d44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
46
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
46
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Cryville.Common.Collections.Generic {
|
||||
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairCollectionDebugView<,>))]
|
||||
public struct PairCollection<TKey, TValue> : IDisposable {
|
||||
public void Dispose() { }
|
||||
readonly IPairList<TKey, TValue> _pairList;
|
||||
readonly IDictionary<TKey, TValue> _dictionary;
|
||||
public PairCollection(object collection) : this() {
|
||||
var type = collection.GetType();
|
||||
if (typeof(IPairList<TKey, TValue>).IsAssignableFrom(type)) _pairList = (IPairList<TKey, TValue>)collection;
|
||||
else if (typeof(IDictionary<TKey, TValue>).IsAssignableFrom(type)) _dictionary = (IDictionary<TKey, TValue>)collection;
|
||||
else throw new ArgumentException("Parameter is not a pair collection");
|
||||
}
|
||||
public int Count {
|
||||
get {
|
||||
if (_pairList != null) return _pairList.Count;
|
||||
else return _dictionary.Count;
|
||||
}
|
||||
}
|
||||
public void Add(TKey key, TValue value) {
|
||||
if (_pairList != null) _pairList.Add(key, value);
|
||||
else _dictionary.Add(key, value);
|
||||
}
|
||||
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int index) {
|
||||
if (_pairList != null) _pairList.CopyTo(array, index);
|
||||
else _dictionary.CopyTo(array, index);
|
||||
}
|
||||
}
|
||||
internal class PairCollectionDebugView<TKey, TValue> {
|
||||
readonly PairCollection<TKey, TValue> _self;
|
||||
public PairCollectionDebugView(PairCollection<TKey, TValue> self) {
|
||||
_self = self;
|
||||
}
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
|
||||
public KeyValuePair<TKey, TValue>[] Items {
|
||||
get {
|
||||
KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[_self.Count];
|
||||
_self.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2517e8f040bd36f46948e5fafaf5335c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Cryville/Common/Collections/Generic/PairList.cs
Normal file
48
Assets/Cryville/Common/Collections/Generic/PairList.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Cryville.Common.Collections.Generic {
|
||||
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairListDebugView<,>))]
|
||||
public class PairList<TKey, TValue> : List<KeyValuePair<TKey, TValue>>, IPairList<TKey, TValue>, IPairList {
|
||||
public void Add(TKey key, TValue value) {
|
||||
Add(new KeyValuePair<TKey, TValue>(key, value));
|
||||
}
|
||||
|
||||
public void Add(object key, object value) {
|
||||
try {
|
||||
Add((TKey)key, (TValue)value);
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
throw new ArgumentException("Wrong key type or value type");
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(int index, TKey key, TValue value) {
|
||||
Insert(index, new KeyValuePair<TKey, TValue>(key, value));
|
||||
}
|
||||
|
||||
public void Insert(int index, object key, object value) {
|
||||
try {
|
||||
Insert(index, (TKey)key, (TValue)value);
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
throw new ArgumentException("Wrong key type or value type");
|
||||
}
|
||||
}
|
||||
}
|
||||
internal class PairListDebugView<TKey, TValue> {
|
||||
readonly PairList<TKey, TValue> _self;
|
||||
public PairListDebugView(PairList<TKey, TValue> self) {
|
||||
_self = self;
|
||||
}
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
|
||||
public KeyValuePair<TKey, TValue>[] Items {
|
||||
get {
|
||||
KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[_self.Count];
|
||||
_self.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Collections/Generic/PairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/Generic/PairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9ed5ea8b7b1a934287e7ec5971166c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Cryville/Common/Collections/IPairList.cs
Normal file
8
Assets/Cryville/Common/Collections/IPairList.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Cryville.Common.Collections {
|
||||
public interface IPairList : IList {
|
||||
void Add(object key, object value);
|
||||
void Insert(int index, object key, object value);
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Collections/IPairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/IPairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 046617672d437de4ab7e644a55defd3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
47
Assets/Cryville/Common/Collections/PairCollection.cs
Normal file
47
Assets/Cryville/Common/Collections/PairCollection.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Cryville.Common.Collections {
|
||||
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairCollectionDebugView))]
|
||||
public struct PairCollection : IDisposable {
|
||||
public void Dispose() { }
|
||||
readonly IPairList _pairList;
|
||||
readonly IDictionary _dictionary;
|
||||
public PairCollection(object collection) : this() {
|
||||
var type = collection.GetType();
|
||||
if (typeof(IPairList).IsAssignableFrom(type)) _pairList = (IPairList)collection;
|
||||
else if (typeof(IDictionary).IsAssignableFrom(type)) _dictionary = (IDictionary)collection;
|
||||
else throw new ArgumentException("Parameter is not a pair collection");
|
||||
}
|
||||
public int Count {
|
||||
get {
|
||||
if (_pairList != null) return _pairList.Count;
|
||||
else return _dictionary.Count;
|
||||
}
|
||||
}
|
||||
public void Add(object key, object value) {
|
||||
if (_pairList != null) _pairList.Add(key, value);
|
||||
else _dictionary.Add(key, value);
|
||||
}
|
||||
public void CopyTo(KeyValuePair<object, object>[] array, int index) {
|
||||
if (_pairList != null) _pairList.CopyTo(array, index);
|
||||
else _dictionary.CopyTo(array, index);
|
||||
}
|
||||
}
|
||||
internal class PairCollectionDebugView {
|
||||
readonly PairCollection _self;
|
||||
public PairCollectionDebugView(PairCollection self) {
|
||||
_self = self;
|
||||
}
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
|
||||
public KeyValuePair<object, object>[] Items {
|
||||
get {
|
||||
KeyValuePair<object, object>[] array = new KeyValuePair<object, object>[_self.Count];
|
||||
_self.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Collections/PairCollection.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/PairCollection.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f87dfb8f6a1f5640b6deae741cd715c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Cryville/Common/Collections/PairList.cs
Normal file
29
Assets/Cryville/Common/Collections/PairList.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Cryville.Common.Collections {
|
||||
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairListDebugView))]
|
||||
public class PairList : List<KeyValuePair<object, object>>, IPairList {
|
||||
public void Add(object key, object value) {
|
||||
Add(new KeyValuePair<object, object>(key, value));
|
||||
}
|
||||
|
||||
public void Insert(int index, object key, object value) {
|
||||
Insert(index, new KeyValuePair<object, object>(key, value));
|
||||
}
|
||||
}
|
||||
internal class PairListDebugView {
|
||||
readonly PairList _self;
|
||||
public PairListDebugView(PairList self) {
|
||||
_self = self;
|
||||
}
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
|
||||
public KeyValuePair<object, object>[] Items {
|
||||
get {
|
||||
KeyValuePair<object, object>[] array = new KeyValuePair<object, object>[_self.Count];
|
||||
_self.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Collections/PairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/PairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57fc9f037c1fda5449e2a365a835c82c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Cryville/Common/Culture.meta
Normal file
8
Assets/Cryville/Common/Culture.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 520554ce9a8205b4b91e0ff2b8011673
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
37
Assets/Cryville/Common/Culture/ScriptUtils.cs
Normal file
37
Assets/Cryville/Common/Culture/ScriptUtils.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Culture {
|
||||
public static class ScriptUtils {
|
||||
public static string[] Scripts = new string[] { "adlm", "afak", "aghb", "ahom", "arab", "aran", "armi", "armn", "avst", "bali", "bamu", "bass", "batk", "beng", "bhks", "blis", "bopo", "brah", "brai", "bugi", "buhd", "cakm", "cans", "cari", "cham", "cher", "chrs", "cirt", "copt", "cpmn", "cprt", "cyrl", "cyrs", "deva", "diak", "dogr", "dsrt", "dupl", "egyd", "egyh", "egyp", "elba", "elym", "ethi", "geok", "geor", "glag", "gong", "gonm", "goth", "gran", "grek", "gujr", "guru", "hanb", "hang", "hani", "hano", "hans", "hant", "hatr", "hebr", "hira", "hluw", "hmng", "hmnp", "hrkt", "hung", "inds", "ital", "jamo", "java", "jpan", "jurc", "kali", "kana", "khar", "khmr", "khoj", "kitl", "kits", "knda", "kore", "kpel", "kthi", "lana", "laoo", "latf", "latg", "latn", "leke", "lepc", "limb", "lina", "linb", "lisu", "loma", "lyci", "lydi", "mahj", "maka", "mand", "mani", "marc", "maya", "medf", "mend", "merc", "mero", "mlym", "modi", "mong", "moon", "mroo", "mtei", "mult", "mymr", "nand", "narb", "nbat", "newa", "nkdb", "nkgb", "nkoo", "nshu", "ogam", "olck", "orkh", "orya", "osge", "osma", "ougr", "palm", "pauc", "pcun", "pelm", "perm", "phag", "phli", "phlp", "phlv", "phnx", "piqd", "plrd", "prti", "psin", "qaaa", "qaai", "qabx", "ranj", "rjng", "rohg", "roro", "runr", "samr", "sara", "sarb", "saur", "sgnw", "shaw", "shrd", "shui", "sidd", "sind", "sinh", "sogd", "sogo", "sora", "soyo", "sund", "sylo", "syrc", "syre", "syrj", "syrn", "tagb", "takr", "tale", "talu", "taml", "tang", "tavt", "telu", "teng", "tfng", "tglg", "thaa", "thai", "tibt", "tirh", "toto", "ugar", "vaii", "visp", "wara", "wcho", "wole", "xpeo", "xsux", "yezi", "yiii", "zanb", "zinh", "zmth", "zsye", "zsym", "zxxx", "zyyy", "zzzz", };
|
||||
public static string UltimateFallbackScript = "zyyy";
|
||||
public static Dictionary<string, string[]> FallbackScriptMap = new Dictionary<string, string[]> {
|
||||
{ "aran", new string[] { "arab" } }, { "cyrs", new string[] { "cyrl" } },
|
||||
{ "hanb", new string[] { "hant", "bopo" } }, { "hans", new string[] { "hani" } }, { "hant", new string[] { "hani" } },
|
||||
{ "hrkt", new string[] { "hira", "kana" } }, { "jpan", new string[] { "hani", "hira", "kana" } },
|
||||
{ "jamo", new string[] { "hang" } }, { "kore", new string[] { "hang", "hani" } },
|
||||
{ "latf", new string[] { "latn" } }, { "latg", new string[] { "latn" } },
|
||||
{ "syre", new string[] { "syrc" } }, { "syrj", new string[] { "syrc" } }, { "syrn", new string[] { "syrc" } },
|
||||
{ "zsye", new string[] { "zsym" } },
|
||||
};
|
||||
public static void FillKeysWithScripts(IDictionary dict, Func<object> value) {
|
||||
foreach (var s in Scripts) dict.Add(s, value());
|
||||
}
|
||||
public static IEnumerable<string> EnumerateFallbackScripts(string script) {
|
||||
if (string.IsNullOrEmpty(script)) throw new ArgumentNullException("script");
|
||||
script = script.ToLower();
|
||||
if (script == UltimateFallbackScript) {
|
||||
yield return null;
|
||||
yield break;
|
||||
}
|
||||
string[] fblist;
|
||||
if (FallbackScriptMap.TryGetValue(script, out fblist)) {
|
||||
foreach (var fb in fblist) {
|
||||
yield return fb;
|
||||
}
|
||||
}
|
||||
else yield return UltimateFallbackScript;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Culture/ScriptUtils.cs.meta
Normal file
11
Assets/Cryville/Common/Culture/ScriptUtils.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae9dab8f520fadc4194032f523ca87c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
113
Assets/Cryville/Common/Font/FontFile.cs
Normal file
113
Assets/Cryville/Common/Font/FontFile.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Cryville.Common.IO;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
public abstract class FontFile : IEnumerable<Typeface> {
|
||||
public abstract int Count { get; }
|
||||
public abstract Typeface this[int index] { get; }
|
||||
protected FileInfo File { get; private set; }
|
||||
protected BinaryReader Reader { get; private set; }
|
||||
public FontFile(FileInfo file) {
|
||||
File = file;
|
||||
Reader = new BinaryReaderBE(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
|
||||
}
|
||||
public void Close() { Reader.Close(); }
|
||||
|
||||
public static FontFile Create(FileInfo file) {
|
||||
switch (file.Extension) {
|
||||
case ".ttf": case ".otf": return new FontFileTTF(file);
|
||||
case ".ttc": case ".otc": return new FontFileTTC(file);
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Enumerator GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
IEnumerator<Typeface> IEnumerable<Typeface>.GetEnumerator() {
|
||||
return GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public struct Enumerator : IEnumerator<Typeface> {
|
||||
readonly FontFile _self;
|
||||
int _index;
|
||||
internal Enumerator(FontFile self) {
|
||||
_self = self;
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
public Typeface 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.Count) {
|
||||
_index = -2;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class FontFileTTF : FontFile {
|
||||
public override int Count { get { return 1; } }
|
||||
public override Typeface this[int index] {
|
||||
get {
|
||||
if (index != 0) throw new ArgumentOutOfRangeException("index");
|
||||
try {
|
||||
return new TypefaceTTF(Reader, File, index);
|
||||
}
|
||||
catch (Exception) {
|
||||
throw new InvalidDataException("Invalid font");
|
||||
}
|
||||
}
|
||||
}
|
||||
public FontFileTTF(FileInfo file) : base(file) { }
|
||||
}
|
||||
public class FontFileTTC : FontFile {
|
||||
readonly IReadOnlyList<uint> _offsets;
|
||||
public override int Count { get { return _offsets.Count; } }
|
||||
public override Typeface this[int index] {
|
||||
get {
|
||||
if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException("index");
|
||||
Reader.BaseStream.Position = _offsets[index];
|
||||
try {
|
||||
return new TypefaceTTF(Reader, File, index);
|
||||
}
|
||||
catch (Exception) {
|
||||
throw new InvalidDataException("Invalid font");
|
||||
}
|
||||
}
|
||||
}
|
||||
public FontFileTTC(FileInfo file) : base(file) {
|
||||
try {
|
||||
_offsets = new TTCHeader(Reader, 0).GetItems();
|
||||
}
|
||||
catch (Exception) {
|
||||
throw new InvalidDataException("Invalid font");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Font/FontFile.cs.meta
Normal file
11
Assets/Cryville/Common/Font/FontFile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f44ccf8ddd364418b4f4965414ff9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/Cryville/Common/Font/FontManager.cs
Normal file
63
Assets/Cryville/Common/Font/FontManager.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
public abstract class FontManager {
|
||||
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapFullNameToTypeface { get; private set; }
|
||||
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapNameToTypefaces { get; private set; }
|
||||
public FontManager() {
|
||||
var map1 = new Dictionary<string, List<Typeface>>();
|
||||
var map2 = new Dictionary<string, List<Typeface>>();
|
||||
foreach (var f in EnumerateAllTypefaces()) {
|
||||
List<Typeface> set1;
|
||||
if (!map1.TryGetValue(f.FullName, out set1)) {
|
||||
map1.Add(f.FullName, set1 = new List<Typeface>());
|
||||
}
|
||||
set1.Add(f);
|
||||
List<Typeface> set2;
|
||||
if (!map2.TryGetValue(f.FamilyName, out set2)) {
|
||||
map2.Add(f.FamilyName, set2 = new List<Typeface>());
|
||||
}
|
||||
set2.Add(f);
|
||||
}
|
||||
MapFullNameToTypeface = map1.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
||||
MapNameToTypefaces = map2.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
||||
}
|
||||
protected abstract IEnumerable<Typeface> EnumerateAllTypefaces();
|
||||
protected static IEnumerable<Typeface> ScanDirectoryForTypefaces(string dir) {
|
||||
foreach (var f in new DirectoryInfo(dir).EnumerateFiles()) {
|
||||
FontFile file;
|
||||
try {
|
||||
file = FontFile.Create(f);
|
||||
}
|
||||
catch (InvalidDataException) {
|
||||
continue;
|
||||
}
|
||||
if (file == null) continue;
|
||||
var enumerator = file.GetEnumerator();
|
||||
while (enumerator.MoveNext()) {
|
||||
Typeface ret;
|
||||
try {
|
||||
ret = enumerator.Current;
|
||||
}
|
||||
catch (InvalidDataException) {
|
||||
continue;
|
||||
}
|
||||
yield return ret;
|
||||
}
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class FontManagerAndroid : FontManager {
|
||||
protected override IEnumerable<Typeface> EnumerateAllTypefaces() {
|
||||
return ScanDirectoryForTypefaces("/system/fonts");
|
||||
}
|
||||
}
|
||||
public class FontManagerWindows : FontManager {
|
||||
protected override IEnumerable<Typeface> EnumerateAllTypefaces() {
|
||||
return ScanDirectoryForTypefaces("C:/Windows/Fonts");
|
||||
}
|
||||
}
|
||||
}
|
329
Assets/Cryville/Common/Font/FontMatcher.cs
Normal file
329
Assets/Cryville/Common/Font/FontMatcher.cs
Normal file
@@ -0,0 +1,329 @@
|
||||
using Cryville.Common.Culture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
public abstract class FontMatcher {
|
||||
protected FontManager Manager { get; private set; }
|
||||
public FontMatcher(FontManager manafer) { Manager = manafer; }
|
||||
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false);
|
||||
}
|
||||
public class FallbackListFontMatcher : FontMatcher {
|
||||
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
|
||||
public void LoadDefaultWindowsFallbackList() {
|
||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return;
|
||||
MapScriptToTypefaces.Clear();
|
||||
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
|
||||
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "SimSun"); // Custom
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "SimHei"); // Custom
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Arial");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Segoe UI"); // Custom
|
||||
MapScriptToTypefaces["arab"].Insert(0, "Tahoma");
|
||||
MapScriptToTypefaces["cyrl"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["grek"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["hebr"].Insert(0, "David");
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "MS PGothic");
|
||||
MapScriptToTypefaces["latn"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "SimSun");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "SimHei"); // Custom
|
||||
MapScriptToTypefaces["thai"].Insert(0, "Tahoma");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "PMingLiU");
|
||||
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
|
||||
var ver = Environment.OSVersion.Version;
|
||||
if (ver >= new Version(5, 0)) { // Windows 2000
|
||||
MapScriptToTypefaces["armn"].Insert(0, "Sylfaen");
|
||||
MapScriptToTypefaces["deva"].Insert(0, "Mangal");
|
||||
MapScriptToTypefaces["geor"].Insert(0, "Sylfaen");
|
||||
MapScriptToTypefaces["taml"].Insert(0, "Latha");
|
||||
}
|
||||
if (ver >= new Version(5, 1)) { // Windows XP
|
||||
MapScriptToTypefaces["gujr"].Insert(0, "Shruti");
|
||||
MapScriptToTypefaces["guru"].Insert(0, "Raavi");
|
||||
MapScriptToTypefaces["knda"].Insert(0, "Tunga");
|
||||
MapScriptToTypefaces["syrc"].Insert(0, "Estrangelo Edessa");
|
||||
MapScriptToTypefaces["telu"].Insert(0, "Gautami");
|
||||
MapScriptToTypefaces["thaa"].Insert(0, "MV Boli");
|
||||
// SP2
|
||||
MapScriptToTypefaces["beng"].Insert(0, "Vrinda");
|
||||
MapScriptToTypefaces["mlym"].Insert(0, "Kartika");
|
||||
}
|
||||
if (ver >= new Version(6, 0)) { // Windows Vista
|
||||
MapScriptToTypefaces["cans"].Insert(0, "Euphemia");
|
||||
MapScriptToTypefaces["cher"].Insert(0, "Plantagenet");
|
||||
MapScriptToTypefaces["ethi"].Insert(0, "Nyala");
|
||||
MapScriptToTypefaces["khmr"].Insert(0, "DaunPenh MoolBoran");
|
||||
MapScriptToTypefaces["laoo"].Insert(0, "DokChampa");
|
||||
MapScriptToTypefaces["mong"].Insert(0, "Mongolian Baiti");
|
||||
MapScriptToTypefaces["orya"].Insert(0, "Kalinga");
|
||||
MapScriptToTypefaces["sinh"].Insert(0, "Iskoola Pota");
|
||||
MapScriptToTypefaces["tibt"].Insert(0, "Microsoft Himalaya");
|
||||
MapScriptToTypefaces["yiii"].Insert(0, "Microsoft Yi Baiti");
|
||||
MapScriptToTypefaces["arab"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["cyrl"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["grek"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["latn"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["hans"].Add("SimSun-ExtB");
|
||||
MapScriptToTypefaces["hant"].Add("MingLiU-ExtB");
|
||||
MapScriptToTypefaces["hant"].Add("MingLiU_HKSCS-ExtB");
|
||||
MapScriptToTypefaces["arab"].Add("Microsoft Uighur");
|
||||
MapScriptToTypefaces["zmth"].Insert(0, "Cambria Math");
|
||||
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei");
|
||||
}
|
||||
if (ver >= new Version(6, 1)) { // Windows 7
|
||||
MapScriptToTypefaces["brai"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["dsrt"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["talu"].Insert(0, "Microsoft New Tai Lue");
|
||||
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["osma"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["phag"].Insert(0, "Microsoft PhagsPa");
|
||||
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["zsym"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["tale"].Insert(0, "Microsoft Tai Le");
|
||||
MapScriptToTypefaces["tfng"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["vaii"].Insert(0, "Ebrima");
|
||||
}
|
||||
if (ver >= new Version(6, 2)) { // Windows 8
|
||||
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["hang"].Add("Malgun Gothic");
|
||||
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["lisu"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["mymr"].Insert(0, "Myanmar Text");
|
||||
MapScriptToTypefaces["nkoo"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["ethi"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["cans"].Insert(0, "Gadugi");
|
||||
MapScriptToTypefaces["hant"].Insert(0, "Microsoft JhengHei UI");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei UI");
|
||||
MapScriptToTypefaces["beng"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["deva"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["gujr"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["mlym"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["orya"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["telu"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["armn"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["geor"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["hebr"].Insert(0, "Segoe UI");
|
||||
}
|
||||
if (ver >= new Version(6, 3)) { // Windows 8.1
|
||||
MapScriptToTypefaces["bugi"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["copt"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["java"].Insert(0, "Javanese Text");
|
||||
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["olck"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["sora"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["khmr"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["laoo"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["thai"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["zsye"].Insert(0, "Segoe UI Emoji");
|
||||
}
|
||||
if (ver >= new Version(10, 0)) { // Windows 10
|
||||
MapScriptToTypefaces["brah"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["cari"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["cprt"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["egyp"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["armi"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["phli"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["prti"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["khar"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["lyci"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["lydi"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["phnx"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["xpeo"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["sarb"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["shaw"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["xsux"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["ugar"].Insert(0, "Segoe UI Historic");
|
||||
// Segoe UI Symbol -> Segoe UI Historic
|
||||
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Historic");
|
||||
//
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI");
|
||||
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets");
|
||||
}
|
||||
}
|
||||
public void LoadDefaultAndroidFallbackList() {
|
||||
if (Environment.OSVersion.Platform != PlatformID.Unix) return;
|
||||
MapScriptToTypefaces.Clear();
|
||||
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK JP");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK SC");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Roboto");
|
||||
MapScriptToTypefaces["zsye"].Insert(0, "Noto Color Emoji");
|
||||
MapScriptToTypefaces["zsye"].Add("Noto Color Emoji Flags");
|
||||
MapScriptToTypefaces["arab"].Insert(0, "Noto Naskh Arabic");
|
||||
MapScriptToTypefaces["adlm"].Insert(0, "Noto Sans Adlam");
|
||||
MapScriptToTypefaces["ahom"].Insert(0, "Noto Sans Ahom");
|
||||
MapScriptToTypefaces["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
|
||||
MapScriptToTypefaces["armn"].Insert(0, "Noto Sans Armenian");
|
||||
MapScriptToTypefaces["avst"].Insert(0, "Noto Sans Avestan");
|
||||
MapScriptToTypefaces["bali"].Insert(0, "Noto Sans Balinese");
|
||||
MapScriptToTypefaces["bamu"].Insert(0, "Noto Sans Bamum");
|
||||
MapScriptToTypefaces["bass"].Insert(0, "Noto Sans Bassa Vah");
|
||||
MapScriptToTypefaces["batk"].Insert(0, "Noto Sans Batak");
|
||||
MapScriptToTypefaces["beng"].Insert(0, "Noto Sans Bengali");
|
||||
MapScriptToTypefaces["bhks"].Insert(0, "Noto Sans Bhaiksuki");
|
||||
MapScriptToTypefaces["brah"].Insert(0, "Noto Sans Brahmi");
|
||||
MapScriptToTypefaces["bugi"].Insert(0, "Noto Sans Buginese");
|
||||
MapScriptToTypefaces["buhd"].Insert(0, "Noto Sans Buhid");
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "Noto Sans CJK JP");
|
||||
MapScriptToTypefaces["kore"].Insert(0, "Noto Sans CJK KR");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "Noto Sans CJK SC");
|
||||
MapScriptToTypefaces["hant"].Insert(0, "Noto Sans CJK TC");
|
||||
MapScriptToTypefaces["hant"].Add("Noto Sans CJK HK");
|
||||
MapScriptToTypefaces["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
|
||||
MapScriptToTypefaces["cari"].Insert(0, "Noto Sans Carian");
|
||||
MapScriptToTypefaces["cakm"].Insert(0, "Noto Sans Chakma");
|
||||
MapScriptToTypefaces["cham"].Insert(0, "Noto Sans Cham");
|
||||
MapScriptToTypefaces["cher"].Insert(0, "Noto Sans Cherokee");
|
||||
MapScriptToTypefaces["copt"].Insert(0, "Noto Sans Coptic");
|
||||
MapScriptToTypefaces["xsux"].Insert(0, "Noto Sans Cuneiform");
|
||||
MapScriptToTypefaces["cprt"].Insert(0, "Noto Sans Cypriot");
|
||||
MapScriptToTypefaces["dsrt"].Insert(0, "Noto Sans Deseret");
|
||||
MapScriptToTypefaces["deva"].Insert(0, "Noto Sans Devanagari");
|
||||
MapScriptToTypefaces["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
|
||||
MapScriptToTypefaces["elba"].Insert(0, "Noto Sans Elbasan");
|
||||
MapScriptToTypefaces["ethi"].Insert(0, "Noto Sans Ethiopic");
|
||||
MapScriptToTypefaces["geor"].Insert(0, "Noto Sans Georgian");
|
||||
MapScriptToTypefaces["glag"].Insert(0, "Noto Sans Glagolitic");
|
||||
MapScriptToTypefaces["goth"].Insert(0, "Noto Sans Gothic");
|
||||
MapScriptToTypefaces["gran"].Insert(0, "Noto Sans Grantha");
|
||||
MapScriptToTypefaces["gujr"].Insert(0, "Noto Sans Gujarati");
|
||||
MapScriptToTypefaces["gong"].Insert(0, "Noto Sans Gunjala Gondi");
|
||||
MapScriptToTypefaces["guru"].Insert(0, "Noto Sans Gurmukhi");
|
||||
MapScriptToTypefaces["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
|
||||
MapScriptToTypefaces["hano"].Insert(0, "Noto Sans Hanunoo");
|
||||
MapScriptToTypefaces["hatr"].Insert(0, "Noto Sans Hatran");
|
||||
MapScriptToTypefaces["hebr"].Insert(0, "Noto Sans Hebrew");
|
||||
MapScriptToTypefaces["armi"].Insert(0, "Noto Sans Imperial Aramaic");
|
||||
MapScriptToTypefaces["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
|
||||
MapScriptToTypefaces["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
|
||||
MapScriptToTypefaces["java"].Insert(0, "Noto Sans Javanese");
|
||||
MapScriptToTypefaces["kthi"].Insert(0, "Noto Sans Kaithi");
|
||||
MapScriptToTypefaces["knda"].Insert(0, "Noto Sans Kannada");
|
||||
MapScriptToTypefaces["kali"].Insert(0, "Noto Sans KayahLi");
|
||||
MapScriptToTypefaces["khar"].Insert(0, "Noto Sans Kharoshthi");
|
||||
MapScriptToTypefaces["khmr"].Insert(0, "Noto Sans Khmer");
|
||||
MapScriptToTypefaces["khoj"].Insert(0, "Noto Sans Khojki");
|
||||
MapScriptToTypefaces["laoo"].Insert(0, "Noto Sans Lao");
|
||||
MapScriptToTypefaces["lepc"].Insert(0, "Noto Sans Lepcha");
|
||||
MapScriptToTypefaces["limb"].Insert(0, "Noto Sans Limbu");
|
||||
MapScriptToTypefaces["lina"].Insert(0, "Noto Sans Linear A");
|
||||
MapScriptToTypefaces["linb"].Insert(0, "Noto Sans Linear B");
|
||||
MapScriptToTypefaces["lisu"].Insert(0, "Noto Sans Lisu");
|
||||
MapScriptToTypefaces["lyci"].Insert(0, "Noto Sans Lycian");
|
||||
MapScriptToTypefaces["lydi"].Insert(0, "Noto Sans Lydian");
|
||||
MapScriptToTypefaces["mlym"].Insert(0, "Noto Sans Malayalam");
|
||||
MapScriptToTypefaces["mand"].Insert(0, "Noto Sans Mandiac");
|
||||
MapScriptToTypefaces["mani"].Insert(0, "Noto Sans Manichaean");
|
||||
MapScriptToTypefaces["marc"].Insert(0, "Noto Sans Marchen");
|
||||
MapScriptToTypefaces["gonm"].Insert(0, "Noto Sans Masaram Gondi");
|
||||
MapScriptToTypefaces["medf"].Insert(0, "Noto Sans Medefaidrin");
|
||||
MapScriptToTypefaces["mtei"].Insert(0, "Noto Sans Meetei Mayek");
|
||||
MapScriptToTypefaces["merc"].Insert(0, "Noto Sans Meroitic");
|
||||
MapScriptToTypefaces["mero"].Insert(0, "Noto Sans Meroitic");
|
||||
MapScriptToTypefaces["plrd"].Insert(0, "Noto Sans Miao");
|
||||
MapScriptToTypefaces["modi"].Insert(0, "Noto Sans Modi");
|
||||
MapScriptToTypefaces["mong"].Insert(0, "Noto Sans Mongolian");
|
||||
MapScriptToTypefaces["mroo"].Insert(0, "Noto Sans Mro");
|
||||
MapScriptToTypefaces["mult"].Insert(0, "Noto Sans Multani");
|
||||
MapScriptToTypefaces["mymr"].Insert(0, "Noto Sans Myanmar");
|
||||
MapScriptToTypefaces["nkoo"].Insert(0, "Noto Sans Nko");
|
||||
MapScriptToTypefaces["nbat"].Insert(0, "Noto Sans Nabataean");
|
||||
MapScriptToTypefaces["talu"].Insert(0, "Noto Sans New Tai Lue");
|
||||
MapScriptToTypefaces["newa"].Insert(0, "Noto Sans Newa");
|
||||
MapScriptToTypefaces["ogam"].Insert(0, "Noto Sans Ogham");
|
||||
MapScriptToTypefaces["olck"].Insert(0, "Noto Sans Ol Chiki");
|
||||
MapScriptToTypefaces["ital"].Insert(0, "Noto Sans Old Italian");
|
||||
MapScriptToTypefaces["narb"].Insert(0, "Noto Sans Old North Arabian");
|
||||
MapScriptToTypefaces["perm"].Insert(0, "Noto Sans Old Permic");
|
||||
MapScriptToTypefaces["xpeo"].Insert(0, "Noto Sans Old Persian");
|
||||
MapScriptToTypefaces["sarb"].Insert(0, "Noto Sans Old South Arabian");
|
||||
MapScriptToTypefaces["orkh"].Insert(0, "Noto Sans Old Turkic");
|
||||
MapScriptToTypefaces["orya"].Insert(0, "Noto Sans Oriya");
|
||||
MapScriptToTypefaces["osge"].Insert(0, "Noto Sans Osage");
|
||||
MapScriptToTypefaces["osma"].Insert(0, "Noto Sans Osmanya");
|
||||
MapScriptToTypefaces["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
|
||||
MapScriptToTypefaces["palm"].Insert(0, "Noto Sans Palmyrene");
|
||||
MapScriptToTypefaces["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
|
||||
MapScriptToTypefaces["phag"].Insert(0, "Noto Sans Phags Pa");
|
||||
MapScriptToTypefaces["phnx"].Insert(0, "Noto Sans Phoenician");
|
||||
MapScriptToTypefaces["rjng"].Insert(0, "Noto Sans Rejang");
|
||||
MapScriptToTypefaces["runr"].Insert(0, "Noto Sans Runic");
|
||||
MapScriptToTypefaces["samr"].Insert(0, "Noto Sans Samaritan");
|
||||
MapScriptToTypefaces["saur"].Insert(0, "Noto Sans Saurashtra");
|
||||
MapScriptToTypefaces["shrd"].Insert(0, "Noto Sans Sharada");
|
||||
MapScriptToTypefaces["shaw"].Insert(0, "Noto Sans Shavian");
|
||||
MapScriptToTypefaces["sinh"].Insert(0, "Noto Sans Sinhala");
|
||||
MapScriptToTypefaces["sora"].Insert(0, "Noto Sans Sora Sompeng");
|
||||
MapScriptToTypefaces["soyo"].Insert(0, "Noto Sans Soyombo");
|
||||
MapScriptToTypefaces["sund"].Insert(0, "Noto Sans Sundanese");
|
||||
MapScriptToTypefaces["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
||||
MapScriptToTypefaces["zsym"].Insert(0, "Noto Sans Symbols");
|
||||
MapScriptToTypefaces["syrn"].Insert(0, "Noto Sans Syriac Eastern");
|
||||
MapScriptToTypefaces["syre"].Insert(0, "Noto Sans Syriac Estrangela");
|
||||
MapScriptToTypefaces["syrj"].Insert(0, "Noto Sans Syriac Western");
|
||||
MapScriptToTypefaces["tglg"].Insert(0, "Noto Sans Tagalog");
|
||||
MapScriptToTypefaces["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
||||
MapScriptToTypefaces["tale"].Insert(0, "Noto Sans Tai Le");
|
||||
MapScriptToTypefaces["lana"].Insert(0, "Noto Sans Tai Tham");
|
||||
MapScriptToTypefaces["tavt"].Insert(0, "Noto Sans Tai Viet");
|
||||
MapScriptToTypefaces["takr"].Insert(0, "Noto Sans Takri");
|
||||
MapScriptToTypefaces["taml"].Insert(0, "Noto Sans Tamil");
|
||||
MapScriptToTypefaces["telu"].Insert(0, "Noto Sans Telugu");
|
||||
MapScriptToTypefaces["thaa"].Insert(0, "Noto Sans Thaana");
|
||||
MapScriptToTypefaces["thai"].Insert(0, "Noto Sans Thai");
|
||||
MapScriptToTypefaces["tfng"].Insert(0, "Noto Sans Tifinagh");
|
||||
MapScriptToTypefaces["ugar"].Insert(0, "Noto Sans Ugaritic");
|
||||
MapScriptToTypefaces["vaii"].Insert(0, "Noto Sans Vai");
|
||||
MapScriptToTypefaces["wcho"].Insert(0, "Noto Sans Wancho");
|
||||
MapScriptToTypefaces["wara"].Insert(0, "Noto Sans Warang Citi");
|
||||
MapScriptToTypefaces["yiii"].Insert(0, "Noto Sans Yi");
|
||||
}
|
||||
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
|
||||
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
|
||||
if (string.IsNullOrEmpty(script)) script = ScriptUtils.UltimateFallbackScript;
|
||||
List<string> candidates;
|
||||
IEnumerable<string> candidateScripts = new string[] { script };
|
||||
while (candidateScripts != null) {
|
||||
foreach (var candidateScript in candidateScripts) {
|
||||
if (MapScriptToTypefaces.TryGetValue(candidateScript, out candidates)) {
|
||||
foreach (var candidate in candidates) {
|
||||
IReadOnlyCollection<Typeface> typefaces1;
|
||||
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out typefaces1)) {
|
||||
foreach (var typeface in typefaces1) {
|
||||
yield return typeface;
|
||||
}
|
||||
}
|
||||
if (distinctFamily) continue;
|
||||
IReadOnlyCollection<Typeface> typefaces2;
|
||||
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
|
||||
foreach (var typeface in typefaces2) {
|
||||
if (typefaces1.Contains(typeface)) continue;
|
||||
yield return typeface;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
candidateScripts = ScriptUtils.EnumerateFallbackScripts(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Font/FontMatcher.cs.meta
Normal file
11
Assets/Cryville/Common/Font/FontMatcher.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afcde0ad1865db24da79ca1ce7256791
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
222
Assets/Cryville/Common/Font/FontTable.cs
Normal file
222
Assets/Cryville/Common/Font/FontTable.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
public abstract class FontTable<T> {
|
||||
protected UInt32 Offset { get; private set; }
|
||||
protected BinaryReader Reader { get; private set; }
|
||||
|
||||
protected FontTable(BinaryReader reader, UInt32 offset) {
|
||||
Reader = reader;
|
||||
Offset = offset;
|
||||
reader.BaseStream.Position = offset;
|
||||
}
|
||||
public abstract IReadOnlyList<T> GetItems();
|
||||
}
|
||||
public abstract class FontTable<T, U> : FontTable<T> {
|
||||
protected FontTable(BinaryReader reader, UInt32 offset) : base(reader, offset) { }
|
||||
public abstract U GetSubTable(T item);
|
||||
}
|
||||
public sealed class TTCHeader : FontTable<UInt32, TableDirectory> {
|
||||
readonly String ttcTag;
|
||||
readonly UInt16 majorVersion;
|
||||
readonly UInt16 minorVersion;
|
||||
readonly UInt32 numFonts;
|
||||
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
|
||||
readonly String dsigTag;
|
||||
readonly UInt32 dsigLength;
|
||||
readonly UInt32 dsigOffset;
|
||||
public TTCHeader(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||
ttcTag = reader.ReadTag();
|
||||
if (ttcTag != "ttcf") throw new NotImplementedException();
|
||||
majorVersion = reader.ReadUInt16();
|
||||
minorVersion = reader.ReadUInt16();
|
||||
numFonts = reader.ReadUInt32();
|
||||
for (UInt32 i = 0; i < numFonts; i++) tableDirectoryOffsets.Add(reader.ReadUInt32());
|
||||
if (majorVersion == 2) {
|
||||
dsigTag = reader.ReadTag();
|
||||
dsigLength = reader.ReadUInt32();
|
||||
dsigOffset = reader.ReadUInt32();
|
||||
}
|
||||
}
|
||||
public override IReadOnlyList<UInt32> GetItems() {
|
||||
return tableDirectoryOffsets;
|
||||
}
|
||||
public override TableDirectory GetSubTable(UInt32 item) {
|
||||
var i = item;
|
||||
return new TableDirectory(Reader, i);
|
||||
}
|
||||
}
|
||||
public sealed class TableDirectory : FontTable<TableRecord, object> {
|
||||
readonly UInt32 sfntVersion;
|
||||
readonly UInt16 numTables;
|
||||
readonly UInt16 searchRange;
|
||||
readonly UInt16 entrySelector;
|
||||
readonly UInt16 rangeShift;
|
||||
readonly List<TableRecord> tableRecords = new List<TableRecord>();
|
||||
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||
sfntVersion = reader.ReadUInt32();
|
||||
numTables = reader.ReadUInt16();
|
||||
searchRange = reader.ReadUInt16();
|
||||
entrySelector = reader.ReadUInt16();
|
||||
rangeShift = reader.ReadUInt16();
|
||||
for (int i = 0; i < numTables; i++)
|
||||
tableRecords.Add(new TableRecord {
|
||||
tableTag = reader.ReadTag(),
|
||||
checksum = reader.ReadUInt32(),
|
||||
offset = reader.ReadUInt32(),
|
||||
length = reader.ReadUInt32(),
|
||||
});
|
||||
}
|
||||
public override IReadOnlyList<TableRecord> GetItems() {
|
||||
return tableRecords;
|
||||
}
|
||||
public override object GetSubTable(TableRecord item) {
|
||||
switch (item.tableTag) {
|
||||
case "name": return new NameTable(Reader, item.offset);
|
||||
case "meta": return new MetaTable(Reader, item.offset);
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
public struct TableRecord {
|
||||
public string tableTag;
|
||||
public UInt32 checksum;
|
||||
public UInt32 offset;
|
||||
public UInt32 length;
|
||||
}
|
||||
public sealed class NameTable : FontTable<NameRecord> {
|
||||
readonly UInt16 version;
|
||||
readonly UInt16 count;
|
||||
readonly UInt16 storageOffset;
|
||||
readonly List<NameRecord> nameRecord = new List<NameRecord>();
|
||||
readonly UInt16 langTagCount;
|
||||
readonly List<LangTagRecord> langTagRecord = new List<LangTagRecord>();
|
||||
public NameTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||
version = reader.ReadUInt16();
|
||||
count = reader.ReadUInt16();
|
||||
storageOffset = reader.ReadUInt16();
|
||||
for (UInt16 i = 0; i < count; i++)
|
||||
nameRecord.Add(new NameRecord {
|
||||
platformID = reader.ReadUInt16(),
|
||||
encodingID = reader.ReadUInt16(),
|
||||
languageID = reader.ReadUInt16(),
|
||||
nameID = (NameID)reader.ReadUInt16(),
|
||||
length = reader.ReadUInt16(),
|
||||
stringOffset = reader.ReadUInt16(),
|
||||
});
|
||||
if (version == 1) {
|
||||
langTagCount = reader.ReadUInt16();
|
||||
for (UInt16 i = 0; i < langTagCount; i++)
|
||||
langTagRecord.Add(new LangTagRecord {
|
||||
length = reader.ReadUInt16(),
|
||||
langTagOffset = reader.ReadUInt16(),
|
||||
});
|
||||
}
|
||||
UInt32 origin = (UInt32)reader.BaseStream.Position;
|
||||
for (int i = 0; i < nameRecord.Count; i++) nameRecord[i] = nameRecord[i].Load(reader, origin);
|
||||
for (int i = 0; i < langTagRecord.Count; i++) langTagRecord[i] = langTagRecord[i].Load(reader, origin);
|
||||
}
|
||||
public sealed override IReadOnlyList<NameRecord> GetItems() {
|
||||
return nameRecord;
|
||||
}
|
||||
}
|
||||
public struct NameRecord {
|
||||
public UInt16 platformID;
|
||||
public UInt16 encodingID;
|
||||
public UInt16 languageID;
|
||||
public NameID nameID;
|
||||
public UInt16 length;
|
||||
public UInt16 stringOffset;
|
||||
public String value { get; private set; }
|
||||
public NameRecord Load(BinaryReader reader, UInt32 origin) {
|
||||
reader.BaseStream.Position = origin + stringOffset;
|
||||
Encoding encoding;
|
||||
switch (platformID) {
|
||||
case 0: encoding = Encoding.BigEndianUnicode; break;
|
||||
case 3: encoding = Encoding.BigEndianUnicode; break;
|
||||
default: return this;
|
||||
}
|
||||
value = encoding.GetString(reader.ReadBytes(length));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public enum NameID : UInt16 {
|
||||
CopyrightNotice = 0,
|
||||
FontFamilyName = 1,
|
||||
FontSubfamilyName = 2,
|
||||
UniqueFontIdentifier = 3,
|
||||
FullFontName = 4,
|
||||
VersionString = 5,
|
||||
PostScriptName = 6,
|
||||
Trademark = 7,
|
||||
ManufacturerName = 8,
|
||||
Designer = 9,
|
||||
Description = 10,
|
||||
URLVendor = 11,
|
||||
URLDesigner = 12,
|
||||
LicenseDescription = 13,
|
||||
LicenseInfoURL = 14,
|
||||
|
||||
TypographicFamilyName = 16,
|
||||
TypographicSubfamilyName = 17,
|
||||
CompatibleFull = 18,
|
||||
SampleText = 19,
|
||||
PostScriptCIDFindfontName = 20,
|
||||
WWSFamilyName = 21,
|
||||
WWSSubfamilyName = 22,
|
||||
LightBackgroundPalette = 23,
|
||||
DarkBackgroundPalette = 24,
|
||||
VariationsPostScriptNamePrefix = 25,
|
||||
}
|
||||
public struct LangTagRecord {
|
||||
public UInt16 length;
|
||||
public UInt16 langTagOffset;
|
||||
public String value { get; private set; }
|
||||
public LangTagRecord Load(BinaryReader reader, UInt32 origin) {
|
||||
reader.BaseStream.Position = origin + langTagOffset;
|
||||
value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(length));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public sealed class MetaTable : FontTable<DataMap> {
|
||||
readonly UInt32 version;
|
||||
readonly UInt32 flags;
|
||||
readonly UInt32 dataMapCount;
|
||||
readonly List<DataMap> dataMaps = new List<DataMap>();
|
||||
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||
version = reader.ReadUInt32();
|
||||
flags = reader.ReadUInt32();
|
||||
reader.ReadUInt32();
|
||||
dataMapCount = reader.ReadUInt32();
|
||||
for (UInt32 i = 0; i < dataMapCount; i++)
|
||||
dataMaps.Add(new DataMap {
|
||||
tag = reader.ReadTag(),
|
||||
dataOffset = reader.ReadUInt32(),
|
||||
dataLength = reader.ReadUInt32(),
|
||||
});
|
||||
for (int i = 0; i < dataMaps.Count; i++) dataMaps[i] = dataMaps[i].Load(reader, offset);
|
||||
}
|
||||
public sealed override IReadOnlyList<DataMap> GetItems() {
|
||||
return dataMaps;
|
||||
}
|
||||
}
|
||||
public struct DataMap {
|
||||
public String tag;
|
||||
public UInt32 dataOffset;
|
||||
public UInt32 dataLength;
|
||||
public String value { get; private set; }
|
||||
public DataMap Load(BinaryReader reader, UInt32 origin) {
|
||||
reader.BaseStream.Position = origin + dataOffset;
|
||||
value = Encoding.ASCII.GetString(reader.ReadBytes((int)dataLength));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public static class BinaryReaderExtensions {
|
||||
public static string ReadTag(this BinaryReader reader) {
|
||||
return Encoding.ASCII.GetString(reader.ReadBytes(4));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Font/FontTable.cs.meta
Normal file
11
Assets/Cryville/Common/Font/FontTable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3eed6aa2387582346b7b21c6f8de5e1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,9 +0,0 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
public static class FontUtil {
|
||||
/*public static string MatchFontNameWithLang(string lang) {
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
31
Assets/Cryville/Common/Font/Typeface.cs
Normal file
31
Assets/Cryville/Common/Font/Typeface.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
public abstract class Typeface {
|
||||
public FileInfo File { get; private set; }
|
||||
public int IndexInFile { get; private set; }
|
||||
public string FamilyName { get; protected set; }
|
||||
public string SubfamilyName { get; protected set; }
|
||||
public string FullName { get; protected set; }
|
||||
protected abstract void GetName(BinaryReader reader);
|
||||
|
||||
public Typeface(BinaryReader reader, FileInfo file, int index) {
|
||||
File = file;
|
||||
IndexInFile = index;
|
||||
GetName(reader);
|
||||
}
|
||||
}
|
||||
public class TypefaceTTF : Typeface {
|
||||
public TypefaceTTF(BinaryReader reader, FileInfo file, int index)
|
||||
: base(reader, file, index) { }
|
||||
|
||||
protected override void GetName(BinaryReader reader) {
|
||||
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position);
|
||||
var nameTable = (NameTable)dir.GetSubTable((from i in dir.GetItems() where i.tableTag == "name" select i).Single());
|
||||
FamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontFamilyName && i.value != null select i.value).First();
|
||||
SubfamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontSubfamilyName && i.value != null select i.value).First();
|
||||
FullName = (from i in nameTable.GetItems() where i.nameID == NameID.FullFontName && i.value != null select i.value).First();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Font/Typeface.cs.meta
Normal file
11
Assets/Cryville/Common/Font/Typeface.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0968fc12b50cffb4682f0c28d0d14703
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Cryville/Common/IO.meta
Normal file
8
Assets/Cryville/Common/IO.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aaa0d8cecafb37b46a6abe372cfefd93
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
75
Assets/Cryville/Common/IO/BinaryReaderBE.cs
Normal file
75
Assets/Cryville/Common/IO/BinaryReaderBE.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Common.IO {
|
||||
public class BinaryReaderBE : BinaryReader {
|
||||
readonly byte[] m_buffer = new byte[8];
|
||||
|
||||
public BinaryReaderBE(Stream input) : base(input) { }
|
||||
|
||||
public BinaryReaderBE(Stream input, Encoding encoding) : base(input, encoding) { }
|
||||
|
||||
public BinaryReaderBE(Stream input, Encoding encoding, bool leaveOpen) : base(input, encoding, leaveOpen) { }
|
||||
|
||||
public override short ReadInt16() {
|
||||
FillBuffer(2);
|
||||
return (short)(m_buffer[1] | (m_buffer[0] << 8));
|
||||
}
|
||||
public override ushort ReadUInt16() {
|
||||
FillBuffer(2);
|
||||
return (ushort)(m_buffer[1] | (m_buffer[0] << 8));
|
||||
}
|
||||
|
||||
public override int ReadInt32() {
|
||||
FillBuffer(4);
|
||||
return m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24);
|
||||
}
|
||||
public override uint ReadUInt32() {
|
||||
FillBuffer(4);
|
||||
return (uint)(m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24));
|
||||
}
|
||||
|
||||
public override long ReadInt64() {
|
||||
FillBuffer(8);
|
||||
uint num = (uint)(m_buffer[7] | (m_buffer[6] << 8) | (m_buffer[5] << 16) | (m_buffer[4] << 24));
|
||||
uint num2 = (uint)(m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24));
|
||||
return (long)(((ulong)num2 << 32) | num);
|
||||
}
|
||||
public override ulong ReadUInt64() {
|
||||
FillBuffer(8);
|
||||
uint num = (uint)(m_buffer[7] | (m_buffer[6] << 8) | (m_buffer[5] << 16) | (m_buffer[4] << 24));
|
||||
uint num2 = (uint)(m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24));
|
||||
return ((ulong)num2 << 32) | num;
|
||||
}
|
||||
protected new void FillBuffer(int numBytes) {
|
||||
if (m_buffer != null && (numBytes < 0 || numBytes > m_buffer.Length)) {
|
||||
throw new ArgumentOutOfRangeException("numBytes", "Requested numBytes is larger than the internal buffer size");
|
||||
}
|
||||
|
||||
int num = 0, num2;
|
||||
if (BaseStream == null) {
|
||||
throw new IOException("File not open");
|
||||
}
|
||||
|
||||
if (numBytes == 1) {
|
||||
num2 = BaseStream.ReadByte();
|
||||
if (num2 == -1) {
|
||||
throw new EndOfStreamException("The end of the stream is reached before numBytes could be read");
|
||||
}
|
||||
m_buffer[0] = (byte)num2;
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
num2 = BaseStream.Read(m_buffer, num, numBytes - num);
|
||||
if (num2 == 0) {
|
||||
throw new EndOfStreamException("The end of the stream is reached before numBytes could be read");
|
||||
}
|
||||
|
||||
num += num2;
|
||||
}
|
||||
while (num < numBytes);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/IO/BinaryReaderBE.cs.meta
Normal file
11
Assets/Cryville/Common/IO/BinaryReaderBE.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aee537c74ab935940b54cb5d784b7f56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Cryville.Common {
|
||||
public struct Identifier : IEquatable<Identifier> {
|
||||
public static Identifier Empty = new Identifier(0);
|
||||
public int Key { get; private set; }
|
||||
public object Name { get { return IdentifierManager.SharedInstance.Retrieve(Key); } }
|
||||
public Identifier(int key) {
|
||||
@@ -24,11 +25,11 @@ namespace Cryville.Common {
|
||||
if (Key == 0) return "";
|
||||
return Name.ToString();
|
||||
}
|
||||
public static implicit operator Identifier(string identifier) {
|
||||
return new Identifier(identifier);
|
||||
public static bool operator ==(Identifier lhs, Identifier rhs) {
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
public static implicit operator string(Identifier identifier) {
|
||||
return identifier.ToString();
|
||||
public static bool operator !=(Identifier lhs, Identifier rhs) {
|
||||
return !lhs.Equals(rhs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -54,16 +54,13 @@ namespace Cryville.Common.Math {
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a <see cref="System.Single" /> column vector and fills it with polynomial coefficients.
|
||||
/// Fills a <see cref="System.Single" /> column vector with polynomial coefficients.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the column vector.</param>
|
||||
/// <param name="vec">The column vector.</param>
|
||||
/// <param name="num">The base number.</param>
|
||||
/// <returns>A <see cref="System.Single" /> column vector filled with polynomial coefficients.</returns>
|
||||
public static ColumnVector<float> WithPolynomialCoefficients(int size, float num) {
|
||||
var m = new ColumnVector<float>(size);
|
||||
for (var i = 0; i < size; i++)
|
||||
m[i] = (float)System.Math.Pow(num, i);
|
||||
return m;
|
||||
public static void FillWithPolynomialCoefficients(ColumnVector<float> vec, float num) {
|
||||
for (var i = 0; i < vec.Size; i++)
|
||||
vec[i] = (float)System.Math.Pow(num, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
44
Assets/Cryville/Common/Math/CubicBezier.cs
Normal file
44
Assets/Cryville/Common/Math/CubicBezier.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using SMath = System.Math;
|
||||
|
||||
namespace Cryville.Common.Math {
|
||||
// Ported from https://github.com/arian/cubic-bezier/blob/master/index.js
|
||||
public static class CubicBezier {
|
||||
public static float Evaluate(float t, float x1, float y1, float x2, float y2, float epsilon) {
|
||||
float x = t, t0, t1, t2, tx, d2, i;
|
||||
for (t2 = x, i = 0; i < 8; i++) {
|
||||
tx = CurveX(t2, x1, x2) - x;
|
||||
if (SMath.Abs(tx) < epsilon) return CurveY(t2, y1, y2);
|
||||
d2 = DerivativeCurveX(t2, x1, x2);
|
||||
if (SMath.Abs(d2) < 1e-6) break;
|
||||
t2 -= tx / d2;
|
||||
}
|
||||
|
||||
t0 = 0; t1 = 1; t2 = x;
|
||||
|
||||
if (t2 < t0) return CurveY(t0, y1, y2);
|
||||
if (t2 > t1) return CurveY(t1, y1, y2);
|
||||
|
||||
while (t0 < t1) {
|
||||
tx = CurveX(t2, x1, x2);
|
||||
if (SMath.Abs(tx - x) < epsilon) return CurveY(t2, y1, y2);
|
||||
if (x > tx) t0 = t2;
|
||||
else t1 = t2;
|
||||
t2 = (t1 - t0) * .5f + t0;
|
||||
}
|
||||
|
||||
return CurveY(t2, y1, y2);
|
||||
}
|
||||
static float CurveX(float t, float x1, float x2) {
|
||||
float v = 1 - t;
|
||||
return 3 * v * v * t * x1 + 3 * v * t * t * x2 + t * t * t;
|
||||
}
|
||||
static float CurveY(float t, float y1, float y2) {
|
||||
float v = 1 - t;
|
||||
return 3 * v * v * t * y1 + 3 * v * t * t * y2 + t * t * t;
|
||||
}
|
||||
static float DerivativeCurveX(float t, float x1, float x2) {
|
||||
float v = 1 - t;
|
||||
return 3 * (2 * (t - 1) * t + v * v) * x1 + 3 * (-t * t * t + 2 * v * t) * x2;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Math/CubicBezier.cs.meta
Normal file
11
Assets/Cryville/Common/Math/CubicBezier.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17dd6f775fc965f43960da7166b55b87
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -12,12 +12,12 @@ namespace Cryville.Common.Math {
|
||||
/// <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>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is less than 0 or <paramref name="error" /> is not greater than 0 or greater 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.");
|
||||
if (error <= 0.0 || error > 1.0)
|
||||
throw new ArgumentOutOfRangeException("error", "Must be > 0 and <= 1.");
|
||||
|
||||
int num = (int)System.Math.Floor(value);
|
||||
value -= num;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Common.Math {
|
||||
/// <summary>
|
||||
@@ -40,11 +40,11 @@ namespace Cryville.Common.Math {
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The vector type.</typeparam>
|
||||
/// <param name="v">The column vector.</param>
|
||||
/// <param name="result">The result column vector.</param>
|
||||
/// <param name="o">The column operator.</param>
|
||||
/// <returns>The column vector eliminated.</returns>
|
||||
public ColumnVector<T> Eliminate<T>(ColumnVector<T> v, IVectorOperator<T> o) {
|
||||
public void Eliminate<T>(ColumnVector<T> v, ColumnVector<T> result, IVectorOperator<T> o) {
|
||||
int s = Size;
|
||||
Array.Copy(content, buffer, Size * Size);
|
||||
FillBuffer();
|
||||
for (int i = 0; i < s; i++) refl[i] = i;
|
||||
for (int r = 0; r < s; r++) {
|
||||
for (int r0 = r; r0 < s; r0++)
|
||||
@@ -66,14 +66,17 @@ namespace Cryville.Common.Math {
|
||||
v[or1] = o.Add(v[or1], o.ScalarMultiply(-sf1, v[or]));
|
||||
}
|
||||
}
|
||||
ColumnVector<T> res = new ColumnVector<T>(s);
|
||||
for (int r2 = s - 1; r2 >= 0; r2--) {
|
||||
var v2 = v[refl[r2]];
|
||||
for (int c2 = r2 + 1; c2 < s; c2++)
|
||||
v2 = o.Add(v2, o.ScalarMultiply(-buffer[refl[r2], c2], res[refl[c2]]));
|
||||
res[refl[r2]] = v2;
|
||||
v2 = o.Add(v2, o.ScalarMultiply(-buffer[refl[r2], c2], result[refl[c2]]));
|
||||
result[refl[r2]] = v2;
|
||||
}
|
||||
}
|
||||
unsafe void FillBuffer() {
|
||||
fixed (void* ptrc = content, ptrb = buffer) {
|
||||
Unsafe.CopyBlock(ptrb, ptrc, (uint)(Size * Size * sizeof(float)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a square matrix and fills it with polynomial coefficients.
|
||||
|
@@ -1,7 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Indicates that the attributed member is an element list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.Generic.IPairList" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class ElementListAttribute : Attribute { }
|
||||
public class ComponentListAttribute : Attribute { }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the attributed member is a property list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>A property list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.Generic.IPairList" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class PropertyListAttribute : Attribute { }
|
||||
}
|
||||
|
@@ -186,7 +186,7 @@ namespace Cryville.Common.Pdt {
|
||||
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
|
||||
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
|
||||
fixed (byte* pmem = _mem) {
|
||||
op.Begin(this);
|
||||
op.Begin(this, pc);
|
||||
for (int i = 0; i < pc; i++) {
|
||||
var frame = _stack[--_framecount];
|
||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||
|
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Whether the value of this expression is constant.
|
||||
/// </summary>
|
||||
/// <remarks>The value of this property is <c>false</c> until it is optimized.</remarks>
|
||||
/// <remarks>The value of this property is <see langword="false" /> until it is optimized.</remarks>
|
||||
public bool IsConstant { get; internal set; }
|
||||
internal bool IsPotentialConstant;
|
||||
internal PdtExpression(LinkedList<PdtInstruction> ins) {
|
||||
@@ -91,8 +91,8 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
}
|
||||
public partial class PdtInterpreter<T> {
|
||||
readonly static Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
|
||||
public partial class PdtInterpreter {
|
||||
static readonly Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
|
||||
{ '@', 7 },
|
||||
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
||||
{ '+', 5 }, { '-', 5 },
|
||||
@@ -103,7 +103,7 @@ namespace Cryville.Common.Pdt {
|
||||
{ ',', 0 },
|
||||
{ '$', -1 },
|
||||
};
|
||||
readonly static Dictionary<char, int> OP_TYPE = new Dictionary<char, int> {
|
||||
static readonly Dictionary<char, int> OP_TYPE = new Dictionary<char, int> {
|
||||
{ '@', 0 },
|
||||
{ '*', 0 }, { '/', 0 }, { '%', 0 },
|
||||
{ '+', 0 }, { '-', 0 },
|
||||
@@ -115,7 +115,7 @@ namespace Cryville.Common.Pdt {
|
||||
{ '$', -1 },
|
||||
};
|
||||
|
||||
readonly static PdtExpression _emptyexp;
|
||||
static readonly PdtExpression _emptyexp;
|
||||
static PdtInterpreter() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
ins.AddLast(new PdtInstruction.PushConstant(
|
||||
@@ -143,7 +143,7 @@ namespace Cryville.Common.Pdt {
|
||||
public override string ToString() {
|
||||
return string.Format("0x{0:x4}: {1}", Type, Value);
|
||||
}
|
||||
public readonly static PdtExpToken EmptyOperator = new PdtExpToken {
|
||||
public static readonly PdtExpToken EmptyOperator = new PdtExpToken {
|
||||
Type = 0x0080,
|
||||
Value = "$",
|
||||
};
|
||||
|
@@ -6,30 +6,30 @@
|
||||
/// <summary>
|
||||
/// Error type.
|
||||
/// </summary>
|
||||
public readonly static int Error = 0x00525245;
|
||||
public const int Error = 0x00525245;
|
||||
/// <summary>
|
||||
/// Array of a same variable-length type, with a suffix indicating the element count and the element type.
|
||||
/// </summary>
|
||||
public readonly static int Array = 0x00525241;
|
||||
public const int Array = 0x00525241;
|
||||
/// <summary>
|
||||
/// Null type.
|
||||
/// </summary>
|
||||
public readonly static int Null = 0x4c4c554e;
|
||||
public const int Null = 0x4c4c554e;
|
||||
/// <summary>
|
||||
/// IEEE 754 32-bit floating-point number.
|
||||
/// </summary>
|
||||
public readonly static int Number = 0x004d554e;
|
||||
public const int Number = 0x004d554e;
|
||||
/// <summary>
|
||||
/// A sequence of UTF-16 code units, with a prefix indicating the number of the code units.
|
||||
/// </summary>
|
||||
public readonly static int String = 0x00525453;
|
||||
public const int String = 0x00525453;
|
||||
/// <summary>
|
||||
/// A sequence of UTF-16 code units, with a prefix indicating the number of the code units, representing the name of an undefined variable.
|
||||
/// </summary>
|
||||
public readonly static int Undefined = 0x00444e55;
|
||||
public const int Undefined = 0x00444e55;
|
||||
/// <summary>
|
||||
/// Vector of a same constant-length type, with a suffix indicating the element type.
|
||||
/// </summary>
|
||||
public readonly static int Vector = 0x00434556;
|
||||
public const int Vector = 0x00434556;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using Cryville.Common.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -8,8 +10,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Interpreter for Property Definition Tree (PDT) file format.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The object type represented by the PDT.</typeparam>
|
||||
public partial class PdtInterpreter<T> {
|
||||
public partial class PdtInterpreter {
|
||||
/// <summary>
|
||||
/// The character category map.
|
||||
/// </summary>
|
||||
@@ -27,16 +28,16 @@ namespace Cryville.Common.Pdt {
|
||||
/// <item><term><c>0x1000</c></term><description>End of Key</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
readonly static int[] cm = new int[] {
|
||||
static readonly int[] cm = new int[] {
|
||||
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
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,
|
||||
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, 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, 0x0080, 0x0000, 0x0080, 0x0030,
|
||||
0x0000, 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, 0x1000, 0x0080, 0x1000, 0x0000, 0x0000,
|
||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0080, 0x0000,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -44,52 +45,102 @@ namespace Cryville.Common.Pdt {
|
||||
/// </summary>
|
||||
/// <param name="src">The source string.</param>
|
||||
/// <returns>The interpreted object.</returns>
|
||||
public static T Interpret(string src) {
|
||||
return Interpret(src, BinderAttribute.CreateBinderOfType(typeof(T)));
|
||||
public static T Interpret<T>(string src) {
|
||||
return Interpret<T>(src, BinderAttribute.CreateBinderOfType(typeof(T)));
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets a source string to an object of type <typeparamref name="T" /> with a binder.
|
||||
/// Interprets a source string to an object of type <typeparamref name="T"/> with a binder.
|
||||
/// </summary>
|
||||
/// <param name="src">The source string.</param>
|
||||
/// <param name="binder">The binder.</param>
|
||||
/// <returns>The interpreted object.</returns>
|
||||
public static T Interpret(string src, Binder binder) {
|
||||
return new PdtInterpreter<T>(src, binder).Interpret();
|
||||
public static T Interpret<T>(string src, Binder binder) {
|
||||
return (T)new PdtInterpreter(src, binder).Interpret(typeof(T));
|
||||
}
|
||||
|
||||
readonly string _src;
|
||||
readonly Binder _binder;
|
||||
protected int Position { get; private set; }
|
||||
/// <summary>
|
||||
/// The source string.
|
||||
/// </summary>
|
||||
public string Source { get; private set; }
|
||||
Binder _binder;
|
||||
/// <summary>
|
||||
/// The current position in the string being parsed by the interpreter.
|
||||
/// </summary>
|
||||
public int Position { get; private set; }
|
||||
#pragma warning disable IDE1006
|
||||
protected char cc { get { return _src[Position]; } }
|
||||
/// <summary>
|
||||
/// The character at the current position.
|
||||
/// </summary>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected char cc { get { return Source[Position]; } }
|
||||
/// <summary>
|
||||
/// The category of the character.
|
||||
/// </summary>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected int ct { get { return cm[cc]; } }
|
||||
protected string tokenb(int flag) { // Token Whitelist
|
||||
/// <summary>
|
||||
/// Reads a token until a character of type <paramref name="flag" /> is met.
|
||||
/// </summary>
|
||||
/// <param name="flag">The type filter.</param>
|
||||
/// <returns>A token from the current position (inclusive) to the next character of type <paramref name="flag" /> (exclusive).</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">No character of type <paramref name="flag" /> is met.</exception>
|
||||
protected string tokenb(int flag) {
|
||||
int sp = Position;
|
||||
while ((ct & flag) == 0) Position++;
|
||||
return _src.Substring(sp, Position - sp);
|
||||
return Source.Substring(sp, Position - sp);
|
||||
}
|
||||
protected string tokenw(int flag) { // Token Whitelist
|
||||
/// <summary>
|
||||
/// Reads a token until a character that is not of type <paramref name="flag" /> is met.
|
||||
/// </summary>
|
||||
/// <param name="flag">The type filter.</param>
|
||||
/// <returns>A token from the current position (inclusive) to the next character that is not of type <paramref name="flag" /> (exclusive).</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">No character that is not of type <paramref name="flag" /> is met.</exception>
|
||||
protected string tokenw(int flag) {
|
||||
int sp = Position;
|
||||
while ((ct & flag) != 0) Position++;
|
||||
return _src.Substring(sp, Position - sp);
|
||||
return Source.Substring(sp, Position - sp);
|
||||
}
|
||||
/// <summary>
|
||||
/// Skips over whitespaces.
|
||||
/// </summary>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected void ws() {
|
||||
while ((ct & 0x0001) != 0) Position++;
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current character and increments the position.
|
||||
/// </summary>
|
||||
/// <returns>The current character.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected char GetChar() {
|
||||
char r = cc;
|
||||
Position++;
|
||||
return r;
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads an identifier.
|
||||
/// </summary>
|
||||
/// <returns>An identifier.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected string GetIdentifier() {
|
||||
if ((ct & 0x0020) == 0) return "";
|
||||
return tokenw(0x0010);
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads a number.
|
||||
/// </summary>
|
||||
/// <returns>A number.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected string GetNumber() {
|
||||
return tokenw(0x0040);
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads a string.
|
||||
/// </summary>
|
||||
/// <returns>A string.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected string GetString() {
|
||||
int sp = Position;
|
||||
do {
|
||||
@@ -97,8 +148,13 @@ namespace Cryville.Common.Pdt {
|
||||
Position++;
|
||||
} while (ct != 0x0100);
|
||||
Position++;
|
||||
return Regex.Replace(_src.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
||||
return Regex.Replace(Source.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads an expression.
|
||||
/// </summary>
|
||||
/// <returns>An expression.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected PdtExpression GetExp() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
int _;
|
||||
@@ -108,23 +164,34 @@ namespace Cryville.Common.Pdt {
|
||||
|
||||
readonly Dictionary<string, PdtExpression> defs = new Dictionary<string, PdtExpression>();
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="PdtInterpreter{T}" /> class.
|
||||
/// Creates an instance of the <see cref="PdtInterpreter" /> class.
|
||||
/// </summary>
|
||||
/// <param name="src">The source string.</param>
|
||||
/// <param name="binder">The binder. May be <c>null</c>.</param>
|
||||
public PdtInterpreter(string src, Binder binder) {
|
||||
_src = src;
|
||||
Source = src;
|
||||
_binder = binder;
|
||||
if (_binder == null)
|
||||
_binder = BinderAttribute.CreateBinderOfType(typeof(T));
|
||||
}
|
||||
int[] m_formatVersion;
|
||||
public int[] GetFormatVersion() {
|
||||
if (m_formatVersion == null) InterpretDirectives();
|
||||
return m_formatVersion;
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets the source to an object of type <typeparamref name="T" />.
|
||||
/// Interprets the source to an object.
|
||||
/// </summary>
|
||||
/// <param name="type">The output type.</param>
|
||||
/// <returns>The interpreted object.</returns>
|
||||
public T Interpret() {
|
||||
InterpretDirectives();
|
||||
return (T)InterpretObject(typeof(T));
|
||||
public object Interpret(Type type) {
|
||||
try {
|
||||
if (m_formatVersion == null) InterpretDirectives();
|
||||
if (_binder == null)
|
||||
_binder = BinderAttribute.CreateBinderOfType(type);
|
||||
return InterpretObject(type);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new PdtParsingException(this, ex);
|
||||
}
|
||||
}
|
||||
void InterpretDirectives() {
|
||||
bool flag = false;
|
||||
@@ -138,7 +205,10 @@ namespace Cryville.Common.Pdt {
|
||||
break;
|
||||
case "format":
|
||||
ws();
|
||||
if (GetNumber() != "1")
|
||||
m_formatVersion = (from i in GetNumber().Split('.') select int.Parse(i)).ToArray();
|
||||
if (m_formatVersion.Length == 0)
|
||||
throw new FormatException("Invalid format version");
|
||||
if (m_formatVersion[0] != 1)
|
||||
throw new NotSupportedException("Format not supported");
|
||||
flag = true;
|
||||
break;
|
||||
@@ -159,10 +229,14 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
object InterpretObject(Type type) {
|
||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
bool dictflag = ReflectionHelper.IsGenericDictionary(type);
|
||||
bool dictflag = typeof(IDictionary).IsAssignableFrom(type);
|
||||
while (true) {
|
||||
try { ws(); }
|
||||
catch (IndexOutOfRangeException) { return result; }
|
||||
if (cc == '}') {
|
||||
GetChar();
|
||||
return result;
|
||||
}
|
||||
object pkey = InterpretKey(type);
|
||||
char c = GetChar();
|
||||
switch (c) {
|
||||
@@ -175,19 +249,20 @@ namespace Cryville.Common.Pdt {
|
||||
((IDictionary)result).Add(key, value);
|
||||
}
|
||||
else {
|
||||
MemberInfo prop;
|
||||
bool flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
||||
if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||
MemberInfo prop = null;
|
||||
bool flag = false;
|
||||
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
Type ptype = ReflectionHelper.GetMemberType(prop);
|
||||
if (ReflectionHelper.IsGenericDictionary(ptype)) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
if (flag) {
|
||||
if (flag) {
|
||||
using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = InterpretObject(vtype);
|
||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||
collection.Add(key, value);
|
||||
}
|
||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
||||
}
|
||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
||||
}
|
||||
@@ -203,30 +278,70 @@ namespace Cryville.Common.Pdt {
|
||||
((IDictionary)result).Add(key, value);
|
||||
}
|
||||
else {
|
||||
MemberInfo prop;
|
||||
bool flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
||||
if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||
MemberInfo prop = null;
|
||||
bool flag = false;
|
||||
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
var ptype = ReflectionHelper.GetMemberType(prop);
|
||||
if (!typeof(IDictionary).IsAssignableFrom(ptype)) {
|
||||
if (flag) {
|
||||
using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = _binder.ChangeType(exp, vtype, null);
|
||||
collection.Add(key, value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
object value = _binder.ChangeType(exp, ptype, null);
|
||||
ReflectionHelper.SetValue(prop, result, value, _binder);
|
||||
}
|
||||
else {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = _binder.ChangeType(exp, vtype, null);
|
||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
return result;
|
||||
default:
|
||||
throw new InvalidOperationException("Internal error: Invalid key interpretation");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets a key from the current position.
|
||||
/// </summary>
|
||||
/// <returns>The interpreted key.</returns>
|
||||
protected virtual object InterpretKey(Type type) {
|
||||
return tokenb(0x1000).Trim();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The exception that is thrown when the interpretation of a PDT fails.
|
||||
/// </summary>
|
||||
public class PdtParsingException : Exception {
|
||||
public PdtParsingException(PdtInterpreter interpreter) : this(interpreter, null) { }
|
||||
public PdtParsingException(PdtInterpreter interpreter, Exception innerException)
|
||||
: base(GenerateMessage(interpreter, innerException), innerException) { }
|
||||
static string GenerateMessage(PdtInterpreter interpreter, Exception innerException) {
|
||||
string src = interpreter.Source;
|
||||
int pos = interpreter.Position;
|
||||
if (pos >= src.Length) return "Failed to interpret the PDT: There are some missing or redundant tokens";
|
||||
int lineStartPos = src.LastIndexOf('\n', pos) + 1;
|
||||
int previewStartPos = src.LastIndexOf('\n', pos, 64);
|
||||
if (previewStartPos == -1) {
|
||||
previewStartPos = pos - 64;
|
||||
if (previewStartPos < 0) previewStartPos = 0;
|
||||
}
|
||||
else previewStartPos++;
|
||||
int previewEndPos = src.IndexOf('\n', pos, 64);
|
||||
if (previewEndPos == -1) {
|
||||
previewEndPos = pos + 64;
|
||||
if (previewEndPos > src.Length) previewEndPos = src.Length;
|
||||
}
|
||||
return string.Format(
|
||||
"Failed to interpret the PDT at line {0}, position {1}: {2}\n{3}",
|
||||
src.Take(interpreter.Position).Count(c => c == '\n') + 1,
|
||||
pos - lineStartPos + 1,
|
||||
innerException == null ? "Unknown error" : innerException.Message,
|
||||
src.Substring(previewStartPos, previewEndPos - previewStartPos)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,14 +4,14 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// PDT operator.
|
||||
/// </summary>
|
||||
public unsafe abstract class PdtOperator {
|
||||
public abstract unsafe class PdtOperator {
|
||||
byte* _prmem;
|
||||
int _loadindex;
|
||||
readonly PdtVariableMemory[] _operands;
|
||||
/// <summary>
|
||||
/// The count of the operands loaded.
|
||||
/// </summary>
|
||||
protected int LoadedOperandCount { get { return ParamCount - _loadindex; } }
|
||||
protected int LoadedOperandCount { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets the operand at the specified index.
|
||||
/// </summary>
|
||||
@@ -24,24 +24,24 @@ namespace Cryville.Common.Pdt {
|
||||
int i = index + _loadindex;
|
||||
return _operands[i];
|
||||
}
|
||||
internal int ParamCount { get; private set; }
|
||||
readonly int _pc;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="PdtOperator" /> class.
|
||||
/// </summary>
|
||||
/// <param name="pc">The suggested parameter count.</param>
|
||||
protected PdtOperator(int pc) {
|
||||
ParamCount = pc;
|
||||
_pc = pc;
|
||||
_operands = new PdtVariableMemory[pc];
|
||||
}
|
||||
PdtEvaluatorBase _etor;
|
||||
bool _rfreq = true;
|
||||
internal void Begin(PdtEvaluatorBase etor) {
|
||||
internal void Begin(PdtEvaluatorBase etor, int pc) {
|
||||
_etor = etor;
|
||||
_loadindex = ParamCount;
|
||||
_loadindex = LoadedOperandCount = pc;
|
||||
}
|
||||
internal void LoadOperand(PdtVariableMemory mem) {
|
||||
if (_loadindex == 0) return;
|
||||
_operands[--_loadindex] = mem;
|
||||
if (--_loadindex >= _pc) return;
|
||||
_operands[_loadindex] = mem;
|
||||
}
|
||||
internal void Call(byte* prmem, bool noset) {
|
||||
_prmem = prmem;
|
||||
@@ -55,6 +55,9 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Executes the operator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>When overridden, this method reads operands by calling <see cref="GetOperand(int)" />, and writes the result to the frame obtained by calling <see cref="GetReturnFrame(int, int)" />.</para>
|
||||
/// </remarks>
|
||||
protected abstract void Execute();
|
||||
/// <summary>
|
||||
/// Gets a return frame.
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
@@ -42,7 +43,9 @@ namespace Cryville.Common.Pdt {
|
||||
/// <param name="dest">The destination buffer.</param>
|
||||
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
||||
/// <param name="length">The length to copy.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is greater than the length of the span.</exception>
|
||||
public void CopyTo(byte* dest, int destOffset, int length) {
|
||||
if (length > Length) throw new ArgumentOutOfRangeException("length");
|
||||
for (int i = 0; i < length; i++)
|
||||
dest[destOffset + i] = _ptr[i];
|
||||
}
|
||||
@@ -126,10 +129,43 @@ namespace Cryville.Common.Pdt {
|
||||
throw new InvalidCastException("Not an identifier");
|
||||
return *(int*)(_ptr + offset);
|
||||
}
|
||||
internal void* TrustedAsOfLength(int len) {
|
||||
if (Length < len)
|
||||
throw new InvalidCastException("Type not matched");
|
||||
return _ptr;
|
||||
/// <summary>
|
||||
/// Gets the memory of the span as an instance of the specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The specified type.</typeparam>
|
||||
/// <param name="offset">The offset on the span to start reading from.</param>
|
||||
/// <returns>An instance of the specified type.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="offset" /> is not less than the length of the span.</exception>
|
||||
/// <exception cref="InvalidCastException">The length of the span is not sufficient.</exception>
|
||||
/// <remarks>
|
||||
/// <para>Use <see cref="AsNumber(int)" /> instead while reading an unaligned number.</para>
|
||||
/// </remarks>
|
||||
public T As<T>(int offset = 0) {
|
||||
var len = Unsafe.SizeOf<T>();
|
||||
if (offset >= Length)
|
||||
throw new ArgumentOutOfRangeException("offset");
|
||||
if (offset + len > Length)
|
||||
throw new InvalidCastException("Frame length not sufficient");
|
||||
return Unsafe.Read<T>(_ptr + offset);
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the memory of the span to an instance of the specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The specified type.</typeparam>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="offset">The offset from the start of the span.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="offset" /> is not less than the length of the span.</exception>
|
||||
/// <exception cref="InvalidCastException">The length of the span is not sufficient.</exception>
|
||||
/// <remarks>
|
||||
/// <para>Use <see cref="SetNumber(float, int)" /> instead while writing an unaligned number.</para>
|
||||
/// </remarks>
|
||||
public void Set<T>(T value, int offset = 0) {
|
||||
var len = Unsafe.SizeOf<T>();
|
||||
if (offset >= Length)
|
||||
throw new ArgumentOutOfRangeException("offset");
|
||||
if (offset + len > Length)
|
||||
throw new InvalidCastException("Frame length not sufficient");
|
||||
Unsafe.Write(_ptr + offset, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the array suffix.
|
||||
|
@@ -31,6 +31,8 @@ namespace Cryville.Common.Unity.Input {
|
||||
public WindowsPointerHandler() {
|
||||
if (Instance != null)
|
||||
throw new InvalidOperationException("WindowsPointerHandler already created");
|
||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
|
||||
throw new NotSupportedException("Windows pointer is not supported on this device");
|
||||
Instance = this;
|
||||
usePointerMessage = true;
|
||||
|
||||
@@ -142,9 +144,11 @@ namespace Cryville.Common.Unity.Input {
|
||||
}
|
||||
|
||||
public override void Dispose(bool disposing) {
|
||||
Deactivate();
|
||||
if (usePointerMessage)
|
||||
NativeMethods.EnableMouseInPointer(false);
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
if (usePointerMessage)
|
||||
NativeMethods.EnableMouseInPointer(false);
|
||||
}
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
public class SetIntegerParameterBehaviour : SetParameterBehaviour {
|
||||
[SerializeField] int m_value;
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
|
||||
animator.SetInteger(m_name, m_value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57079cdf55a0d1149903f00ee732fa85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Cryville/Common/Unity/UI/SetParameterBehaviour.cs
Normal file
8
Assets/Cryville/Common/Unity/UI/SetParameterBehaviour.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
public abstract class SetParameterBehaviour : StateMachineBehaviour {
|
||||
[SerializeField] protected string m_name;
|
||||
public abstract override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d48088ca586ef5a41a42f6564e35b230
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
66
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
Normal file
66
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Cryville.Common.Font;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
using UnityEngine.TextCore.Text;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
[RequireComponent(typeof(TextMeshProUGUI))]
|
||||
public class TMPAutoFont : MonoBehaviour {
|
||||
public static Shader DefaultShader;
|
||||
public static FontMatcher FontMatcher;
|
||||
public static int MaxFallbackCount = 4;
|
||||
static FontAsset _font;
|
||||
TextMeshProUGUI _text;
|
||||
|
||||
[SerializeField]
|
||||
Shader m_shader;
|
||||
void Awake() {
|
||||
if (FontMatcher == null) return;
|
||||
_text = GetComponent<TextMeshProUGUI>();
|
||||
if (_font == null) {
|
||||
foreach (var typeface in FontMatcher.MatchScript(null, true)) {
|
||||
try {
|
||||
var ifont = CreateFontAsset(typeface.File.FullName, typeface.IndexInFile);
|
||||
if (m_shader) ifont.material.shader = m_shader;
|
||||
else if (DefaultShader) ifont.material.shader = DefaultShader;
|
||||
if (_font == null) {
|
||||
_font = ifont;
|
||||
if (MaxFallbackCount <= 0) break;
|
||||
}
|
||||
else {
|
||||
if (_font.fallbackFontAssetTable == null)
|
||||
_font.fallbackFontAssetTable = new List<FontAsset>();
|
||||
_font.fallbackFontAssetTable.Add(ifont);
|
||||
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
_text.font = _font;
|
||||
}
|
||||
|
||||
static MethodInfo _methodCreateFontAsset;
|
||||
static readonly object[] _paramsCreateFontAsset = new object[] { null, null, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, Type.Missing, Type.Missing };
|
||||
static FontAsset CreateFontAsset(string path, int index) {
|
||||
if (_methodCreateFontAsset == null) {
|
||||
_methodCreateFontAsset = typeof(FontAsset).GetMethod(
|
||||
"CreateFontAsset", BindingFlags.Static | BindingFlags.NonPublic, null,
|
||||
new Type[] {
|
||||
typeof(string), typeof(int), typeof(int), typeof(int),
|
||||
typeof(GlyphRenderMode), typeof(int), typeof(int),
|
||||
typeof(AtlasPopulationMode), typeof(bool)
|
||||
},
|
||||
null
|
||||
);
|
||||
}
|
||||
_paramsCreateFontAsset[0] = path;
|
||||
_paramsCreateFontAsset[1] = index;
|
||||
return (FontAsset)_methodCreateFontAsset.Invoke(null, _paramsCreateFontAsset);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57404eb6519ecae44b051485280e879f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -120
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -7,10 +7,10 @@ namespace Cryville.Crtr {
|
||||
public Transform Transform { get; private set; }
|
||||
public SkinContext SkinContext { get; private set; }
|
||||
public Dictionary<int, PropSrc> PropSrcs { get; private set; }
|
||||
public Anchor(int name, Transform transform, bool hasProps = false) {
|
||||
public Anchor(int name, Transform transform, int propSrcCount = 0) {
|
||||
Name = name;
|
||||
Transform = transform;
|
||||
if (hasProps) PropSrcs = new Dictionary<int, PropSrc>();
|
||||
if (propSrcCount > 0) PropSrcs = new Dictionary<int, PropSrc>(propSrcCount);
|
||||
SkinContext = new SkinContext(transform, PropSrcs);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
@@ -10,14 +11,14 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
private bool _dir;
|
||||
private Image _icon;
|
||||
private Text _title;
|
||||
private Text _desc;
|
||||
private TMP_Text _title;
|
||||
private TMP_Text _desc;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_icon = transform.Find("__content__/Icon").GetComponent<Image>();
|
||||
_title = transform.Find("__content__/Texts/Title/__text__").GetComponent<Text>();
|
||||
_desc = transform.Find("__content__/Texts/Description/__text__").GetComponent<Text>();
|
||||
_title = transform.Find("__content__/Texts/Title/__text__").GetComponent<TMP_Text>();
|
||||
_desc = transform.Find("__content__/Texts/Description/__text__").GetComponent<TMP_Text>();
|
||||
}
|
||||
void OnDestroy() {
|
||||
if (meta.Icon != null) meta.Icon.Cancel();
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -18,8 +19,8 @@ namespace Cryville.Crtr.Browsing {
|
||||
DockOccupiedRatioLayoutGroup _outerContentGroup;
|
||||
Transform _content;
|
||||
Image _cover;
|
||||
Text _title;
|
||||
Text _desc;
|
||||
TMP_Text _title;
|
||||
TMP_Text _desc;
|
||||
|
||||
protected override void Awake() {
|
||||
base.Awake();
|
||||
@@ -28,8 +29,8 @@ namespace Cryville.Crtr.Browsing {
|
||||
_outerContentGroup = _outerContent.GetComponent<DockOccupiedRatioLayoutGroup>();
|
||||
_content = _outerContent.transform.Find("__content__");
|
||||
_cover = _content.Find("Cover").GetComponent<Image>();
|
||||
_title = _content.Find("Texts/Title").GetComponent<Text>();
|
||||
_desc = _content.Find("Texts/Description").GetComponent<Text>();
|
||||
_title = _content.Find("Texts/Title").GetComponent<TMP_Text>();
|
||||
_desc = _content.Find("Texts/Description").GetComponent<TMP_Text>();
|
||||
}
|
||||
void OnDestroy() {
|
||||
if (_data.Cover != null) _data.Cover.Cancel();
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class ExtensionInterface {
|
||||
|
@@ -9,11 +9,11 @@ namespace Cryville.Crtr.Browsing {
|
||||
public override object Value {
|
||||
get {
|
||||
float s_value = GetDisplayValue();
|
||||
return IntegerMode ? (object)(int)s_value : (object)s_value;
|
||||
return IntegerMode ? (int)s_value : (object)s_value;
|
||||
}
|
||||
set {
|
||||
if (value is double) m_value = (double)value;
|
||||
else m_value = IntegerMode ? (double)(int)value : (double)(float)value;
|
||||
else m_value = IntegerMode ? (int)value : (double)(float)value;
|
||||
float s_value = GetDisplayValue();
|
||||
m_text.text = s_value.ToString();
|
||||
if (Range != null && MaxStep == 0) {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using Cryville.Crtr.Config;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -12,11 +13,12 @@ namespace Cryville.Crtr.Browsing {
|
||||
private Button m_playButton;
|
||||
[SerializeField]
|
||||
private Button m_configButton;
|
||||
[SerializeField]
|
||||
private ConfigPanelMaster m_configPanel;
|
||||
|
||||
private DockLayoutGroup _group;
|
||||
public ResourceBrowser MainBrowser { get; private set; }
|
||||
private DetailPanel _detailPanel;
|
||||
private SettingsPanel _settingsPanel;
|
||||
readonly List<ResourceBrowserUnit> _units = new List<ResourceBrowserUnit>();
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
@@ -25,7 +27,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
MainBrowser = transform.GetChild(0).GetComponent<ResourceBrowser>();
|
||||
MainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
|
||||
_detailPanel = transform.GetChild(1).GetComponent<DetailPanel>();
|
||||
_settingsPanel = transform.GetChild(2).GetComponent<SettingsPanel>();
|
||||
_units.Add(MainBrowser);
|
||||
_units.Add(_detailPanel);
|
||||
}
|
||||
@@ -80,12 +81,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
public void OpenConfig(int id, ChartDetail detail) {
|
||||
SetDataSettings(id, detail);
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
SceneManager.LoadScene("Config", LoadSceneMode.Additive);
|
||||
#else
|
||||
Application.LoadLevelAdditive("Config");
|
||||
#endif
|
||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||
}
|
||||
|
||||
void SetDataSettings(int id, ChartDetail detail) {
|
||||
|
@@ -6,6 +6,7 @@ using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
[JsonConverter(typeof(BeatTimeConverter))]
|
||||
@@ -109,10 +110,11 @@ namespace Cryville.Crtr {
|
||||
public float BeatOffset;
|
||||
|
||||
[JsonIgnore]
|
||||
public abstract int Priority {
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract int Priority { get; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual bool Standalone { get { return false; } }
|
||||
|
||||
public ChartEvent Clone() {
|
||||
return (ChartEvent)MemberwiseClone();
|
||||
}
|
||||
@@ -130,11 +132,11 @@ namespace Cryville.Crtr {
|
||||
get { return Duration > 0; }
|
||||
}
|
||||
|
||||
private InstantEvent relev = null;
|
||||
private ReleaseEvent relev = null;
|
||||
[JsonIgnore]
|
||||
public InstantEvent ReleaseEvent {
|
||||
public ReleaseEvent ReleaseEvent {
|
||||
get {
|
||||
if (relev == null) relev = new InstantEvent(this, true);
|
||||
if (relev == null) relev = new ReleaseEvent(this);
|
||||
return relev;
|
||||
}
|
||||
}
|
||||
@@ -153,6 +155,10 @@ namespace Cryville.Crtr {
|
||||
protected ChartEvent() {
|
||||
PropSrcs = new Dictionary<int, PropSrc>();
|
||||
PropOps = new Dictionary<int, PropOp>();
|
||||
SubmitPropSrc("event", new PropSrc.Float(() => {
|
||||
int hash = GetHashCode();
|
||||
return Unsafe.As<int, float>(ref hash);
|
||||
}));
|
||||
SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong));
|
||||
SubmitPropSrc("time", new PropSrc.BeatTime(() => time.Value));
|
||||
SubmitPropSrc("endtime", new PropSrc.BeatTime(() => endtime.Value));
|
||||
@@ -161,18 +167,12 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public class InstantEvent : ChartEvent {
|
||||
public class ReleaseEvent : ChartEvent {
|
||||
public readonly ChartEvent Original;
|
||||
public bool IsRelease;
|
||||
|
||||
public InstantEvent(ChartEvent orig, bool release = false) {
|
||||
IsRelease = release;
|
||||
if (orig != null) {
|
||||
Original = orig;
|
||||
time = orig.time;
|
||||
if (IsRelease)
|
||||
BeatOffset = orig.Duration;
|
||||
}
|
||||
public ReleaseEvent(ChartEvent orig) {
|
||||
Original = orig;
|
||||
time = orig.endtime;
|
||||
}
|
||||
|
||||
public override int Priority {
|
||||
@@ -183,6 +183,13 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public abstract class EventContainer : ChartEvent {
|
||||
public List<Chart.Motion> motions = new List<Chart.Motion>();
|
||||
|
||||
[JsonIgnore]
|
||||
public Clip Clip { get; private set; }
|
||||
|
||||
public EventContainer() {
|
||||
SubmitPropOp("clip", new PropOp.Clip(v => Clip = v));
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual IEnumerable<ChartEvent> Events {
|
||||
@@ -194,7 +201,7 @@ namespace Cryville.Crtr {
|
||||
public virtual EventList GetEventsOfType(string type) {
|
||||
switch (type) {
|
||||
case "motions": return new EventList<Chart.Motion>(motions);
|
||||
default: throw new ArgumentException(string.Format("Unknown event type {0}", type));
|
||||
default: throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,9 +265,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public override int Priority {
|
||||
get { return 10; }
|
||||
}
|
||||
public override int Priority { get { return 10; } }
|
||||
|
||||
public class Group : EventContainer {
|
||||
public List<Track> tracks = new List<Track>();
|
||||
@@ -280,15 +285,11 @@ namespace Cryville.Crtr {
|
||||
default: return base.GetEventsOfType(type);
|
||||
}
|
||||
}
|
||||
public override int Priority {
|
||||
get { return 10; }
|
||||
}
|
||||
public override int Priority { get { return 10; } }
|
||||
}
|
||||
|
||||
public class Track : EventContainer {
|
||||
public override int Priority {
|
||||
get { return 10; }
|
||||
}
|
||||
public override int Priority { get { return 10; } }
|
||||
}
|
||||
|
||||
public class Motion : ChartEvent {
|
||||
@@ -324,7 +325,7 @@ namespace Cryville.Crtr {
|
||||
else {
|
||||
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
||||
}
|
||||
SubmitPropSrc("value", VectorSrc.Construct(() => {
|
||||
SubmitPropSrc("value", new VectorSrc(() => {
|
||||
if (RelativeNode != null) return RelativeNode.Value;
|
||||
else return AbsoluteValue;
|
||||
}));
|
||||
@@ -374,9 +375,7 @@ namespace Cryville.Crtr {
|
||||
[DefaultValue(0.0f)]
|
||||
public float sumfix = 0.0f;
|
||||
|
||||
public override int Priority {
|
||||
get { return -2; }
|
||||
}
|
||||
public override int Priority { get { return -2; } }
|
||||
|
||||
public Motion() {
|
||||
SubmitPropOp("motion", new PropOp.String(v => motion = v));
|
||||
@@ -412,9 +411,7 @@ namespace Cryville.Crtr {
|
||||
default: return base.GetEventsOfType(type);
|
||||
}
|
||||
}
|
||||
public override int Priority {
|
||||
get { return 12; }
|
||||
}
|
||||
public override int Priority { get { return 12; } }
|
||||
}
|
||||
|
||||
public class Judge : ChartEvent {
|
||||
@@ -427,9 +424,8 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public override int Priority {
|
||||
get { return 0; }
|
||||
}
|
||||
public override int Priority { get { return 0; } }
|
||||
public override bool Standalone { get { return true; } }
|
||||
|
||||
public Judge() {
|
||||
SubmitPropSrc("name", new PropSrc.Identifier(() => Id.Key));
|
||||
@@ -443,9 +439,7 @@ namespace Cryville.Crtr {
|
||||
public class Signature : ChartEvent {
|
||||
public float? tempo;
|
||||
|
||||
public override int Priority {
|
||||
get { return -4; }
|
||||
}
|
||||
public override int Priority { get { return -4; } }
|
||||
}
|
||||
|
||||
public List<Sound> sounds;
|
||||
@@ -456,9 +450,7 @@ namespace Cryville.Crtr {
|
||||
// TODO [Obsolete]
|
||||
public float offset;
|
||||
|
||||
public override int Priority {
|
||||
get { return 0; }
|
||||
}
|
||||
public override int Priority { get { return 0; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,22 +14,12 @@ namespace Cryville.Crtr {
|
||||
chart = _chart;
|
||||
}
|
||||
|
||||
public override string TypeName {
|
||||
get {
|
||||
return "chart";
|
||||
}
|
||||
}
|
||||
public override string TypeName { get { return "chart"; } }
|
||||
|
||||
public override void PreInit() {
|
||||
base.PreInit();
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
if (Disposed) return;
|
||||
base.Dispose();
|
||||
foreach (var s in sounds) s.Dispose();
|
||||
}
|
||||
|
||||
public override void Update(ContainerState s, StampedEvent ev) {
|
||||
base.Update(s, ev);
|
||||
if (s.CloneType == 16) {
|
||||
@@ -50,9 +40,14 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public override void EndUpdate(ContainerState s) {
|
||||
base.EndUpdate(s);
|
||||
public override void EndLogicalUpdate(ContainerState s) {
|
||||
base.EndLogicalUpdate(s);
|
||||
// TODO End of chart
|
||||
}
|
||||
|
||||
public override void DisposeAll() {
|
||||
base.DisposeAll();
|
||||
foreach (var s in sounds) s.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#define BUILD
|
||||
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Crtr.Config;
|
||||
using Cryville.Crtr.Event;
|
||||
using Newtonsoft.Json;
|
||||
@@ -8,20 +9,22 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Formatting;
|
||||
using System.Threading;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Scripting;
|
||||
using UnityEngine.UI;
|
||||
using diag = System.Diagnostics;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class ChartPlayer : MonoBehaviour {
|
||||
#region Fields
|
||||
Chart chart;
|
||||
Skin skin;
|
||||
PdtSkin pskin;
|
||||
public static PdtSkin pskin;
|
||||
Ruleset ruleset;
|
||||
PdtRuleset pruleset;
|
||||
Dictionary<string, Texture2D> texs;
|
||||
@@ -39,12 +42,14 @@ namespace Cryville.Crtr {
|
||||
EventBus bbus;
|
||||
EventBus tbus;
|
||||
EventBus nbus;
|
||||
InputProxy inputProxy;
|
||||
Judge judge;
|
||||
public static EffectManager effectManager;
|
||||
bool started = false;
|
||||
|
||||
static bool initialized;
|
||||
static Text logs;
|
||||
Text status;
|
||||
TextMeshProUGUI logs;
|
||||
TextMeshProUGUI status;
|
||||
|
||||
static Vector2 screenSize;
|
||||
public static Rect hitRect;
|
||||
@@ -57,6 +62,7 @@ namespace Cryville.Crtr {
|
||||
static double renderStep = 0.05;
|
||||
public static double actualRenderStep = 0;
|
||||
static bool autoRenderStep = false;
|
||||
public static float graphicalOffset = 0;
|
||||
public static float soundOffset = 0;
|
||||
static float startOffset = 0;
|
||||
public static float sv = 16f;
|
||||
@@ -64,14 +70,15 @@ namespace Cryville.Crtr {
|
||||
public static Dictionary<Identifier, MotionRegistry> motionRegistry = new Dictionary<Identifier, MotionRegistry>();
|
||||
|
||||
public static PdtEvaluator etor;
|
||||
|
||||
InputProxy inputProxy;
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour
|
||||
void Start() {
|
||||
d_addLogEntry = new Action<int, string, string>(AddLogEntry);
|
||||
|
||||
var logobj = GameObject.Find("Logs");
|
||||
if (logobj != null)
|
||||
logs = logobj.GetComponent<Text>();
|
||||
logs = logobj.GetComponent<TextMeshProUGUI>();
|
||||
if (!initialized) {
|
||||
Game.Init();
|
||||
GenericResources.LoadDefault();
|
||||
@@ -79,7 +86,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
OnSettingsUpdate();
|
||||
|
||||
status = GameObject.Find("Status").GetComponent<Text>();
|
||||
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
|
||||
|
||||
texHandler = new DownloadHandlerTexture();
|
||||
#if BUILD
|
||||
@@ -105,7 +112,6 @@ namespace Cryville.Crtr {
|
||||
if (texLoader != null) texLoader.Dispose();
|
||||
if (inputProxy != null) inputProxy.Dispose();
|
||||
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
||||
Camera.onPostRender -= OnCameraPostRender;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
@@ -127,7 +133,7 @@ namespace Cryville.Crtr {
|
||||
if (forceSyncFrames != 0) {
|
||||
forceSyncFrames--;
|
||||
double target = Game.AudioClient.Position - atime0;
|
||||
dt = target - cbus.Time;
|
||||
dt = target - cbus.Time - graphicalOffset;
|
||||
step = autoRenderStep ? 1f / Application.targetFrameRate : renderStep;
|
||||
inputProxy.SyncTime(target);
|
||||
}
|
||||
@@ -136,6 +142,7 @@ namespace Cryville.Crtr {
|
||||
step = autoRenderStep ? Time.smoothDeltaTime : renderStep;
|
||||
}
|
||||
inputProxy.ForceTick();
|
||||
if (paused) return;
|
||||
cbus.ForwardByTime(dt);
|
||||
bbus.ForwardByTime(dt);
|
||||
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
||||
@@ -146,14 +153,16 @@ namespace Cryville.Crtr {
|
||||
actualRenderStep = step;
|
||||
|
||||
nbus.ForwardStepByTime(clippingDist, step);
|
||||
nbus.BroadcastEndUpdate();
|
||||
nbus.EndPreGraphicalUpdate();
|
||||
nbus.Anchor();
|
||||
|
||||
tbus.StripTempEvents();
|
||||
tbus.ForwardStepByTime(clippingDist, step);
|
||||
tbus.ForwardStepByTime(renderDist, step);
|
||||
tbus.BroadcastEndUpdate();
|
||||
tbus.EndGraphicalUpdate();
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
|
||||
effectManager.Tick(cbus.Time);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Game", "An error occured while playing", ex);
|
||||
@@ -166,10 +175,21 @@ namespace Cryville.Crtr {
|
||||
string url = texLoader.url;
|
||||
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
if (texHandler.isDone) {
|
||||
var tex = texHandler.texture;
|
||||
tex.wrapMode = TextureWrapMode.Clamp;
|
||||
texs.Add(name, tex);
|
||||
if (texLoader.isDone) {
|
||||
if (texHandler.isDone) {
|
||||
var tex = texHandler.texture;
|
||||
tex.wrapMode = TextureWrapMode.Clamp;
|
||||
if (frames.ContainsKey(name)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", name);
|
||||
}
|
||||
else {
|
||||
frames.Add(name, new SpriteFrame(tex));
|
||||
}
|
||||
texs.Add(name, tex);
|
||||
}
|
||||
else {
|
||||
Logger.Log("main", 4, "Load/Prehandle", "Unable to load texture: {0}", name);
|
||||
}
|
||||
texLoader.Dispose();
|
||||
texHandler.Dispose();
|
||||
texLoader = null;
|
||||
@@ -184,14 +204,14 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (texLoader == null)
|
||||
if (texLoader == null) {
|
||||
if (texLoadQueue.Count > 0) {
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
texHandler = new DownloadHandlerTexture();
|
||||
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + texLoadQueue.Dequeue(), "GET", texHandler, null);
|
||||
texLoader.SendWebRequest();
|
||||
#else
|
||||
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
||||
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
||||
#endif
|
||||
}
|
||||
else if (!texloaddone) {
|
||||
@@ -199,6 +219,7 @@ namespace Cryville.Crtr {
|
||||
texloadtimer.Stop();
|
||||
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
if (!loadThread.IsAlive) {
|
||||
if (threadException != null) {
|
||||
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
||||
@@ -214,56 +235,89 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
string timetext = string.Empty;
|
||||
void LogUpdate() {
|
||||
string _logs = logs.text;
|
||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
||||
string color;
|
||||
switch (level) {
|
||||
case 0: color = "#888888"; break;
|
||||
case 1: color = "#bbbbbb"; break;
|
||||
case 2: color = "#0088ff"; break;
|
||||
case 3: color = "#ffff00"; break;
|
||||
case 4: color = "#ff0000"; break;
|
||||
case 5: color = "#bb0000"; break;
|
||||
default: color = "#ff00ff"; break;
|
||||
}
|
||||
_logs += string.Format(
|
||||
"\r\n<color={1}bb><{2}> {3}</color>",
|
||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||
);
|
||||
});
|
||||
logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\n', Mathf.Max(0, _logs.Length - 4096))));
|
||||
var sttext = string.Format(
|
||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
||||
1 / Time.deltaTime,
|
||||
1 / Time.smoothDeltaTime,
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
||||
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
||||
#else
|
||||
UnityEngine.Profiling.Profiler.GetMonoUsedSize(),
|
||||
UnityEngine.Profiling.Profiler.GetMonoHeapSize(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemory(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
||||
#endif
|
||||
);
|
||||
sttext += timetext;
|
||||
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString();
|
||||
status.text = sttext;
|
||||
}
|
||||
void OnCameraPostRender(Camera cam) {
|
||||
if (!started) return;
|
||||
if (!logEnabled) return;
|
||||
timetext = string.Format(
|
||||
"\nSTime: {0:R}s {3}\ndATime: {1:+0.0ms;-0.0ms;0} {3}\ndITime: {2:+0.0ms;-0.0ms;0} {3}",
|
||||
cbus.Time,
|
||||
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
|
||||
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
|
||||
forceSyncFrames != 0 ? "(force sync)" : ""
|
||||
readonly TargetString statusstr = new TargetString();
|
||||
readonly StringBuffer statusbuf = new StringBuffer();
|
||||
readonly TargetString logsstr = new TargetString();
|
||||
readonly StringBuffer logsbuf = new StringBuffer();
|
||||
readonly List<string> logEntries = new List<string>();
|
||||
int logsLength = 0;
|
||||
Action<int, string, string> d_addLogEntry;
|
||||
void AddLogEntry(int level, string module, string msg) {
|
||||
string color;
|
||||
switch (level) {
|
||||
case 0: color = "#888888"; break;
|
||||
case 1: color = "#bbbbbb"; break;
|
||||
case 2: color = "#0088ff"; break;
|
||||
case 3: color = "#ffff00"; break;
|
||||
case 4: color = "#ff0000"; break;
|
||||
case 5: color = "#bb0000"; break;
|
||||
default: color = "#ff00ff"; break;
|
||||
}
|
||||
var l = string.Format(
|
||||
"\n<color={1}bb><{2}> {3}</color>",
|
||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||
);
|
||||
logEntries.Add(l);
|
||||
logsLength += l.Length;
|
||||
}
|
||||
void LogUpdate() {
|
||||
logsbuf.Clear();
|
||||
Game.MainLogger.Enumerate(d_addLogEntry);
|
||||
while (logsLength >= 4096) {
|
||||
logsLength -= logEntries[0].Length;
|
||||
logEntries.RemoveAt(0);
|
||||
}
|
||||
foreach (var l in logEntries) {
|
||||
logsbuf.Append(l);
|
||||
}
|
||||
logsstr.Length = logsbuf.Count;
|
||||
var larr = logsstr.TrustedAsArray();
|
||||
logsbuf.CopyTo(0, larr, 0, logsbuf.Count);
|
||||
logs.SetText(larr, 0, logsbuf.Count);
|
||||
|
||||
statusbuf.Clear();
|
||||
statusbuf.AppendFormat(
|
||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
||||
1 / Time.deltaTime,
|
||||
1 / Time.smoothDeltaTime,
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
||||
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
||||
#else
|
||||
UnityEngine.Profiling.Profiler.GetMonoUsedSize(),
|
||||
UnityEngine.Profiling.Profiler.GetMonoHeapSize(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemory(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
||||
#endif
|
||||
);
|
||||
if (started) {
|
||||
statusbuf.AppendFormat(
|
||||
"\nStates: c{0} / b{1}\nPools: RMV {2}, MC {3}",
|
||||
cbus.ActiveStateCount, bbus.ActiveStateCount,
|
||||
ContainerState.RMVPool.RentedCount,
|
||||
ContainerState.MCPool.RentedCount
|
||||
);
|
||||
statusbuf.AppendFormat(
|
||||
"\nSTime: {0:G17}s {3} {4}\ndATime: {1:+0.0ms;-0.0ms;0} {3} {4}\ndITime: {2:+0.0ms;-0.0ms;0} {3} {5}",
|
||||
cbus.Time,
|
||||
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
|
||||
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
|
||||
forceSyncFrames != 0 ? "(force sync)" : "",
|
||||
paused ? "(paused)" : "",
|
||||
paused ? "(semi-locked)" : ""
|
||||
);
|
||||
if (judge != null) {
|
||||
statusbuf.Append("\n== Scores ==\n");
|
||||
var fullScoreStr = judge.GetFullFormattedScoreString();
|
||||
statusbuf.Append(fullScoreStr.TrustedAsArray(), 0, fullScoreStr.Length);
|
||||
}
|
||||
}
|
||||
statusstr.Length = statusbuf.Count;
|
||||
var sarr = statusstr.TrustedAsArray();
|
||||
statusbuf.CopyTo(0, sarr, 0, statusbuf.Count);
|
||||
status.SetText(sarr, 0, statusbuf.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -293,8 +347,10 @@ namespace Cryville.Crtr {
|
||||
|
||||
bool logEnabled = true;
|
||||
public void ToggleLogs() {
|
||||
logEntries.Clear();
|
||||
logsLength = 0;
|
||||
logs.text = "";
|
||||
status.text = "";
|
||||
status.SetText("");
|
||||
logEnabled = !logEnabled;
|
||||
}
|
||||
|
||||
@@ -305,6 +361,20 @@ namespace Cryville.Crtr {
|
||||
else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading");
|
||||
}
|
||||
}
|
||||
|
||||
bool paused = false;
|
||||
public void TogglePause() {
|
||||
paused = !paused;
|
||||
if (!paused) {
|
||||
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||
Game.AudioClient.Start();
|
||||
inputProxy.UnlockTime();
|
||||
}
|
||||
else {
|
||||
Game.AudioClient.Pause();
|
||||
inputProxy.LockTime();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Load
|
||||
@@ -315,15 +385,14 @@ namespace Cryville.Crtr {
|
||||
renderStep = Settings.Default.RenderStep;
|
||||
actualRenderStep = renderStep;
|
||||
autoRenderStep = renderStep == 0;
|
||||
graphicalOffset = Settings.Default.GraphicalOffset;
|
||||
soundOffset = Settings.Default.SoundOffset;
|
||||
startOffset = Settings.Default.StartOffset;
|
||||
forceSyncFrames= Settings.Default.ForceSyncFrames;
|
||||
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||
texloaddone = false;
|
||||
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||
|
||||
Camera.onPostRender += OnCameraPostRender;
|
||||
|
||||
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
||||
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
||||
float dist;
|
||||
@@ -356,6 +425,7 @@ namespace Cryville.Crtr {
|
||||
});
|
||||
}
|
||||
sv = _rscfg.generic.ScrollVelocity;
|
||||
soundOffset += _rscfg.generic.SoundOffset;
|
||||
|
||||
FileInfo skinFile = new FileInfo(
|
||||
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
|
||||
@@ -390,16 +460,6 @@ namespace Cryville.Crtr {
|
||||
try {
|
||||
diag::Stopwatch timer = new diag::Stopwatch();
|
||||
timer.Reset(); timer.Start();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Initializing textures");
|
||||
foreach (var t in texs) {
|
||||
if (frames.ContainsKey(t.Key)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
||||
continue;
|
||||
}
|
||||
var f = new SpriteFrame(t.Value);
|
||||
f.Init();
|
||||
frames.Add(t.Key, f);
|
||||
}
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)");
|
||||
cbus.BroadcastPreInit();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
||||
@@ -413,15 +473,18 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up");
|
||||
GC.Collect();
|
||||
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
|
||||
cbus.ForwardByTime(startOffset);
|
||||
bbus.ForwardByTime(startOffset);
|
||||
timer.Stop();
|
||||
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds);
|
||||
if (Settings.Default.ClearLogOnPlay) {
|
||||
logs.text = "";
|
||||
logEntries.Clear();
|
||||
logsLength = 0;
|
||||
Game.MainLogger.Enumerate((level, module, msg) => { });
|
||||
logs.text = "";
|
||||
}
|
||||
Game.AudioSequencer.Playing = true;
|
||||
atime0 = Game.AudioClient.BufferPosition;
|
||||
Thread.Sleep((int)((atime0 - Game.AudioClient.Position) * 1000));
|
||||
inputProxy.SyncTime(cbus.Time);
|
||||
started = true;
|
||||
}
|
||||
@@ -435,12 +498,16 @@ namespace Cryville.Crtr {
|
||||
public void Stop() {
|
||||
try {
|
||||
Logger.Log("main", 1, "Game", "Stopping");
|
||||
Game.AudioClient.Start();
|
||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||
inputProxy.Deactivate();
|
||||
if (cbus != null) { cbus.Dispose(); cbus = null; }
|
||||
if (bbus != null) { bbus.Dispose(); bbus = null; }
|
||||
if (tbus != null) { tbus.Dispose(); tbus = null; }
|
||||
if (nbus != null) { nbus.Dispose(); nbus = null; }
|
||||
if (tbus != null) { tbus.Dispose(); tbus = null; }
|
||||
if (bbus != null) { bbus.Dispose(); bbus = null; }
|
||||
if (cbus != null) { cbus.Dispose(); cbus.DisposeAll(); cbus = null; }
|
||||
effectManager.Dispose();
|
||||
effectManager = null;
|
||||
etor = null;
|
||||
Logger.Log("main", 1, "Game", "Stopped");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -484,8 +551,6 @@ namespace Cryville.Crtr {
|
||||
try {
|
||||
workerTimer = new diag::Stopwatch();
|
||||
workerTimer.Start();
|
||||
RMVPool.Prepare();
|
||||
MotionCachePool.Prepare();
|
||||
LoadChart(info);
|
||||
workerTimer.Stop();
|
||||
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
||||
@@ -521,12 +586,12 @@ namespace Cryville.Crtr {
|
||||
LoadSkin(info.skinFile);
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input");
|
||||
judge = new Judge(pruleset);
|
||||
judge = new Judge(this, pruleset);
|
||||
etor.ContextJudge = judge;
|
||||
|
||||
inputProxy = new InputProxy(pruleset, judge);
|
||||
inputProxy.LoadFrom(_rscfg.inputs);
|
||||
if (!inputProxy.IsCompleted) {
|
||||
if (!inputProxy.IsCompleted()) {
|
||||
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||
}
|
||||
|
||||
@@ -574,6 +639,8 @@ namespace Cryville.Crtr {
|
||||
pruleset = ruleset.Root;
|
||||
pruleset.Optimize(etor);
|
||||
}
|
||||
ContainerState.RMVPool = new RMVPool();
|
||||
ContainerState.MCPool = new MotionCachePool();
|
||||
}
|
||||
|
||||
void LoadSkin(FileInfo file) {
|
||||
@@ -582,6 +649,7 @@ namespace Cryville.Crtr {
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
effectManager = new EffectManager(pskin);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
10
Assets/Cryville/Crtr/Clip.cs
Normal file
10
Assets/Cryville/Crtr/Clip.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Cryville.Crtr {
|
||||
public struct Clip {
|
||||
public float Behind { get; set; }
|
||||
public float Ahead { get; set; }
|
||||
public Clip(float behind, float ahead) {
|
||||
Behind = behind;
|
||||
Ahead = ahead;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Clip.cs.meta
Normal file
11
Assets/Cryville/Crtr/Clip.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31109f74226deb947b93732206b112ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,12 +1,21 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
[DisallowMultipleComponent]
|
||||
public abstract class MeshBase : SkinComponent {
|
||||
public MeshBase() {
|
||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => {
|
||||
var c = Color;
|
||||
c.a *= v;
|
||||
Color = c;
|
||||
}));
|
||||
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
||||
}
|
||||
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
protected Material[] materials;
|
||||
|
||||
short _zindex;
|
||||
public short ZIndex {
|
||||
@@ -22,9 +31,36 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
protected void UpdateZIndex() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var mat in mesh.Renderer.materials) {
|
||||
foreach (var mat in materials) {
|
||||
mat.renderQueue = _zindex;
|
||||
}
|
||||
}
|
||||
|
||||
Color _color = Color.white;
|
||||
public Color Color {
|
||||
get { return _color; }
|
||||
set {
|
||||
_color = value;
|
||||
UpdateColor();
|
||||
}
|
||||
}
|
||||
protected void UpdateColor() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var mat in materials) {
|
||||
mat.color = _color;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
DestroyMaterials();
|
||||
mesh.Destroy();
|
||||
}
|
||||
|
||||
protected void DestroyMaterials() {
|
||||
if (materials == null) return;
|
||||
foreach (var mat in materials) {
|
||||
Material.Destroy(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,11 +19,7 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
public SectionalGameObject() {
|
||||
SubmitProperty("partial", new PropOp.Boolean(v => part = Part.idle));
|
||||
SubmitProperty("part", new PropOp.Enum<Part>(v => part = v, v => (Part)v), 2);
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
SubmitProperty("part", new PropOp.Enum<Part>(v => part = v, v => (Part)v), 1);
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
@@ -67,7 +63,7 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
||||
SubmitProperty("shape", new op_set_shape(this), 2);
|
||||
SubmitProperty("shape", new op_set_shape(this), 1);
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
@@ -76,15 +72,14 @@ namespace Cryville.Crtr.Components {
|
||||
public op_set_shape(PolygonSGO self) : base(1) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
protected override unsafe void Execute() {
|
||||
var o = GetOperand(0);
|
||||
if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector");
|
||||
_self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2);
|
||||
var ptr = (Vector2*)o.TrustedAsOfLength(sizeof(Vector2));
|
||||
if (_self._shape != null) _shapePool.Return(_self._shape);
|
||||
_self._shape = _shapePool.Rent(_self._shapeLength);
|
||||
for (int i = 0; i < _self._shapeLength; i++) {
|
||||
_self._shape[i] = ptr[i];
|
||||
_self._shape[i] = o.As<Vector2>(i * sizeof(Vector2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,23 +107,25 @@ namespace Cryville.Crtr.Components {
|
||||
base.Init();
|
||||
mesh.Init(transform);
|
||||
|
||||
var mats = mesh.Renderer.materials = new Material[] { mesh.NewMaterial, mesh.NewMaterial, mesh.NewMaterial };
|
||||
head.Bind(mats[0]);
|
||||
body.Bind(mats[1]);
|
||||
tail.Bind(mats[2]);
|
||||
mesh.Renderer.sharedMaterials = materials = new Material[] {
|
||||
MeshWrapper.NewMaterial(),
|
||||
MeshWrapper.NewMaterial(),
|
||||
MeshWrapper.NewMaterial(),
|
||||
};
|
||||
head.Bind(materials[0]);
|
||||
body.Bind(materials[1]);
|
||||
tail.Bind(materials[2]);
|
||||
|
||||
UpdateZIndex();
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
base.OnDestroy();
|
||||
Reset();
|
||||
foreach (var m in mesh.Renderer.materials) Material.Destroy(m);
|
||||
if (_shape != null) _shapePool.Return(_shape);
|
||||
if (vertices != null) {
|
||||
_ptPool.Return(vertices);
|
||||
_lPool.Return(lengths);
|
||||
}
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
protected override void AppendPointInternal(Vector3 p, Quaternion r) {
|
||||
@@ -152,7 +149,7 @@ namespace Cryville.Crtr.Components {
|
||||
List<Vector3> verts;
|
||||
List<Vector2> uvs;
|
||||
List<int> trih = null, trib = null, trit = null;
|
||||
static List<int> _emptyTris = new List<int>();
|
||||
static readonly List<int> _emptyTris = new List<int>();
|
||||
|
||||
public override void Seal() {
|
||||
if (vertCount <= 1 || sumLength == 0) return;
|
||||
|
89
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
89
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SkinAnimation : SkinComponent {
|
||||
public SkinAnimation() {
|
||||
SubmitProperty("name", new PropOp.Identifier(v => Name = v));
|
||||
SubmitProperty("duration", new PropOp.Float(v => Duration = v));
|
||||
SubmitProperty("iteration", new PropOp.Float(v => Iteration = v));
|
||||
SubmitProperty("direction", new PropOp.Enum<AnimationDirection>(v => Direction = v, v => (AnimationDirection)v));
|
||||
SubmitProperty("delay", new PropOp.Float(v => Delay = v));
|
||||
Iteration = 1;
|
||||
}
|
||||
|
||||
SkinContext _skinContext;
|
||||
Transform _writeTransform;
|
||||
|
||||
AnimationSpan _anim;
|
||||
int _name;
|
||||
public int Name {
|
||||
set {
|
||||
if (_name == value) return;
|
||||
_name = value;
|
||||
if (value == 0) {
|
||||
_anim = null;
|
||||
}
|
||||
else {
|
||||
var id = new Identifier(value);
|
||||
AnimationSpan anim;
|
||||
if (!ChartPlayer.pskin.animations.TryGetValue(id, out anim)) {
|
||||
Logger.Log("main", 4, "Skin", "Animation {0} not found", id.Name);
|
||||
_anim = null;
|
||||
return;
|
||||
}
|
||||
_anim = anim;
|
||||
}
|
||||
}
|
||||
}
|
||||
public float Duration { get; private set; }
|
||||
public float Iteration { get; private set; }
|
||||
public AnimationDirection Direction { get; private set; }
|
||||
public float Delay { get; private set; }
|
||||
|
||||
double _startTime;
|
||||
|
||||
public override void Init() {
|
||||
_skinContext = new SkinContext(transform);
|
||||
}
|
||||
public override void Rewind(double time, Transform target) {
|
||||
_startTime = time;
|
||||
if (target == null) target = transform;
|
||||
_writeTransform = target;
|
||||
}
|
||||
public override void Tick(SkinContainer c, double time) {
|
||||
float _rtime = (float)(time - _startTime - Delay) / Duration;
|
||||
if (_rtime < 0) _rtime = 0;
|
||||
else if (_rtime > Iteration) {
|
||||
if (Direction.HasFlag(AnimationDirection.alternate)) {
|
||||
_rtime = Iteration % 2;
|
||||
if (_rtime > 1) _rtime = 2 - _rtime;
|
||||
}
|
||||
else {
|
||||
_rtime = Iteration % 1;
|
||||
if (_rtime == 0) _rtime = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Direction.HasFlag(AnimationDirection.alternate)) {
|
||||
_rtime %= 2;
|
||||
if (_rtime > 1) _rtime = 2 - _rtime;
|
||||
}
|
||||
else {
|
||||
_rtime %= 1;
|
||||
}
|
||||
}
|
||||
if (Direction.HasFlag(AnimationDirection.reverse)) _rtime = 1 - _rtime;
|
||||
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext, _writeTransform));
|
||||
}
|
||||
protected override void OnDestroy() { }
|
||||
}
|
||||
[Flags]
|
||||
public enum AnimationDirection {
|
||||
normal = 0,
|
||||
reverse = 1,
|
||||
alternate = 2,
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80318e36af5412345871bdbf80d49ef2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -14,8 +14,8 @@ namespace Cryville.Crtr.Components {
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="property">The property.</param>
|
||||
protected void SubmitProperty(string name, PdtOperator property, int uct = 1) {
|
||||
Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, uct));
|
||||
protected void SubmitProperty(string name, PdtOperator property, int udl = 0) {
|
||||
Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, udl));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,14 +26,16 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
|
||||
public virtual void Init() { }
|
||||
public virtual void Rewind(double time, Transform target) { }
|
||||
public virtual void Tick(SkinContainer c, double time) { }
|
||||
protected abstract void OnDestroy();
|
||||
}
|
||||
public struct SkinProperty {
|
||||
public PdtOperator Operator { get; set; }
|
||||
public int UpdateCloneType { get; set; }
|
||||
public SkinProperty(PdtOperator op, int uct = 1) {
|
||||
public int UpdateDynamicLevel { get; set; }
|
||||
public SkinProperty(PdtOperator op, int udl = 0) {
|
||||
Operator = op;
|
||||
UpdateCloneType = uct;
|
||||
UpdateDynamicLevel = udl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,19 +16,15 @@ namespace Cryville.Crtr.Components {
|
||||
public op_set_bound(SpriteBase self) : base(2) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
protected override void Execute() {
|
||||
_self.SetBound(
|
||||
*(Vector2*)GetOperand(0).TrustedAsOfLength(sizeof(Vector2)),
|
||||
*(Vector3*)GetOperand(1).TrustedAsOfLength(sizeof(Vector3))
|
||||
GetOperand(0).As<Vector2>(),
|
||||
GetOperand(1).As<Vector3>()
|
||||
);
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
}
|
||||
|
||||
Vector2 _scale = Vector2.one;
|
||||
public Vector2 Scale {
|
||||
get { return _scale; }
|
||||
@@ -92,7 +88,9 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
protected void InternalInit(string meshName = "quad") {
|
||||
mesh.Init(transform);
|
||||
mesh.Renderer.sharedMaterials = materials = new Material[] { MeshWrapper.NewMaterial() };
|
||||
mesh.Mesh = GenericResources.Meshes[meshName];
|
||||
UpdateColor();
|
||||
UpdateScale();
|
||||
UpdateZIndex();
|
||||
}
|
||||
|
@@ -29,19 +29,12 @@ namespace Cryville.Crtr.Components {
|
||||
return Rect.width / Rect.height;
|
||||
}
|
||||
}
|
||||
bool _loaded;
|
||||
Material _mat;
|
||||
public void Bind(Material mat) {
|
||||
_loaded = true;
|
||||
_mat = mat;
|
||||
Reload();
|
||||
}
|
||||
public void Load() {
|
||||
_loaded = true;
|
||||
Reload();
|
||||
}
|
||||
public void Reload() {
|
||||
if (!_loaded) return;
|
||||
if (!string.IsNullOrEmpty(FrameName)) {
|
||||
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
||||
Frame = ChartPlayer.frames[FrameName];
|
||||
@@ -56,13 +49,18 @@ namespace Cryville.Crtr.Components {
|
||||
_mat.mainTexture = Frame == null ? null : Frame.Texture;
|
||||
}
|
||||
}
|
||||
public static bool IsNullOrEmpty(SpriteInfo sprite) {
|
||||
return sprite == null || sprite.Frame == null;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpritePlane : SpriteBase {
|
||||
public SpritePlane() {
|
||||
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
||||
SubmitProperty("frames", new PropOp.StringArray(v => Frames = v));
|
||||
SubmitProperty("index", new PropOp.Integer(v => Index = v));
|
||||
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v, v => (FitMode)v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||
SubmitProperty("shader", new PropOp.String(v => Shader = v));
|
||||
}
|
||||
|
||||
static Vector2[] _origuv;
|
||||
@@ -83,52 +81,73 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
}
|
||||
|
||||
protected SpriteInfo frameInfo = new SpriteInfo();
|
||||
|
||||
public string Frame {
|
||||
get { return frameInfo.FrameName; }
|
||||
int m_index;
|
||||
public int Index {
|
||||
get { return m_index; }
|
||||
set {
|
||||
frameInfo.FrameName = value;
|
||||
m_index = value;
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
SpriteInfo[] m_frames = new SpriteInfo[] { new SpriteInfo() };
|
||||
public string[] Frames {
|
||||
set {
|
||||
m_frames = new SpriteInfo[value.Length];
|
||||
for (int i = 0; i < value.Length; i++) {
|
||||
m_frames[i] = new SpriteInfo() { FrameName = value[i] };
|
||||
}
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
public string Frame {
|
||||
set {
|
||||
if (value == CurrentFrame.FrameName) return;
|
||||
CurrentFrame.FrameName = value;
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
protected SpriteInfo CurrentFrame {
|
||||
get {
|
||||
if (m_frames.Length == 0) return null;
|
||||
if (m_index < 0) m_index = 0;
|
||||
else if (m_index >= m_frames.Length) m_index = m_frames.Length - 1;
|
||||
return m_frames[m_index];
|
||||
}
|
||||
}
|
||||
protected void OnFrameUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
if (frameInfo.Frame == null) {
|
||||
var frame = CurrentFrame;
|
||||
if (SpriteInfo.IsNullOrEmpty(frame)) {
|
||||
mesh.Renderer.enabled = false;
|
||||
return;
|
||||
}
|
||||
mesh.Renderer.enabled = true;
|
||||
mesh.Renderer.sharedMaterial.mainTexture = frame.Frame.Texture;
|
||||
UpdateUV();
|
||||
UpdateScale();
|
||||
}
|
||||
Shader m_shader;
|
||||
public string Shader {
|
||||
set {
|
||||
m_shader = GenericResources.Shaders[value];
|
||||
UpdateShader();
|
||||
}
|
||||
}
|
||||
void UpdateShader() {
|
||||
if (!mesh.Initialized) return;
|
||||
if (m_shader == null) m_shader = GenericResources.Shaders["default"];
|
||||
mesh.Renderer.sharedMaterial.shader = m_shader;
|
||||
UpdateZIndex();
|
||||
}
|
||||
readonly Vector2[] _uvs = new Vector2[4];
|
||||
protected virtual void UpdateUV() {
|
||||
if (frameInfo.Frame == null) {
|
||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
||||
return;
|
||||
}
|
||||
var frame = CurrentFrame;
|
||||
if (SpriteInfo.IsNullOrEmpty(frame)) return;
|
||||
Vector2[] muv = OriginalUV;
|
||||
Vector2[] uv = new Vector2[muv.Length];
|
||||
for (int i = 0; i < uv.Length; i++) {
|
||||
uv[i] = frameInfo.Frame.GetUV(muv[i]);
|
||||
for (int i = 0; i < _uvs.Length; i++) {
|
||||
_uvs[i] = frame.Frame.GetUV(muv[i]);
|
||||
}
|
||||
mesh.Mesh.uv = uv;
|
||||
}
|
||||
|
||||
float _opacity = 1;
|
||||
public float Opacity {
|
||||
get { return _opacity; }
|
||||
set {
|
||||
_opacity = value;
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
void UpdateOpacity() {
|
||||
if (!mesh.Initialized) return;
|
||||
var c = mesh.Renderer.material.color;
|
||||
c.a = _opacity;
|
||||
mesh.Renderer.material.color = c;
|
||||
mesh.Mesh.uv = _uvs;
|
||||
}
|
||||
|
||||
private FitMode m_fit = FitMode.height;
|
||||
@@ -144,7 +163,7 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
|
||||
protected override void UpdateScale() {
|
||||
if (frameInfo.Frame == null) return;
|
||||
if (SpriteInfo.IsNullOrEmpty(CurrentFrame)) return;
|
||||
base.UpdateScale();
|
||||
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
||||
}
|
||||
@@ -153,8 +172,8 @@ namespace Cryville.Crtr.Components {
|
||||
get {
|
||||
switch (m_fit) {
|
||||
case FitMode.none: return Vector3.one;
|
||||
case FitMode.width: return new Vector3(1, 1, 1 / frameInfo.Ratio);
|
||||
case FitMode.height: return new Vector3(frameInfo.Ratio, 1, 1);
|
||||
case FitMode.width: return new Vector3(1, 1, 1 / CurrentFrame.Ratio);
|
||||
case FitMode.height: return new Vector3(CurrentFrame.Ratio, 1, 1);
|
||||
default: throw new NotSupportedException("Unsupported fit mode");
|
||||
}
|
||||
}
|
||||
@@ -162,9 +181,8 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
frameInfo.Bind(mesh.Renderer.material);
|
||||
OnFrameUpdate();
|
||||
UpdateOpacity();
|
||||
UpdateShader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,22 +2,7 @@
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteRect : SpriteBase {
|
||||
public SpriteRect() {
|
||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||
}
|
||||
|
||||
Color _color;
|
||||
public Color Color {
|
||||
get { return _color; }
|
||||
set {
|
||||
_color = value;
|
||||
OnColorUpdate();
|
||||
}
|
||||
}
|
||||
void OnColorUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
mesh.Renderer.material.SetColor("_Color", _color);
|
||||
}
|
||||
public SpriteRect() { }
|
||||
|
||||
protected override Vector3 BaseScale {
|
||||
get { return Vector3.one; }
|
||||
@@ -25,7 +10,6 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
OnColorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,12 +8,12 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("border", new PropOp.Vector2(v => Border = v));
|
||||
}
|
||||
|
||||
readonly static Dictionary<float, int> uvrefl
|
||||
static readonly Dictionary<float, int> uvrefl
|
||||
= new Dictionary<float, int>() {
|
||||
{-0.5f, 0}, {-0.4f, 1}, {0.4f, 2}, {0.5f, 3},
|
||||
};
|
||||
static Vector2[] _origuv;
|
||||
protected new static Vector2[] OriginalUV {
|
||||
protected static new Vector2[] OriginalUV {
|
||||
get {
|
||||
if (_origuv == null) {
|
||||
var m = GenericResources.Meshes["quad_scale3h"];
|
||||
@@ -44,24 +44,26 @@ namespace Cryville.Crtr.Components {
|
||||
UpdateUV();
|
||||
}
|
||||
|
||||
readonly Vector2[] _uvs = new Vector2[8];
|
||||
readonly Vector3[] _verts = new Vector3[8];
|
||||
protected override void UpdateUV() {
|
||||
Vector2[] muv = OriginalUV;
|
||||
Vector2[] uv = new Vector2[muv.Length];
|
||||
var frame = CurrentFrame;
|
||||
if (SpriteInfo.IsNullOrEmpty(frame)) return;
|
||||
|
||||
var or = frameInfo.Ratio;
|
||||
Vector2[] muv = OriginalUV;
|
||||
|
||||
var or = frame.Ratio;
|
||||
var sr = Scale.x / Scale.y;
|
||||
var b = new Vector2(
|
||||
(or / sr) * _border.x,
|
||||
1 - (or / sr) * (1 - _border.y)
|
||||
);
|
||||
Vector3[] vert = mesh.Mesh.vertices;
|
||||
var rr = or / sr;
|
||||
var b1 = rr * _border.x;
|
||||
var b2 = 1 - rr * (1 - _border.y);
|
||||
|
||||
for (int i = 0; i < muv.Length; i++) {
|
||||
float x; float bx;
|
||||
switch ((int)muv[i].x) {
|
||||
case 0: x = 0; bx = 0; break;
|
||||
case 1: x = _border.x; bx = b.x; break;
|
||||
case 2: x = _border.y; bx = b.y; break;
|
||||
case 1: x = _border.x; bx = b1; break;
|
||||
case 2: x = _border.y; bx = b2; break;
|
||||
case 3: x = 1; bx = 1; break;
|
||||
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||
}
|
||||
@@ -71,16 +73,15 @@ namespace Cryville.Crtr.Components {
|
||||
case 3: y = 1; break;
|
||||
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||
}
|
||||
uv[i] = frameInfo.Frame.GetUV(x, y);
|
||||
_uvs[i] = frame.Frame.GetUV(x, y);
|
||||
bx -= 0.5f; y -= 0.5f;
|
||||
vert[i] = new Vector3(bx, 0, y);
|
||||
_verts[i] = new Vector3(bx, 0, y);
|
||||
}
|
||||
mesh.Mesh.uv = uv;
|
||||
mesh.Mesh.vertices = vert;
|
||||
mesh.Mesh.uv = _uvs;
|
||||
mesh.Mesh.vertices = _verts;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
frameInfo.Load();
|
||||
InternalInit("quad_scale3h");
|
||||
OnFrameUpdate();
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("value", new PropOp.TargetString(() => Value));
|
||||
SubmitProperty("size", new PropOp.Float(v => Size = v));
|
||||
SubmitProperty("spacing", new PropOp.Float(v => Spacing = v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
@@ -20,11 +19,13 @@ namespace Cryville.Crtr.Components {
|
||||
public op_set_frames(SpriteText self) : base(2) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
protected override unsafe void Execute() {
|
||||
var keys = GetOperand(0).AsString();
|
||||
var values = GetOperand(1);
|
||||
int arrtype; int len;
|
||||
values.GetArraySuffix(out arrtype, out len);
|
||||
if (arrtype != PdtInternalType.String) throw new InvalidCastException("Not an array of strings");
|
||||
if (len != keys.Length) throw new ArgumentException("Length of key not equal to frame count");
|
||||
var result = new Dictionary<char, SpriteInfo>(len);
|
||||
int o = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -45,7 +46,7 @@ namespace Cryville.Crtr.Components {
|
||||
Dictionary<char, SpriteInfo> m_frames;
|
||||
public Dictionary<char, SpriteInfo> Frames {
|
||||
get { return m_frames; }
|
||||
set { m_frames = value; UpdateFrames(); UpdateScale(); }
|
||||
set { m_frames = value; UpdateFrames(); }
|
||||
}
|
||||
|
||||
readonly TargetString m_value = new TargetString();
|
||||
@@ -76,8 +77,11 @@ namespace Cryville.Crtr.Components {
|
||||
meshes.Clear();
|
||||
verts.Clear();
|
||||
uvs.Clear();
|
||||
DestroyMaterials();
|
||||
materials = new Material[m_frames.Count];
|
||||
int i = 0;
|
||||
foreach (var f in m_frames) {
|
||||
f.Value.Load();
|
||||
if (SpriteInfo.IsNullOrEmpty(f.Value)) continue;
|
||||
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
|
||||
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height for text component");
|
||||
var tex = f.Value.Frame.Texture;
|
||||
@@ -85,13 +89,17 @@ namespace Cryville.Crtr.Components {
|
||||
var m = new MeshWrapper();
|
||||
m.Init(mesh.MeshTransform);
|
||||
m.Mesh = new Mesh();
|
||||
m.Renderer.material.mainTexture = tex;
|
||||
var mat = MeshWrapper.NewMaterial();
|
||||
mat.mainTexture = tex;
|
||||
m.Renderer.sharedMaterial = materials[i++] = mat;
|
||||
meshes.Add(tex, m);
|
||||
verts.Add(tex, new List<Vector3>());
|
||||
uvs.Add(tex, new List<Vector2>());
|
||||
tris.Add(tex, new List<int>());
|
||||
}
|
||||
}
|
||||
UpdateColor();
|
||||
UpdateScale();
|
||||
}
|
||||
|
||||
float sum_x;
|
||||
@@ -102,10 +110,11 @@ namespace Cryville.Crtr.Components {
|
||||
void UpdateMeshes() {
|
||||
if (meshes.Count == 0) return;
|
||||
sum_x = 0;
|
||||
foreach (var t in meshes.Keys) {
|
||||
verts[t].Clear();
|
||||
uvs[t].Clear();
|
||||
tris[t].Clear();
|
||||
foreach (var t in meshes) {
|
||||
var key = t.Key;
|
||||
verts[key].Clear();
|
||||
uvs[key].Clear();
|
||||
tris[key].Clear();
|
||||
}
|
||||
foreach (var c in m_value) {
|
||||
var f = m_frames[c];
|
||||
@@ -121,11 +130,12 @@ namespace Cryville.Crtr.Components {
|
||||
uvs[t].Add(f.Frame.GetUV(new Vector2(0, 1)));
|
||||
sum_x += w + m_spacing;
|
||||
}
|
||||
foreach (var t in meshes.Keys) {
|
||||
var m = meshes[t].Mesh;
|
||||
foreach (var t in meshes) {
|
||||
var key = t.Key;
|
||||
var m = meshes[key].Mesh;
|
||||
m.Clear();
|
||||
int cc = verts[t].Count / 4;
|
||||
var _tris = tris[t];
|
||||
int cc = verts[key].Count / 4;
|
||||
var _tris = tris[key];
|
||||
for (int i = 0; i < cc; i++) {
|
||||
_tris.Add(i * 4);
|
||||
_tris.Add(i * 4 + 3);
|
||||
@@ -134,9 +144,9 @@ namespace Cryville.Crtr.Components {
|
||||
_tris.Add(i * 4 + 3);
|
||||
_tris.Add(i * 4 + 2);
|
||||
}
|
||||
m.SetVertices(verts[t]);
|
||||
m.SetUVs(0, uvs[t]);
|
||||
m.SetTriangles(tris[t], 0);
|
||||
m.SetVertices(verts[key]);
|
||||
m.SetUVs(0, uvs[key]);
|
||||
m.SetTriangles(tris[key], 0);
|
||||
m.RecalculateNormals();
|
||||
}
|
||||
sum_x -= m_spacing;
|
||||
@@ -154,23 +164,6 @@ namespace Cryville.Crtr.Components {
|
||||
get { return new Vector2(-0.5f, -0.5f); }
|
||||
}
|
||||
|
||||
float _opacity = 1;
|
||||
public float Opacity {
|
||||
get { return _opacity; }
|
||||
set {
|
||||
_opacity = value;
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
void UpdateOpacity() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var m in meshes.Values) {
|
||||
var c = m.Renderer.material.color;
|
||||
c.a = _opacity;
|
||||
m.Renderer.material.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
UpdateFrames();
|
||||
|
91
Assets/Cryville/Crtr/Config/ConfigPanelMaster.cs
Normal file
91
Assets/Cryville/Crtr/Config/ConfigPanelMaster.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class ConfigPanelMaster : MonoBehaviour {
|
||||
[SerializeField]
|
||||
Menu m_menu;
|
||||
|
||||
[SerializeField]
|
||||
Transform m_content;
|
||||
|
||||
[SerializeField]
|
||||
SettingsPanel m_genericConfigPanel;
|
||||
|
||||
[SerializeField]
|
||||
InputConfigPanel m_inputConfigPanel;
|
||||
|
||||
public Ruleset ruleset;
|
||||
RulesetConfig _rscfg;
|
||||
|
||||
void OnEnable() {
|
||||
try {
|
||||
ChartPlayer.etor = new PdtEvaluator();
|
||||
FileInfo file = new FileInfo(
|
||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||
);
|
||||
if (!file.Exists) {
|
||||
throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||
}
|
||||
DirectoryInfo dir = file.Directory;
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
}
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
if (!cfgfile.Exists) {
|
||||
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
|
||||
_rscfg = new RulesetConfig();
|
||||
}
|
||||
else {
|
||||
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
m_genericConfigPanel.Target = _rscfg.generic;
|
||||
|
||||
var proxy = new InputProxy(ruleset.Root, null);
|
||||
proxy.LoadFrom(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy = proxy;
|
||||
|
||||
m_inputConfigPanel.OnConfigEnable();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Popup.CreateException(ex);
|
||||
Logger.Log("main", 4, "Config", "An error occured while loading the config: {0}", ex);
|
||||
m_menu.Back();
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchCategory(GameObject cat) {
|
||||
foreach (Transform c in m_content) {
|
||||
c.gameObject.SetActive(false);
|
||||
}
|
||||
cat.SetActive(true);
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
m_inputConfigPanel.OnConfigDisable();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class ConfigScene : MonoBehaviour {
|
||||
[SerializeField]
|
||||
Transform m_content;
|
||||
|
||||
[SerializeField]
|
||||
SettingsPanel m_genericConfigPanel;
|
||||
|
||||
[SerializeField]
|
||||
InputConfigPanel m_inputConfigPanel;
|
||||
|
||||
public Ruleset ruleset;
|
||||
RulesetConfig _rscfg;
|
||||
|
||||
void Start() {
|
||||
ChartPlayer.etor = new PdtEvaluator();
|
||||
FileInfo file = new FileInfo(
|
||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||
);
|
||||
if (!file.Exists) {
|
||||
Popup.Create("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||
ReturnToMenu();
|
||||
return;
|
||||
}
|
||||
DirectoryInfo dir = file.Directory;
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
}
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
if (!cfgfile.Exists) {
|
||||
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
|
||||
_rscfg = new RulesetConfig();
|
||||
}
|
||||
else {
|
||||
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
m_genericConfigPanel.Target = _rscfg.generic;
|
||||
|
||||
var proxy = new InputProxy(ruleset.Root, null);
|
||||
proxy.LoadFrom(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy = proxy;
|
||||
}
|
||||
|
||||
public void SwitchCategory(GameObject cat) {
|
||||
foreach (Transform c in m_content) {
|
||||
c.gameObject.SetActive(false);
|
||||
}
|
||||
cat.SetActive(true);
|
||||
}
|
||||
|
||||
public void SaveAndReturnToMenu() {
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
ReturnToMenu();
|
||||
}
|
||||
public void ReturnToMenu() {
|
||||
GameObject.Find("Master").GetComponent<Master>().ShowMenu();
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
SceneManager.UnloadSceneAsync("Config");
|
||||
#elif UNITY_5_3_OR_NEWER
|
||||
SceneManager.UnloadScene("Config");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common.Unity.Input;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -7,7 +8,7 @@ using UnityEngine.UI;
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class InputConfigPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
ConfigScene m_configScene;
|
||||
ConfigPanelMaster m_configScene;
|
||||
|
||||
[SerializeField]
|
||||
GameObject m_inputDialog;
|
||||
@@ -24,12 +25,12 @@ namespace Cryville.Crtr.Config {
|
||||
[SerializeField]
|
||||
GameObject m_prefabInputConfigEntry;
|
||||
|
||||
readonly SimpleInputConsumer _consumer = new SimpleInputConsumer(Game.InputManager);
|
||||
SimpleInputConsumer _consumer;
|
||||
public InputProxy proxy;
|
||||
readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
||||
|
||||
string _sel;
|
||||
public void OpenDialog(string entry) {
|
||||
Identifier _sel;
|
||||
public void OpenDialog(Identifier entry) {
|
||||
_sel = entry;
|
||||
m_inputDialog.SetActive(true);
|
||||
CallHelper.Purge(m_deviceList);
|
||||
@@ -50,7 +51,10 @@ namespace Cryville.Crtr.Config {
|
||||
CloseDialog();
|
||||
}
|
||||
|
||||
void Start() {
|
||||
public void OnConfigEnable() {
|
||||
CallHelper.Purge(m_entryList);
|
||||
_entries.Clear();
|
||||
_consumer = new SimpleInputConsumer(Game.InputManager);
|
||||
_consumer.Activate();
|
||||
foreach (var i in m_configScene.ruleset.Root.inputs) {
|
||||
var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
|
||||
@@ -61,13 +65,12 @@ namespace Cryville.Crtr.Config {
|
||||
proxy.ProxyChanged += OnProxyChanged;
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
public void OnConfigDisable() {
|
||||
_consumer.Deactivate();
|
||||
}
|
||||
|
||||
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
||||
_entries[e.Name].SetEnabled(!e.Used);
|
||||
_entries[e.Name].SetValue(e.Proxy == null ? "None" : e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type));
|
||||
_entries[e.Name].OnProxyChanged(e);
|
||||
}
|
||||
|
||||
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
|
||||
@@ -83,9 +86,21 @@ namespace Cryville.Crtr.Config {
|
||||
if (_recvsrcs.Contains(src)) return;
|
||||
_recvsrcs.Add(src);
|
||||
var obj = Instantiate(m_prefabListItem, m_deviceList);
|
||||
obj.transform.Find("Text").GetComponent<Text>().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||
var text = obj.transform.Find("Text").GetComponent<Text>();
|
||||
text.text = src == null ? "(None)" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||
var btn = obj.GetComponent<Button>();
|
||||
if (src != null) btn.interactable = !proxy.IsUsed(src.Value);
|
||||
if (src != null) {
|
||||
var tsrc = src.Value;
|
||||
bool flag = false;
|
||||
if (proxy.IsUsed(tsrc)) {
|
||||
text.text += " <size=9>(Used)</size>";
|
||||
}
|
||||
else if (tsrc.Handler.GetDimension(src.Value.Type) < m_configScene.ruleset.Root.inputs[_sel].dim) {
|
||||
text.text += " <size=9>(Not Applicable)</size>";
|
||||
}
|
||||
else flag = true;
|
||||
btn.interactable = flag;
|
||||
}
|
||||
btn.onClick.AddListener(() => {
|
||||
CloseDialog(src);
|
||||
});
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using UnityEngine;
|
||||
using Cryville.Common;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
@@ -12,20 +14,31 @@ namespace Cryville.Crtr.Config {
|
||||
[SerializeField]
|
||||
Button m_button;
|
||||
|
||||
public void SetKey(InputConfigPanel master, string name) {
|
||||
m_key.text = name;
|
||||
public void SetKey(InputConfigPanel master, Identifier name) {
|
||||
m_key.text = (string)name.Name;
|
||||
m_value.text = "None";
|
||||
m_button.onClick.AddListener(() => {
|
||||
master.OpenDialog(name);
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
});
|
||||
}
|
||||
|
||||
public void SetValue(string name) {
|
||||
m_value.text = name;
|
||||
}
|
||||
|
||||
public void SetEnabled(bool flag) {
|
||||
m_button.interactable = flag;
|
||||
public void OnProxyChanged(ProxyChangedEventArgs e) {
|
||||
if (e.Used) {
|
||||
m_button.interactable = false;
|
||||
m_value.text = "(Not Required)";
|
||||
}
|
||||
else {
|
||||
m_button.interactable = true;
|
||||
if (e.Proxy == null) {
|
||||
m_value.text = "(Unassigned)";
|
||||
if (e.Required) m_value.text += " (Required)";
|
||||
}
|
||||
else {
|
||||
m_value.text = e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type);
|
||||
}
|
||||
}
|
||||
m_value.color = e.Required ? Color.yellow : Color.black;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,12 @@ namespace Cryville.Crtr.Config {
|
||||
[JsonProperty("skin")]
|
||||
public string Skin { get; set; }
|
||||
|
||||
[Category("gameplay")]
|
||||
[JsonProperty("sound_offset")]
|
||||
[Step(0.04f)]
|
||||
[Precision(1e-3)]
|
||||
public float SoundOffset { get; set; }
|
||||
|
||||
[Category("deprecated")][Obsolete]
|
||||
[JsonProperty("scroll_velocity")][DefaultValue(1)]
|
||||
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
|
||||
@@ -19,6 +25,7 @@ namespace Cryville.Crtr.Config {
|
||||
|
||||
public Generic() {
|
||||
Skin = "";
|
||||
SoundOffset = 0;
|
||||
ScrollVelocity = 1;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user