Skip to content

Commit

Permalink
Fix exporting parameter commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
Damnae committed Nov 15, 2022
1 parent fb0861c commit ade192d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions common/Storyboarding/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public abstract class Command<TValue> : ITypedCommand<TValue>, IFragmentableComm
public double Duration => EndTime - StartTime;
public TValue StartValue { get; set; }
public TValue EndValue { get; set; }
public virtual bool MaintainValue => true;
public virtual bool ExportEndValue => true;
public bool Active => true;
public int Cost => 1;
Expand All @@ -38,11 +39,11 @@ public void Offset(double offset)

public TValue ValueAtTime(double time)
{
if (time <= StartTime) return ValueAtProgress(0);
if (EndTime <= time) return ValueAtProgress(1);
if (time < StartTime) return MaintainValue ? ValueAtProgress(0) : default;
if (EndTime < time) return MaintainValue ? ValueAtProgress(1) : default;

var duration = EndTime - StartTime;
var progress = Easing.Ease((time - StartTime) / duration);
var progress = duration > 0 ? Easing.Ease((time - StartTime) / duration) : 0;
return ValueAtProgress(progress);
}

Expand Down
10 changes: 7 additions & 3 deletions common/Storyboarding/Commands/ParameterCommand.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using StorybrewCommon.Storyboarding.CommandValues;
using System;

namespace StorybrewCommon.Storyboarding.Commands
{
public class ParameterCommand : Command<CommandParameter>
{
public override bool MaintainValue => StartTime == EndTime;
public override bool ExportEndValue => false;

public ParameterCommand(OsbEasing easing, double startTime, double endTime, CommandParameter startValue)
: base("P", easing, startTime, endTime, startValue, ((int)endTime - (int)startTime) == 0 ? startValue : CommandParameter.None)
public ParameterCommand(OsbEasing easing, double startTime, double endTime, CommandParameter value)
: base("P", easing, startTime, endTime, value, value)
{
if (value == CommandParameter.None)
throw new InvalidOperationException($"Parameter command cannot be None");
}

public override CommandParameter ValueAtProgress(double progress)
=> progress > 0 && progress < 1 || StartTime == EndTime ? StartValue : EndValue;
=> StartValue;

public override CommandParameter Midpoint(Command<CommandParameter> endCommand, double progress)
=> StartValue;
Expand Down

0 comments on commit ade192d

Please sign in to comment.