Neg_Utils/Achievments/Achievment.cs

158 lines
6.7 KiB
C#

using NEG.Utils.Achievments.AchievmentTypes;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NEG.Utils.Achievments
{
/// <summary>
/// Static utility for achievment managment
/// </summary>
public static class Achievment
{
public static AchievmentManager Instance
{
get
{
if (instance == null)
{
instance = AchievmentManager.Builder.FromDefaultConfig()
.WithLabeledBackend(BackendLabel)
.Build();
}
return instance;
}
}
public static string BackendLabel
{
get => backendLabel;
set
{
if(instance != null)
{
throw new ApplicationException("Achievments - Cannot set backend label, Managed already created");
}
if (backendLabel != null)
{
throw new ApplicationException("Multiple AchievmentBackends enabled, this is not allowed");
}
backendLabel = value;
}
}
private static string backendLabel;
private static AchievmentManager instance;
#region Achievment Manipulation (Sets, Gets)
/// <summary>
/// Returns if an achivment at a given id is completed
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <seealso cref="AchievmentManager.IsCompleted(string)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id</remarks>
public static bool IsCompleted(string id)
{
return instance.IsCompleted(id);
}
#region Toggle
/// <summary>
/// Sets a <see cref="ToggleAchievmentData"/> as completed. <br/>
/// </summary>
/// <seealso cref="ToggleAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.SetToggleAchivment(string)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static bool SetToggleAchivment(string id)
{
return instance.SetToggleAchivment(id);
}
/// <summary>
/// Gets a completion state from a <see cref="ToggleAchievmentData"/>.<br/>
/// </summary>
/// <seealso cref="ToggleAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.GetToggleState(string)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static bool GetToggleState(string id)
{
return instance.GetToggleState(id);
}
#endregion
#region Int
/// <summary>
/// Sets progress of a given <see cref="IntAchievmentData"/> to <paramref name="progress"/> <br/>
/// </summary>
/// <seealso cref="IntAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.SetIntProgress(string, int)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static bool SetIntProgress(string id, int progress)
{
return instance.SetIntProgress(id, progress);
}
/// <summary>
/// Changes progress of a given <see cref="IntAchievmentData"/> by <paramref name="delta"/><br/>
/// </summary>
/// <seealso cref="IntAchievmentDefinition"/>\
/// <seealso cref="AchievmentManager.ChangeIntProgress(string, int)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static bool ChangeIntProgress(string id, int delta)
{
return instance.ChangeIntProgress(id, delta);
}
/// <summary>
/// Gets current progress from a <see cref="IntAchievmentData"/>.<br/>
/// </summary>
/// <seealso cref="ToggleAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.GetIntProgress(string)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static int GetIntProgress(string id)
{
return instance.GetIntProgress(id);
}
#endregion
#region Float
/// <summary>
/// Sets progress of a given <see cref="FloatAchievmentData"/> to <paramref name="progress"/><br/>
/// </summary>
/// <seealso cref="FloatAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.SetFloatProgress(string, float)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static bool SetFloatProgress(string id, float progress)
{
return instance.SetFloatProgress(id, progress);
}
/// <summary>
/// Changes progress of a given <see cref="FloatAchievmentData"/> by <paramref name="delta"/><br/>
/// </summary>
/// <seealso cref="FloatAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.ChangeFloatProgress(string, float)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static bool ChangeFloatProgress(string id, float delta)
{
return instance.ChangeFloatProgress(id, delta);
}
/// <summary>
/// Gets current progress from a <see cref="FloatAchievmentData"/>.<br/>
/// </summary>
/// <seealso cref="FloatAchievmentDefinition"/>
/// <seealso cref="AchievmentManager.GetFloatProgress(string)"/>
/// <remarks>throws an <see cref="AchievmentException"/> if there is no achievment under id or an <see cref="AchievmentTypeException"/> if achievment under id is of a different type</remarks>
public static float GetFloatProgress(string id)
{
return instance.GetFloatProgress(id);
}
#endregion
#endregion
}
}