Add resource action. Implement play chart and import resource action.
This commit is contained in:
12
Assets/Cryville/Crtr/Browsing/Actions/IResourceAction.cs
Normal file
12
Assets/Cryville/Crtr/Browsing/Actions/IResourceAction.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.Actions {
|
||||
public interface IResourceAction {
|
||||
string Name { get; }
|
||||
int Priority { get; }
|
||||
void Invoke(Uri uri, object resource);
|
||||
}
|
||||
public interface IResourceAction<T> : IResourceAction {
|
||||
void Invoke(Uri uri, T resource);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06644fed46df1e3479274e77d7050770
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
using Cryville.Crtr.UI;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.Actions {
|
||||
internal class ImportResourceAction : IResourceAction {
|
||||
readonly IResourceManager _destination;
|
||||
public ImportResourceAction(IResourceManager destination) {
|
||||
_destination = destination;
|
||||
}
|
||||
|
||||
public string Name { get { return "Import"; } }
|
||||
public int Priority { get { return 0; } }
|
||||
|
||||
public void Invoke(Uri uri, object resource) {
|
||||
if (_destination.ImportFrom(uri))
|
||||
Popup.Create("Import succeeded");
|
||||
else
|
||||
Popup.Create("Import failed");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 051f1b92e4abcdc48a3de86ddf3838ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
26
Assets/Cryville/Crtr/Browsing/Actions/PlayChartAction.cs
Normal file
26
Assets/Cryville/Crtr/Browsing/Actions/PlayChartAction.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Cryville.Crtr.UI;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.Actions {
|
||||
internal class PlayChartAction : ResourceAction<ChartDetail> {
|
||||
public override string Name { get { return "Play"; } }
|
||||
public override int Priority { get { return -100; } }
|
||||
|
||||
public override void Invoke(Uri uri, ChartDetail resource) {
|
||||
Settings.Default.LoadRuleset = Path.Combine(resource.Meta.ruleset, ".umgr");
|
||||
Settings.Default.LoadRulesetConfig = resource.Meta.ruleset + ".json";
|
||||
Settings.Default.LoadChart = uri.LocalPath;
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
||||
#else
|
||||
Application.LoadLevelAdditive("Play");
|
||||
#endif
|
||||
Master.Instance.HideMenu();
|
||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", resource.Meta.song.name, resource.Meta.name), resource.Meta.length);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62f16d8524484ef4f8b2dda039b3f54e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs
Normal file
14
Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.Actions {
|
||||
public abstract class ResourceAction<T> : IResourceAction<T> {
|
||||
public abstract string Name { get; }
|
||||
public abstract int Priority { get; }
|
||||
public abstract void Invoke(Uri uri, T resource);
|
||||
public void Invoke(Uri uri, object resource) {
|
||||
if (resource == null) throw new ArgumentNullException("resource");
|
||||
if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
|
||||
Invoke(uri, (T)resource);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/Actions/ResourceAction.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97f5674394761704bae04fe222afd086
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user