From 33ee7a9a87a4ec86d4de34cc9f1448079e20953c Mon Sep 17 00:00:00 2001 From: PopSlime Date: Sat, 18 Feb 2023 15:46:32 +0800 Subject: [PATCH] Code cleanup. --- Assets/Cryville/Common/Identifier.cs | 8 ++--- .../Cryville/Crtr/Config/InputConfigPanel.cs | 9 +++--- .../Crtr/Config/InputConfigPanelEntry.cs | 15 +++------- Assets/Cryville/Crtr/Event/MotionCache.cs | 2 +- Assets/Cryville/Crtr/Event/RMVPool.cs | 2 +- Assets/Cryville/Crtr/Game.cs | 20 ++++++------- Assets/Cryville/Crtr/InputProxy.cs | 30 +++++++++---------- Assets/Cryville/Crtr/PdtBinder.cs | 2 +- 8 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Assets/Cryville/Common/Identifier.cs b/Assets/Cryville/Common/Identifier.cs index e659cd6..bb7ce9c 100644 --- a/Assets/Cryville/Common/Identifier.cs +++ b/Assets/Cryville/Common/Identifier.cs @@ -24,11 +24,11 @@ namespace Cryville.Common { if (Key == 0) return ""; return Name.ToString(); } - public static implicit operator Identifier(string identifier) { - return new Identifier(identifier); + public static bool operator ==(Identifier lhs, Identifier rhs) { + return lhs.Equals(rhs); } - public static implicit operator string(Identifier identifier) { - return identifier.ToString(); + public static bool operator !=(Identifier lhs, Identifier rhs) { + return !lhs.Equals(rhs); } } } diff --git a/Assets/Cryville/Crtr/Config/InputConfigPanel.cs b/Assets/Cryville/Crtr/Config/InputConfigPanel.cs index ab9cb89..4df76ee 100644 --- a/Assets/Cryville/Crtr/Config/InputConfigPanel.cs +++ b/Assets/Cryville/Crtr/Config/InputConfigPanel.cs @@ -1,4 +1,5 @@ -using Cryville.Common.Unity; +using Cryville.Common; +using Cryville.Common.Unity; using Cryville.Common.Unity.Input; using System.Collections.Generic; using UnityEngine; @@ -26,10 +27,10 @@ namespace Cryville.Crtr.Config { SimpleInputConsumer _consumer; public InputProxy proxy; - readonly Dictionary _entries = new Dictionary(); + readonly Dictionary _entries = new Dictionary(); - string _sel; - public void OpenDialog(string entry) { + Identifier _sel; + public void OpenDialog(Identifier entry) { _sel = entry; m_inputDialog.SetActive(true); CallHelper.Purge(m_deviceList); diff --git a/Assets/Cryville/Crtr/Config/InputConfigPanelEntry.cs b/Assets/Cryville/Crtr/Config/InputConfigPanelEntry.cs index 0a0834f..a74fdb4 100644 --- a/Assets/Cryville/Crtr/Config/InputConfigPanelEntry.cs +++ b/Assets/Cryville/Crtr/Config/InputConfigPanelEntry.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using Cryville.Common; +using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -13,8 +14,8 @@ namespace Cryville.Crtr.Config { [SerializeField] Button m_button; - public void SetKey(InputConfigPanel master, string name) { - m_key.text = name; + public void SetKey(InputConfigPanel master, Identifier name) { + m_key.text = (string)name.Name; m_value.text = "None"; m_button.onClick.AddListener(() => { master.OpenDialog(name); @@ -40,13 +41,5 @@ namespace Cryville.Crtr.Config { } } } - - public void SetValue(string name) { - m_value.text = name; - } - - public void SetEnabled(bool flag) { - m_button.interactable = flag; - } } } diff --git a/Assets/Cryville/Crtr/Event/MotionCache.cs b/Assets/Cryville/Crtr/Event/MotionCache.cs index 0e2c43e..8f58b91 100644 --- a/Assets/Cryville/Crtr/Event/MotionCache.cs +++ b/Assets/Cryville/Crtr/Event/MotionCache.cs @@ -14,7 +14,7 @@ namespace Cryville.Crtr.Event { internal class MotionCachePool : CategorizedPool { private class Bucket : ObjectPool { readonly MotionRegistry _reg; - public Bucket(string name, int capacity) : base(capacity) { + public Bucket(Identifier name, int capacity) : base(capacity) { _reg = ChartPlayer.motionRegistry[name]; } protected override MotionCache Construct() { diff --git a/Assets/Cryville/Crtr/Event/RMVPool.cs b/Assets/Cryville/Crtr/Event/RMVPool.cs index 263950a..2591103 100644 --- a/Assets/Cryville/Crtr/Event/RMVPool.cs +++ b/Assets/Cryville/Crtr/Event/RMVPool.cs @@ -6,7 +6,7 @@ namespace Cryville.Crtr.Event { internal class RMVPool : CategorizedPool { private class Bucket : ObjectPool { readonly MotionRegistry _reg; - public Bucket(string name, int capacity) : base(capacity) { + public Bucket(Identifier name, int capacity) : base(capacity) { _reg = ChartPlayer.motionRegistry[name]; } protected override RealtimeMotionValue Construct() { diff --git a/Assets/Cryville/Crtr/Game.cs b/Assets/Cryville/Crtr/Game.cs index a22954a..684a151 100644 --- a/Assets/Cryville/Crtr/Game.cs +++ b/Assets/Cryville/Crtr/Game.cs @@ -104,16 +104,16 @@ namespace Cryville.Crtr { } ChartPlayer.motionRegistry = new Dictionary { - { "pt" , new MotionRegistry(typeof(VecPt)) }, - { "dir" , new MotionRegistry(typeof(Vec3)) }, - { "normal" , new MotionRegistry(typeof(Vec3)) }, - { "sv" , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, 1f)) }, - { "svm" , new MotionRegistry(new Vec1m(1f)) }, - { "dist" , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, float.PositiveInfinity)) }, - { "corner" , new MotionRegistry(typeof(VecI1)) }, - { "ctrl0" , new MotionRegistry(typeof(VecCtrl)) }, - { "ctrl1" , new MotionRegistry(typeof(VecCtrl)) }, - { "track" , new MotionRegistry(typeof(Vec1)) }, + { new Identifier("pt") , new MotionRegistry(typeof(VecPt)) }, + { new Identifier("dir") , new MotionRegistry(typeof(Vec3)) }, + { new Identifier("normal") , new MotionRegistry(typeof(Vec3)) }, + { new Identifier("sv") , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, 1f)) }, + { new Identifier("svm") , new MotionRegistry(new Vec1m(1f)) }, + { new Identifier("dist") , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, float.PositiveInfinity)) }, + { new Identifier("corner") , new MotionRegistry(typeof(VecI1)) }, + { new Identifier("ctrl0") , new MotionRegistry(typeof(VecCtrl)) }, + { new Identifier("ctrl1") , new MotionRegistry(typeof(VecCtrl)) }, + { new Identifier("track") , new MotionRegistry(typeof(Vec1)) }, }; var dir = new DirectoryInfo(Settings.Default.GameDataPath + "/charts"); diff --git a/Assets/Cryville/Crtr/InputProxy.cs b/Assets/Cryville/Crtr/InputProxy.cs index 0a61423..c3f21c0 100644 --- a/Assets/Cryville/Crtr/InputProxy.cs +++ b/Assets/Cryville/Crtr/InputProxy.cs @@ -23,7 +23,7 @@ namespace Cryville.Crtr { _judge = judge; foreach (var i in ruleset.inputs) { _use.Add(i.Key, 0); - _rev.Add(i.Key, new List()); + _rev.Add(i.Key, new List()); } foreach (var i in ruleset.inputs) { if (i.Value.pass != null) { @@ -33,15 +33,15 @@ namespace Cryville.Crtr { } } #region Settings - readonly Dictionary _tproxies = new Dictionary(); + readonly Dictionary _tproxies = new Dictionary(); readonly Dictionary _sproxies = new Dictionary(); - readonly Dictionary _use = new Dictionary(); - readonly Dictionary> _rev = new Dictionary>(); + readonly Dictionary _use = new Dictionary(); + readonly Dictionary> _rev = new Dictionary>(); public event EventHandler ProxyChanged; public void LoadFrom(Dictionary config) { foreach (var cfg in config) { Set(new InputProxyEntry { - Target = cfg.Key, + Target = new Identifier(cfg.Key), Source = new InputSource { Handler = Game.InputManager.GetHandler(cfg.Value.handler), Type = cfg.Value.type @@ -52,7 +52,7 @@ namespace Cryville.Crtr { public void SaveTo(Dictionary config) { config.Clear(); foreach (var p in _tproxies) { - config.Add(p.Key, new RulesetConfig.InputEntry { + config.Add((string)p.Key.Name, new RulesetConfig.InputEntry { handler = ReflectionHelper.GetNamespaceQualifiedName(p.Value.Source.Value.Handler.GetType()), type = p.Value.Source.Value.Type }); @@ -88,7 +88,7 @@ namespace Cryville.Crtr { return true; } } - void IncrementUseRecursive(string name) { + void IncrementUseRecursive(Identifier name) { BroadcastProxyChanged(name); var passes = _ruleset.inputs[name].pass; if (passes != null) { @@ -98,14 +98,14 @@ namespace Cryville.Crtr { } } } - void IncrementReversedUseRecursive(string name) { + void IncrementReversedUseRecursive(Identifier name) { foreach (var p in _rev[name]) { _use[p]++; BroadcastProxyChanged(p); IncrementReversedUseRecursive(p); } } - void DecrementUseRecursive(string name) { + void DecrementUseRecursive(Identifier name) { BroadcastProxyChanged(name); var passes = _ruleset.inputs[name].pass; if (passes != null) { @@ -115,18 +115,18 @@ namespace Cryville.Crtr { } } } - void DecrementReversedUseRecursive(string name) { + void DecrementReversedUseRecursive(Identifier name) { foreach (var p in _rev[name]) { _use[p]--; BroadcastProxyChanged(p); DecrementReversedUseRecursive(p); } } - void BroadcastProxyChanged(string name) { + void BroadcastProxyChanged(Identifier name) { var del = ProxyChanged; if (del != null) del(this, this[name]); } - public ProxyChangedEventArgs this[string name] { + public ProxyChangedEventArgs this[Identifier name] { get { return new ProxyChangedEventArgs(name, _tproxies.ContainsKey(name) ? _tproxies[name].Source : null, _use[name] > 0); } @@ -263,10 +263,10 @@ namespace Cryville.Crtr { } public class ProxyChangedEventArgs : EventArgs { - public string Name { get; private set; } + public Identifier Name { get; private set; } public InputSource? Proxy { get; private set; } public bool Used { get; private set; } - public ProxyChangedEventArgs(string name, InputSource? src, bool used) { + public ProxyChangedEventArgs(Identifier name, InputSource? src, bool used) { Name = name; Proxy = src; Used = used; @@ -275,7 +275,7 @@ namespace Cryville.Crtr { public class InputProxyEntry { public InputSource? Source { get; set; } - public string Target { get; set; } + public Identifier Target { get; set; } public byte[] Mapping { get; private set; } } diff --git a/Assets/Cryville/Crtr/PdtBinder.cs b/Assets/Cryville/Crtr/PdtBinder.cs index 579adf7..f2dfb74 100644 --- a/Assets/Cryville/Crtr/PdtBinder.cs +++ b/Assets/Cryville/Crtr/PdtBinder.cs @@ -49,7 +49,7 @@ namespace Cryville.Crtr { else if (value is string) { var exp = (string)value; if (type.Equals(typeof(Identifier))) { - return (Identifier)exp; + return new Identifier(exp); } else if (type == typeof(ScoreOperation)) { var m = Regex.Match(exp, @"^(\S+)\s*?(\S+)?$");