From a39a861d22f582cf3c80ee9d963f0178836f3fec Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Thu, 19 Sep 2024 02:06:43 -0400 Subject: [PATCH] Program: Allow generating rotations even if the phase list is empty --- Rotationator/Program.cs | 61 +++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/Rotationator/Program.cs b/Rotationator/Program.cs index 0b46a0d..c4f0e50 100644 --- a/Rotationator/Program.cs +++ b/Rotationator/Program.cs @@ -1,4 +1,4 @@ -using System.CommandLine; +using System.CommandLine; using System.CommandLine.Invocation; using System.Text.Json; using OatmealDome.BinaryData; @@ -114,42 +114,51 @@ void Run(InvocationContext context) // Find phase start point // - DateTime loopTime = lastBaseTime; DateTime referenceNow = DateTime.UtcNow; - - int lastPhasesStartIdx = -1; - - for (int i = 0; i < lastPhases.Count; i++) - { - Dictionary phase = lastPhases[i]; - - DateTime phaseEndTime = loopTime.AddHours((int)phase["Time"]); - - if (referenceNow >= loopTime && phaseEndTime > referenceNow) - { - lastPhasesStartIdx = i; - break; - } - - loopTime = phaseEndTime; - } + + DateTime loopTime = lastBaseTime; DateTime baseTime; List currentPhases; - if (lastPhasesStartIdx != -1) + if (lastPhases.Count > 0) { - baseTime = loopTime; - currentPhases = lastPhases.Skip(lastPhasesStartIdx).Select(p => new GambitVersusPhase(p)).ToList(); + int lastPhasesStartIdx = -1; + + for (int i = 0; i < lastPhases.Count; i++) + { + Dictionary phase = lastPhases[i]; + + DateTime phaseEndTime = loopTime.AddHours((int)phase["Time"]); + + if (referenceNow >= loopTime && phaseEndTime > referenceNow) + { + lastPhasesStartIdx = i; + break; + } + + loopTime = phaseEndTime; + } + + if (lastPhasesStartIdx != -1) + { + baseTime = loopTime; + currentPhases = lastPhases.Skip(lastPhasesStartIdx).Select(p => new GambitVersusPhase(p)).ToList(); + } + else + { + throw new NotImplementedException("not supported yet"); + } + + // The last phase is set to 10 years, so correct this to the correct phase length. + currentPhases.Last().Length = phaseLength; } else { - throw new NotImplementedException("not supported yet"); + baseTime = lastBaseTime; + currentPhases = new List(); } - // The last phase is set to 10 years, so correct this to the correct phase length. - currentPhases.Last().Length = phaseLength; - // // Load the override phases //