Added AchievmentExceptions, fixed some names
This commit is contained in:
parent
1bd77d9628
commit
af47348919
44
Achievments/AchievmentException.cs
Normal file
44
Achievments/AchievmentException.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
|
||||
namespace NEG.Utils.Achievments
|
||||
{
|
||||
public class AchievmentException : ApplicationException
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of related achievment
|
||||
/// </summary>
|
||||
/// <seealso cref="AchievmentTypes.AchievmentData"/>
|
||||
/// <seealso cref="AchievmentTypes.AchievmentDefinition"/>
|
||||
public string Id { get; private set; }
|
||||
|
||||
public AchievmentException(string message, string achievmentId) : base(message)
|
||||
{
|
||||
Id = achievmentId;
|
||||
}
|
||||
}
|
||||
|
||||
public class AchievmentTypeExcetion : AchievmentException
|
||||
{
|
||||
/// <summary>
|
||||
/// Expected achievment type under <see cref="AchievmentException.Id"/>
|
||||
/// </summary>
|
||||
/// <seealso cref="AchievmentTypes.AchievmentData"/>
|
||||
/// <seealso cref="AchievmentTypes.AchievmentDefinition"/>
|
||||
public Type Expected { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Actual achievment type under <see cref="AchievmentException.Id"/>
|
||||
/// </summary>
|
||||
/// <seealso cref="AchievmentTypes.AchievmentData"/>
|
||||
/// <seealso cref="AchievmentTypes.AchievmentDefinition"/>
|
||||
public Type Actual { get; private set; }
|
||||
|
||||
public AchievmentTypeExcetion(string message, string achievmentId, Type expectedType, Type actualType) : base(message, achievmentId)
|
||||
{
|
||||
Expected = expectedType;
|
||||
Actual = actualType;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Achievments/AchievmentException.cs.meta
Normal file
11
Achievments/AchievmentException.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 241344322b9771049b6962e48ac98085
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -264,7 +264,7 @@ namespace NEG.Utils.Achievments
|
||||
/// <remarks>throws an <see cref="ApplicationException"/> if either there is no achievment under id or achievment under id is of a different type</remarks>
|
||||
public T GetAchievmentForId<T>(string id) where T : AchievmentData
|
||||
{
|
||||
return CheckAchievmentType<T>(GetAchievmentForId(id));
|
||||
return ValidateAchievmentType<T>(GetAchievmentForId(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -281,15 +281,15 @@ namespace NEG.Utils.Achievments
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException($"Invalid achivment id {id}");
|
||||
throw new AchievmentException($"Invalid achivment id {id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
private T CheckAchievmentType<T>(AchievmentData data) where T : AchievmentData
|
||||
private T ValidateAchievmentType<T>(AchievmentData data) where T : AchievmentData
|
||||
{
|
||||
if (data is not T convetred)
|
||||
{
|
||||
throw new ApplicationException($"Attempting to perform an operation on an invalid achievment type. Expected {typeof(T)} got {data.GetType()}");
|
||||
throw new AchievmentTypeExcetion($"Attempting to perform an operation on an invalid achievment type. Expected {typeof(T)} got {data.GetType()}", data.Achivment.Id, typeof(T), data.GetType());
|
||||
}
|
||||
return convetred;
|
||||
}
|
||||
|
||||
@ -11,13 +11,13 @@ namespace NEG.Utils.Achievments
|
||||
/// <summary>
|
||||
/// Called when an achivment is completed
|
||||
/// </summary>
|
||||
/// <param name="achivment"></param>
|
||||
void AchievmentCompleted(AchievmentData achivment);
|
||||
/// <param name="achievment"></param>
|
||||
void AchievmentCompleted(AchievmentData achievment);
|
||||
|
||||
/// <summary>
|
||||
/// Called when achivment progress changes
|
||||
/// </summary>
|
||||
/// <param name="achivment"></param>
|
||||
void AchievmentStateChanged(AchievmentData achivment);
|
||||
/// <param name="achievment"></param>
|
||||
void AchievmentStateChanged(AchievmentData achievment);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user