Code cleanup.

This commit is contained in:
2023-02-18 15:46:32 +08:00
parent 900bd7b77a
commit 33ee7a9a87
8 changed files with 41 additions and 47 deletions

View File

@@ -24,11 +24,11 @@ namespace Cryville.Common {
if (Key == 0) return ""; if (Key == 0) return "";
return Name.ToString(); return Name.ToString();
} }
public static implicit operator Identifier(string identifier) { public static bool operator ==(Identifier lhs, Identifier rhs) {
return new Identifier(identifier); return lhs.Equals(rhs);
} }
public static implicit operator string(Identifier identifier) { public static bool operator !=(Identifier lhs, Identifier rhs) {
return identifier.ToString(); return !lhs.Equals(rhs);
} }
} }
} }

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Unity; using Cryville.Common;
using Cryville.Common.Unity;
using Cryville.Common.Unity.Input; using Cryville.Common.Unity.Input;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@@ -26,10 +27,10 @@ namespace Cryville.Crtr.Config {
SimpleInputConsumer _consumer; SimpleInputConsumer _consumer;
public InputProxy proxy; public InputProxy proxy;
readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>(); readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
string _sel; Identifier _sel;
public void OpenDialog(string entry) { public void OpenDialog(Identifier entry) {
_sel = entry; _sel = entry;
m_inputDialog.SetActive(true); m_inputDialog.SetActive(true);
CallHelper.Purge(m_deviceList); CallHelper.Purge(m_deviceList);

View File

@@ -1,4 +1,5 @@
using UnityEngine; using Cryville.Common;
using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
@@ -13,8 +14,8 @@ namespace Cryville.Crtr.Config {
[SerializeField] [SerializeField]
Button m_button; Button m_button;
public void SetKey(InputConfigPanel master, string name) { public void SetKey(InputConfigPanel master, Identifier name) {
m_key.text = name; m_key.text = (string)name.Name;
m_value.text = "None"; m_value.text = "None";
m_button.onClick.AddListener(() => { m_button.onClick.AddListener(() => {
master.OpenDialog(name); 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;
}
} }
} }

View File

@@ -14,7 +14,7 @@ namespace Cryville.Crtr.Event {
internal class MotionCachePool : CategorizedPool<Identifier, MotionCache> { internal class MotionCachePool : CategorizedPool<Identifier, MotionCache> {
private class Bucket : ObjectPool<MotionCache> { private class Bucket : ObjectPool<MotionCache> {
readonly MotionRegistry _reg; readonly MotionRegistry _reg;
public Bucket(string name, int capacity) : base(capacity) { public Bucket(Identifier name, int capacity) : base(capacity) {
_reg = ChartPlayer.motionRegistry[name]; _reg = ChartPlayer.motionRegistry[name];
} }
protected override MotionCache Construct() { protected override MotionCache Construct() {

View File

@@ -6,7 +6,7 @@ namespace Cryville.Crtr.Event {
internal class RMVPool : CategorizedPool<Identifier, RealtimeMotionValue> { internal class RMVPool : CategorizedPool<Identifier, RealtimeMotionValue> {
private class Bucket : ObjectPool<RealtimeMotionValue> { private class Bucket : ObjectPool<RealtimeMotionValue> {
readonly MotionRegistry _reg; readonly MotionRegistry _reg;
public Bucket(string name, int capacity) : base(capacity) { public Bucket(Identifier name, int capacity) : base(capacity) {
_reg = ChartPlayer.motionRegistry[name]; _reg = ChartPlayer.motionRegistry[name];
} }
protected override RealtimeMotionValue Construct() { protected override RealtimeMotionValue Construct() {

View File

@@ -104,16 +104,16 @@ namespace Cryville.Crtr {
} }
ChartPlayer.motionRegistry = new Dictionary<Identifier, MotionRegistry> { ChartPlayer.motionRegistry = new Dictionary<Identifier, MotionRegistry> {
{ "pt" , new MotionRegistry(typeof(VecPt)) }, { new Identifier("pt") , new MotionRegistry(typeof(VecPt)) },
{ "dir" , new MotionRegistry(typeof(Vec3)) }, { new Identifier("dir") , new MotionRegistry(typeof(Vec3)) },
{ "normal" , new MotionRegistry(typeof(Vec3)) }, { new Identifier("normal") , new MotionRegistry(typeof(Vec3)) },
{ "sv" , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, 1f)) }, { new Identifier("sv") , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, 1f)) },
{ "svm" , new MotionRegistry(new Vec1m(1f)) }, { new Identifier("svm") , new MotionRegistry(new Vec1m(1f)) },
{ "dist" , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, float.PositiveInfinity)) }, { new Identifier("dist") , new MotionRegistry(new VecPtComp(0f, 0f), new VecPtComp(0f, float.PositiveInfinity)) },
{ "corner" , new MotionRegistry(typeof(VecI1)) }, { new Identifier("corner") , new MotionRegistry(typeof(VecI1)) },
{ "ctrl0" , new MotionRegistry(typeof(VecCtrl)) }, { new Identifier("ctrl0") , new MotionRegistry(typeof(VecCtrl)) },
{ "ctrl1" , new MotionRegistry(typeof(VecCtrl)) }, { new Identifier("ctrl1") , new MotionRegistry(typeof(VecCtrl)) },
{ "track" , new MotionRegistry(typeof(Vec1)) }, { new Identifier("track") , new MotionRegistry(typeof(Vec1)) },
}; };
var dir = new DirectoryInfo(Settings.Default.GameDataPath + "/charts"); var dir = new DirectoryInfo(Settings.Default.GameDataPath + "/charts");

View File

@@ -23,7 +23,7 @@ namespace Cryville.Crtr {
_judge = judge; _judge = judge;
foreach (var i in ruleset.inputs) { foreach (var i in ruleset.inputs) {
_use.Add(i.Key, 0); _use.Add(i.Key, 0);
_rev.Add(i.Key, new List<string>()); _rev.Add(i.Key, new List<Identifier>());
} }
foreach (var i in ruleset.inputs) { foreach (var i in ruleset.inputs) {
if (i.Value.pass != null) { if (i.Value.pass != null) {
@@ -33,15 +33,15 @@ namespace Cryville.Crtr {
} }
} }
#region Settings #region Settings
readonly Dictionary<string, InputProxyEntry> _tproxies = new Dictionary<string, InputProxyEntry>(); readonly Dictionary<Identifier, InputProxyEntry> _tproxies = new Dictionary<Identifier, InputProxyEntry>();
readonly Dictionary<InputSource, InputProxyEntry> _sproxies = new Dictionary<InputSource, InputProxyEntry>(); readonly Dictionary<InputSource, InputProxyEntry> _sproxies = new Dictionary<InputSource, InputProxyEntry>();
readonly Dictionary<string, int> _use = new Dictionary<string, int>(); readonly Dictionary<Identifier, int> _use = new Dictionary<Identifier, int>();
readonly Dictionary<string, List<string>> _rev = new Dictionary<string, List<string>>(); readonly Dictionary<Identifier, List<Identifier>> _rev = new Dictionary<Identifier, List<Identifier>>();
public event EventHandler<ProxyChangedEventArgs> ProxyChanged; public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
public void LoadFrom(Dictionary<string, RulesetConfig.InputEntry> config) { public void LoadFrom(Dictionary<string, RulesetConfig.InputEntry> config) {
foreach (var cfg in config) { foreach (var cfg in config) {
Set(new InputProxyEntry { Set(new InputProxyEntry {
Target = cfg.Key, Target = new Identifier(cfg.Key),
Source = new InputSource { Source = new InputSource {
Handler = Game.InputManager.GetHandler(cfg.Value.handler), Handler = Game.InputManager.GetHandler(cfg.Value.handler),
Type = cfg.Value.type Type = cfg.Value.type
@@ -52,7 +52,7 @@ namespace Cryville.Crtr {
public void SaveTo(Dictionary<string, RulesetConfig.InputEntry> config) { public void SaveTo(Dictionary<string, RulesetConfig.InputEntry> config) {
config.Clear(); config.Clear();
foreach (var p in _tproxies) { 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()), handler = ReflectionHelper.GetNamespaceQualifiedName(p.Value.Source.Value.Handler.GetType()),
type = p.Value.Source.Value.Type type = p.Value.Source.Value.Type
}); });
@@ -88,7 +88,7 @@ namespace Cryville.Crtr {
return true; return true;
} }
} }
void IncrementUseRecursive(string name) { void IncrementUseRecursive(Identifier name) {
BroadcastProxyChanged(name); BroadcastProxyChanged(name);
var passes = _ruleset.inputs[name].pass; var passes = _ruleset.inputs[name].pass;
if (passes != null) { if (passes != null) {
@@ -98,14 +98,14 @@ namespace Cryville.Crtr {
} }
} }
} }
void IncrementReversedUseRecursive(string name) { void IncrementReversedUseRecursive(Identifier name) {
foreach (var p in _rev[name]) { foreach (var p in _rev[name]) {
_use[p]++; _use[p]++;
BroadcastProxyChanged(p); BroadcastProxyChanged(p);
IncrementReversedUseRecursive(p); IncrementReversedUseRecursive(p);
} }
} }
void DecrementUseRecursive(string name) { void DecrementUseRecursive(Identifier name) {
BroadcastProxyChanged(name); BroadcastProxyChanged(name);
var passes = _ruleset.inputs[name].pass; var passes = _ruleset.inputs[name].pass;
if (passes != null) { if (passes != null) {
@@ -115,18 +115,18 @@ namespace Cryville.Crtr {
} }
} }
} }
void DecrementReversedUseRecursive(string name) { void DecrementReversedUseRecursive(Identifier name) {
foreach (var p in _rev[name]) { foreach (var p in _rev[name]) {
_use[p]--; _use[p]--;
BroadcastProxyChanged(p); BroadcastProxyChanged(p);
DecrementReversedUseRecursive(p); DecrementReversedUseRecursive(p);
} }
} }
void BroadcastProxyChanged(string name) { void BroadcastProxyChanged(Identifier name) {
var del = ProxyChanged; var del = ProxyChanged;
if (del != null) del(this, this[name]); if (del != null) del(this, this[name]);
} }
public ProxyChangedEventArgs this[string name] { public ProxyChangedEventArgs this[Identifier name] {
get { get {
return new ProxyChangedEventArgs(name, _tproxies.ContainsKey(name) ? _tproxies[name].Source : null, _use[name] > 0); 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 class ProxyChangedEventArgs : EventArgs {
public string Name { get; private set; } public Identifier Name { get; private set; }
public InputSource? Proxy { get; private set; } public InputSource? Proxy { get; private set; }
public bool Used { 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; Name = name;
Proxy = src; Proxy = src;
Used = used; Used = used;
@@ -275,7 +275,7 @@ namespace Cryville.Crtr {
public class InputProxyEntry { public class InputProxyEntry {
public InputSource? Source { get; set; } public InputSource? Source { get; set; }
public string Target { get; set; } public Identifier Target { get; set; }
public byte[] Mapping { get; private set; } public byte[] Mapping { get; private set; }
} }

View File

@@ -49,7 +49,7 @@ namespace Cryville.Crtr {
else if (value is string) { else if (value is string) {
var exp = (string)value; var exp = (string)value;
if (type.Equals(typeof(Identifier))) { if (type.Equals(typeof(Identifier))) {
return (Identifier)exp; return new Identifier(exp);
} }
else if (type == typeof(ScoreOperation)) { else if (type == typeof(ScoreOperation)) {
var m = Regex.Match(exp, @"^(\S+)\s*?(\S+)?$"); var m = Regex.Match(exp, @"^(\S+)\s*?(\S+)?$");