81 lines
2.9 KiB
C#
81 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using JD.Guinness.WPF.Module.Configuration;
|
|
using JD.Guinness.WPF.Module.Model.Ps4;
|
|
using JD.Guinness.WPF.Module.Model.Ps5;
|
|
using JD.Guinness.WPF.Module.Model.Stadia;
|
|
using JD.Guinness.WPF.Module.Model.XBoxOne;
|
|
using JD.Guinness.WPF.Module.Model.XBoxSeriesX;
|
|
using JD.Oasis.Service.API;
|
|
|
|
namespace JD.Guinness.WPF.Module.Model
|
|
{
|
|
public sealed class Challenge : AChallenge
|
|
{
|
|
private readonly DispatcherObservableCollection<APlatformChallenge> _platformChallenges;
|
|
|
|
private LocalizedLine _name;
|
|
private LocalizedLine _objective;
|
|
|
|
public event NotifyCollectionChangedEventHandler PlatformChallengesChanged
|
|
{
|
|
add => _platformChallenges.CollectionChanged += value;
|
|
remove => _platformChallenges.CollectionChanged -= value;
|
|
}
|
|
|
|
public LocalizedLine Name
|
|
{
|
|
get => _name;
|
|
set => SetProperty(ref _name, value);
|
|
}
|
|
|
|
public LocalizedLine Objective
|
|
{
|
|
get => _objective;
|
|
set => SetProperty(ref _objective, value);
|
|
}
|
|
|
|
public IEnumerable<APlatformChallenge> PlatformChallenges => _platformChallenges;
|
|
|
|
public Challenge()
|
|
{
|
|
_platformChallenges = new DispatcherObservableCollection<APlatformChallenge>();
|
|
}
|
|
|
|
public T GetPlatformChallenge<T>() where T : APlatformChallenge => PlatformChallenges.OfType<T>().FirstOrDefault();
|
|
|
|
public T GetOrAddPlatformChallenge<T>() where T : APlatformChallenge => GetPlatformChallenge<T>() ?? (T)Activator.CreateInstance(typeof(T), this);
|
|
|
|
public void RemovePlatformChallenge(APlatformChallenge platformChallenge)
|
|
{
|
|
if (platformChallenge.Challenge == this)
|
|
{
|
|
_platformChallenges.Remove(platformChallenge);
|
|
}
|
|
}
|
|
|
|
public void AddPlatformChallenge(APlatformChallenge platformChallenge)
|
|
{
|
|
if (platformChallenge.Challenge == this)
|
|
{
|
|
_platformChallenges.Add(platformChallenge);
|
|
}
|
|
}
|
|
|
|
public void NotifyPlatformChallenges() => OnPropertyChanged(nameof(PlatformChallenges));
|
|
|
|
public ChallengeSave ToSave(string workspacePath) => new ChallengeSave
|
|
{
|
|
Extra = CustomData.Values.ToDictionary(p => p.Key, p => p.Value),
|
|
Name = Name?.Id,
|
|
Objective = Objective?.Id,
|
|
Ps4 = GetPlatformChallenge<Ps4Trophy>()?.ToSave(workspacePath),
|
|
Ps5 = GetPlatformChallenge<Ps5Trophy>()?.ToSave(workspacePath),
|
|
XBoxOne = GetPlatformChallenge<XBoxOneAchievement>()?.ToSave(workspacePath),
|
|
XBoxSeriesX = GetPlatformChallenge<XBoxSeriesXAchievement>()?.ToSave(workspacePath),
|
|
Stadia = GetPlatformChallenge<StadiaAchievement>()?.ToSave(workspacePath)
|
|
};
|
|
}
|
|
}
|