diff --git a/Source/Parser/Functions/AchievementSetFunction.cs b/Source/Parser/Functions/AchievementSetFunction.cs index 0e140bff..ccac490d 100644 --- a/Source/Parser/Functions/AchievementSetFunction.cs +++ b/Source/Parser/Functions/AchievementSetFunction.cs @@ -44,7 +44,24 @@ public override bool Evaluate(InterpreterScope scope, out ExpressionBase result) set = context.Sets.FirstOrDefault(s => s.OwnerGameId == gameId.Value); if (set == null) + { set = context.Sets.FirstOrDefault(s => s.Title == title.Value); + + if (set != null) + { + if (id != null && id.Value > 0) + { + result = new ErrorExpression("Set with title '" + set.Title + "' already exists with id " + set.Id, id); + return false; + } + + if (gameId != null && gameId.Value > 0) + { + result = new ErrorExpression("Set with title '" + set.Title + "' already exists with game_id " + set.OwnerGameId, gameId); + return false; + } + } + } } if (set == null) @@ -77,17 +94,6 @@ public override bool Evaluate(InterpreterScope scope, out ExpressionBase result) } } - if ((set.Id != 0 || set.OwnerGameId != 0) && - set.Type.CanLoadWithBaseSet() && - context.Sets.Any(s => s.Id < AssetBase.FirstLocalId / 10)) - { - if (set.Id != 0) - result = new ErrorExpression("Could not find set " + set.Id, id); - else - result = new ErrorExpression("Could not find set for game " + set.OwnerGameId, gameId); - return false; - } - if (set.Id == 0) set.Id = set.OwnerSetId = AssetBase.FirstLocalId / 10 + context.Sets.Count + 1; if (set.OwnerGameId == 0) diff --git a/Source/ViewModels/AchievementSetViewModel.cs b/Source/ViewModels/AchievementSetViewModel.cs index db86560e..f70785d4 100644 --- a/Source/ViewModels/AchievementSetViewModel.cs +++ b/Source/ViewModels/AchievementSetViewModel.cs @@ -167,7 +167,18 @@ public void AssociateRACacheDirectory(string raCacheDirectory, List s.AchievementSet.Id == set.Id); + if (subset != null) + { + subset.PublishedAssets = PublishedAssets; + subset.LocalAssets = LocalAssets; + } + else + { + sets.Add(new AchievementSetViewModel(set, this)); + } + } } } } diff --git a/Source/ViewModels/GameViewModel.cs b/Source/ViewModels/GameViewModel.cs index 9917af74..6ce078ee 100644 --- a/Source/ViewModels/GameViewModel.cs +++ b/Source/ViewModels/GameViewModel.cs @@ -684,8 +684,15 @@ public void AssociateRACacheDirectory(string raCacheDirectory) { RACacheDirectory = raCacheDirectory; - foreach (var set in _achievementSets) - set.AssociateRACacheDirectory(raCacheDirectory); + var achievementSets = new List(_achievementSets); + foreach (var set in achievementSets) + { + if (set.AchievementSet.Type == AchievementSetType.Core || + !set.AchievementSet.Type.CanLoadWithBaseSet()) + { + set.AssociateRACacheDirectory(raCacheDirectory, _achievementSets); + } + } var coreSet = _achievementSets.First(); Title = coreSet.Title; diff --git a/Source/ViewModels/Navigation/AchievementsFolderNavigationViewModel.cs b/Source/ViewModels/Navigation/AchievementsFolderNavigationViewModel.cs index 34047134..1a46ffcb 100644 --- a/Source/ViewModels/Navigation/AchievementsFolderNavigationViewModel.cs +++ b/Source/ViewModels/Navigation/AchievementsFolderNavigationViewModel.cs @@ -36,5 +36,16 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e) base.OnPropertyChanged(e); } + + public override bool Equals(object obj) + { + var that = obj as AchievementsFolderNavigationViewModel; + return (that != null && ReferenceEquals(_achievementSet, that._achievementSet)); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } } diff --git a/Tests/Parser/Functions/AchievementSetFunctionTests.cs b/Tests/Parser/Functions/AchievementSetFunctionTests.cs index 003ef9ea..bdde4423 100644 --- a/Tests/Parser/Functions/AchievementSetFunctionTests.cs +++ b/Tests/Parser/Functions/AchievementSetFunctionTests.cs @@ -167,7 +167,7 @@ public void TestExistingById() } [Test] - public void TestExistingByIdNotFound() + public void TestExistingByWrongId() { var harness = new AchievementSetFunctionHarness(); harness.Context.Sets.Add(new AchievementSet @@ -180,10 +180,10 @@ public void TestExistingByIdNotFound() }); harness.Evaluate( "// #ID=1234\r\n" + - "set_id = achievement_set(\"Game Bonus\", id=6666)", + "set_id = achievement_set(\"Banana\", id=6666)", "2:10 achievement_set call failed\r\n" + - "- 2:43 Could not find set 6666" + "- 2:39 Set with title 'Banana' already exists with id 5555" ); } @@ -211,7 +211,7 @@ public void TestExistingByGameId() } [Test] - public void TestExistingByGameIdNotFound() + public void TestExistingByWrongGameId() { var harness = new AchievementSetFunctionHarness(); harness.Context.Sets.Add(new AchievementSet @@ -224,10 +224,10 @@ public void TestExistingByGameIdNotFound() }); harness.Evaluate( "// #ID=1234\r\n" + - "set_id = achievement_set(\"Game Bonus\", game_id=5555)", + "set_id = achievement_set(\"Banana\", game_id=5555)", "2:10 achievement_set call failed\r\n" + - "- 2:48 Could not find set for game 5555" + "- 2:44 Set with title 'Banana' already exists with game_id 6666" ); }