JD2022-TU1/main/tools/modules/JD.Guinness.WPF.Module/Model/Stadia/StadiaAchievement.cs

111 lines
3.8 KiB
C#

using System.Collections.Generic;
using System.Linq;
using JD.GoogleAchievement.Service;
using JD.Guinness.WPF.Module.Configuration.Stadia;
using JD.Guinness.WPF.Module.Extension;
using JD.Oasis.Service.API;
namespace JD.Guinness.WPF.Module.Model.Stadia
{
public sealed class StadiaAchievement : APlatformChallenge
{
private AchievementType _type;
private string _lockedImagePath;
private string _unlockedImagePath;
private LocalizedLine _lockedName;
private LocalizedLine _lockedObjective;
private LocalizedLine _unlockedName;
private LocalizedLine _unlockedObjective;
public AchievementType Type
{
get => _type;
set => SetProperty(ref _type, value);
}
public string LockedImagePath
{
get => _lockedImagePath;
set => SetProperty(ref _lockedImagePath, value);
}
public string UnlockedImagePath
{
get => _unlockedImagePath;
set => SetProperty(ref _unlockedImagePath, value);
}
public LocalizedLine LockedName
{
get => _lockedName;
set => SetProperty(ref _lockedName, value);
}
public LocalizedLine LockedObjective
{
get => _lockedObjective;
set => SetProperty(ref _lockedObjective, value);
}
public LocalizedLine UnlockedName
{
get => _unlockedName;
set => SetProperty(ref _unlockedName, value);
}
public LocalizedLine UnlockedObjective
{
get => _unlockedObjective;
set => SetProperty(ref _unlockedObjective, value);
}
public StadiaAchievement(Challenge challenge)
: base(challenge)
{ }
public StadiaAchievement DuplicateInto(Challenge challenge)
{
StadiaAchievement achievement = new StadiaAchievement(challenge)
{
Id = Id,
LockedImagePath = LockedImagePath,
LockedName = LockedName,
LockedObjective = LockedObjective,
UnlockedImagePath = UnlockedImagePath,
UnlockedName = UnlockedName,
UnlockedObjective = UnlockedObjective
};
achievement.CustomData.Add(CustomData.Values);
return achievement;
}
public StadiaAchievementSave ToSave(string worspacePapth) => new StadiaAchievementSave
{
Extra = CustomData.Values.ToDictionary(p => p.Key, p => p.Value),
Id = Id,
Type = Type,
LockedImagePath = LockedImagePath.ToRelativePath(worspacePapth),
LockedName = LockedName?.Id,
LockedObjective = LockedObjective?.Id,
UnlockedImagePath = UnlockedImagePath.ToRelativePath(worspacePapth),
UnlockedName = UnlockedName?.Id,
UnlockedObjective = UnlockedObjective?.Id
};
public Achievement ToServiceAchievement(IEnumerable<LanguageInfo> languages) => new Achievement(
Id,
Type,
LockedImagePath,
UnlockedImagePath,
languages.Where(l => !string.IsNullOrEmpty(l.GoogleId)).ToDictionary(
l => l.GoogleId,
l => new LocalizedData(
LockedName.GetTranslation(l.Language) ?? Challenge.Name.GetTranslation(l.Language),
LockedObjective.GetTranslation(l.Language) ?? Challenge.Objective.GetTranslation(l.Language),
null,
UnlockedName.GetTranslation(l.Language) ?? Challenge.Name.GetTranslation(l.Language),
UnlockedObjective.GetTranslation(l.Language) ?? Challenge.Objective.GetTranslation(l.Language),
null)));
}
}