Bug fixes, add type name to TypeIdentifier
This commit is contained in:
@@ -13,11 +13,6 @@ public interface IReadOnlyTypeLibrary
|
||||
/// </summary>
|
||||
bool TryGetTypeIdentifier(StringKey key, out TypeIdentifier typeIdentifier);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type name from the type identifier.
|
||||
/// </summary>
|
||||
bool TryGetTypeName(TypeIdentifier t, [NotNullWhen(true)] out StringKey? stringKey);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the effectiveness for a single attacking type against a single defending type.
|
||||
/// </summary>
|
||||
@@ -35,25 +30,19 @@ public interface IReadOnlyTypeLibrary
|
||||
/// <inheritdoc />
|
||||
public class TypeLibrary : IReadOnlyTypeLibrary
|
||||
{
|
||||
private readonly Dictionary<StringKey, TypeIdentifier> _types = new();
|
||||
private readonly List<TypeIdentifier> _types = new();
|
||||
private readonly List<List<float>> _effectiveness = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetTypeIdentifier(StringKey key, out TypeIdentifier type) => _types.TryGetValue(key, out type);
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetTypeName(TypeIdentifier t, [NotNullWhen(true)] out StringKey? stringKey)
|
||||
public bool TryGetTypeIdentifier(StringKey key, out TypeIdentifier type)
|
||||
{
|
||||
foreach (var (key, value) in _types)
|
||||
var found = _types.FirstOrDefault(t => t.Name.Equals(key));
|
||||
if (found.Value is not 0)
|
||||
{
|
||||
if (value == t)
|
||||
{
|
||||
stringKey = key;
|
||||
return true;
|
||||
}
|
||||
type = found;
|
||||
return true;
|
||||
}
|
||||
|
||||
stringKey = default;
|
||||
type = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,7 +68,8 @@ public class TypeLibrary : IReadOnlyTypeLibrary
|
||||
throw new ArgumentOutOfRangeException(nameof(attacking));
|
||||
for (var i = 0; i < _effectiveness.Count; i++)
|
||||
{
|
||||
yield return (new TypeIdentifier((byte)(i + 1)), _effectiveness[attacking.Value - 1][i]);
|
||||
var type = _types[i];
|
||||
yield return (type, _effectiveness[attacking.Value - 1][i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +78,8 @@ public class TypeLibrary : IReadOnlyTypeLibrary
|
||||
/// </summary>
|
||||
public TypeIdentifier RegisterType(StringKey name)
|
||||
{
|
||||
var id = new TypeIdentifier((byte)(_types.Count + 1));
|
||||
_types.Add(name, id);
|
||||
var id = new TypeIdentifier((byte)(_types.Count + 1), name);
|
||||
_types.Add(id);
|
||||
_effectiveness.Add(Enumerable.Repeat(1.0f, _effectiveness.Count).ToList());
|
||||
foreach (var list in _effectiveness)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user