Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
388a41cb55 | |||
3b23f78960 | |||
4fce8369f0 | |||
373554912a | |||
46039f6a12 | |||
9b872654d5 | |||
2c4ac3191c | |||
20632d9b54 | |||
28cad97bbb | |||
75652ecff1 | |||
1734cf9b72 | |||
5eb9786a7c | |||
16be67dc75 | |||
a7dfaa4558 | |||
3b65dbea5b | |||
3ed7e566dd | |||
f3549353f3 | |||
78bb820f9e | |||
b954dda676 | |||
1be5cc77ca | |||
bf942cbe45 | |||
79bfd6764c | |||
dcc92bb024 | |||
15e9217f93 | |||
79240fdfe8 | |||
678e145271 | |||
5cdf10874e | |||
777b7d9c34 | |||
34b17f3111 | |||
fd9e2ce409 | |||
cd8aa0e65c | |||
5240408f00 | |||
a7e6522a57 | |||
d89e5a2e68 | |||
05124ac406 |
Binary file not shown.
52
Assets/Cryville/Common/Math/FractionUtils.cs
Normal file
52
Assets/Cryville/Common/Math/FractionUtils.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.Math {
|
||||
/// <summary>
|
||||
/// Provides a set of <see langword="static" /> methods related to fractions.
|
||||
/// </summary>
|
||||
public static class FractionUtils {
|
||||
/// <summary>
|
||||
/// Converts a <see cref="double" /> decimal to a fraction.
|
||||
/// </summary>
|
||||
/// <param name="value">The decimal.</param>
|
||||
/// <param name="error">The error.</param>
|
||||
/// <param name="n">The numerator.</param>
|
||||
/// <param name="d">The denominator.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is less than 0 or <paramref name="error" /> is not greater than 0 or not less than 1.</exception>
|
||||
public static void ToFraction(double value, double error, out int n, out int d) {
|
||||
if (value < 0.0)
|
||||
throw new ArgumentOutOfRangeException("value", "Must be >= 0.");
|
||||
if (error <= 0.0 || error >= 1.0)
|
||||
throw new ArgumentOutOfRangeException("accuracy", "Must be > 0 and < 1.");
|
||||
|
||||
int num = (int)System.Math.Floor(value);
|
||||
value -= num;
|
||||
|
||||
if (value < error) { n = num; d = 1; return; }
|
||||
if (1 - error < value) { n = num + 1; d = 1; return; }
|
||||
|
||||
int lower_n = 0;
|
||||
int lower_d = 1;
|
||||
int upper_n = 1;
|
||||
int upper_d = 1;
|
||||
while (true) {
|
||||
int middle_n = lower_n + upper_n;
|
||||
int middle_d = lower_d + upper_d;
|
||||
|
||||
if (middle_d * (value + error) < middle_n) {
|
||||
upper_n = middle_n;
|
||||
upper_d = middle_d;
|
||||
}
|
||||
else if (middle_n < (value - error) * middle_d) {
|
||||
lower_n = middle_n;
|
||||
lower_d = middle_d;
|
||||
}
|
||||
else {
|
||||
n = num * middle_d + middle_n;
|
||||
d = middle_d;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da665e46f8c2b5b46ad8e3bf5cd34007
|
||||
timeCreated: 1605077404
|
||||
licenseType: Free
|
||||
guid: 6829ada596979a545a935785eeea2972
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Common.Plist {
|
||||
public class PlistConvert {
|
||||
public static T Deserialize<T>(string file) {
|
||||
return (T)Deserialize(typeof(T), PlistCS.Plist.readPlist(file));
|
||||
}
|
||||
|
||||
public static object Deserialize(Type type, object obj, Binder binder = null) {
|
||||
if (binder == null)
|
||||
binder = BinderAttribute.CreateBinderOfType(type);
|
||||
if (obj is IList) {
|
||||
var lobj = (List<object>)obj;
|
||||
foreach (var i in lobj) {
|
||||
throw new NotImplementedException(); // TODO
|
||||
}
|
||||
}
|
||||
else if (obj is IDictionary) {
|
||||
var dobj = (Dictionary<string, object>)obj;
|
||||
if (typeof(IDictionary).IsAssignableFrom(type)) {
|
||||
var result = (IDictionary)ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
var it = type.GetGenericArguments()[1];
|
||||
foreach (var i in dobj) {
|
||||
var value = Deserialize(it, i.Value, binder);
|
||||
result.Add(i.Key, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
foreach (var i in dobj) {
|
||||
var imis = type.GetMember(i.Key);
|
||||
if (imis.Length == 0) continue;
|
||||
var imi = imis[0];
|
||||
var it = ReflectionHelper.GetMemberType(imi);
|
||||
var value = Deserialize(it, i.Value, binder);
|
||||
ReflectionHelper.SetValue(imi, result, value, binder);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else return obj;
|
||||
throw new Exception(); // TODO
|
||||
}
|
||||
}
|
||||
}
|
@@ -40,7 +40,9 @@ namespace Cryville.Common {
|
||||
/// <param name="name">The file name excluding the extension.</param>
|
||||
/// <returns>The escaped file name.</returns>
|
||||
public static string EscapeFileName(string name) {
|
||||
return Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}\.\s]", "_");
|
||||
var result = Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}]", "_").TrimEnd(' ', '.');
|
||||
if (result.Length == 0) return "_";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs
Normal file
22
Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class ChartResourceImporter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".umgc" };
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
var meta = Path.Combine(file.Directory.FullName, "meta.json");
|
||||
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
|
||||
using (StreamReader reader = new StreamReader(meta, Encoding.UTF8)) {
|
||||
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
return new Resource[] { new ChartResource(data.name, file) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bc71e8b62d4022409aa5518bbf3a7d8
|
||||
timeCreated: 1608801352
|
||||
licenseType: Free
|
||||
guid: 168366bb891392b42a1d0a6bfa068ff3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
@@ -47,11 +47,11 @@ namespace Cryville.Crtr.Browsing {
|
||||
_cover.sprite = m_coverPlaceholder;
|
||||
if (data.Cover != null) data.Cover.Destination = DisplayCover;
|
||||
var meta = data.Meta;
|
||||
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.chart.name);
|
||||
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.name);
|
||||
_desc.text = string.Format(
|
||||
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
|
||||
meta.song.author, meta.chart.author,
|
||||
TimeSpan.FromSeconds(meta.chart.length).ToString(3), meta.note_count
|
||||
meta.song.author, meta.author,
|
||||
TimeSpan.FromSeconds(meta.length).ToString(3), meta.note_count
|
||||
);
|
||||
}
|
||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||
|
@@ -62,12 +62,12 @@ namespace Cryville.Crtr.Browsing {
|
||||
var meta = new ChartMeta();
|
||||
string name = item.Name;
|
||||
string desc = "(Unknown)";
|
||||
var metaFile = new FileInfo(item.FullName + "/meta.json");
|
||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||
if (metaFile.Exists) {
|
||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
name = meta.song.name;
|
||||
desc = meta.chart.name;
|
||||
desc = meta.name;
|
||||
}
|
||||
}
|
||||
AsyncDelivery<Texture2D> cover = null;
|
||||
@@ -91,7 +91,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
public ChartDetail GetItemDetail(int id) {
|
||||
var item = items[id];
|
||||
var meta = new ChartMeta();
|
||||
var metaFile = new FileInfo(item.FullName + "/meta.json");
|
||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||
if (metaFile.Exists) {
|
||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
@@ -114,7 +114,13 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
|
||||
public string GetItemPath(int id) {
|
||||
return items[id].Name + "/.umgc";
|
||||
var item = items[id];
|
||||
var meta = new ChartMeta();
|
||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
}
|
||||
return string.Format("{0}/{1}.json", items[id].Name, meta.data);
|
||||
}
|
||||
|
||||
public bool ImportItemFrom(string path) {
|
||||
@@ -126,38 +132,54 @@ namespace Cryville.Crtr.Browsing {
|
||||
resources = converter.ConvertFrom(file);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Popup.Create(ex.Message);
|
||||
LogAndPopup(4, ex.Message);
|
||||
return false;
|
||||
}
|
||||
foreach (var res in resources) {
|
||||
if (!res.Valid) {
|
||||
Logger.Log("main", 3, "Resource", "Attempt to import invalid resource {0}", res);
|
||||
LogAndPopup(3, "Attempt to import invalid resource: {0}", res);
|
||||
}
|
||||
else if (res is ChartResource) {
|
||||
var tres = (ChartResource)res;
|
||||
else if (res is RawChartResource) {
|
||||
var tres = (RawChartResource)res;
|
||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||
if (!dir.Exists) dir.Create();
|
||||
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
||||
using (var writer = new StreamWriter(dir.FullName + "/.json")) {
|
||||
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
using (var writer = new StreamWriter(dir.FullName + "/meta.json")) {
|
||||
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
||||
tres.Meta.data = "";
|
||||
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
if (tres.Meta.cover != null)
|
||||
new FileInfo(Path.Combine(file.Directory.FullName, tres.Meta.cover))
|
||||
.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
||||
}
|
||||
else if (res is CoverResource) {
|
||||
var tres = (CoverResource)res;
|
||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||
if (!dir.Exists) dir.Create();
|
||||
var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/" + tres.Source.Name);
|
||||
if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
|
||||
|
||||
else if (res is FileResource) {
|
||||
var tres = (FileResource)res;
|
||||
DirectoryInfo dest;
|
||||
if (res is ChartResource)
|
||||
dest = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||
else if (res is RulesetResource)
|
||||
dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name);
|
||||
else if (res is SkinResource)
|
||||
dest = new DirectoryInfo(_rootPath + "/skins/" + (res as SkinResource).RulesetName + "/" + res.Name);
|
||||
else if (res is SongResource)
|
||||
dest = new DirectoryInfo(_rootPath + "/songs/" + res.Name);
|
||||
else {
|
||||
LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res);
|
||||
continue;
|
||||
}
|
||||
if (!dest.Exists) {
|
||||
dest.Create();
|
||||
tres.Master.CopyTo(Path.Combine(dest.FullName, tres.Master.Extension));
|
||||
foreach (var attachment in tres.Attachments) {
|
||||
attachment.CopyTo(Path.Combine(dest.FullName, attachment.Name));
|
||||
}
|
||||
}
|
||||
else LogAndPopup(1, "Resource already exists: {0}", res);
|
||||
}
|
||||
else if (res is SongResource) {
|
||||
var tres = (SongResource)res;
|
||||
var dir = new DirectoryInfo(_rootPath + "/songs/" + res.Name);
|
||||
if (!dir.Exists) dir.Create();
|
||||
var dest = new FileInfo(_rootPath + "/songs/" + res.Name + "/.ogg");
|
||||
if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
|
||||
else {
|
||||
LogAndPopup(3, "Attempt to import unsupported resource: {0}", res);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -165,6 +187,12 @@ namespace Cryville.Crtr.Browsing {
|
||||
return false;
|
||||
}
|
||||
|
||||
void LogAndPopup(int level, string format, params object[] args) {
|
||||
var msg = string.Format(format, args);
|
||||
Logger.Log("main", level, "Resource", msg);
|
||||
Popup.Create(msg);
|
||||
}
|
||||
|
||||
public string[] GetSupportedFormats() {
|
||||
return converters.Keys.ToArray();
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -97,14 +98,19 @@ namespace Cryville.Crtr.Browsing {
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public struct ChartMeta {
|
||||
public MetaInfo song { get; set; }
|
||||
public MetaInfo chart { get; set; }
|
||||
public struct MetaInfo {
|
||||
public string name { get; set; }
|
||||
public string author { get; set; }
|
||||
public float length { get; set; }
|
||||
}
|
||||
public class MetaInfo {
|
||||
public string name { get; set; }
|
||||
public string author { get; set; }
|
||||
[JsonRequired]
|
||||
public string data { get; set; }
|
||||
}
|
||||
public class SongMetaInfo {
|
||||
public string name { get; set; }
|
||||
public string author { get; set; }
|
||||
}
|
||||
public class ChartMeta : MetaInfo {
|
||||
public SongMetaInfo song { get; set; }
|
||||
public float length { get; set; }
|
||||
public string ruleset { get; set; }
|
||||
public int note_count { get; set; }
|
||||
public string cover { get; set; }
|
||||
|
@@ -1,5 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
@@ -17,26 +19,62 @@ namespace Cryville.Crtr.Browsing {
|
||||
return string.Format("{0} ({1})", Name, ReflectionHelper.GetSimpleName(GetType()));
|
||||
}
|
||||
}
|
||||
public class ChartResource : Resource {
|
||||
public ChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
||||
public class RawChartResource : Resource {
|
||||
public RawChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
||||
Main = main; Meta = meta;
|
||||
}
|
||||
public Chart Main { get; private set; }
|
||||
public ChartMeta Meta { get; private set; }
|
||||
public override bool Valid { get { return true; } }
|
||||
}
|
||||
public class CoverResource : Resource {
|
||||
public CoverResource(string name, FileInfo src) : base(name) {
|
||||
Source = src;
|
||||
public abstract class FileResource : Resource {
|
||||
public FileResource(string name, FileInfo master) : base(name) {
|
||||
Master = master;
|
||||
Attachments = new List<FileInfo>();
|
||||
}
|
||||
public FileInfo Master { get; private set; }
|
||||
public List<FileInfo> Attachments { get; private set; }
|
||||
public override bool Valid {
|
||||
get {
|
||||
if (!Master.Exists) return false;
|
||||
foreach (var file in Attachments) {
|
||||
if (!file.Exists) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public FileInfo Source { get; private set; }
|
||||
public override bool Valid { get { return Source.Exists; } }
|
||||
}
|
||||
public class SongResource : Resource {
|
||||
public SongResource(string name, FileInfo src) : base(name) {
|
||||
Source = src;
|
||||
public class ChartResource : FileResource {
|
||||
public ChartResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
|
||||
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SongResource : FileResource {
|
||||
public SongResource(string name, FileInfo master) : base(name, master) { }
|
||||
}
|
||||
public class RulesetResource : FileResource {
|
||||
public RulesetResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SkinResource : FileResource {
|
||||
public string RulesetName { get; private set; }
|
||||
public SkinResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
|
||||
RulesetName = meta.ruleset;
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
foreach (var frame in meta.frames) {
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||
}
|
||||
}
|
||||
}
|
||||
public FileInfo Source { get; private set; }
|
||||
public override bool Valid { get { return Source.Exists; } }
|
||||
}
|
||||
}
|
20
Assets/Cryville/Crtr/Browsing/RulesetResourceImporter.cs
Normal file
20
Assets/Cryville/Crtr/Browsing/RulesetResourceImporter.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class RulesetResourceImporter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".umgr" };
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
var data = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||
return new Resource[] { new RulesetResource(data.name, file) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2c1531e76f19a647865f7ec335561cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Cryville/Crtr/Browsing/SkinResourceImporter.cs
Normal file
20
Assets/Cryville/Crtr/Browsing/SkinResourceImporter.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class SkinResourceImporter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".umgs" };
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
var data = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
|
||||
return new Resource[] { new SkinResource(data.name, file) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Browsing/SkinResourceImporter.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/SkinResourceImporter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9904b4c21758c5046afc341fe2fa8845
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -377,14 +377,6 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public Note() {
|
||||
SubmitPropSrc("track", new PropSrc.Float(() => {
|
||||
var i = motions.FirstOrDefault(m => m.RelativeNode == null && m.Name == "track");
|
||||
if (i == null) return ((Vec1)ChartPlayer.motionRegistry["track"].InitValue).Value;
|
||||
else return ((Vec1)i.AbsoluteValue).Value;
|
||||
}));
|
||||
}
|
||||
|
||||
public override EventList GetEventsOfType(string type) {
|
||||
switch (type) {
|
||||
case "judges": return new EventList<Judge>(judges);
|
||||
|
@@ -37,9 +37,9 @@ namespace Cryville.Crtr {
|
||||
else if (ev.Unstamped == null) { }
|
||||
else if (ev.Unstamped is Chart.Sound) {
|
||||
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
||||
var source = new LibavFileAudioSource(
|
||||
Game.GameDataPath + "/songs/" + tev.id + "/.ogg"
|
||||
);
|
||||
var dir = new DirectoryInfo(Game.GameDataPath + "/songs/" + tev.id);
|
||||
var files = dir.GetFiles();
|
||||
var source = new LibavFileAudioSource(files[0].FullName);
|
||||
source.SelectStream();
|
||||
sounds.Add(source);
|
||||
Game.AudioSession.Sequence(
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#define BUILD
|
||||
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Plist;
|
||||
using Cryville.Crtr.Config;
|
||||
using Cryville.Crtr.Event;
|
||||
using Newtonsoft.Json;
|
||||
@@ -26,8 +25,7 @@ namespace Cryville.Crtr {
|
||||
Ruleset ruleset;
|
||||
PdtRuleset pruleset;
|
||||
Dictionary<string, Texture2D> texs;
|
||||
public static Dictionary<string, Cocos2dFrames.Frame> frames;
|
||||
List<Cocos2dFrames> plists;
|
||||
public static Dictionary<string, SpriteFrame> frames;
|
||||
|
||||
readonly Queue<string> texLoadQueue = new Queue<string>();
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
@@ -252,6 +250,7 @@ namespace Cryville.Crtr {
|
||||
status.text = sttext;
|
||||
}
|
||||
void OnCameraPostRender(Camera cam) {
|
||||
if (!logEnabled) return;
|
||||
if (started) timetext = string.Format(
|
||||
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
|
||||
cbus.Time,
|
||||
@@ -353,6 +352,13 @@ namespace Cryville.Crtr {
|
||||
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
|
||||
);
|
||||
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
|
||||
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
|
||||
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (skin.format != Skin.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
|
||||
}
|
||||
|
||||
loadThread = new Thread(new ParameterizedThreadStart(Load));
|
||||
loadThread.Start(new LoadInfo() {
|
||||
chartFile = chartFile,
|
||||
@@ -363,10 +369,10 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 0, "Load/MainThread", "Loading textures...");
|
||||
texloadtimer = new diag::Stopwatch();
|
||||
texloadtimer.Start();
|
||||
frames = new Dictionary<string, SpriteFrame>();
|
||||
texs = new Dictionary<string, Texture2D>();
|
||||
var flist = skinFile.Directory.GetFiles("*.png");
|
||||
foreach (FileInfo f in flist) {
|
||||
texLoadQueue.Enqueue(f.FullName);
|
||||
foreach (var f in skin.frames) {
|
||||
texLoadQueue.Enqueue(Path.Combine(skinFile.Directory.FullName, f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,13 +381,12 @@ namespace Cryville.Crtr {
|
||||
diag::Stopwatch timer = new diag::Stopwatch();
|
||||
timer.Reset(); timer.Start();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
||||
foreach (var i in plists) i.Init(texs);
|
||||
foreach (var t in texs) {
|
||||
if (frames.ContainsKey(t.Key)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
||||
continue;
|
||||
}
|
||||
var f = new Cocos2dFrames.Frame(t.Value);
|
||||
var f = new SpriteFrame(t.Value);
|
||||
f.Init();
|
||||
frames.Add(t.Key, f);
|
||||
}
|
||||
@@ -504,7 +509,6 @@ namespace Cryville.Crtr {
|
||||
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||
}
|
||||
|
||||
cbus.AttachSystems(pskin, judge);
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
|
||||
var ch = new ChartHandler(chart, dir);
|
||||
cbus.RootState.AttachHandler(ch);
|
||||
@@ -522,6 +526,7 @@ namespace Cryville.Crtr {
|
||||
ts.Value.AttachHandler(th);
|
||||
}
|
||||
}
|
||||
cbus.AttachSystems(pskin, judge);
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)");
|
||||
using (var pbus = cbus.Clone(16)) {
|
||||
pbus.Forward();
|
||||
@@ -549,7 +554,7 @@ namespace Cryville.Crtr {
|
||||
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (ruleset.format != 1) throw new FormatException("Invalid ruleset file version");
|
||||
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
pruleset = ruleset.Root;
|
||||
pruleset.Optimize(etor);
|
||||
@@ -559,23 +564,9 @@ namespace Cryville.Crtr {
|
||||
void LoadSkin(FileInfo file) {
|
||||
DirectoryInfo dir = file.Directory;
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (skin.format != 1) throw new FormatException("Invalid skin file version");
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
}
|
||||
plists = new List<Cocos2dFrames>();
|
||||
frames = new Dictionary<string, Cocos2dFrames.Frame>();
|
||||
foreach (FileInfo f in file.Directory.GetFiles("*.plist")) {
|
||||
var pobj = PlistConvert.Deserialize<Cocos2dFrames>(f.FullName);
|
||||
plists.Add(pobj);
|
||||
foreach (var i in pobj.frames)
|
||||
frames.Add(StringUtils.TrimExt(i.Key), i.Value);
|
||||
}
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@@ -1,176 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
[BinderAttribute(typeof(Cocos2dFramesBinder))]
|
||||
public class Cocos2dFrames {
|
||||
public Metadata metadata;
|
||||
public class Metadata {
|
||||
public int format;
|
||||
public Vector2 size;
|
||||
public string textureFileName;
|
||||
}
|
||||
|
||||
public Dictionary<string, Frame> frames;
|
||||
public class Frame {
|
||||
#pragma warning disable IDE1006
|
||||
Rect _frame;
|
||||
public Rect frame {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
public Rect textureRect {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
|
||||
bool _rotated = false;
|
||||
public bool rotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
public bool textureRotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public Vector2 offset;
|
||||
|
||||
public Rect sourceColorRect;
|
||||
public Vector2 sourceSize;
|
||||
private Rect _uv;
|
||||
private Vector2[] cuv;
|
||||
public Rect UV {
|
||||
get {
|
||||
return _uv;
|
||||
}
|
||||
private set {
|
||||
_uv = value;
|
||||
float x0 = Mathf.Min(_uv.xMin, _uv.xMax);
|
||||
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
|
||||
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
|
||||
float y1 = Mathf.Max(_uv.yMin, _uv.yMax);
|
||||
if (_rotated) cuv = new Vector2[]{
|
||||
new Vector2(x0, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
};
|
||||
else cuv = new Vector2[]{
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y1),
|
||||
};
|
||||
}
|
||||
}
|
||||
public Vector2 GetUV(Vector2 uv) {
|
||||
return GetUV(uv.x, uv.y);
|
||||
}
|
||||
public Vector2 GetUV(float u, float v) {
|
||||
Vector2 uv00 = cuv[0], uv11 = cuv[1],
|
||||
uv10 = cuv[2], uv01 = cuv[3];
|
||||
return (1 - u - v) * uv00
|
||||
+ u * uv10
|
||||
+ v * uv01
|
||||
+ u * v * (uv00 + uv11 - uv10 - uv01);
|
||||
}
|
||||
public Texture2D Texture {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Vector2 Size {
|
||||
get {
|
||||
return new Vector2(Texture.width, Texture.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
if (Texture == null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
_frame = new Rect(Vector2.zero, Size);
|
||||
var w = _frame.width;
|
||||
var h = _frame.height;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
|
||||
public void Init(int w, int h, Texture2D _base) {
|
||||
if (Texture != null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
Texture = _base;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
public Frame() { }
|
||||
public Frame(Texture2D tex) {
|
||||
Texture = tex;
|
||||
}
|
||||
}
|
||||
|
||||
Texture2D _base;
|
||||
|
||||
public void Init(Dictionary<string, Texture2D> texs) {
|
||||
_base = texs[StringUtils.TrimExt(metadata.textureFileName)];
|
||||
var w = (int)metadata.size.x;
|
||||
var h = (int)metadata.size.y;
|
||||
if (w == 0 || h == 0) {
|
||||
w = _base.width;
|
||||
h = _base.height;
|
||||
}
|
||||
foreach (var f in frames) {
|
||||
f.Value.Init(w, h, _base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Cocos2dFramesBinder : EmptyBinder {
|
||||
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
||||
if (value is string) {
|
||||
var str = (string)value;
|
||||
if (type == typeof(Rect)) {
|
||||
var m = Regex.Match(str, @"^{({.*?}),({.*?})}$");
|
||||
var p = (Vector2)ChangeType(m.Groups[1].Value, typeof(Vector2), culture);
|
||||
var s = (Vector2)ChangeType(m.Groups[2].Value, typeof(Vector2), culture);
|
||||
return new Rect(p, s);
|
||||
}
|
||||
else if (type == typeof(Vector2)) {
|
||||
var m = Regex.Match(str, @"^{(.*?),(.*?)}$");
|
||||
var w = float.Parse(m.Groups[1].Value);
|
||||
var h = float.Parse(m.Groups[2].Value);
|
||||
return new Vector2(w, h);
|
||||
}
|
||||
}
|
||||
else if (typeof(IDictionary).IsAssignableFrom(value.GetType())) {
|
||||
var dict = (IDictionary)value;
|
||||
if (type == typeof(Rect)) {
|
||||
var x = float.Parse((string)dict["x"]);
|
||||
var y = float.Parse((string)dict["y"]);
|
||||
var w = float.Parse((string)dict["w"]);
|
||||
var h = float.Parse((string)dict["h"]);
|
||||
return new Rect(x, y, w, h);
|
||||
}
|
||||
else if (type == typeof(Vector2)) {
|
||||
var w = float.Parse((string)dict["w"]);
|
||||
var h = float.Parse((string)dict["h"]);
|
||||
return new Vector2(w, h);
|
||||
}
|
||||
}
|
||||
return base.ChangeType(value, type, culture);
|
||||
}
|
||||
}
|
||||
}
|
28
Assets/Cryville/Crtr/Components/MeshBase.cs
Normal file
28
Assets/Cryville/Crtr/Components/MeshBase.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public abstract class MeshBase : SkinComponent {
|
||||
public MeshBase() {
|
||||
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
||||
}
|
||||
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
|
||||
short _zindex;
|
||||
public short ZIndex {
|
||||
get {
|
||||
return _zindex;
|
||||
}
|
||||
set {
|
||||
if (value < 0 || value > 5000)
|
||||
throw new ArgumentOutOfRangeException("value", "Z-index must be in [0..5000]");
|
||||
_zindex = value;
|
||||
UpdateZIndex();
|
||||
}
|
||||
}
|
||||
protected void UpdateZIndex() {
|
||||
if (!mesh.Initialized) return;
|
||||
mesh.Renderer.material.renderQueue = _zindex;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Components/MeshBase.cs.meta
Normal file
11
Assets/Cryville/Crtr/Components/MeshBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75daba44e5811b943a08e6f137cc2b0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -5,11 +5,10 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public abstract class SectionalGameObject : SkinComponent {
|
||||
public abstract class SectionalGameObject : MeshBase {
|
||||
protected Vector3? prevpt;
|
||||
protected Quaternion? prevrot;
|
||||
protected int vertCount = 0;
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
@@ -56,7 +55,6 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
||||
SubmitProperty("transparent", new PropOp.Boolean(v => transparent = v));
|
||||
SubmitProperty("shape", new op_set_shape(this));
|
||||
}
|
||||
|
||||
@@ -94,7 +92,6 @@ namespace Cryville.Crtr.Components {
|
||||
public SpriteInfo body = new SpriteInfo();
|
||||
public SpriteInfo tail = new SpriteInfo();
|
||||
|
||||
public bool transparent;
|
||||
List<Vector3> vertices;
|
||||
List<float> lengths;
|
||||
float sumLength = 0;
|
||||
@@ -106,7 +103,7 @@ namespace Cryville.Crtr.Components {
|
||||
body.Load();
|
||||
tail.Load();
|
||||
|
||||
mesh.Init(transform, transparent);
|
||||
mesh.Init(transform);
|
||||
|
||||
List<Material> materials = new List<Material>();
|
||||
if (head.FrameName != null) AddMat(materials, head.FrameName);
|
||||
|
@@ -2,14 +2,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public abstract class SpriteBase : SkinComponent {
|
||||
public abstract class SpriteBase : MeshBase {
|
||||
public SpriteBase() {
|
||||
SubmitProperty("bound", new op_set_bound(this));
|
||||
SubmitProperty("transparent", new PropOp.Boolean(v => transparent = v));
|
||||
SubmitProperty("pivot", new PropOp.Vector2(v => Pivot = v));
|
||||
SubmitProperty("scale", new PropOp.Vector2(v => Scale = v));
|
||||
SubmitProperty("ui", new PropOp.Boolean(v => UI = v));
|
||||
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
@@ -27,8 +25,6 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
}
|
||||
@@ -82,21 +78,6 @@ namespace Cryville.Crtr.Components {
|
||||
if (da.x != 0) _scale.x = dp.x / da.x;
|
||||
if (da.y != 0) _scale.y = dp.z / da.y;
|
||||
}
|
||||
|
||||
short _zindex;
|
||||
public short ZIndex {
|
||||
get {
|
||||
return _zindex;
|
||||
}
|
||||
set {
|
||||
_zindex = value;
|
||||
UpdateZIndex();
|
||||
}
|
||||
}
|
||||
protected void UpdateZIndex() {
|
||||
if (!mesh.Initialized) return;
|
||||
mesh.Renderer.sortingOrder = _zindex;
|
||||
}
|
||||
|
||||
static readonly Quaternion uirot
|
||||
= Quaternion.Euler(new Vector3(-90, 0, 0));
|
||||
@@ -109,10 +90,8 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
}
|
||||
|
||||
public bool transparent = false;
|
||||
|
||||
protected void InternalInit(string meshName = "quad") {
|
||||
mesh.Init(transform, transparent);
|
||||
mesh.Init(transform);
|
||||
mesh.Mesh = GenericResources.Meshes[meshName];
|
||||
UpdateScale();
|
||||
UpdateZIndex();
|
||||
|
@@ -5,7 +5,7 @@ using Logger = Cryville.Common.Logger;
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteInfo {
|
||||
public string FrameName;
|
||||
public Cocos2dFrames.Frame Frame {
|
||||
public SpriteFrame Frame {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@ namespace Cryville.Crtr.Components {
|
||||
public class SpriteRect : SpriteBase {
|
||||
public SpriteRect() {
|
||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||
|
||||
transparent = true;
|
||||
}
|
||||
|
||||
Color _color;
|
||||
|
@@ -86,7 +86,7 @@ namespace Cryville.Crtr.Components {
|
||||
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height");
|
||||
if (!meshes.ContainsKey(f.Value.Frame.Texture)) {
|
||||
var m = new MeshWrapper();
|
||||
m.Init(mesh.MeshTransform, transparent);
|
||||
m.Init(mesh.MeshTransform);
|
||||
m.Mesh = new Mesh();
|
||||
m.Renderer.material.mainTexture = f.Value.Frame.Texture;
|
||||
meshes.Add(f.Value.Frame.Texture, m);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -24,12 +25,17 @@ namespace Cryville.Crtr.Config {
|
||||
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 != 1) throw new FormatException("Invalid ruleset file version");
|
||||
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
}
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
@@ -62,7 +68,7 @@ namespace Cryville.Crtr.Config {
|
||||
cat.SetActive(true);
|
||||
}
|
||||
|
||||
public void ReturnToMenu() {
|
||||
public void SaveAndReturnToMenu() {
|
||||
Game.InputManager.Deactivate();
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
@@ -72,6 +78,9 @@ namespace Cryville.Crtr.Config {
|
||||
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
ReturnToMenu();
|
||||
}
|
||||
public void ReturnToMenu() {
|
||||
GameObject.Find("Master").GetComponent<Master>().ShowMenu();
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
SceneManager.UnloadSceneAsync("Config");
|
||||
|
@@ -63,6 +63,13 @@ namespace Cryville.Crtr.Event {
|
||||
get { return cs.Container; }
|
||||
}
|
||||
|
||||
public SkinContainer skinContainer;
|
||||
public Judge judge;
|
||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||
skinContainer = new SkinContainer(skin);
|
||||
this.judge = judge;
|
||||
}
|
||||
|
||||
public ContainerHandler() { }
|
||||
public abstract string TypeName {
|
||||
get;
|
||||
@@ -82,7 +89,7 @@ namespace Cryville.Crtr.Event {
|
||||
/// Called upon initialization of <see cref="cs" />.
|
||||
/// </summary>
|
||||
public virtual void Init() {
|
||||
cs.skinContainer.MatchStatic(cs);
|
||||
skinContainer.MatchStatic(cs);
|
||||
foreach (var i in gogroup.GetComponentsInChildren<SkinComponent>())
|
||||
i.Init();
|
||||
}
|
||||
@@ -115,7 +122,7 @@ namespace Cryville.Crtr.Event {
|
||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
||||
if (flag) PreAwake(s);
|
||||
if (Awoken && s.CloneType <= 2) if (gogroup) cs.skinContainer.MatchDynamic(s);
|
||||
if (Awoken && s.CloneType <= 2) if (gogroup) skinContainer.MatchDynamic(s);
|
||||
if (flag) Awake(s);
|
||||
}
|
||||
public virtual void ExUpdate(ContainerState s, StampedEvent ev) { }
|
||||
@@ -123,7 +130,7 @@ namespace Cryville.Crtr.Event {
|
||||
public virtual void EndUpdate(ContainerState s) {
|
||||
if (s.CloneType < 16) {
|
||||
Awoken = false;
|
||||
if (gogroup && s.CloneType <= 2) cs.skinContainer.MatchDynamic(s);
|
||||
if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
|
||||
}
|
||||
}
|
||||
public virtual void Anchor() { }
|
||||
|
@@ -50,8 +50,6 @@ namespace Cryville.Crtr.Event {
|
||||
public byte CloneType;
|
||||
private ContainerState rootPrototype = null;
|
||||
private ContainerState prototype = null;
|
||||
public SkinContainer skinContainer;
|
||||
public Judge judge;
|
||||
|
||||
public ContainerHandler Handler {
|
||||
get;
|
||||
@@ -210,8 +208,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||
skinContainer = new SkinContainer(skin);
|
||||
this.judge = judge;
|
||||
Handler.AttachSystems(skin, judge);
|
||||
}
|
||||
|
||||
public Vector GetRawValue(Identifier key) {
|
||||
|
@@ -35,6 +35,7 @@ namespace Cryville.Crtr.Event {
|
||||
r.invalidatedStates = new HashSet<ContainerState>();
|
||||
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);
|
||||
|
@@ -20,7 +20,7 @@ namespace Cryville.Crtr.Event {
|
||||
_buckets.Add(reg.Key, new Bucket(reg.Key, 4096));
|
||||
}
|
||||
|
||||
readonly Dictionary<RealtimeMotionValue, string> _rented = new Dictionary<RealtimeMotionValue, string>();
|
||||
readonly Dictionary<RealtimeMotionValue, Identifier> _rented = new Dictionary<RealtimeMotionValue, Identifier>();
|
||||
public RealtimeMotionValue Rent(Identifier name) {
|
||||
var n = name;
|
||||
var obj = _buckets[n].Rent();
|
||||
|
@@ -1,9 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 925f95cb7c6644a4695b2701d42e1ea2
|
||||
guid: b9bd9e24d7c553341a2a12391843542f
|
||||
folderAsset: yes
|
||||
timeCreated: 1606989037
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,183 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Math;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Bestdori {
|
||||
public class BestdoriChartConverter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".json" };
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
List<Resource> result = new List<Resource>();
|
||||
List<BestdoriChartEvent> src;
|
||||
using (var reader = new StreamReader(file.FullName)) {
|
||||
src = JsonConvert.DeserializeObject<List<BestdoriChartEvent>>(reader.ReadToEnd());
|
||||
}
|
||||
var group = new Chart.Group() {
|
||||
tracks = new List<Chart.Track>(),
|
||||
notes = new List<Chart.Note>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
};
|
||||
Chart chart = new Chart {
|
||||
format = 2,
|
||||
time = new BeatTime(0, 0, 1),
|
||||
ruleset = "bang_dream_girls_band_party",
|
||||
sigs = new List<Chart.Signature>(),
|
||||
sounds = new List<Chart.Sound>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
groups = new List<Chart.Group> { group },
|
||||
};
|
||||
string bgm = null;
|
||||
double? cbpm = null;
|
||||
double pbeat = 0, ctime = 0;
|
||||
double endbeat = 0;
|
||||
foreach (var ev in src) {
|
||||
double cbeat = ev.StartBeat;
|
||||
ctime += cbpm == null ? 0 : (cbeat - pbeat) / cbpm.Value * 60;
|
||||
pbeat = cbeat;
|
||||
if (cbeat > endbeat) endbeat = cbeat;
|
||||
if (ev is BestdoriChartEvent.System) {
|
||||
if (bgm != null) continue;
|
||||
var tev = (BestdoriChartEvent.System)ev;
|
||||
bgm = StringUtils.TrimExt(tev.data);
|
||||
var name = "bang_dream_girls_band_party__" + bgm;
|
||||
result.Add(new SongResource(name, new FileInfo(Path.Combine(file.Directory.FullName, tev.data))));
|
||||
chart.sounds.Add(new Chart.Sound { time = ToBeatTime(tev.beat), id = name });
|
||||
}
|
||||
else if (ev is BestdoriChartEvent.BPM) {
|
||||
var tev = (BestdoriChartEvent.BPM)ev;
|
||||
cbpm = tev.bpm;
|
||||
chart.sigs.Add(new Chart.Signature { time = ToBeatTime(tev.beat), tempo = (float)tev.bpm });
|
||||
}
|
||||
else if (ev is BestdoriChartEvent.Single) {
|
||||
var tev = (BestdoriChartEvent.Single)ev;
|
||||
group.notes.Add(new Chart.Note {
|
||||
time = ToBeatTime(tev.beat),
|
||||
judges = new List<Chart.Judge> { new Chart.Judge { name = tev.flick ? "single_flick" : "single" } },
|
||||
motions = new List<Chart.Motion> { new Chart.Motion { motion = "track:" + tev.lane.ToString() } },
|
||||
});
|
||||
}
|
||||
else if (ev is BestdoriChartEvent.Long) {
|
||||
var tev = (BestdoriChartEvent.Long)ev;
|
||||
var c1 = tev.connections[tev.connections.Count - 1];
|
||||
var note = new Chart.Note {
|
||||
time = ToBeatTime(tev.connections[0].beat),
|
||||
endtime = ToBeatTime(c1.beat),
|
||||
judges = new List<Chart.Judge>(),
|
||||
};
|
||||
for (int i = 0; i < tev.connections.Count; i++) {
|
||||
BestdoriChartEvent.Connection c = tev.connections[i];
|
||||
note.motions.Add(new Chart.Motion { motion = "track:" + c.lane.ToString() });
|
||||
if (i == 0)
|
||||
note.judges.Add(new Chart.Judge { name = "single" });
|
||||
else if (i == tev.connections.Count - 1)
|
||||
note.judges.Add(new Chart.Judge { time = ToBeatTime(c.beat), name = c.flick ? "longend_flick" : "longend" });
|
||||
else if (!c.hidden)
|
||||
note.judges.Add(new Chart.Judge { time = ToBeatTime(c.beat), name = "longnode" });
|
||||
}
|
||||
if (c1.beat > endbeat) endbeat = c1.beat;
|
||||
group.notes.Add(note);
|
||||
}
|
||||
else throw new NotImplementedException("Unsupported event: " + ev.type);
|
||||
}
|
||||
if (bgm == null) throw new FormatException("Chart contains no song");
|
||||
chart.endtime = ToBeatTime(endbeat);
|
||||
result.Add(new RawChartResource(string.Format("bang_dream_girls_band_party__{0}__{1}", bgm, StringUtils.TrimExt(file.Name)), chart, new ChartMeta {
|
||||
name = string.Format("Bandori {0} {1}", bgm, StringUtils.TrimExt(file.Name)),
|
||||
author = "©BanG Dream! Project ©Craft Egg Inc. ©bushiroad",
|
||||
ruleset = "bang_dream_girls_band_party",
|
||||
note_count = group.notes.Count,
|
||||
length = (float)ctime,
|
||||
song = new SongMetaInfo {
|
||||
name = bgm,
|
||||
author = "©BanG Dream! Project ©Craft Egg Inc. ©bushiroad",
|
||||
}
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
BeatTime ToBeatTime(double beat, double error = 1e-4) {
|
||||
int i, n, d;
|
||||
FractionUtils.ToFraction(beat, error, out n, out d);
|
||||
i = n / d; n %= d;
|
||||
return new BeatTime(i, n, d);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
[JsonConverter(typeof(BestdoriChartEventCreator))]
|
||||
abstract class BestdoriChartEvent {
|
||||
public abstract string type { get; }
|
||||
public abstract double StartBeat { get; }
|
||||
public abstract class InstantEvent : BestdoriChartEvent {
|
||||
public double beat;
|
||||
public override double StartBeat { get { return beat; } }
|
||||
}
|
||||
public class BPM : InstantEvent {
|
||||
public override string type { get { return "BPM"; } }
|
||||
public double bpm;
|
||||
}
|
||||
public class System : InstantEvent {
|
||||
public override string type { get { return "System"; } }
|
||||
public string data;
|
||||
}
|
||||
public abstract class SingleBase : InstantEvent {
|
||||
public double lane;
|
||||
public bool skill;
|
||||
public bool flick;
|
||||
}
|
||||
public class Single : SingleBase {
|
||||
public override string type { get { return "Single"; } }
|
||||
}
|
||||
public class Directional : SingleBase {
|
||||
public override string type { get { return "Directional"; } }
|
||||
public string direction;
|
||||
public int width;
|
||||
}
|
||||
public class Connection : SingleBase {
|
||||
public override string type { get { return null; } }
|
||||
public bool hidden;
|
||||
}
|
||||
public class Long : BestdoriChartEvent {
|
||||
public override string type { get { return "Long"; } }
|
||||
public List<Connection> connections;
|
||||
public override double StartBeat { get { return connections[0].beat; } }
|
||||
}
|
||||
public class Slide : Long {
|
||||
public override string type { get { return "Slide"; } }
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
class BestdoriChartEventCreator : CustomCreationConverter<BestdoriChartEvent> {
|
||||
string _currentType;
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
var obj = JObject.ReadFrom(reader);
|
||||
var type = obj["type"];
|
||||
if (type == null) _currentType = null;
|
||||
else _currentType = obj["type"].ToObject<string>();
|
||||
return base.ReadJson(obj.CreateReader(), objectType, existingValue, serializer);
|
||||
}
|
||||
|
||||
public override BestdoriChartEvent Create(Type objectType) {
|
||||
switch (_currentType) {
|
||||
case "BPM": return new BestdoriChartEvent.BPM();
|
||||
case "System": return new BestdoriChartEvent.System();
|
||||
case "Single": return new BestdoriChartEvent.Single();
|
||||
case "Directional": return new BestdoriChartEvent.Directional();
|
||||
case null: return new BestdoriChartEvent.Connection();
|
||||
case "Long": return new BestdoriChartEvent.Long();
|
||||
case "Slide": return new BestdoriChartEvent.Slide();
|
||||
default: throw new ArgumentException("Unknown event type: " + _currentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3c5a8bf05d5e284ba498e91cb0dd35e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -31,7 +31,9 @@ namespace Cryville.Crtr.Extensions.Malody {
|
||||
}
|
||||
|
||||
ChartMeta meta = new ChartMeta() {
|
||||
song = new ChartMeta.MetaInfo() {
|
||||
name = src.meta.version,
|
||||
author = src.meta.creator,
|
||||
song = new SongMetaInfo() {
|
||||
name = src.meta.song.titleorg != null ? src.meta.song.titleorg : src.meta.song.title,
|
||||
author = src.meta.song.artistorg != null ? src.meta.song.artistorg : src.meta.song.artist,
|
||||
},
|
||||
@@ -72,16 +74,17 @@ namespace Cryville.Crtr.Extensions.Malody {
|
||||
Dictionary<MalodyChart.IEvent, StartEventState> longEvents
|
||||
= new Dictionary<MalodyChart.IEvent, StartEventState>();
|
||||
|
||||
float? baseBpm = null;
|
||||
float? baseBpm = null, cbpm = null;
|
||||
float pbeat = 0f, ctime = 0f;
|
||||
int[] endbeat = new int[] { 0, 0, 1 };
|
||||
foreach (var ev in events) {
|
||||
float cbeat = ConvertBeat(ev.beat);
|
||||
ctime += baseBpm == null ? 0 : (cbeat - pbeat) / baseBpm.Value * 60f;
|
||||
ctime += cbpm == null ? 0 : (cbeat - pbeat) / cbpm.Value * 60f;
|
||||
pbeat = cbeat;
|
||||
if (ev is MalodyChart.Time) {
|
||||
var tev = (MalodyChart.Time)ev;
|
||||
if (baseBpm == null) baseBpm = tev.bpm;
|
||||
cbpm = tev.bpm;
|
||||
chart.sigs.Add(new Chart.Signature {
|
||||
time = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]),
|
||||
tempo = tev.bpm,
|
||||
@@ -142,18 +145,13 @@ namespace Cryville.Crtr.Extensions.Malody {
|
||||
else throw new NotSupportedException();
|
||||
}
|
||||
chart.endtime = new BeatTime(endbeat[0] + 4, endbeat[1], endbeat[2]);
|
||||
meta.chart = new ChartMeta.MetaInfo() {
|
||||
name = src.meta.version,
|
||||
author = src.meta.creator,
|
||||
length = ctime,
|
||||
};
|
||||
meta.length = ctime;
|
||||
meta.note_count = group.notes.Count;
|
||||
string chartName = string.Format("{0} - {1}", meta.song.name, meta.chart.name);
|
||||
string chartName = string.Format("{0} - {1}", meta.song.name, meta.name);
|
||||
if (src.meta.background != null) {
|
||||
result.Add(new CoverResource(chartName, new FileInfo(file.DirectoryName + "/" + src.meta.background)));
|
||||
meta.cover = src.meta.background;
|
||||
}
|
||||
result.Add(new ChartResource(chartName, chart, meta));
|
||||
result.Add(new RawChartResource(chartName, chart, meta));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -168,7 +166,7 @@ namespace Cryville.Crtr.Extensions.Malody {
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public struct MalodyChart {
|
||||
struct MalodyChart {
|
||||
public interface IEvent {
|
||||
int[] beat { get; set; }
|
||||
int[] endbeat { get; set; }
|
||||
|
@@ -19,6 +19,7 @@ namespace Cryville.Crtr {
|
||||
public static void LoadDefault() {
|
||||
if (loaded) return;
|
||||
Components.Add("image", typeof(SpritePlane));
|
||||
Components.Add("mesh", typeof(MeshBase));
|
||||
Components.Add("polysec", typeof(PolygonSGO));
|
||||
Components.Add("rect", typeof(SpriteRect));
|
||||
Components.Add("scale3", typeof(SpriteScale3));
|
||||
@@ -29,8 +30,7 @@ namespace Cryville.Crtr {
|
||||
Meshes.Add("quad_scale3h", Resources.Load<Mesh>("quad_scale3h"));
|
||||
Meshes.Add("quad_scale9", Resources.Load<Mesh>("quad_scale9"));
|
||||
|
||||
Materials.Add("-CutoutMat", Resources.Load<Material>("CutoutMat"));
|
||||
Materials.Add("-TransparentMat", Resources.Load<Material>("TransparentMat"));
|
||||
Materials.Add("-SpriteMat", Resources.Load<Material>("SpriteMat"));
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Event;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class Judge {
|
||||
@@ -30,14 +33,7 @@ namespace Cryville.Crtr {
|
||||
public Judge(PdtRuleset rs) {
|
||||
_etor = ChartPlayer.etor;
|
||||
_rs = rs;
|
||||
foreach (var s in rs.scores) {
|
||||
var key = s.Key;
|
||||
scoreSrcs.Add(key.Key, new PropSrc.Float(() => scores[key.Key]));
|
||||
scoreOps.Add(key.Key, new PropOp.Float(v => scores[key.Key] = v));
|
||||
scoreFmtKeys.Add(key.Key, IdentifierManager.SharedInstance.Request("_score_" + (string)key.Name));
|
||||
scoreDefs.Add(key.Key, s.Value);
|
||||
scores.Add(key.Key, s.Value.init);
|
||||
}
|
||||
InitScores();
|
||||
}
|
||||
public void Prepare(float st, float et, Identifier input, JudgeDefinition def, ContainerState container) {
|
||||
List<JudgeEvent> list;
|
||||
@@ -166,42 +162,95 @@ namespace Cryville.Crtr {
|
||||
var key = scoreop.Key;
|
||||
_etor.ContextSelfValue = scoreSrcs[key.name.Key];
|
||||
_etor.Evaluate(scoreOps[key.name.Key], scoreop.Value);
|
||||
scoreSrcs[key.name.Key].Invalidate();
|
||||
InvalidateScore(key.name.Key);
|
||||
foreach (var s in _rs.scores) {
|
||||
if (s.Value.value != null) {
|
||||
_etor.ContextSelfValue = scoreSrcs[s.Key.Key];
|
||||
_etor.Evaluate(scoreOps[s.Key.Key], s.Value.value);
|
||||
scoreSrcs[s.Key.Key].Invalidate();
|
||||
InvalidateScore(s.Key.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
ScoreCache.Clear();
|
||||
}
|
||||
readonly Dictionary<int, int> scoreFmtKeys = new Dictionary<int, int>();
|
||||
readonly Dictionary<int, int> scoreStringKeys = new Dictionary<int, int>();
|
||||
readonly Dictionary<int, int> scoreStringKeysRev = new Dictionary<int, int>();
|
||||
readonly Dictionary<int, PropSrc> scoreSrcs = new Dictionary<int, PropSrc>();
|
||||
readonly Dictionary<int, PropOp> scoreOps = new Dictionary<int, PropOp>();
|
||||
readonly Dictionary<int, ScoreDefinition> scoreDefs = new Dictionary<int, ScoreDefinition>();
|
||||
public readonly Dictionary<int, float> scores = new Dictionary<int, float>();
|
||||
readonly Dictionary<int, string> ScoreCache = new Dictionary<int, string>();
|
||||
readonly object _lock = new object();
|
||||
public Dictionary<int, string> GetFormattedScoreStrings() {
|
||||
lock (_lock) {
|
||||
if (ScoreCache.Count == 0) {
|
||||
foreach (var s in scores)
|
||||
ScoreCache.Add(scoreFmtKeys[s.Key], s.Value.ToString(scoreDefs[s.Key].format));
|
||||
}
|
||||
return ScoreCache;
|
||||
readonly Dictionary<int, float> scores = new Dictionary<int, float>();
|
||||
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>();
|
||||
void InitScores() {
|
||||
foreach (var s in _rs.scores) {
|
||||
var key = s.Key.Key;
|
||||
var strkey = IdentifierManager.SharedInstance.Request("_score_" + (string)s.Key.Name);
|
||||
scoreStringKeys.Add(key, strkey);
|
||||
scoreStringKeysRev.Add(strkey, key);
|
||||
scoreSrcs.Add(key, new PropSrc.Float(() => scores[key]));
|
||||
scoreOps.Add(key, new PropOp.Float(v => scores[key] = v));
|
||||
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)));
|
||||
}
|
||||
}
|
||||
void InvalidateScore(int key) {
|
||||
scoreSrcs[key].Invalidate();
|
||||
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() {
|
||||
bool flag = false;
|
||||
string result = "";
|
||||
foreach (var s in GetFormattedScoreStrings()) {
|
||||
result += string.Format(flag ? "\n{0}: {1}" : "{0}: {1}", IdentifierManager.SharedInstance.Retrieve(s.Key), s.Value);
|
||||
foreach (var s in scores.Keys) {
|
||||
result += string.Format(flag ? "\n{0}: {1}" : "{0}: {1}", IdentifierManager.SharedInstance.Retrieve(s), GetScoreString(scoreStringKeys[s]));
|
||||
flag = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
class ScoreStringSrc : PropSrc {
|
||||
readonly Func<string> _cb;
|
||||
readonly ArrayPool<byte> _pool;
|
||||
byte[] _buf;
|
||||
public ScoreStringSrc(ArrayPool<byte> pool, Func<string> cb) {
|
||||
_pool = pool;
|
||||
_cb = cb;
|
||||
}
|
||||
public override void Invalidate() {
|
||||
base.Invalidate();
|
||||
if (_buf != null) {
|
||||
_pool.Return(_buf);
|
||||
_buf = null;
|
||||
}
|
||||
}
|
||||
protected override unsafe void InternalGet(out int type, out byte[] value) {
|
||||
var src = _cb();
|
||||
int strlen = src.Length;
|
||||
type = PdtInternalType.String;
|
||||
value = _pool.Rent(sizeof(int) + strlen * sizeof(char));
|
||||
fixed (byte* _ptr = value) {
|
||||
char* ptr = (char*)(_ptr + sizeof(int));
|
||||
*(int*)_ptr = strlen;
|
||||
int i = 0;
|
||||
foreach (var c in src) ptr[i++] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class InputDefinition {
|
||||
public int dim;
|
||||
|
@@ -15,6 +15,7 @@ namespace Cryville.Crtr {
|
||||
SettingsPanel m_settingsPanel;
|
||||
#pragma warning restore IDE0044
|
||||
|
||||
int frameIndex = 2;
|
||||
bool initialized = false;
|
||||
int totalTasks = 0;
|
||||
#pragma warning disable IDE0051
|
||||
@@ -27,7 +28,11 @@ namespace Cryville.Crtr {
|
||||
if (!initialized) {
|
||||
int taskCount = Game.NetworkTaskWorker.TaskCount;
|
||||
if (totalTasks < taskCount) totalTasks = taskCount;
|
||||
m_progressBar.value = 1 - (float)taskCount / totalTasks;
|
||||
if (frameIndex > 0) {
|
||||
frameIndex--;
|
||||
return;
|
||||
}
|
||||
m_progressBar.value = totalTasks == 0 ? 1 : (1 - (float)taskCount / totalTasks);
|
||||
if (taskCount == 0) {
|
||||
initialized = true;
|
||||
m_targetAnimator.SetTrigger("T_Main");
|
||||
|
@@ -22,23 +22,16 @@ namespace Cryville.Crtr {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool Transparent {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool Initialized {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Material NewMaterial {
|
||||
get {
|
||||
return Material.Instantiate(GenericResources.Materials[
|
||||
Transparent ? "-TransparentMat" : "-CutoutMat"
|
||||
]);
|
||||
return Material.Instantiate(GenericResources.Materials["-SpriteMat"]);
|
||||
}
|
||||
}
|
||||
public void Init(Transform parent, bool transparent = false) {
|
||||
Transparent = transparent;
|
||||
public void Init(Transform parent) {
|
||||
MeshObject = new GameObject("__mesh__");
|
||||
MeshTransform = MeshObject.transform;
|
||||
MeshTransform.SetParent(parent, false);
|
||||
@@ -48,9 +41,7 @@ namespace Cryville.Crtr {
|
||||
MeshObject.AddComponent<MeshRenderer>();
|
||||
MeshFilter = MeshObject.GetComponent<MeshFilter>();
|
||||
Renderer = MeshObject.GetComponent<Renderer>();
|
||||
Renderer.material = GenericResources.Materials[
|
||||
transparent ? "-TransparentMat" : "-CutoutMat"
|
||||
]; // TODO
|
||||
Renderer.material = GenericResources.Materials["-SpriteMat"];
|
||||
Initialized = true;
|
||||
}
|
||||
public void Destroy() {
|
||||
|
@@ -11,7 +11,6 @@ namespace Cryville.Crtr {
|
||||
readonly GroupHandler gh;
|
||||
public readonly Chart.Note Event;
|
||||
readonly PdtRuleset ruleset;
|
||||
readonly Judge judge;
|
||||
public NoteHandler(GroupHandler gh, Chart.Note ev, PdtRuleset rs, Judge j) : base() {
|
||||
this.gh = gh;
|
||||
Event = ev;
|
||||
@@ -62,18 +61,6 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<Chart.Motion, Vec1> phMotions = new Dictionary<Chart.Motion, Vec1>();
|
||||
bool invalidated = false;
|
||||
readonly List<StampedEvent.Judge> patchedJudgeEvents = new List<StampedEvent.Judge>();
|
||||
|
||||
public override void StartUpdate(ContainerState s) {
|
||||
base.StartUpdate(s);
|
||||
/*if (s.CloneType == 16 && Event.judge != null) {
|
||||
// var etor = new Evaluator();
|
||||
//CompiledRuleset.PatchJudge(Event, ChartPlayer.cruleset.primary_judges[Event.judge], s.Time, etor, patchedJudgeEvents, !Event.@long);
|
||||
}*/
|
||||
}
|
||||
|
||||
public override void Update(ContainerState s, StampedEvent ev) {
|
||||
base.Update(s, ev);
|
||||
if (s.CloneType == 1) {
|
||||
@@ -103,73 +90,6 @@ namespace Cryville.Crtr {
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
}
|
||||
else if (ev.Unstamped is Chart.Motion) {
|
||||
/*var tev = (Chart.Motion)ev.Unstamped;
|
||||
if (tev.Name != "judge") return;
|
||||
phMotions.Add(tev, (Vec1)s.GetRawValue<Vec1>(tev.Name).Clone());*/
|
||||
}
|
||||
else if (ev.Unstamped is InstantEvent) {
|
||||
/*var oev = ((InstantEvent)ev.Unstamped).Original;
|
||||
if (oev is Chart.Motion) {
|
||||
var tev = (Chart.Motion)oev;
|
||||
if (tev.Name != "judge") return;
|
||||
var v0 = phMotions[tev];
|
||||
var v1 = s.GetRawValue<Vec1>(tev.Name);
|
||||
// var etor = new Evaluator();
|
||||
for (var vi = Mathf.Ceil(v0.Value); vi < v1.Value; vi++) {
|
||||
var v = new Vec1(vi);
|
||||
var t = MotionLerper.Delerp(v, ev.Time, v1, ev.Origin.Time, v0, tev.transition, tev.rate);
|
||||
CompiledRuleset.PatchJudge(
|
||||
Event, ChartPlayer.cruleset.primary_judges[tev.Name.SubName],
|
||||
t, etor, patchedJudgeEvents
|
||||
);
|
||||
}
|
||||
phMotions.Remove(tev);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExUpdate(ContainerState s, StampedEvent ev) {
|
||||
base.ExUpdate(s, ev);
|
||||
if (ev is StampedEvent.Judge) {
|
||||
var tev = (StampedEvent.Judge)ev;
|
||||
if (tev.TargetJudge != null && s.CloneType == 0 && !invalidated) {
|
||||
//judge.Issue(tev, this);
|
||||
}
|
||||
else if (tev.TargetJudge == null && s.CloneType == 17) {
|
||||
//judge.RecordPos(tev.StartEvent, GetFramePoint(s.Parent, s.Track));
|
||||
}
|
||||
else
|
||||
return;
|
||||
patchedJudgeEvents.Remove(tev);
|
||||
// Logger.Log("main", 0, "Judge", "ir {0}", patchedJudgeEvents.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public override void MotionUpdate(byte ct, Chart.Motion ev) {
|
||||
base.MotionUpdate(ct, ev);
|
||||
if (ct == 0) {
|
||||
/*if (ev.Name == "judge") {
|
||||
if (invalidated) return;
|
||||
if (ev.Name == null)
|
||||
throw new InvalidOperationException();
|
||||
judge.IssueImmediate(this, ev.Name.SubName, GetFramePoint(cs.Parent, cs.Track));
|
||||
}*/
|
||||
}
|
||||
else if (ct == 16) {
|
||||
/*var etor = new EvalImpl();
|
||||
if (ev.MotionName == "judge") {
|
||||
if (ev.MotionSubName == null)
|
||||
throw new InvalidOperationException();
|
||||
var l = new List<StampedEvent>();
|
||||
float t = ps.Time;
|
||||
CompiledRuleset.PatchJudge(
|
||||
Event, ChartPlayer.cruleset.primary_judges[ev.MotionSubName],
|
||||
t, etor, ref l
|
||||
);
|
||||
cs.Bus.IssueEventPatch(l);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,13 +103,6 @@ namespace Cryville.Crtr {
|
||||
a_tail.rotation = Quaternion.Euler(ts.Direction);
|
||||
#endif
|
||||
}
|
||||
else if (s.CloneType == 16) {
|
||||
/*if (Event.endjudge != null) {
|
||||
//var etor = new Evaluator();
|
||||
//CompiledRuleset.PatchJudge(Event, ChartPlayer.cruleset.primary_judges[Event.endjudge], ps.Time, etor, patchedJudgeEvents, true);
|
||||
}
|
||||
cs.Bus.IssuePatch(patchedJudgeEvents.Cast<StampedEvent>());*/
|
||||
}
|
||||
OpenAnchor("tail");
|
||||
base.EndUpdate(s);
|
||||
CloseAnchor("tail");
|
||||
@@ -248,10 +161,5 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<StampedEvent.Judge> Invalidate() {
|
||||
invalidated = true;
|
||||
return patchedJudgeEvents;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,8 +23,6 @@ namespace Cryville.Crtr {
|
||||
else {
|
||||
var id = new Identifier(name);
|
||||
PropSrc prop;
|
||||
string str;
|
||||
float num;
|
||||
if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) {
|
||||
prop.Get(out type, out value);
|
||||
}
|
||||
@@ -32,15 +30,12 @@ namespace Cryville.Crtr {
|
||||
var vec = ContextState.GetRawValue(id);
|
||||
new VectorSrc(() => vec).Get(out type, out value);
|
||||
}
|
||||
else if (ContextJudge != null && ContextJudge.scores.TryGetValue(name, out num)) {
|
||||
type = PdtInternalType.Number;
|
||||
LoadNum(num);
|
||||
value = _numbuf;
|
||||
else if (ContextJudge != null && ContextJudge.TryGetScoreSrc(name, out prop)) {
|
||||
prop.Get(out type, out value);
|
||||
RevokePotentialConstant();
|
||||
}
|
||||
else if (ContextJudge != null && ContextJudge.GetFormattedScoreStrings().TryGetValue(name, out str)) {
|
||||
type = PdtInternalType.String;
|
||||
value = GetBytes(str);
|
||||
else if (ContextJudge != null && ContextJudge.TryGetScoreStringSrc(name, out prop)) {
|
||||
prop.Get(out type, out value);
|
||||
RevokePotentialConstant();
|
||||
}
|
||||
else {
|
||||
|
@@ -6,7 +6,7 @@ namespace Cryville.Crtr {
|
||||
public abstract class PropSrc {
|
||||
int _type;
|
||||
byte[] _buf = null;
|
||||
public void Invalidate() { _buf = null; }
|
||||
public virtual void Invalidate() { _buf = null; }
|
||||
public void Get(out int type, out byte[] value) {
|
||||
if (_buf == null) InternalGet(out _type, out _buf);
|
||||
type = _type;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,21 +11,19 @@ using System.Text.RegularExpressions;
|
||||
using SIdentifier = Cryville.Common.Identifier;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class Ruleset {
|
||||
public class Ruleset : MetaInfo {
|
||||
public const long CURRENT_FORMAT = 2;
|
||||
|
||||
[JsonRequired]
|
||||
public long format;
|
||||
|
||||
[JsonRequired]
|
||||
public string @base;
|
||||
|
||||
[JsonRequired]
|
||||
public string pdt;
|
||||
|
||||
[JsonIgnore]
|
||||
public PdtRuleset Root { get; private set; }
|
||||
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + pdt + ".pdt", Encoding.UTF8)) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
Root = new RulesetInterpreter(src, null).Interpret();
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Cryville.Crtr.Components;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@@ -10,7 +11,9 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class Skin {
|
||||
public class Skin : MetaInfo {
|
||||
public const long CURRENT_FORMAT = 2;
|
||||
|
||||
[JsonRequired]
|
||||
public long format;
|
||||
|
||||
@@ -18,15 +21,14 @@ namespace Cryville.Crtr {
|
||||
|
||||
[JsonRequired]
|
||||
public string ruleset;
|
||||
|
||||
[JsonRequired]
|
||||
public string pdt;
|
||||
|
||||
public List<string> frames = new List<string>();
|
||||
|
||||
[JsonIgnore]
|
||||
public PdtSkin Root { get; private set; }
|
||||
|
||||
public void LoadPdt(DirectoryInfo dir) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + pdt + ".pdt", Encoding.UTF8)) {
|
||||
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + data + ".pdt", Encoding.UTF8)) {
|
||||
var src = pdtreader.ReadToEnd();
|
||||
Root = new SkinInterpreter(src, null).Interpret();
|
||||
}
|
||||
|
@@ -17,24 +17,26 @@ namespace Cryville.Crtr {
|
||||
skin = _skin;
|
||||
}
|
||||
public void MatchStatic(ContainerState context) {
|
||||
ChartPlayer.etor.ContextState = context;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
matchedStatic.Clear();
|
||||
MatchStatic(skin, context, context.Handler.gogroup);
|
||||
|
||||
foreach (var m in matchedStatic) {
|
||||
var el = m.Key;
|
||||
var obj = m.Value;
|
||||
ChartPlayer.etor.ContextTransform = obj;
|
||||
foreach (var p in el.properties) {
|
||||
if (p.Key.Name == null)
|
||||
obj.gameObject.AddComponent(p.Key.Component);
|
||||
else {
|
||||
ChartPlayer.etor.ContextTransform = obj;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
ChartPlayer.etor.Evaluate(GetPropOp(obj, p.Key), p.Value);
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
}
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
}
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
}
|
||||
void MatchStatic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
||||
matchedStatic.Add(rel, anchor);
|
||||
@@ -47,22 +49,24 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public void MatchDynamic(ContainerState context) {
|
||||
Profiler.BeginSample("SkinContainer.MatchDynamic");
|
||||
ChartPlayer.etor.ContextState = context;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
matchedDynamic.Clear();
|
||||
MatchDynamic(skin, context, context.Handler.gogroup);
|
||||
|
||||
foreach (var m in matchedDynamic) {
|
||||
var el = m.Key;
|
||||
var obj = m.Value;
|
||||
ChartPlayer.etor.ContextTransform = obj;
|
||||
foreach (var p in el.properties) {
|
||||
if (p.Key.Name == null) continue;
|
||||
if (p.Value.IsConstant) continue;
|
||||
ChartPlayer.etor.ContextTransform = obj;
|
||||
ChartPlayer.etor.ContextEvent = context.Container;
|
||||
ChartPlayer.etor.Evaluate(GetPropOp(obj, p.Key), p.Value);
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
}
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
}
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
Profiler.EndSample();
|
||||
}
|
||||
void MatchDynamic(SkinElement rel, ContainerState context, Transform anchor = null) {
|
||||
|
@@ -114,9 +114,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
|
||||
ChartPlayer.etor.ContextTransform = a;
|
||||
ChartPlayer.etor.ContextEvent = h.Container;
|
||||
ChartPlayer.etor.Evaluate(_op, _exp);
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextTransform = null;
|
||||
return _flag ? a : null;
|
||||
}
|
||||
|
109
Assets/Cryville/Crtr/SpriteFrame.cs
Normal file
109
Assets/Cryville/Crtr/SpriteFrame.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class SpriteFrame {
|
||||
#pragma warning disable IDE1006
|
||||
Rect _frame;
|
||||
public Rect frame {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
public Rect textureRect {
|
||||
get { return _frame; }
|
||||
set { _frame = value; }
|
||||
}
|
||||
|
||||
bool _rotated = false;
|
||||
public bool rotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
public bool textureRotated {
|
||||
get { return _rotated; }
|
||||
set { _rotated = value; }
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public Vector2 offset;
|
||||
|
||||
public Rect sourceColorRect;
|
||||
public Vector2 sourceSize;
|
||||
private Rect _uv;
|
||||
private Vector2[] cuv;
|
||||
public Rect UV {
|
||||
get {
|
||||
return _uv;
|
||||
}
|
||||
private set {
|
||||
_uv = value;
|
||||
float x0 = Mathf.Min(_uv.xMin, _uv.xMax);
|
||||
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
|
||||
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
|
||||
float y1 = Mathf.Max(_uv.yMin, _uv.yMax);
|
||||
if (_rotated) cuv = new Vector2[]{
|
||||
new Vector2(x0, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
};
|
||||
else cuv = new Vector2[]{
|
||||
new Vector2(x0, y0),
|
||||
new Vector2(x1, y1),
|
||||
new Vector2(x1, y0),
|
||||
new Vector2(x0, y1),
|
||||
};
|
||||
}
|
||||
}
|
||||
public Vector2 GetUV(Vector2 uv) {
|
||||
return GetUV(uv.x, uv.y);
|
||||
}
|
||||
public Vector2 GetUV(float u, float v) {
|
||||
Vector2 uv00 = cuv[0], uv11 = cuv[1],
|
||||
uv10 = cuv[2], uv01 = cuv[3];
|
||||
return (1 - u - v) * uv00
|
||||
+ u * uv10
|
||||
+ v * uv01
|
||||
+ u * v * (uv00 + uv11 - uv10 - uv01);
|
||||
}
|
||||
public Texture2D Texture {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Vector2 Size {
|
||||
get {
|
||||
return new Vector2(Texture.width, Texture.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
if (Texture == null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
_frame = new Rect(Vector2.zero, Size);
|
||||
var w = _frame.width;
|
||||
var h = _frame.height;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
|
||||
public void Init(int w, int h, Texture2D _base) {
|
||||
if (Texture != null)
|
||||
throw new InvalidOperationException(); // TODO
|
||||
Texture = _base;
|
||||
float x = _frame.x / w;
|
||||
float y = 1 - _frame.y / h;
|
||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
||||
else UV = new Rect(x, y, tw, -th);
|
||||
}
|
||||
public SpriteFrame() { }
|
||||
public SpriteFrame(Texture2D tex) {
|
||||
Texture = tex;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71d5ddaf108e0014c98c206ed5135ded
|
||||
folderAsset: yes
|
||||
timeCreated: 1605077401
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f21b229422310b40a4d539f7319bd1f
|
||||
folderAsset: yes
|
||||
timeCreated: 1605077401
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,838 +0,0 @@
|
||||
//
|
||||
// PlistCS Property List (plist) serialization and parsing library.
|
||||
//
|
||||
// https://github.com/animetrics/PlistCS
|
||||
//
|
||||
// Copyright (c) 2011 Animetrics Inc. (marc@animetrics.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace PlistCS {
|
||||
public static class Plist {
|
||||
private static List<int> offsetTable = new List<int>();
|
||||
private static List<byte> objectTable = new List<byte>();
|
||||
private static int refCount;
|
||||
private static int objRefSize;
|
||||
private static int offsetByteSize;
|
||||
private static long offsetTableOffset;
|
||||
|
||||
#region Public Functions
|
||||
|
||||
public static object readPlist(string path) {
|
||||
using (FileStream f = new FileStream(path, FileMode.Open, FileAccess.Read)) {
|
||||
return readPlist(f, plistType.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
public static object readPlistSource(string source) {
|
||||
return readPlist(System.Text.Encoding.UTF8.GetBytes(source));
|
||||
}
|
||||
|
||||
public static object readPlist(byte[] data) {
|
||||
using (var memory = new MemoryStream(data)) {
|
||||
return readPlist(memory, plistType.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
public static plistType getPlistType(Stream stream) {
|
||||
byte[] magicHeader = new byte[8];
|
||||
stream.Read(magicHeader, 0, 8);
|
||||
|
||||
if (BitConverter.ToInt64(magicHeader, 0) == 3472403351741427810) {
|
||||
return plistType.Binary;
|
||||
}
|
||||
else {
|
||||
return plistType.Xml;
|
||||
}
|
||||
}
|
||||
|
||||
public static object readPlist(Stream stream, plistType type) {
|
||||
if (type == plistType.Auto) {
|
||||
type = getPlistType(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
if (type == plistType.Binary) {
|
||||
using (BinaryReader reader = new BinaryReader(stream)) {
|
||||
byte[] data = reader.ReadBytes((int)reader.BaseStream.Length);
|
||||
return readBinary(data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.XmlResolver = null;
|
||||
xml.Load(stream);
|
||||
return readXml(xml);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeXml(object value, string path) {
|
||||
using (StreamWriter writer = new StreamWriter(path)) {
|
||||
writer.Write(writeXml(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeXml(object value, Stream stream) {
|
||||
using (StreamWriter writer = new StreamWriter(stream)) {
|
||||
writer.Write(writeXml(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static string writeXml(object value) {
|
||||
using (MemoryStream ms = new MemoryStream()) {
|
||||
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
|
||||
xmlWriterSettings.Encoding = new System.Text.UTF8Encoding(false);
|
||||
xmlWriterSettings.ConformanceLevel = ConformanceLevel.Document;
|
||||
xmlWriterSettings.Indent = true;
|
||||
|
||||
using (XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings)) {
|
||||
xmlWriter.WriteStartDocument();
|
||||
//xmlWriter.WriteComment("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
|
||||
xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
|
||||
xmlWriter.WriteStartElement("plist");
|
||||
xmlWriter.WriteAttributeString("version", "1.0");
|
||||
compose(value, xmlWriter);
|
||||
xmlWriter.WriteEndElement();
|
||||
xmlWriter.WriteEndDocument();
|
||||
xmlWriter.Flush();
|
||||
return Encoding.UTF8.GetString(ms.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBinary(object value, string path) {
|
||||
using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create))) {
|
||||
writer.Write(writeBinary(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBinary(object value, Stream stream) {
|
||||
using (BinaryWriter writer = new BinaryWriter(stream)) {
|
||||
writer.Write(writeBinary(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] writeBinary(object value) {
|
||||
offsetTable.Clear();
|
||||
objectTable.Clear();
|
||||
refCount = 0;
|
||||
objRefSize = 0;
|
||||
offsetByteSize = 0;
|
||||
offsetTableOffset = 0;
|
||||
|
||||
//Do not count the root node, subtract by 1
|
||||
int totalRefs = countObject(value) - 1;
|
||||
|
||||
refCount = totalRefs;
|
||||
|
||||
objRefSize = RegulateNullBytes(BitConverter.GetBytes(refCount)).Length;
|
||||
|
||||
composeBinary(value);
|
||||
|
||||
writeBinaryString("bplist00", false);
|
||||
|
||||
offsetTableOffset = (long)objectTable.Count;
|
||||
|
||||
offsetTable.Add(objectTable.Count - 8);
|
||||
|
||||
offsetByteSize = RegulateNullBytes(BitConverter.GetBytes(offsetTable[offsetTable.Count - 1])).Length;
|
||||
|
||||
List<byte> offsetBytes = new List<byte>();
|
||||
|
||||
offsetTable.Reverse();
|
||||
|
||||
for (int i = 0; i < offsetTable.Count; i++) {
|
||||
offsetTable[i] = objectTable.Count - offsetTable[i];
|
||||
byte[] buffer = RegulateNullBytes(BitConverter.GetBytes(offsetTable[i]), offsetByteSize);
|
||||
Array.Reverse(buffer);
|
||||
offsetBytes.AddRange(buffer);
|
||||
}
|
||||
|
||||
objectTable.AddRange(offsetBytes);
|
||||
|
||||
objectTable.AddRange(new byte[6]);
|
||||
objectTable.Add(Convert.ToByte(offsetByteSize));
|
||||
objectTable.Add(Convert.ToByte(objRefSize));
|
||||
|
||||
var a = BitConverter.GetBytes((long)totalRefs + 1);
|
||||
Array.Reverse(a);
|
||||
objectTable.AddRange(a);
|
||||
|
||||
objectTable.AddRange(BitConverter.GetBytes((long)0));
|
||||
a = BitConverter.GetBytes(offsetTableOffset);
|
||||
Array.Reverse(a);
|
||||
objectTable.AddRange(a);
|
||||
|
||||
return objectTable.ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
private static object readXml(XmlDocument xml) {
|
||||
XmlNode rootNode = xml.DocumentElement.ChildNodes[0];
|
||||
return parse(rootNode);
|
||||
}
|
||||
|
||||
private static object readBinary(byte[] data) {
|
||||
offsetTable.Clear();
|
||||
List<byte> offsetTableBytes = new List<byte>();
|
||||
objectTable.Clear();
|
||||
refCount = 0;
|
||||
objRefSize = 0;
|
||||
offsetByteSize = 0;
|
||||
offsetTableOffset = 0;
|
||||
|
||||
List<byte> bList = new List<byte>(data);
|
||||
|
||||
List<byte> trailer = bList.GetRange(bList.Count - 32, 32);
|
||||
|
||||
parseTrailer(trailer);
|
||||
|
||||
objectTable = bList.GetRange(0, (int)offsetTableOffset);
|
||||
|
||||
offsetTableBytes = bList.GetRange((int)offsetTableOffset, bList.Count - (int)offsetTableOffset - 32);
|
||||
|
||||
parseOffsetTable(offsetTableBytes);
|
||||
|
||||
return parseBinary(0);
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> parseDictionary(XmlNode node) {
|
||||
XmlNodeList children = node.ChildNodes;
|
||||
if (children.Count % 2 != 0) {
|
||||
throw new DataMisalignedException("Dictionary elements must have an even number of child nodes");
|
||||
}
|
||||
|
||||
Dictionary<string, object> dict = new Dictionary<string, object>();
|
||||
|
||||
for (int i = 0; i < children.Count; i += 2) {
|
||||
XmlNode keynode = children[i];
|
||||
XmlNode valnode = children[i + 1];
|
||||
|
||||
if (keynode.Name != "key") {
|
||||
throw new ApplicationException("expected a key node");
|
||||
}
|
||||
|
||||
object result = parse(valnode);
|
||||
|
||||
if (result != null) {
|
||||
dict.Add(keynode.InnerText, result);
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static List<object> parseArray(XmlNode node) {
|
||||
List<object> array = new List<object>();
|
||||
|
||||
foreach (XmlNode child in node.ChildNodes) {
|
||||
object result = parse(child);
|
||||
if (result != null) {
|
||||
array.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
private static void composeArray(List<object> value, XmlWriter writer) {
|
||||
writer.WriteStartElement("array");
|
||||
foreach (object obj in value) {
|
||||
compose(obj, writer);
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
private static object parse(XmlNode node) {
|
||||
switch (node.Name) {
|
||||
case "dict":
|
||||
return parseDictionary(node);
|
||||
case "array":
|
||||
return parseArray(node);
|
||||
case "string":
|
||||
return node.InnerText;
|
||||
case "integer":
|
||||
// int result;
|
||||
//int.TryParse(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo, out result);
|
||||
return Convert.ToInt32(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
case "real":
|
||||
return Convert.ToDouble(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
case "false":
|
||||
return false;
|
||||
case "true":
|
||||
return true;
|
||||
case "null":
|
||||
return null;
|
||||
case "date":
|
||||
return XmlConvert.ToDateTime(node.InnerText, XmlDateTimeSerializationMode.Utc);
|
||||
case "data":
|
||||
return Convert.FromBase64String(node.InnerText);
|
||||
}
|
||||
|
||||
throw new ApplicationException(String.Format("Plist Node `{0}' is not supported", node.Name));
|
||||
}
|
||||
|
||||
private static void compose(object value, XmlWriter writer) {
|
||||
|
||||
if (value == null || value is string) {
|
||||
writer.WriteElementString("string", value as string);
|
||||
}
|
||||
else if (value is int || value is long) {
|
||||
writer.WriteElementString("integer", ((int)value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
else if (value is System.Collections.Generic.Dictionary<string, object> ||
|
||||
value.GetType().ToString().StartsWith("System.Collections.Generic.Dictionary`2[System.String")) {
|
||||
//Convert to Dictionary<string, object>
|
||||
Dictionary<string, object> dic = value as Dictionary<string, object>;
|
||||
if (dic == null) {
|
||||
dic = new Dictionary<string, object>();
|
||||
IDictionary idic = (IDictionary)value;
|
||||
foreach (var key in idic.Keys) {
|
||||
dic.Add(key.ToString(), idic[key]);
|
||||
}
|
||||
}
|
||||
writeDictionaryValues(dic, writer);
|
||||
}
|
||||
else if (value is List<object>) {
|
||||
composeArray((List<object>)value, writer);
|
||||
}
|
||||
else if (value is byte[]) {
|
||||
writer.WriteElementString("data", Convert.ToBase64String((Byte[])value));
|
||||
}
|
||||
else if (value is float || value is double) {
|
||||
writer.WriteElementString("real", ((double)value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
else if (value is DateTime) {
|
||||
DateTime time = (DateTime)value;
|
||||
string theString = XmlConvert.ToString(time, XmlDateTimeSerializationMode.Utc);
|
||||
writer.WriteElementString("date", theString);//, "yyyy-MM-ddTHH:mm:ssZ"));
|
||||
}
|
||||
else if (value is bool) {
|
||||
writer.WriteElementString(value.ToString().ToLower(), "");
|
||||
}
|
||||
else {
|
||||
throw new Exception(String.Format("Value type '{0}' is unhandled", value.GetType().ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeDictionaryValues(Dictionary<string, object> dictionary, XmlWriter writer) {
|
||||
writer.WriteStartElement("dict");
|
||||
foreach (string key in dictionary.Keys) {
|
||||
object value = dictionary[key];
|
||||
writer.WriteElementString("key", key);
|
||||
compose(value, writer);
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
private static int countObject(object value) {
|
||||
int count = 0;
|
||||
switch (value.GetType().ToString()) {
|
||||
case "System.Collections.Generic.Dictionary`2[System.String,System.Object]":
|
||||
Dictionary<string, object> dict = (Dictionary<string, object>)value;
|
||||
foreach (string key in dict.Keys) {
|
||||
count += countObject(dict[key]);
|
||||
}
|
||||
count += dict.Keys.Count;
|
||||
count++;
|
||||
break;
|
||||
case "System.Collections.Generic.List`1[System.Object]":
|
||||
List<object> list = (List<object>)value;
|
||||
foreach (object obj in list) {
|
||||
count += countObject(obj);
|
||||
}
|
||||
count++;
|
||||
break;
|
||||
default:
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryDictionary(Dictionary<string, object> dictionary) {
|
||||
List<byte> buffer = new List<byte>();
|
||||
List<byte> header = new List<byte>();
|
||||
List<int> refs = new List<int>();
|
||||
for (int i = dictionary.Count - 1; i >= 0; i--) {
|
||||
var o = new object[dictionary.Count];
|
||||
dictionary.Values.CopyTo(o, 0);
|
||||
composeBinary(o[i]);
|
||||
offsetTable.Add(objectTable.Count);
|
||||
refs.Add(refCount);
|
||||
refCount--;
|
||||
}
|
||||
for (int i = dictionary.Count - 1; i >= 0; i--) {
|
||||
var o = new string[dictionary.Count];
|
||||
dictionary.Keys.CopyTo(o, 0);
|
||||
composeBinary(o[i]);//);
|
||||
offsetTable.Add(objectTable.Count);
|
||||
refs.Add(refCount);
|
||||
refCount--;
|
||||
}
|
||||
|
||||
if (dictionary.Count < 15) {
|
||||
header.Add(Convert.ToByte(0xD0 | Convert.ToByte(dictionary.Count)));
|
||||
}
|
||||
else {
|
||||
header.Add(0xD0 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(dictionary.Count, false));
|
||||
}
|
||||
|
||||
|
||||
foreach (int val in refs) {
|
||||
byte[] refBuffer = RegulateNullBytes(BitConverter.GetBytes(val), objRefSize);
|
||||
Array.Reverse(refBuffer);
|
||||
buffer.InsertRange(0, refBuffer);
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] composeBinaryArray(List<object> objects) {
|
||||
List<byte> buffer = new List<byte>();
|
||||
List<byte> header = new List<byte>();
|
||||
List<int> refs = new List<int>();
|
||||
|
||||
for (int i = objects.Count - 1; i >= 0; i--) {
|
||||
composeBinary(objects[i]);
|
||||
offsetTable.Add(objectTable.Count);
|
||||
refs.Add(refCount);
|
||||
refCount--;
|
||||
}
|
||||
|
||||
if (objects.Count < 15) {
|
||||
header.Add(Convert.ToByte(0xA0 | Convert.ToByte(objects.Count)));
|
||||
}
|
||||
else {
|
||||
header.Add(0xA0 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(objects.Count, false));
|
||||
}
|
||||
|
||||
foreach (int val in refs) {
|
||||
byte[] refBuffer = RegulateNullBytes(BitConverter.GetBytes(val), objRefSize);
|
||||
Array.Reverse(refBuffer);
|
||||
buffer.InsertRange(0, refBuffer);
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] composeBinary(object obj) {
|
||||
byte[] value;
|
||||
switch (obj.GetType().ToString()) {
|
||||
case "System.Collections.Generic.Dictionary`2[System.String,System.Object]":
|
||||
value = writeBinaryDictionary((Dictionary<string, object>)obj);
|
||||
return value;
|
||||
|
||||
case "System.Collections.Generic.List`1[System.Object]":
|
||||
value = composeBinaryArray((List<object>)obj);
|
||||
return value;
|
||||
|
||||
case "System.Byte[]":
|
||||
value = writeBinaryByteArray((byte[])obj);
|
||||
return value;
|
||||
|
||||
case "System.Double":
|
||||
value = writeBinaryDouble((double)obj);
|
||||
return value;
|
||||
|
||||
case "System.Int32":
|
||||
value = writeBinaryInteger((int)obj, true);
|
||||
return value;
|
||||
|
||||
case "System.String":
|
||||
value = writeBinaryString((string)obj, true);
|
||||
return value;
|
||||
|
||||
case "System.DateTime":
|
||||
value = writeBinaryDate((DateTime)obj);
|
||||
return value;
|
||||
|
||||
case "System.Boolean":
|
||||
value = writeBinaryBool((bool)obj);
|
||||
return value;
|
||||
|
||||
default:
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] writeBinaryDate(DateTime obj) {
|
||||
List<byte> buffer = new List<byte>(RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)), 8));
|
||||
buffer.Reverse();
|
||||
buffer.Insert(0, 0x33);
|
||||
objectTable.InsertRange(0, buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] writeBinaryBool(bool obj) {
|
||||
List<byte> buffer = new List<byte>(new byte[1] { (bool)obj ? (byte)9 : (byte)8 });
|
||||
objectTable.InsertRange(0, buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryInteger(int value, bool write) {
|
||||
List<byte> buffer = new List<byte>(BitConverter.GetBytes((long)value));
|
||||
buffer = new List<byte>(RegulateNullBytes(buffer.ToArray()));
|
||||
while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
|
||||
buffer.Add(0);
|
||||
int header = 0x10 | (int)(Math.Log(buffer.Count) / Math.Log(2));
|
||||
|
||||
buffer.Reverse();
|
||||
|
||||
buffer.Insert(0, Convert.ToByte(header));
|
||||
|
||||
if (write)
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryDouble(double value) {
|
||||
List<byte> buffer = new List<byte>(RegulateNullBytes(BitConverter.GetBytes(value), 4));
|
||||
while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
|
||||
buffer.Add(0);
|
||||
int header = 0x20 | (int)(Math.Log(buffer.Count) / Math.Log(2));
|
||||
|
||||
buffer.Reverse();
|
||||
|
||||
buffer.Insert(0, Convert.ToByte(header));
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryByteArray(byte[] value) {
|
||||
List<byte> buffer = new List<byte>(value);
|
||||
List<byte> header = new List<byte>();
|
||||
if (value.Length < 15) {
|
||||
header.Add(Convert.ToByte(0x40 | Convert.ToByte(value.Length)));
|
||||
}
|
||||
else {
|
||||
header.Add(0x40 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(buffer.Count, false));
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryString(string value, bool head) {
|
||||
List<byte> buffer = new List<byte>();
|
||||
List<byte> header = new List<byte>();
|
||||
foreach (char chr in value.ToCharArray())
|
||||
buffer.Add(Convert.ToByte(chr));
|
||||
|
||||
if (head) {
|
||||
if (value.Length < 15) {
|
||||
header.Add(Convert.ToByte(0x50 | Convert.ToByte(value.Length)));
|
||||
}
|
||||
else {
|
||||
header.Add(0x50 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(buffer.Count, false));
|
||||
}
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] RegulateNullBytes(byte[] value) {
|
||||
return RegulateNullBytes(value, 1);
|
||||
}
|
||||
|
||||
private static byte[] RegulateNullBytes(byte[] value, int minBytes) {
|
||||
Array.Reverse(value);
|
||||
List<byte> bytes = new List<byte>(value);
|
||||
for (int i = 0; i < bytes.Count; i++) {
|
||||
if (bytes[i] == 0 && bytes.Count > minBytes) {
|
||||
bytes.Remove(bytes[i]);
|
||||
i--;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytes.Count < minBytes) {
|
||||
int dist = minBytes - bytes.Count;
|
||||
for (int i = 0; i < dist; i++)
|
||||
bytes.Insert(0, 0);
|
||||
}
|
||||
|
||||
value = bytes.ToArray();
|
||||
Array.Reverse(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void parseTrailer(List<byte> trailer) {
|
||||
offsetByteSize = BitConverter.ToInt32(RegulateNullBytes(trailer.GetRange(6, 1).ToArray(), 4), 0);
|
||||
objRefSize = BitConverter.ToInt32(RegulateNullBytes(trailer.GetRange(7, 1).ToArray(), 4), 0);
|
||||
byte[] refCountBytes = trailer.GetRange(12, 4).ToArray();
|
||||
Array.Reverse(refCountBytes);
|
||||
refCount = BitConverter.ToInt32(refCountBytes, 0);
|
||||
byte[] offsetTableOffsetBytes = trailer.GetRange(24, 8).ToArray();
|
||||
Array.Reverse(offsetTableOffsetBytes);
|
||||
offsetTableOffset = BitConverter.ToInt64(offsetTableOffsetBytes, 0);
|
||||
}
|
||||
|
||||
private static void parseOffsetTable(List<byte> offsetTableBytes) {
|
||||
for (int i = 0; i < offsetTableBytes.Count; i += offsetByteSize) {
|
||||
byte[] buffer = offsetTableBytes.GetRange(i, offsetByteSize).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
offsetTable.Add(BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0));
|
||||
}
|
||||
}
|
||||
|
||||
private static object parseBinaryDictionary(int objRef) {
|
||||
Dictionary<string, object> buffer = new Dictionary<string, object>();
|
||||
List<int> refs = new List<int>();
|
||||
int refCount = 0;
|
||||
|
||||
int refStartPosition;
|
||||
refCount = getCount(offsetTable[objRef], out refStartPosition);
|
||||
|
||||
|
||||
if (refCount < 15)
|
||||
refStartPosition = offsetTable[objRef] + 1;
|
||||
else
|
||||
refStartPosition = offsetTable[objRef] + 2 + RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
|
||||
|
||||
for (int i = refStartPosition; i < refStartPosition + refCount * 2 * objRefSize; i += objRefSize) {
|
||||
byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
|
||||
Array.Reverse(refBuffer);
|
||||
refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < refCount; i++) {
|
||||
buffer.Add((string)parseBinary(refs[i]), parseBinary(refs[i + refCount]));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static object parseBinaryArray(int objRef) {
|
||||
List<object> buffer = new List<object>();
|
||||
List<int> refs = new List<int>();
|
||||
int refCount = 0;
|
||||
|
||||
int refStartPosition;
|
||||
refCount = getCount(offsetTable[objRef], out refStartPosition);
|
||||
|
||||
|
||||
if (refCount < 15)
|
||||
refStartPosition = offsetTable[objRef] + 1;
|
||||
else
|
||||
//The following integer has a header aswell so we increase the refStartPosition by two to account for that.
|
||||
refStartPosition = offsetTable[objRef] + 2 + RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
|
||||
|
||||
for (int i = refStartPosition; i < refStartPosition + refCount * objRefSize; i += objRefSize) {
|
||||
byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
|
||||
Array.Reverse(refBuffer);
|
||||
refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < refCount; i++) {
|
||||
buffer.Add(parseBinary(refs[i]));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static int getCount(int bytePosition, out int newBytePosition) {
|
||||
byte headerByte = objectTable[bytePosition];
|
||||
byte headerByteTrail = Convert.ToByte(headerByte & 0xf);
|
||||
int count;
|
||||
if (headerByteTrail < 15) {
|
||||
count = headerByteTrail;
|
||||
newBytePosition = bytePosition + 1;
|
||||
}
|
||||
else
|
||||
count = (int)parseBinaryInt(bytePosition + 1, out newBytePosition);
|
||||
return count;
|
||||
}
|
||||
|
||||
private static object parseBinary(int objRef) {
|
||||
byte header = objectTable[offsetTable[objRef]];
|
||||
switch (header & 0xF0) {
|
||||
case 0: {
|
||||
//If the byte is
|
||||
//0 return null
|
||||
//9 return true
|
||||
//8 return false
|
||||
return (objectTable[offsetTable[objRef]] == 0) ? (object)null : ((objectTable[offsetTable[objRef]] == 9) ? true : false);
|
||||
}
|
||||
case 0x10: {
|
||||
return parseBinaryInt(offsetTable[objRef]);
|
||||
}
|
||||
case 0x20: {
|
||||
return parseBinaryReal(offsetTable[objRef]);
|
||||
}
|
||||
case 0x30: {
|
||||
return parseBinaryDate(offsetTable[objRef]);
|
||||
}
|
||||
case 0x40: {
|
||||
return parseBinaryByteArray(offsetTable[objRef]);
|
||||
}
|
||||
case 0x50://String ASCII
|
||||
{
|
||||
return parseBinaryAsciiString(offsetTable[objRef]);
|
||||
}
|
||||
case 0x60://String Unicode
|
||||
{
|
||||
return parseBinaryUnicodeString(offsetTable[objRef]);
|
||||
}
|
||||
case 0xD0: {
|
||||
return parseBinaryDictionary(objRef);
|
||||
}
|
||||
case 0xA0: {
|
||||
return parseBinaryArray(objRef);
|
||||
}
|
||||
}
|
||||
throw new Exception("This type is not supported");
|
||||
}
|
||||
|
||||
public static object parseBinaryDate(int headerPosition) {
|
||||
byte[] buffer = objectTable.GetRange(headerPosition + 1, 8).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
double appleTime = BitConverter.ToDouble(buffer, 0);
|
||||
DateTime result = PlistDateConverter.ConvertFromAppleTimeStamp(appleTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static object parseBinaryInt(int headerPosition) {
|
||||
int output;
|
||||
return parseBinaryInt(headerPosition, out output);
|
||||
}
|
||||
|
||||
private static object parseBinaryInt(int headerPosition, out int newHeaderPosition) {
|
||||
byte header = objectTable[headerPosition];
|
||||
int byteCount = (int)Math.Pow(2, header & 0xf);
|
||||
byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
//Add one to account for the header byte
|
||||
newHeaderPosition = headerPosition + byteCount + 1;
|
||||
return BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0);
|
||||
}
|
||||
|
||||
private static object parseBinaryReal(int headerPosition) {
|
||||
byte header = objectTable[headerPosition];
|
||||
int byteCount = (int)Math.Pow(2, header & 0xf);
|
||||
byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
|
||||
return BitConverter.ToDouble(RegulateNullBytes(buffer, 8), 0);
|
||||
}
|
||||
|
||||
private static object parseBinaryAsciiString(int headerPosition) {
|
||||
int charStartPosition;
|
||||
int charCount = getCount(headerPosition, out charStartPosition);
|
||||
|
||||
var buffer = objectTable.GetRange(charStartPosition, charCount);
|
||||
return buffer.Count > 0 ? Encoding.ASCII.GetString(buffer.ToArray()) : string.Empty;
|
||||
}
|
||||
|
||||
private static object parseBinaryUnicodeString(int headerPosition) {
|
||||
int charStartPosition;
|
||||
int charCount = getCount(headerPosition, out charStartPosition);
|
||||
charCount = charCount * 2;
|
||||
|
||||
byte[] buffer = new byte[charCount];
|
||||
byte one, two;
|
||||
|
||||
for (int i = 0; i < charCount; i += 2) {
|
||||
one = objectTable.GetRange(charStartPosition + i, 1)[0];
|
||||
two = objectTable.GetRange(charStartPosition + i + 1, 1)[0];
|
||||
|
||||
if (BitConverter.IsLittleEndian) {
|
||||
buffer[i] = two;
|
||||
buffer[i + 1] = one;
|
||||
}
|
||||
else {
|
||||
buffer[i] = one;
|
||||
buffer[i + 1] = two;
|
||||
}
|
||||
}
|
||||
|
||||
return Encoding.Unicode.GetString(buffer);
|
||||
}
|
||||
|
||||
private static object parseBinaryByteArray(int headerPosition) {
|
||||
int byteStartPosition;
|
||||
int byteCount = getCount(headerPosition, out byteStartPosition);
|
||||
return objectTable.GetRange(byteStartPosition, byteCount).ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum plistType {
|
||||
Auto, Binary, Xml
|
||||
}
|
||||
|
||||
public static class PlistDateConverter {
|
||||
public static long timeDifference = 978307200;
|
||||
|
||||
public static long GetAppleTime(long unixTime) {
|
||||
return unixTime - timeDifference;
|
||||
}
|
||||
|
||||
public static long GetUnixTime(long appleTime) {
|
||||
return appleTime + timeDifference;
|
||||
}
|
||||
|
||||
public static DateTime ConvertFromAppleTimeStamp(double timestamp) {
|
||||
DateTime origin = new DateTime(2001, 1, 1, 0, 0, 0, 0);
|
||||
return origin.AddSeconds(timestamp);
|
||||
}
|
||||
|
||||
public static double ConvertToAppleTimeStamp(DateTime date) {
|
||||
DateTime begin = new DateTime(2001, 1, 1, 0, 0, 0, 0);
|
||||
TimeSpan diff = date - begin;
|
||||
return Math.Floor(diff.TotalSeconds);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6805a4a1bc3dde4418e39fe1e4ab68b0
|
||||
timeCreated: 1614591336
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -11,7 +11,7 @@
|
||||
"depth": 2,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.16",
|
||||
@@ -20,14 +20,14 @@
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.9"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.nuget.newtonsoft-json": {
|
||||
"version": "3.0.2",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.test-framework": {
|
||||
"version": "1.1.31",
|
||||
@@ -38,7 +38,7 @@
|
||||
"com.unity.modules.imgui": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ugui": {
|
||||
"version": "1.0.0",
|
||||
|
@@ -21,15 +21,16 @@ MonoBehaviour:
|
||||
m_Registries:
|
||||
- m_Id: main
|
||||
m_Name:
|
||||
m_Url: https://packages.unity.cn
|
||||
m_Url: https://packages.unity.com
|
||||
m_Scopes: []
|
||||
m_IsDefault: 1
|
||||
m_Capabilities: 7
|
||||
m_ConfigSource: 0
|
||||
m_UserSelectedRegistryName:
|
||||
m_UserAddingNewScopedRegistry: 0
|
||||
m_RegistryInfoDraft:
|
||||
m_Modified: 0
|
||||
m_ErrorMessage:
|
||||
m_UserModificationsInstanceId: -844
|
||||
m_OriginalInstanceId: -846
|
||||
m_UserModificationsInstanceId: -830
|
||||
m_OriginalInstanceId: -832
|
||||
m_LoadAssets: 0
|
||||
|
@@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 2021.3.10f1c1
|
||||
m_EditorVersionWithRevision: 2021.3.10f1c1 (fad0948fb939)
|
||||
m_EditorVersion: 2021.3.14f1
|
||||
m_EditorVersionWithRevision: 2021.3.14f1 (eee1884e7226)
|
||||
|
Reference in New Issue
Block a user