Compare commits
45 Commits
0.5.2
...
dca1ba304e
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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
File diff suppressed because one or more lines are too long
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 = (UInt32)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:
|
||||
@@ -91,7 +91,7 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
}
|
||||
public partial class PdtInterpreter<T> {
|
||||
public partial class PdtInterpreter {
|
||||
readonly static Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
|
||||
{ '@', 7 },
|
||||
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -8,8 +9,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>
|
||||
@@ -44,34 +44,35 @@ 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, typeof(T), binder).Interpret();
|
||||
}
|
||||
|
||||
readonly string _src;
|
||||
public string Source { get; private set; }
|
||||
readonly Type _type;
|
||||
readonly Binder _binder;
|
||||
protected int Position { get; private set; }
|
||||
public int Position { get; private set; }
|
||||
#pragma warning disable IDE1006
|
||||
protected char cc { get { return _src[Position]; } }
|
||||
protected char cc { get { return Source[Position]; } }
|
||||
protected int ct { get { return cm[cc]; } }
|
||||
protected string tokenb(int flag) { // Token Whitelist
|
||||
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
|
||||
int sp = Position;
|
||||
while ((ct & flag) != 0) Position++;
|
||||
return _src.Substring(sp, Position - sp);
|
||||
return Source.Substring(sp, Position - sp);
|
||||
}
|
||||
protected void ws() {
|
||||
while ((ct & 0x0001) != 0) Position++;
|
||||
@@ -97,7 +98,7 @@ 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");
|
||||
}
|
||||
protected PdtExpression GetExp() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
@@ -108,23 +109,30 @@ 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="type">The destination type.</param>
|
||||
/// <param name="binder">The binder. May be <c>null</c>.</param>
|
||||
public PdtInterpreter(string src, Binder binder) {
|
||||
_src = src;
|
||||
public PdtInterpreter(string src, Type type, Binder binder) {
|
||||
Source = src;
|
||||
_type = type;
|
||||
_binder = binder;
|
||||
if (_binder == null)
|
||||
_binder = BinderAttribute.CreateBinderOfType(typeof(T));
|
||||
_binder = BinderAttribute.CreateBinderOfType(_type);
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets the source to an object of type <typeparamref name="T" />.
|
||||
/// Interprets the source to an object.
|
||||
/// </summary>
|
||||
/// <returns>The interpreted object.</returns>
|
||||
public T Interpret() {
|
||||
InterpretDirectives();
|
||||
return (T)InterpretObject(typeof(T));
|
||||
public object Interpret() {
|
||||
try {
|
||||
InterpretDirectives();
|
||||
return InterpretObject(_type);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new PdtParsingException(this, ex);
|
||||
}
|
||||
}
|
||||
void InterpretDirectives() {
|
||||
bool flag = false;
|
||||
@@ -229,4 +237,36 @@ namespace Cryville.Common.Pdt {
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
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 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 {
|
||||
|
||||
@@ -130,11 +130,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;
|
||||
}
|
||||
}
|
||||
@@ -161,18 +161,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 +177,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 +195,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,7 +9,9 @@ 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;
|
||||
@@ -19,6 +22,7 @@ using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class ChartPlayer : MonoBehaviour {
|
||||
#region Fields
|
||||
Chart chart;
|
||||
Skin skin;
|
||||
PdtSkin pskin;
|
||||
@@ -44,7 +48,9 @@ namespace Cryville.Crtr {
|
||||
|
||||
static bool initialized;
|
||||
static Text logs;
|
||||
Text status;
|
||||
TextMeshProUGUI status;
|
||||
readonly TargetString statusstr = new TargetString();
|
||||
readonly StringBuffer statusbuf = new StringBuffer();
|
||||
|
||||
static Vector2 screenSize;
|
||||
public static Rect hitRect;
|
||||
@@ -66,6 +72,7 @@ namespace Cryville.Crtr {
|
||||
public static PdtEvaluator etor;
|
||||
|
||||
InputProxy inputProxy;
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour
|
||||
void Start() {
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -146,13 +152,13 @@ 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();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -214,7 +220,6 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
string timetext = string.Empty;
|
||||
void LogUpdate() {
|
||||
string _logs = logs.text;
|
||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
||||
@@ -234,36 +239,45 @@ namespace Cryville.Crtr {
|
||||
);
|
||||
});
|
||||
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,
|
||||
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()
|
||||
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()
|
||||
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)" : ""
|
||||
);
|
||||
if (started) {
|
||||
statusbuf.AppendFormat(
|
||||
"\nStates: c{0} / b{1}",
|
||||
cbus.ActiveStateCount, bbus.ActiveStateCount
|
||||
);
|
||||
statusbuf.AppendFormat(
|
||||
"\nSTime: {0:G17}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)" : ""
|
||||
);
|
||||
if (judge != null) {
|
||||
statusbuf.Append("\n== Scores ==\n");
|
||||
var fullScoreStr = judge.GetFullFormattedScoreString();
|
||||
statusbuf.Append(fullScoreStr.TrustedAsArray(), 0, fullScoreStr.Length);
|
||||
}
|
||||
}
|
||||
statusstr.Length = statusbuf.Count;
|
||||
var arr = statusstr.TrustedAsArray();
|
||||
statusbuf.CopyTo(0, arr, 0, statusbuf.Count);
|
||||
status.SetText(arr, 0, statusbuf.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -294,7 +308,7 @@ namespace Cryville.Crtr {
|
||||
bool logEnabled = true;
|
||||
public void ToggleLogs() {
|
||||
logs.text = "";
|
||||
status.text = "";
|
||||
status.SetText("");
|
||||
logEnabled = !logEnabled;
|
||||
}
|
||||
|
||||
@@ -322,8 +336,6 @@ namespace Cryville.Crtr {
|
||||
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;
|
||||
@@ -437,10 +449,10 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 1, "Game", "Stopping");
|
||||
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; }
|
||||
Logger.Log("main", 1, "Game", "Stopped");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
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:
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class ConfigScene : MonoBehaviour {
|
||||
@@ -20,43 +21,48 @@ namespace Cryville.Crtr.Config {
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Popup.CreateException(ex);
|
||||
Logger.Log("main", 4, "Config", "An error occured while loading the config: {0}", ex);
|
||||
ReturnToMenu();
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -4,10 +4,15 @@ using Cryville.Crtr.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
public abstract class ContainerHandler : IDisposable {
|
||||
public abstract class ContainerHandler {
|
||||
#region Struct
|
||||
public ContainerHandler() { }
|
||||
public abstract string TypeName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Prehandling <see cref="ContainerState"/>, prehandling the events.
|
||||
/// </summary>
|
||||
@@ -42,8 +47,20 @@ namespace Cryville.Crtr.Event {
|
||||
public Vector3 Position { get; protected set; }
|
||||
public Quaternion Rotation { get; protected set; }
|
||||
public bool Alive { get; private set; }
|
||||
public bool Awoken { get; private set; }
|
||||
public bool Disposed { get; private set; }
|
||||
bool PreGraphicalActive;
|
||||
public void SetPreGraphicalActive(bool value, ContainerState s) {
|
||||
if (PreGraphicalActive == value) return;
|
||||
PreGraphicalActive = value;
|
||||
if (PreGraphicalActive) StartPreGraphicalUpdate(s);
|
||||
else EndPreGraphicalUpdate(s);
|
||||
}
|
||||
bool GraphicalActive;
|
||||
public void SetGraphicalActive(bool value, ContainerState s) {
|
||||
if (GraphicalActive == value) return;
|
||||
GraphicalActive = value;
|
||||
if (GraphicalActive) StartGraphicalUpdate(s);
|
||||
else EndGraphicalUpdate(s);
|
||||
}
|
||||
|
||||
public EventContainer Container {
|
||||
get { return cs.Container; }
|
||||
@@ -56,11 +73,9 @@ namespace Cryville.Crtr.Event {
|
||||
this.judge = judge;
|
||||
}
|
||||
|
||||
public ContainerHandler() { }
|
||||
public abstract string TypeName {
|
||||
get;
|
||||
}
|
||||
public readonly Dictionary<int, List<Anchor>> Anchors = new Dictionary<int, List<Anchor>>();
|
||||
public readonly Dictionary<int, Anchor> DynamicAnchors = new Dictionary<int, Anchor>();
|
||||
public readonly Dictionary<int, bool> DynamicAnchorSet = new Dictionary<int, bool>();
|
||||
public Anchor OpenedAnchor;
|
||||
protected Anchor a_cur;
|
||||
protected Anchor a_head;
|
||||
@@ -68,29 +83,43 @@ namespace Cryville.Crtr.Event {
|
||||
protected readonly static int _a_cur = IdentifierManager.SharedInstance.Request("cur");
|
||||
protected readonly static int _a_head = IdentifierManager.SharedInstance.Request("head");
|
||||
protected readonly static int _a_tail = IdentifierManager.SharedInstance.Request("tail");
|
||||
public virtual void PreInit() {
|
||||
gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
|
||||
SkinContext = new SkinContext(gogroup);
|
||||
if (cs.Parent != null)
|
||||
gogroup.SetParent(cs.Parent.Handler.gogroup, false);
|
||||
a_cur = RegisterAnchor(_a_cur);
|
||||
a_head = RegisterAnchor(_a_head);
|
||||
a_tail = RegisterAnchor(_a_tail);
|
||||
}
|
||||
protected Anchor RegisterAnchor(int name, bool hasPropSrcs = false) {
|
||||
var go = new GameObject("." + IdentifierManager.SharedInstance.Retrieve(name)).transform;
|
||||
public Anchor RegisterAnchor(int name, bool dyn = false, int propSrcCount = 0) {
|
||||
var strname = IdentifierManager.SharedInstance.Retrieve(name);
|
||||
var go = new GameObject("." + strname).transform;
|
||||
go.SetParent(gogroup, false);
|
||||
var result = new Anchor(name, go, hasPropSrcs);
|
||||
var result = new Anchor(name, go, propSrcCount);
|
||||
if (dyn) {
|
||||
if (DynamicAnchors.ContainsKey(name))
|
||||
throw new ArgumentException(string.Format("The anchor \"{0}\" already exists", strname));
|
||||
DynamicAnchors.Add(name, result);
|
||||
DynamicAnchorSet.Add(name, false);
|
||||
}
|
||||
List<Anchor> list;
|
||||
if (!Anchors.TryGetValue(name, out list))
|
||||
Anchors.Add(name, list = new List<Anchor>());
|
||||
list.Add(result);
|
||||
return result;
|
||||
}
|
||||
protected void OpenAnchor(Anchor anchor) {
|
||||
if (OpenedAnchor != null) throw new InvalidOperationException("An anchor has been opened");
|
||||
OpenedAnchor = anchor;
|
||||
}
|
||||
protected void CloseAnchor() {
|
||||
OpenedAnchor = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Called upon StartUpdate of ps 17.
|
||||
/// </summary>
|
||||
#region Logic
|
||||
#region Init methods: Called on prehandle
|
||||
public virtual void PreInit() {
|
||||
gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
|
||||
SkinContext = new SkinContext(gogroup);
|
||||
if (cs.Parent != null)
|
||||
gogroup.SetParent(cs.Parent.Handler.gogroup, false);
|
||||
a_cur = RegisterAnchor(_a_cur);
|
||||
a_head = RegisterAnchor(_a_head, true);
|
||||
a_tail = RegisterAnchor(_a_tail, true);
|
||||
}
|
||||
public virtual void Init() {
|
||||
skinContainer.MatchStatic(ps);
|
||||
foreach (var i in gogroup.GetComponentsInChildren<SkinComponent>())
|
||||
@@ -99,57 +128,28 @@ namespace Cryville.Crtr.Event {
|
||||
public virtual void PostInit() {
|
||||
gogroup.gameObject.SetActive(false);
|
||||
}
|
||||
public virtual void Dispose() {
|
||||
if (Disposed) return;
|
||||
Disposed = true;
|
||||
if (gogroup)
|
||||
GameObject.Destroy(gogroup.gameObject);
|
||||
// gogroup.gameObject.SetActive(false);
|
||||
Alive = false;
|
||||
#endregion
|
||||
#region Start methods
|
||||
public virtual void StartPhysicalUpdate(ContainerState s) {
|
||||
if (s.CloneType < 16) Alive = true;
|
||||
else if (s.CloneType == 17) Init();
|
||||
}
|
||||
protected virtual void PreAwake(ContainerState s) {
|
||||
if (gogroup) {
|
||||
gogroup.gameObject.SetActive(true);
|
||||
OpenAnchor(a_head);
|
||||
}
|
||||
Awoken = true; Alive = true;
|
||||
}
|
||||
protected virtual void Awake(ContainerState s) {
|
||||
if (gogroup) CloseAnchor();
|
||||
}
|
||||
protected virtual void GetPosition(ContainerState s) { }
|
||||
public virtual void StartUpdate(ContainerState s) {
|
||||
if (s.CloneType >= 2 && s.CloneType < 16) {
|
||||
PreAwake(s);
|
||||
Awake(s);
|
||||
}
|
||||
else if (s.CloneType == 17) {
|
||||
Init();
|
||||
}
|
||||
}
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
protected void PushAnchorEvent(double time, Anchor anchor) {
|
||||
var tev = anchorEvPool.Rent();
|
||||
tev.Time = time;
|
||||
tev.Container = Container;
|
||||
tev.Target = anchor;
|
||||
ts.Bus.PushTempEvent(tev);
|
||||
}
|
||||
public virtual void Discard(ContainerState s, StampedEvent ev) {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
anchorEvPool.Return((StampedEvent.Anchor)ev);
|
||||
}
|
||||
public virtual void StartLogicalUpdate(ContainerState s) { }
|
||||
public virtual void StartPreGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void StartGraphicalUpdate(ContainerState s) {
|
||||
if (gogroup) gogroup.gameObject.SetActive(true);
|
||||
}
|
||||
#endregion
|
||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
||||
if (flag) PreAwake(s);
|
||||
if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
|
||||
if (flag) Awake(s);
|
||||
}
|
||||
public virtual void ExUpdate(ContainerState s, StampedEvent ev) {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
if (s.CloneType == 3) SetPreGraphicalActive(true, s);
|
||||
else if (ev is StampedEvent.Anchor) {
|
||||
var tev = (StampedEvent.Anchor)ev;
|
||||
if (tev.Target == a_head) {
|
||||
SetGraphicalActive(true, s);
|
||||
}
|
||||
else if (tev.Target == a_tail) {
|
||||
SetGraphicalActive(false, s);
|
||||
}
|
||||
if (gogroup) {
|
||||
OpenAnchor(tev.Target);
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
@@ -163,28 +163,58 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
anchorEvPool.Return(tev);
|
||||
}
|
||||
else if (gogroup && s.CloneType == 2) skinContainer.MatchDynamic(s);
|
||||
}
|
||||
public virtual void MotionUpdate(byte ct, Chart.Motion ev) { }
|
||||
public virtual void EndUpdate(ContainerState s) {
|
||||
if (s.CloneType < 16) {
|
||||
Awoken = false;
|
||||
if (gogroup && s.CloneType <= 2) {
|
||||
OpenAnchor(a_tail);
|
||||
skinContainer.MatchDynamic(s);
|
||||
CloseAnchor();
|
||||
}
|
||||
#region End methods
|
||||
public virtual void EndGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void EndPreGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void EndLogicalUpdate(ContainerState s) { }
|
||||
public virtual void EndPhysicalUpdate(ContainerState s) { }
|
||||
public virtual void Dispose() {
|
||||
if (gogroup)
|
||||
GameObject.Destroy(gogroup.gameObject);
|
||||
Alive = false;
|
||||
}
|
||||
public virtual void DisposeAll() { }
|
||||
#endregion
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected static bool CanDoGraphicalUpdate(ContainerState s) { return s.CloneType >= 2 && s.CloneType < 16; }
|
||||
#region Anchor
|
||||
public virtual void Anchor() {
|
||||
foreach (var a in DynamicAnchors.Keys) DynamicAnchorSet[a] = false;
|
||||
skinContainer.MatchDynamic(cs);
|
||||
if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
|
||||
if (Alive) {
|
||||
if (!DynamicAnchorSet[_a_head]) PushAnchorEvent(cs.StampedContainer.Time, a_head, -1, true);
|
||||
if (!DynamicAnchorSet[_a_tail]) PushAnchorEvent(cs.StampedContainer.Time + cs.StampedContainer.Duration, a_tail, 1, true);
|
||||
}
|
||||
}
|
||||
public virtual void Anchor() {
|
||||
skinContainer.MatchDynamic(cs);
|
||||
if (cs.Working) PushAnchorEvent(cs.Time, a_cur);
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
public void PushAnchorEvent(double time, int name) {
|
||||
Anchor anchor;
|
||||
if (!DynamicAnchors.TryGetValue(name, out anchor))
|
||||
throw new ArgumentException(string.Format("Specified anchor \"{0}\" not found", IdentifierManager.SharedInstance.Retrieve(name)));
|
||||
if (DynamicAnchorSet[name])
|
||||
throw new InvalidOperationException(string.Format("Specified anchor \"{0}\" has been set", IdentifierManager.SharedInstance.Retrieve(name)));
|
||||
PushAnchorEvent(time, anchor);
|
||||
DynamicAnchorSet[name] = true;
|
||||
}
|
||||
protected void OpenAnchor(Anchor anchor) {
|
||||
if (OpenedAnchor != null) throw new InvalidOperationException("An anchor has been opened");
|
||||
OpenedAnchor = anchor;
|
||||
void PushAnchorEvent(double time, Anchor anchor, int priority = 0, bool forced = false) {
|
||||
var tev = anchorEvPool.Rent();
|
||||
tev.Time = time;
|
||||
tev.Container = Container;
|
||||
tev.Target = anchor;
|
||||
tev.CanDiscard = !forced;
|
||||
tev.SetPriority(priority);
|
||||
ts.Bus.PushTempEvent(tev);
|
||||
}
|
||||
protected void CloseAnchor() {
|
||||
OpenedAnchor = null;
|
||||
public virtual void Discard(ContainerState s, StampedEvent ev) {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
anchorEvPool.Return((StampedEvent.Anchor)ev);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
public class ContainerState {
|
||||
#region Struct
|
||||
public EventBus Bus;
|
||||
public EventContainer Container;
|
||||
public StampedEvent StampedContainer;
|
||||
@@ -15,9 +17,7 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public Dictionary<EventContainer, ContainerState> Children
|
||||
= new Dictionary<EventContainer, ContainerState>();
|
||||
readonly HashSet<EventContainer> WorkingChildren
|
||||
= new HashSet<EventContainer>();
|
||||
readonly HashSet<EventContainer> InvalidatedChildren
|
||||
HashSet<EventContainer> ActiveChildren
|
||||
= new HashSet<EventContainer>();
|
||||
public Dictionary<Type, List<ContainerState>> TypedChildren
|
||||
= new Dictionary<Type, List<ContainerState>>();
|
||||
@@ -29,28 +29,47 @@ namespace Cryville.Crtr.Event {
|
||||
return Children[ev];
|
||||
}
|
||||
|
||||
void NotifyWorkingChanged(EventContainer key) {
|
||||
InvalidatedChildren.Add(key);
|
||||
}
|
||||
void ValidateChildren() {
|
||||
foreach (var cev in InvalidatedChildren)
|
||||
if (Children[cev].Working && !WorkingChildren.Contains(cev)) WorkingChildren.Add(cev);
|
||||
else if (!Children[cev].Working && WorkingChildren.Contains(cev)) WorkingChildren.Remove(cev);
|
||||
InvalidatedChildren.Clear();
|
||||
}
|
||||
|
||||
public bool Active { get; set; }
|
||||
private bool m_Working;
|
||||
public bool Working {
|
||||
get { return m_Working; }
|
||||
set {
|
||||
m_Working = value;
|
||||
if (Parent != null) Parent.NotifyWorkingChanged(Container);
|
||||
Bus.NotifyWorkingChanged(this);
|
||||
private bool m_active;
|
||||
public bool Active {
|
||||
get { return m_active; }
|
||||
private set {
|
||||
if (m_active == value) return;
|
||||
m_active = value;
|
||||
if (!m_active && CloneType == 1) Dispose();
|
||||
if (Parent != null) {
|
||||
if (m_active) Parent.ActiveChildren.Add(Container);
|
||||
else Parent.ActiveChildren.Remove(Container);
|
||||
}
|
||||
Bus.NotifyActiveChanged(this);
|
||||
}
|
||||
}
|
||||
private bool m_lActive;
|
||||
public bool LogicalActive {
|
||||
get { return m_lActive; }
|
||||
set {
|
||||
if (m_lActive == value) return;
|
||||
m_lActive = value;
|
||||
UpdateActive();
|
||||
if (m_lActive) Handler.StartLogicalUpdate(this);
|
||||
else Handler.EndLogicalUpdate(this);
|
||||
}
|
||||
}
|
||||
private bool m_pActive;
|
||||
public bool PhysicalActive {
|
||||
get { return m_pActive; }
|
||||
set {
|
||||
if (m_pActive == value) return;
|
||||
m_pActive = value;
|
||||
UpdateActive();
|
||||
if (m_pActive) Handler.StartPhysicalUpdate(this);
|
||||
else Handler.EndPhysicalUpdate(this);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void UpdateActive() { Active = m_lActive || m_pActive; }
|
||||
|
||||
public byte CloneType;
|
||||
private ContainerState rootPrototype = null;
|
||||
public ContainerState rootPrototype = null;
|
||||
private ContainerState prototype = null;
|
||||
|
||||
public ContainerHandler Handler {
|
||||
@@ -64,35 +83,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
readonly RMVPool RMVPool = new RMVPool();
|
||||
readonly MotionCachePool MCPool = new MotionCachePool();
|
||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
||||
Dictionary<Identifier, RealtimeMotionValue> Values;
|
||||
Dictionary<Identifier, MotionCache> CachedValues;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a motion value.
|
||||
/// </summary>
|
||||
/// <param name="name">The motion name.</param>
|
||||
/// <param name="clone">Returns a cloned motion value instead.</param>
|
||||
/// <returns>A motion value.</returns>
|
||||
RealtimeMotionValue GetMotionValue(Identifier name, bool clone = false) {
|
||||
RealtimeMotionValue value = Values[name];
|
||||
if (clone) return value.Clone();
|
||||
return value;
|
||||
}
|
||||
|
||||
void InvalidateMotion(Identifier name) {
|
||||
MotionCache cache;
|
||||
if (!CachedValues.TryGetValue(name, out cache))
|
||||
CachedValues.Add(name, cache = MCPool.Rent(name));
|
||||
cache.Valid = false;
|
||||
ValidateChildren();
|
||||
foreach (var c in WorkingChildren)
|
||||
Children[c].InvalidateMotion(name);
|
||||
}
|
||||
|
||||
public ContainerState(Chart c, EventContainer _ev, ContainerState parent = null) {
|
||||
public ContainerState(EventContainer _ev, ContainerState parent = null) {
|
||||
Container = _ev;
|
||||
|
||||
if (parent != null) {
|
||||
@@ -104,6 +95,8 @@ namespace Cryville.Crtr.Event {
|
||||
CachedValues = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||
foreach (var m in ChartPlayer.motionRegistry)
|
||||
Values.Add(m.Key, new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue));
|
||||
|
||||
rootPrototype = this;
|
||||
}
|
||||
|
||||
static void AddChild(EventContainer c, ContainerState s, ContainerState target) {
|
||||
@@ -137,6 +130,8 @@ namespace Cryville.Crtr.Event {
|
||||
AddChild(child.Key, cc, r);
|
||||
}
|
||||
|
||||
r.ActiveChildren = new HashSet<EventContainer>();
|
||||
|
||||
var pms = new Dictionary<StampedEvent, RealtimeMotionValue>(Math.Max(4, PlayingMotions.Count));
|
||||
foreach (var m in PlayingMotions)
|
||||
pms.Add(m.Key, m.Value);
|
||||
@@ -148,14 +143,15 @@ namespace Cryville.Crtr.Event {
|
||||
else if (ct >= 16) Handler.ps = r;
|
||||
else throw new InvalidOperationException("Invalid clone type");
|
||||
r.prototype = this;
|
||||
if (prototype == null) r.rootPrototype = this;
|
||||
else r.rootPrototype = rootPrototype;
|
||||
r.CloneType = ct;
|
||||
return r;
|
||||
}
|
||||
|
||||
public void CopyTo(byte ct, ContainerState dest) {
|
||||
dest.Working = Working;
|
||||
dest.m_lActive = m_lActive;
|
||||
dest.m_pActive = m_pActive;
|
||||
dest.m_active = m_active;
|
||||
if (dest.m_active) dest.Bus.NotifyActiveChanged(dest);
|
||||
|
||||
foreach (var mv in Values) {
|
||||
RealtimeMotionValue dv;
|
||||
@@ -172,11 +168,15 @@ namespace Cryville.Crtr.Event {
|
||||
cv.Value.CopyTo(dv);
|
||||
}
|
||||
|
||||
if (ct != 1) foreach (var cev in WorkingChildren)
|
||||
foreach (var cev in dest.ActiveChildren) {
|
||||
if (!ActiveChildren.Contains(cev))
|
||||
Children[cev].CopyTo(ct, dest.Children[cev]);
|
||||
}
|
||||
dest.ActiveChildren.Clear();
|
||||
foreach (var cev in ActiveChildren) {
|
||||
dest.ActiveChildren.Add(cev);
|
||||
Children[cev].CopyTo(ct, dest.Children[cev]);
|
||||
else foreach (var child in Children)
|
||||
child.Value.CopyTo(ct, dest.Children[child.Key]);
|
||||
dest.ValidateChildren();
|
||||
}
|
||||
|
||||
dest.PlayingMotions.Clear();
|
||||
foreach (var m in PlayingMotions) dest.PlayingMotions.Add(m.Key, m.Value);
|
||||
@@ -189,12 +189,17 @@ namespace Cryville.Crtr.Event {
|
||||
public void Dispose() {
|
||||
if (Disposed) return;
|
||||
Disposed = true;
|
||||
if (CloneType < 16 && Handler != null) Handler.Dispose();
|
||||
if (CloneType == 1) Handler.Dispose();
|
||||
foreach (var s in Children)
|
||||
s.Value.Dispose();
|
||||
RMVPool.ReturnAll();
|
||||
MCPool.ReturnAll();
|
||||
}
|
||||
public void DisposeAll() {
|
||||
foreach (var s in Children)
|
||||
s.Value.DisposeAll();
|
||||
Handler.DisposeAll();
|
||||
}
|
||||
|
||||
public void AttachHandler(ContainerHandler h) {
|
||||
if (Handler != null)
|
||||
@@ -206,6 +211,35 @@ namespace Cryville.Crtr.Event {
|
||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||
Handler.AttachSystems(skin, judge);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Motion
|
||||
readonly RMVPool RMVPool = new RMVPool();
|
||||
readonly MotionCachePool MCPool = new MotionCachePool();
|
||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
||||
Dictionary<Identifier, RealtimeMotionValue> Values;
|
||||
Dictionary<Identifier, MotionCache> CachedValues;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a motion value.
|
||||
/// </summary>
|
||||
/// <param name="name">The motion name.</param>
|
||||
/// <param name="clone">Returns a cloned motion value instead.</param>
|
||||
/// <returns>A motion value.</returns>
|
||||
RealtimeMotionValue GetMotionValue(Identifier name, bool clone = false) {
|
||||
RealtimeMotionValue value = Values[name];
|
||||
if (clone) return value.Clone();
|
||||
return value;
|
||||
}
|
||||
|
||||
void InvalidateMotion(Identifier name) {
|
||||
MotionCache cache;
|
||||
if (!CachedValues.TryGetValue(name, out cache))
|
||||
CachedValues.Add(name, cache = MCPool.Rent(name));
|
||||
cache.Valid = false;
|
||||
foreach (var c in ActiveChildren)
|
||||
Children[c].InvalidateMotion(name);
|
||||
}
|
||||
|
||||
public Vector GetRawValue(Identifier key) {
|
||||
MotionCache tr;
|
||||
@@ -299,13 +333,15 @@ namespace Cryville.Crtr.Event {
|
||||
return GetRawValue<Vec1>(n_track).Value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Update
|
||||
bool breakflag = false;
|
||||
|
||||
public void Break() {
|
||||
Handler.EndUpdate(this);
|
||||
// Handler.EndLogicalUpdate(this);
|
||||
breakflag = true;
|
||||
Working = false;
|
||||
// LogicalActive = false;
|
||||
}
|
||||
|
||||
public void Discard(StampedEvent ev) {
|
||||
@@ -330,33 +366,26 @@ namespace Cryville.Crtr.Event {
|
||||
else if (ev.Unstamped is EventContainer) {
|
||||
var cev = (EventContainer)ev.Unstamped;
|
||||
var ccs = GetChild(cev);
|
||||
ccs.Working = true;
|
||||
ccs.StartUpdate();
|
||||
ccs.LogicalActive = true;
|
||||
UpdateMotions();
|
||||
if (!cev.IsLong) {
|
||||
ccs.Working = false;
|
||||
ccs.BroadcastEndUpdate();
|
||||
if (CloneType == 1) ccs.Dispose();
|
||||
ccs.LogicalActive = false;
|
||||
}
|
||||
}
|
||||
else if (ev.Unstamped is InstantEvent) {
|
||||
var tev = (InstantEvent)ev.Unstamped;
|
||||
if (tev.IsRelease) {
|
||||
var nev = tev.Original;
|
||||
if (nev is Chart.Motion) {
|
||||
Update(ev);
|
||||
var mv = PlayingMotions[ev.Origin];
|
||||
if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv);
|
||||
PlayingMotions.Remove(ev.Origin);
|
||||
}
|
||||
else if (nev is EventContainer) {
|
||||
var cev = (EventContainer)ev.Origin.Unstamped;
|
||||
var ccs = GetChild(cev);
|
||||
UpdateMotions();
|
||||
ccs.Working = false;
|
||||
ccs.BroadcastEndUpdate();
|
||||
if (CloneType == 1) ccs.Dispose();
|
||||
}
|
||||
else if (ev.Unstamped is ReleaseEvent) {
|
||||
var tev = (ReleaseEvent)ev.Unstamped;
|
||||
var nev = tev.Original;
|
||||
if (nev is Chart.Motion) {
|
||||
Update(ev);
|
||||
var mv = PlayingMotions[ev.Origin];
|
||||
if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv);
|
||||
PlayingMotions.Remove(ev.Origin);
|
||||
}
|
||||
else if (nev is EventContainer) {
|
||||
var cev = (EventContainer)ev.Origin.Unstamped;
|
||||
var ccs = GetChild(cev);
|
||||
UpdateMotions();
|
||||
ccs.LogicalActive = false;
|
||||
}
|
||||
}
|
||||
Update(ev.Unstamped == null || ev.Unstamped.Priority >= 0 ? ev : null);
|
||||
@@ -364,12 +393,10 @@ namespace Cryville.Crtr.Event {
|
||||
else Update(null);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void Update(StampedEvent ev) {
|
||||
UpdateMotions();
|
||||
if (ev == null || ev.Unstamped != null) Handler.Update(this, ev);
|
||||
else Handler.ExUpdate(this, ev);
|
||||
foreach (var m in PlayingMotions)
|
||||
Handler.MotionUpdate(CloneType, (Chart.Motion)m.Key.Unstamped);
|
||||
Handler.Update(this, ev);
|
||||
}
|
||||
|
||||
private void UpdateMotions() {
|
||||
@@ -414,14 +441,17 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
public void StartUpdate() {
|
||||
Handler.StartUpdate(this);
|
||||
public void EndPreGraphicalUpdate() {
|
||||
Handler.SetPreGraphicalActive(false, this);
|
||||
foreach (var ls in ActiveChildren) {
|
||||
Children[ls].EndPreGraphicalUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void BroadcastEndUpdate() {
|
||||
Handler.EndUpdate(this);
|
||||
foreach (var ls in Children.Values) {
|
||||
if (ls.Working) ls.BroadcastEndUpdate();
|
||||
public void EndGraphicalUpdate() {
|
||||
Handler.SetGraphicalActive(false, this);
|
||||
foreach (var ls in ActiveChildren) {
|
||||
Children[ls].EndGraphicalUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,5 +461,6 @@ namespace Cryville.Crtr.Event {
|
||||
if (ls.Handler.Alive) ls.Anchor();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
void AddEventContainer(EventContainer c, ContainerState parent = null) {
|
||||
var cs = new ContainerState(chart, c, parent);
|
||||
var cs = new ContainerState(c, parent);
|
||||
stateMap.Add(c, cs);
|
||||
if (parent == null) {
|
||||
cs.Depth = 0;
|
||||
@@ -84,13 +84,34 @@ namespace Cryville.Crtr.Event {
|
||||
Container = con
|
||||
};
|
||||
if (ev is EventContainer) {
|
||||
stateMap[(EventContainer)ev].StampedContainer = sev;
|
||||
var tev = (EventContainer)ev;
|
||||
stateMap[tev].StampedContainer = sev;
|
||||
stampedEvents.Add(new StampedEvent.ClipBehind {
|
||||
Container = con,
|
||||
Origin = sev,
|
||||
Time = etime + tev.Clip.Behind,
|
||||
});
|
||||
if (!ev.IsLong) {
|
||||
stampedEvents.Add(new StampedEvent.ClipAhead {
|
||||
Container = con,
|
||||
Origin = sev,
|
||||
Time = etime + tev.Clip.Ahead,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (ev is InstantEvent) {
|
||||
var tev = (InstantEvent)ev;
|
||||
var pev = map[tev.Original];
|
||||
pev.Subevents.Add(sev);
|
||||
if (ev is ReleaseEvent) {
|
||||
var tev = (ReleaseEvent)ev;
|
||||
var oev = tev.Original;
|
||||
var pev = map[oev];
|
||||
pev.ReleaseEvent = sev;
|
||||
sev.Origin = pev;
|
||||
if (oev is EventContainer) {
|
||||
stampedEvents.Add(new StampedEvent.ClipAhead {
|
||||
Container = con,
|
||||
Origin = pev,
|
||||
Time = etime + ((EventContainer)oev).Clip.Ahead,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (con != null && coevents.Contains(ev)) {
|
||||
List<StampedEvent> cevs;
|
||||
|
||||
@@ -11,31 +11,27 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
Dictionary<EventContainer, ContainerState> states
|
||||
= new Dictionary<EventContainer, ContainerState>();
|
||||
HashSet<EventContainer> activeContainers
|
||||
= new HashSet<EventContainer>();
|
||||
HashSet<ContainerState> workingStates
|
||||
HashSet<ContainerState> activeStates
|
||||
= new HashSet<ContainerState>();
|
||||
HashSet<ContainerState> invalidatedStates
|
||||
= new HashSet<ContainerState>();
|
||||
public int ActiveStateCount { get { return activeStates.Count; } }
|
||||
|
||||
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
||||
RootState = root;
|
||||
Expand();
|
||||
AttachBus();
|
||||
RootState.Working = true;
|
||||
}
|
||||
|
||||
public EventBus Clone(byte ct, float offsetTime = 0) {
|
||||
var r = (EventBus)MemberwiseClone();
|
||||
r.prototype = this;
|
||||
r.states = new Dictionary<EventContainer, ContainerState>();
|
||||
r.activeContainers = new HashSet<EventContainer>();
|
||||
r.workingStates = new HashSet<ContainerState>();
|
||||
r.activeStates = new HashSet<ContainerState>();
|
||||
r.invalidatedStates = new HashSet<ContainerState>();
|
||||
r.tempEvents = new List<StampedEvent>();
|
||||
r.tempEvents = new List<StampedEvent.Temporary>();
|
||||
r.Time += offsetTime;
|
||||
r.RootState = RootState.Clone(ct);
|
||||
r.RootState.StartUpdate();
|
||||
r.Expand();
|
||||
r.AttachBus();
|
||||
foreach (var s in r.states) r.invalidatedStates.Add(s.Value);
|
||||
@@ -45,26 +41,20 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public void CopyTo(byte ct, EventBus dest) {
|
||||
base.CopyTo(dest);
|
||||
dest.workingStates.Clear();
|
||||
dest.activeStates.Clear();
|
||||
dest.invalidatedStates.Clear();
|
||||
RootState.CopyTo(ct, dest.RootState);
|
||||
if (ct >= 2) {
|
||||
dest.activeContainers.Clear();
|
||||
foreach (var c in activeContainers) {
|
||||
if (states[c].Working) {
|
||||
states[c].CopyTo(ct, dest.states[c]);
|
||||
dest.activeContainers.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
dest.ValidateStates();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
RootState.Dispose();
|
||||
}
|
||||
public void DisposeAll() {
|
||||
RootState.DisposeAll();
|
||||
}
|
||||
|
||||
public void NotifyWorkingChanged(ContainerState state) {
|
||||
public void NotifyActiveChanged(ContainerState state) {
|
||||
if (!invalidatedStates.Contains(state)) invalidatedStates.Add(state);
|
||||
}
|
||||
|
||||
@@ -83,22 +73,6 @@ namespace Cryville.Crtr.Event {
|
||||
s.Bus = this;
|
||||
}
|
||||
|
||||
void EnsureActivity(EventContainer c) {
|
||||
if (activeContainers.Contains(c)) return;
|
||||
var state = states[c];
|
||||
if (state.Parent != null) EnsureActivity(state.Parent.Container);
|
||||
if (RootState.CloneType >= 2) prototype.states[c].CopyTo(RootState.CloneType, state);
|
||||
state.Active = true;
|
||||
activeContainers.Add(c);
|
||||
|
||||
if (state.StampedContainer.Coevents == null) return;
|
||||
foreach (var cev in state.StampedContainer.Coevents) {
|
||||
if (cev.Container == null) continue;
|
||||
EnsureActivity(cev.Container);
|
||||
states[cev.Container].Handle(cev);
|
||||
}
|
||||
}
|
||||
|
||||
void AttachBus() {
|
||||
foreach (var s in states.Values)
|
||||
s.Bus = this;
|
||||
@@ -109,25 +83,31 @@ namespace Cryville.Crtr.Event {
|
||||
s.AttachSystems(skin, judge);
|
||||
}
|
||||
|
||||
List<StampedEvent> tempEvents = new List<StampedEvent>();
|
||||
public void PushTempEvent(StampedEvent ev) {
|
||||
List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>();
|
||||
public void PushTempEvent(StampedEvent.Temporary ev) {
|
||||
var index = tempEvents.BinarySearch(ev);
|
||||
if (index < 0) index = ~index;
|
||||
tempEvents.Insert(index, ev);
|
||||
}
|
||||
|
||||
readonly StampedEvent _dummyEvent = new StampedEvent();
|
||||
readonly StampedEvent.Temporary _dummyEvent = new StampedEvent.Temporary();
|
||||
public void StripTempEvents() {
|
||||
_dummyEvent.Time = Time;
|
||||
var index = tempEvents.BinarySearch(_dummyEvent);
|
||||
if (index < 0) index = ~index;
|
||||
for (var i = 0; i < index; i++) {
|
||||
for (var i = index - 1; i >= 0; i--) {
|
||||
var ev = tempEvents[i];
|
||||
if (ev.Container != null) {
|
||||
states[ev.Container].Discard(ev);
|
||||
tempEvents.RemoveAt(i);
|
||||
if (ev.CanDiscard) {
|
||||
if (ev.Container != null) {
|
||||
states[ev.Container].Discard(ev);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ev.Time = Time;
|
||||
PushTempEvent(ev);
|
||||
}
|
||||
}
|
||||
tempEvents.RemoveRange(0, index);
|
||||
}
|
||||
|
||||
public override void ForwardOnceToTime(double toTime) {
|
||||
@@ -136,18 +116,26 @@ namespace Cryville.Crtr.Event {
|
||||
double time0 = Math.Min(time1, time2);
|
||||
if (time0 <= toTime && time0 != double.PositiveInfinity) {
|
||||
Time = time0;
|
||||
foreach (var s in workingStates) s.Handle(null);
|
||||
foreach (var s in activeStates) s.Handle(null);
|
||||
ValidateStates();
|
||||
if (time1 == time0) {
|
||||
var batch = Events[EventId];
|
||||
for (var i = 0; i < batch.Count; i++) {
|
||||
var ev = batch[i];
|
||||
if (ev.Container != null) {
|
||||
if (ev.Unstamped is EventContainer) EnsureActivity((EventContainer)ev.Unstamped);
|
||||
else EnsureActivity(ev.Container);
|
||||
if (ev is StampedEvent.ClipBehind) {
|
||||
var cevs = ev.Origin.Coevents;
|
||||
if (cevs != null) foreach (var cev in cevs) {
|
||||
if (cev.Container == null) continue;
|
||||
states[cev.Container].Handle(cev);
|
||||
}
|
||||
states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = true;
|
||||
}
|
||||
else if (ev is StampedEvent.ClipAhead) {
|
||||
states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = false;
|
||||
}
|
||||
else if (ev.Container != null) {
|
||||
states[ev.Container].Handle(ev);
|
||||
}
|
||||
else if (ev.Coevents != null) EnsureActivity((EventContainer)ev.Unstamped);
|
||||
}
|
||||
EventId++;
|
||||
}
|
||||
@@ -156,25 +144,23 @@ namespace Cryville.Crtr.Event {
|
||||
var ev = tempEvents[0];
|
||||
if (ev.Time != time0) break;
|
||||
if (ev.Container != null) {
|
||||
EnsureActivity(ev.Container);
|
||||
states[ev.Container].Handle(ev);
|
||||
}
|
||||
tempEvents.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
ValidateStates();
|
||||
}
|
||||
else {
|
||||
Time = toTime;
|
||||
foreach (var s in workingStates) s.Handle(null);
|
||||
ValidateStates();
|
||||
foreach (var s in activeStates) s.Handle(null);
|
||||
}
|
||||
ValidateStates();
|
||||
}
|
||||
|
||||
private void ValidateStates() {
|
||||
foreach (var s in invalidatedStates)
|
||||
if (s.Working && !workingStates.Contains(s)) workingStates.Add(s);
|
||||
else if (!s.Working && workingStates.Contains(s)) workingStates.Remove(s);
|
||||
if (s.Active && !activeStates.Contains(s)) activeStates.Add(s);
|
||||
else if (!s.Active && activeStates.Contains(s)) activeStates.Remove(s);
|
||||
invalidatedStates.Clear();
|
||||
}
|
||||
|
||||
@@ -185,13 +171,21 @@ namespace Cryville.Crtr.Event {
|
||||
RootState.BroadcastPostInit();
|
||||
}
|
||||
|
||||
public void BroadcastEndUpdate() {
|
||||
RootState.BroadcastEndUpdate();
|
||||
public void EndPreGraphicalUpdate() {
|
||||
RootState.EndPreGraphicalUpdate();
|
||||
}
|
||||
public void EndGraphicalUpdate() {
|
||||
RootState.EndGraphicalUpdate();
|
||||
foreach (var ev in tempEvents) {
|
||||
if (ev.Container != null) {
|
||||
states[ev.Container].Discard(ev);
|
||||
}
|
||||
}
|
||||
tempEvents.Clear();
|
||||
}
|
||||
|
||||
public void Anchor() {
|
||||
RootState.Anchor();
|
||||
if (RootState.Handler.Alive) RootState.Anchor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Cryville.Audio;
|
||||
using Cryville.Audio.Source;
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Font;
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common.Unity.Input;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using FFmpeg.AutoGen;
|
||||
using Ionic.Zip;
|
||||
using Newtonsoft.Json;
|
||||
@@ -127,6 +129,21 @@ namespace Cryville.Crtr {
|
||||
Settings.Default.LastRunVersion = Application.version;
|
||||
Settings.Default.Save();
|
||||
|
||||
Logger.Log("main", 1, "UI", "Initializing font manager");
|
||||
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
||||
var fontMatcher = new FallbackListFontMatcher(new FontManagerWindows());
|
||||
fontMatcher.LoadDefaultWindowsFallbackList();
|
||||
TMPAutoFont.FontMatcher = fontMatcher;
|
||||
TMPAutoFont.DefaultShader = Resources.Load<Shader>("TextMesh Pro/Shaders/TMP_SDF SSD");
|
||||
#elif UNITY_ANDROID
|
||||
var fontMatcher = new FallbackListFontMatcher(new FontManagerAndroid());
|
||||
fontMatcher.LoadDefaultAndroidFallbackList();
|
||||
TMPAutoFont.FontMatcher = fontMatcher;
|
||||
TMPAutoFont.DefaultShader = Resources.Load<Shader>("TextMesh Pro/Shaders/TMP_SDF-Mobile SSD");
|
||||
#else
|
||||
#error No font manager initialization logic.
|
||||
#endif
|
||||
|
||||
Logger.Log("main", 1, "Game", "Initialized");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,7 @@ namespace Cryville.Crtr {
|
||||
this.ch = ch;
|
||||
}
|
||||
|
||||
public override string TypeName {
|
||||
get {
|
||||
return "group";
|
||||
}
|
||||
}
|
||||
public override string TypeName { get { return "group"; } }
|
||||
|
||||
public override void PreInit() {
|
||||
base.PreInit();
|
||||
|
||||
@@ -4,6 +4,7 @@ using Cryville.Common.Pdt;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.Formatting;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class Judge {
|
||||
@@ -34,6 +35,10 @@ namespace Cryville.Crtr {
|
||||
public Judge(PdtRuleset rs) {
|
||||
_etor = ChartPlayer.etor;
|
||||
_rs = rs;
|
||||
_numsrc1 = new PropSrc.Float(() => _numbuf1);
|
||||
_numsrc2 = new PropSrc.Float(() => _numbuf2);
|
||||
_numsrc3 = new PropSrc.Float(() => _numbuf3);
|
||||
_numsrc4 = new PropSrc.Float(() => _numbuf4);
|
||||
InitJudges();
|
||||
InitScores();
|
||||
}
|
||||
@@ -52,8 +57,8 @@ namespace Cryville.Crtr {
|
||||
var ev = new JudgeEvent {
|
||||
StartTime = st,
|
||||
EndTime = et,
|
||||
StartClip = st + def.clip[0],
|
||||
EndClip = et + def.clip[1],
|
||||
StartClip = st + def.clip.Behind,
|
||||
EndClip = et + def.clip.Ahead,
|
||||
BaseEvent = tev,
|
||||
Definition = def,
|
||||
Handler = handler,
|
||||
@@ -65,13 +70,9 @@ namespace Cryville.Crtr {
|
||||
#endregion
|
||||
#region Judge
|
||||
internal readonly Dictionary<int, int> judgeMap = new Dictionary<int, int>();
|
||||
internal readonly Dictionary<int, int> jtabsMap = new Dictionary<int, int>();
|
||||
internal readonly Dictionary<int, int> jtrelMap = new Dictionary<int, int>();
|
||||
void InitJudges() {
|
||||
foreach (var i in _rs.judges.Keys) {
|
||||
judgeMap.Add(i.Key, IdentifierManager.SharedInstance.Request("judge_" + i.Name));
|
||||
jtabsMap.Add(i.Key, IdentifierManager.SharedInstance.Request("jtabs_" + i.Name));
|
||||
jtrelMap.Add(i.Key, IdentifierManager.SharedInstance.Request("jtrel_" + i.Name));
|
||||
}
|
||||
}
|
||||
static bool _flag;
|
||||
@@ -80,10 +81,8 @@ namespace Cryville.Crtr {
|
||||
static readonly int _var_tn = IdentifierManager.SharedInstance.Request("tn");
|
||||
static readonly int _var_ft = IdentifierManager.SharedInstance.Request("ft");
|
||||
static readonly int _var_tt = IdentifierManager.SharedInstance.Request("tt");
|
||||
readonly byte[] _numbuf1 = new byte[sizeof(float)];
|
||||
readonly byte[] _numbuf2 = new byte[sizeof(float)];
|
||||
readonly byte[] _numbuf3 = new byte[sizeof(float)];
|
||||
readonly byte[] _numbuf4 = new byte[sizeof(float)];
|
||||
float _numbuf1, _numbuf2, _numbuf3, _numbuf4;
|
||||
readonly PropSrc _numsrc1, _numsrc2, _numsrc3, _numsrc4;
|
||||
unsafe void LoadNum(byte[] buffer, float value) {
|
||||
fixed (byte* ptr = buffer) *(float*)ptr = value;
|
||||
}
|
||||
@@ -120,13 +119,13 @@ namespace Cryville.Crtr {
|
||||
Forward(target, tt);
|
||||
var actlist = activeEvs[target];
|
||||
if (actlist.Count > 0) {
|
||||
LoadNum(_numbuf3, ft); _etor.ContextCascadeUpdate(_var_ft, new PropSrc.Arbitrary(PdtInternalType.Number, _numbuf3));
|
||||
LoadNum(_numbuf4, tt); _etor.ContextCascadeUpdate(_var_tt, new PropSrc.Arbitrary(PdtInternalType.Number, _numbuf4));
|
||||
_numbuf3 = ft; _numsrc3.Invalidate(); _etor.ContextCascadeUpdate(_var_ft, _numsrc3);
|
||||
_numbuf4 = tt; _numsrc4.Invalidate(); _etor.ContextCascadeUpdate(_var_tt, _numsrc4);
|
||||
var index = 0;
|
||||
while (index >= 0 && index < actlist.Count) {
|
||||
var ev = actlist[index];
|
||||
LoadNum(_numbuf1, (float)ev.StartTime); _etor.ContextCascadeUpdate(_var_fn, new PropSrc.Arbitrary(PdtInternalType.Number, _numbuf1));
|
||||
LoadNum(_numbuf2, (float)ev.EndTime); _etor.ContextCascadeUpdate(_var_tn, new PropSrc.Arbitrary(PdtInternalType.Number, _numbuf2));
|
||||
_numbuf1 = (float)ev.StartTime; _numsrc1.Invalidate(); _etor.ContextCascadeUpdate(_var_fn, _numsrc1);
|
||||
_numbuf2 = (float)ev.EndTime; _numsrc2.Invalidate(); _etor.ContextCascadeUpdate(_var_tn, _numsrc2);
|
||||
var def = ev.Definition;
|
||||
if (def.hit != null) _etor.Evaluate(_flagop, def.hit);
|
||||
else _flag = true;
|
||||
@@ -206,6 +205,9 @@ namespace Cryville.Crtr {
|
||||
readonly Dictionary<int, string> scoreStringCache = new Dictionary<int, string>();
|
||||
readonly Dictionary<int, PropSrc> scoreStringSrcs = new Dictionary<int, PropSrc>();
|
||||
readonly ArrayPool<byte> scoreStringPool = new ArrayPool<byte>();
|
||||
readonly Dictionary<int, string> scoreFormatCache = new Dictionary<int, string>();
|
||||
readonly TargetString scoreFullStr = new TargetString();
|
||||
readonly StringBuffer scoreFullBuf = new StringBuffer();
|
||||
void InitScores() {
|
||||
foreach (var s in _rs.scores) {
|
||||
var key = s.Key.Key;
|
||||
@@ -217,7 +219,8 @@ namespace Cryville.Crtr {
|
||||
scoreDefs.Add(key, s.Value);
|
||||
scores.Add(key, s.Value.init);
|
||||
scoreStringCache.Add(scoreStringKeys[key], null);
|
||||
scoreStringSrcs.Add(scoreStringKeys[key], new ScoreStringSrc(scoreStringPool, () => GetScoreString(strkey)));
|
||||
scoreStringSrcs.Add(scoreStringKeys[key], new ScoreStringSrc(scoreStringPool, () => scores[key], scoreDefs[key].format));
|
||||
scoreFormatCache[key] = string.Format("{{0:{0}}}", s.Value.format);
|
||||
}
|
||||
}
|
||||
void InvalidateScore(int key) {
|
||||
@@ -225,54 +228,52 @@ namespace Cryville.Crtr {
|
||||
scoreStringCache[scoreStringKeys[key]] = null;
|
||||
scoreStringSrcs[scoreStringKeys[key]].Invalidate();
|
||||
}
|
||||
string GetScoreString(int key) {
|
||||
var result = scoreStringCache[key];
|
||||
if (result == null) {
|
||||
var rkey = scoreStringKeysRev[key];
|
||||
return scoreStringCache[key] = scores[rkey].ToString(scoreDefs[rkey].format, CultureInfo.InvariantCulture);
|
||||
}
|
||||
else return result;
|
||||
}
|
||||
public bool TryGetScoreSrc(int key, out PropSrc value) {
|
||||
return scoreSrcs.TryGetValue(key, out value);
|
||||
}
|
||||
public bool TryGetScoreStringSrc(int key, out PropSrc value) {
|
||||
return scoreStringSrcs.TryGetValue(key, out value);
|
||||
}
|
||||
public string GetFullFormattedScoreString() {
|
||||
public TargetString GetFullFormattedScoreString() {
|
||||
bool flag = false;
|
||||
string result = "";
|
||||
scoreFullBuf.Clear();
|
||||
foreach (var s in scores.Keys) {
|
||||
result += string.Format(flag ? "\n{0}: {1}" : "{0}: {1}", IdentifierManager.SharedInstance.Retrieve(s), GetScoreString(scoreStringKeys[s]));
|
||||
scoreFullBuf.AppendFormat(flag ? "\n{0}: " : "{0}: ", (string)IdentifierManager.SharedInstance.Retrieve(s));
|
||||
scoreFullBuf.AppendFormat(scoreFormatCache[s], scores[s]);
|
||||
flag = true;
|
||||
}
|
||||
return result;
|
||||
scoreFullStr.Length = scoreFullBuf.Count;
|
||||
var arr = scoreFullStr.TrustedAsArray();
|
||||
scoreFullBuf.CopyTo(0, arr, 0, scoreFullBuf.Count);
|
||||
return scoreFullStr;
|
||||
}
|
||||
class ScoreStringSrc : PropSrc {
|
||||
readonly Func<string> _cb;
|
||||
readonly Func<float> _cb;
|
||||
readonly string _format;
|
||||
readonly ArrayPool<byte> _pool;
|
||||
byte[] _buf;
|
||||
public ScoreStringSrc(ArrayPool<byte> pool, Func<string> cb)
|
||||
readonly StringBuffer _buf = new StringBuffer() { Culture = CultureInfo.InvariantCulture };
|
||||
public ScoreStringSrc(ArrayPool<byte> pool, Func<float> cb, string format)
|
||||
: base(PdtInternalType.String) {
|
||||
_pool = pool;
|
||||
_cb = cb;
|
||||
_format = string.Format("{{0:{0}}}", format);
|
||||
}
|
||||
public override void Invalidate() {
|
||||
base.Invalidate();
|
||||
if (_buf != null) {
|
||||
_pool.Return(_buf);
|
||||
_buf = null;
|
||||
if (buf != null) {
|
||||
_pool.Return(buf);
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
protected override unsafe void InternalGet() {
|
||||
var src = _cb();
|
||||
int strlen = src.Length;
|
||||
_buf.Clear();
|
||||
_buf.AppendFormat(_format, src);
|
||||
int strlen = _buf.Count;
|
||||
buf = _pool.Rent(sizeof(int) + strlen * sizeof(char));
|
||||
fixed (byte* _ptr = buf) {
|
||||
char* ptr = (char*)(_ptr + sizeof(int));
|
||||
*(int*)_ptr = strlen;
|
||||
int i = 0;
|
||||
foreach (var c in src) ptr[i++] = c;
|
||||
char* ptr = (char*)(_ptr + sizeof(int));
|
||||
_buf.CopyTo(ptr, 0, strlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,7 +286,7 @@ namespace Cryville.Crtr {
|
||||
public Dictionary<Identifier, PdtExpression> pass;
|
||||
}
|
||||
public class JudgeDefinition {
|
||||
public float[] clip;
|
||||
public Clip clip;
|
||||
public PdtExpression input;
|
||||
public PdtExpression hit;
|
||||
public Identifier[] pass;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ceefede648e4d6d40839f2dda9019066
|
||||
timeCreated: 1637222453
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -500
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
||||
@@ -15,57 +15,38 @@ namespace Cryville.Crtr {
|
||||
this.gh = gh;
|
||||
}
|
||||
|
||||
public override string TypeName {
|
||||
get {
|
||||
return "note";
|
||||
}
|
||||
}
|
||||
public override string TypeName { get { return "note"; } }
|
||||
|
||||
SectionalGameObject[] sgos;
|
||||
readonly Dictionary<Chart.Judge, JudgeState> judges = new Dictionary<Chart.Judge, JudgeState>();
|
||||
readonly Dictionary<int, DynamicJudgeAnchorPair> dynJudgeAnchors = new Dictionary<int, DynamicJudgeAnchorPair>();
|
||||
class JudgeState {
|
||||
static readonly int _var_judge_result = IdentifierManager.SharedInstance.Request("judge_result");
|
||||
static readonly int _var_judge_time_absolute = IdentifierManager.SharedInstance.Request("judge_time_absolute");
|
||||
static readonly int _var_judge_time_relative = IdentifierManager.SharedInstance.Request("judge_time_relative");
|
||||
public Anchor StaticAnchor { get; private set; }
|
||||
public DynamicJudgeAnchorPair DynamicAnchors { get; private set; }
|
||||
public bool Judged { get; private set; }
|
||||
public float AbsoluteTime { get; private set; }
|
||||
PropSrc _jtabsPropSrc;
|
||||
public float RelativeTime { get; private set; }
|
||||
int _result = 0;
|
||||
PropSrc _jtrelPropSrc;
|
||||
public int Result { get; private set; }
|
||||
PropSrc _resultPropSrc;
|
||||
public JudgeState(NoteHandler handler, int name) {
|
||||
StaticAnchor = handler.RegisterAnchor(handler.judge.judgeMap[name], true);
|
||||
DynamicAnchors = handler.GetDynamicJudgeAnchorPair(name);
|
||||
StaticAnchor = handler.RegisterAnchor(handler.judge.judgeMap[name], false, 3);
|
||||
}
|
||||
public void MarkJudged(float abs, float rel, int result) {
|
||||
Judged = true;
|
||||
AbsoluteTime = abs;
|
||||
RelativeTime = rel;
|
||||
_result = result;
|
||||
Result = result;
|
||||
_jtabsPropSrc.Invalidate();
|
||||
_jtrelPropSrc.Invalidate();
|
||||
_resultPropSrc.Invalidate();
|
||||
}
|
||||
public void InitPropSrcs() {
|
||||
StaticAnchor.PropSrcs.Add(_var_judge_result, _resultPropSrc = new PropSrc.Identifier(() => _result));
|
||||
StaticAnchor.PropSrcs.Add(_var_judge_result, _resultPropSrc = new PropSrc.Identifier(() => Result));
|
||||
StaticAnchor.PropSrcs.Add(_var_judge_time_absolute, _jtabsPropSrc = new PropSrc.Float(() => AbsoluteTime));
|
||||
StaticAnchor.PropSrcs.Add(_var_judge_time_relative, _jtrelPropSrc = new PropSrc.Float(() => RelativeTime));
|
||||
}
|
||||
}
|
||||
class DynamicJudgeAnchorPair {
|
||||
public Anchor Absolute { get; private set; }
|
||||
public Anchor Relative { get; private set; }
|
||||
public DynamicJudgeAnchorPair(Anchor absolute, Anchor relative) {
|
||||
Absolute = absolute;
|
||||
Relative = relative;
|
||||
}
|
||||
}
|
||||
DynamicJudgeAnchorPair GetDynamicJudgeAnchorPair(int name) {
|
||||
DynamicJudgeAnchorPair result;
|
||||
if (!dynJudgeAnchors.TryGetValue(name, out result)) {
|
||||
dynJudgeAnchors.Add(name, result = new DynamicJudgeAnchorPair(
|
||||
RegisterAnchor(judge.jtabsMap[name]),
|
||||
RegisterAnchor(judge.jtrelMap[name])
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void PreInit() {
|
||||
base.PreInit();
|
||||
@@ -78,19 +59,17 @@ namespace Cryville.Crtr {
|
||||
sgos = gogroup.GetComponentsInChildren<SectionalGameObject>();
|
||||
foreach (var judge in judges.Values) judge.InitPropSrcs();
|
||||
}
|
||||
protected override void PreAwake(ContainerState s) {
|
||||
base.PreAwake(s);
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
a_head.Transform.SetPositionAndRotation(Position = GetFramePoint(s.Parent, s.Track), Rotation = GetFrameRotation(s.Parent, s.Track));
|
||||
#else
|
||||
a_head.Transform.position = Position = GetFramePoint(s.Parent, s.Track);
|
||||
a_head.Transform.rotation = Rotation = GetFrameRotation(s.Parent, s.Track);
|
||||
#endif
|
||||
}
|
||||
protected override void Awake(ContainerState s) {
|
||||
base.Awake(s);
|
||||
|
||||
public override void StartPhysicalUpdate(ContainerState s) {
|
||||
base.StartPhysicalUpdate(s);
|
||||
if (s.CloneType == 2) {
|
||||
if (!gogroup) return;
|
||||
TransformAwake(s);
|
||||
}
|
||||
}
|
||||
public override void StartGraphicalUpdate(ContainerState s) {
|
||||
base.StartGraphicalUpdate(s);
|
||||
TransformAwake(s);
|
||||
if (gogroup) {
|
||||
if (Event.IsLong) {
|
||||
foreach (var i in sgos) {
|
||||
i.Reset();
|
||||
@@ -107,17 +86,18 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
void TransformAwake(ContainerState s) {
|
||||
Position = GetFramePoint(s.Parent, s.Track);
|
||||
Rotation = GetFrameRotation(s.Parent, s.Track);
|
||||
}
|
||||
|
||||
public override void Update(ContainerState s, StampedEvent ev) {
|
||||
base.Update(s, ev);
|
||||
if (s.CloneType <= 2) {
|
||||
Position = GetFramePoint(s.Parent, s.Track);
|
||||
Rotation = GetFrameRotation(s.Parent, s.Track);
|
||||
}
|
||||
if (s.CloneType == 2) {
|
||||
if (!gogroup) return;
|
||||
Chart.Note tev = Event;
|
||||
if (tev.IsLong) {
|
||||
if (s.CloneType == 2) {
|
||||
if (!gogroup || !Event.IsLong) return;
|
||||
foreach (var i in sgos)
|
||||
i.AppendPoint(Position, Rotation);
|
||||
}
|
||||
@@ -135,26 +115,11 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public override void Anchor() {
|
||||
base.Anchor();
|
||||
foreach (var j in judges.Values) {
|
||||
if (!j.Judged) continue;
|
||||
PushAnchorEvent(j.AbsoluteTime, j.DynamicAnchors.Absolute);
|
||||
PushAnchorEvent(j.RelativeTime + cs.Time, j.DynamicAnchors.Relative);
|
||||
}
|
||||
}
|
||||
|
||||
public override void EndUpdate(ContainerState s) {
|
||||
if (s.CloneType == 2 && gogroup) {
|
||||
public override void EndGraphicalUpdate(ContainerState s) {
|
||||
if (gogroup) {
|
||||
foreach (var i in sgos) i.Seal();
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
a_tail.Transform.SetPositionAndRotation(GetFramePoint(ts.Parent, ts.Track), Quaternion.Euler(ts.Direction));
|
||||
#else
|
||||
a_tail.Transform.position = GetFramePoint(ts.Parent, ts.Track);
|
||||
a_tail.Transform.rotation = Quaternion.Euler(ts.Direction);
|
||||
#endif
|
||||
}
|
||||
base.EndUpdate(s);
|
||||
base.EndGraphicalUpdate(s);
|
||||
}
|
||||
|
||||
Vector3 GetFramePoint(ContainerState state, float track) {
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Cryville.Crtr {
|
||||
readonly byte[] _numbuf = new byte[4];
|
||||
static readonly int _var_w = IdentifierManager.SharedInstance.Request("w");
|
||||
static readonly int _var_h = IdentifierManager.SharedInstance.Request("h");
|
||||
static readonly int _var_current_time = IdentifierManager.SharedInstance.Request("current_time");
|
||||
static readonly int _var_true = IdentifierManager.SharedInstance.Request("true");
|
||||
static readonly int _var_false = IdentifierManager.SharedInstance.Request("false");
|
||||
static readonly int _var_null = IdentifierManager.SharedInstance.Request("null");
|
||||
@@ -34,6 +35,11 @@ namespace Cryville.Crtr {
|
||||
var vec = ContextState.GetRawValue(id);
|
||||
VectorSrc.Construct(() => vec).Get(out type, out value);
|
||||
}
|
||||
else if (ContextState != null && name == _var_current_time) {
|
||||
LoadNum((float)ContextState.rootPrototype.Time);
|
||||
type = PdtInternalType.Number;
|
||||
value = _numbuf;
|
||||
}
|
||||
else if (ContextJudge != null && ContextJudge.TryGetScoreSrc(name, out prop)) {
|
||||
prop.Get(out type, out value);
|
||||
RevokePotentialConstant();
|
||||
|
||||
@@ -4,11 +4,13 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using RBeatTime = Cryville.Crtr.BeatTime;
|
||||
using RClip = Cryville.Crtr.Clip;
|
||||
using RTargetString = Cryville.Common.Buffers.TargetString;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public abstract class PropOp : PdtOperator {
|
||||
internal PropOp() : base(1) { }
|
||||
protected PropOp() : base(1) { }
|
||||
protected PropOp(int pc) : base(pc) { }
|
||||
public class Arbitrary : PropOp {
|
||||
public int Name { get; set; }
|
||||
protected override void Execute() {
|
||||
@@ -25,6 +27,15 @@ namespace Cryville.Crtr {
|
||||
_cb(GetOperand(0).AsNumber() > 0);
|
||||
}
|
||||
}
|
||||
public class Clip : PropOp {
|
||||
readonly Action<RClip> _cb;
|
||||
public Clip(Action<RClip> cb) : base(2) { _cb = cb; }
|
||||
protected override void Execute() {
|
||||
if (LoadedOperandCount < 2)
|
||||
throw new ArgumentException("Invalid clip syntax");
|
||||
_cb(new RClip(GetOperand(0).AsNumber(), GetOperand(1).AsNumber()));
|
||||
}
|
||||
}
|
||||
public class Integer : PropOp {
|
||||
readonly Action<int> _cb;
|
||||
public Integer(Action<int> cb) { _cb = cb; }
|
||||
|
||||
@@ -17,6 +17,15 @@ namespace Cryville.Crtr {
|
||||
value = buf;
|
||||
}
|
||||
protected abstract void InternalGet();
|
||||
public abstract class FixedBuffer : PropSrc {
|
||||
bool m_invalidated = true;
|
||||
protected override bool Invalidated { get { return m_invalidated; } }
|
||||
public override void Invalidate() { m_invalidated = true; }
|
||||
public FixedBuffer(int type, int size) : base(type) { buf = new byte[size]; }
|
||||
protected override void InternalGet() {
|
||||
m_invalidated = false;
|
||||
}
|
||||
}
|
||||
public class Arbitrary : PropSrc {
|
||||
readonly byte[] _value;
|
||||
public Arbitrary(int type, byte[] value) : base(type) {
|
||||
@@ -26,25 +35,19 @@ namespace Cryville.Crtr {
|
||||
buf = _value;
|
||||
}
|
||||
}
|
||||
public class Boolean : PropSrc {
|
||||
public class Boolean : FixedBuffer {
|
||||
readonly Func<bool> _cb;
|
||||
bool m_invalidated = true;
|
||||
protected override bool Invalidated { get { return m_invalidated; } }
|
||||
public override void Invalidate() { m_invalidated = true; }
|
||||
public Boolean(Func<bool> cb) : base(PdtInternalType.Number) { _cb = cb; buf = new byte[4]; }
|
||||
public Boolean(Func<bool> cb) : base(PdtInternalType.Number, 4) { _cb = cb; }
|
||||
protected override void InternalGet() {
|
||||
m_invalidated = false;
|
||||
base.InternalGet();
|
||||
buf[0] = _cb() ? (byte)1 : (byte)0;
|
||||
}
|
||||
}
|
||||
public class Float : PropSrc {
|
||||
public class Float : FixedBuffer {
|
||||
readonly Func<float> _cb;
|
||||
bool m_invalidated = true;
|
||||
protected override bool Invalidated { get { return m_invalidated; } }
|
||||
public override void Invalidate() { m_invalidated = true; }
|
||||
public Float(Func<float> cb) : base(PdtInternalType.Number) { _cb = cb; buf = new byte[4]; }
|
||||
public Float(Func<float> cb) : base(PdtInternalType.Number, 4) { _cb = cb; }
|
||||
protected override unsafe void InternalGet() {
|
||||
m_invalidated = false;
|
||||
base.InternalGet();
|
||||
fixed (byte* _ptr = buf) {
|
||||
*(float*)_ptr = _cb();
|
||||
}
|
||||
@@ -65,19 +68,22 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Identifier : PropSrc {
|
||||
public class Identifier : FixedBuffer {
|
||||
readonly Func<int> _cb;
|
||||
public Identifier(Func<int> cb) : base(PdtInternalType.Undefined) { _cb = cb; }
|
||||
protected override void InternalGet() {
|
||||
buf = BitConverter.GetBytes(_cb());
|
||||
public Identifier(Func<int> cb) : base(PdtInternalType.Undefined, 4) { _cb = cb; }
|
||||
protected override unsafe void InternalGet() {
|
||||
base.InternalGet();
|
||||
fixed (byte* _ptr = buf) {
|
||||
*(int*)_ptr = _cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class BeatTime : PropSrc {
|
||||
public class BeatTime : FixedBuffer {
|
||||
readonly Func<RBeatTime> _cb;
|
||||
public BeatTime(Func<RBeatTime> cb) : base(PdtInternalType.Vector) { _cb = cb; }
|
||||
public BeatTime(Func<RBeatTime> cb) : base(PdtInternalType.Vector, 4 * sizeof(int)) { _cb = cb; }
|
||||
protected override unsafe void InternalGet() {
|
||||
base.InternalGet();
|
||||
var bt = _cb();
|
||||
buf = new byte[4 * sizeof(int)];
|
||||
fixed (byte* _ptr = buf) {
|
||||
int* ptr = (int*)_ptr;
|
||||
*ptr++ = bt.b;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Cryville.Crtr {
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
Root = new RulesetInterpreter(src, null).Interpret();
|
||||
Root = (PdtRuleset)new RulesetInterpreter(src, null).Interpret();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,9 +150,9 @@ namespace Cryville.Crtr {
|
||||
ChartPlayer.etor.Evaluate(new PropOp.String(r => result = r), exp);
|
||||
return result;
|
||||
}
|
||||
else if (type.Equals(typeof(float[]))) {
|
||||
float[] result = null;
|
||||
ChartPlayer.etor.Evaluate(new pop_numarr(r => result = r), exp);
|
||||
else if (type.Equals(typeof(Clip))) {
|
||||
Clip result = default(Clip);
|
||||
ChartPlayer.etor.Evaluate(new PropOp.Clip(r => result = r), exp);
|
||||
return result;
|
||||
}
|
||||
else if (type.Equals(typeof(Identifier))) {
|
||||
@@ -182,17 +182,6 @@ namespace Cryville.Crtr {
|
||||
return base.ChangeType(value, type, culture);
|
||||
}
|
||||
#pragma warning disable IDE1006
|
||||
class pop_numarr : PdtOperator {
|
||||
readonly Action<float[]> _cb;
|
||||
public pop_numarr(Action<float[]> cb) : base(16) { _cb = cb; }
|
||||
protected override void Execute() {
|
||||
var result = new float[LoadedOperandCount];
|
||||
for (int i = 0; i < LoadedOperandCount; i++) {
|
||||
result[i] = GetOperand(i).AsNumber();
|
||||
}
|
||||
_cb(result);
|
||||
}
|
||||
}
|
||||
class pop_identstr : PropOp {
|
||||
readonly Action<SIdentifier> _cb;
|
||||
public pop_identstr(Action<SIdentifier> cb) { _cb = cb; }
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
internal class RulesetInterpreter : PdtInterpreter<PdtRuleset> {
|
||||
public RulesetInterpreter(string src, Binder binder) : base(src, binder) { }
|
||||
internal class RulesetInterpreter : PdtInterpreter {
|
||||
public RulesetInterpreter(string src, Binder binder) : base(src, typeof(PdtRuleset), binder) { }
|
||||
|
||||
readonly List<RulesetSelector> s = new List<RulesetSelector>();
|
||||
readonly List<string> a = new List<string>();
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Cryville.Crtr.Components;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
@@ -30,14 +25,13 @@ namespace Cryville.Crtr {
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
Root = new SkinInterpreter(src, null).Interpret();
|
||||
Root = (PdtSkin)new SkinInterpreter(src, null).Interpret();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PdtSkin : SkinElement { }
|
||||
|
||||
[Binder(typeof(SkinElementBinder))]
|
||||
public class SkinElement {
|
||||
[ElementList]
|
||||
public Dictionary<SkinSelectors, SkinElement> elements
|
||||
@@ -67,36 +61,4 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
public struct SkinPropertyKey {
|
||||
public Type Component;
|
||||
public int Name;
|
||||
}
|
||||
public class SkinElementBinder : EmptyBinder {
|
||||
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
||||
if (value is string && type == typeof(SkinPropertyKey)) {
|
||||
var cp = ((string)value).Split('.');
|
||||
switch (cp.Length) {
|
||||
case 1:
|
||||
var key = cp[0];
|
||||
if (key[0] == '*')
|
||||
return new SkinPropertyKey { Component = GetComponentByName(key.Substring(1)) };
|
||||
else
|
||||
return new SkinPropertyKey { Component = typeof(TransformInterface), Name = IdentifierManager.SharedInstance.Request(key) };
|
||||
case 2:
|
||||
return new SkinPropertyKey { Component = GetComponentByName(cp[0]), Name = IdentifierManager.SharedInstance.Request(cp[1]) };
|
||||
}
|
||||
}
|
||||
return base.ChangeType(value, type, culture);
|
||||
}
|
||||
|
||||
static readonly char[] nssep = new char[]{':'};
|
||||
Type GetComponentByName(string name) {
|
||||
var nstuple = name.Split(nssep, 2);
|
||||
var ns = nssep.Length == 2 ? nstuple[0] : "generic";
|
||||
name = nssep.Length == 2 ? nstuple[1] : nstuple[0];
|
||||
if (ns == "generic")
|
||||
return GenericResources.Components[name];
|
||||
throw new ArgumentException(string.Format("Component type {0} not found", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Components;
|
||||
using Cryville.Crtr.Event;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
@@ -10,13 +7,20 @@ using UnityEngine.Profiling;
|
||||
namespace Cryville.Crtr {
|
||||
public class SkinContainer {
|
||||
readonly PdtSkin skin;
|
||||
readonly List<DynamicProperty> dynprops = new List<DynamicProperty>();
|
||||
readonly DynamicStack[] _stacks = new DynamicStack[2];
|
||||
class DynamicStack {
|
||||
public readonly List<DynamicProperty> Properties = new List<DynamicProperty>();
|
||||
public readonly List<DynamicElement> Elements = new List<DynamicElement>();
|
||||
public void Clear() {
|
||||
Properties.Clear();
|
||||
Elements.Clear();
|
||||
}
|
||||
}
|
||||
struct DynamicProperty {
|
||||
public RuntimeSkinContext Context { get; set; }
|
||||
public SkinPropertyKey Key { get; set; }
|
||||
public PdtExpression Value { get; set; }
|
||||
}
|
||||
readonly List<DynamicElement> dynelems = new List<DynamicElement>();
|
||||
struct DynamicElement {
|
||||
public RuntimeSkinContext Context { get; set; }
|
||||
public SkinSelectors Selectors { get; set; }
|
||||
@@ -24,68 +28,73 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public SkinContainer(PdtSkin _skin) {
|
||||
skin = _skin;
|
||||
for (int i = 0; i < _stacks.Length; i++) _stacks[i] = new DynamicStack();
|
||||
}
|
||||
public void MatchStatic(ContainerState state) {
|
||||
dynprops.Clear(); dynelems.Clear();
|
||||
var stack = _stacks[0];
|
||||
stack.Clear();
|
||||
ChartPlayer.etor.ContextState = state;
|
||||
ChartPlayer.etor.ContextEvent = state.Container;
|
||||
MatchStatic(skin, state, new RuntimeSkinContext(state.Handler.SkinContext));
|
||||
MatchStatic(skin, state, stack, new RuntimeSkinContext(state.Handler.SkinContext));
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
}
|
||||
void MatchStatic(SkinElement rel, ContainerState state, RuntimeSkinContext ctx) {
|
||||
void MatchStatic(SkinElement rel, ContainerState state, DynamicStack stack, RuntimeSkinContext ctx) {
|
||||
var rc = ctx.ReadContext;
|
||||
ChartPlayer.etor.ContextTransform = rc.Transform;
|
||||
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeInsert(rc.PropSrcs);
|
||||
foreach (var p in rel.properties) {
|
||||
if (p.Key.Name == 0)
|
||||
rc.Transform.gameObject.AddComponent(p.Key.Component);
|
||||
else {
|
||||
ChartPlayer.etor.Evaluate(GetPropOp(ctx.WriteTransform, p.Key).Operator, p.Value);
|
||||
if (!p.Value.IsConstant) dynprops.Add(
|
||||
new DynamicProperty { Context = ctx, Key = p.Key, Value = p.Value }
|
||||
);
|
||||
}
|
||||
p.Key.ExecuteStatic(state, ctx, p.Value);
|
||||
if (p.Key.IsValueRequired && !p.Value.IsConstant) stack.Properties.Add(
|
||||
new DynamicProperty { Context = ctx, Key = p.Key, Value = p.Value }
|
||||
);
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
foreach (var r in rel.elements) {
|
||||
foreach (var e in rel.elements) {
|
||||
try {
|
||||
var nctxs = r.Key.MatchStatic(state, rc);
|
||||
var roflag = r.Key.annotations.Contains("if");
|
||||
var woflag = r.Key.annotations.Contains("then");
|
||||
foreach (var nctx in nctxs) {
|
||||
var nrctx = new RuntimeSkinContext(nctx, ctx, roflag, woflag);
|
||||
MatchStatic(r.Value, state, nrctx);
|
||||
var nctxs = e.Key.MatchStatic(state, rc);
|
||||
if (nctxs != null) {
|
||||
var roflag = e.Key.annotations.Contains("if");
|
||||
var woflag = e.Key.annotations.Contains("then");
|
||||
foreach (var nctx in nctxs) {
|
||||
var nrctx = new RuntimeSkinContext(nctx, ctx, roflag, woflag);
|
||||
MatchStatic(e.Value, state, stack, nrctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SelectorNotAvailableException) {
|
||||
dynelems.Add(
|
||||
new DynamicElement { Context = ctx, Selectors = r.Key, Element = r.Value }
|
||||
stack.Elements.Add(
|
||||
new DynamicElement { Context = ctx, Selectors = e.Key, Element = e.Value }
|
||||
);
|
||||
}
|
||||
}
|
||||
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
|
||||
}
|
||||
public void MatchDynamic(ContainerState state) {
|
||||
if (dynprops.Count == 0 && dynelems.Count == 0) return;
|
||||
var stack = _stacks[state.CloneType >> 1];
|
||||
var nstack = (state.CloneType >> 1) + 1 < _stacks.Length ? _stacks[(state.CloneType >> 1) + 1] : null;
|
||||
if (nstack != null) nstack.Clear();
|
||||
if (stack.Properties.Count == 0 && stack.Elements.Count == 0) return;
|
||||
Profiler.BeginSample("SkinContainer.MatchDynamic");
|
||||
ChartPlayer.etor.ContextState = state;
|
||||
ChartPlayer.etor.ContextEvent = state.Container;
|
||||
for (int i = 0; i < dynprops.Count; i++) {
|
||||
DynamicProperty p = dynprops[i];
|
||||
var psrcs = p.Context.ReadContext.PropSrcs;
|
||||
if (psrcs != null) ChartPlayer.etor.ContextCascadeInsert(psrcs);
|
||||
var prop = GetPropOp(p.Context.WriteTransform, p.Key);
|
||||
if (state.CloneType > prop.UpdateCloneType) continue;
|
||||
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||
if (psrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
|
||||
for (int i = 0; i < stack.Properties.Count; i++) {
|
||||
DynamicProperty p = stack.Properties[i];
|
||||
p.Key.ExecuteDynamic(state, p.Context, p.Value);
|
||||
}
|
||||
for (int i = 0; i < dynelems.Count; i++) {
|
||||
DynamicElement e = dynelems[i];
|
||||
for (int i = 0; i < stack.Elements.Count; i++) {
|
||||
DynamicElement e = stack.Elements[i];
|
||||
var psrcs = e.Context.ReadContext.PropSrcs;
|
||||
if (psrcs != null) ChartPlayer.etor.ContextCascadeInsert(psrcs);
|
||||
var nctx = e.Selectors.MatchDynamic(state, e.Context.ReadContext);
|
||||
if (nctx != null) MatchDynamic(e.Element, state, new RuntimeSkinContext(
|
||||
SkinContext nctx = null;
|
||||
try {
|
||||
nctx = e.Selectors.MatchDynamic(state, e.Context.ReadContext);
|
||||
}
|
||||
catch (SelectorNotAvailableException) {
|
||||
if (nstack == null) throw;
|
||||
nstack.Elements.Add(e);
|
||||
}
|
||||
if (nctx != null) MatchDynamic(e.Element, state, nstack, new RuntimeSkinContext(
|
||||
nctx, e.Context, e.Selectors.annotations.Contains("if"), e.Selectors.annotations.Contains("then")
|
||||
));
|
||||
if (psrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
|
||||
@@ -94,42 +103,30 @@ namespace Cryville.Crtr {
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
Profiler.EndSample();
|
||||
}
|
||||
void MatchDynamic(SkinElement rel, ContainerState state, RuntimeSkinContext ctx) {
|
||||
void MatchDynamic(SkinElement rel, ContainerState state, DynamicStack stack, RuntimeSkinContext ctx) {
|
||||
var rc = ctx.ReadContext;
|
||||
ChartPlayer.etor.ContextTransform = rc.Transform;
|
||||
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeInsert(rc.PropSrcs);
|
||||
foreach (var p in rel.properties) {
|
||||
if (p.Key.Name == 0)
|
||||
throw new InvalidOperationException("Component creation in dynamic context is not allowed");
|
||||
var prop = GetPropOp(ctx.WriteTransform, p.Key);
|
||||
if (state.CloneType > prop.UpdateCloneType) continue;
|
||||
ChartPlayer.etor.Evaluate(prop.Operator, p.Value);
|
||||
p.Key.ExecuteDynamic(state, ctx, p.Value);
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
foreach (var r in rel.elements) {
|
||||
if (!r.Key.IsUpdatable(state)) continue;
|
||||
var nctx = r.Key.MatchDynamic(state, rc);
|
||||
if (nctx != null) MatchDynamic(r.Value, state, new RuntimeSkinContext(
|
||||
nctx, ctx, r.Key.annotations.Contains("if"), r.Key.annotations.Contains("then")
|
||||
));
|
||||
foreach (var e in rel.elements) {
|
||||
if (e.Key.IsUpdatable(state)) {
|
||||
SkinContext nctx = e.Key.MatchDynamic(state, rc);
|
||||
if (nctx != null) MatchDynamic(e.Value, state, stack, new RuntimeSkinContext(
|
||||
nctx, ctx, e.Key.annotations.Contains("if"), e.Key.annotations.Contains("then")
|
||||
));
|
||||
}
|
||||
else {
|
||||
if (stack == null) throw new SelectorNotAvailableException();
|
||||
stack.Elements.Add(
|
||||
new DynamicElement { Context = ctx, Selectors = e.Key, Element = e.Value }
|
||||
);
|
||||
}
|
||||
}
|
||||
if (rc.PropSrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
|
||||
}
|
||||
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
|
||||
var ctype = key.Component;
|
||||
var comp = (SkinComponent)obj.GetComponent(ctype);
|
||||
if (comp == null) throw new InvalidOperationException(string.Format(
|
||||
"Trying to set property {0} but the component is not found",
|
||||
IdentifierManager.SharedInstance.Retrieve(key.Name)
|
||||
));
|
||||
SkinProperty result;
|
||||
if (!comp.Properties.TryGetValue(key.Name, out result))
|
||||
throw new ArgumentException(string.Format(
|
||||
"Property {0} not found on component",
|
||||
IdentifierManager.SharedInstance.Retrieve(key.Name)
|
||||
));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public class SkinContext {
|
||||
public Transform Transform { get; private set; }
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user