-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove input chunk from GhostFrame, input record & replay"
This reverts commit bec1b31b558465248c56aed539b840f31803d2e2.
- Loading branch information
Showing
6 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using FMOD.Studio; | ||
using Microsoft.Xna.Framework; | ||
using Monocle; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace Celeste.Mod.Ghost { | ||
public static class GhostInputNodes { | ||
|
||
public class MoveX : VirtualAxis.Node { | ||
public GhostInputReplayer Replayer; | ||
public MoveX(GhostInputReplayer replayer) { | ||
Replayer = replayer; | ||
} | ||
public override float Value => Replayer.Frame.MoveX; | ||
} | ||
|
||
public class MoveY : VirtualAxis.Node { | ||
public GhostInputReplayer Replayer; | ||
public MoveY(GhostInputReplayer replayer) { | ||
Replayer = replayer; | ||
} | ||
public override float Value => Replayer.Frame.MoveY; | ||
} | ||
|
||
public class Aim : VirtualJoystick.Node { | ||
public GhostInputReplayer Replayer; | ||
public Aim(GhostInputReplayer replayer) { | ||
Replayer = replayer; | ||
} | ||
public override Vector2 Value => Replayer.Frame.Aim; | ||
} | ||
|
||
public class MountainAim : VirtualJoystick.Node { | ||
public GhostInputReplayer Replayer; | ||
public MountainAim(GhostInputReplayer replayer) { | ||
Replayer = replayer; | ||
} | ||
public override Vector2 Value => Replayer.Frame.MountainAim; | ||
} | ||
|
||
public class Button : VirtualButton.Node { | ||
public GhostInputReplayer Replayer; | ||
public int Mask; | ||
public Button(GhostInputReplayer replayer, GhostFrame.ButtonMask mask) { | ||
Replayer = replayer; | ||
Mask = (int) mask; | ||
} | ||
public override bool Check => !MInput.Disabled && (Replayer.Frame.Buttons & Mask) == Mask; | ||
public override bool Pressed => !MInput.Disabled && (Replayer.Frame.Buttons & Mask) == Mask && (Replayer.PrevFrame.Buttons & Mask) == 0; | ||
public override bool Released => !MInput.Disabled && (Replayer.Frame.Buttons & Mask) == 0 && (Replayer.PrevFrame.Buttons & Mask) == Mask; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using FMOD.Studio; | ||
using Microsoft.Xna.Framework; | ||
using Monocle; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace Celeste.Mod.Ghost { | ||
// We need this to work across scenes. | ||
public class GhostInputReplayer : GameComponent { | ||
|
||
public GhostData Data; | ||
public int FrameIndex = 0; | ||
public GhostFrame Frame => Data == null ? default(GhostFrame) : Data[FrameIndex]; | ||
public GhostFrame PrevFrame => Data == null ? default(GhostFrame) : Data[FrameIndex - 1]; | ||
|
||
public GhostInputReplayer(Game game, GhostData data) | ||
: base(game) { | ||
Data = data; | ||
|
||
Everest.Events.Input.OnInitialize += HookInput; | ||
HookInput(); | ||
} | ||
|
||
public void HookInput() { | ||
Input.MoveX.Nodes.Add(new GhostInputNodes.MoveX(this)); | ||
Input.MoveY.Nodes.Add(new GhostInputNodes.MoveY(this)); | ||
|
||
Input.Aim.Nodes.Add(new GhostInputNodes.Aim(this)); | ||
Input.MountainAim.Nodes.Add(new GhostInputNodes.MountainAim(this)); | ||
|
||
Input.ESC.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.ESC)); | ||
Input.Pause.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.Pause)); | ||
Input.MenuLeft.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuLeft)); | ||
Input.MenuRight.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuRight)); | ||
Input.MenuUp.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuUp)); | ||
Input.MenuDown.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuDown)); | ||
Input.MenuConfirm.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuConfirm)); | ||
Input.MenuCancel.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuCancel)); | ||
Input.MenuJournal.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.MenuJournal)); | ||
Input.QuickRestart.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.QuickRestart)); | ||
Input.Jump.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.Jump)); | ||
Input.Dash.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.Dash)); | ||
Input.Grab.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.Grab)); | ||
Input.Talk.Nodes.Add(new GhostInputNodes.Button(this, GhostFrame.ButtonMask.Talk)); | ||
|
||
Logger.Log("ghost", "GhostReplayer hooked input."); | ||
} | ||
|
||
public override void Update(GameTime gameTime) { | ||
base.Update(gameTime); | ||
|
||
do { | ||
FrameIndex++; | ||
} while ( | ||
(!Frame.HasInput && FrameIndex < Data.Frames.Count) // Skip any frames not containing the input chunk. | ||
); | ||
|
||
if (Data == null || FrameIndex >= Data.Frames.Count) | ||
Remove(); | ||
} | ||
|
||
public void Remove() { | ||
Everest.Events.Input.OnInitialize -= HookInput; | ||
Input.Initialize(); | ||
Logger.Log("ghost", "GhostReplayer returned input."); | ||
Game.Components.Remove(this); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.