Skip to content

Commit

Permalink
Merge branch 'EverestAPI:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
LozenChen authored Jan 24, 2025
2 parents f1ee4fd + b549648 commit 1dbb9e7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ public IEnumerator<CommandAutoCompleteEntry> GetAutoCompleteEntries(string[] arg
}
}

/// Next available save-file slot
private static int EmptyFileSlot {
private static int MaxSaveFileSlots {
get {
if (LibTasHelper.Exporting) {
return -1;
}

// Taken from Everest
int maxSaveFile;
if (CoreModule.Settings.MaxSaveSlots != null) {
Expand All @@ -61,9 +56,21 @@ private static int EmptyFileSlot {
maxSaveFile += 2;
}

return maxSaveFile;
}
}

/// Next available save-file slot
private static int EmptyFileSlot {
get {
if (LibTasHelper.Exporting) {
return -1;
}

bool hasSlots = false;
int firstEmpty = int.MaxValue;

int maxSaveFile = MaxSaveFileSlots;
for (int slot = 0; slot < maxSaveFile; slot++) {
if (!UserIO.Exists(SaveData.GetFilename(slot))) {
firstEmpty = Math.Min(slot, firstEmpty);
Expand Down Expand Up @@ -147,22 +154,30 @@ public static void SelectCampaign(CommandLine commandLine, int studioLine, strin
controller.ReadLine("Assert,Equal,True,[[local ui = scene.Current; return ui ~= nil and ui.SlotSelected and not ui.Slots[ui.SlotIndex].Exists and getValue(ui.Slots[ui.SlotIndex], \"buttonIndex\") == 0]]", filePath, fileLine, studioLine);

controller.AddFrames("1,D", studioLine);
InputName(controller, saveFileName, studioLine);
InputName(controller, slot, saveFileName, studioLine);

SelectCampaign(controller, campaignName, studioLine);

// Runtime-assert for even more additional safety
controller.ReadLine("Assert,Equal,True,[[local ui = scene.Current; return ui ~= nil and ui.SlotSelected and not ui.Slots[ui.SlotIndex].Exists and getValue(ui.Slots[ui.SlotIndex], \"buttonIndex\") == 0]]", filePath, fileLine, studioLine);
}

private static void InputName(InputController controller, string saveFileName, int studioLine) {
private static void InputName(InputController controller, int slot, string saveFileName, int studioLine) {
if (Settings.Instance.Language == "japanese") {
AbortTas("Japanese language is currently not supported for inputting a file name");
return;
}

controller.AddFrames("1,O", studioLine);
controller.AddFrames("41", studioLine);

int maxSaveFile = MaxSaveFileSlots;
for (int i = 0; i < maxSaveFile; i++) {
if (Math.Abs(slot - i) <= 2) {
// Each visible slots causes a delay of 3f
controller.AddFrames("3", studioLine);
}
}
controller.AddFrames("32", studioLine);

// Prepare available letters
string[] letters = Dialog.Clean("name_letters")
Expand Down Expand Up @@ -223,7 +238,6 @@ private static void InputName(InputController controller, string saveFileName, i

// Search for optimal path
var end = (X: targetIndex, Y: targetLine);
Console.WriteLine($" == '{targetChar}' ({end}) ==");

var queue = new Queue<(int X, int Y)>();
var visited = new HashSet<(int X, int Y)>();
Expand Down Expand Up @@ -285,7 +299,6 @@ private static void InputName(InputController controller, string saveFileName, i

while (currentCell != start) {
var prevCell = parent[currentCell];
Console.WriteLine($"- {currentCell} <- {prevCell}");

// Manually handle horizontal wrapping
if (prevCell.X == 0 && currentCell.X == letters[currentCell.Y].Length - 1) {
Expand Down Expand Up @@ -313,8 +326,6 @@ private static void InputName(InputController controller, string saveFileName, i

// Write inputs
foreach ((int moveX, int moveY) in path) {
Console.WriteLine($"* {moveX},{moveY}");

if (moveX > 0) {
controller.AddFrames(controller.Inputs.Count % 2 == 0 ? "1,R" : "1,F,90", studioLine);
} else if (moveX < 0) {
Expand Down
39 changes: 39 additions & 0 deletions CelesteTAS-EverestInterop/Source/TAS/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using JetBrains.Annotations;
using Monocle;
using StudioCommunication;
using System.Runtime.InteropServices.ComTypes;
using TAS.Communication;
using TAS.EverestInterop;
using TAS.Input;
Expand Down Expand Up @@ -313,4 +314,42 @@ internal static void SendStudioState() {

CommunicationWrapper.SendState(state);
}

[Monocle.Command("dump_tas", "Dumps the parsed TAS file into the console (CelesteTAS)"), UsedImplicitly]
private static void CmdDumpTas() {
// Pretend to start a TAS. so that AbortTas detection works
NextState = State.Running;
Controller.RefreshInputs(forceRefresh: true);
if (NextState == State.Disabled) {
"TAS contains errors. Cannot dump to console".ConsoleLog(LogLevel.Error);
return;
}
NextState = State.Disabled;

$"TAS file dump for '{Controller.FilePath}':".Log();

var writer = Console.Out;
for (int i = 0; i < Controller.Inputs.Count;) {
foreach (var comment in Controller.Comments!.GetValueOrDefault(i) ?? []) {
writer.WriteLine($"#{comment.Text}");
}
foreach (var command in Controller.Commands!.GetValueOrDefault(i) ?? []) {
if (command.Attribute.ExecuteTiming == ExecuteTiming.Parse) {
// Comment-out parse-only commands
writer.WriteLine($"# {command.CommandLine.ToString()}");
} else {
writer.WriteLine(command.CommandLine.ToString());
}
}
if (Controller.FastForwards.TryGetValue(i, out var fastForward)) {
writer.WriteLine(fastForward.ToString());
}

writer.WriteLine(Controller.Inputs[i]);
i += Controller.Inputs[i].Frames;
}
writer.Flush();

"Successfully dumped TAS file to console".ConsoleLog();
}
}

0 comments on commit 1dbb9e7

Please sign in to comment.