Code cleanup.
This commit is contained in:
@@ -5,7 +5,6 @@ using Cryville.Crtr.Config;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class InputProxy : IDisposable {
|
||||
@@ -59,28 +58,29 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
public void Set(InputProxyEntry proxy) {
|
||||
var name = proxy.Target;
|
||||
if (!_ruleset.inputs.ContainsKey(name)) throw new ArgumentException("Invalid input name");
|
||||
if (_use[proxy.Target] > 0)
|
||||
var target = proxy.Target;
|
||||
if (!_ruleset.inputs.ContainsKey(target)) throw new ArgumentException("Invalid input name");
|
||||
if (_tproxies.ContainsKey(target)) Remove(proxy);
|
||||
if (_use[target] > 0)
|
||||
throw new InvalidOperationException("Input already assigned");
|
||||
if (proxy.Source != null) {
|
||||
if (_judge != null) {
|
||||
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
||||
proxy.Source.Value.Handler.OnInput += OnInput;
|
||||
}
|
||||
_tproxies.Add(proxy.Target, proxy);
|
||||
_tproxies.Add(target, proxy);
|
||||
_sproxies.Add(proxy.Source.Value, proxy);
|
||||
IncrementUseRecursive(name);
|
||||
IncrementReversedUseRecursive(name);
|
||||
IncrementUseRecursive(target);
|
||||
IncrementReversedUseRecursive(target);
|
||||
}
|
||||
}
|
||||
void Remove(InputProxyEntry proxy) {
|
||||
var name = proxy.Target;
|
||||
if (_judge != null) _tproxies[name].Source.Value.Handler.OnInput -= OnInput;
|
||||
_sproxies.Remove(_tproxies[name].Source.Value);
|
||||
_tproxies.Remove(name);
|
||||
DecrementUseRecursive(name);
|
||||
DecrementReversedUseRecursive(name);
|
||||
var target = proxy.Target;
|
||||
if (_judge != null) _tproxies[target].Source.Value.Handler.OnInput -= OnInput;
|
||||
_sproxies.Remove(_tproxies[target].Source.Value);
|
||||
_tproxies.Remove(target);
|
||||
DecrementUseRecursive(target);
|
||||
DecrementReversedUseRecursive(target);
|
||||
}
|
||||
public bool IsUsed(InputSource src) {
|
||||
return _sproxies.ContainsKey(src);
|
||||
|
Reference in New Issue
Block a user