UI/KillFeedHistory.cs
using System;
using System.Collections.Generic;

namespace Sandbox;

/// <summary>Client-side killfeed history that survives player and HUD respawns.</summary>
internal sealed class KillFeedHistory
{
	private const int MaxEntries = 5;
	public const float EntryLifetime = 5f;

	private readonly List<Entry> _entries = new();
	public IReadOnlyList<Entry> Entries => _entries;
	public int Version { get; private set; }

	public void Add( Guid killerId, Guid victimId, string killerName, string victimName, bool headshot, bool isSuicide, string weaponIconPath )
	{
		RemoveExpired();
		_entries.Insert( 0, new Entry
		{
			KillerId = killerId,
			VictimId = victimId,
			KillerName = killerName,
			VictimName = victimName,
			Headshot = headshot,
			IsSuicide = isSuicide,
			WeaponIconPath = isSuicide ? "" : (weaponIconPath ?? ""),
			CreatedAt = Time.Now
		} );

		while ( _entries.Count > MaxEntries )
			_entries.RemoveAt( _entries.Count - 1 );

		Version++;
	}

	public void RemoveExpired()
	{
		var now = Time.Now;
		if ( _entries.RemoveAll( e => now - e.CreatedAt >= EntryLifetime ) > 0 )
			Version++;
	}

	internal sealed class Entry
	{
		public Guid KillerId { get; init; }
		public Guid VictimId { get; init; }
		public string KillerName { get; init; }
		public string VictimName { get; init; }
		public string WeaponIconPath { get; init; }
		public bool Headshot { get; init; }
		public bool IsSuicide { get; init; }
		public float CreatedAt { get; init; }
	}
}