/// <summary> /// Calls tickAction with timingPoint, time, beatCount, tickCount /// </summary> public static void ForEachTick(this Beatmap beatmap, int startTime, int endTime, int snapDivisor, Action <ControlPoint, double, int, int> tickAction) { var leftTimingPoint = beatmap.GetTimingPointAt(startTime); var timingPoints = beatmap.TimingPoints.GetEnumerator(); if (timingPoints.MoveNext()) { var timingPoint = timingPoints.Current; while (timingPoint != null) { var nextTimingPoint = timingPoints.MoveNext() ? timingPoints.Current : null; if (timingPoint.Offset < leftTimingPoint.Offset) { timingPoint = nextTimingPoint; continue; } if (timingPoint != leftTimingPoint && endTime + Beatmap.ControlPointLeniency < timingPoint.Offset) { break; } int tickCount = 0, beatCount = 0; var step = Math.Max(1, timingPoint.BeatDuration / snapDivisor); var sectionStartTime = timingPoint.Offset; var sectionEndTime = Math.Min(nextTimingPoint?.Offset ?? endTime, endTime); if (timingPoint == leftTimingPoint) { while (startTime < sectionStartTime) { sectionStartTime -= step; tickCount--; if (tickCount % snapDivisor == 0) { beatCount--; } } } for (var time = sectionStartTime; time < sectionEndTime + Beatmap.ControlPointLeniency; time += step) { if (startTime < time) { tickAction(timingPoint, time, beatCount, tickCount); } if (tickCount % snapDivisor == 0) { beatCount++; } tickCount++; } timingPoint = nextTimingPoint; } } }
public static OsuHitObject Parse(Beatmap beatmap, string line) { var values = line.Split(','); var x = int.Parse(values[0]); var y = int.Parse(values[1]); var startTime = double.Parse(values[2], CultureInfo.InvariantCulture); var flags = (HitObjectFlag)int.Parse(values[3]); var additions = (HitSoundAddition)int.Parse(values[4]); var timingPoint = beatmap.GetTimingPointAt((int)startTime); var controlPoint = beatmap.GetControlPointAt((int)startTime); var sampleSet = controlPoint.SampleSet; var additionsSampleSet = controlPoint.SampleSet; var customSampleSet = controlPoint.CustomSampleSet; var volume = controlPoint.Volume; if (flags.HasFlag(HitObjectFlag.Circle)) { return(OsuCircle.Parse(beatmap, values, x, y, startTime, flags, additions, timingPoint, controlPoint, sampleSet, additionsSampleSet, customSampleSet, volume)); } else if (flags.HasFlag(HitObjectFlag.Slider)) { return(OsuSlider.Parse(beatmap, values, x, y, startTime, flags, additions, timingPoint, controlPoint, sampleSet, additionsSampleSet, customSampleSet, volume)); } else if (flags.HasFlag(HitObjectFlag.Hold)) { return(OsuHold.Parse(beatmap, values, x, y, startTime, flags, additions, timingPoint, controlPoint, sampleSet, additionsSampleSet, customSampleSet, volume)); } else if (flags.HasFlag(HitObjectFlag.Spinner)) { return(OsuSpinner.Parse(beatmap, values, x, y, startTime, flags, additions, timingPoint, controlPoint, sampleSet, additionsSampleSet, customSampleSet, volume)); } return(null); }
public static OsuSlider Parse(Beatmap beatmap, string[] values, int x, int y, double startTime, HitObjectFlag flags, HitSoundAddition additions, ControlPoint timingPoint, ControlPoint controlPoint, SampleSet sampleSet, SampleSet additionsSampleSet, int customSampleSet, float volume) { var slider = values[5]; var sliderValues = slider.Split('|'); var curveType = LetterToCurveType(sliderValues[0]); var sliderControlPointCount = sliderValues.Length - 1; var sliderControlPoints = new List <OsuSliderControlPoint>(sliderControlPointCount); for (var i = 0; i < sliderControlPointCount; i++) { var controlPointValues = sliderValues[i + 1].Split(':'); var controlPointX = float.Parse(controlPointValues[0], CultureInfo.InvariantCulture); var controlPointY = float.Parse(controlPointValues[1], CultureInfo.InvariantCulture); sliderControlPoints.Add(new Vector2(controlPointX, controlPointY)); } var nodeCount = int.Parse(values[6]) + 1; var length = double.Parse(values[7], CultureInfo.InvariantCulture); var sliderMultiplierLessLength = length / beatmap.SliderMultiplier; var travelDurationBeats = sliderMultiplierLessLength / 100 * controlPoint.SliderMultiplier; var travelDuration = timingPoint.BeatDuration * travelDurationBeats; var sliderNodes = new List <OsuSliderNode>(nodeCount); for (var i = 0; i < nodeCount; i++) { var nodeStartTime = startTime + i * travelDuration; var nodeControlPoint = beatmap.GetTimingPointAt((int)nodeStartTime); sliderNodes.Add(new OsuSliderNode() { Time = nodeStartTime, SampleSet = nodeControlPoint.SampleSet, AdditionsSampleSet = nodeControlPoint.SampleSet, CustomSampleSet = nodeControlPoint.CustomSampleSet, Volume = nodeControlPoint.Volume, Additions = additions, }); } if (values.Length > 8) { var sliderAddition = values[8]; var sliderAdditionValues = sliderAddition.Split('|'); for (var i = 0; i < sliderAdditionValues.Length; i++) { var node = sliderNodes[i]; var nodeAdditions = (HitSoundAddition)int.Parse(sliderAdditionValues[i]); node.Additions = nodeAdditions; } } if (values.Length > 9) { var sampleAndAdditionSampleSet = values[9]; var sampleAndAdditionSampleSetValues = sampleAndAdditionSampleSet.Split('|'); for (var i = 0; i < sampleAndAdditionSampleSetValues.Length; i++) { var node = sliderNodes[i]; var sampleAndAdditionSampleSetValues2 = sampleAndAdditionSampleSetValues[i].Split(':'); var nodeSampleSet = (SampleSet)int.Parse(sampleAndAdditionSampleSetValues2[0]); var nodeAdditionsSampleSet = (SampleSet)int.Parse(sampleAndAdditionSampleSetValues2[1]); if (nodeSampleSet != 0) { node.SampleSet = nodeSampleSet; node.AdditionsSampleSet = nodeSampleSet; } if (nodeAdditionsSampleSet != 0) { node.AdditionsSampleSet = nodeAdditionsSampleSet; } } } string samplePath = string.Empty; if (values.Length > 10) { var special = values[10]; var specialValues = special.Split(':'); var objectSampleSet = (SampleSet)int.Parse(specialValues[0]); var objectAdditionsSampleSet = (SampleSet)int.Parse(specialValues[1]); var objectCustomSampleSet = int.Parse(specialValues[2]); var objectVolume = 0.0f; if (specialValues.Length > 3) { objectVolume = int.Parse(specialValues[3]); } if (specialValues.Length > 4) { samplePath = specialValues[4]; } if (objectSampleSet != 0) { sampleSet = objectSampleSet; additionsSampleSet = objectSampleSet; } if (objectAdditionsSampleSet != 0) { additionsSampleSet = objectAdditionsSampleSet; } if (objectCustomSampleSet != 0) { customSampleSet = objectCustomSampleSet; } if (objectVolume > 0.001f) { volume = objectVolume; } } return(new OsuSlider(sliderNodes, sliderControlPoints) { PlayfieldPosition = new Vector2(x, y), StartTime = startTime, Flags = flags, Additions = additions, SampleSet = sampleSet, AdditionsSampleSet = additionsSampleSet, CustomSampleSet = customSampleSet, Volume = volume, SamplePath = samplePath, // Slider specific CurveType = curveType, Length = length, TravelDurationBeats = travelDurationBeats, TravelDuration = travelDuration, }); }