public WorkoutStepsList GetStepsForPart(int partNumber, ref WorkoutStepsList result, ref UInt16 partNumberCounter, ref int stepCounter) { for (int i = 0; i < Steps.Count; ++i) { IStep currentStep = Steps[i]; if (currentStep is WorkoutLinkStep) { WorkoutLinkStep linkStep = currentStep as WorkoutLinkStep; linkStep.GetStepsForPart(partNumber, ref result, ref partNumberCounter, ref stepCounter); } else { stepCounter += currentStep.StepCount; if (i != 0 && (currentStep.ForceSplitOnStep || stepCounter > Constants.MaxStepsPerWorkout)) { partNumberCounter++; stepCounter = currentStep.StepCount; } if (partNumberCounter == partNumber) { // Add step to result, it's in the right part result.Add(currentStep); } else if (partNumberCounter > partNumber) { break; } } } return result; }
private WorkoutStepsList UnrollRepeats(List<IStep> originalSteps, Workout parent) { WorkoutStepsList result = new WorkoutStepsList(parent); foreach(IStep currentStep in originalSteps) { bool copyOriginal = true; if (m_UnrollRepeats) { if (currentStep is RepeatStep) { RepeatStep currentRepeat = currentStep as RepeatStep; WorkoutStepsList unrolledRepeat; if (currentRepeat.Duration is RepeatCountDuration) { RepeatCountDuration duration = currentRepeat.Duration as RepeatCountDuration; copyOriginal = false; unrolledRepeat = UnrollRepeats(currentRepeat.StepsToRepeat, parent); for (int i = 0; i < duration.RepetitionCount; ++i) { foreach (IStep currentUnrolledStep in unrolledRepeat) { result.Add(currentUnrolledStep.Clone()); } } } } else if (currentStep is WorkoutLinkStep) { WorkoutLinkStep currentLink = currentStep as WorkoutLinkStep; WorkoutStepsList unrolledRepeat; copyOriginal = false; unrolledRepeat = UnrollRepeats(currentLink.LinkedWorkoutSteps, parent); foreach (IStep currentUnrolledStep in unrolledRepeat) { result.Add(currentUnrolledStep); } } } if (copyOriginal) { result.Add(currentStep.Clone()); } } return result; }