Editor/Tool/ArchKeys.cs
using System.Collections.Generic;
using Editor;
namespace Sunless.Architecture;
// A viewport shortcut, edge triggered, read in ONE place. Two guards, both learned the hard way: the pointer
// has to be over the viewport, and the keyboard must not be in a text field - otherwise every R typed into a
// building's name spins the building behind the sheet. Edge triggered because a held key is one press, and
// each key is read once a frame, so the reader asks and the answer is spent.
public static class ArchKeys {
static readonly HashSet<KeyCode> held = new();
public static bool Pressed( ArchTool tool, KeyCode key ) {
var down = Down( tool, key );
var edge = down && held.Add( key );
if ( !down ) {
held.Remove( key );
}
return edge;
}
static bool Down( ArchTool tool, KeyCode key ) {
return tool?.Manager?.IsCurrentViewFocused == true
&& global::Editor.Application.FocusWidget is not (LineEdit or TextEdit)
&& global::Editor.Application.IsKeyDown( key );
}
}