Skip to content

Commit

Permalink
feat: use the new Everest api to get player states name which added b…
Browse files Browse the repository at this point in the history
…y mods
  • Loading branch information
DemoJameson committed Jan 20, 2024
1 parent edb71d1 commit 48c492c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CelesteTAS-EverestInterop/Source/TAS/ExportGameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void ExportInfo(InputFrame inputFrame) {

output = string.Join("\t",
inputFrame.Line + 1, $"{controller.CurrentFrameInInput}/{inputFrame}", controller.CurrentFrameInTas, time, pos, speed,
PlayerStates.GetStateName(player.StateMachine.State),
PlayerStates.GetCurrentStateName(player),
statuses);

foreach (string typeName in trackedEntities.Keys) {
Expand Down
16 changes: 14 additions & 2 deletions CelesteTAS-EverestInterop/Source/TAS/GameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static void Update(bool updateVel = false) {
string miscStats = $"Stamina: {player.Stamina:F2} "
+ (player.WallJumpCheck(1) ? "Wall-R " : string.Empty)
+ (player.WallJumpCheck(-1) ? "Wall-L " : string.Empty)
+ PlayerStates.GetStateName(player.StateMachine.State);
+ PlayerStates.GetCurrentStateName(player);

int dashCooldown = player.dashCooldownTimer.ToFloorFrames();

Expand Down Expand Up @@ -453,7 +453,7 @@ private static string GetStatusWithoutTime(string pos, string speed, string velo
builder.AppendLine(velocity);

if (player.StateMachine.State == Player.StStarFly
|| PlayerStates.GetStateName(player.StateMachine.State) == "Custom Feather"
|| PlayerStates.GetCurrentStateName(player) == "Custom Feather"
|| playerSeeker != null
|| SaveData.Instance.Assists.ThreeSixtyDashing
|| SaveData.Instance.Assists.SuperDashing
Expand Down Expand Up @@ -595,6 +595,8 @@ private static double GetAngle(Vector2 vector) {
}

public static class PlayerStates {
private static readonly Func<StateMachine, string> GetCurrentStateNameFunc = typeof(StateMachine).GetMethod("GetCurrentStateName")?.CreateDelegate<Func<StateMachine, string>>();

private static readonly IDictionary<int, string> States = new Dictionary<int, string> {
{Player.StNormal, nameof(Player.StNormal)},
{Player.StClimb, nameof(Player.StClimb)},
Expand Down Expand Up @@ -624,10 +626,20 @@ public static class PlayerStates {
{Player.StIntroThinkForABit, nameof(Player.StIntroThinkForABit)},
};

[Obsolete("GetStateName(int) is deprecated, please use GetCurrentStateName(Player) instead.")]
public static string GetStateName(int state) {
return States.TryGetValue(state, out string name) ? name : state.ToString();
}

public static string GetCurrentStateName(Player player) {
StateMachine stateMachine = player.StateMachine;
if (States.TryGetValue(stateMachine.state, out string name)) {
return name;
} else {
return GetCurrentStateNameFunc?.Invoke(stateMachine) ?? stateMachine.state.ToString();
}
}

// ReSharper disable once UnusedMember.Global
public static void Register(int state, string stateName) {
States[state] = stateName;
Expand Down

0 comments on commit 48c492c

Please sign in to comment.