using System.Diagnostics.CodeAnalysis;
using PkmnLib.Static.Species;
using PkmnLib.Static.Utils;
namespace PkmnLib.Static.Libraries;
///
/// The library for all species in the game.
///
public interface IReadOnlySpeciesLibrary : IEnumerable
{
///
/// Tries to get a species from the library. Returns false if the species is not found.
///
bool TryGet(StringKey key, [MaybeNullWhen(false)] out ISpecies value);
bool TryGetById(int id, [MaybeNullWhen(false)] out ISpecies value);
///
/// Gets a random species from the library.
///
ISpecies GetRandom(IRandom random);
///
/// The amount of species in the library.
///
int Count { get; }
///
/// Whether the library is empty.
///
bool IsEmpty { get; }
}
///
public class SpeciesLibrary : DataLibrary, IReadOnlySpeciesLibrary
{
///
public bool TryGetById(int id, [MaybeNullWhen(false)] out ISpecies value)
{
return this.FirstOrDefault(s => s.Id == id) is { } species
? (value = species) != null
: (value = default) != null;
}
}