Skip to content

Commit

Permalink
feat(Studio): Allow disabling input sending while running a TAS
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Nov 29, 2024
1 parent c9b6740 commit bbdee23
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
41 changes: 24 additions & 17 deletions Studio/CelesteStudio/Editing/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,30 @@ protected override void OnKeyDown(KeyEventArgs e) {
if (e.Key is Keys.LeftApplication or Keys.RightApplication) mods |= Keys.Application;
UpdateMouseCursor(PointFromScreen(Mouse.Position), mods);

string lineTrimmed = Document.Lines[Document.Caret.Row].TrimStart();

// Send inputs to Celeste if applicable
bool isActionLine = lineTrimmed.StartsWith("***") ||
ActionLine.TryParse(Document.Lines[Document.Caret.Row], out _ );
bool isComment = lineTrimmed.StartsWith('#');
bool isTyping = (DateTime.UtcNow - lastModification).TotalSeconds < Settings.Instance.SendInputsTypingTimeout;
bool isRunning = CommunicationWrapper.Connected && CommunicationWrapper.TasStates.HasFlag(States.Enable) && !CommunicationWrapper.TasStates.HasFlag(States.FrameStep);
bool sendInputs =
(Settings.Instance.SendInputsOnActionLines && isActionLine) ||
(Settings.Instance.SendInputsOnComments && isComment) ||
(Settings.Instance.SendInputsOnCommands && !isActionLine && !isComment);

if (Settings.Instance.SendInputsToCeleste && CommunicationWrapper.Connected && !isTyping && sendInputs && CommunicationWrapper.SendKeyEvent(e.Key, e.Modifiers, released: false)) {
e.Handled = true;
return;
}

// Prevent editing file on accident
if (Settings.Instance.SendInputsToCeleste && CommunicationWrapper.Connected && isRunning && Settings.Instance.SendInputsDisableWhileRunning) {
e.Handled = true;
return;
}

// While there are quick-edits available, Tab will cycle through them
// Using tab doesn't feel "right" for the context actions menu
if (ActivePopupMenu?.HandleKeyDown(e, useTabComplete: ActivePopupMenu == autoCompleteMenu && !GetQuickEdits().Any()) ?? false) {
Expand Down Expand Up @@ -1245,23 +1269,6 @@ protected override void OnKeyDown(KeyEventArgs e) {
}
}

string lineTrimmed = Document.Lines[Document.Caret.Row].TrimStart();

// Send inputs to Celeste if applicable
bool isActionLine = lineTrimmed.StartsWith("***") ||
ActionLine.TryParse(Document.Lines[Document.Caret.Row], out _ );
bool isComment = lineTrimmed.StartsWith('#');
bool isTyping = (DateTime.UtcNow - lastModification).TotalSeconds < Settings.Instance.SendInputsTypingTimeout;
bool sendInputs =
(Settings.Instance.SendInputsOnActionLines && isActionLine) ||
(Settings.Instance.SendInputsOnComments && isComment) ||
(Settings.Instance.SendInputsOnCommands && !isActionLine && !isComment);

if (Settings.Instance.SendInputsToCeleste && CommunicationWrapper.Connected && !isTyping && sendInputs && CommunicationWrapper.SendKeyEvent(e.Key, e.Modifiers, released: false)) {
e.Handled = true;
return;
}

if (calculationState != null) {
CalculationHandleKey(e);
Invalidate();
Expand Down
1 change: 1 addition & 0 deletions Studio/CelesteStudio/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public string ThemeName {
public bool SendInputsOnActionLines { get; set; } = true;
public bool SendInputsOnCommands { get; set; } = true;
public bool SendInputsOnComments { get; set; } = false;
public bool SendInputsDisableWhileRunning { get; set; } = true;
public bool SendInputsNonWritable { get; set; } = true;
public float SendInputsTypingTimeout { get; set; } = 0.3f;

Expand Down
1 change: 1 addition & 0 deletions Studio/CelesteStudio/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ private MenuBar CreateMenu() {
MenuUtils.CreateSettingToggle("On Inputs", nameof(Settings.SendInputsOnActionLines)),
MenuUtils.CreateSettingToggle("On Comments", nameof(Settings.SendInputsOnComments)),
MenuUtils.CreateSettingToggle("On Commands", nameof(Settings.SendInputsOnCommands)),
MenuUtils.CreateSettingToggle("Disable while Running", nameof(Settings.SendInputsDisableWhileRunning)),
}};
if (!Platform.IsWpf) {
inputSendingMenu.Items.Add(MenuUtils.CreateSettingToggle("Always send non-writable Inputs", nameof(Settings.SendInputsNonWritable)));
Expand Down

0 comments on commit bbdee23

Please sign in to comment.