Fix error when trying to change layer that doesn't exist in SpriteChange and SpriteStateChange.

This commit is contained in:
Víctor Aguilera Puerto
2020-10-12 12:54:41 +02:00
parent 99ba632afc
commit c904a7e9c4
2 changed files with 7 additions and 5 deletions

View File

@@ -22,17 +22,15 @@ namespace Content.Server.Construction.Completions
public int Layer { get; private set; } = 0;
public string? State { get; private set; } = string.Empty;
public async Task StepCompleted(IEntity entity, IEntity user)
{
await PerformAction(entity, user);
}
public async Task PerformAction(IEntity entity, IEntity? user)
{
if (entity.Deleted || string.IsNullOrEmpty(State)) return;
if (!entity.TryGetComponent(out SpriteComponent? sprite)) return;
// That layer doesn't exist, we do nothing.
if (sprite.LayerCount <= Layer) return;
sprite.LayerSetState(Layer, State);
}
}