Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fill in wakeup frames if possible when creating a new file #85

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ protected override void HandleMessage(MessageID messageId, BinaryReader reader)

gameData = meta.GetHash(commandArgs, filePath, fileLine);
break;
case GameDataType.LevelInfo:
gameData = new LevelInfo {
ModUrl = GameData.GetModUrl(),
WakeupTime = GameData.GetWakeupTime(),
};
break;

default:
gameData = null;
Expand Down Expand Up @@ -163,6 +169,10 @@ protected override void HandleMessage(MessageID messageId, BinaryReader reader)
case GameDataType.CommandHash:
writer.Write((int)gameData!);
break;

case GameDataType.LevelInfo:
writer.WriteObject((LevelInfo)gameData!);
break;
}
LogVerbose($"Sent message GameDataResponse: {gameDataType} = '{gameData}'");
});
Expand Down
28 changes: 28 additions & 0 deletions CelesteTAS-EverestInterop/Source/Communication/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,34 @@ public static string GetModUrl() {
return string.Empty;
}

public static int? GetWakeupTime() {
if (Engine.Scene is not Level level) {
return null;
}

AreaData areaData = AreaData.Get(level);

int? wakeupTime = areaData.IntroType switch {
// Player.IntroTypes.Transition => expr,
Player.IntroTypes.Respawn => 36,
// Player.IntroTypes.WalkInRight => expr,
// Player.IntroTypes.WalkInLeft => expr,
// Player.IntroTypes.Jump => expr,
Player.IntroTypes.WakeUp => 190,
// Player.IntroTypes.Fall => expr,
// Player.IntroTypes.TempleMirrorVoid => expr,
Player.IntroTypes.None => null,
// Player.IntroTypes.ThinkForABit => expr,
_ => null,
};

if (wakeupTime == null) {
$"Couldn't determine wakeup time for intro type '{areaData.IntroType}'".Log(LogLevel.Warn);
}

return wakeupTime;
}

public static GameState? GetGameState() {
if (Engine.Scene is not Level level) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ protected override void HandleMessage(MessageID messageId, BinaryReader reader)
case GameDataType.CommandHash:
gameData[gameDataType] = reader.ReadInt32();
break;

case GameDataType.LevelInfo:
gameData[gameDataType] = reader.ReadObject<LevelInfo>();
break;
}
gameDataPending[gameDataType] = false;

Expand Down
7 changes: 7 additions & 0 deletions Studio/CelesteStudio/Communication/CommunicationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ public static string GetExactGameInfo() {

return (string?)comm!.RequestGameData(GameDataType.ExactGameInfo).Result ?? string.Empty;
}
public static LevelInfo? GetLevelInfo() {
if (!Connected) {
return null;
}

return (LevelInfo?)comm!.RequestGameData(GameDataType.LevelInfo).Result;
}

// The hashcode is stored instead of the actual key, since it is used as an identifier in responses from Celeste
private static readonly Dictionary<int, (List<CommandAutoCompleteEntry> Entries, bool Done)> autoCompleteEntryCache = [];
Expand Down
19 changes: 12 additions & 7 deletions Studio/CelesteStudio/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,21 @@ private void OnNewFile() {
if (!ShouldDiscardChanges())
return;

string simpleConsoleCommand = CommunicationWrapper.GetConsoleCommand(simple: true);
CommunicationWrapper.GetModURL();
LevelInfo? levelInfo = CommunicationWrapper.GetLevelInfo();

string initText = $"RecordCount: 1{Document.NewLine}";
if (CommunicationWrapper.Connected) {
if (CommunicationWrapper.GetConsoleCommand(simple: true) is var simpleConsoleCommand && !string.IsNullOrWhiteSpace(simpleConsoleCommand)) {
initText += $"{Document.NewLine}{simpleConsoleCommand}{Document.NewLine} 1{Document.NewLine}";
if (CommunicationWrapper.GetModURL() is var modUrl && !string.IsNullOrWhiteSpace(modUrl)) {
initText = modUrl + initText;
}
}
if (levelInfo != null && !string.IsNullOrWhiteSpace(levelInfo?.ModUrl)) {
initText = levelInfo?.ModUrl + initText;
}
if (!string.IsNullOrWhiteSpace(simpleConsoleCommand)) {
initText += $"{Document.NewLine}{simpleConsoleCommand}{Document.NewLine} 1{Document.NewLine}";
}
initText += $"{Document.NewLine}#Start{Document.NewLine}";
if (levelInfo?.WakeupTime is { } wakeupTime) {
initText += wakeupTime.ToString().PadLeft(ActionLine.MaxFramesDigits) + Document.NewLine;
}

File.WriteAllText(Document.ScratchFile, initText);
OpenFile(Document.ScratchFile);
Expand Down
9 changes: 9 additions & 0 deletions StudioCommunication/LevelData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MemoryPack;

namespace StudioCommunication;

[MemoryPackable]
public partial record struct LevelInfo {
public int? WakeupTime;
public string ModUrl;
}
1 change: 1 addition & 0 deletions StudioCommunication/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public enum GameDataType : byte {
RawInfo,
GameState,
CommandHash,
LevelInfo,
}

public enum RecordingFailedReason : byte {
Expand Down
Loading