Skip to content

Commit

Permalink
Add only necessary anchors to the first dummy DD level
Browse files Browse the repository at this point in the history
  • Loading branch information
iminashi committed Apr 29, 2023
1 parent 384b7f8 commit 8c0d4ba
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion XmlCombiners/InstrumentalCombiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,42 @@ public void Save(string fileName, bool coercePhrases = false, bool generateDummy
CoercePhrasesAndSections(CombinedArrangement);

if (generateDummyDD && CombinedArrangement.Levels.Count == 1)
{
FixPhraseStartAnchors(CombinedArrangement);
GenerateDummyDD(CombinedArrangement);
}

var ver = string.IsNullOrWhiteSpace(versionString) ? "" : $" v{versionString}";
CombinedArrangement.XmlComments.Add(new RSXmlComment($"XML Combiner{ver}"));
CombinedArrangement.Save(fileName);
Console.WriteLine($"Saved combined file as {fileName}");
}

private static void FixPhraseStartAnchors(InstrumentalArrangement arr)
{
var anchors = arr.Levels[0].Anchors;

// Skip the COUNT and END phrases
for (int i = 1; i < arr.PhraseIterations.Count - 1; i++)
{
var piTime = arr.PhraseIterations[i].Time;
var activeAnchor = anchors.FindLast(a => a.Time <= piTime);

if (activeAnchor is not null && activeAnchor.Time != piTime)
{
anchors.InsertByTime(new Anchor(activeAnchor.Fret, piTime, activeAnchor.Width));
}
else if (activeAnchor is null)
{
var nextAnchor = anchors.Find(a => a.Time > piTime);
if (nextAnchor is not null)
{
nextAnchor.Time = piTime;
}
}
}
}

private static void GenerateDummyDD(InstrumentalArrangement arr)
{
var noGuitarPhraseIds = new HashSet<int>();
Expand Down Expand Up @@ -101,7 +129,8 @@ private static void GenerateDummyDD(InstrumentalArrangement arr)
}

// Add one empty level
var newlevelZero = new Level(0) { Anchors = arr.Levels[0].Anchors };
var necessaryAnchors = arr.Levels[0].Anchors.Where(a => arr.PhraseIterations.Exists(pi => pi.Time == a.Time)).ToList();
var newlevelZero = new Level(0) { Anchors = necessaryAnchors };
var newLevelOne = arr.Levels[0];
newLevelOne.Difficulty = 1;
arr.Levels = new List<Level> { newlevelZero, newLevelOne };
Expand Down

0 comments on commit 8c0d4ba

Please sign in to comment.