Add safety against playfield potentially not being available during mania note placement

This commit is contained in:
Dean Herbert
2022-05-19 15:53:53 +09:00
parent f7e055dbfe
commit 5af7641e94

View File

@ -55,24 +55,25 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
base.UpdateTimeAndPosition(result); base.UpdateTimeAndPosition(result);
var playfield = (Column)result.Playfield; if (result.Playfield is Column col)
{
// Apply an offset to better align with the visual grid. // Apply an offset to better align with the visual grid.
// This should only be applied during placement, as during selection / drag operations the movement is relative // This should only be applied during placement, as during selection / drag operations the movement is relative
// to the initial point of interaction rather than the grid. // to the initial point of interaction rather than the grid.
switch (playfield.ScrollingInfo.Direction.Value) switch (col.ScrollingInfo.Direction.Value)
{ {
case ScrollingDirection.Down: case ScrollingDirection.Down:
result.ScreenSpacePosition -= new Vector2(0, getNoteHeight(playfield) / 2); result.ScreenSpacePosition -= new Vector2(0, getNoteHeight(col) / 2);
break; break;
case ScrollingDirection.Up: case ScrollingDirection.Up:
result.ScreenSpacePosition += new Vector2(0, getNoteHeight(playfield) / 2); result.ScreenSpacePosition += new Vector2(0, getNoteHeight(col) / 2);
break; break;
} }
if (PlacementActive == PlacementState.Waiting) if (PlacementActive == PlacementState.Waiting)
Column = playfield; Column = col;
}
} }
private float getNoteHeight(Column resultPlayfield) => private float getNoteHeight(Column resultPlayfield) =>