Merge 'dev-extension' into 'master'.
This commit is contained in:
@@ -28,8 +28,8 @@ namespace Cryville.Common.Unity {
|
||||
set { m_filter = value; }
|
||||
}
|
||||
|
||||
public Dictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> PresetPaths {
|
||||
public IReadOnlyDictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||
public IReadOnlyDictionary<string, string> PresetPaths {
|
||||
get { return m_presetPaths; }
|
||||
set { m_presetPaths = value; }
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class ExtensionInterface {
|
||||
public abstract IEnumerable<ResourceConverter> GetResourceConverters();
|
||||
public abstract IEnumerable<LocalResourceFinder> GetResourceFinders();
|
||||
}
|
||||
}
|
||||
138
Assets/Cryville/Crtr/Browsing/ExtensionManager.cs
Normal file
138
Assets/Cryville/Crtr/Browsing/ExtensionManager.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Crtr.Extension;
|
||||
using Mono.Cecil;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
internal static class ExtensionManager {
|
||||
static readonly Dictionary<string, List<ResourceConverter>> _converters
|
||||
= new Dictionary<string, List<ResourceConverter>>();
|
||||
public static IEnumerable<string> GetSupportedFormats() {
|
||||
return _converters.Keys;
|
||||
}
|
||||
public static bool TryGetConverters(string extension, out IEnumerable<ResourceConverter> converters) {
|
||||
List<ResourceConverter> outResult;
|
||||
bool result = _converters.TryGetValue(extension, out outResult);
|
||||
converters = outResult;
|
||||
return result;
|
||||
}
|
||||
static readonly Dictionary<string, string> _localRes
|
||||
= new Dictionary<string, string>();
|
||||
public static IReadOnlyDictionary<string, string> GetLocalResourcePaths() {
|
||||
return _localRes;
|
||||
}
|
||||
public static void Init(string rootPath) {
|
||||
LoadExtension(typeof(Extensions.Umg.Extension));
|
||||
var asms = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToHashSet();
|
||||
var modules = new Queue<ModuleItem>();
|
||||
var extensionDir = new DirectoryInfo(Path.Combine(rootPath, "extensions"));
|
||||
if (extensionDir.Exists) {
|
||||
foreach (var extension in extensionDir.EnumerateFiles("*.dll")) {
|
||||
try {
|
||||
modules.Enqueue(new ModuleItem(extension.OpenRead()));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Extension", "Failed to load DLL {0}: {1}", extension, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
int refCounter = 0;
|
||||
while (modules.Count > 0 && refCounter < modules.Count) {
|
||||
var module = modules.Dequeue();
|
||||
bool flag = false;
|
||||
foreach (var reference in module.Definition.AssemblyReferences) {
|
||||
if (!asms.Contains(reference.Name)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
modules.Enqueue(module);
|
||||
refCounter++;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var stream = module.Stream;
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var buf = new byte[stream.Length];
|
||||
stream.Read(buf, 0, buf.Length);
|
||||
var asm = Assembly.Load(buf);
|
||||
if (asm == null) throw new TypeLoadException("Failed to load the module");
|
||||
asms.Add(asm.GetName().Name);
|
||||
foreach (var type in asm.GetTypes()) {
|
||||
if (typeof(ExtensionInterface).IsAssignableFrom(type)) {
|
||||
LoadExtension(type);
|
||||
}
|
||||
}
|
||||
Logger.Log("main", 1, "Extension", "Loaded module {0}", module.Definition.Name);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Extension", "An error occured while trying to load module {0}: {1}", module.Definition.Name, ex);
|
||||
}
|
||||
finally {
|
||||
module.Definition.Dispose();
|
||||
module.Stream.Dispose();
|
||||
refCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
var missingList = new List<string>();
|
||||
while (modules.Count > 0) {
|
||||
missingList.Clear();
|
||||
var module = modules.Dequeue();
|
||||
foreach (var reference in module.Definition.AssemblyReferences) {
|
||||
if (!asms.Contains(reference.Name)) {
|
||||
missingList.Add(reference.Name);
|
||||
}
|
||||
}
|
||||
Logger.Log("main", 4, "Extension", "Could not load the module {0} because the following dependencies were missing: {1}", module.Definition.Name, missingList.Aggregate((current, next) => current + ", " + next));
|
||||
module.Definition.Dispose();
|
||||
module.Stream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
struct ModuleItem {
|
||||
public ModuleDefinition Definition { get; set; }
|
||||
public FileStream Stream { get; set; }
|
||||
public ModuleItem(FileStream stream) {
|
||||
Stream = stream;
|
||||
Definition = ModuleDefinition.ReadModule(stream);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadExtension(Type type) {
|
||||
try {
|
||||
var extension = (ExtensionInterface)Activator.CreateInstance(type);
|
||||
var l1 = extension.GetResourceConverters();
|
||||
if (l1 != null) {
|
||||
foreach (var c in l1) {
|
||||
var fs = c.GetSupportedFormats();
|
||||
if (fs == null) continue;
|
||||
foreach (var f in fs) {
|
||||
if (f == null) continue;
|
||||
if (!_converters.ContainsKey(f))
|
||||
_converters.Add(f, new List<ResourceConverter> { c });
|
||||
else _converters[f].Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
var l2 = extension.GetResourceFinders();
|
||||
if (l2 != null) {
|
||||
foreach (var f in l2) {
|
||||
var name = f.Name;
|
||||
var path = f.GetRootPath();
|
||||
if (name != null && path != null) _localRes.Add(name, path);
|
||||
}
|
||||
}
|
||||
Logger.Log("main", 1, "Extension", "Loaded extension {0}", type);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Extension", "Failed to load extension {0}: {1}", type, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5b3f3294f679f14f8ec1195b0def630
|
||||
guid: a9ea11165e6269b488f916982507a2af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -12,6 +12,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
bool ImportItemFrom(string path);
|
||||
string[] GetSupportedFormats();
|
||||
Dictionary<string, string> GetPresetPaths();
|
||||
IReadOnlyDictionary<string, string> GetPresetPaths();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Crtr.Extension;
|
||||
using Cryville.Crtr.Extensions.Umg;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,49 +17,13 @@ namespace Cryville.Crtr.Browsing {
|
||||
private DirectoryInfo[] items = new DirectoryInfo[0];
|
||||
public string[] CurrentDirectory { get; private set; }
|
||||
|
||||
static readonly Dictionary<string, List<ResourceConverter>> converters
|
||||
= new Dictionary<string, List<ResourceConverter>>();
|
||||
static readonly Dictionary<string, string> localRes
|
||||
= new Dictionary<string, string>();
|
||||
static bool _init;
|
||||
|
||||
public LegacyResourceManager(string rootPath) {
|
||||
_rootPath = rootPath;
|
||||
}
|
||||
|
||||
static LegacyResourceManager() {
|
||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) {
|
||||
foreach (var type in asm.GetTypes()) {
|
||||
if (!type.IsSubclassOf(typeof(ExtensionInterface))) continue;
|
||||
var ext = (ExtensionInterface)Activator.CreateInstance(type);
|
||||
try {
|
||||
var cs = ext.GetResourceConverters();
|
||||
if (cs != null) {
|
||||
foreach (var c in cs) {
|
||||
var fs = c.GetSupportedFormats();
|
||||
if (fs == null) continue;
|
||||
foreach (var f in fs) {
|
||||
if (f == null) continue;
|
||||
if (!converters.ContainsKey(f))
|
||||
converters.Add(f, new List<ResourceConverter> { c });
|
||||
else converters[f].Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
var fs2 = ext.GetResourceFinders();
|
||||
if (fs2 != null) {
|
||||
foreach (var f in fs2) {
|
||||
var name = f.Name;
|
||||
var path = f.GetRootPath();
|
||||
if (name != null && path != null)
|
||||
localRes.Add(name, path);
|
||||
}
|
||||
}
|
||||
Logger.Log("main", 1, "Resource", "Loaded extension {0}", ReflectionHelper.GetNamespaceQualifiedName(type));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Resource", "Failed to initialize extension {0}: {1}", ReflectionHelper.GetNamespaceQualifiedName(type), ex);
|
||||
}
|
||||
}
|
||||
if (!_init) {
|
||||
_init = true;
|
||||
ExtensionManager.Init(rootPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,14 +115,15 @@ namespace Cryville.Crtr.Browsing {
|
||||
|
||||
public bool ImportItemFrom(string path) {
|
||||
var file = new FileInfo(path);
|
||||
if (!converters.ContainsKey(file.Extension)) return false;
|
||||
foreach (var converter in converters[file.Extension]) {
|
||||
IEnumerable<ResourceConverter> converters;
|
||||
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
|
||||
foreach (var converter in converters) {
|
||||
IEnumerable<Resource> resources = null;
|
||||
try {
|
||||
resources = converter.ConvertFrom(file);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogAndPopup(4, ex.Message);
|
||||
LogAndPopupExtra(4, ex, "Failed to import resource: {0}", ex.Message);
|
||||
return false;
|
||||
}
|
||||
foreach (var res in resources) {
|
||||
@@ -168,7 +135,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||
if (!dir.Exists) dir.Create();
|
||||
using (var writer = new StreamWriter(dir.FullName + "/.json")) {
|
||||
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings));
|
||||
writer.Write(JsonConvert.SerializeObject(ConvertChartData(tres.Main), Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
|
||||
tres.Meta.data = "";
|
||||
@@ -219,12 +186,89 @@ namespace Cryville.Crtr.Browsing {
|
||||
Popup.Create(msg);
|
||||
}
|
||||
|
||||
public string[] GetSupportedFormats() {
|
||||
return converters.Keys.ToArray();
|
||||
void LogAndPopupExtra(int level, object extraLog, string format, params object[] args) {
|
||||
var msg = string.Format(format, args);
|
||||
Logger.Log("main", level, "Resource", "{0}\n{1}", msg, extraLog);
|
||||
Popup.Create(msg);
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetPresetPaths() {
|
||||
return localRes;
|
||||
public string[] GetSupportedFormats() {
|
||||
return ExtensionManager.GetSupportedFormats().ToArray();
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, string> GetPresetPaths() {
|
||||
return ExtensionManager.GetLocalResourcePaths();
|
||||
}
|
||||
|
||||
static Chart ConvertChartData(ChartData i) {
|
||||
return new Chart {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
format = i.format,
|
||||
groups = ConvertGroups(i.groups),
|
||||
motions = ConvertMotions(i.motions),
|
||||
ruleset = i.ruleset,
|
||||
sigs = ConvertSignatures(i.sigs),
|
||||
sounds = ConvertSounds(i.sounds),
|
||||
time = ConvertBeatTime(i.time),
|
||||
};
|
||||
}
|
||||
static BeatTime? ConvertBeatTime(Extension.BeatTime? value) {
|
||||
if (value == null) return null;
|
||||
return new BeatTime(value.Value.b, value.Value.n, value.Value.d);
|
||||
}
|
||||
static List<Chart.Group> ConvertGroups(List<ChartData.Group> l) {
|
||||
return l.Select(i => new Chart.Group {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
motions = ConvertMotions(i.motions),
|
||||
notes = ConvertNotes(i.notes),
|
||||
time = ConvertBeatTime(i.time),
|
||||
tracks = ConvertTracks(i.tracks),
|
||||
}).ToList();
|
||||
}
|
||||
static List<Chart.Judge> ConvertJudges(List<ChartData.Judge> l) {
|
||||
return l.Select(i => new Chart.Judge {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
name = i.name,
|
||||
time = ConvertBeatTime(i.time),
|
||||
}).ToList();
|
||||
}
|
||||
static List<Chart.Motion> ConvertMotions(List<ChartData.Motion> l) {
|
||||
return l.Select(i => new Chart.Motion {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
motion = i.motion,
|
||||
sumfix = i.sumfix,
|
||||
time = ConvertBeatTime(i.time),
|
||||
}).ToList();
|
||||
}
|
||||
static List<Chart.Note> ConvertNotes(List<ChartData.Note> l) {
|
||||
return l.Select(i => new Chart.Note {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
judges = ConvertJudges(i.judges),
|
||||
motions = ConvertMotions(i.motions),
|
||||
time = ConvertBeatTime(i.time),
|
||||
}).ToList();
|
||||
}
|
||||
static List<Chart.Signature> ConvertSignatures(List<ChartData.Signature> l) {
|
||||
return l.Select(i => new Chart.Signature {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
tempo = i.tempo,
|
||||
time = ConvertBeatTime(i.time),
|
||||
}).ToList();
|
||||
}
|
||||
static List<Chart.Sound> ConvertSounds(List<ChartData.Sound> l) {
|
||||
return l.Select(i => new Chart.Sound {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
id = i.id,
|
||||
offset = i.offset,
|
||||
time = ConvertBeatTime(i.time),
|
||||
}).ToList();
|
||||
}
|
||||
static List<Chart.Track> ConvertTracks(List<ChartData.Track> l) {
|
||||
return l.Select(i => new Chart.Track {
|
||||
endtime = ConvertBeatTime(i.endtime),
|
||||
motions = ConvertMotions(i.motions),
|
||||
time = ConvertBeatTime(i.time),
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class LocalResourceFinder {
|
||||
public abstract string Name { get; }
|
||||
public abstract string GetRootPath();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using Cryville.Crtr.Config;
|
||||
using Newtonsoft.Json;
|
||||
using Cryville.Crtr.Extension;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -94,24 +94,4 @@ namespace Cryville.Crtr.Browsing {
|
||||
public AsyncDelivery<Texture2D> Cover { get; set; }
|
||||
public ChartMeta Meta { get; set; }
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public class MetaInfo {
|
||||
public string name { get; set; }
|
||||
public string author { get; set; }
|
||||
[JsonRequired]
|
||||
public string data { get; set; }
|
||||
}
|
||||
public class SongMetaInfo {
|
||||
public string name { get; set; }
|
||||
public string author { get; set; }
|
||||
}
|
||||
public class ChartMeta : MetaInfo {
|
||||
public SongMetaInfo song { get; set; }
|
||||
public float length { get; set; }
|
||||
public string ruleset { get; set; }
|
||||
public int note_count { get; set; }
|
||||
public string cover { get; set; }
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class ResourceConverter {
|
||||
public abstract string[] GetSupportedFormats();
|
||||
public abstract IEnumerable<Resource> ConvertFrom(FileInfo file);
|
||||
}
|
||||
public abstract class Resource {
|
||||
protected Resource(string name) {
|
||||
Name = StringUtils.EscapeFileName(name);
|
||||
}
|
||||
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 RawChartResource : Resource {
|
||||
public RawChartResource(string name, Chart main, ChartMeta meta) : base(name) {
|
||||
Main = main; Meta = meta;
|
||||
}
|
||||
public Chart Main { get; private set; }
|
||||
public ChartMeta Meta { get; private set; }
|
||||
public override bool Valid { get { return true; } }
|
||||
}
|
||||
public abstract class FileResource : Resource {
|
||||
public FileResource(string name, FileInfo master) : base(name) {
|
||||
Master = master;
|
||||
Attachments = new List<FileInfo>();
|
||||
}
|
||||
public FileInfo Master { get; private set; }
|
||||
public List<FileInfo> Attachments { get; private set; }
|
||||
public override bool Valid {
|
||||
get {
|
||||
if (!Master.Exists) return false;
|
||||
foreach (var file in Attachments) {
|
||||
if (!file.Exists) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class ChartResource : FileResource {
|
||||
public ChartResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
|
||||
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SongResource : FileResource {
|
||||
public SongResource(string name, FileInfo master) : base(name, master) { }
|
||||
}
|
||||
public class RulesetResource : FileResource {
|
||||
public RulesetResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SkinResource : FileResource {
|
||||
public string RulesetName { get; private set; }
|
||||
public SkinResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
|
||||
RulesetName = meta.ruleset;
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
foreach (var frame in meta.frames) {
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2546fb1d514348842a14a03531be192d
|
||||
timeCreated: 1637982768
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,20 +0,0 @@
|
||||
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) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5335612e48e4c3947808c99fb99411d5
|
||||
guid: b35ffffce02252548a66e18cf98050e2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
107
Assets/Cryville/Crtr/Extension/RefTypes.cs
Normal file
107
Assets/Cryville/Crtr/Extension/RefTypes.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Cryville.Crtr.Extension {
|
||||
[Preserve]
|
||||
public static class RefTypes {
|
||||
[Preserve]
|
||||
public static void PreserveEnumerable() {
|
||||
IEnumerable<object> p = Enumerable.Empty<object>();
|
||||
p.All(i => false);
|
||||
p.Any();
|
||||
p.Any(i => false);
|
||||
p.Cast<object>();
|
||||
p.Concat(Enumerable.Empty<object>());
|
||||
p.Contains(null);
|
||||
p.Count();
|
||||
p.Count(i => false);
|
||||
p.DefaultIfEmpty();
|
||||
p.DefaultIfEmpty(null);
|
||||
p.Distinct();
|
||||
p.ElementAt(0);
|
||||
p.ElementAtOrDefault(0);
|
||||
p.First();
|
||||
p.First(i => false);
|
||||
p.FirstOrDefault();
|
||||
p.FirstOrDefault(i => false);
|
||||
p.GetEnumerator();
|
||||
p.Last();
|
||||
p.Last(i => false);
|
||||
p.LastOrDefault();
|
||||
p.LastOrDefault(i => false);
|
||||
p.LongCount();
|
||||
p.LongCount(i => false);
|
||||
p.OrderBy(i => i).ThenBy(i => i);
|
||||
p.OrderByDescending(i => i).ThenByDescending(i => i);
|
||||
p.Reverse();
|
||||
p.Select(i => i);
|
||||
p.Select((i, j) => false);
|
||||
p.SequenceEqual(p);
|
||||
p.Single();
|
||||
p.Single(i => false);
|
||||
p.SingleOrDefault();
|
||||
p.SingleOrDefault(i => false);
|
||||
p.Skip(0);
|
||||
p.SkipLast(0);
|
||||
p.SkipWhile(i => false);
|
||||
p.SkipWhile((i, j) => false);
|
||||
p.Take(0);
|
||||
p.TakeLast(0);
|
||||
p.TakeWhile(i => false);
|
||||
p.TakeWhile((i, j) => false);
|
||||
p.ToArray();
|
||||
p.ToDictionary(i => new object());
|
||||
p.ToDictionary(i => new object(), i => new object());
|
||||
p.ToHashSet();
|
||||
p.ToList();
|
||||
p.Where(i => false);
|
||||
p.Where((i, j) => false);
|
||||
}
|
||||
[Preserve]
|
||||
public static void PreserveBinaryReader() {
|
||||
BinaryReader p = new BinaryReader(null);
|
||||
p.Close();
|
||||
p.Dispose();
|
||||
p.PeekChar();
|
||||
p.Read();
|
||||
p.ReadBoolean();
|
||||
p.ReadByte();
|
||||
p.ReadBytes(0);
|
||||
p.ReadChar();
|
||||
p.ReadChars(0);
|
||||
p.ReadDouble();
|
||||
p.ReadInt16();
|
||||
p.ReadInt32();
|
||||
p.ReadInt64();
|
||||
p.ReadSByte();
|
||||
p.ReadSingle();
|
||||
p.ReadUInt16();
|
||||
p.ReadUInt32();
|
||||
p.ReadUInt64();
|
||||
}
|
||||
[Preserve]
|
||||
public static void PreserveStreamReader() {
|
||||
object _;
|
||||
StreamReader p = new StreamReader((Stream)null);
|
||||
p.Close();
|
||||
_ = p.CurrentEncoding;
|
||||
p.DiscardBufferedData();
|
||||
p.Dispose();
|
||||
_ = p.EndOfStream;
|
||||
p.Peek();
|
||||
p.Read();
|
||||
p.ReadBlock(null, 0, 0);
|
||||
p.ReadLine();
|
||||
p.ReadToEnd();
|
||||
}
|
||||
[Preserve]
|
||||
public static void PreserveConvert() {
|
||||
Convert.ChangeType(0, typeof(byte));
|
||||
Convert.ChangeType(0, typeof(byte), CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23377bf2926d93a4b8e3f3ab6040c7f2
|
||||
guid: 29a6376ce10b77e4099d2613876f9549
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9bd9e24d7c553341a2a12391843542f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,189 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Math;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Bestdori {
|
||||
public class BestdoriChartConverter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".bestdori" };
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
List<Resource> result = new List<Resource>();
|
||||
List<BestdoriChartEvent> src;
|
||||
using (var reader = new StreamReader(file.FullName)) {
|
||||
src = JsonConvert.DeserializeObject<List<BestdoriChartEvent>>(reader.ReadToEnd());
|
||||
}
|
||||
var group = new Chart.Group() {
|
||||
tracks = new List<Chart.Track>(),
|
||||
notes = new List<Chart.Note>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
};
|
||||
Chart chart = new Chart {
|
||||
format = 2,
|
||||
time = new BeatTime(0, 0, 1),
|
||||
ruleset = "bang_dream_girls_band_party",
|
||||
sigs = new List<Chart.Signature>(),
|
||||
sounds = new List<Chart.Sound>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
groups = new List<Chart.Group> { group },
|
||||
};
|
||||
var tm = new BeatTimeTimingModel();
|
||||
string bgm = null;
|
||||
double endbeat = 0;
|
||||
foreach (var ev in src) {
|
||||
tm.ForwardTo(ev.StartBeat);
|
||||
if (ev.StartBeat > endbeat) endbeat = ev.StartBeat;
|
||||
if (ev is BestdoriChartEvent.System) {
|
||||
if (bgm != null) continue;
|
||||
var tev = (BestdoriChartEvent.System)ev;
|
||||
bgm = StringUtils.TrimExt(tev.data);
|
||||
var name = "bang_dream_girls_band_party__" + bgm;
|
||||
result.Add(new SongResource(name, new FileInfo(Path.Combine(file.Directory.FullName, tev.data))));
|
||||
chart.sounds.Add(new Chart.Sound { time = ToBeatTime(tev.beat), id = name });
|
||||
}
|
||||
else if (ev is BestdoriChartEvent.BPM) {
|
||||
var tev = (BestdoriChartEvent.BPM)ev;
|
||||
tm.BPM = tev.bpm;
|
||||
chart.sigs.Add(new Chart.Signature { time = ToBeatTime(tev.beat), tempo = (float)tev.bpm });
|
||||
}
|
||||
else if (ev is BestdoriChartEvent.Single) {
|
||||
var tev = (BestdoriChartEvent.Single)ev;
|
||||
group.notes.Add(new Chart.Note {
|
||||
time = ToBeatTime(tev.beat),
|
||||
judges = new List<Chart.Judge> { new Chart.Judge { name = tev.flick ? "single_flick" : "single" } },
|
||||
motions = new List<Chart.Motion> { new Chart.Motion { motion = "track:" + tev.lane.ToString(CultureInfo.InvariantCulture) } },
|
||||
});
|
||||
}
|
||||
else if (ev is BestdoriChartEvent.Long) {
|
||||
var tev = (BestdoriChartEvent.Long)ev;
|
||||
var c1 = tev.connections[tev.connections.Count - 1];
|
||||
var note = new Chart.Note {
|
||||
time = ToBeatTime(tev.connections[0].beat),
|
||||
endtime = ToBeatTime(c1.beat),
|
||||
judges = new List<Chart.Judge>(),
|
||||
};
|
||||
for (int i = 0; i < tev.connections.Count; i++) {
|
||||
BestdoriChartEvent.Connection c = tev.connections[i];
|
||||
var motion = new Chart.Motion { motion = "track:" + c.lane.ToString(CultureInfo.InvariantCulture) };
|
||||
if (i == 0) {
|
||||
note.judges.Add(new Chart.Judge { name = "single" });
|
||||
note.motions.Add(motion);
|
||||
}
|
||||
else {
|
||||
var cbeat = motion.endtime = ToBeatTime(c.beat);
|
||||
if (i > 1) motion.time = ToBeatTime(tev.connections[i - 1].beat);
|
||||
note.motions.Add(motion);
|
||||
if (i == tev.connections.Count - 1)
|
||||
note.judges.Add(new Chart.Judge { time = cbeat, name = c.flick ? "longend_flick" : "longend" });
|
||||
else if (!c.hidden)
|
||||
note.judges.Add(new Chart.Judge { time = cbeat, name = "longnode" });
|
||||
}
|
||||
}
|
||||
if (c1.beat > endbeat) endbeat = c1.beat;
|
||||
group.notes.Add(note);
|
||||
}
|
||||
else throw new NotImplementedException("Unsupported event: " + ev.type);
|
||||
}
|
||||
if (bgm == null) throw new FormatException("Chart contains no song");
|
||||
chart.endtime = ToBeatTime(endbeat + 4);
|
||||
if (endbeat > tm.BeatTime) tm.ForwardTo(endbeat);
|
||||
result.Add(new RawChartResource(string.Format("bang_dream_girls_band_party__{0}__{1}", bgm, StringUtils.TrimExt(file.Name)), chart, new ChartMeta {
|
||||
name = string.Format("Bandori {0} {1}", bgm, StringUtils.TrimExt(file.Name)),
|
||||
author = "©BanG Dream! Project ©Craft Egg Inc. ©bushiroad",
|
||||
ruleset = "bang_dream_girls_band_party",
|
||||
note_count = group.notes.Count,
|
||||
length = (float)tm.Time,
|
||||
song = new SongMetaInfo {
|
||||
name = bgm,
|
||||
author = "©BanG Dream! Project ©Craft Egg Inc. ©bushiroad",
|
||||
}
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
BeatTime ToBeatTime(double beat, double error = 1e-4) {
|
||||
int i, n, d;
|
||||
FractionUtils.ToFraction(beat, error, out n, out d);
|
||||
i = n / d; n %= d;
|
||||
return new BeatTime(i, n, d);
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
[JsonConverter(typeof(BestdoriChartEventCreator))]
|
||||
abstract class BestdoriChartEvent {
|
||||
public abstract string type { get; }
|
||||
public abstract double StartBeat { get; }
|
||||
public abstract class InstantEvent : BestdoriChartEvent {
|
||||
public double beat;
|
||||
public override double StartBeat { get { return beat; } }
|
||||
}
|
||||
public class BPM : InstantEvent {
|
||||
public override string type { get { return "BPM"; } }
|
||||
public double bpm;
|
||||
}
|
||||
public class System : InstantEvent {
|
||||
public override string type { get { return "System"; } }
|
||||
public string data;
|
||||
}
|
||||
public abstract class SingleBase : InstantEvent {
|
||||
public double lane;
|
||||
public bool skill;
|
||||
public bool flick;
|
||||
}
|
||||
public class Single : SingleBase {
|
||||
public override string type { get { return "Single"; } }
|
||||
}
|
||||
public class Directional : SingleBase {
|
||||
public override string type { get { return "Directional"; } }
|
||||
public string direction;
|
||||
public int width;
|
||||
}
|
||||
public class Connection : SingleBase {
|
||||
public override string type { get { return null; } }
|
||||
public bool hidden;
|
||||
}
|
||||
public class Long : BestdoriChartEvent {
|
||||
public override string type { get { return "Long"; } }
|
||||
public List<Connection> connections;
|
||||
public override double StartBeat { get { return connections[0].beat; } }
|
||||
}
|
||||
public class Slide : Long {
|
||||
public override string type { get { return "Slide"; } }
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
class BestdoriChartEventCreator : CustomCreationConverter<BestdoriChartEvent> {
|
||||
string _currentType;
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
var obj = JObject.ReadFrom(reader);
|
||||
var type = obj["type"];
|
||||
if (type == null) _currentType = null;
|
||||
else _currentType = obj["type"].ToObject<string>();
|
||||
return base.ReadJson(obj.CreateReader(), objectType, existingValue, serializer);
|
||||
}
|
||||
|
||||
public override BestdoriChartEvent Create(Type objectType) {
|
||||
switch (_currentType) {
|
||||
case "BPM": return new BestdoriChartEvent.BPM();
|
||||
case "System": return new BestdoriChartEvent.System();
|
||||
case "Single": return new BestdoriChartEvent.Single();
|
||||
case "Directional": return new BestdoriChartEvent.Directional();
|
||||
case null: return new BestdoriChartEvent.Connection();
|
||||
case "Long": return new BestdoriChartEvent.Long();
|
||||
case "Slide": return new BestdoriChartEvent.Slide();
|
||||
default: throw new ArgumentException("Unknown event type: " + _currentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3c5a8bf05d5e284ba498e91cb0dd35e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,27 +0,0 @@
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Cryville.Crtr.Extensions.Bestdori;
|
||||
using Cryville.Crtr.Extensions.Malody;
|
||||
using Cryville.Crtr.Extensions.osu;
|
||||
using Cryville.Crtr.Extensions.Quaver;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Extensions {
|
||||
public class Extensions : ExtensionInterface {
|
||||
public override IEnumerable<ResourceConverter> GetResourceConverters() {
|
||||
return new ResourceConverter[] {
|
||||
new BestdoriChartConverter(),
|
||||
new MalodyChartConverter(),
|
||||
new osuChartConverter(),
|
||||
new QuaverChartConverter(),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalResourceFinder> GetResourceFinders() {
|
||||
return new LocalResourceFinder[] {
|
||||
new MalodyChartFinder(),
|
||||
new osuChartFinder(),
|
||||
new QuaverChartFinder(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfd44d1c0681e4842a1f031556519042
|
||||
folderAsset: yes
|
||||
timeCreated: 1637936550
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,225 +0,0 @@
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Malody {
|
||||
public class MalodyChartConverter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".mc", ".mcz" };
|
||||
static readonly string[] MODES = { "key", "step", "dj", "catch", "pad", "taiko", "ring", "slide", "live" };
|
||||
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
List<Resource> result = new List<Resource>();
|
||||
MalodyChart src;
|
||||
if (file.Extension != ".mc") throw new NotImplementedException("mcz file is not supported yet");
|
||||
using (var reader = new StreamReader(file.FullName)) {
|
||||
src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd());
|
||||
}
|
||||
if (src.meta.mode != 0) throw new NotImplementedException(string.Format("{0} mode is not supported yet", MODES[src.meta.mode]));
|
||||
|
||||
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() {
|
||||
name = src.meta.version,
|
||||
author = src.meta.creator,
|
||||
song = new SongMetaInfo() {
|
||||
name = src.meta.song.titleorg != null ? src.meta.song.titleorg : src.meta.song.title,
|
||||
author = src.meta.song.artistorg != null ? src.meta.song.artistorg : src.meta.song.artist,
|
||||
},
|
||||
ruleset = ruleset,
|
||||
};
|
||||
|
||||
Chart chart = new Chart {
|
||||
format = 2,
|
||||
time = new BeatTime(-4, 0, 1),
|
||||
ruleset = ruleset,
|
||||
sigs = new List<Chart.Signature>(),
|
||||
sounds = new List<Chart.Sound>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
groups = new List<Chart.Group>(),
|
||||
};
|
||||
var group = new Chart.Group() {
|
||||
tracks = new List<Chart.Track>(),
|
||||
notes = new List<Chart.Note>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
};
|
||||
chart.groups.Add(group);
|
||||
int col = src.meta.mode_ext.column;
|
||||
|
||||
IEnumerable<MalodyChart.IEvent> events = src.time.Cast<MalodyChart.IEvent>();
|
||||
if (src.effect != null) events = events.Concat(src.effect.Cast<MalodyChart.IEvent>());
|
||||
events = events.Concat(src.note.Cast<MalodyChart.IEvent>());
|
||||
List<MalodyChart.IEvent> endEvents = new List<MalodyChart.IEvent>();
|
||||
foreach (var ev in events)
|
||||
if (ev.endbeat != null)
|
||||
endEvents.Add(new MalodyChart.EndEvent {
|
||||
beat = ev.endbeat,
|
||||
StartEvent = ev,
|
||||
});
|
||||
events = events.Concat(endEvents)
|
||||
.OrderBy(e => e.beat[0] + (float)e.beat[1] / e.beat[2])
|
||||
.ThenBy(e => e.Priority);
|
||||
|
||||
Dictionary<MalodyChart.IEvent, StartEventState> longEvents
|
||||
= new Dictionary<MalodyChart.IEvent, StartEventState>();
|
||||
|
||||
float? baseBpm = null;
|
||||
var tm = new FractionalBeatTimeTimingModel();
|
||||
foreach (var ev in events) {
|
||||
var beat = new BeatTime(ev.beat[0], ev.beat[1], ev.beat[2]);
|
||||
tm.ForwardTo(beat);
|
||||
if (ev is MalodyChart.Time) {
|
||||
var tev = (MalodyChart.Time)ev;
|
||||
if (baseBpm == null) baseBpm = tev.bpm;
|
||||
tm.BPM = tev.bpm;
|
||||
chart.sigs.Add(new Chart.Signature {
|
||||
time = beat,
|
||||
tempo = tev.bpm,
|
||||
});
|
||||
chart.motions.Add(new Chart.Motion {
|
||||
time = beat,
|
||||
motion = "svm:" + (tev.bpm / baseBpm.Value).ToString(CultureInfo.InvariantCulture)
|
||||
});
|
||||
}
|
||||
else if (ev is MalodyChart.Effect) {
|
||||
var tev = (MalodyChart.Effect)ev;
|
||||
if (tev.scroll != null) group.motions.Add(new Chart.Motion {
|
||||
time = beat,
|
||||
motion = "svm:" + tev.scroll.Value.ToString(CultureInfo.InvariantCulture)
|
||||
});
|
||||
}
|
||||
else if (ev is MalodyChart.Note) {
|
||||
var tev = (MalodyChart.Note)ev;
|
||||
if (tev.type == 1) {
|
||||
if (tev.beat[0] == 0 && tev.beat[1] == 0) {
|
||||
var res = new SongResource(meta.song.name, new FileInfo(file.DirectoryName + "/" + tev.sound));
|
||||
result.Add(res);
|
||||
chart.sounds.Add(new Chart.Sound {
|
||||
time = new BeatTime(0, 0, 1),
|
||||
id = res.Name,
|
||||
offset = -tev.offset / 1000f,
|
||||
});
|
||||
}
|
||||
else throw new NotImplementedException("Key sounds are not supported yet");
|
||||
}
|
||||
else {
|
||||
var rn = new Chart.Note() {
|
||||
time = beat,
|
||||
motions = new List<Chart.Motion> {
|
||||
new Chart.Motion() { motion = "track:" + tev.column.ToString(CultureInfo.InvariantCulture) }
|
||||
},
|
||||
};
|
||||
if (tev.endbeat != null) {
|
||||
rn.endtime = new BeatTime(tev.endbeat[0], tev.endbeat[1], tev.endbeat[2]);
|
||||
longEvents.Add(ev, new StartEventState {
|
||||
Destination = rn,
|
||||
Time = tm.Time,
|
||||
});
|
||||
}
|
||||
group.notes.Add(rn);
|
||||
}
|
||||
}
|
||||
else if (ev is MalodyChart.EndEvent) {
|
||||
var tev = (MalodyChart.EndEvent)ev;
|
||||
if (tev.StartEvent is MalodyChart.Note) {
|
||||
var sev = tev.StartEvent;
|
||||
longEvents.Remove(sev);
|
||||
}
|
||||
else throw new NotSupportedException("Unrecognized long event");
|
||||
}
|
||||
else throw new NotSupportedException("Unrecognized event");
|
||||
}
|
||||
var endbeat = tm.FractionalBeatTime;
|
||||
endbeat.b += 4;
|
||||
chart.endtime = endbeat;
|
||||
meta.length = (float)tm.Time;
|
||||
meta.note_count = group.notes.Count;
|
||||
string chartName = string.Format("{0} - {1}", meta.song.name, meta.name);
|
||||
if (src.meta.background != null) {
|
||||
meta.cover = src.meta.background;
|
||||
}
|
||||
result.Add(new RawChartResource(chartName, chart, meta));
|
||||
return result;
|
||||
}
|
||||
|
||||
struct StartEventState {
|
||||
public double Time { get; set; }
|
||||
public ChartEvent Destination { get; set; }
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
struct MalodyChart {
|
||||
public interface IEvent {
|
||||
int[] beat { get; set; }
|
||||
int[] endbeat { get; set; }
|
||||
int Priority { get; }
|
||||
}
|
||||
public struct EndEvent : IEvent {
|
||||
public int[] beat { get; set; }
|
||||
public int[] endbeat { get; set; }
|
||||
public IEvent StartEvent { get; set; }
|
||||
public int Priority { get { return StartEvent.Priority - 1; } }
|
||||
}
|
||||
|
||||
public Meta meta;
|
||||
public struct Meta {
|
||||
public SongInfo song;
|
||||
public struct SongInfo {
|
||||
public string title;
|
||||
public string artist;
|
||||
public string titleorg;
|
||||
public string artistorg;
|
||||
}
|
||||
|
||||
public string background;
|
||||
|
||||
public string creator;
|
||||
public string version;
|
||||
|
||||
public int mode;
|
||||
public ModeExt mode_ext;
|
||||
public struct ModeExt {
|
||||
public int column;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Time> time;
|
||||
public struct Time : IEvent {
|
||||
public int[] beat { get; set; }
|
||||
public int[] endbeat { get; set; }
|
||||
public float bpm;
|
||||
public int Priority { get { return -2; } }
|
||||
}
|
||||
|
||||
public List<Effect> effect;
|
||||
public struct Effect : IEvent {
|
||||
public int[] beat { get; set; }
|
||||
public int[] endbeat { get; set; }
|
||||
public float? scroll;
|
||||
public int Priority { get { return 0; } }
|
||||
}
|
||||
|
||||
public List<Note> note;
|
||||
public struct Note : IEvent {
|
||||
public int[] beat { get; set; }
|
||||
public int[] endbeat { get; set; }
|
||||
public int column;
|
||||
public string sound;
|
||||
public int offset;
|
||||
public int type;
|
||||
public int Priority { get { return 0; } }
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3624013a6911ba45933085332724ff1
|
||||
timeCreated: 1637936498
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,47 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Malody {
|
||||
public class MalodyChartFinder : LocalResourceFinder {
|
||||
public override string Name { get { return "Malody beatmaps"; } }
|
||||
|
||||
public override string GetRootPath() {
|
||||
var malodyDataPath = GetMalodyDataPath();
|
||||
var malodyConfigPath = Path.Combine(malodyDataPath, "config.json");
|
||||
if (File.Exists(malodyConfigPath)) {
|
||||
using (var reader = new StreamReader(malodyConfigPath, Encoding.UTF8)) {
|
||||
var config = JsonConvert.DeserializeObject<Dictionary<string, object>>(reader.ReadToEnd());
|
||||
object userPath;
|
||||
if (config.TryGetValue("user_chart_path", out userPath)) {
|
||||
var strUserPath = userPath as string;
|
||||
if (!string.IsNullOrEmpty(strUserPath)) {
|
||||
return strUserPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Path.Combine(malodyDataPath, "beatmap");
|
||||
}
|
||||
|
||||
string GetMalodyDataPath() {
|
||||
switch (Environment.OSVersion.Platform) {
|
||||
case PlatformID.Unix:
|
||||
return "/storage/emulated/0/data/malody";
|
||||
case PlatformID.Win32NT:
|
||||
var reg = Registry.ClassesRoot.OpenSubKey(@"malody\Shell\Open\Command");
|
||||
if (reg == null) return null;
|
||||
var pathObj = reg.GetValue(null);
|
||||
if (pathObj == null) return null;
|
||||
var path = (string)pathObj;
|
||||
return new FileInfo(StringUtils.GetProcessPathFromCommand(path)).Directory.FullName;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c9beaff62143a2468e18ad4642232c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,154 +0,0 @@
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Quaver.API.Maps;
|
||||
using Quaver.API.Maps.Structures;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Quaver {
|
||||
public class QuaverChartConverter : ResourceConverter {
|
||||
static readonly string[] SUPPORTED_FORMATS = { ".qua" };
|
||||
const double OFFSET = 0.05;
|
||||
|
||||
public override string[] GetSupportedFormats() {
|
||||
return SUPPORTED_FORMATS;
|
||||
}
|
||||
|
||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||
List<Resource> result = new List<Resource>();
|
||||
var src = Qua.Parse(file.FullName);
|
||||
var ruleset = "quaver!" + src.Mode.ToString().ToLower();
|
||||
var meta = new ChartMeta {
|
||||
name = src.DifficultyName,
|
||||
author = src.Creator,
|
||||
song = new SongMetaInfo {
|
||||
name = src.Title,
|
||||
author = src.Artist,
|
||||
},
|
||||
ruleset = ruleset,
|
||||
cover = src.BackgroundFile,
|
||||
note_count = src.HitObjects.Count,
|
||||
};
|
||||
var chart = new Chart {
|
||||
format = 2,
|
||||
time = new BeatTime(-4, 0, 1),
|
||||
ruleset = ruleset,
|
||||
sigs = new List<Chart.Signature>(),
|
||||
sounds = new List<Chart.Sound> {
|
||||
new Chart.Sound { time = new BeatTime(0, 0, 1), id = src.Title, offset = (float)(src.TimingPoints[0].StartTime / 1e3 + OFFSET) }
|
||||
},
|
||||
motions = new List<Chart.Motion>(),
|
||||
groups = new List<Chart.Group>(),
|
||||
};
|
||||
var group = new Chart.Group() {
|
||||
tracks = new List<Chart.Track>(),
|
||||
notes = new List<Chart.Note>(),
|
||||
motions = new List<Chart.Motion>(),
|
||||
};
|
||||
chart.groups.Add(group);
|
||||
result.Add(new RawChartResource(string.Format("{0} - {1}", meta.song.name, meta.name), chart, meta));
|
||||
result.Add(new SongResource(meta.song.name, new FileInfo(Path.Combine(file.DirectoryName, src.AudioFile))));
|
||||
|
||||
var evs = new List<EventWrapper>();
|
||||
foreach (var e in src.HitObjects) evs.Add(new EventWrapper.HitObject(e));
|
||||
foreach (var e in src.SliderVelocities) evs.Add(new EventWrapper.SliderVelocity(e));
|
||||
foreach (var e in src.SoundEffects) evs.Add(new EventWrapper.SoundEffect(e));
|
||||
foreach (var e in src.TimingPoints) evs.Add(new EventWrapper.TimingPoint(e));
|
||||
var evc = evs.Count;
|
||||
for (int i = 0; i < evc; i++) if (evs[i].IsLong) evs.Add(new EventWrapper.EndEvent(evs[i]));
|
||||
evs.Sort();
|
||||
|
||||
var longevs = new Dictionary<EventWrapper, ChartEvent>();
|
||||
var tm = new TimeTimingModel(src.TimingPoints[0].StartTime / 1e3, 2e-3);
|
||||
foreach (var ev in evs) {
|
||||
tm.ForwardTo(ev.StartTime / 1e3);
|
||||
if (ev is EventWrapper.HitObject) {
|
||||
var tev = (EventWrapper.HitObject)ev;
|
||||
var rn = new Chart.Note {
|
||||
time = tm.FractionalBeatTime,
|
||||
motions = new List<Chart.Motion> {
|
||||
new Chart.Motion { motion = string.Format(CultureInfo.InvariantCulture, "track:{0}", tev.Event.Lane - 1) }
|
||||
},
|
||||
};
|
||||
if (ev.IsLong) longevs.Add(ev, rn);
|
||||
group.notes.Add(rn);
|
||||
}
|
||||
else if (ev is EventWrapper.SliderVelocity) {
|
||||
var tev = (EventWrapper.SliderVelocity)ev;
|
||||
group.motions.Add(new Chart.Motion {
|
||||
time = tm.FractionalBeatTime,
|
||||
motion = string.Format(CultureInfo.InvariantCulture, "svm:{0}", tev.Event.Multiplier),
|
||||
});
|
||||
}
|
||||
else if (ev is EventWrapper.TimingPoint) {
|
||||
var tev = (EventWrapper.TimingPoint)ev;
|
||||
tm.BPM = tev.Event.Bpm;
|
||||
tm.ForceSnap();
|
||||
chart.sigs.Add(new Chart.Signature {
|
||||
time = tm.FractionalBeatTime,
|
||||
tempo = tev.Event.Bpm,
|
||||
});
|
||||
}
|
||||
else if (ev is EventWrapper.EndEvent) {
|
||||
var tev = (EventWrapper.EndEvent)ev;
|
||||
var oev = tev.Original;
|
||||
longevs[oev].endtime = tm.FractionalBeatTime;
|
||||
}
|
||||
else throw new NotSupportedException("Sound effects are not supported yet");
|
||||
}
|
||||
var endbeat = tm.FractionalBeatTime;
|
||||
endbeat.b += 4;
|
||||
chart.endtime = endbeat;
|
||||
meta.length = (float)tm.Time;
|
||||
return result;
|
||||
}
|
||||
|
||||
abstract class EventWrapper : IComparable<EventWrapper> {
|
||||
public abstract int StartTime { get; }
|
||||
public abstract int EndTime { get; }
|
||||
public bool IsLong { get { return EndTime > 0; } }
|
||||
public abstract int Priority { get; }
|
||||
public int CompareTo(EventWrapper other) {
|
||||
var c = StartTime.CompareTo(other.StartTime);
|
||||
if (c != 0) return c;
|
||||
return Priority.CompareTo(other.Priority);
|
||||
}
|
||||
public class HitObject : EventWrapper {
|
||||
public HitObjectInfo Event;
|
||||
public HitObject(HitObjectInfo ev) { Event = ev; }
|
||||
public override int StartTime { get { return Event.StartTime; } }
|
||||
public override int EndTime { get { return Event.EndTime; } }
|
||||
public override int Priority { get { return 0; } }
|
||||
}
|
||||
public class SliderVelocity : EventWrapper {
|
||||
public SliderVelocityInfo Event;
|
||||
public SliderVelocity(SliderVelocityInfo ev) { Event = ev; }
|
||||
public override int StartTime { get { return (int)Event.StartTime; } }
|
||||
public override int EndTime { get { return 0; } }
|
||||
public override int Priority { get { return 0; } }
|
||||
}
|
||||
public class SoundEffect : EventWrapper {
|
||||
public SoundEffectInfo Event;
|
||||
public SoundEffect(SoundEffectInfo ev) { Event = ev; }
|
||||
public override int StartTime { get { return (int)Event.StartTime; } }
|
||||
public override int EndTime { get { return 0; } }
|
||||
public override int Priority { get { return 0; } }
|
||||
}
|
||||
public class TimingPoint : EventWrapper {
|
||||
public TimingPointInfo Event;
|
||||
public TimingPoint(TimingPointInfo ev) { Event = ev; }
|
||||
public override int StartTime { get { return (int)Event.StartTime; } }
|
||||
public override int EndTime { get { return 0; } }
|
||||
public override int Priority { get { return -2; } }
|
||||
}
|
||||
public class EndEvent : EventWrapper {
|
||||
public EventWrapper Original;
|
||||
public EndEvent(EventWrapper ev) { if (!ev.IsLong) throw new ArgumentException("Event is not long"); Original = ev; }
|
||||
public override int StartTime { get { return Original.EndTime; } }
|
||||
public override int EndTime { get { return 0; } }
|
||||
public override int Priority { get { return Original.Priority - 1; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b073cac7ce0d41a4f8ca589845678aa2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,24 +0,0 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Quaver {
|
||||
public class QuaverChartFinder : LocalResourceFinder {
|
||||
public override string Name { get { return "Quaver beatmaps"; } }
|
||||
|
||||
public override string GetRootPath() {
|
||||
switch (Environment.OSVersion.Platform) {
|
||||
case PlatformID.Win32NT:
|
||||
var reg = Registry.ClassesRoot.OpenSubKey(@"quaver\Shell\Open\Command");
|
||||
if (reg == null) return null;
|
||||
var pathObj = reg.GetValue(null);
|
||||
if (pathObj == null) return null;
|
||||
var path = (string)pathObj;
|
||||
return Path.Combine(new FileInfo(StringUtils.GetProcessPathFromCommand(path)).Directory.FullName, "Songs");
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68bacf7746cbeea42a78a7d55cfdbea0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,65 +0,0 @@
|
||||
using Cryville.Common.Math;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Extensions {
|
||||
public abstract class TimingModel {
|
||||
public double Time { get; protected set; }
|
||||
public double BeatTime { get; protected set; }
|
||||
public BeatTime FractionalBeatTime { get; protected set; }
|
||||
double m_bpm;
|
||||
public double BPM { get { return m_bpm; } set { m_bpm = value; } }
|
||||
public double BeatLength { get { return 60 / m_bpm; } set { m_bpm = 60 / value; } }
|
||||
public TimingModel(double offset) {
|
||||
Time = offset;
|
||||
FractionalBeatTime = new BeatTime(0, 0, 1);
|
||||
}
|
||||
}
|
||||
public class FractionalBeatTimeTimingModel : TimingModel {
|
||||
public FractionalBeatTimeTimingModel(double offset = 0) : base(offset) { }
|
||||
public void ForwardTo(BeatTime t) {
|
||||
if (t == FractionalBeatTime) return;
|
||||
if (BPM == 0) throw new InvalidOperationException("BPM not determined");
|
||||
FractionalBeatTime = t;
|
||||
var nt = t.Decimal;
|
||||
Time += (nt - BeatTime) / BPM * 60;
|
||||
BeatTime = nt;
|
||||
}
|
||||
}
|
||||
public class BeatTimeTimingModel : TimingModel {
|
||||
public BeatTimeTimingModel(double offset = 0) : base(offset) { }
|
||||
public void ForwardTo(double t) {
|
||||
if (t == BeatTime) return;
|
||||
if (BPM == 0) throw new InvalidOperationException("BPM not determined");
|
||||
Time += (t - BeatTime) / BPM * 60;
|
||||
BeatTime = t;
|
||||
FractionalBeatTime = ToBeatTime(t);
|
||||
}
|
||||
static BeatTime ToBeatTime(double beat, double error = 1e-4) {
|
||||
int i, n, d;
|
||||
FractionUtils.ToFraction(beat, error, out n, out d);
|
||||
i = n / d; n %= d;
|
||||
return new BeatTime(i, n, d);
|
||||
}
|
||||
}
|
||||
public class TimeTimingModel : TimingModel {
|
||||
public readonly double InputTimeAccuracy;
|
||||
public TimeTimingModel(double offset = 0, double accuracy = 2e-3) : base(offset) {
|
||||
if (accuracy <= 0) throw new ArgumentOutOfRangeException("accuracy");
|
||||
InputTimeAccuracy = accuracy;
|
||||
}
|
||||
public void ForwardTo(double t) {
|
||||
if (t == Time) return;
|
||||
if (BPM == 0) throw new InvalidOperationException("BPM not determined");
|
||||
BeatTime += (t - Time) * BPM / 60;
|
||||
int n, d;
|
||||
FractionUtils.ToFraction(BeatTime, Math.Min(1, InputTimeAccuracy * BPM / 60), out n, out d);
|
||||
FractionalBeatTime = new BeatTime(n, d);
|
||||
Time = t;
|
||||
}
|
||||
public void ForceSnap() {
|
||||
var alignedBeat = (int)Math.Round(BeatTime);
|
||||
BeatTime = alignedBeat;
|
||||
FractionalBeatTime = new BeatTime(alignedBeat, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c4a1fab8f53dd742ba6501d682eb7f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6823ead66b33bc048bbad48719feb25d
|
||||
guid: 3fe9f91db8da80f459bcf70ff680644f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user