public void RebuildTree() { root.next.Clear(); foreach (var map in maps) { if (map.chords.Length == 0) { continue; } var node = root; foreach (var binding in map.chords) { KeyMapTreeNode next; if (node.TryGet(binding, out next)) { node = next; continue; } next = new KeyMapTreeNode { keyChord = binding }; node.next.Add(next); node = next; } node.map = map; } }
// ReSharper disable once UnusedMember.Global public void Debug(KeyMapTreeNode node, int indent = 0) { var indentStr = new string(' ', indent); SuperController.LogMessage($"{indentStr}- {node}"); foreach (var child in node.next) { Debug(child, indent + 2); } }
private static KeyMapTreeNode DoMatch(KeyMapTreeNode node) { for (var i = 0; i < node.next.Count; i++) { var child = node.next[i]; if (child.keyChord.IsDown()) { return(child); } } return(null); }
public void OnKeyDown() { CheckReleasers(); if (!Input.anyKeyDown) { return; } if (_timeoutCoroutine != null) { _owner.StopCoroutine(_timeoutCoroutine); } if (LookInputModule.singleton.inputFieldActive) { return; } var current = _current; _current = null; var match = current != null?DoMatch(current) : null; if (match == null) { match = DoMatch(_keyMapManager.root); if (match == null) { return; } } if (_settings.showKeyPressesJSON.val) { _overlay.value.Append(match.keyChord.ToString()); } if (match.next.Count == 0) { if (match.map != null) { Invoke(match.map); } return; } _current = match; _timeoutCoroutine = _owner.StartCoroutine(TimeoutCoroutine()); }
public bool TryGet(KeyChord source, out KeyMapTreeNode result) { for (var i = 0; i < next.Count; i++) { if (!next[i].keyChord.Equals(source)) { continue; } result = next[i]; return(true); } result = null; return(false); }
private IEnumerator TimeoutCoroutine() { yield return(new WaitForSecondsRealtime(Settings.TimeoutLen)); if (_current == null) { yield break; } try { if (_current.map != null) { Invoke(_current.map); _current = _keyMapManager.root; } _timeoutCoroutine = null; } catch (Exception e) { SuperController.LogError($"{nameof(Keybindings)}.{nameof(TimeoutCoroutine)}: {e}"); } }