Skip to content

Commit

Permalink
Merge pull request taulazer#40 from MATRIX-feather/replay_func
Browse files Browse the repository at this point in the history
Add local replay support for tau
  • Loading branch information
naoei authored Mar 26, 2020
2 parents 7057230 + 450a6e0 commit 09c43b3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 9 deletions.
35 changes: 30 additions & 5 deletions osu.Game.Rulesets.tau/Replays/tauReplayFrame.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using osuTK;

namespace osu.Game.Rulesets.Tau.Replays
{
public class TauReplayFrame : ReplayFrame
public class TauReplayFrame : ReplayFrame, IConvertibleReplayFrame
{
public List<TauAction> Actions = new List<TauAction>();
public Vector2 Position;

public TauReplayFrame(double time, Vector2 position, TauAction? button = null) : base(time)
public TauReplayFrame()
{
}

public TauReplayFrame(double time, Vector2 position, params TauAction[] actions) : base(time)
{
Position = position;
Actions.AddRange(actions);
}

public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
{
Position = currentFrame.Position;

if (currentFrame.MouseLeft) Actions.Add(TauAction.LeftButton);
if (currentFrame.MouseRight) Actions.Add(TauAction.RightButton);
if (currentFrame.MouseLeft2) Actions.Add(TauAction.HardButton);
}

public LegacyReplayFrame ToLegacy(IBeatmap beatmap)
{
ReplayButtonState state = ReplayButtonState.None;

if (Actions.Contains(TauAction.LeftButton)) state |= ReplayButtonState.Left1;
if (Actions.Contains(TauAction.RightButton)) state |= ReplayButtonState.Right1;
if (Actions.Contains(TauAction.HardButton)) state |= ReplayButtonState.Left2;

if (button.HasValue)
Actions.Add(button.Value);
return new LegacyReplayFrame(Time, Position.X, Position.Y, state);
}
}
}
23 changes: 23 additions & 0 deletions osu.Game.Rulesets.tau/UI/TauReplayRecorder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Game.Replays;
using osu.Game.Rulesets.Tau.Replays;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI;
using osuTK;

namespace osu.Game.Rulesets.Tau.UI
{
public class TauReplayRecorder : ReplayRecorder<TauAction>
{
public TauReplayRecorder(Replay replay)
: base(replay)
{
}

protected override ReplayFrame HandleFrame(Vector2 mousePosition, List<TauAction> actions, ReplayFrame previousFrame)
=> new TauReplayFrame(Time.Current, mousePosition, actions.ToArray() );
}
}
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.tau/UI/tauDrawableRuleset.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
Expand Down Expand Up @@ -33,5 +33,7 @@ public DrawabletauRuleset(TauRuleset ruleset, IBeatmap beatmap, IReadOnlyList<Mo
protected override PassThroughInputManager CreateInputManager() => new TauInputManager(Ruleset?.RulesetInfo);

public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new TauPlayfieldAdjustmentContainer();

protected override ReplayRecorder CreateReplayRecorder(Replay replay) => new TauReplayRecorder(replay);
}
}
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.tau/osu.Game.Rulesets.tau.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<EmbeddedResource Include="Resources\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework" Version="2020.305.0" />
<PackageReference Include="ppy.osu.Game" Version="2020.306.0" />
<PackageReference Include="ppy.osu.Framework" Version="2020.319.0" />
<PackageReference Include="ppy.osu.Game" Version="2020.325.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\Samples\Gameplay" />
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.tau/tauInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool AllowUserPresses
/// </summary>
public bool AllowUserCursorMovement { get; set; } = true;

protected override RulesetKeyBindingContainer CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
protected override KeyBindingContainer<TauAction> CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
=> new TauKeyBindingContainer(ruleset, variant, unique);

public TauInputManager(RulesetInfo ruleset)
Expand Down
4 changes: 4 additions & 0 deletions osu.Game.Rulesets.tau/tauRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Tau.Beatmaps;
using osu.Game.Rulesets.Tau.Configuration;
using osu.Game.Rulesets.Tau.Mods;
using osu.Game.Rulesets.Tau.Replays;
using osu.Game.Rulesets.Tau.Scoring;
using osu.Game.Rulesets.Tau.UI;
using osu.Game.Rulesets.UI;
Expand Down Expand Up @@ -103,5 +105,7 @@ public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) =
{
Texture = new TextureStore(new TextureLoaderStore(CreateResourceStore()), false).Get("Textures/tau"),
};

public override IConvertibleReplayFrame CreateConvertibleReplayFrame() => new TauReplayFrame();
}
}

0 comments on commit 09c43b3

Please sign in to comment.