using DoomDeathmatch.Component.MVC.Model;
using Engine.Scene.Component.BuiltIn.Renderer;

namespace DoomDeathmatch.Component.MVC.View;

public class HealthView : Engine.Scene.Component.Component
{
  protected readonly TextRenderer _healthTextRenderer;

  public HealthView(TextRenderer parHealthTextRenderer)
  {
    _healthTextRenderer = parHealthTextRenderer;
  }

  public virtual void UpdateView(HealthModel parHealthModel)
  {
    var percentage = parHealthModel.Health / parHealthModel.MaxHealth * 100;
    if (parHealthModel.Health != 0)
      percentage = Math.Max(1, percentage);

    _healthTextRenderer.Text = $"Здоровье: {percentage:000}";
  }
}