Skip to content

Commit

Permalink
Merge pull request #131 from OliBomby/dev
Browse files Browse the repository at this point in the history
Dev update 1.8.0.0
  • Loading branch information
OliBomby authored Nov 14, 2020
2 parents 71145a5 + e061482 commit 1e8c9a1
Show file tree
Hide file tree
Showing 274 changed files with 18,408 additions and 1,118 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Mapping_Tools.Classes.BeatmapHelper {
namespace Mapping_Tools.Classes.BeatmapHelper.BeatDivisors {
public interface IBeatDivisor : IEquatable<IBeatDivisor> {
double GetValue();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mapping_Tools.Classes.BeatmapHelper {
namespace Mapping_Tools.Classes.BeatmapHelper.BeatDivisors {
public class IrrationalBeatDivisor : IBeatDivisor {
public readonly double Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

using Newtonsoft.Json;

namespace Mapping_Tools.Classes.BeatmapHelper {
namespace Mapping_Tools.Classes.BeatmapHelper.BeatDivisors {
public class RationalBeatDivisor : IBeatDivisor {
/// <summary>
/// The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken, for example, 2 in 2/3.
Expand Down
374 changes: 254 additions & 120 deletions Mapping Tools/Classes/BeatmapHelper/Beatmap.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Mapping Tools/Classes/BeatmapHelper/BeatmapEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Mapping_Tools.Classes.Tools;
using System.Collections.Generic;
using System.IO;
using Mapping_Tools.Classes.ToolHelpers;

namespace Mapping_Tools.Classes.BeatmapHelper {
public class BeatmapEditor : Editor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mapping_Tools.Classes.BeatmapHelper
namespace Mapping_Tools.Classes.BeatmapHelper.Enums
{
/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mapping_Tools.Classes.BeatmapHelper {
namespace Mapping_Tools.Classes.BeatmapHelper.Enums {
public enum HitObjectType {
Circle,
Slider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mapping_Tools.Classes.HitsoundStuff {
namespace Mapping_Tools.Classes.BeatmapHelper.Enums {
/// <summary>
/// The hitsound placed into the hitobject.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace Mapping_Tools.Classes.SliderPathStuff {
namespace Mapping_Tools.Classes.BeatmapHelper.Enums {

/// <summary>
/// The Slider curve type relating to the osu beatmap.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mapping_Tools.Classes.HitsoundStuff {
namespace Mapping_Tools.Classes.BeatmapHelper.Enums {
/// <summary>
/// The types of samples used for inherited timing points and hitobjects themselves.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mapping_Tools.Classes.BeatmapHelper.Events {
/// <example>
/// Sample,56056,0,"soft-hitnormal.wav",30
/// </example>
public class StoryboardSoundSample : Event, IEquatable<StoryboardSoundSample>, IHasStartTime, IHasEndTime {
public class StoryboardSoundSample : Event, IEquatable<StoryboardSoundSample>, IHasStartTime, IHasEndTime, IComparable<StoryboardSoundSample> {
/// <summary>
/// The time when this sound event occurs.
/// </summary>
Expand Down Expand Up @@ -98,5 +98,11 @@ public int EndTime {
get => StartTime;
set => StartTime = value;
}

public int CompareTo(StoryboardSoundSample other) {
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
return StartTime.CompareTo(other.StartTime);
}
}
}
42 changes: 40 additions & 2 deletions Mapping Tools/Classes/BeatmapHelper/FileFormatHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Mapping_Tools.Classes.HitsoundStuff;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Mapping_Tools.Classes.BeatmapHelper.Enums;

namespace Mapping_Tools.Classes.BeatmapHelper {
/// <summary>
Expand Down Expand Up @@ -45,5 +47,41 @@ public static bool TryParseDouble(string str, out double result) {
public static bool TryParseInt(string str, out int result) {
return int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
}

public static void AddDictionaryToLines(Dictionary<string, TValue> dict, List<string> lines) {
lines.AddRange(dict.Select(kvp => kvp.Key + ":" + kvp.Value.Value));
}

public static void FillDictionary(Dictionary<string, TValue> dict, IEnumerable<string> lines) {
foreach (var split in lines.Select(SplitKeyValue)) {
dict[split[0]] = new TValue(split[1]);
}
}

public static string[] SplitKeyValue(string line) {
return line.Split(new[] { ':' }, 2);
}

public static IEnumerable<string> GetCategoryLines(IEnumerable<string> lines, string category, string[] categoryIdentifiers=null) {
if (categoryIdentifiers == null)
categoryIdentifiers = new[] { "[" };

bool atCategory = false;

foreach (string line in lines) {
if (atCategory && line != "") {
if (categoryIdentifiers.Any(o => line.StartsWith(o))) // Reached another category
{
yield break;
}
yield return line;
}
else {
if (line == category) {
atCategory = true;
}
}
}
}
}
}
129 changes: 115 additions & 14 deletions Mapping Tools/Classes/BeatmapHelper/HitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mapping_Tools.Classes.HitsoundStuff;
using Mapping_Tools.Classes.BeatmapHelper.BeatDivisors;
using Mapping_Tools.Classes.BeatmapHelper.Enums;
using Mapping_Tools.Classes.BeatmapHelper.SliderPathStuff;
using Mapping_Tools.Classes.MathUtil;
using Mapping_Tools.Classes.SliderPathStuff;
using Newtonsoft.Json;
using static Mapping_Tools.Classes.BeatmapHelper.FileFormatHelper;

Expand All @@ -32,6 +33,8 @@ public HitObject(Vector2 pos, double time, HitObjectType type, bool newCombo, in
bool normal, bool whistle, bool finish, bool clap, SampleSet sampleSet, SampleSet additionSet,
int index, double volume, string filename) {
Pos = pos;
// Let the end position be the same as the start position before changed later for sliders
EndPos = Pos;
Time = time;
SetObjectType(type);
NewCombo = newCombo;
Expand All @@ -50,6 +53,8 @@ public HitObject(Vector2 pos, double time, HitObjectType type, bool newCombo, in
public HitObject(Vector2 pos, double time, int type, int hitsounds, SampleSet sampleSet, SampleSet additionSet,
int index, double volume, string filename) {
Pos = pos;
// Let the end position be the same as the start position before changed later for sliders
EndPos = Pos;
Time = time;
SetObjectType(type);
SetHitsounds(hitsounds);
Expand All @@ -63,6 +68,8 @@ public HitObject(Vector2 pos, double time, int type, int hitsounds, SampleSet sa
public HitObject(double time, int hitsounds, SampleSet sampleSet, SampleSet additions) {
// Basic hitsoundind circle
Pos = new Vector2(256, 192);
// Let the end position be the same as the start position before changed later for sliders
EndPos = Pos;
Time = time;
SetObjectType(5);
SetHitsounds(hitsounds);
Expand Down Expand Up @@ -109,6 +116,9 @@ public HitObject(Editor_Reader.HitObject ob) {
}

Pos = new Vector2(ob.X, ob.Y);
// Let the end position be the same as the start position before changed later for sliders
EndPos = Pos;

Filename = ob.SampleFile;
SampleVolume = ob.SampleVolume;
SampleSet = (SampleSet) ob.SampleSet;
Expand All @@ -123,8 +133,26 @@ public string Line {
set => SetLine(value);
}

/// <summary>
/// Base position of hit object.
/// </summary>
public Vector2 Pos { get; set; }

/// <summary>
/// Position of slider end. By default is equal to the start position.
/// </summary>
public Vector2 EndPos { get; set; }

/// <summary>
/// Stacked position of hit object. Must be computed by beatmap.
/// </summary>
public Vector2 StackedPos { get; set; }

/// <summary>
/// Stacked slider end position of hit object. Must be computed by beatmap.
/// </summary>
public Vector2 StackedEndPos { get; set; }

public double Time { get; set; }

public int ObjectType {
Expand Down Expand Up @@ -206,6 +234,12 @@ private void SetEndTime(double value) {
TemporalLength = Repeat == 0 ? 0 : (value - Time) / Repeat;
}

/// <summary>
/// The stack count indicates the number of hit objects that this object is stacked upon.
/// Used for calculating stack offset.
/// </summary>
public int StackCount { get; set; }

// Special combined with greenline
[JsonProperty]
public double SliderVelocity { get; set; }
Expand Down Expand Up @@ -242,6 +276,9 @@ public void SetLine(string line) {
Pos = new Vector2(x, y);
else throw new BeatmapParsingException("Failed to parse coordinate of hit object.", line);

// Let the end position be the same as the start position before changed later for sliders
EndPos = Pos;

if (TryParseDouble(values[2], out var t))
Time = t;
else throw new BeatmapParsingException("Failed to parse time of hit object.", line);
Expand Down Expand Up @@ -477,6 +514,36 @@ public List<double> GetAllTloTimes(Timing timing) {
return times;
}

/// <summary>
/// Removes all hitounds and sets samplesets to auto.
/// Also clears hitsounds from timeline objects and clears body hitsounds.
/// </summary>
public void ResetHitsounds() {
SetHitsounds(1);
SampleSet = SampleSet.Auto;
AdditionSet = SampleSet.Auto;
SampleVolume = 0;
CustomIndex = 0;
Filename = string.Empty;
if (IsSlider) {
for (int i = 0; i < EdgeHitsounds.Count; i++) {
EdgeHitsounds[i] = 0;
}
for (int i = 0; i < EdgeSampleSets.Count; i++) {
EdgeSampleSets[i] = SampleSet.Auto;
}
for (int i = 0; i < EdgeAdditionSets.Count; i++) {
EdgeAdditionSets[i] = SampleSet.Auto;
}
}

foreach (var tlo in TimelineObjects) {
tlo.ResetHitsounds();
}

BodyHitsounds.Clear();
}

/// <summary>
/// </summary>
/// <param name="deltaTime"></param>
Expand All @@ -495,26 +562,48 @@ public void MoveEndTime(Timing timing, double deltaTime) {
ChangeTemporalTime(timing, deltaTime / Repeat);
}

public void CalculateSliderTemporalLength(Timing timing, bool useOwnSv) {
if (!IsSlider) return;
if (double.IsNaN(PixelLength) || PixelLength < 0 || CurvePoints.All(o => o == Pos)) {
TemporalLength = 0;
} else {
TemporalLength = useOwnSv
? timing.CalculateSliderTemporalLength(Time, PixelLength, SliderVelocity)
: timing.CalculateSliderTemporalLength(Time, PixelLength);
}
}

public void ChangeTemporalTime(Timing timing, double deltaTemporalTime) {
if (Repeat == 0) return;

if (IsSlider) {
var deltaLength = -10000 * timing.SliderMultiplier * deltaTemporalTime /
(UnInheritedTimingPoint.MpB *
SliderVelocity); // Divide by repeats because the endtime is multiplied by repeats
(double.IsNaN(SliderVelocity) ? -100 : SliderVelocity)); // Divide by repeats because the endtime is multiplied by repeats
PixelLength += deltaLength; // Change the pixel length to match the new time
}

// Change
TemporalLength += deltaTemporalTime;

// Move body objects
for (int i = 0; i <= Math.Min(Repeat, TimelineObjects.Count - 1); i++) {
UpdateTimelineObjectTimes();

BodyHitsounds.RemoveAll(s => s.Offset >= EndTime);
}

public void UpdateTimelineObjectTimes() {
for (int i = 0; i < Math.Min(Repeat + 1, TimelineObjects.Count); i++) {
double time = Math.Floor(Time + TemporalLength * i);
TimelineObjects[i].Time = time;
}
}

BodyHitsounds.RemoveAll(s => s.Offset >= EndTime);
/// <summary>
/// Calculates the <see cref="EndPos"/> for sliders.
/// </summary>
public void CalculateEndPosition() {
EndPos = IsSlider ? GetSliderPath().PositionAt(1) : Pos;
}

/// <summary>
Expand All @@ -526,6 +615,16 @@ public void Move(Vector2 delta) {
for (var i = 0; i < CurvePoints.Count; i++) CurvePoints[i] = CurvePoints[i] + delta;
}

/// <summary>
/// Apply a 2x2 transformation matrix to the positions and curve points.
/// </summary>
/// <param name="mat"></param>
public void Transform(Matrix2 mat) {
Pos = Matrix2.Mult(mat, Pos);
if (!IsSlider) return;
for (var i = 0; i < CurvePoints.Count; i++) CurvePoints[i] = Matrix2.Mult(mat, CurvePoints[i]);;
}

public bool ResnapSelf(Timing timing, IEnumerable<IBeatDivisor> beatDivisors, bool floor = true, TimingPoint tp = null,
TimingPoint firstTp = null) {
var newTime = GetResnappedTime(timing, beatDivisors, floor, tp, firstTp);
Expand All @@ -539,18 +638,29 @@ public bool ResnapEnd(Timing timing, IEnumerable<IBeatDivisor> beatDivisors, boo
// If there is a redline in the sliderbody then the sliderend gets snapped to a tick of the latest redline
if (!IsSlider || timing.TimingPoints.Any(o => o.Uninherited && o.Offset <= EndTime + 20 && o.Offset > Time))
return ResnapEndTime(timing, beatDivisors, floor, tp, firstTp);

return ResnapEndClassic(timing, beatDivisors, firstTp);
}

public bool ResnapEndTime(Timing timing, IEnumerable<IBeatDivisor> beatDivisors, bool floor = true, TimingPoint tp = null,
TimingPoint firstTp = null) {
var newTime = timing.Resnap(EndTime, beatDivisors, floor, tp: tp, firstTp: firstTp);

var deltaTime = newTime - EndTime;
MoveEndTime(timing, deltaTime);

return Math.Abs(deltaTime) > Precision.DOUBLE_EPSILON;
}

public bool ResnapEndClassic(Timing timing, IEnumerable<IBeatDivisor> beatDivisors, TimingPoint firstTp = null) {
var newTemporalLength = timing.ResnapDuration(Time, TemporalLength, beatDivisors, false, firstTp: firstTp);

var deltaTime = newTemporalLength - TemporalLength;
ChangeTemporalTime(timing, deltaTime);

return Math.Abs(deltaTime) > Precision.DOUBLE_EPSILON;
}

public bool ResnapPosition(GameMode mode, double circleSize) {
if (mode != GameMode.Mania) return false;
// Resnap X to the middle of the columns and Y to 192
Expand All @@ -564,15 +674,6 @@ public bool ResnapPosition(GameMode mode, double circleSize) {
return Math.Abs(dX) > Precision.DOUBLE_EPSILON || Math.Abs(dY) > Precision.DOUBLE_EPSILON;
}

public bool ResnapEndClassic(Timing timing, IEnumerable<IBeatDivisor> beatDivisors, TimingPoint firstTp = null) {
var newTemporalLength = timing.ResnapDuration(Time, TemporalLength, beatDivisors, false, firstTp: firstTp);

var deltaTime = newTemporalLength - TemporalLength;
ChangeTemporalTime(timing, deltaTime);

return Math.Abs(deltaTime) > Precision.DOUBLE_EPSILON;
}

public double GetResnappedTime(Timing timing, IEnumerable<IBeatDivisor> beatDivisors, bool floor = true, TimingPoint tp = null,
TimingPoint firstTp = null) {
return timing.Resnap(Time, beatDivisors, floor, tp: tp, firstTp: firstTp);
Expand Down
2 changes: 1 addition & 1 deletion Mapping Tools/Classes/BeatmapHelper/HitObjectComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;

namespace Mapping_Tools.Classes.BeatmapHelper {
class HitObjectComparer : IEqualityComparer<HitObject> {
public class HitObjectComparer : IEqualityComparer<HitObject> {
public bool CheckIsSelected { get; set; }
public bool CheckPosition { get; set; }
public bool CheckTime { get; set; }
Expand Down
Loading

0 comments on commit 1e8c9a1

Please sign in to comment.