Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Beatmap "cutting" #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
105 changes: 96 additions & 9 deletions OppaiSharp/Beatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Beatmap
public int FormatVersion { get; internal set; }
public GameMode Mode { get; internal set; }
public string Title { get; internal set; }
public string TitleUnicode { get; internal set; }
public string TitleUnicode { get; internal set; }
public string Artist { get; internal set; }
public string ArtistUnicode { get; internal set; }

Expand All @@ -20,19 +20,105 @@ public class Beatmap
/// <summary>Difficulty name</summary>
public string Version { get; internal set; }

public int CountCircles { get; set; }
public int CountSliders { get; set; }
public int CountSpinners { get; set; }
private int _allCountCircles;
private int _allCountSliders;
private int _allCountSpinners;
private int _cutCountCircles;
private int _cutCountSliders;
private int _cutCountSpinners;

public int CountCircles
{
get
{
if (Cutting)
return _cutCountCircles;
return _allCountCircles;
}
set { _allCountCircles = value; }
}

public int CountSliders
{
get
{
if (Cutting)
return _cutCountSliders;
return _allCountSliders;
}
set { _allCountSliders = value; }
}

public int CountSpinners
{
get
{
if (Cutting)
return _cutCountSpinners;
return _allCountSpinners;
}
set { _allCountSpinners = value; }
}

public float HP { get; set; } = 5f;
public float CS { get; set; } = 5f;
public float OD { get; set; } = 5f;
public float AR { get; set; } = 5f;
public float SliderVelocity { get; set; } = 1f;
public float TickRate { get; set; } = 1f;
public bool Cutting { get; private set; } = false;
private List<HitObject> _allObjects = new List<HitObject>(512);
private List<HitObject> CutObjects { get; set; }
public List<HitObject> Objects
{
get
{
if (Cutting)
return CutObjects;
return _allObjects;
}
set { _allObjects = value; }
}

public List<Timing> TimingPoints { get; set; } = new List<Timing>(32);

public void Cut(int startTime, int endTime)
{
if (endTime <= 0)
throw new ArgumentException(nameof(endTime));
if (startTime < 0 || startTime > endTime)
throw new ArgumentException(nameof(endTime));
Cutting = true;
CutObjects = new List<HitObject>();
foreach (var o in _allObjects)
{
//Assuming chronological order
if (o.Time < startTime)
continue;
if (o.Time < endTime)
CutObjects.Add(o);
else
break;
}

public List<HitObject> Objects { get; } = new List<HitObject>(512);
public List<Timing> TimingPoints { get; } = new List<Timing>(32);
_cutCountCircles = 0;
_cutCountSpinners = 0;
_cutCountSliders = 0;
foreach (var o in CutObjects)
{
if ((o.Type & HitObjectType.Circle) != 0)
_cutCountCircles++;
else if ((o.Type & HitObjectType.Slider) != 0)
_cutCountSliders++;
else if ((o.Type & HitObjectType.Spinner) != 0)
_cutCountSpinners++;
}
}

public void ResetCut()
{
Cutting = false;
}
public static Beatmap Read(StreamReader reader) => Parser.Read(reader);

internal Beatmap() { }
Expand Down Expand Up @@ -67,8 +153,8 @@ public override string ToString()
+ $" hp={HP}, cs={CS}, od={OD}, ar={AR}, sv={SliderVelocity}, tick_rate={TickRate}, "
+ $"tpoints=[ {timingPoints} ], objects=[ {objects} ] }}";
}

public int GetMaxCombo()
public int GetMaxCombo(bool onlyCount300=false)
{
int res = 0;
int tIndex = -1;
Expand All @@ -77,7 +163,8 @@ public int GetMaxCombo()

foreach (HitObject obj in Objects)
{
if ((obj.Type & HitObjectType.Slider) == 0) {
if (onlyCount300 || (obj.Type & HitObjectType.Slider) == 0)
{
//non-sliders add 1 combo
res++;
continue;
Expand Down