Implement input config loading and saving.
This commit is contained in:
@@ -168,5 +168,19 @@ namespace Cryville.Common {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the namespace qualified name of a type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The type.</param>
|
||||||
|
/// <returns>The namespace qualified name of the class.</returns>
|
||||||
|
public static string GetNamespaceQualifiedName(Type type) {
|
||||||
|
string result = type.Namespace + "." + type.Name;
|
||||||
|
var typeargs = type.GetGenericArguments();
|
||||||
|
if (typeargs.Length > 0) {
|
||||||
|
result = string.Format("{0}[{1}]", result, string.Join(",", from a in typeargs select GetNamespaceQualifiedName(a)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
};
|
};
|
||||||
// TODO set private
|
// TODO set private
|
||||||
public readonly List<InputHandler> _handlers = new List<InputHandler>();
|
public readonly List<InputHandler> _handlers = new List<InputHandler>();
|
||||||
|
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
||||||
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
||||||
readonly object _lock = new object();
|
readonly object _lock = new object();
|
||||||
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
||||||
@@ -22,6 +23,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
try {
|
try {
|
||||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||||
|
_typemap.Add(t, h);
|
||||||
h.OnInput += OnInput;
|
h.OnInput += OnInput;
|
||||||
_handlers.Add(h);
|
_handlers.Add(h);
|
||||||
_timeOrigins.Add(h, 0);
|
_timeOrigins.Add(h, 0);
|
||||||
@@ -32,6 +34,9 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public InputHandler GetHandler(string name) {
|
||||||
|
return _typemap[Type.GetType(name)];
|
||||||
|
}
|
||||||
public void Activate() {
|
public void Activate() {
|
||||||
lock (_lock) {
|
lock (_lock) {
|
||||||
_events.Clear();
|
_events.Clear();
|
||||||
|
@@ -487,6 +487,11 @@ namespace Cryville.Crtr {
|
|||||||
etor.ContextJudge = judge;
|
etor.ContextJudge = judge;
|
||||||
|
|
||||||
inputProxy = new InputProxy(pruleset, judge);
|
inputProxy = new InputProxy(pruleset, judge);
|
||||||
|
inputProxy.LoadFrom(_rscfg.inputs);
|
||||||
|
if (!inputProxy.IsCompleted) {
|
||||||
|
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||||
|
}
|
||||||
|
|
||||||
cbus.AttachSystems(pskin, judge);
|
cbus.AttachSystems(pskin, judge);
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
|
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
|
||||||
var ch = new ChartHandler(chart, dir);
|
var ch = new ChartHandler(chart, dir);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Common.Unity.Input;
|
using Cryville.Common.Unity.Input;
|
||||||
|
using Cryville.Crtr.Config;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -37,9 +38,29 @@ namespace Cryville.Crtr {
|
|||||||
readonly Dictionary<string, int> _use = new Dictionary<string, int>();
|
readonly Dictionary<string, int> _use = new Dictionary<string, int>();
|
||||||
readonly Dictionary<string, List<string>> _rev = new Dictionary<string, List<string>>();
|
readonly Dictionary<string, List<string>> _rev = new Dictionary<string, List<string>>();
|
||||||
public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
|
public event EventHandler<ProxyChangedEventArgs> ProxyChanged;
|
||||||
|
public void LoadFrom(Dictionary<string, InputConfigEntry> config) {
|
||||||
|
foreach (var cfg in config) {
|
||||||
|
Set(new InputProxyEntry {
|
||||||
|
Target = cfg.Key,
|
||||||
|
Source = new InputSource {
|
||||||
|
Handler = Game.InputManager.GetHandler(cfg.Value.handler),
|
||||||
|
Type = cfg.Value.type
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SaveTo(Dictionary<string, InputConfigEntry> config) {
|
||||||
|
config.Clear();
|
||||||
|
foreach (var p in _tproxies) {
|
||||||
|
config.Add(p.Key, new InputConfigEntry {
|
||||||
|
handler = ReflectionHelper.GetNamespaceQualifiedName(p.Value.Source.Value.Handler.GetType()),
|
||||||
|
type = p.Value.Source.Value.Type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
public void Set(InputProxyEntry proxy) {
|
public void Set(InputProxyEntry proxy) {
|
||||||
var name = proxy.Target;
|
var name = proxy.Target;
|
||||||
if (_tproxies.ContainsKey(name)) Remove(proxy);
|
if (!_ruleset.inputs.ContainsKey(name)) throw new ArgumentException("Invalid input name");
|
||||||
if (_use[proxy.Target] > 0)
|
if (_use[proxy.Target] > 0)
|
||||||
throw new InvalidOperationException("Input already assigned");
|
throw new InvalidOperationException("Input already assigned");
|
||||||
if (proxy.Source != null) {
|
if (proxy.Source != null) {
|
||||||
@@ -64,6 +85,13 @@ namespace Cryville.Crtr {
|
|||||||
public bool IsUsed(InputSource src) {
|
public bool IsUsed(InputSource src) {
|
||||||
return _sproxies.ContainsKey(src);
|
return _sproxies.ContainsKey(src);
|
||||||
}
|
}
|
||||||
|
public bool IsCompleted {
|
||||||
|
get {
|
||||||
|
foreach (var i in _use)
|
||||||
|
if (i.Value == 0 && !_tproxies.ContainsKey(i.Key)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
void IncrementUseRecursive(string name) {
|
void IncrementUseRecursive(string name) {
|
||||||
BroadcastProxyChanged(name);
|
BroadcastProxyChanged(name);
|
||||||
var passes = _ruleset.inputs[name].pass;
|
var passes = _ruleset.inputs[name].pass;
|
||||||
@@ -100,7 +128,12 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
void BroadcastProxyChanged(string name) {
|
void BroadcastProxyChanged(string name) {
|
||||||
var del = ProxyChanged;
|
var del = ProxyChanged;
|
||||||
if (del != null) del(this, new ProxyChangedEventArgs(name, _tproxies.ContainsKey(name) ? _tproxies[name].Source : null, _use[name] > 0));
|
if (del != null) del(this, this[name]);
|
||||||
|
}
|
||||||
|
public ProxyChangedEventArgs this[string name] {
|
||||||
|
get {
|
||||||
|
return new ProxyChangedEventArgs(name, _tproxies.ContainsKey(name) ? _tproxies[name].Source : null, _use[name] > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user