Skip to content

Commit

Permalink
Merge pull request #85 from jakobhellermann/autofill-wakup-time
Browse files Browse the repository at this point in the history
feat: fill in wakeup frames if possible when creating a new file
  • Loading branch information
psyGamer authored Oct 2, 2024
2 parents 89be187 + d78af47 commit 8d5b202
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 7 deletions.
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

0 comments on commit 8d5b202

Please sign in to comment.