JD2022-TU1/main/tools/modules/JD.Guinness.WPF.Module/ViewModel/WarningViewModel.cs

637 lines
34 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using JD.Guinness.WPF.Module.Extension;
using JD.Guinness.WPF.Module.Model;
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;
using JD.SonyTrophy.Service;
namespace JD.Guinness.WPF.Module.ViewModel
{
public sealed class WarningViewModel
{
public GameViewModel Game { get; }
public DispatcherObservableCollection<Warning> Warnings { get; }
public WarningViewModel(GameViewModel gameViewModel)
{
Game = gameViewModel;
Warnings = new DispatcherObservableCollection<Warning>();
Game.Ps4Configuration.PropertyChanged += GetPropertyChangedEventHandler<Ps4Configuration>(Check);
Game.Ps4Configuration.Zones.CollectionChanged += OnZonesChanged;
Game.Ps5Configuration.PropertyChanged += GetPropertyChangedEventHandler<Ps5Configuration>(Check);
AddLanguagesChanged<Ps5Trophy>(Game.Ps5Configuration.Languages);
Game.XBoxOneConfiguration.PropertyChanged += GetPropertyChangedEventHandler<XBoxOneConfiguration>(Check);
AddLanguagesChanged<XBoxOneAchievement>(Game.XBoxOneConfiguration.Languages);
Game.XBoxSeriesXConfiguration.PropertyChanged += GetPropertyChangedEventHandler<XBoxSeriesXConfiguration>(Check);
AddLanguagesChanged<XBoxSeriesXAchievement>(Game.XBoxSeriesXConfiguration.Languages);
Game.StadiaConfiguration.PropertyChanged += GetPropertyChangedEventHandler<StadiaConfiguration>(Check);
AddLanguagesChanged<StadiaAchievement>(Game.StadiaConfiguration.Languages);
Game.Challenges.CollectionChanged += OnChallengesChanged;
OnChallengesChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, Game.Challenges));
}
private void OnZonesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
RemoveWarnings((e.OldItems ?? Array.Empty<IWarnable>()).OfType<IWarnable>());
foreach (Ps4Zone zone in e.NewItems ?? Array.Empty<Ps4Zone>())
{
zone.PropertyChanged += GetPropertyChangedEventHandler<Ps4Zone>(Check);
AddLanguagesChanged<Ps4Trophy>(zone.Languages);
}
Check(Game.Ps4Configuration);
Check<Ps4Trophy>();
}
private void OnChallengesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
foreach (Challenge challenge in e.OldItems ?? Array.Empty<Challenge>())
{
challenge.PlatformChallengesChanged -= OnPlatformChallengesChanged;
}
RemoveWarnings((e.OldItems ?? Array.Empty<object>())
.Cast<Challenge>()
.SelectMany(c => c.PlatformChallenges.Cast<AChallenge>().Concat(Enumerable.Repeat(c, 1))));
foreach (Challenge challenge in e.NewItems ?? Array.Empty<Challenge>())
{
challenge.PlatformChallengesChanged += OnPlatformChallengesChanged;
}
AddAndCheck((e.NewItems ?? Array.Empty<Challenge>())
.OfType<Challenge>()
.SelectMany(c => c.PlatformChallenges.Cast<AChallenge>().Concat(Enumerable.Repeat(c, 1))));
Check(Game.Ps4Configuration);
Check(Game.XBoxOneConfiguration);
Check(Game.XBoxSeriesXConfiguration);
Check(Game.StadiaConfiguration);
}
private void OnPlatformChallengesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
RemoveWarnings((e.OldItems ?? Array.Empty<IWarnable>()).OfType<IWarnable>());
AddAndCheck((e.NewItems ?? Array.Empty<AChallenge>()).OfType<AChallenge>());
Check(Game.Ps4Configuration);
Check(Game.XBoxOneConfiguration);
Check(Game.XBoxSeriesXConfiguration);
Check(Game.StadiaConfiguration);
}
private void Check<T>()
where T : APlatformChallenge
{
foreach (T platformChallenge in Game.Challenges.SelectMany(c => c.PlatformChallenges).OfType<T>())
{
Check(platformChallenge, false);
}
if (typeof(T) == typeof(Ps4Trophy))
{
foreach (Ps4Zone zone in Game.Ps4Configuration.Zones)
{
Check(zone);
}
}
if (typeof(T) == typeof(Ps5Trophy))
{
Check(Game.Ps5Configuration);
}
else if (typeof(T) == typeof(XBoxOneAchievement))
{
Check(Game.XBoxOneConfiguration);
}
else if (typeof(T) == typeof(XBoxSeriesXAchievement))
{
Check(Game.XBoxSeriesXConfiguration);
}
else if (typeof(T) == typeof(StadiaAchievement))
{
Check(Game.StadiaConfiguration);
}
}
private void AddLanguagesChanged<T>(ObservableCollection<Selectable<LanguageInfo>> languages)
where T : APlatformChallenge
{
void OnLanguageChanged(object _, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Selectable<LanguageInfo>.IsSelected))
{
Check<T>();
}
}
languages.CollectionChanged += (_, e) =>
{
foreach (Selectable<LanguageInfo> language in e.NewItems ?? Array.Empty<Selectable<LanguageInfo>>())
{
language.PropertyChanged += OnLanguageChanged;
}
};
foreach (Selectable<LanguageInfo> language in languages)
{
language.PropertyChanged += OnLanguageChanged;
}
}
private PropertyChangedEventHandler GetPropertyChangedEventHandler<T>(Action<T> check) where T : IWarnable => (sender, e) =>
{
if (sender is T item && e.PropertyName != nameof(IWarnable.Warnings))
{
check(item);
}
};
private void RemoveWarnings<T>(IEnumerable<T> items)
where T : IWarnable
{
foreach (Warning warning in items.SelectMany(i => Warnings.Where(w => ReferenceEquals(w.Item, i))).ToList())
{
Warnings.Remove(warning);
}
}
private void AddAndCheck(IEnumerable<AChallenge> items)
{
foreach (AChallenge item in items)
{
item.PropertyChanged += GetPropertyChangedEventHandler<AChallenge>(c => Check(c, true));
Check(item, false);
}
}
private void Check<T>(T item, Predicate<T> createWarning, Func<T, Warning> warningFactory)
where T : IWarnable
{
if (createWarning(item))
{
Warning warning = warningFactory(item);
Warnings.Add(warning);
item.Warnings = item.Warnings is null ? warning.Message : item.Warnings + Environment.NewLine + warning.Message;
}
}
private void CheckImage<T>(T item, string type, string imagePath, string propertyName, int? width, int? height)
where T : IWarnable
{
if (string.IsNullOrEmpty(imagePath))
{
Check(item, _ => true, i => new Warning(i, type, $"missing {propertyName}"));
}
else if (!File.Exists(imagePath))
{
Check(item, _ => true, i => new Warning(i, type, $"{propertyName} {imagePath} does not exist"));
}
else
{
try
{
using (Bitmap image = new Bitmap(imagePath))
{
Check(
item,
_ => image.Width != (width ?? image.Width) || image.Height != (height ?? image.Height),
i => new Warning(i, type, $"invalid {propertyName} size {image.Width}x{image.Height}, {width}x{height} required"));
}
}
catch
{
Check(item, _ => true, i => new Warning(i, type, $"error loading {propertyName} {imagePath}"));
}
}
}
private void Check(Ps4Configuration configuration)
{
RemoveWarnings(Enumerable.Repeat(configuration, 1));
configuration.Warnings = null;
HashSet<int> ids = new HashSet<int>();
bool hasPlatinium = false;
int points = 0;
foreach (Ps4Trophy trophy in Game.Challenges.SelectMany(c => c.PlatformChallenges.OfType<Ps4Trophy>()))
{
Check(configuration, _ => !ids.Add(trophy.Id), c => new Warning(c, "PS4 trophy", $"duplicate id {trophy.Id}"));
Check(configuration, _ => hasPlatinium && trophy.Grade == TrophyGrade.Platinium, c => new Warning(c, "PS4 trophy", "more than one platinium trophy"));
hasPlatinium |= trophy.Grade == TrophyGrade.Platinium;
points += trophy.Grade.ToPoints();
}
if (ids.Count > 0)
{
Check(configuration, _ => !ids.OrderBy(i => i).SequenceEqual(Enumerable.Range(0, ids.Max() + 1)), c => new Warning(c, "PS4 trophy", $"missing some ids {string.Join(", ", Enumerable.Range(0, ids.Max() + 1).Except(ids))}"));
Check(configuration, _ => !hasPlatinium, c => new Warning(c, "PS4 trophy", "missing platinium trophy"));
Check(configuration, _ => points < 950 || points > 1050, c => new Warning(c, "PS4 trophy", $"total points {points} not in the 950-1050 range"));
Check(configuration, c => string.IsNullOrEmpty(c.Version), c => new Warning(c, "PS4 title", "missing version"));
Check(configuration, c => c.TitleName is null, c => new Warning(c, "PS4 title", "missing Title name"));
Check(configuration, c => c.TitleDescription is null, c => new Warning(c, "PS4 title", "missing Title description"));
CheckImage(configuration, "PS4 title", configuration.TitleImagePath, "Title image", 320, 176);
Check(configuration, c => c.Zones.Count == 0, c => new Warning(c, "PS4 zone", "missing zone"));
}
}
private void Check(Ps4Zone zone)
{
RemoveWarnings(Enumerable.Repeat(zone, 1));
zone.Warnings = null;
Check(zone, c => !c.Languages.Any(l => l.IsSelected), c => new Warning(c, "PS4 zone", "no languages selected"));
Check(zone, c => string.IsNullOrEmpty(c.NpCommId), c => new Warning(c, "PS4 zone", "missing NpCommId"));
Check(zone, c => string.IsNullOrEmpty(c.TrpFilePath), c => new Warning(c, "PS4 zone", "missing trp file"));
}
private void Check(Ps5Configuration configuration)
{
RemoveWarnings(Enumerable.Repeat(configuration, 1));
configuration.Warnings = null;
HashSet<int> ids = new HashSet<int>();
bool hasPlatinium = false;
int points = 0;
foreach (Ps5Trophy trophy in Game.Challenges.SelectMany(c => c.PlatformChallenges.OfType<Ps5Trophy>()))
{
Check(configuration, _ => !ids.Add(trophy.Id), c => new Warning(c, "PS5 trophy", $"duplicate id {trophy.Id}"));
Check(configuration, _ => hasPlatinium && trophy.Grade == TrophyGrade.Platinium, c => new Warning(c, "PS5 trophy", "more than one platinium trophy"));
hasPlatinium |= trophy.Grade == TrophyGrade.Platinium;
points += trophy.Grade.ToPoints();
}
if (ids.Count > 0)
{
Check(configuration, _ => !ids.OrderBy(i => i).SequenceEqual(Enumerable.Range(0, ids.Max() + 1)), c => new Warning(c, "PS5 trophy", $"missing some ids {string.Join(", ", Enumerable.Range(0, ids.Max() + 1).Except(ids))}"));
Check(configuration, _ => !hasPlatinium, c => new Warning(c, "PS5 trophy", "missing platinium trophy"));
Check(configuration, _ => points < 950 || points > 1050, c => new Warning(c, "PS5 trophy", $"total points {points} not in the 950-1050 range"));
Check(configuration, c => string.IsNullOrEmpty(c.Version), c => new Warning(c, "PS5 title", "missing version"));
Check(configuration, c => c.TitleName is null, c => new Warning(c, "PS5 title", "missing Title name"));
CheckImage(configuration, "PS5 title", configuration.TitleImagePath, "Title image", 512, 512);
Check(configuration, c => !c.Languages.Any(l => l.IsSelected), c => new Warning(c, "PS5 settings", "no languages selected"));
Check(configuration, c => string.IsNullOrEmpty(c.SettingsFilePath), c => new Warning(c, "PS5 settings", "missing settings file"));
}
}
private void Check(XBoxOneConfiguration configuration)
{
RemoveWarnings(Enumerable.Repeat(configuration, 1));
configuration.Warnings = null;
HashSet<int> ids = new HashSet<int>();
int points = 0;
foreach (XBoxOneAchievement achievement in Game.Challenges.SelectMany(c => c.PlatformChallenges.OfType<XBoxOneAchievement>()))
{
Check(configuration, _ => !ids.Add(achievement.Id), c => new Warning(c, "XBOX ONE achievement", $"duplicate id {achievement.Id}"));
if (achievement.IsBaseAchievement)
{
points += achievement.Gamerscore;
}
}
if (ids.Count > 0)
{
Check(configuration, _ => points != 1000, c => new Warning(c, "XBOX ONE achievement", $"total points for base achievements {points} is not equal to 1000"));
Check(configuration, c => !c.Languages.Any(l => l.IsSelected), c => new Warning(c, "XBOX ONE settings", "no languages selected"));
Check(configuration, c => string.IsNullOrEmpty(c.SettingsFilePath), c => new Warning(c, "XBOX ONE settings", "missing settings file"));
}
}
private void Check(XBoxSeriesXConfiguration configuration)
{
RemoveWarnings(Enumerable.Repeat(configuration, 1));
configuration.Warnings = null;
HashSet<int> ids = new HashSet<int>();
int points = 0;
foreach (XBoxSeriesXAchievement achievement in Game.Challenges.SelectMany(c => c.PlatformChallenges.OfType<XBoxSeriesXAchievement>()))
{
Check(configuration, _ => !ids.Add(achievement.Id), c => new Warning(c, "XBOX SERIES X achievement", $"duplicate id {achievement.Id}"));
if (achievement.IsBaseAchievement)
{
points += achievement.Gamerscore;
}
}
if (ids.Count > 0)
{
Check(configuration, _ => points != 1000, c => new Warning(c, "XBOX SERIES X achievement", $"total points for base achievements {points} is not equal to 1000"));
Check(configuration, c => !c.Languages.Any(l => l.IsSelected), c => new Warning(c, "XBOX SERIES X settings", "no languages selected"));
Check(configuration, c => string.IsNullOrEmpty(c.SettingsFilePath), c => new Warning(c, "XBOX SERIES X settings", "missing settings file"));
}
}
private void Check(StadiaConfiguration configuration)
{
RemoveWarnings(Enumerable.Repeat(configuration, 1));
configuration.Warnings = null;
HashSet<int> ids = new HashSet<int>();
foreach (StadiaAchievement achievement in Game.Challenges.SelectMany(c => c.PlatformChallenges.OfType<StadiaAchievement>()))
{
Check(configuration, _ => !ids.Add(achievement.Id), c => new Warning(c, "Stadia achievement", $"duplicate id {achievement.Id}"));
}
if (ids.Count > 0)
{
Check(configuration, c => !c.Languages.Any(l => l.IsSelected), c => new Warning(c, "Stadia settings", "no languages selected"));
if (configuration.GenerateExcel)
{
Check(configuration, c => string.IsNullOrEmpty(c.ExcelFilePath), c => new Warning(c, "Stadia excel", "missing excel file"));
}
if (configuration.SyncToStoreFront)
{
Check(configuration, c => string.IsNullOrEmpty(c.StoreFrontFilePath), c => new Warning(c, "Stadia store front", "missing store front file"));
}
}
}
private void Check(AChallenge item, bool checkConfigs)
{
RemoveWarnings(Enumerable.Repeat(item, 1));
item.Warnings = null;
if (item is Challenge challenge)
{
Check(challenge, c => c.Name is null, c => new Warning(c, "common", "missing Name"));
Check(challenge, c => c.Objective is null, c => new Warning(c, "common", "missing Objective"));
foreach (AChallenge platformChallenge in challenge.PlatformChallenges)
{
Check(platformChallenge, false);
}
}
else if (item is Ps4Trophy ps4)
{
foreach (Ps4Zone zone in Game.Ps4Configuration.Zones)
{
foreach (Language language in zone.Languages.Where(l => l.IsSelected).Select(l => l.Value.Language))
{
Check(
ps4,
c => c.Challenge.Name is null || string.IsNullOrEmpty(c.Challenge.Name.GetTranslation(language)),
c => new Warning(c, "PS4 tropy", $"missing Name translation for {language.Name} in zone {zone.Name}"));
Check(
ps4,
c => c.Challenge.Name?.GetTranslation(language)?.Length > Game.Settings.Ps4NameLimit,
c => new Warning(c, "PS4 tropy", $"Name translation for {language.Name} in zone {zone.Name} is longer than {Game.Settings.Ps4NameLimit}"));
Check(
ps4,
c => c.Challenge.Objective is null || string.IsNullOrEmpty(c.Challenge.Objective?.GetTranslation(language)),
c => new Warning(c, "PS4 tropy", $"missing Objective translation for {language.Name} in zone {zone.Name}"));
Check(
ps4,
c => c.Challenge.Objective?.GetTranslation(language)?.Length > Game.Settings.Ps4ObjectiveLimit,
c => new Warning(c, "PS4 tropy", $"Objective translation for {language.Name} in zone {zone.Name} is longer than {Game.Settings.Ps4ObjectiveLimit}"));
}
}
Check(ps4, c => c.Id < 0, c => new Warning(c, "PS4 trophy", "Id can't be negative"));
CheckImage(ps4, "PS4 trophy", ps4.ImagePath, "Image", 240, 240);
if (checkConfigs)
{
Check(Game.Ps4Configuration);
}
}
else if (item is Ps5Trophy ps5)
{
foreach (Language language in Game.Ps5Configuration.Languages.Where(l => l.IsSelected).Select(l => l.Value.Language))
{
Check(
ps5,
c => c.Challenge.Name is null || string.IsNullOrEmpty(c.Challenge.Name.GetTranslation(language)),
c => new Warning(c, "PS5 tropy", $"missing Name translation for {language.Name}"));
Check(
ps5,
c => c.Challenge.Name?.GetTranslation(language)?.Length > Game.Settings.Ps4NameLimit,
c => new Warning(c, "PS5 tropy", $"Name translation for {language.Name} is longer than {Game.Settings.Ps4NameLimit}"));
Check(
ps5,
c => c.Challenge.Objective is null || string.IsNullOrEmpty(c.Challenge.Objective?.GetTranslation(language)),
c => new Warning(c, "PS5 tropy", $"missing Objective translation for {language.Name}"));
Check(
ps5,
c => c.Challenge.Objective?.GetTranslation(language)?.Length > Game.Settings.Ps4ObjectiveLimit,
c => new Warning(c, "PS5 tropy", $"Objective translation for {language.Name} is longer than {Game.Settings.Ps4ObjectiveLimit}"));
}
Check(ps5, c => c.Id < 0, c => new Warning(c, "PS5 trophy", "Id can't be negative"));
CheckImage(ps5, "PS5 trophy", ps5.ImagePath, "Image", 512, 512);
if (checkConfigs)
{
Check(Game.Ps5Configuration);
}
}
else if (item is XBoxOneAchievement xBoxOne)
{
foreach (Language language in Game.XBoxOneConfiguration.Languages.Where(l => l.IsSelected).Select(l => l.Value.Language))
{
Check(
xBoxOne,
c => c.Challenge.Name is null || string.IsNullOrEmpty(c.Challenge.Name.GetTranslation(language)),
c => new Warning(c, "XBOX ONE achievement", $"missing Name translation for {language.Name}"));
Check(
xBoxOne,
c => c.Challenge.Name?.GetTranslation(language)?.Length > Game.Settings.XBoxOneNameLimit,
c => new Warning(c, "XBOX ONE achievement", $"Name translation for {language.Name} is longer than {Game.Settings.XBoxOneNameLimit}"));
Check(
xBoxOne,
c => c.LockedObjective != null && string.IsNullOrEmpty(c.LockedObjective.GetTranslation(language)),
c => new Warning(c, "XBOX ONE achievement", $"missing Locked objective translation for {language.Name}"));
Check(
xBoxOne,
c => c.LockedObjective?.GetTranslation(language)?.Length > Game.Settings.XBoxOneObjectiveLimit,
c => new Warning(c, "XBOX ONE achievement", $"Locked objective translation for {language.Name} is longer than {Game.Settings.XBoxOneObjectiveLimit}"));
Check(
xBoxOne,
c => c.UnlockedObjective != null && string.IsNullOrEmpty(c.UnlockedObjective.GetTranslation(language)),
c => new Warning(c, "XBOX ONE achievement", $"missing Unlocked objective translation for {language.Name}"));
Check(
xBoxOne,
c => c.UnlockedObjective?.GetTranslation(language)?.Length > Game.Settings.XBoxOneObjectiveLimit,
c => new Warning(c, "XBOX ONE achievement", $"Unlocked objective translation for {language.Name} is longer than {Game.Settings.XBoxOneObjectiveLimit}"));
if (xBoxOne.LockedObjective is null || xBoxOne.UnlockedObjective is null)
{
Check(
xBoxOne,
c => c.Challenge.Objective is null || string.IsNullOrEmpty(c.Challenge.Objective.GetTranslation(language)),
c => new Warning(c, "XBOX ONE achievement", $"missing Objective translation for {language.Name}"));
Check(
xBoxOne,
c => c.Challenge.Objective?.GetTranslation(language)?.Length > Game.Settings.XBoxOneObjectiveLimit,
c => new Warning(c, "XBOX ONE achievement", $"Objective translation for {language.Name} is longer than {Game.Settings.XBoxOneObjectiveLimit}"));
}
}
Check(xBoxOne, c => c.Gamerscore <= 0, c => new Warning(c, "XBOX ONE achievement", "no gamerscore"));
Check(xBoxOne, c => c.Gamerscore > 200, c => new Warning(c, "XBOX ONE achievement", "maximum gamerscore value is 200"));
Check(xBoxOne, c => string.IsNullOrEmpty(c.NameId), c => new Warning(c, "XBOX ONE achievement", "missing NameId"));
Check(xBoxOne, c => string.IsNullOrEmpty(c.LockedObjectiveId), c => new Warning(c, "XBOX ONE achievement", "missing LockedObjectiveId"));
Check(xBoxOne, c => string.IsNullOrEmpty(c.UnlockedObjectiveId), c => new Warning(c, "XBOX ONE achievement", "missing UnlockedObjectiveId"));
CheckImage(xBoxOne, "XBOX ONE achievement", xBoxOne.ImagePath, "Image", 1920, 1080);
if (checkConfigs)
{
Check(Game.XBoxOneConfiguration);
}
}
else if (item is XBoxSeriesXAchievement xBoxSeriesX)
{
foreach (Language language in Game.XBoxSeriesXConfiguration.Languages.Where(l => l.IsSelected).Select(l => l.Value.Language))
{
Check(
xBoxSeriesX,
c => c.Challenge.Name is null || string.IsNullOrEmpty(c.Challenge.Name.GetTranslation(language)),
c => new Warning(c, "XBOX SERIES X achievement", $"missing Name translation for {language.Name}"));
Check(
xBoxSeriesX,
c => c.Challenge.Name?.GetTranslation(language)?.Length > Game.Settings.XBoxSeriesXNameLimit,
c => new Warning(c, "XBOX SERIES X achievement", $"Name translation for {language.Name} is longer than {Game.Settings.XBoxSeriesXNameLimit}"));
Check(
xBoxSeriesX,
c => c.LockedObjective != null && string.IsNullOrEmpty(c.LockedObjective.GetTranslation(language)),
c => new Warning(c, "XBOX SERIES X achievement", $"missing Locked objective translation for {language.Name}"));
Check(
xBoxSeriesX,
c => c.LockedObjective?.GetTranslation(language)?.Length > Game.Settings.XBoxSeriesXObjectiveLimit,
c => new Warning(c, "XBOX SERIES X achievement", $"Locked objective translation for {language.Name} is longer than {Game.Settings.XBoxSeriesXObjectiveLimit}"));
Check(
xBoxSeriesX,
c => c.UnlockedObjective != null && string.IsNullOrEmpty(c.UnlockedObjective.GetTranslation(language)),
c => new Warning(c, "XBOX SERIES X achievement", $"missing Unlocked objective translation for {language.Name}"));
Check(
xBoxSeriesX,
c => c.UnlockedObjective?.GetTranslation(language)?.Length > Game.Settings.XBoxSeriesXObjectiveLimit,
c => new Warning(c, "XBOX SERIES X achievement", $"Unlocked objective translation for {language.Name} is longer than {Game.Settings.XBoxSeriesXObjectiveLimit}"));
if (xBoxSeriesX.LockedObjective is null || xBoxSeriesX.UnlockedObjective is null)
{
Check(
xBoxSeriesX,
c => c.Challenge.Objective is null || string.IsNullOrEmpty(c.Challenge.Objective.GetTranslation(language)),
c => new Warning(c, "XBOX SERIES X achievement", $"missing Objective translation for {language.Name}"));
Check(
xBoxSeriesX,
c => c.Challenge.Objective?.GetTranslation(language)?.Length > Game.Settings.XBoxSeriesXObjectiveLimit,
c => new Warning(c, "XBOX SERIES X achievement", $"Objective translation for {language.Name} is longer than {Game.Settings.XBoxSeriesXObjectiveLimit}"));
}
}
Check(xBoxSeriesX, c => c.Gamerscore <= 0, c => new Warning(c, "XBOX SERIES X achievement", "no gamerscore"));
Check(xBoxSeriesX, c => c.Gamerscore > 200, c => new Warning(c, "XBOX SERIES X achievement", "maximum gamerscore value is 200"));
Check(xBoxSeriesX, c => string.IsNullOrEmpty(c.NameId), c => new Warning(c, "XBOX SERIES X achievement", "missing NameId"));
Check(xBoxSeriesX, c => string.IsNullOrEmpty(c.LockedObjectiveId), c => new Warning(c, "XBOX SERIES X achievement", "missing LockedObjectiveId"));
Check(xBoxSeriesX, c => string.IsNullOrEmpty(c.UnlockedObjectiveId), c => new Warning(c, "XBOX SERIES X achievement", "missing UnlockedObjectiveId"));
CheckImage(xBoxSeriesX, "XBOX SERIES X achievement", xBoxSeriesX.ImagePath, "Image", 1920, 1080);
if (checkConfigs)
{
Check(Game.XBoxSeriesXConfiguration);
}
}
else if (item is StadiaAchievement stadia)
{
foreach (Language language in Game.StadiaConfiguration.Languages.Where(l => l.IsSelected).Select(l => l.Value.Language))
{
Check(
stadia,
c => c.LockedName != null && string.IsNullOrEmpty(c.LockedName.GetTranslation(language)),
c => new Warning(c, "Stadia achievement", $"missing Locked name translation for {language.Name}"));
Check(
stadia,
c => c.LockedName?.GetTranslation(language)?.Length > Game.Settings.StadiaNameLimit,
c => new Warning(c, "Stadia achievement", $"Locked name translation for {language.Name} is longer than {Game.Settings.StadiaNameLimit}"));
Check(
stadia,
c => c.UnlockedName != null && string.IsNullOrEmpty(c.UnlockedName.GetTranslation(language)),
c => new Warning(c, "Stadia achievement", $"missing Unlocked name translation for {language.Name}"));
Check(
stadia,
c => c.UnlockedName?.GetTranslation(language)?.Length > Game.Settings.StadiaNameLimit,
c => new Warning(c, "Stadia achievement", $"Unlocked name translation for {language.Name} is longer than {Game.Settings.StadiaNameLimit}"));
if (stadia.LockedName is null || stadia.UnlockedName is null)
{
Check(
stadia,
c => c.Challenge.Name is null || string.IsNullOrEmpty(c.Challenge.Name.GetTranslation(language)),
c => new Warning(c, "Stadia achievement", $"missing Name translation for {language.Name}"));
Check(
stadia,
c => c.Challenge.Name?.GetTranslation(language)?.Length > Game.Settings.StadiaNameLimit,
c => new Warning(c, "Stadia achievement", $"Name translation for {language.Name} is longer than {Game.Settings.StadiaNameLimit}"));
}
Check(
stadia,
c => c.LockedObjective != null && string.IsNullOrEmpty(c.LockedObjective.GetTranslation(language)),
c => new Warning(c, "Stadia achievement", $"missing Locked objective translation for {language.Name}"));
Check(
stadia,
c => c.LockedObjective?.GetTranslation(language)?.Length > Game.Settings.StadiaObjectiveLimit,
c => new Warning(c, "Stadia achievement", $"Locked objective translation for {language.Name} is longer than {Game.Settings.StadiaObjectiveLimit}"));
Check(
stadia,
c => c.UnlockedObjective != null && string.IsNullOrEmpty(c.UnlockedObjective.GetTranslation(language)),
c => new Warning(c, "Stadia achievement", $"missing Unlocked objective translation for {language.Name}"));
Check(
stadia,
c => c.UnlockedObjective?.GetTranslation(language)?.Length > Game.Settings.StadiaObjectiveLimit,
c => new Warning(c, "Stadia achievement", $"Unlocked objective translation for {language.Name} is longer than {Game.Settings.StadiaObjectiveLimit}"));
if (stadia.LockedObjective is null || stadia.UnlockedObjective is null)
{
Check(
stadia,
c => c.Challenge.Objective is null || string.IsNullOrEmpty(c.Challenge.Objective.GetTranslation(language)),
c => new Warning(c, "Stadia achievement", $"missing Objective translation for {language.Name}"));
Check(
stadia,
c => c.Challenge.Objective?.GetTranslation(language)?.Length > Game.Settings.StadiaObjectiveLimit,
c => new Warning(c, "Stadia achievement", $"Objective translation for {language.Name} is longer than {Game.Settings.StadiaObjectiveLimit}"));
}
}
CheckImage(stadia, "Stadia achievement", stadia.UnlockedImagePath, "Unlocked image", null, null);
if (!string.IsNullOrEmpty(stadia.LockedImagePath))
{
CheckImage(stadia, "Stadia achievement", stadia.LockedImagePath, "Locked image", null, null);
}
if (checkConfigs)
{
Check(Game.StadiaConfiguration);
}
}
}
}
}