Compare commits
2 Commits
b45cf9cba7
...
8c11be48cf
Author | SHA1 | Date | |
---|---|---|---|
8c11be48cf | |||
9fcf6f3379 |
@@ -2,14 +2,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
public interface IResourceManager<T> {
|
public interface IResourceManager<T> : IReadOnlyList<T> {
|
||||||
int ItemCount { get; }
|
Uri GetItemUri(int id);
|
||||||
|
|
||||||
ResourceItemMeta GetItemMeta(int id);
|
bool ImportItemFrom(Uri uri);
|
||||||
T GetItemDetail(int id);
|
|
||||||
string GetItemPath(int id);
|
|
||||||
|
|
||||||
bool ImportItemFrom(string path);
|
|
||||||
string[] GetSupportedFormats();
|
string[] GetSupportedFormats();
|
||||||
IReadOnlyDictionary<string, string> GetPresetPaths();
|
IReadOnlyDictionary<string, string> GetPresetPaths();
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ using Cryville.Crtr.Extensions.Umg;
|
|||||||
using Cryville.Crtr.UI;
|
using Cryville.Crtr.UI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -18,7 +19,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
private DirectoryInfo cd;
|
private DirectoryInfo cd;
|
||||||
private DirectoryInfo[] items = new DirectoryInfo[0];
|
private DirectoryInfo[] items = new DirectoryInfo[0];
|
||||||
public string[] CurrentDirectory { get; private set; }
|
public string[] CurrentDirectory { get; private set; }
|
||||||
public int ItemCount { get { return items.Length; } }
|
public int Count { get { return items.Length; } }
|
||||||
|
|
||||||
static bool _init;
|
static bool _init;
|
||||||
|
|
||||||
@@ -46,47 +47,17 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
ChangeDirectory(nd);
|
ChangeDirectory(nd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReturnToDirectory(int id) {
|
public void ReturnToDirectory(int index) {
|
||||||
string[] nd = new string[id + 1];
|
string[] nd = new string[index + 1];
|
||||||
Array.Copy(CurrentDirectory, nd, id + 1);
|
Array.Copy(CurrentDirectory, nd, index + 1);
|
||||||
ChangeDirectory(nd);
|
ChangeDirectory(nd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceItemMeta GetItemMeta(int id) {
|
public ChartDetail this[int index] {
|
||||||
var item = items[id];
|
get {
|
||||||
var meta = new ChartMeta();
|
var item = items[index];
|
||||||
string name = item.Name;
|
ChartMeta meta = null;
|
||||||
string desc = "(Unknown)";
|
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
||||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
|
||||||
if (metaFile.Exists) {
|
|
||||||
using (var reader = new StreamReader(metaFile.FullName)) {
|
|
||||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
|
||||||
name = meta.song.name;
|
|
||||||
desc = meta.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(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
|
||||||
cover.CancelSource = task.Cancel;
|
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ResourceItemMeta {
|
|
||||||
IsDirectory = false,
|
|
||||||
Icon = cover,
|
|
||||||
Name = name,
|
|
||||||
DescriptionMain = desc,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChartDetail GetItemDetail(int id) {
|
|
||||||
var item = items[id];
|
|
||||||
var meta = new ChartMeta();
|
|
||||||
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)) {
|
||||||
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||||
@@ -107,19 +78,21 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
Meta = meta,
|
Meta = meta,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetItemPath(int id) {
|
public Uri GetItemUri(int id) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
var meta = new ChartMeta();
|
var meta = new ChartMeta();
|
||||||
var metaFile = new FileInfo(item.FullName + "/.umgc");
|
var metaFile = new FileInfo(Path.Combine(item.FullName, ".umgc"));
|
||||||
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());
|
||||||
}
|
}
|
||||||
return string.Format("{0}/{1}.json", items[id].Name, meta.data);
|
return new Uri(Path.Combine(items[id].Name, string.Format("{0}.json", meta.data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ImportItemFrom(string path) {
|
public bool ImportItemFrom(Uri uri) {
|
||||||
var file = new FileInfo(path);
|
if (!uri.IsFile) throw new NotSupportedException();
|
||||||
|
var file = new FileInfo(uri.LocalPath);
|
||||||
IEnumerable<ResourceConverter> converters;
|
IEnumerable<ResourceConverter> converters;
|
||||||
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
|
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
|
||||||
foreach (var converter in converters) {
|
foreach (var converter in converters) {
|
||||||
@@ -195,6 +168,27 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Enumerator GetEnumerator() { return new Enumerator(this); }
|
||||||
|
IEnumerator<ChartDetail> IEnumerable<ChartDetail>.GetEnumerator() { return GetEnumerator(); }
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||||
|
|
||||||
|
public struct Enumerator : IEnumerator<ChartDetail> {
|
||||||
|
readonly LegacyResourceManager _list;
|
||||||
|
public ChartDetail Current => throw new NotImplementedException();
|
||||||
|
object IEnumerator.Current => Current;
|
||||||
|
|
||||||
|
public Enumerator(LegacyResourceManager list) { _list = list; }
|
||||||
|
public void Dispose() { }
|
||||||
|
|
||||||
|
public bool MoveNext() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LogAndPopup(int level, string format, params object[] args) {
|
void LogAndPopup(int level, string format, params object[] args) {
|
||||||
var msg = string.Format(format, args);
|
var msg = string.Format(format, args);
|
||||||
Logger.Log("main", level, "Resource", msg);
|
Logger.Log("main", level, "Resource", msg);
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
using Cryville.Common;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
|
||||||
public struct ResourceItemMeta {
|
|
||||||
public bool IsDirectory { get; set; }
|
|
||||||
public AsyncDelivery<Texture2D> Icon { get; set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string DescriptionMain { get; set; }
|
|
||||||
public string DescriptionSub { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: f535064222dd08c4f8e52d6e9144079a
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@@ -3,8 +3,8 @@ using UnityEngine;
|
|||||||
namespace Cryville.Crtr.Browsing.UI {
|
namespace Cryville.Crtr.Browsing.UI {
|
||||||
internal abstract class BrowserItem : MonoBehaviour {
|
internal abstract class BrowserItem : MonoBehaviour {
|
||||||
public int? Id { get; private set; }
|
public int? Id { get; private set; }
|
||||||
protected ResourceItemMeta meta;
|
protected ChartDetail meta;
|
||||||
internal void Load(int id, ResourceItemMeta item, bool selected) {
|
internal void Load(int id, ChartDetail item, bool selected) {
|
||||||
OnReset();
|
OnReset();
|
||||||
Id = id;
|
Id = id;
|
||||||
meta = item;
|
meta = item;
|
||||||
|
@@ -11,7 +11,6 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
Sprite m_iconPlaceholder;
|
Sprite m_iconPlaceholder;
|
||||||
#pragma warning restore IDE0044
|
#pragma warning restore IDE0044
|
||||||
|
|
||||||
bool _dir;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Image m_icon;
|
Image m_icon;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@@ -29,7 +28,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
OnReset();
|
OnReset();
|
||||||
}
|
}
|
||||||
protected override void OnReset() {
|
protected override void OnReset() {
|
||||||
if (meta.Icon != null) meta.Icon.Cancel();
|
if (meta.Cover != null) meta.Cover.Cancel();
|
||||||
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
|
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
|
||||||
Destroy(m_icon.sprite.texture);
|
Destroy(m_icon.sprite.texture);
|
||||||
Destroy(m_icon.sprite);
|
Destroy(m_icon.sprite);
|
||||||
@@ -38,11 +37,16 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLoad(bool selected) {
|
protected override void OnLoad(bool selected) {
|
||||||
_dir = meta.IsDirectory;
|
|
||||||
m_icon.sprite = m_iconPlaceholder;
|
m_icon.sprite = m_iconPlaceholder;
|
||||||
if (meta.Icon != null) meta.Icon.Destination = DisplayCover;
|
if (meta.Cover != null) meta.Cover.Destination = DisplayCover;
|
||||||
m_title.text = meta.Name;
|
if (meta.Meta != null) {
|
||||||
m_desc.text = string.Format("{0}\n{1}", meta.DescriptionMain, meta.DescriptionSub);
|
m_title.text = meta.Meta.name;
|
||||||
|
m_desc.text = meta.Meta.song.name;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_title.text = "<color=#ff0000>Invalid resource</color>";
|
||||||
|
m_desc.text = string.Empty;
|
||||||
|
}
|
||||||
if (selected) _tweener.EnterState("Selected");
|
if (selected) _tweener.EnterState("Selected");
|
||||||
}
|
}
|
||||||
private void DisplayCover(bool succeeded, Texture2D tex) {
|
private void DisplayCover(bool succeeded, Texture2D tex) {
|
||||||
@@ -53,8 +57,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
public void OnClick() {
|
public void OnClick() {
|
||||||
if (Id == null) return;
|
if (Id == null) return;
|
||||||
var resourceBrowser = GetComponentInParent<PathedResourceBrowser>();
|
var resourceBrowser = GetComponentInParent<PathedResourceBrowser>();
|
||||||
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
|
resourceBrowser.OnObjectItemClicked(Id.Value);
|
||||||
else resourceBrowser.OnObjectItemClicked(Id.Value);
|
|
||||||
}
|
}
|
||||||
public void OnPointerClick(PointerEventData eventData) {
|
public void OnPointerClick(PointerEventData eventData) {
|
||||||
OnClick();
|
OnClick();
|
||||||
|
@@ -31,7 +31,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnItemChanged() {
|
void OnItemChanged() {
|
||||||
ItemContainer.ItemCount = ResourceManager.ItemCount;
|
ItemContainer.ItemCount = ResourceManager.Count;
|
||||||
_selectedItems.Clear();
|
_selectedItems.Clear();
|
||||||
_items.Clear();
|
_items.Clear();
|
||||||
}
|
}
|
||||||
@@ -40,11 +40,11 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
var bi = obj.GetComponent<BrowserItem>();
|
var bi = obj.GetComponent<BrowserItem>();
|
||||||
_items[id] = bi;
|
_items[id] = bi;
|
||||||
try {
|
try {
|
||||||
var item = ResourceManager.GetItemMeta(id);
|
var item = ResourceManager[id];
|
||||||
bi.Load(id, item, _selectedItems.Contains(id));
|
bi.Load(id, item, _selectedItems.Contains(id));
|
||||||
}
|
}
|
||||||
catch (Exception) {
|
catch (Exception) {
|
||||||
bi.Load(id, new ResourceItemMeta { Name = "<color=#ff0000>Invalid resource</color>" }, _selectedItems.Contains(id));
|
bi.Load(id, default(ChartDetail), _selectedItems.Contains(id));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
_selectedItems.Clear();
|
_selectedItems.Clear();
|
||||||
_items[id].OnSelect();
|
_items[id].OnSelect();
|
||||||
_selectedItems.Add(id);
|
_selectedItems.Add(id);
|
||||||
Master.ShowDetail(id, ResourceManager.GetItemDetail(id));
|
Master.ShowDetail(id, ResourceManager[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPathClicked(int id) {
|
public void OnPathClicked(int id) {
|
||||||
@@ -71,7 +71,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
|
|
||||||
private void OnAddDialogClosed() {
|
private void OnAddDialogClosed() {
|
||||||
if (_dialog.FileName == null) return;
|
if (_dialog.FileName == null) return;
|
||||||
if (ResourceManager.ImportItemFrom(_dialog.FileName)) {
|
if (ResourceManager.ImportItemFrom(new Uri(_dialog.FileName))) {
|
||||||
Popup.Create("Import succeeded");
|
Popup.Create("Import succeeded");
|
||||||
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
OnPathClicked(ResourceManager.CurrentDirectory.Length - 1);
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
void SetDataSettings(int id, ChartDetail detail) {
|
void SetDataSettings(int id, ChartDetail detail) {
|
||||||
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
||||||
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
||||||
Settings.Default.LoadChart = m_mainBrowser.ResourceManager.GetItemPath(id);
|
Settings.Default.LoadChart = m_mainBrowser.ResourceManager.GetItemUri(id).LocalPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user