Skip to content

Commit 16a29c3

Browse files
Add additional shuffle option
1 parent a499bab commit 16a29c3

File tree

4 files changed

+141
-11
lines changed

4 files changed

+141
-11
lines changed

MSURandomizerLibrary/MsuShuffleStyle.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ public enum MsuShuffleStyle
2323
/// Shuffle mode where for a given track, it'll include songs intended for other tracks. For special tracks such as the ALttP
2424
/// crystal get theme, it'll continue to only allow songs for that given track
2525
/// </summary>
26-
[Description("Chaos shuffle - shuffle in songs not meant for a given location, ignoring special tracks")]
26+
[Description("Chaos shuffle - shuffle full length songs not meant for a given location (ignoring short special jingles)")]
2727
ChaosNonSpecialTracks,
2828

29+
30+
/// <summary>
31+
/// Shuffle mode where for a given track, it'll include songs intended for other tracks, shuffling special tracks amongst
32+
/// each other and non special tracks amongst each other
33+
/// </summary>
34+
[Description("Chaos shuffle (jinglesanity) - shuffle all songs not meant for a given location (does not swap jingles for full songs and vice versa)")]
35+
ChaosJingleTracks,
36+
2937
/// <summary>
3038
/// Shuffle mode where literally any song can be picked. Even for special tracks such as
3139
/// </summary>
32-
[Description("Chaos shuffle (full chaos) - shuffle in songs not meant for a given location, including special tracks like the crystal get theme")]
40+
[Description("Chaos shuffle (allsanity) - shuffle all songs songs not meant for a given location (sometimes swaps full length and jingle songs)")]
3341
ChaosAllTracks
3442
}

MSURandomizerLibrary/Services/MsuSelectorService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ public MsuSelectorResponse CreateShuffledMsu(MsuSelectorRequest request)
148148
possibleTracks = possibleTracks.Where(t => !specialTrackNumbers.Contains(t.Number)).ToList();
149149
}
150150
}
151+
else if (request.ShuffleStyle == MsuShuffleStyle.ChaosJingleTracks)
152+
{
153+
if (msuTypeTrack.IsSpecial)
154+
{
155+
possibleTracks = possibleTracks.Where(t => specialTrackNumbers.Contains(t.Number)).ToList();
156+
}
157+
else
158+
{
159+
possibleTracks = possibleTracks.Where(t => !specialTrackNumbers.Contains(t.Number)).ToList();
160+
}
161+
}
151162
else if (request.ShuffleStyle == MsuShuffleStyle.ChaosAllTracks)
152163
{
153164
if (_random.Next(0, 100) < request.ChaosShuffleChance)

MSURandomizerLibraryTests/MsuSelectorServiceTests.cs

Lines changed: 118 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,14 @@ public void SpecialTracksMsuTest()
316316
new() { (1, 3) },
317317
new() { (1, 3) },
318318
},
319-
out var msuTypes, out var msus, new Dictionary<int, List<int>>() { { 1, new List<int>() { 2 } }}, 1);
319+
out var msuTypes, out var msus, new Dictionary<int, List<int>>() { { 1, new List<int>() { 2 } }}, [1]);
320320

321321
var anyNotMatchedTrack2 = false;
322322
var anyNotMatchedTrack3 = false;
323323

324+
var anyMatchedTrack2 = false;
325+
var anyMatchedTrack3 = false;
326+
324327
for (var i = 0; i < 10; i++)
325328
{
326329
var response = msuSelectService.CreateShuffledMsu(new MsuSelectorRequest()
@@ -340,16 +343,124 @@ public void SpecialTracksMsuTest()
340343

341344
if (tracks[1].OriginalTrackNumber != tracks[1].Number)
342345
{
343-
anyNotMatchedTrack2 = true;
346+
anyMatchedTrack2 = true;
344347
}
345348
if (tracks[2].OriginalTrackNumber != tracks[2].Number)
349+
{
350+
anyMatchedTrack3 = true;
351+
}
352+
353+
if (tracks[1].OriginalTrackNumber == tracks[0].Number)
354+
{
355+
anyNotMatchedTrack2 = true;
356+
}
357+
if (tracks[2].OriginalTrackNumber == tracks[0].Number)
346358
{
347359
anyNotMatchedTrack3 = true;
348360
}
349361
}
350362

351-
Assert.That(anyNotMatchedTrack2, Is.True);
352-
Assert.That(anyNotMatchedTrack3, Is.True);
363+
Assert.That(anyMatchedTrack2, Is.True);
364+
Assert.That(anyMatchedTrack3, Is.True);
365+
Assert.That(anyNotMatchedTrack2, Is.False);
366+
Assert.That(anyNotMatchedTrack3, Is.False);
367+
}
368+
369+
[Test]
370+
public void ChaosJingleTracksMsuTest()
371+
{
372+
var msuSelectService = CreateMsuSelectorService(new List<List<(int, int)>>()
373+
{
374+
new() { (1, 4) }
375+
},
376+
new List<List<(int, int)>>()
377+
{
378+
new() { (1, 4) },
379+
new() { (1, 4) },
380+
new() { (1, 4) },
381+
new() { (1, 4) },
382+
new() { (1, 4) },
383+
new() { (1, 4) },
384+
new() { (1, 4) },
385+
new() { (1, 4) },
386+
new() { (1, 4) },
387+
new() { (1, 4) },
388+
new() { (1, 4) },
389+
},
390+
out var msuTypes, out var msus, new Dictionary<int, List<int>>() { { 1, new List<int>() { 2 } }}, [1, 2]);
391+
392+
var anyNotMatchedTrack1 = false;
393+
var anyNotMatchedTrack2 = false;
394+
var anyNotMatchedTrack3 = false;
395+
var anyNotMatchedTrack4 = false;
396+
var anyMatchedTrack1 = false;
397+
var anyMatchedTrack2 = false;
398+
var anyMatchedTrack3 = false;
399+
var anyMatchedTrack4 = false;
400+
401+
for (var i = 0; i < 1000; i++)
402+
{
403+
var response = msuSelectService.CreateShuffledMsu(new MsuSelectorRequest()
404+
{
405+
Msus = msus,
406+
OutputMsuType = msuTypes.First(),
407+
OutputPath = msus.First().Path.Replace(".msu", "-output.msu"),
408+
EmptyFolder = false,
409+
OpenFolder = false,
410+
PrevMsu = null,
411+
ShuffleStyle = MsuShuffleStyle.ChaosJingleTracks
412+
});
413+
414+
var tracks = response.Msu?.Tracks.OrderBy(x => x.Number).ToList() ?? new List<Track>();
415+
416+
if (tracks[0].OriginalTrackNumber >= 3)
417+
{
418+
anyNotMatchedTrack1 = true;
419+
}
420+
if (tracks[1].OriginalTrackNumber >= 3)
421+
{
422+
anyNotMatchedTrack1 = true;
423+
}
424+
if (tracks[2].OriginalTrackNumber < 3)
425+
{
426+
anyNotMatchedTrack2 = true;
427+
}
428+
if (tracks[3].OriginalTrackNumber < 3)
429+
{
430+
anyNotMatchedTrack3 = true;
431+
}
432+
433+
if (tracks[0].OriginalTrackNumber != 1)
434+
{
435+
anyMatchedTrack1 = true;
436+
}
437+
if (tracks[1].OriginalTrackNumber != 2)
438+
{
439+
anyMatchedTrack2 = true;
440+
}
441+
if (tracks[2].OriginalTrackNumber != 3)
442+
{
443+
anyMatchedTrack3 = true;
444+
}
445+
if (tracks[3].OriginalTrackNumber != 4)
446+
{
447+
anyMatchedTrack4 = true;
448+
}
449+
450+
if (anyNotMatchedTrack1 && anyNotMatchedTrack2 && anyNotMatchedTrack3)
451+
{
452+
break;
453+
}
454+
}
455+
456+
Assert.That(anyNotMatchedTrack1, Is.False);
457+
Assert.That(anyNotMatchedTrack2, Is.False);
458+
Assert.That(anyNotMatchedTrack3, Is.False);
459+
Assert.That(anyNotMatchedTrack4, Is.False);
460+
Assert.That(anyMatchedTrack1, Is.True);
461+
Assert.That(anyMatchedTrack2, Is.True);
462+
Assert.That(anyMatchedTrack3, Is.True);
463+
Assert.That(anyMatchedTrack4, Is.True);
353464
}
354465

355466
[Test]
@@ -373,7 +484,7 @@ public void ChaosTracksMsuTest()
373484
new() { (1, 3) },
374485
new() { (1, 3) },
375486
},
376-
out var msuTypes, out var msus, new Dictionary<int, List<int>>() { { 1, new List<int>() { 2 } }}, 1);
487+
out var msuTypes, out var msus, new Dictionary<int, List<int>>() { { 1, new List<int>() { 2 } }}, [1]);
377488

378489
var anyNotMatchedTrack1 = false;
379490
var anyNotMatchedTrack2 = false;
@@ -614,12 +725,12 @@ public void SaveMsuTest()
614725
}
615726

616727

617-
private MsuSelectorService CreateMsuSelectorService(List<List<(int, int)>> msuTypeTracks, List<List<(int, int)>> msuTracks, out ICollection<MsuType> msuTypes, out ICollection<Msu> msus, Dictionary<int, List<int>>? pairs = null, int? specialTrack = null)
728+
private MsuSelectorService CreateMsuSelectorService(List<List<(int, int)>> msuTypeTracks, List<List<(int, int)>> msuTracks, out ICollection<MsuType> msuTypes, out ICollection<Msu> msus, Dictionary<int, List<int>>? pairs = null, List<int>? specialTracks = null)
618729
{
619730
var logger = TestHelpers.CreateMockLogger<MsuSelectorService>();
620731
var lookupLogger = TestHelpers.CreateMockLogger<MsuLookupService>();
621732
var msuDetailsService = TestHelpers.CreateMockMsuDetailsService(null, null);
622-
var msuTypeService = TestHelpers.CreateMockMsuTypeServiceMulti(msuTypeTracks, out var generatedMsuTypes, pairs, specialTrack);
733+
var msuTypeService = TestHelpers.CreateMockMsuTypeServiceMulti(msuTypeTracks, out var generatedMsuTypes, pairs, specialTracks);
623734
var msuUserOptionsService = TestHelpers.CreateMockMsuUserOptionsService(null);
624735
var msuCacheService = TestHelpers.CreateMockMsuCacheService();
625736

MSURandomizerLibraryTests/TestHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static IMsuTypeService CreateMockMsuTypeService(List<(int, int)> tracks,
7373
return CreateMockMsuTypeService(msuTypes);
7474
}
7575

76-
public static IMsuTypeService CreateMockMsuTypeServiceMulti(List<List<(int, int)>> msuTypeTracks, out List<MsuType> msuTypes, Dictionary<int, List<int>>? pairs = null, int? specialTrack = null)
76+
public static IMsuTypeService CreateMockMsuTypeServiceMulti(List<List<(int, int)>> msuTypeTracks, out List<MsuType> msuTypes, Dictionary<int, List<int>>? pairs = null, List<int>? specialTracks = null)
7777
{
7878
msuTypes = new List<MsuType>();
7979

@@ -95,7 +95,7 @@ public static IMsuTypeService CreateMockMsuTypeServiceMulti(List<List<(int, int)
9595
Number = x,
9696
Name = $"MSU Type {currentIndex} Track {x}",
9797
PairedTracks = pairs != null && pairs.ContainsKey(x) ? pairs[x] : null,
98-
IsSpecial = x == specialTrack
98+
IsSpecial = specialTracks?.Contains(x) == true
9999
})
100100
});
101101

0 commit comments

Comments
 (0)