Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions Source/Parser/Functions/AchievementSetFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion Source/ViewModels/AchievementSetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,18 @@ public void AssociateRACacheDirectory(string raCacheDirectory, List<AchievementS
foreach (var set in PublishedAssets.Sets)
{
if (!ReferenceEquals(_achievementSet, set))
sets.Add(new AchievementSetViewModel(set, this));
{
var subset = sets.FirstOrDefault(s => s.AchievementSet.Id == set.Id);
if (subset != null)
{
subset.PublishedAssets = PublishedAssets;
subset.LocalAssets = LocalAssets;
}
else
{
sets.Add(new AchievementSetViewModel(set, this));
}
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions Source/ViewModels/GameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,15 @@ public void AssociateRACacheDirectory(string raCacheDirectory)
{
RACacheDirectory = raCacheDirectory;

foreach (var set in _achievementSets)
set.AssociateRACacheDirectory(raCacheDirectory);
var achievementSets = new List<AchievementSetViewModel>(_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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
12 changes: 6 additions & 6 deletions Tests/Parser/Functions/AchievementSetFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void TestExistingById()
}

[Test]
public void TestExistingByIdNotFound()
public void TestExistingByWrongId()
{
var harness = new AchievementSetFunctionHarness();
harness.Context.Sets.Add(new AchievementSet
Expand All @@ -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"
);
}

Expand Down Expand Up @@ -211,7 +211,7 @@ public void TestExistingByGameId()
}

[Test]
public void TestExistingByGameIdNotFound()
public void TestExistingByWrongGameId()
{
var harness = new AchievementSetFunctionHarness();
harness.Context.Sets.Add(new AchievementSet
Expand All @@ -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"
);
}

Expand Down
Loading