From af47348919bf8664e99fc49d15723da06847c4b4 Mon Sep 17 00:00:00 2001 From: LubieKakao1212 Date: Wed, 4 Jan 2023 13:07:03 +0100 Subject: [PATCH] Added AchievmentExceptions, fixed some names --- Achievments/AchievmentException.cs | 44 ++++++++++++++++++++++ Achievments/AchievmentException.cs.meta | 11 ++++++ Achievments/AchievmentManager.cs | 8 ++-- Achievments/IAchievmentCallbackReciever.cs | 8 ++-- 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 Achievments/AchievmentException.cs create mode 100644 Achievments/AchievmentException.cs.meta diff --git a/Achievments/AchievmentException.cs b/Achievments/AchievmentException.cs new file mode 100644 index 0000000..3ae6dea --- /dev/null +++ b/Achievments/AchievmentException.cs @@ -0,0 +1,44 @@ +using JetBrains.Annotations; +using System; + +namespace NEG.Utils.Achievments +{ + public class AchievmentException : ApplicationException + { + /// + /// Id of related achievment + /// + /// + /// + public string Id { get; private set; } + + public AchievmentException(string message, string achievmentId) : base(message) + { + Id = achievmentId; + } + } + + public class AchievmentTypeExcetion : AchievmentException + { + /// + /// Expected achievment type under + /// + /// + /// + public Type Expected { get; private set; } + + /// + /// Actual achievment type under + /// + /// + /// + public Type Actual { get; private set; } + + public AchievmentTypeExcetion(string message, string achievmentId, Type expectedType, Type actualType) : base(message, achievmentId) + { + Expected = expectedType; + Actual = actualType; + } + } + +} \ No newline at end of file diff --git a/Achievments/AchievmentException.cs.meta b/Achievments/AchievmentException.cs.meta new file mode 100644 index 0000000..b09eea7 --- /dev/null +++ b/Achievments/AchievmentException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 241344322b9771049b6962e48ac98085 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Achievments/AchievmentManager.cs b/Achievments/AchievmentManager.cs index 64f26cd..56e361a 100644 --- a/Achievments/AchievmentManager.cs +++ b/Achievments/AchievmentManager.cs @@ -264,7 +264,7 @@ namespace NEG.Utils.Achievments /// throws an if either there is no achievment under id or achievment under id is of a different type public T GetAchievmentForId(string id) where T : AchievmentData { - return CheckAchievmentType(GetAchievmentForId(id)); + return ValidateAchievmentType(GetAchievmentForId(id)); } /// @@ -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(AchievmentData data) where T : AchievmentData + private T ValidateAchievmentType(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; } diff --git a/Achievments/IAchievmentCallbackReciever.cs b/Achievments/IAchievmentCallbackReciever.cs index 6c6a87d..133a4e5 100644 --- a/Achievments/IAchievmentCallbackReciever.cs +++ b/Achievments/IAchievmentCallbackReciever.cs @@ -11,13 +11,13 @@ namespace NEG.Utils.Achievments /// /// Called when an achivment is completed /// - /// - void AchievmentCompleted(AchievmentData achivment); + /// + void AchievmentCompleted(AchievmentData achievment); /// /// Called when achivment progress changes /// - /// - void AchievmentStateChanged(AchievmentData achivment); + /// + void AchievmentStateChanged(AchievmentData achievment); } } \ No newline at end of file