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 "";
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);
}
}
}

View File

@@ -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<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
string _sel;
public void OpenDialog(string entry) {
Identifier _sel;
public void OpenDialog(Identifier entry) {
_sel = entry;
m_inputDialog.SetActive(true);
CallHelper.Purge(m_deviceList);

View File

@@ -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;
}
}
}

View File

@@ -14,7 +14,7 @@ namespace Cryville.Crtr.Event {
internal class MotionCachePool : CategorizedPool<Identifier, MotionCache> {
private class Bucket : ObjectPool<MotionCache> {
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() {

View File

@@ -6,7 +6,7 @@ namespace Cryville.Crtr.Event {
internal class RMVPool : CategorizedPool<Identifier, RealtimeMotionValue> {
private class Bucket : ObjectPool<RealtimeMotionValue> {
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() {

View File

@@ -104,16 +104,16 @@ namespace Cryville.Crtr {
}
ChartPlayer.motionRegistry = new Dictionary<Identifier, MotionRegistry> {
{ "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");

View File

@@ -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<string>());
_rev.Add(i.Key, new List<Identifier>());
}
foreach (var i in ruleset.inputs) {
if (i.Value.pass != null) {
@@ -33,15 +33,15 @@ namespace Cryville.Crtr {
}
}
#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<string, int> _use = new Dictionary<string, int>();
readonly Dictionary<string, List<string>> _rev = new Dictionary<string, List<string>>();
readonly Dictionary<Identifier, int> _use = new Dictionary<Identifier, int>();
readonly Dictionary<Identifier, List<Identifier>> _rev = new Dictionary<Identifier, List<Identifier>>();
public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
public void LoadFrom(Dictionary<string, RulesetConfig.InputEntry> 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<string, RulesetConfig.InputEntry> 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; }
}

View File

@@ -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+)?$");