Compare commits
52 Commits
0.5.0-rc0
...
15e9217f93
Author | SHA1 | Date | |
---|---|---|---|
15e9217f93 | |||
79240fdfe8 | |||
678e145271 | |||
5cdf10874e | |||
777b7d9c34 | |||
34b17f3111 | |||
fd9e2ce409 | |||
cd8aa0e65c | |||
5240408f00 | |||
a7e6522a57 | |||
d89e5a2e68 | |||
05124ac406 | |||
a4fdb97424 | |||
735a85b914 | |||
be0c71702b | |||
535959a6ed | |||
ae37b27dc0 | |||
80cc5fdbda | |||
87e406e903 | |||
f04d0ec299 | |||
a19057f869 | |||
d0d981b790 | |||
c95ae92ba8 | |||
31e9f1352b | |||
9974b25377 | |||
852c93c6d0 | |||
15e66d29c4 | |||
3d5ea4f056 | |||
1772c90c2f | |||
53ada70dda | |||
a8ab73ac65 | |||
35ac57bfba | |||
945f9ca7d1 | |||
d2b2834a60 | |||
f82e0ce9ef | |||
5444ea7186 | |||
3a54d2023f | |||
cb3e3e5f28 | |||
174f616e5c | |||
0f8bb5f1f6 | |||
2d35e3177b | |||
7b1f639412 | |||
fcc9935325 | |||
8b29cd2893 | |||
f44d9546e1 | |||
1d1d2646c4 | |||
6444de41a2 | |||
ea856f3339 | |||
74b1a5485b | |||
975b48e61e | |||
9e0bf024d7 | |||
d2ff168e25 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -61,6 +61,7 @@ crashlytics-build.properties
|
|||||||
#
|
#
|
||||||
/Docs
|
/Docs
|
||||||
/Issues
|
/Issues
|
||||||
|
/Local
|
||||||
/Obsolete
|
/Obsolete
|
||||||
/Snapshots
|
/Snapshots
|
||||||
/UI
|
/UI
|
||||||
|
Binary file not shown.
@@ -17,7 +17,7 @@ namespace Cryville.Common {
|
|||||||
public static void SetLogPath(string path) {
|
public static void SetLogPath(string path) {
|
||||||
logPath = path;
|
logPath = path;
|
||||||
var dir = new DirectoryInfo(path);
|
var dir = new DirectoryInfo(path);
|
||||||
if (!dir.Exists) Directory.CreateDirectory(dir.FullName);
|
if (!dir.Exists) dir.Create();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs to the specified logger.
|
/// Logs to the specified logger.
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 925f95cb7c6644a4695b2701d42e1ea2
|
|
||||||
folderAsset: yes
|
|
||||||
timeCreated: 1606989037
|
|
||||||
licenseType: Free
|
|
||||||
DefaultImporter:
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Plist {
|
|
||||||
public class PlistConvert {
|
|
||||||
public static T Deserialize<T>(string file) {
|
|
||||||
return (T)Deserialize(typeof(T), PlistCS.Plist.readPlist(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static object Deserialize(Type type, object obj, Binder binder = null) {
|
|
||||||
if (binder == null)
|
|
||||||
binder = BinderAttribute.CreateBinderOfType(type);
|
|
||||||
if (obj is IList) {
|
|
||||||
var lobj = (List<object>)obj;
|
|
||||||
foreach (var i in lobj) {
|
|
||||||
throw new NotImplementedException(); // TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (obj is IDictionary) {
|
|
||||||
var dobj = (Dictionary<string, object>)obj;
|
|
||||||
if (typeof(IDictionary).IsAssignableFrom(type)) {
|
|
||||||
var result = (IDictionary)ReflectionHelper.InvokeEmptyConstructor(type);
|
|
||||||
var it = type.GetGenericArguments()[1];
|
|
||||||
foreach (var i in dobj) {
|
|
||||||
var value = Deserialize(it, i.Value, binder);
|
|
||||||
result.Add(i.Key, value);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
|
||||||
foreach (var i in dobj) {
|
|
||||||
var imis = type.GetMember(i.Key);
|
|
||||||
if (imis.Length == 0) continue;
|
|
||||||
var imi = imis[0];
|
|
||||||
var it = ReflectionHelper.GetMemberType(imi);
|
|
||||||
var value = Deserialize(it, i.Value, binder);
|
|
||||||
ReflectionHelper.SetValue(imi, result, value, binder);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else return obj;
|
|
||||||
throw new Exception(); // TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -168,5 +168,19 @@ namespace Cryville.Common {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the namespace qualified name of a type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The type.</param>
|
||||||
|
/// <returns>The namespace qualified name of the class.</returns>
|
||||||
|
public static string GetNamespaceQualifiedName(Type type) {
|
||||||
|
string result = type.Namespace + "." + type.Name;
|
||||||
|
var typeargs = type.GetGenericArguments();
|
||||||
|
if (typeargs.Length > 0) {
|
||||||
|
result = string.Format("{0}[{1}]", result, string.Join(",", from a in typeargs select GetNamespaceQualifiedName(a)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,9 @@ namespace Cryville.Common {
|
|||||||
/// <param name="name">The file name excluding the extension.</param>
|
/// <param name="name">The file name excluding the extension.</param>
|
||||||
/// <returns>The escaped file name.</returns>
|
/// <returns>The escaped file name.</returns>
|
||||||
public static string EscapeFileName(string name) {
|
public static string EscapeFileName(string name) {
|
||||||
return Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}\.\s]", "_");
|
var result = Regex.Replace(name, @"[\/\\\<\>\:\x22\|\?\*\p{Cc}]", "_").TrimEnd(' ', '.');
|
||||||
|
if (result.Length == 0) return "_";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,14 +9,6 @@ namespace Cryville.Common.Unity {
|
|||||||
return (num2 & num) == num;
|
return (num2 & num) == num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowException(Exception ex) {
|
|
||||||
ShowMessageBox(ex.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ShowMessageBox(string message) {
|
|
||||||
GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Popup")).GetComponent<Popup>().Message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Purge(Transform obj) {
|
public static void Purge(Transform obj) {
|
||||||
foreach (Transform i in obj)
|
foreach (Transform i in obj)
|
||||||
GameObject.Destroy(i.gameObject);
|
GameObject.Destroy(i.gameObject);
|
||||||
|
@@ -13,6 +13,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
};
|
};
|
||||||
// TODO set private
|
// TODO set private
|
||||||
public readonly List<InputHandler> _handlers = new List<InputHandler>();
|
public readonly List<InputHandler> _handlers = new List<InputHandler>();
|
||||||
|
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
||||||
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
||||||
readonly object _lock = new object();
|
readonly object _lock = new object();
|
||||||
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
||||||
@@ -22,6 +23,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
try {
|
try {
|
||||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||||
|
_typemap.Add(t, h);
|
||||||
h.OnInput += OnInput;
|
h.OnInput += OnInput;
|
||||||
_handlers.Add(h);
|
_handlers.Add(h);
|
||||||
_timeOrigins.Add(h, 0);
|
_timeOrigins.Add(h, 0);
|
||||||
@@ -32,6 +34,9 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public InputHandler GetHandler(string name) {
|
||||||
|
return _typemap[Type.GetType(name)];
|
||||||
|
}
|
||||||
public void Activate() {
|
public void Activate() {
|
||||||
lock (_lock) {
|
lock (_lock) {
|
||||||
_events.Clear();
|
_events.Clear();
|
||||||
|
@@ -1,29 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Unity {
|
|
||||||
public class Popup : MonoBehaviour {
|
|
||||||
|
|
||||||
public string Message = "";
|
|
||||||
|
|
||||||
LayoutElement layout;
|
|
||||||
|
|
||||||
float timer = 0;
|
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
|
||||||
void Start() {
|
|
||||||
layout = GetComponent<LayoutElement>();
|
|
||||||
GetComponentInChildren<Text>().text = Message;
|
|
||||||
transform.SetParent(GameObject.Find("PopupList").transform);
|
|
||||||
layout.minHeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update() {
|
|
||||||
if (timer <= 0.8f) layout.minHeight = timer * 50;
|
|
||||||
else if (timer >= 5f) GameObject.Destroy(gameObject);
|
|
||||||
else if (timer >= 4.2f) layout.minHeight = (300 - timer) * 50;
|
|
||||||
timer += Time.deltaTime;
|
|
||||||
}
|
|
||||||
#pragma warning restore IDE0051
|
|
||||||
}
|
|
||||||
}
|
|
@@ -133,10 +133,10 @@ namespace Cryville.Common.Unity {
|
|||||||
prop.SetValue(Target, v, new object[]{ });
|
prop.SetValue(Target, v, new object[]{ });
|
||||||
}
|
}
|
||||||
catch (TargetInvocationException ex) {
|
catch (TargetInvocationException ex) {
|
||||||
CallHelper.ShowMessageBox(ex.InnerException.Message);
|
// CallHelper.ShowMessageBox(ex.InnerException.Message);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
CallHelper.ShowMessageBox(ex.Message);
|
// CallHelper.ShowMessageBox(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateValue();
|
UpdateValue();
|
||||||
|
@@ -200,8 +200,7 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
|
|
||||||
void GenerateLine(int index, int line) {
|
void GenerateLine(int index, int line) {
|
||||||
for (int j = 0; j < LineItemCount; j++) {
|
for (int j = 0; j < LineItemCount; j++) {
|
||||||
var child = GameObject.Instantiate(m_itemTemplate);
|
var child = GameObject.Instantiate(m_itemTemplate, transform, false);
|
||||||
child.transform.SetParent(transform, false);
|
|
||||||
lines[index][j] = child;
|
lines[index][j] = child;
|
||||||
}
|
}
|
||||||
LoadLine(index, line);
|
LoadLine(index, line);
|
||||||
|
22
Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs
Normal file
22
Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public class ChartResourceImporter : ResourceConverter {
|
||||||
|
static readonly string[] SUPPORTED_FORMATS = { ".umgc" };
|
||||||
|
public override string[] GetSupportedFormats() {
|
||||||
|
return SUPPORTED_FORMATS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||||
|
var meta = Path.Combine(file.Directory.FullName, "meta.json");
|
||||||
|
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
|
||||||
|
using (StreamReader reader = new StreamReader(meta, Encoding.UTF8)) {
|
||||||
|
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
return new Resource[] { new ChartResource(data.name, file) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: da665e46f8c2b5b46ad8e3bf5cd34007
|
guid: 168366bb891392b42a1d0a6bfa068ff3
|
||||||
timeCreated: 1605077404
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
@@ -47,11 +47,11 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
_cover.sprite = m_coverPlaceholder;
|
_cover.sprite = m_coverPlaceholder;
|
||||||
if (data.Cover != null) data.Cover.Destination = DisplayCover;
|
if (data.Cover != null) data.Cover.Destination = DisplayCover;
|
||||||
var meta = data.Meta;
|
var meta = data.Meta;
|
||||||
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.chart.name);
|
_title.text = string.Format("{0}\n{1}", meta.song.name, meta.name);
|
||||||
_desc.text = string.Format(
|
_desc.text = string.Format(
|
||||||
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
|
"Music artist: {0}\nCharter: {1}\nLength: {2}\nNote Count: {3}",
|
||||||
meta.song.author, meta.chart.author,
|
meta.song.author, meta.author,
|
||||||
TimeSpan.FromSeconds(meta.chart.length).ToString(3), meta.note_count
|
TimeSpan.FromSeconds(meta.length).ToString(3), meta.note_count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||||
@@ -60,10 +60,10 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void OnPlay() {
|
public void OnPlay() {
|
||||||
Master.Open(_id);
|
Master.Open(_id, _data);
|
||||||
}
|
}
|
||||||
public void OnConfig() {
|
public void OnConfig() {
|
||||||
Master.OpenConfig(_id);
|
Master.OpenConfig(_id, _data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
|
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
|
||||||
@@ -58,22 +59,25 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
public ResourceItemMeta GetItemMeta(int id) {
|
public ResourceItemMeta GetItemMeta(int id) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
AsyncDelivery<Texture2D> cover = null;
|
var meta = new ChartMeta();
|
||||||
var coverFile = item.GetFiles("cover.*");
|
|
||||||
if (coverFile.Length > 0) {
|
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
|
||||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
|
||||||
cover.CancelSource = task.Cancel;
|
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
|
||||||
}
|
|
||||||
string name = item.Name;
|
string name = item.Name;
|
||||||
string desc = "(Unknown)";
|
string desc = "(Unknown)";
|
||||||
var metaFile = new FileInfo(item.FullName + "/meta.json");
|
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||||
if (metaFile.Exists) {
|
if (metaFile.Exists) {
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
name = meta.song.name;
|
name = meta.song.name;
|
||||||
desc = meta.chart.name;
|
desc = meta.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AsyncDelivery<Texture2D> cover = null;
|
||||||
|
if (meta.cover != null && meta.cover != "") {
|
||||||
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
|
if (coverFile.Length > 0) {
|
||||||
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
|
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
|
cover.CancelSource = task.Cancel;
|
||||||
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ResourceItemMeta {
|
return new ResourceItemMeta {
|
||||||
@@ -86,21 +90,23 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
public ChartDetail GetItemDetail(int id) {
|
public ChartDetail GetItemDetail(int id) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
AsyncDelivery<Texture2D> cover = null;
|
var meta = new ChartMeta();
|
||||||
var coverFile = item.GetFiles("cover.*");
|
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||||
if (coverFile.Length > 0) {
|
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
|
||||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
|
||||||
cover.CancelSource = task.Cancel;
|
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
|
||||||
}
|
|
||||||
ChartMeta meta = new ChartMeta();
|
|
||||||
var metaFile = new FileInfo(item.FullName + "/meta.json");
|
|
||||||
if (metaFile.Exists) {
|
if (metaFile.Exists) {
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AsyncDelivery<Texture2D> cover = null;
|
||||||
|
if (meta.cover != null && meta.cover != "") {
|
||||||
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
|
if (coverFile.Length > 0) {
|
||||||
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
|
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
|
cover.CancelSource = task.Cancel;
|
||||||
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
return new ChartDetail {
|
return new ChartDetail {
|
||||||
Cover = cover,
|
Cover = cover,
|
||||||
Meta = meta,
|
Meta = meta,
|
||||||
@@ -108,39 +114,72 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string GetItemPath(int id) {
|
public string GetItemPath(int id) {
|
||||||
return items[id].Name + "/.umgc";
|
var item = items[id];
|
||||||
|
var meta = new ChartMeta();
|
||||||
|
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
||||||
|
using (var reader = new StreamReader(metaFile.FullName)) {
|
||||||
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
return string.Format("{0}/{1}.json", items[id].Name, meta.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ImportItemFrom(string path) {
|
public bool ImportItemFrom(string path) {
|
||||||
var file = new FileInfo(path);
|
var file = new FileInfo(path);
|
||||||
if (!converters.ContainsKey(file.Extension)) return false;
|
if (!converters.ContainsKey(file.Extension)) return false;
|
||||||
foreach (var converter in converters[file.Extension]) {
|
foreach (var converter in converters[file.Extension]) {
|
||||||
var resources = converter.ConvertFrom(file);
|
IEnumerable<Resource> resources = null;
|
||||||
|
try {
|
||||||
|
resources = converter.ConvertFrom(file);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
LogAndPopup(4, ex.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
foreach (var res in resources) {
|
foreach (var res in resources) {
|
||||||
if (res is ChartResource) {
|
if (!res.Valid) {
|
||||||
var tres = (ChartResource)res;
|
LogAndPopup(3, "Attempt to import invalid resource: {0}", res);
|
||||||
|
}
|
||||||
|
else if (res is RawChartResource) {
|
||||||
|
var tres = (RawChartResource)res;
|
||||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||||
if (!dir.Exists) dir.Create();
|
if (!dir.Exists) dir.Create();
|
||||||
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
using (var writer = new StreamWriter(dir.FullName + "/.json")) {
|
||||||
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings));
|
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings));
|
||||||
}
|
}
|
||||||
using (var writer = new StreamWriter(dir.FullName + "/meta.json")) {
|
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
||||||
|
tres.Meta.data = "";
|
||||||
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
||||||
}
|
}
|
||||||
|
if (tres.Meta.cover != null)
|
||||||
|
new FileInfo(Path.Combine(file.Directory.FullName, tres.Meta.cover))
|
||||||
|
.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
||||||
}
|
}
|
||||||
else if (res is CoverResource) {
|
else if (res is FileResource) {
|
||||||
var tres = (CoverResource)res;
|
var tres = (FileResource)res;
|
||||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
DirectoryInfo dest;
|
||||||
if (!dir.Exists) dir.Create();
|
if (res is ChartResource)
|
||||||
var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/cover" + tres.Source.Extension);
|
dest = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||||
if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
|
else if (res is RulesetResource)
|
||||||
|
dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name);
|
||||||
|
else if (res is SkinResource)
|
||||||
|
dest = new DirectoryInfo(_rootPath + "/skins/" + res.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) {
|
else {
|
||||||
var tres = (SongResource)res;
|
LogAndPopup(3, "Attempt to import unsupported resource: {0}", 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -148,6 +187,12 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogAndPopup(int level, string format, params object[] args) {
|
||||||
|
var msg = string.Format(format, args);
|
||||||
|
Logger.Log("main", level, "Resource", msg);
|
||||||
|
Popup.Create(msg);
|
||||||
|
}
|
||||||
|
|
||||||
public string[] GetSupportedFormats() {
|
public string[] GetSupportedFormats() {
|
||||||
return converters.Keys.ToArray();
|
return converters.Keys.ToArray();
|
||||||
}
|
}
|
||||||
|
@@ -24,10 +24,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
const float SPEED = 8;
|
const float SPEED = 8;
|
||||||
float _ratio;
|
float _ratio;
|
||||||
#pragma warning disable IDE0051
|
#pragma warning disable IDE0051
|
||||||
void Start() {
|
|
||||||
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (_value && _ratio != 1) {
|
if (_value && _ratio != 1) {
|
||||||
_ratio += SPEED * Time.deltaTime;
|
_ratio += SPEED * Time.deltaTime;
|
||||||
@@ -40,6 +36,10 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
UpdateGraphics();
|
UpdateGraphics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnRectTransformDimensionsChange() {
|
||||||
|
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
||||||
|
}
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
|
|
||||||
void UpdateGraphics() {
|
void UpdateGraphics() {
|
||||||
|
@@ -60,7 +60,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
|
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
|
||||||
m_ctn.triggers.Add(ev);
|
m_ctn.triggers.Add(ev);
|
||||||
|
|
||||||
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
|
||||||
if (MaxStep != 0) SetRatio(0.5f);
|
if (MaxStep != 0) SetRatio(0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +69,10 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
SetValueFromPos(pp);
|
SetValueFromPos(pp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnRectTransformDimensionsChange() {
|
||||||
|
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
|
||||||
|
}
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
|
|
||||||
Vector2 pp;
|
Vector2 pp;
|
||||||
|
28
Assets/Cryville/Crtr/Browsing/PVPString.cs
Normal file
28
Assets/Cryville/Crtr/Browsing/PVPString.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public class PVPString : PropertyValuePanel {
|
||||||
|
string m_value;
|
||||||
|
public override object Value {
|
||||||
|
get {
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
m_value = (string)value;
|
||||||
|
_inputField.text = m_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InputField _inputField;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
_inputField = GetComponent<InputField>();
|
||||||
|
_inputField.onValueChanged.AddListener(OnValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnValueChanged(string value) {
|
||||||
|
m_value = value;
|
||||||
|
Callback(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 3bc71e8b62d4022409aa5518bbf3a7d8
|
guid: aadf11739189bc94e9cb4f702eb7ccd3
|
||||||
timeCreated: 1608801352
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
@@ -32,8 +32,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
|
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
|
||||||
Name = name.ToUpper();
|
Name = name.ToUpper();
|
||||||
foreach (var prop in props) {
|
foreach (var prop in props) {
|
||||||
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab);
|
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab, transform, false);
|
||||||
obj.transform.SetParent(transform, false);
|
|
||||||
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject m_bool;
|
GameObject m_bool;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_number;
|
GameObject m_number;
|
||||||
|
[SerializeField]
|
||||||
|
GameObject m_string;
|
||||||
|
|
||||||
PropertyInfo _property;
|
PropertyInfo _property;
|
||||||
object _target;
|
object _target;
|
||||||
@@ -32,8 +34,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject vp;
|
GameObject vp;
|
||||||
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
||||||
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
||||||
|
else if (prop.PropertyType == typeof(string)) vp = m_string;
|
||||||
else return;
|
else return;
|
||||||
_value = GameObject.Instantiate(vp, _valueContainer).GetComponent<PropertyValuePanel>();
|
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
||||||
if (_value is PVPNumber) {
|
if (_value is PVPNumber) {
|
||||||
var t = (PVPNumber)_value;
|
var t = (PVPNumber)_value;
|
||||||
t.IntegerMode = prop.PropertyType == typeof(int);
|
t.IntegerMode = prop.PropertyType == typeof(int);
|
||||||
|
@@ -59,11 +59,11 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
private void OnAddDialogClosed() {
|
private void OnAddDialogClosed() {
|
||||||
if (_dialog.FileName == null) return;
|
if (_dialog.FileName == null) return;
|
||||||
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
|
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
|
||||||
Debug.Log("Import succeeded"); // TODO
|
Popup.Create("Import succeeded");
|
||||||
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Debug.Log("Import failed"); // TODO
|
Popup.Create("Import failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Unity.UI;
|
using Cryville.Common.Unity.UI;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
@@ -64,8 +65,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
_units[_slideDest + 1].SlideToRight();
|
_units[_slideDest + 1].SlideToRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open(int id) {
|
public void Open(int id, ChartDetail detail) {
|
||||||
SetDataSettings(id);
|
SetDataSettings(id, detail);
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
||||||
#else
|
#else
|
||||||
@@ -74,8 +75,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenConfig(int id) {
|
public void OpenConfig(int id, ChartDetail detail) {
|
||||||
SetDataSettings(id);
|
SetDataSettings(id, detail);
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
SceneManager.LoadScene("Config", LoadSceneMode.Additive);
|
SceneManager.LoadScene("Config", LoadSceneMode.Additive);
|
||||||
#else
|
#else
|
||||||
@@ -84,9 +85,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDataSettings(int id) {
|
void SetDataSettings(int id, ChartDetail detail) {
|
||||||
Settings.Default.LoadRuleset = "key/.umgr";
|
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
||||||
Settings.Default.LoadSkin = "key/0/.umgs";
|
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
||||||
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
|
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,16 +98,22 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
public struct ChartMeta {
|
public class MetaInfo {
|
||||||
public MetaInfo song { get; set; }
|
public string name { get; set; }
|
||||||
public MetaInfo chart { get; set; }
|
public string author { get; set; }
|
||||||
public struct MetaInfo {
|
[JsonRequired]
|
||||||
public string name { get; set; }
|
public string data { get; set; }
|
||||||
public string author { get; set; }
|
}
|
||||||
public float length { get; set; }
|
public class SongMetaInfo {
|
||||||
}
|
public string name { get; set; }
|
||||||
|
public string author { get; set; }
|
||||||
|
}
|
||||||
|
public class ChartMeta : MetaInfo {
|
||||||
|
public SongMetaInfo song { get; set; }
|
||||||
|
public float length { get; set; }
|
||||||
public string ruleset { get; set; }
|
public string ruleset { get; set; }
|
||||||
public int note_count { get; set; }
|
public int note_count { get; set; }
|
||||||
|
public string cover { get; set; }
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
@@ -12,24 +13,76 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
Name = StringUtils.EscapeFileName(name);
|
Name = StringUtils.EscapeFileName(name);
|
||||||
}
|
}
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
public abstract bool Valid { get; }
|
||||||
|
public override string ToString() {
|
||||||
|
return string.Format("{0} ({1})", Name, ReflectionHelper.GetSimpleName(GetType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public class ChartResource : Resource {
|
public class RawChartResource : Resource {
|
||||||
public ChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
public RawChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
||||||
Main = main; Meta = meta;
|
Main = main; Meta = meta;
|
||||||
}
|
}
|
||||||
public Chart Main { get; private set; }
|
public Chart Main { get; private set; }
|
||||||
public ChartMeta Meta { get; private set; }
|
public ChartMeta Meta { get; private set; }
|
||||||
|
public override bool Valid { get { return true; } }
|
||||||
}
|
}
|
||||||
public class CoverResource : Resource {
|
public abstract class FileResource : Resource {
|
||||||
public CoverResource(string name, FileInfo src) : base(name) {
|
public FileResource(string name, FileInfo master, FileInfo[] attachments) : base(name) {
|
||||||
Source = src;
|
Master = master;
|
||||||
|
Attachments = attachments;
|
||||||
|
}
|
||||||
|
public FileInfo Master { get; private set; }
|
||||||
|
public 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 class SongResource : Resource {
|
public class ChartResource : FileResource {
|
||||||
public SongResource(string name, FileInfo src) : base(name) {
|
public ChartResource(string name, FileInfo master) : base(name, master, GetAttachments(master)) { }
|
||||||
Source = src;
|
static FileInfo[] GetAttachments(FileInfo master) {
|
||||||
|
using (var reader = new StreamReader(master.FullName)) {
|
||||||
|
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
|
var result = new List<FileInfo> {
|
||||||
|
new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")),
|
||||||
|
};
|
||||||
|
if (meta.cover != null) result.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class SongResource : FileResource {
|
||||||
|
public SongResource(string name, FileInfo master) : base(name, master, new FileInfo[0]) { }
|
||||||
|
}
|
||||||
|
public class RulesetResource : FileResource {
|
||||||
|
public RulesetResource(string name, FileInfo master) : base(name, master, GetAttachments(master)) { }
|
||||||
|
static FileInfo[] GetAttachments(FileInfo master) {
|
||||||
|
using (var reader = new StreamReader(master.FullName)) {
|
||||||
|
var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||||
|
return new FileInfo[] {
|
||||||
|
new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class SkinResource : FileResource {
|
||||||
|
public SkinResource(string name, FileInfo master) : base(name, master, GetAttachments(master)) { }
|
||||||
|
static FileInfo[] GetAttachments(FileInfo master) {
|
||||||
|
using (var reader = new StreamReader(master.FullName)) {
|
||||||
|
var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
|
||||||
|
var result = new List<FileInfo> {
|
||||||
|
new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")),
|
||||||
|
};
|
||||||
|
foreach (var frame in meta.frames) {
|
||||||
|
result.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||||
|
}
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public FileInfo Source { get; private set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
20
Assets/Cryville/Crtr/Browsing/RulesetResourceImporter.cs
Normal file
20
Assets/Cryville/Crtr/Browsing/RulesetResourceImporter.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public class RulesetResourceImporter : ResourceConverter {
|
||||||
|
static readonly string[] SUPPORTED_FORMATS = { ".umgr" };
|
||||||
|
public override string[] GetSupportedFormats() {
|
||||||
|
return SUPPORTED_FORMATS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||||
|
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||||
|
var data = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||||
|
return new Resource[] { new RulesetResource(data.name, file) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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:
|
@@ -37,9 +37,9 @@ namespace Cryville.Crtr {
|
|||||||
else if (ev.Unstamped == null) { }
|
else if (ev.Unstamped == null) { }
|
||||||
else if (ev.Unstamped is Chart.Sound) {
|
else if (ev.Unstamped is Chart.Sound) {
|
||||||
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
||||||
var source = new LibavFileAudioSource(
|
var dir = new DirectoryInfo(Game.GameDataPath + "/songs/" + tev.id);
|
||||||
Game.GameDataPath + "/songs/" + tev.id + "/.ogg"
|
var files = dir.GetFiles();
|
||||||
);
|
var source = new LibavFileAudioSource(files[0].FullName);
|
||||||
source.SelectStream();
|
source.SelectStream();
|
||||||
sounds.Add(source);
|
sounds.Add(source);
|
||||||
Game.AudioSession.Sequence(
|
Game.AudioSession.Sequence(
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
//#define NO_THREAD
|
|
||||||
#define BUILD
|
#define BUILD
|
||||||
|
|
||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Plist;
|
using Cryville.Crtr.Config;
|
||||||
using Cryville.Common.Unity.Input;
|
|
||||||
using Cryville.Crtr.Event;
|
using Cryville.Crtr.Event;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
@@ -27,8 +25,7 @@ namespace Cryville.Crtr {
|
|||||||
Ruleset ruleset;
|
Ruleset ruleset;
|
||||||
PdtRuleset pruleset;
|
PdtRuleset pruleset;
|
||||||
Dictionary<string, Texture2D> texs;
|
Dictionary<string, Texture2D> texs;
|
||||||
public static Dictionary<string, Cocos2dFrames.Frame> frames;
|
public static Dictionary<string, SpriteFrame> frames;
|
||||||
List<Cocos2dFrames> plists;
|
|
||||||
|
|
||||||
readonly Queue<string> texLoadQueue = new Queue<string>();
|
readonly Queue<string> texLoadQueue = new Queue<string>();
|
||||||
#if UNITY_5_4_OR_NEWER
|
#if UNITY_5_4_OR_NEWER
|
||||||
@@ -53,6 +50,7 @@ namespace Cryville.Crtr {
|
|||||||
public static Rect hitRect;
|
public static Rect hitRect;
|
||||||
public static Plane[] frustumPlanes;
|
public static Plane[] frustumPlanes;
|
||||||
|
|
||||||
|
RulesetConfig _rscfg;
|
||||||
static bool disableGC = true;
|
static bool disableGC = true;
|
||||||
static float clippingDist = 1f;
|
static float clippingDist = 1f;
|
||||||
static float renderDist = 6f;
|
static float renderDist = 6f;
|
||||||
@@ -69,17 +67,6 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
InputProxy inputProxy;
|
InputProxy inputProxy;
|
||||||
|
|
||||||
~ChartPlayer() {
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
#if !NO_THREAD
|
|
||||||
if (loadThread != null) loadThread.Abort();
|
|
||||||
#endif
|
|
||||||
if (texLoader != null) texLoader.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region MonoBehaviour
|
#region MonoBehaviour
|
||||||
void Start() {
|
void Start() {
|
||||||
var logobj = GameObject.Find("Logs");
|
var logobj = GameObject.Find("Logs");
|
||||||
@@ -96,134 +83,153 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
texHandler = new DownloadHandlerTexture();
|
texHandler = new DownloadHandlerTexture();
|
||||||
#if BUILD
|
#if BUILD
|
||||||
Play();
|
try {
|
||||||
|
Play();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Game.LogException("Load/WorkerThread", "An error occured while loading the data", ex);
|
||||||
|
Popup.CreateException(ex);
|
||||||
|
ReturnToMenu();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Camera.main.RenderToCubemap();
|
// Camera.main.RenderToCubemap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnDestroy() {
|
||||||
|
if (cbus != null) cbus.Dispose();
|
||||||
|
if (bbus != null) bbus.Dispose();
|
||||||
|
if (tbus != null) tbus.Dispose();
|
||||||
|
if (nbus != null) nbus.Dispose();
|
||||||
|
if (loadThread != null) loadThread.Abort();
|
||||||
|
if (texLoader != null) texLoader.Dispose();
|
||||||
|
if (inputProxy != null) inputProxy.Dispose();
|
||||||
|
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
||||||
|
Camera.onPostRender -= OnCameraPostRender;
|
||||||
|
GC.Collect();
|
||||||
|
}
|
||||||
|
|
||||||
bool texloaddone;
|
bool texloaddone;
|
||||||
diag::Stopwatch texloadtimer = new diag::Stopwatch();
|
diag::Stopwatch texloadtimer = new diag::Stopwatch();
|
||||||
bool firstFrame;
|
bool firstFrame;
|
||||||
double atime0;
|
double atime0;
|
||||||
void Update() {
|
void Update() {
|
||||||
// if (Input.GetKeyDown(KeyCode.Return)) TogglePlay();
|
if (started) GameUpdate();
|
||||||
if (started) {
|
else if (loadThread != null) LoadUpdate();
|
||||||
try {
|
if (logEnabled) LogUpdate();
|
||||||
if (Screen.width != screenSize.x || Screen.height != screenSize.y)
|
else Game.MainLogger.Enumerate((level, module, msg) => { });
|
||||||
throw new InvalidOperationException("Window resized while playing");
|
}
|
||||||
float dt = firstFrame
|
void GameUpdate() {
|
||||||
|
try {
|
||||||
|
if (Screen.width != screenSize.x || Screen.height != screenSize.y)
|
||||||
|
throw new InvalidOperationException("Window resized while playing");
|
||||||
|
float dt = firstFrame
|
||||||
? 1f / Application.targetFrameRate
|
? 1f / Application.targetFrameRate
|
||||||
: Time.deltaTime;
|
: Time.deltaTime;
|
||||||
firstFrame = false;
|
firstFrame = false;
|
||||||
inputProxy.ForceTick();
|
inputProxy.ForceTick();
|
||||||
cbus.ForwardByTime(dt);
|
cbus.ForwardByTime(dt);
|
||||||
bbus.ForwardByTime(dt);
|
bbus.ForwardByTime(dt);
|
||||||
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
||||||
UnityEngine.Profiling.Profiler.BeginSample("EventBus.Copy");
|
UnityEngine.Profiling.Profiler.BeginSample("EventBus.Copy");
|
||||||
bbus.CopyTo(2, tbus);
|
bbus.CopyTo(2, tbus);
|
||||||
bbus.CopyTo(3, nbus);
|
bbus.CopyTo(3, nbus);
|
||||||
UnityEngine.Profiling.Profiler.EndSample();
|
UnityEngine.Profiling.Profiler.EndSample();
|
||||||
float step = autoRenderStep ? ( firstFrame
|
float step = autoRenderStep ? ( firstFrame
|
||||||
? 1f / Application.targetFrameRate
|
? 1f / Application.targetFrameRate
|
||||||
: Time.smoothDeltaTime
|
: Time.smoothDeltaTime
|
||||||
) : renderStep;
|
) : renderStep;
|
||||||
actualRenderStep = step;
|
actualRenderStep = step;
|
||||||
|
|
||||||
nbus.ForwardStepByTime(clippingDist, step);
|
nbus.ForwardStepByTime(clippingDist, step);
|
||||||
nbus.BroadcastEndUpdate();
|
nbus.BroadcastEndUpdate();
|
||||||
nbus.Anchor();
|
nbus.Anchor();
|
||||||
|
|
||||||
tbus.ForwardStepByTime(clippingDist, step);
|
tbus.ForwardStepByTime(clippingDist, step);
|
||||||
tbus.ForwardStepByTime(renderDist, step);
|
tbus.ForwardStepByTime(renderDist, step);
|
||||||
tbus.BroadcastEndUpdate();
|
tbus.BroadcastEndUpdate();
|
||||||
UnityEngine.Profiling.Profiler.EndSample();
|
UnityEngine.Profiling.Profiler.EndSample();
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Game.LogException("Game", "An error occured while playing", ex);
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#if !NO_THREAD
|
catch (Exception ex) {
|
||||||
else if (loadThread != null) {
|
Game.LogException("Game", "An error occured while playing", ex);
|
||||||
if (texLoader != null) {
|
Popup.CreateException(ex);
|
||||||
string url = texLoader.url;
|
Stop();
|
||||||
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
|
}
|
||||||
|
}
|
||||||
|
void LoadUpdate() {
|
||||||
|
if (texLoader != null) {
|
||||||
|
string url = texLoader.url;
|
||||||
|
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
|
||||||
#if UNITY_5_4_OR_NEWER
|
#if UNITY_5_4_OR_NEWER
|
||||||
if (texHandler.isDone) {
|
if (texHandler.isDone) {
|
||||||
var tex = texHandler.texture;
|
var tex = texHandler.texture;
|
||||||
texs.Add(name, tex);
|
tex.wrapMode = TextureWrapMode.Clamp;
|
||||||
Logger.Log("main", 0, "Load/MainThread", "Loaded texture {0} ({1} bytes)", name, texLoader.downloadedBytes);
|
texs.Add(name, tex);
|
||||||
texLoader.Dispose();
|
texLoader.Dispose();
|
||||||
texHandler.Dispose();
|
texHandler.Dispose();
|
||||||
texLoader = null;
|
texLoader = null;
|
||||||
}
|
|
||||||
else if (texLoader.downloadProgress != 0) {
|
|
||||||
Logger.Log("main", 0, "Load/MainThread", "Loading texture {0} {1:P0}", name, texLoader.downloadProgress);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (texLoader.isDone) {
|
|
||||||
var tex = texLoader.texture;
|
|
||||||
texs.Add(name, tex);
|
|
||||||
Logger.Log("main", 0, "Load/MainThread", "Loaded texture {0} ({1} bytes)", name, texLoader.bytesDownloaded);
|
|
||||||
texLoader.Dispose();
|
|
||||||
texLoader = null;
|
|
||||||
}
|
|
||||||
else if (texLoader.progress != 0) {
|
|
||||||
Logger.Log("main", 0, "Load/MainThread", "Loading texture {0} {1:P0}", name, texLoader.progress);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (texLoader == null)
|
#else
|
||||||
if (texLoadQueue.Count > 0) {
|
if (texLoader.isDone) {
|
||||||
|
var tex = texLoader.texture;
|
||||||
|
tex.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
texs.Add(name, tex);
|
||||||
|
texLoader.Dispose();
|
||||||
|
texLoader = null;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (texLoader == null)
|
||||||
|
if (texLoadQueue.Count > 0) {
|
||||||
#if UNITY_5_4_OR_NEWER
|
#if UNITY_5_4_OR_NEWER
|
||||||
texHandler = new DownloadHandlerTexture();
|
texHandler = new DownloadHandlerTexture();
|
||||||
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + texLoadQueue.Dequeue(), "GET", texHandler, null);
|
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + texLoadQueue.Dequeue(), "GET", texHandler, null);
|
||||||
texLoader.SendWebRequest();
|
texLoader.SendWebRequest();
|
||||||
#else
|
#else
|
||||||
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (!texloaddone) {
|
else if (!texloaddone) {
|
||||||
texloaddone = true;
|
texloaddone = true;
|
||||||
texloadtimer.Stop();
|
texloadtimer.Stop();
|
||||||
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
||||||
}
|
}
|
||||||
if (!loadThread.IsAlive) {
|
if (!loadThread.IsAlive) {
|
||||||
if (cbus == null) {
|
if (threadException != null) {
|
||||||
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
||||||
loadThread = null;
|
loadThread = null;
|
||||||
|
Popup.CreateException(threadException);
|
||||||
#if BUILD
|
#if BUILD
|
||||||
ReturnToMenu();
|
ReturnToMenu();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (texLoader == null) {
|
else if (texLoader == null) {
|
||||||
Prehandle();
|
Prehandle();
|
||||||
loadThread = null;
|
loadThread = null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
if (logEnabled) {
|
string timetext = string.Empty;
|
||||||
string _logs = logs.text;
|
void LogUpdate() {
|
||||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
string _logs = logs.text;
|
||||||
string color;
|
Game.MainLogger.Enumerate((level, module, msg) => {
|
||||||
switch (level) {
|
string color;
|
||||||
case 0: color = "#888888"; break;
|
switch (level) {
|
||||||
case 1: color = "#bbbbbb"; break;
|
case 0: color = "#888888"; break;
|
||||||
case 2: color = "#0088ff"; break;
|
case 1: color = "#bbbbbb"; break;
|
||||||
case 3: color = "#ffff00"; break;
|
case 2: color = "#0088ff"; break;
|
||||||
case 4: color = "#ff0000"; break;
|
case 3: color = "#ffff00"; break;
|
||||||
case 5: color = "#bb0000"; break;
|
case 4: color = "#ff0000"; break;
|
||||||
default: color = "#ff00ff"; break;
|
case 5: color = "#bb0000"; break;
|
||||||
}
|
default: color = "#ff00ff"; break;
|
||||||
_logs += string.Format(
|
}
|
||||||
"\r\n<color={1}bb><{2}> {3}</color>",
|
_logs += string.Format(
|
||||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
"\r\n<color={1}bb><{2}> {3}</color>",
|
||||||
);
|
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||||
});
|
);
|
||||||
logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\n', Mathf.Max(0, _logs.Length - 4096))));
|
});
|
||||||
var sttext = string.Format(
|
logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\n', Mathf.Max(0, _logs.Length - 4096))));
|
||||||
|
var sttext = string.Format(
|
||||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
||||||
1 / Time.deltaTime,
|
1 / Time.deltaTime,
|
||||||
1 / Time.smoothDeltaTime,
|
1 / Time.smoothDeltaTime,
|
||||||
@@ -239,18 +245,18 @@ namespace Cryville.Crtr {
|
|||||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if (started) sttext += string.Format(
|
sttext += timetext;
|
||||||
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
|
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString();
|
||||||
cbus.Time,
|
status.text = sttext;
|
||||||
Game.AudioClient.Position - atime0,
|
}
|
||||||
inputProxy.GetTimestampAverage()
|
void OnCameraPostRender(Camera cam) {
|
||||||
);
|
if (started) timetext = string.Format(
|
||||||
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString();
|
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
|
||||||
status.text = sttext;
|
cbus.Time,
|
||||||
}
|
Game.AudioClient.Position - atime0,
|
||||||
else {
|
inputProxy.GetTimestampAverage()
|
||||||
Game.MainLogger.Enumerate((level, module, msg) => { });
|
);
|
||||||
}
|
else timetext = string.Empty;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -301,14 +307,13 @@ namespace Cryville.Crtr {
|
|||||||
autoRenderStep = renderStep == 0;
|
autoRenderStep = renderStep == 0;
|
||||||
soundOffset = Settings.Default.SoundOffset;
|
soundOffset = Settings.Default.SoundOffset;
|
||||||
startOffset = Settings.Default.StartOffset;
|
startOffset = Settings.Default.StartOffset;
|
||||||
sv = Settings.Default.ScrollVelocity;
|
|
||||||
firstFrame = true;
|
firstFrame = true;
|
||||||
#if !NO_THREAD
|
|
||||||
texloaddone = false;
|
texloaddone = false;
|
||||||
#endif
|
|
||||||
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
||||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||||
|
|
||||||
|
Camera.onPostRender += OnCameraPostRender;
|
||||||
|
|
||||||
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
||||||
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
||||||
float dist;
|
float dist;
|
||||||
@@ -325,45 +330,48 @@ namespace Cryville.Crtr {
|
|||||||
FileInfo chartFile = new FileInfo(
|
FileInfo chartFile = new FileInfo(
|
||||||
Game.GameDataPath + "/charts/" + Settings.Default.LoadChart
|
Game.GameDataPath + "/charts/" + Settings.Default.LoadChart
|
||||||
);
|
);
|
||||||
|
|
||||||
FileInfo rulesetFile = new FileInfo(
|
FileInfo rulesetFile = new FileInfo(
|
||||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||||
);
|
);
|
||||||
FileInfo skinFile = new FileInfo(
|
if (!rulesetFile.Exists) throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||||
Game.GameDataPath + "/skins/" + Settings.Default.LoadSkin
|
|
||||||
|
FileInfo rulesetConfigFile = new FileInfo(
|
||||||
|
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||||
);
|
);
|
||||||
#if NO_THREAD
|
if (!rulesetConfigFile.Exists) throw new FileNotFoundException("Ruleset config not found\nPlease open the config to generate");
|
||||||
texloadtimer.Stop();
|
using (StreamReader cfgreader = new StreamReader(rulesetConfigFile.FullName, Encoding.UTF8)) {
|
||||||
Logger.LogFormat("main", 0, "Load/MainThread", "Textures loaded successfully ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
Load(new LoadInfo(){
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
chartFile = chartFile,
|
});
|
||||||
rulesetFile = rulesetFile,
|
}
|
||||||
skinFile = skinFile,
|
sv = _rscfg.generic.ScrollVelocity;
|
||||||
});
|
|
||||||
Prehandle();
|
FileInfo skinFile = new FileInfo(
|
||||||
#else
|
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 != 1) throw new FormatException("Invalid skin file version");
|
||||||
|
}
|
||||||
|
|
||||||
loadThread = new Thread(new ParameterizedThreadStart(Load));
|
loadThread = new Thread(new ParameterizedThreadStart(Load));
|
||||||
loadThread.Start(new LoadInfo() {
|
loadThread.Start(new LoadInfo() {
|
||||||
chartFile = chartFile,
|
chartFile = chartFile,
|
||||||
rulesetFile = rulesetFile,
|
rulesetFile = rulesetFile,
|
||||||
skinFile = skinFile,
|
skinFile = skinFile,
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
|
|
||||||
Logger.Log("main", 0, "Load/MainThread", "Loading textures...");
|
Logger.Log("main", 0, "Load/MainThread", "Loading textures...");
|
||||||
texloadtimer = new diag::Stopwatch();
|
texloadtimer = new diag::Stopwatch();
|
||||||
texloadtimer.Start();
|
texloadtimer.Start();
|
||||||
|
frames = new Dictionary<string, SpriteFrame>();
|
||||||
texs = new Dictionary<string, Texture2D>();
|
texs = new Dictionary<string, Texture2D>();
|
||||||
var flist = skinFile.Directory.GetFiles("*.png");
|
foreach (var f in skin.frames) {
|
||||||
foreach (FileInfo f in flist) {
|
texLoadQueue.Enqueue(Path.Combine(skinFile.Directory.FullName, f));
|
||||||
#if NO_THREAD
|
|
||||||
using (WWW w = new WWW("file:///" + f.FullName)) {
|
|
||||||
string name = StringUtils.TrimExt(f.Name);
|
|
||||||
while (!w.isDone);
|
|
||||||
texs.Add(name, w.texture);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
texLoadQueue.Enqueue(f.FullName);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,35 +380,18 @@ namespace Cryville.Crtr {
|
|||||||
diag::Stopwatch timer = new diag::Stopwatch();
|
diag::Stopwatch timer = new diag::Stopwatch();
|
||||||
timer.Reset(); timer.Start();
|
timer.Reset(); timer.Start();
|
||||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
||||||
foreach (var i in plists) i.Init(texs);
|
|
||||||
foreach (var t in texs) {
|
foreach (var t in texs) {
|
||||||
if (frames.ContainsKey(t.Key)) {
|
if (frames.ContainsKey(t.Key)) {
|
||||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var f = new Cocos2dFrames.Frame(t.Value);
|
var f = new SpriteFrame(t.Value);
|
||||||
f.Init();
|
f.Init();
|
||||||
frames.Add(t.Key, f);
|
frames.Add(t.Key, f);
|
||||||
}
|
}
|
||||||
Logger.Log("main", 0, "Load/Prehandle", "Initializing states");
|
Logger.Log("main", 0, "Load/Prehandle", "Initializing states");
|
||||||
cbus.BroadcastInit();
|
cbus.BroadcastInit();
|
||||||
|
|
||||||
inputProxy = new InputProxy(pruleset, judge);
|
|
||||||
foreach (var i in Game.InputManager._handlers) {
|
|
||||||
/*if (i is UnityKeyHandler<UnityKeyboardReceiver>) {
|
|
||||||
inputProxy.Set(new InputProxyEntry { Source = new InputSource { Handler = i, Type = (int)KeyCode.Z }, Target = "track0" });
|
|
||||||
inputProxy.Set(new InputProxyEntry { Source = new InputSource { Handler = i, Type = (int)KeyCode.X }, Target = "track1" });
|
|
||||||
inputProxy.Set(new InputProxyEntry { Source = new InputSource { Handler = i, Type = (int)KeyCode.Comma }, Target = "track2" });
|
|
||||||
inputProxy.Set(new InputProxyEntry { Source = new InputSource { Handler = i, Type = (int)KeyCode.Period }, Target = "track3" });
|
|
||||||
break;
|
|
||||||
}*/
|
|
||||||
if (i is UnityMouseHandler) {
|
|
||||||
inputProxy.Set(new InputProxyEntry { Source = new InputSource { Handler = i, Type = 0 }, Target = "screen_x" });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inputProxy.Activate();
|
inputProxy.Activate();
|
||||||
|
|
||||||
if (logEnabled) ToggleLogs();
|
if (logEnabled) ToggleLogs();
|
||||||
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up");
|
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up");
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
@@ -415,6 +406,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex);
|
Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex);
|
||||||
|
Popup.CreateException(ex);
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -422,19 +414,18 @@ namespace Cryville.Crtr {
|
|||||||
public void Stop() {
|
public void Stop() {
|
||||||
try {
|
try {
|
||||||
Logger.Log("main", 1, "Game", "Stopping");
|
Logger.Log("main", 1, "Game", "Stopping");
|
||||||
chart = null;
|
|
||||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||||
if (cbus != null) cbus.Dispose();
|
|
||||||
if (bbus != null) bbus.Dispose();
|
|
||||||
if (tbus != null) tbus.Dispose();
|
|
||||||
if (nbus != null) nbus.Dispose();
|
|
||||||
inputProxy.Deactivate();
|
inputProxy.Deactivate();
|
||||||
foreach (var t in texs) Texture.Destroy(t.Value);
|
if (cbus != null) { cbus.Dispose(); cbus = null; }
|
||||||
|
if (bbus != null) { bbus.Dispose(); bbus = null; }
|
||||||
|
if (tbus != null) { tbus.Dispose(); tbus = null; }
|
||||||
|
if (nbus != null) { nbus.Dispose(); nbus = null; }
|
||||||
Logger.Log("main", 1, "Game", "Stopped");
|
Logger.Log("main", 1, "Game", "Stopped");
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (!logEnabled) ToggleLogs();
|
if (!logEnabled) ToggleLogs();
|
||||||
Game.LogException("Game", "An error occured while stopping", ex);
|
Game.LogException("Game", "An error occured while stopping", ex);
|
||||||
|
Popup.CreateException(ex);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (started) {
|
if (started) {
|
||||||
@@ -462,6 +453,7 @@ namespace Cryville.Crtr {
|
|||||||
public FileInfo skinFile;
|
public FileInfo skinFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Exception threadException;
|
||||||
#if !NO_THREAD
|
#if !NO_THREAD
|
||||||
Thread loadThread = null;
|
Thread loadThread = null;
|
||||||
diag::Stopwatch workerTimer;
|
diag::Stopwatch workerTimer;
|
||||||
@@ -478,6 +470,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Game.LogException("Load/WorkerThread", "An error occured while loading the data", ex);
|
Game.LogException("Load/WorkerThread", "An error occured while loading the data", ex);
|
||||||
|
threadException = ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,6 +502,12 @@ namespace Cryville.Crtr {
|
|||||||
judge = new Judge(pruleset);
|
judge = new Judge(pruleset);
|
||||||
etor.ContextJudge = judge;
|
etor.ContextJudge = judge;
|
||||||
|
|
||||||
|
inputProxy = new InputProxy(pruleset, judge);
|
||||||
|
inputProxy.LoadFrom(_rscfg.inputs);
|
||||||
|
if (!inputProxy.IsCompleted) {
|
||||||
|
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||||
|
}
|
||||||
|
|
||||||
cbus.AttachSystems(pskin, judge);
|
cbus.AttachSystems(pskin, judge);
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
|
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
|
||||||
var ch = new ChartHandler(chart, dir);
|
var ch = new ChartHandler(chart, dir);
|
||||||
@@ -528,11 +527,15 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)");
|
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 1)");
|
||||||
cbus.Clone(16).Forward();
|
using (var pbus = cbus.Clone(16)) {
|
||||||
|
pbus.Forward();
|
||||||
|
}
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Patching events");
|
Logger.Log("main", 0, "Load/WorkerThread", "Patching events");
|
||||||
cbus.DoPatch();
|
cbus.DoPatch();
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 2)");
|
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 2)");
|
||||||
cbus.Clone(17).Forward();
|
using (var pbus = cbus.Clone(17)) {
|
||||||
|
pbus.Forward();
|
||||||
|
}
|
||||||
|
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)");
|
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)");
|
||||||
bbus = cbus.Clone(1, -clippingDist);
|
bbus = cbus.Clone(1, -clippingDist);
|
||||||
@@ -560,23 +563,9 @@ namespace Cryville.Crtr {
|
|||||||
void LoadSkin(FileInfo file) {
|
void LoadSkin(FileInfo file) {
|
||||||
DirectoryInfo dir = file.Directory;
|
DirectoryInfo dir = file.Directory;
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
|
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
skin.LoadPdt(dir);
|
||||||
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
pskin = skin.Root;
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
pskin.Optimize(etor);
|
||||||
});
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endregion
|
#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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -5,7 +5,7 @@ using Logger = Cryville.Common.Logger;
|
|||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public class SpriteInfo {
|
public class SpriteInfo {
|
||||||
public string FrameName;
|
public string FrameName;
|
||||||
public Cocos2dFrames.Frame Frame {
|
public SpriteFrame Frame {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,85 @@
|
|||||||
using UnityEngine;
|
using JetBrains.Annotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class ConfigScene : MonoBehaviour {
|
public class ConfigScene : MonoBehaviour {
|
||||||
|
[SerializeField]
|
||||||
|
Transform m_content;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
SettingsPanel m_genericConfigPanel;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
InputConfigPanel m_inputConfigPanel;
|
||||||
|
|
||||||
|
public Ruleset ruleset;
|
||||||
|
RulesetConfig _rscfg;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
ChartPlayer.etor = new PdtEvaluator();
|
||||||
|
FileInfo file = new FileInfo(
|
||||||
|
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||||
|
);
|
||||||
|
if (!file.Exists) {
|
||||||
|
Popup.Create("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||||
|
ReturnToMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DirectoryInfo dir = file.Directory;
|
||||||
|
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||||
|
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
|
});
|
||||||
|
if (ruleset.format != 1) throw new FormatException("Invalid ruleset file version");
|
||||||
|
ruleset.LoadPdt(dir);
|
||||||
|
}
|
||||||
|
FileInfo cfgfile = new FileInfo(
|
||||||
|
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||||
|
);
|
||||||
|
if (!cfgfile.Exists) {
|
||||||
|
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
|
||||||
|
_rscfg = new RulesetConfig();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
||||||
|
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_genericConfigPanel.Target = _rscfg.generic;
|
||||||
|
|
||||||
|
var proxy = new InputProxy(ruleset.Root, null);
|
||||||
|
proxy.LoadFrom(_rscfg.inputs);
|
||||||
|
m_inputConfigPanel.proxy = proxy;
|
||||||
|
Game.InputManager.Activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SwitchCategory(GameObject cat) {
|
||||||
|
foreach (Transform c in m_content) {
|
||||||
|
c.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
cat.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveAndReturnToMenu() {
|
||||||
|
Game.InputManager.Deactivate();
|
||||||
|
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||||
|
m_inputConfigPanel.proxy.Dispose();
|
||||||
|
FileInfo cfgfile = new FileInfo(
|
||||||
|
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||||
|
);
|
||||||
|
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||||
|
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||||
|
}
|
||||||
|
ReturnToMenu();
|
||||||
|
}
|
||||||
public void ReturnToMenu() {
|
public void ReturnToMenu() {
|
||||||
GameObject.Find("Master").GetComponent<Master>().ShowMenu();
|
GameObject.Find("Master").GetComponent<Master>().ShowMenu();
|
||||||
#if UNITY_5_5_OR_NEWER
|
#if UNITY_5_5_OR_NEWER
|
||||||
|
@@ -1,15 +1,14 @@
|
|||||||
using Cryville.Common.Unity;
|
using Cryville.Common.Unity;
|
||||||
using Cryville.Common.Unity.Input;
|
using Cryville.Common.Unity.Input;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class InputConfig : MonoBehaviour {
|
public class InputConfigPanel : MonoBehaviour {
|
||||||
|
[SerializeField]
|
||||||
|
ConfigScene m_configScene;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_inputDialog;
|
GameObject m_inputDialog;
|
||||||
|
|
||||||
@@ -25,14 +24,13 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_prefabInputConfigEntry;
|
GameObject m_prefabInputConfigEntry;
|
||||||
|
|
||||||
InputProxy _proxy;
|
public InputProxy proxy;
|
||||||
Dictionary<string, InputConfigEntry> _entries = new Dictionary<string, InputConfigEntry>();
|
Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||||
|
|
||||||
string _sel;
|
string _sel;
|
||||||
public void OpenDialog(string entry) {
|
public void OpenDialog(string entry) {
|
||||||
_sel = entry;
|
_sel = entry;
|
||||||
m_inputDialog.SetActive(true);
|
m_inputDialog.SetActive(true);
|
||||||
Game.InputManager.Activate();
|
|
||||||
CallHelper.Purge(m_deviceList);
|
CallHelper.Purge(m_deviceList);
|
||||||
_recvsrcs.Clear();
|
_recvsrcs.Clear();
|
||||||
AddSourceItem(null);
|
AddSourceItem(null);
|
||||||
@@ -40,39 +38,24 @@ namespace Cryville.Crtr.Config {
|
|||||||
|
|
||||||
public void CloseDialog() {
|
public void CloseDialog() {
|
||||||
m_inputDialog.SetActive(false);
|
m_inputDialog.SetActive(false);
|
||||||
Game.InputManager.Deactivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseDialog(InputSource? src) {
|
public void CloseDialog(InputSource? src) {
|
||||||
_proxy.Set(new InputProxyEntry {
|
proxy.Set(new InputProxyEntry {
|
||||||
Target = _sel,
|
Target = _sel,
|
||||||
Source = src,
|
Source = src,
|
||||||
});
|
});
|
||||||
m_inputDialog.SetActive(false);
|
m_inputDialog.SetActive(false);
|
||||||
Game.InputManager.Deactivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
ChartPlayer.etor = new PdtEvaluator();
|
foreach (var i in m_configScene.ruleset.Root.inputs) {
|
||||||
FileInfo file = new FileInfo(
|
var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
|
||||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
_entries.Add(i.Key, e);
|
||||||
);
|
e.SetKey(this, i.Key);
|
||||||
DirectoryInfo dir = file.Directory;
|
OnProxyChanged(this, proxy[i.Key]);
|
||||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
|
||||||
var ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
|
||||||
MissingMemberHandling = MissingMemberHandling.Error
|
|
||||||
});
|
|
||||||
if (ruleset.format != 1) throw new FormatException("Invalid ruleset file version");
|
|
||||||
ruleset.LoadPdt(dir);
|
|
||||||
_proxy = new InputProxy(ruleset.Root, null);
|
|
||||||
foreach (var i in ruleset.Root.inputs) {
|
|
||||||
var e = GameObject.Instantiate(m_prefabInputConfigEntry).GetComponent<InputConfigEntry>();
|
|
||||||
e.transform.SetParent(m_entryList.transform);
|
|
||||||
_entries.Add(i.Key, e);
|
|
||||||
e.SetKey(this, i.Key);
|
|
||||||
}
|
|
||||||
_proxy.ProxyChanged += OnProxyChanged;
|
|
||||||
}
|
}
|
||||||
|
proxy.ProxyChanged += OnProxyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
||||||
@@ -92,11 +75,10 @@ namespace Cryville.Crtr.Config {
|
|||||||
void AddSourceItem(InputSource? src) {
|
void AddSourceItem(InputSource? src) {
|
||||||
if (_recvsrcs.Contains(src)) return;
|
if (_recvsrcs.Contains(src)) return;
|
||||||
_recvsrcs.Add(src);
|
_recvsrcs.Add(src);
|
||||||
var obj = Instantiate(m_prefabListItem);
|
var obj = Instantiate(m_prefabListItem, m_deviceList);
|
||||||
obj.transform.SetParent(m_deviceList);
|
|
||||||
obj.transform.Find("Text").GetComponent<Text>().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type);
|
obj.transform.Find("Text").GetComponent<Text>().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||||
var btn = obj.GetComponent<Button>();
|
var btn = obj.GetComponent<Button>();
|
||||||
if (src != null) btn.interactable = !_proxy.IsUsed(src.Value);
|
if (src != null) btn.interactable = !proxy.IsUsed(src.Value);
|
||||||
btn.onClick.AddListener(() => {
|
btn.onClick.AddListener(() => {
|
||||||
CloseDialog(src);
|
CloseDialog(src);
|
||||||
});
|
});
|
@@ -2,7 +2,7 @@
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class InputConfigEntry : MonoBehaviour {
|
public class InputConfigPanelEntry : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Text m_key;
|
Text m_key;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
Button m_button;
|
Button m_button;
|
||||||
|
|
||||||
public void SetKey(InputConfig master, string name) {
|
public void SetKey(InputConfigPanel master, string name) {
|
||||||
m_key.text = name;
|
m_key.text = name;
|
||||||
m_value.text = "None";
|
m_value.text = "None";
|
||||||
m_button.onClick.AddListener(() => {
|
m_button.onClick.AddListener(() => {
|
32
Assets/Cryville/Crtr/Config/RulesetConfig.cs
Normal file
32
Assets/Cryville/Crtr/Config/RulesetConfig.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Cryville.Common.ComponentModel;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Config {
|
||||||
|
public class RulesetConfig {
|
||||||
|
public Generic generic = new Generic();
|
||||||
|
public class Generic {
|
||||||
|
[Category("basic")]
|
||||||
|
[JsonProperty("skin")]
|
||||||
|
public string Skin { get; set; }
|
||||||
|
|
||||||
|
[Category("deprecated")][Obsolete]
|
||||||
|
[JsonProperty("scroll_velocity")][DefaultValue(1)]
|
||||||
|
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
|
||||||
|
public float ScrollVelocity { get; set; }
|
||||||
|
|
||||||
|
public Generic() {
|
||||||
|
Skin = "";
|
||||||
|
ScrollVelocity = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Dictionary<string, InputEntry> inputs
|
||||||
|
= new Dictionary<string, InputEntry>();
|
||||||
|
public class InputEntry {
|
||||||
|
public string handler;
|
||||||
|
public int type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Config/RulesetConfig.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/RulesetConfig.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aa140184f4b7acb4b994a0826e1f107d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -196,7 +196,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
if (Disposed) return;
|
if (Disposed) return;
|
||||||
Disposed = true;
|
Disposed = true;
|
||||||
if (Handler != null) Handler.Dispose();
|
if (CloneType < 16 && Handler != null) Handler.Dispose();
|
||||||
foreach (var s in Children)
|
foreach (var s in Children)
|
||||||
s.Value.Dispose();
|
s.Value.Dispose();
|
||||||
RMVPool.ReturnAll();
|
RMVPool.ReturnAll();
|
||||||
|
@@ -2,6 +2,7 @@ using Cryville.Crtr.Browsing;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -17,23 +18,32 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||||
List<Resource> result = new List<Resource>();
|
List<Resource> result = new List<Resource>();
|
||||||
MalodyChart src;
|
MalodyChart src;
|
||||||
|
if (file.Extension != ".mc") throw new NotImplementedException("mcz file is not supported");
|
||||||
using (var reader = new StreamReader(file.FullName)) {
|
using (var reader = new StreamReader(file.FullName)) {
|
||||||
src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd());
|
src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd());
|
||||||
}
|
}
|
||||||
if (src.meta.mode != 0) throw new NotImplementedException("The chart mode is not supported");
|
if (src.meta.mode != 0) throw new NotImplementedException("The chart mode is not supported");
|
||||||
|
if (src.meta.mode_ext.column != 4) throw new NotImplementedException("The key count is not supported");
|
||||||
|
|
||||||
|
var ruleset = "malody!" + MODES[src.meta.mode];
|
||||||
|
if (src.meta.mode == 0) {
|
||||||
|
ruleset += "." + src.meta.mode_ext.column.ToString(CultureInfo.InvariantCulture) + "k";
|
||||||
|
}
|
||||||
|
|
||||||
ChartMeta meta = new ChartMeta() {
|
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,
|
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,
|
author = src.meta.song.artistorg != null ? src.meta.song.artistorg : src.meta.song.artist,
|
||||||
},
|
},
|
||||||
ruleset = "malody!" + MODES[src.meta.mode],
|
ruleset = ruleset,
|
||||||
};
|
};
|
||||||
|
|
||||||
Chart chart = new Chart {
|
Chart chart = new Chart {
|
||||||
format = 2,
|
format = 2,
|
||||||
time = new BeatTime(-4, 0, 1),
|
time = new BeatTime(-4, 0, 1),
|
||||||
ruleset = "malody!" + MODES[src.meta.mode],
|
ruleset = ruleset,
|
||||||
sigs = new List<Chart.Signature>(),
|
sigs = new List<Chart.Signature>(),
|
||||||
sounds = new List<Chart.Sound>(),
|
sounds = new List<Chart.Sound>(),
|
||||||
motions = new List<Chart.Motion>(),
|
motions = new List<Chart.Motion>(),
|
||||||
@@ -68,7 +78,7 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
float pbeat = 0f, ctime = 0f;
|
float pbeat = 0f, ctime = 0f;
|
||||||
int[] endbeat = new int[] { 0, 0, 1 };
|
int[] endbeat = new int[] { 0, 0, 1 };
|
||||||
foreach (var ev in events) {
|
foreach (var ev in events) {
|
||||||
float cbeat = bp(ev.beat);
|
float cbeat = ConvertBeat(ev.beat);
|
||||||
ctime += baseBpm == null ? 0 : (cbeat - pbeat) / baseBpm.Value * 60f;
|
ctime += baseBpm == null ? 0 : (cbeat - pbeat) / baseBpm.Value * 60f;
|
||||||
pbeat = cbeat;
|
pbeat = cbeat;
|
||||||
if (ev is MalodyChart.Time) {
|
if (ev is MalodyChart.Time) {
|
||||||
@@ -105,7 +115,7 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
else throw new NotImplementedException();
|
else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (bp(tev.beat) > bp(endbeat)) endbeat = tev.beat;
|
if (ConvertBeat(tev.beat) > ConvertBeat(endbeat)) endbeat = tev.beat;
|
||||||
var rn = new Chart.Note() {
|
var rn = new Chart.Note() {
|
||||||
time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]),
|
time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]),
|
||||||
motions = new List<Chart.Motion> {
|
motions = new List<Chart.Motion> {
|
||||||
@@ -113,7 +123,7 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (tev.endbeat != null) {
|
if (tev.endbeat != null) {
|
||||||
if (bp(tev.endbeat) > bp(endbeat)) endbeat = tev.endbeat;
|
if (ConvertBeat(tev.endbeat) > ConvertBeat(endbeat)) endbeat = tev.endbeat;
|
||||||
rn.endtime = new BeatTime(tev.endbeat[0], tev.endbeat[1], tev.endbeat[2]);
|
rn.endtime = new BeatTime(tev.endbeat[0], tev.endbeat[1], tev.endbeat[2]);
|
||||||
longEvents.Add(ev, new StartEventState {
|
longEvents.Add(ev, new StartEventState {
|
||||||
Destination = rn,
|
Destination = rn,
|
||||||
@@ -134,16 +144,13 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
else throw new NotSupportedException();
|
else throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
chart.endtime = new BeatTime(endbeat[0] + 4, endbeat[1], endbeat[2]);
|
chart.endtime = new BeatTime(endbeat[0] + 4, endbeat[1], endbeat[2]);
|
||||||
meta.chart = new ChartMeta.MetaInfo() {
|
meta.length = ctime;
|
||||||
name = src.meta.version,
|
|
||||||
author = src.meta.creator,
|
|
||||||
length = ctime,
|
|
||||||
};
|
|
||||||
meta.note_count = group.notes.Count;
|
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);
|
||||||
result.Add(new ChartResource(chartName, chart, meta));
|
if (src.meta.background != null) {
|
||||||
if (src.meta.background != null)
|
meta.cover = src.meta.background;
|
||||||
result.Add(new CoverResource(chartName, new FileInfo(file.DirectoryName + "/" + src.meta.background)));
|
}
|
||||||
|
result.Add(new RawChartResource(chartName, chart, meta));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +159,7 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
public ChartEvent Destination { get; set; }
|
public ChartEvent Destination { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
float bp(int[] beat) {
|
float ConvertBeat(int[] beat) {
|
||||||
return beat[0] + (float)beat[1] / beat[2];
|
return beat[0] + (float)beat[1] / beat[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Common.Unity.Input;
|
using Cryville.Common.Unity.Input;
|
||||||
|
using Cryville.Crtr.Config;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = Cryville.Common.Logger;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class InputProxy {
|
public class InputProxy : IDisposable {
|
||||||
readonly PdtEvaluator _etor;
|
readonly PdtEvaluator _etor;
|
||||||
readonly PdtRuleset _ruleset;
|
readonly PdtRuleset _ruleset;
|
||||||
readonly Judge _judge;
|
readonly Judge _judge;
|
||||||
@@ -37,31 +37,61 @@ namespace Cryville.Crtr {
|
|||||||
readonly Dictionary<string, int> _use = new Dictionary<string, int>();
|
readonly Dictionary<string, int> _use = new Dictionary<string, int>();
|
||||||
readonly Dictionary<string, List<string>> _rev = new Dictionary<string, List<string>>();
|
readonly Dictionary<string, List<string>> _rev = new Dictionary<string, List<string>>();
|
||||||
public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
|
public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
|
||||||
|
public void LoadFrom(Dictionary<string, RulesetConfig.InputEntry> config) {
|
||||||
|
foreach (var cfg in config) {
|
||||||
|
Set(new InputProxyEntry {
|
||||||
|
Target = cfg.Key,
|
||||||
|
Source = new InputSource {
|
||||||
|
Handler = Game.InputManager.GetHandler(cfg.Value.handler),
|
||||||
|
Type = cfg.Value.type
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SaveTo(Dictionary<string, RulesetConfig.InputEntry> config) {
|
||||||
|
config.Clear();
|
||||||
|
foreach (var p in _tproxies) {
|
||||||
|
config.Add(p.Key, new RulesetConfig.InputEntry {
|
||||||
|
handler = ReflectionHelper.GetNamespaceQualifiedName(p.Value.Source.Value.Handler.GetType()),
|
||||||
|
type = p.Value.Source.Value.Type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
public void Set(InputProxyEntry proxy) {
|
public void Set(InputProxyEntry proxy) {
|
||||||
var name = proxy.Target;
|
var target = proxy.Target;
|
||||||
if (_tproxies.ContainsKey(name)) Remove(proxy);
|
if (!_ruleset.inputs.ContainsKey(target)) throw new ArgumentException("Invalid input name");
|
||||||
if (_use[proxy.Target] > 0)
|
if (_tproxies.ContainsKey(target)) Remove(proxy);
|
||||||
|
if (_use[target] > 0)
|
||||||
throw new InvalidOperationException("Input already assigned");
|
throw new InvalidOperationException("Input already assigned");
|
||||||
if (proxy.Source != null) {
|
if (proxy.Source != null) {
|
||||||
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
if (_judge != null) {
|
||||||
proxy.Source.Value.Handler.OnInput += OnInput;
|
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
||||||
_tproxies.Add(proxy.Target, proxy);
|
proxy.Source.Value.Handler.OnInput += OnInput;
|
||||||
|
}
|
||||||
|
_tproxies.Add(target, proxy);
|
||||||
_sproxies.Add(proxy.Source.Value, proxy);
|
_sproxies.Add(proxy.Source.Value, proxy);
|
||||||
IncrementUseRecursive(name);
|
IncrementUseRecursive(target);
|
||||||
IncrementReversedUseRecursive(name);
|
IncrementReversedUseRecursive(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Remove(InputProxyEntry proxy) {
|
void Remove(InputProxyEntry proxy) {
|
||||||
var name = proxy.Target;
|
var target = proxy.Target;
|
||||||
proxy.Source.Value.Handler.OnInput -= OnInput;
|
if (_judge != null) _tproxies[target].Source.Value.Handler.OnInput -= OnInput;
|
||||||
_sproxies.Remove(_tproxies[name].Source.Value);
|
_sproxies.Remove(_tproxies[target].Source.Value);
|
||||||
_tproxies.Remove(name);
|
_tproxies.Remove(target);
|
||||||
DecrementUseRecursive(name);
|
DecrementUseRecursive(target);
|
||||||
DecrementReversedUseRecursive(name);
|
DecrementReversedUseRecursive(target);
|
||||||
}
|
}
|
||||||
public bool IsUsed(InputSource src) {
|
public bool IsUsed(InputSource src) {
|
||||||
return _sproxies.ContainsKey(src);
|
return _sproxies.ContainsKey(src);
|
||||||
}
|
}
|
||||||
|
public bool IsCompleted {
|
||||||
|
get {
|
||||||
|
foreach (var i in _use)
|
||||||
|
if (i.Value == 0 && !_tproxies.ContainsKey(i.Key)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
void IncrementUseRecursive(string name) {
|
void IncrementUseRecursive(string name) {
|
||||||
BroadcastProxyChanged(name);
|
BroadcastProxyChanged(name);
|
||||||
var passes = _ruleset.inputs[name].pass;
|
var passes = _ruleset.inputs[name].pass;
|
||||||
@@ -98,7 +128,12 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
void BroadcastProxyChanged(string name) {
|
void BroadcastProxyChanged(string name) {
|
||||||
var del = ProxyChanged;
|
var del = ProxyChanged;
|
||||||
if (del != null) del(this, new ProxyChangedEventArgs(name, _tproxies.ContainsKey(name) ? _tproxies[name].Source : null, _use[name] > 0));
|
if (del != null) del(this, this[name]);
|
||||||
|
}
|
||||||
|
public ProxyChangedEventArgs this[string name] {
|
||||||
|
get {
|
||||||
|
return new ProxyChangedEventArgs(name, _tproxies.ContainsKey(name) ? _tproxies[name].Source : null, _use[name] > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -113,6 +148,22 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
||||||
|
|
||||||
|
~InputProxy() {
|
||||||
|
Dispose(false);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
}
|
||||||
|
protected void Dispose(bool disposing) {
|
||||||
|
if (disposing) {
|
||||||
|
Deactivate();
|
||||||
|
foreach (var proxy in _tproxies.Values) {
|
||||||
|
proxy.Source.Value.Handler.OnInput -= OnInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readonly object _lock = new object();
|
readonly object _lock = new object();
|
||||||
static readonly int _var_value = IdentifierManager.SharedInstance.Request("value");
|
static readonly int _var_value = IdentifierManager.SharedInstance.Request("value");
|
||||||
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
|
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
|
||||||
@@ -131,14 +182,15 @@ namespace Cryville.Crtr {
|
|||||||
if (!_vect.TryGetValue(id, out ft)) ft = tt;
|
if (!_vect.TryGetValue(id, out ft)) ft = tt;
|
||||||
if (vec.IsNull) {
|
if (vec.IsNull) {
|
||||||
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, _nullvalue));
|
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, _nullvalue));
|
||||||
|
OnInput(id, proxy.Target, ft, tt, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fixed (byte* ptr = _vecbuf) {
|
fixed (byte* ptr = _vecbuf) {
|
||||||
*(Vector3*)ptr = vec.Vector;
|
*(Vector3*)ptr = vec.Vector;
|
||||||
}
|
}
|
||||||
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Vector, _vecbuf));
|
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Vector, _vecbuf));
|
||||||
|
OnInput(id, proxy.Target, ft, tt, false);
|
||||||
}
|
}
|
||||||
OnInput(id, proxy.Target, ft, tt);
|
|
||||||
_vect[id] = tt;
|
_vect[id] = tt;
|
||||||
_etor.ContextCascadeDiscard();
|
_etor.ContextCascadeDiscard();
|
||||||
}
|
}
|
||||||
@@ -146,14 +198,14 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
static readonly int _var_fv = IdentifierManager.SharedInstance.Request("fv");
|
static readonly int _var_fv = IdentifierManager.SharedInstance.Request("fv");
|
||||||
static readonly int _var_tv = IdentifierManager.SharedInstance.Request("tv");
|
static readonly int _var_tv = IdentifierManager.SharedInstance.Request("tv");
|
||||||
unsafe void OnInput(InputIdentifier id, Identifier target, float ft, float tt) {
|
unsafe void OnInput(InputIdentifier id, Identifier target, float ft, float tt, bool nullflag) {
|
||||||
var def = _ruleset.inputs[target];
|
var def = _ruleset.inputs[target];
|
||||||
if (def.pass != null) {
|
if (def.pass != null) {
|
||||||
foreach (var p in def.pass) {
|
foreach (var p in def.pass) {
|
||||||
_etor.ContextCascadeInsert();
|
_etor.ContextCascadeInsert();
|
||||||
_arbop.Name = _var_value;
|
_arbop.Name = _var_value;
|
||||||
_etor.Evaluate(_arbop, p.Value);
|
if (!nullflag) _etor.Evaluate(_arbop, p.Value);
|
||||||
OnInput(id, p.Key, ft, tt);
|
OnInput(id, p.Key, ft, tt, nullflag);
|
||||||
_etor.ContextCascadeDiscard();
|
_etor.ContextCascadeDiscard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -85,6 +85,19 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
return ~num;
|
return ~num;
|
||||||
}
|
}
|
||||||
|
int BinarySearchFirst(List<JudgeEvent> list, float time, int stack) {
|
||||||
|
if (list[0].Definition.stack == stack && list[0].StartClip == time) return 0;
|
||||||
|
int num = 0;
|
||||||
|
int num2 = list.Count - 1;
|
||||||
|
while (num <= num2) {
|
||||||
|
int num3 = num + (num2 - num >> 1);
|
||||||
|
int num4 = -list[num3].Definition.stack.CompareTo(stack);
|
||||||
|
if (num4 == 0) num4 = list[num3].StartClip.CompareTo(time);
|
||||||
|
if (num4 >= 0) num2 = num3 - 1;
|
||||||
|
else num = num3 + 1;
|
||||||
|
}
|
||||||
|
return num + 1;
|
||||||
|
}
|
||||||
public void Feed(Identifier target, float ft, float tt) {
|
public void Feed(Identifier target, float ft, float tt) {
|
||||||
Forward(target, tt);
|
Forward(target, tt);
|
||||||
var actlist = activeEvs[target];
|
var actlist = activeEvs[target];
|
||||||
@@ -103,8 +116,11 @@ namespace Cryville.Crtr {
|
|||||||
if (def.scores != null) UpdateScore(def.scores);
|
if (def.scores != null) UpdateScore(def.scores);
|
||||||
if (def.pass != null) Pass(def.pass);
|
if (def.pass != null) Pass(def.pass);
|
||||||
actlist.RemoveAt(index);
|
actlist.RemoveAt(index);
|
||||||
index = BinarySearch(actlist, ev.StartClip, def.prop);
|
if (def.prop != 0 && actlist.Count > 0) {
|
||||||
if (index < 0) index = ~index;
|
index = BinarySearchFirst(actlist, ev.StartClip, def.stack - def.prop);
|
||||||
|
if (index < 0) index = ~index;
|
||||||
|
}
|
||||||
|
else index++;
|
||||||
}
|
}
|
||||||
else index++;
|
else index++;
|
||||||
}
|
}
|
||||||
@@ -150,10 +166,12 @@ namespace Cryville.Crtr {
|
|||||||
var key = scoreop.Key;
|
var key = scoreop.Key;
|
||||||
_etor.ContextSelfValue = scoreSrcs[key.name.Key];
|
_etor.ContextSelfValue = scoreSrcs[key.name.Key];
|
||||||
_etor.Evaluate(scoreOps[key.name.Key], scoreop.Value);
|
_etor.Evaluate(scoreOps[key.name.Key], scoreop.Value);
|
||||||
|
scoreSrcs[key.name.Key].Invalidate();
|
||||||
foreach (var s in _rs.scores) {
|
foreach (var s in _rs.scores) {
|
||||||
if (s.Value.value != null) {
|
if (s.Value.value != null) {
|
||||||
_etor.ContextSelfValue = scoreSrcs[s.Key.Key];
|
_etor.ContextSelfValue = scoreSrcs[s.Key.Key];
|
||||||
_etor.Evaluate(scoreOps[s.Key.Key], s.Value.value);
|
_etor.Evaluate(scoreOps[s.Key.Key], s.Value.value);
|
||||||
|
scoreSrcs[s.Key.Key].Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,7 +216,7 @@ namespace Cryville.Crtr {
|
|||||||
public Identifier[] miss;
|
public Identifier[] miss;
|
||||||
public Dictionary<ScoreOperation, PdtExpression> scores;
|
public Dictionary<ScoreOperation, PdtExpression> scores;
|
||||||
public int stack;
|
public int stack;
|
||||||
public int prop = -1;
|
public int prop = 1;
|
||||||
}
|
}
|
||||||
public class ScoreOperation {
|
public class ScoreOperation {
|
||||||
public Identifier name;
|
public Identifier name;
|
||||||
|
@@ -6,11 +6,13 @@ namespace Cryville.Crtr {
|
|||||||
public class Menu : MonoBehaviour {
|
public class Menu : MonoBehaviour {
|
||||||
#pragma warning disable IDE0044
|
#pragma warning disable IDE0044
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private ResourceBrowserMaster m_browserMaster;
|
ResourceBrowserMaster m_browserMaster;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Animator m_targetAnimator;
|
Animator m_targetAnimator;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private ProgressBar m_progressBar;
|
ProgressBar m_progressBar;
|
||||||
|
[SerializeField]
|
||||||
|
SettingsPanel m_settingsPanel;
|
||||||
#pragma warning restore IDE0044
|
#pragma warning restore IDE0044
|
||||||
|
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
@@ -19,6 +21,7 @@ namespace Cryville.Crtr {
|
|||||||
void Awake() {
|
void Awake() {
|
||||||
Game.Init();
|
Game.Init();
|
||||||
transform.parent.Find("Canvas/Contents").gameObject.SetActive(true);
|
transform.parent.Find("Canvas/Contents").gameObject.SetActive(true);
|
||||||
|
m_settingsPanel.Target = Settings.Default;
|
||||||
}
|
}
|
||||||
void Update() {
|
void Update() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
@@ -146,6 +146,8 @@ namespace Cryville.Crtr {
|
|||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("attack_timing"), new func_attack_timing(cccb));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("attack_timing"), new func_attack_timing(cccb));
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("enter_timing"), new func_enter_timing(cccb));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("enter_timing"), new func_enter_timing(cccb));
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("release_timing"), new func_release_timing(cccb));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("release_timing"), new func_release_timing(cccb));
|
||||||
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("leave_timing"), new func_leave_timing(cccb));
|
||||||
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("contact_timing"), new func_contact_timing(cccb));
|
||||||
}
|
}
|
||||||
static PdtEvaluator() {
|
static PdtEvaluator() {
|
||||||
_shortops.Add(new PdtOperatorSignature("@", 2), new op_at_2());
|
_shortops.Add(new PdtOperatorSignature("@", 2), new op_at_2());
|
||||||
@@ -507,6 +509,22 @@ namespace Cryville.Crtr {
|
|||||||
return ft > t0 && ft <= t1;
|
return ft > t0 && ft <= t1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class func_leave_timing : JudgeFunction {
|
||||||
|
public func_leave_timing(Func<int, PropSrc> ctxcb) : base(1, ctxcb) { }
|
||||||
|
protected override bool ExecuteImpl(float fn, float tn, float ft, float tt, Vector3? fv, Vector3? tv) {
|
||||||
|
if (fv == null || tv == null) return false;
|
||||||
|
var t1 = GetOperand(0).AsNumber() + tn;
|
||||||
|
return ft < t1 && tt >= t1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class func_contact_timing : JudgeFunction {
|
||||||
|
public func_contact_timing(Func<int, PropSrc> ctxcb) : base(2, ctxcb) { }
|
||||||
|
protected override bool ExecuteImpl(float fn, float tn, float ft, float tt, Vector3? fv, Vector3? tv) {
|
||||||
|
var t0 = GetOperand(0).AsNumber() + fn;
|
||||||
|
var t1 = GetOperand(1).AsNumber() + tn;
|
||||||
|
return (fv == null || ft < t1) && (tv == null || tt >= t0);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
unsafe static class oputil {
|
unsafe static class oputil {
|
||||||
public static float AsNumber(PropSrc src) {
|
public static float AsNumber(PropSrc src) {
|
||||||
|
37
Assets/Cryville/Crtr/Popup.cs
Normal file
37
Assets/Cryville/Crtr/Popup.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr {
|
||||||
|
public class Popup : MonoBehaviour {
|
||||||
|
public string Message = "";
|
||||||
|
CanvasGroup group;
|
||||||
|
float timer = 0;
|
||||||
|
|
||||||
|
const float DURATION = 5.0f;
|
||||||
|
const float DURIN = 0.4f;
|
||||||
|
const float DUROUT = 0.4f;
|
||||||
|
|
||||||
|
void Start() {
|
||||||
|
group = GetComponent<CanvasGroup>();
|
||||||
|
group.alpha = 0;
|
||||||
|
GetComponentInChildren<Text>().text = Message;
|
||||||
|
transform.SetParent(GameObject.Find("PopupList").transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
if (timer <= DURIN) group.alpha = timer / DURIN;
|
||||||
|
else if (timer >= DURATION) GameObject.Destroy(gameObject);
|
||||||
|
else if (timer >= DURATION - DUROUT) group.alpha = (DURATION - timer) / DUROUT;
|
||||||
|
timer += Time.deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateException(Exception ex) {
|
||||||
|
Create(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Create(string msg) {
|
||||||
|
Instantiate(Resources.Load<GameObject>("Common/Popup")).GetComponent<Popup>().Message = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -6,6 +6,7 @@ namespace Cryville.Crtr {
|
|||||||
public abstract class PropSrc {
|
public abstract class PropSrc {
|
||||||
int _type;
|
int _type;
|
||||||
byte[] _buf = null;
|
byte[] _buf = null;
|
||||||
|
public void Invalidate() { _buf = null; }
|
||||||
public void Get(out int type, out byte[] value) {
|
public void Get(out int type, out byte[] value) {
|
||||||
if (_buf == null) InternalGet(out _type, out _buf);
|
if (_buf == null) InternalGet(out _type, out _buf);
|
||||||
type = _type;
|
type = _type;
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
|
using Cryville.Crtr.Browsing;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -10,21 +11,17 @@ using System.Text.RegularExpressions;
|
|||||||
using SIdentifier = Cryville.Common.Identifier;
|
using SIdentifier = Cryville.Common.Identifier;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Ruleset {
|
public class Ruleset : MetaInfo {
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public long format;
|
public long format;
|
||||||
|
|
||||||
[JsonRequired]
|
|
||||||
public string @base;
|
public string @base;
|
||||||
|
|
||||||
[JsonRequired]
|
|
||||||
public string pdt;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public PdtRuleset Root { get; private set; }
|
public PdtRuleset Root { get; private set; }
|
||||||
|
|
||||||
public void LoadPdt(DirectoryInfo dir) {
|
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();
|
var src = pdtreader.ReadToEnd();
|
||||||
Root = new RulesetInterpreter(src, null).Interpret();
|
Root = new RulesetInterpreter(src, null).Interpret();
|
||||||
}
|
}
|
||||||
|
@@ -84,6 +84,18 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
[Category("data")]
|
||||||
|
[Description("The ruleset config file to load.")]
|
||||||
|
public string LoadRulesetConfig {
|
||||||
|
get {
|
||||||
|
return PlayerPrefs.GetString("LoadRulesetConfig", "");
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
PlayerPrefs.SetString("LoadRulesetConfig", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
[Category("data")]
|
[Category("data")]
|
||||||
[Description("The skin file to load.")]
|
[Description("The skin file to load.")]
|
||||||
@@ -100,7 +112,7 @@ namespace Cryville.Crtr {
|
|||||||
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
|
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
|
||||||
public float RenderDistance {
|
public float RenderDistance {
|
||||||
get {
|
get {
|
||||||
return PlayerPrefs.GetFloat("RenderDistance", 6);
|
return PlayerPrefs.GetFloat("RenderDistance", 4);
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
PlayerPrefs.SetFloat("RenderDistance", value);
|
PlayerPrefs.SetFloat("RenderDistance", value);
|
||||||
@@ -119,17 +131,6 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Category("gameplay")]
|
|
||||||
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
|
|
||||||
public float ScrollVelocity {
|
|
||||||
get {
|
|
||||||
return PlayerPrefs.GetFloat("ScrollVelocity", 1);
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
PlayerPrefs.SetFloat("ScrollVelocity", value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Category("gameplay")]
|
[Category("gameplay")]
|
||||||
[Step(0.04f)][Precision(1e-3)]
|
[Step(0.04f)][Precision(1e-3)]
|
||||||
public float SoundOffset {
|
public float SoundOffset {
|
||||||
|
@@ -7,30 +7,41 @@ using UnityEngine;
|
|||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class SettingsPanel : MonoBehaviour {
|
public class SettingsPanel : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject m_categoryPrefab;
|
GameObject m_categoryPrefab;
|
||||||
|
|
||||||
private Transform _container;
|
[SerializeField]
|
||||||
|
Transform m_container;
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
bool _invalidated = true;
|
||||||
void Awake() {
|
object m_target;
|
||||||
_container = transform.Find("Content/__content__");
|
public object Target {
|
||||||
}
|
get {
|
||||||
public void Start() {
|
return m_target;
|
||||||
LoadProperties();
|
}
|
||||||
foreach (Transform c in _container) GameObject.Destroy(c.gameObject);
|
set {
|
||||||
foreach (var c in _categories) {
|
if (m_target != value) {
|
||||||
var obj = GameObject.Instantiate<GameObject>(m_categoryPrefab);
|
m_target = value;
|
||||||
obj.transform.SetParent(_container, false);
|
_invalidated = true;
|
||||||
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value, Settings.Default);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE0051
|
|
||||||
|
|
||||||
Dictionary<string, List<PropertyInfo>> _categories = null;
|
public void Update() {
|
||||||
|
if (!_invalidated) return;
|
||||||
|
LoadProperties();
|
||||||
|
foreach (Transform c in m_container) GameObject.Destroy(c.gameObject);
|
||||||
|
foreach (var c in _categories) {
|
||||||
|
var obj = GameObject.Instantiate<GameObject>(m_categoryPrefab, m_container, false);
|
||||||
|
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value, Target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, List<PropertyInfo>> _categories = new Dictionary<string, List<PropertyInfo>>();
|
||||||
public void LoadProperties() {
|
public void LoadProperties() {
|
||||||
if (_categories != null) return;
|
_categories.Clear();
|
||||||
_categories = new Dictionary<string, List<PropertyInfo>>();
|
_invalidated = false;
|
||||||
foreach (var p in typeof(Settings).GetProperties()) {
|
if (Target == null) return;
|
||||||
|
foreach (var p in Target.GetType().GetProperties()) {
|
||||||
bool browsable = true;
|
bool browsable = true;
|
||||||
string category = "miscellaneous";
|
string category = "miscellaneous";
|
||||||
foreach (var attr in p.GetCustomAttributes(true)) {
|
foreach (var attr in p.GetCustomAttributes(true)) {
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
|
using Cryville.Crtr.Browsing;
|
||||||
using Cryville.Crtr.Components;
|
using Cryville.Crtr.Components;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
@@ -10,7 +11,7 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Skin {
|
public class Skin : MetaInfo {
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public long format;
|
public long format;
|
||||||
|
|
||||||
@@ -18,15 +19,14 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public string ruleset;
|
public string ruleset;
|
||||||
|
|
||||||
[JsonRequired]
|
public List<string> frames = new List<string>();
|
||||||
public string pdt;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public PdtSkin Root { get; private set; }
|
public PdtSkin Root { get; private set; }
|
||||||
|
|
||||||
public void LoadPdt(DirectoryInfo dir) {
|
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();
|
var src = pdtreader.ReadToEnd();
|
||||||
Root = new SkinInterpreter(src, null).Interpret();
|
Root = new SkinInterpreter(src, null).Interpret();
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
24
Assets/MsvcStdextWorkaround.cs
Normal file
24
Assets/MsvcStdextWorkaround.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
|
using System;
|
||||||
|
using UnityEditor.Build;
|
||||||
|
using UnityEditor.Build.Reporting;
|
||||||
|
|
||||||
|
public class MsvcStdextWorkaround : IPreprocessBuildWithReport {
|
||||||
|
const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS";
|
||||||
|
|
||||||
|
public int callbackOrder => 0;
|
||||||
|
|
||||||
|
public void OnPreprocessBuild(BuildReport report) {
|
||||||
|
var clEnv = Environment.GetEnvironmentVariable("_CL_");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(clEnv)) {
|
||||||
|
Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag);
|
||||||
|
}
|
||||||
|
else if (!clEnv.Contains(kWorkaroundFlag)) {
|
||||||
|
clEnv += " " + kWorkaroundFlag;
|
||||||
|
Environment.SetEnvironmentVariable("_CL_", clEnv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // UNITY_EDITOR
|
11
Assets/MsvcStdextWorkaround.cs.meta
Normal file
11
Assets/MsvcStdextWorkaround.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9ed0687e714ce1042921c0057f42039f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -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.
BIN
Assets/Prefabs/PVString.prefab
Normal file
BIN
Assets/Prefabs/PVString.prefab
Normal file
Binary file not shown.
7
Assets/Prefabs/PVString.prefab.meta
Normal file
7
Assets/Prefabs/PVString.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d3142009b74dda042a75e9b808dde66d
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
Assets/Resources/default.txt
Symbolic link
1
Assets/Resources/default.txt
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../Local/default_resources.zip
|
Reference in New Issue
Block a user