Skip to content

Commit

Permalink
feat(Studio): Sort TAS-commands depending on relevancy
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Sep 25, 2024
1 parent c7f6464 commit daaee6a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 209 deletions.
6 changes: 3 additions & 3 deletions CelesteTAS-EverestInterop/TAS/LibTasHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ private static string LibTasButtons(InputFrame inputFrame) {
return string.Join("", buttons);
}

// StartExportLibTAS (Optional Path)
[TasCommand("StartExportLibTAS", Aliases = ["ExportLibTAS"], ExecuteTiming = ExecuteTiming.Parse)]
// ExportLibTAS (Optional Path)
[TasCommand("ExportLibTAS", Aliases = ["StartExportLibTAS"], ExecuteTiming = ExecuteTiming.Parse)]
private static void StartExportLibTasCommand(CommandLine commandLine, int studioLine, string filePath, int fileLine) {
string[] args = commandLine.Arguments;
string path = "Celeste.ltm";
Expand All @@ -247,7 +247,7 @@ private static void StartExportLibTasCommand(CommandLine commandLine, int studio
StartExport(path);
}

[TasCommand("FinishExportLibTAS", Aliases = new[] {"EndExportLibTAS"}, ExecuteTiming = ExecuteTiming.Parse)]
[TasCommand("EndExportLibTAS", Aliases = new[] {"FinishExportLibTAS"}, ExecuteTiming = ExecuteTiming.Parse)]
private static void FinishExportLibTasCommand(CommandLine commandLine, int studioLine, string filePath, int fileLine) {
FinishExport();
}
Expand Down
5 changes: 2 additions & 3 deletions Studio/CelesteStudio/Communication/CommunicationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ private static void OnCommandsChanged(CommandInfo[] newCommands) {
autoCompleteEntryCache.Clear();

commands = newCommands;
for (var i = 0; i < newCommands.Length; i++)
{
Console.WriteLine($"TAS COMMAND {newCommands[i].Name}");
foreach (var command in newCommands) {
Console.WriteLine($"TAS command: '{command.Name}'");
}
Application.Instance.AsyncInvoke(() => CommandsChanged?.Invoke(newCommands));
}
Expand Down
181 changes: 0 additions & 181 deletions Studio/CelesteStudio/Data/LegacyCommandInfo.cs

This file was deleted.

66 changes: 46 additions & 20 deletions Studio/CelesteStudio/Editing/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,12 @@ public Editor(Document document, Scrollable scrollable) {

Focus();

CommunicationWrapper.CommandsChanged += _ => {
GenerateBaseAutoCompleteEntries();
Recalc();
};
// Update command separator
Settings.Changed += () => {
GenerateBaseAutoCompleteEntries();
Recalc();
};

highlighter = new(FontManager.EditorFontRegular, FontManager.EditorFontBold, FontManager.EditorFontItalic, FontManager.EditorFontBoldItalic);
Settings.FontChanged += () => {
highlighter = new(FontManager.EditorFontRegular, FontManager.EditorFontBold, FontManager.EditorFontItalic, FontManager.EditorFontBoldItalic);
Recalc();
};

GenerateBaseAutoCompleteEntries();

BackgroundColor = Settings.Instance.Theme.Background;
Settings.ThemeChanged += () => BackgroundColor = Settings.Instance.Theme.Background;

Expand Down Expand Up @@ -308,18 +296,44 @@ public Editor(Document document, Scrollable scrollable) {
});
};

// Commands
var commandsMenu = new SubMenuItem { Text = "Insert Other Command" };

CommunicationWrapper.CommandsChanged += _ => {
GenerateBaseAutoCompleteEntries();
GenerateCommandMenu();
Recalc();
};
// Update command separator
Settings.Changed += () => {
GenerateBaseAutoCompleteEntries();
GenerateCommandMenu();
Recalc();
};

GenerateBaseAutoCompleteEntries();
GenerateCommandMenu();
Settings.Changed += GenerateCommandMenu;

void GenerateCommandMenu() {
commandsMenu.Items.Clear();
foreach (var command in LegacyCommandInfo.AllCommands) {
if (command == null) {

foreach (string? commandName in CommandInfo.CommandOrder) {
if (commandName == null) {
commandsMenu.Items.Add(new SeparatorMenuItem());
} else {
commandsMenu.Items.Add(CreateCommandInsert(command.Value));
} else if (CommunicationWrapper.Commands.FirstOrDefault(cmd => cmd.Name == commandName) is var command) {
commandsMenu.Items.Add(CreateCommandInsert(command));
}
}

// 3rd party commands (i.e. added through the API by another mod)
var thirdPartyCommands = CommunicationWrapper.Commands
.Where(command => !CommandInfo.CommandOrder.Contains(command.Name) && !CommandInfo.HiddenCommands.Contains(command.Name))
.ToArray();

if (thirdPartyCommands.Any()) {
commandsMenu.Items.Add(new SeparatorMenuItem());
foreach (var command in thirdPartyCommands) {
commandsMenu.Items.Add(CreateCommandInsert(command));
}
}
}
Expand Down Expand Up @@ -379,15 +393,15 @@ void GenerateCommandMenu() {
}
};

MenuItem CreateCommandInsert(LegacyCommandInfo info) {
MenuItem CreateCommandInsert(CommandInfo info) {
var cmd = new Command { Shortcut = Keys.None };
cmd.Executed += (_, _) => {
InsertQuickEdit(info.Insert);
Recalc();
ScrollCaretIntoView();
};

return new ButtonMenuItem(cmd) { Text = info.Name, ToolTip = info.Description };
return new ButtonMenuItem(cmd) { Text = info.Name };
}
}

Expand Down Expand Up @@ -1236,15 +1250,27 @@ private void CloseContextActionsPopup() {
private void GenerateBaseAutoCompleteEntries() {
baseAutoCompleteEntries.Clear();

// Snippets
foreach (var snippet in Settings.Instance.Snippets) {
if (!string.IsNullOrWhiteSpace(snippet.Shortcut) && snippet.Enabled &&
CreateEntry(snippet.Shortcut, snippet.Insert, "Snippet", hasArguments: false) is { } entry)
{
baseAutoCompleteEntries.Add(entry);
}
}

// Commands
foreach (string? commandName in CommandInfo.CommandOrder) {
if (commandName != null && CommunicationWrapper.Commands.FirstOrDefault(cmd => cmd.Name == commandName) is var command && !string.IsNullOrEmpty(command.Name) &&
CreateEntry(command.Name, command.Insert.Replace(CommandInfo.Separator, Settings.Instance.CommandSeparatorText), "Command", command.HasArguments) is { } entry)
{
baseAutoCompleteEntries.Add(entry);
}
}
foreach (var command in CommunicationWrapper.Commands) {
if (CreateEntry(command.Name, command.Insert.Replace(CommandInfo.Separator, Settings.Instance.CommandSeparatorText), "Command", command.HasArguments) is { } entry) {
if (!CommandInfo.CommandOrder.Contains(command.Name) && !CommandInfo.HiddenCommands.Contains(command.Name) &&
CreateEntry(command.Name, command.Insert.Replace(CommandInfo.Separator, Settings.Instance.CommandSeparatorText), "Command", command.HasArguments) is { } entry)
{
baseAutoCompleteEntries.Add(entry);
}
}
Expand Down
2 changes: 0 additions & 2 deletions Studio/CelesteStudio/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ public void RecalculateLayout() {
private void ApplySettings() {
Topmost = Settings.Instance.AlwaysOnTop;
Menu = CreateMenu(); // Recreate menu to reflect changes

LegacyCommandInfo.GenerateCommandInfos(Settings.Instance.CommandSeparatorText);
}

protected override void OnDragDrop(DragEventArgs e) {
Expand Down
Loading

0 comments on commit daaee6a

Please sign in to comment.