Pull up IChartDetail.

This commit is contained in:
2023-12-19 15:23:40 +08:00
parent 81d458f7de
commit b7f5dbc4da
11 changed files with 59 additions and 20 deletions

View File

@@ -46,12 +46,16 @@ namespace Cryville.Crtr.Browsing.Actions {
} }
public IEnumerable<IResourceAction> GetActions(Type type) { public IEnumerable<IResourceAction> GetActions(Type type) {
if (type == null) return Enumerable.Empty<IResourceAction>();
List<IResourceAction> actions; List<IResourceAction> actions;
if (!_actions.TryGetValue(type, out actions)) { if (!_actions.TryGetValue(type, out actions)) {
actions = new List<IResourceAction>(); actions = new List<IResourceAction>();
} }
IEnumerable<IResourceAction> result = actions; IEnumerable<IResourceAction> result = actions;
if (type != typeof(object)) result = result.Concat(GetActions(type.BaseType)); if (type != typeof(object))
result = result
.Concat(GetActions(type.BaseType))
.Concat(type.GetInterfaces().SelectMany(i => GetActions(i)));
return result; return result;
} }
} }

View File

@@ -5,16 +5,16 @@ using System.Collections.Generic;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
namespace Cryville.Crtr.Browsing.Actions { namespace Cryville.Crtr.Browsing.Actions {
internal class OpenConfigAction : ResourceAction<ChartDetail> { internal class OpenConfigAction : ResourceAction<IChartDetail> {
public override string Name { get { return "Config"; } } public override string Name { get { return "Config"; } }
public override int Priority { get { return -50; } } public override int Priority { get { return -50; } }
static readonly Dictionary<string, int> _rulesetTabs = new Dictionary<string, int>(); static readonly Dictionary<string, int> _rulesetTabs = new Dictionary<string, int>();
public override void Invoke(Uri uri, ChartDetail resource) { public override void Invoke(Uri uri, IChartDetail resource) {
var master = ResourceBrowserMaster.Instance; var master = ResourceBrowserMaster.Instance;
var ruleset = resource.Meta.ruleset; var ruleset = resource.RulesetId;
int tabId; int tabId;
if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId)) if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
return; return;

View File

@@ -4,13 +4,13 @@ using System.IO;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
namespace Cryville.Crtr.Browsing.Actions { namespace Cryville.Crtr.Browsing.Actions {
internal class PlayChartAction : ResourceAction<ChartDetail> { internal class PlayChartAction : ResourceAction<IChartDetail> {
public override string Name { get { return "Play"; } } public override string Name { get { return "Play"; } }
public override int Priority { get { return -100; } } public override int Priority { get { return -100; } }
public override void Invoke(Uri uri, ChartDetail resource) { public override void Invoke(Uri uri, IChartDetail resource) {
Settings.Default.LoadRuleset = Path.Combine(resource.Meta.ruleset, ".umgr"); Settings.Default.LoadRuleset = Path.Combine(resource.RulesetId, ".umgr");
Settings.Default.LoadRulesetConfig = resource.Meta.ruleset + ".json"; Settings.Default.LoadRulesetConfig = resource.RulesetId + ".json";
Settings.Default.LoadChart = uri.LocalPath; Settings.Default.LoadChart = uri.LocalPath;
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
SceneManager.LoadScene("Play", LoadSceneMode.Additive); SceneManager.LoadScene("Play", LoadSceneMode.Additive);
@@ -19,7 +19,7 @@ namespace Cryville.Crtr.Browsing.Actions {
#endif #endif
Master.Instance.HideMenu(); Master.Instance.HideMenu();
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", resource.Meta.song.name, resource.Meta.name), resource.Meta.length); DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", resource.SongName, resource.Name), resource.Length.TotalSeconds);
#endif #endif
} }
} }

View File

@@ -0,0 +1,10 @@
using System;
namespace Cryville.Crtr.Browsing {
internal interface IChartDetail {
string RulesetId { get; }
string Name { get; }
string SongName { get; }
TimeSpan Length { get; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 117e1aa46a380524096d0b6bea97c3d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee929ca432bd0ff41bee174081ef16df
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,24 +4,29 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing.Legacy {
public class ChartDetail : IResourceMeta { public class LegacyChartDetail : IChartDetail, IResourceMeta {
public AsyncDelivery<Texture2D> Cover { get; set; } public AsyncDelivery<Texture2D> Cover { get; set; }
public ChartMeta Meta { get; set; } public ChartMeta Meta { get; set; }
public string RulesetId { get { return Meta.ruleset; } }
public string Name { get { return Meta.name; } }
public string SongName { get { return Meta.song.name; } }
public TimeSpan Length { get { return TimeSpan.FromSeconds(Meta.length); } }
public IEnumerable<MetaProperty> Properties { public IEnumerable<MetaProperty> Properties {
get { get {
if (Meta == null) yield break; if (Meta == null) yield break;
yield return new MetaProperty("Name", new Dictionary<string, object> { yield return new MetaProperty("Name", new Dictionary<string, object> {
{ "", string.Format("{0} - {1}", Meta.song.name, Meta.name) }, { "", string.Format("{0} - {1}", SongName, Name) },
{ "short", Meta.name }, { "short", Name },
{ "distinct-primary", Meta.song.name }, { "distinct-primary", SongName },
{ "distinct-secondary", Meta.name }, { "distinct-secondary", Name },
}); });
yield return new MetaProperty("Image", Cover); yield return new MetaProperty("Image", Cover);
yield return new MetaProperty("Song.Author", Meta.song.author); yield return new MetaProperty("Song.Author", Meta.song.author);
yield return new MetaProperty("Author", Meta.author); yield return new MetaProperty("Author", Meta.author);
yield return new MetaProperty("Length", TimeSpan.FromSeconds(Meta.length)); yield return new MetaProperty("Length", Length);
yield return new MetaProperty("NoteCount", Meta.note_count); yield return new MetaProperty("NoteCount", Meta.note_count);
} }
} }

View File

@@ -11,8 +11,8 @@ using System.IO;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing.Legacy {
internal class LegacyResourceManager : IPathedResourceManager<ChartDetail> { internal class LegacyResourceManager : IPathedResourceManager<LegacyChartDetail> {
readonly string _rootPath; readonly string _rootPath;
DirectoryInfo _cd; DirectoryInfo _cd;
readonly FileSystemWatcher _watcher = new FileSystemWatcher(); readonly FileSystemWatcher _watcher = new FileSystemWatcher();
@@ -98,7 +98,7 @@ namespace Cryville.Crtr.Browsing {
ItemChanged?.Invoke(); ItemChanged?.Invoke();
} }
public ChartDetail this[int index] { public LegacyChartDetail this[int index] {
get { get {
var item = _filteredItems[index]; var item = _filteredItems[index];
ChartMeta meta = null; ChartMeta meta = null;
@@ -118,7 +118,7 @@ namespace Cryville.Crtr.Browsing {
} }
} }
} }
return new ChartDetail { return new LegacyChartDetail {
Cover = cover, Cover = cover,
Meta = meta, Meta = meta,
}; };

View File

@@ -1,5 +1,6 @@
using Cryville.Common.Unity; using Cryville.Common.Unity;
using Cryville.Crtr.Browsing.Actions; using Cryville.Crtr.Browsing.Actions;
using Cryville.Crtr.Browsing.Legacy;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;