Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using bindables to swap note playfields #596

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,21 @@ public LineLifetimeEntry(DrawableSentakkiRuleset? drawableSentakkiRuleset, doubl

public void Add(SentakkiLanedHitObject hitObject)
{
hitObject.LaneBindable.ValueChanged += onLaneChanged;
hitObject.BreakBindable.ValueChanged += onBreakChanged;
hitObject.ColourBindable.ValueChanged += onColorChanged;
HitObjects.AddInPlace(hitObject, Comparer<SentakkiLanedHitObject>.Create((lhs, rhs) => lhs.Lane.CompareTo(rhs.Lane)));
UpdateLine();
}

public void Remove(SentakkiLanedHitObject hitObject)
{
hitObject.LaneBindable.ValueChanged -= onLaneChanged;
hitObject.BreakBindable.ValueChanged -= onBreakChanged;
HitObjects.Remove(hitObject);
UpdateLine();
}

private void onLaneChanged(ValueChangedEvent<int> obj) => UpdateLine();

private void onBreakChanged(ValueChangedEvent<bool> obj) => UpdateLine();
private void onColorChanged(ValueChangedEvent<Color4> obj) => UpdateLine();

public Action<LineLifetimeEntry> OnLineUpdated = null!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public void AddHitObject(SentakkiLanedHitObject hitObject)

public void RemoveHitObject(SentakkiLanedHitObject hitObject)
{
// Ensure that we don't continue to receive time changes
startTimeMap[hitObject].UnbindAll();

startTimeMap.Remove(hitObject);

removeHitObjectFromEntry(hitObject.StartTime, hitObject);
}

Expand Down
19 changes: 6 additions & 13 deletions osu.Game.Rulesets.Sentakki/UI/LanedPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,13 @@ public LanedPlayfield()
});
}

public override void Add(HitObject h)
public override void Add(HitObject hitObject)
{
switch (h)
{
case SentakkiLanedHitObject laned:
HitObjectLineRenderer.AddHitObject(laned);
laned.LaneBindable.BindValueChanged(lane =>
{
if (lane.OldValue != lane.NewValue)
Lanes[lane.OldValue].Remove(h);
Lanes[lane.NewValue].Add(h);
}, true);
break;
}
if (hitObject is not SentakkiLanedHitObject lanedHitObject)
return;

HitObjectLineRenderer.AddHitObject(lanedHitObject);
Lanes[lanedHitObject.Lane].Add(lanedHitObject);
}

public override bool Remove(HitObject hitObject)
Expand Down
14 changes: 14 additions & 0 deletions osu.Game.Rulesets.Sentakki/UI/SentakkiPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ public override void Add(HitObject h)
}
}

public override bool Remove(HitObject h)
{
switch (h)
{
case SentakkiLanedHitObject:
return LanedPlayfield.Remove(h);

case Touch:
return touchPlayfield.Remove(h);
default:
return base.Remove(h);
}
}

private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
if (!judgedObject.DisplayResult || !DisplayJudgements.Value || judgedObject is not DrawableSentakkiHitObject sentakkiHitObject)
Expand Down
Loading