Skip to content

Commit

Permalink
If AbsoluteRange is off Scale, Length, and Distance are relative now
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Aug 24, 2022
1 parent b087d33 commit a347d6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static TumourLayer GetDefaultLayer() {
Name = "Layer",
TumourCount = 0,
TumourStart = 0,
TumourEnd = 1,
TumourEnd = 256,
TumourLength = GetGraphState(15),
TumourScale = GetGraphState(30),
TumourRotation = GetGraphState(0),
Expand Down
16 changes: 13 additions & 3 deletions Mapping_Tools/Classes/Tools/TumourGenerating/TumourGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace Mapping_Tools.Classes.Tools.TumourGenerating {
/// All reconstruction hints must be used when reconstructing the slider.
/// </summary>
public class TumourGenerator {
private const double RelativePropertyScale = 256;

/// <summary>
/// The number of points per osu! pixel used to approximate the shape of the tumours.
/// </summary>
Expand All @@ -43,7 +45,7 @@ public class TumourGenerator {

public Random Random { get; set; } = new();

private List<double> layerLengths = new();
private readonly List<double> layerLengths = new();

/// <summary>
/// The lengths of the slider at the start of each layer in the last tumour generate call.
Expand All @@ -68,6 +70,7 @@ public bool TumourGenerate(HitObject ho, CancellationToken ct = default) {
return false;
}
var totalLength = pathWithHints.Path.Last!.Value.CumulativeLength;
var initialLength = totalLength;

// Reset the layer lengths
layerLengths.Clear();
Expand Down Expand Up @@ -110,6 +113,8 @@ public bool TumourGenerate(HitObject ho, CancellationToken ct = default) {
ct.ThrowIfCancellationRequested();

var length = tumourLayer.TumourLength.GetValue(ToProgress(nextDist, tumourStart, tumourEnd, totalLength));
if (!tumourLayer.UseAbsoluteRange)
length *= initialLength / RelativePropertyScale;
var endDist = Math.Min(nextDist + length, tumourEnd);

// Get which side the tumour should be on
Expand Down Expand Up @@ -137,12 +142,14 @@ public bool TumourGenerate(HitObject ho, CancellationToken ct = default) {
endT = MathHelper.Clamp((end.Value.CumulativeLength - nextDist) / length, 0, 1);
}

PlaceTumour(pathWithHints, tumourLayer, layer, start, end, startT, endT, Math.Max(0, tumourStart), Math.Min(totalLength, tumourEnd), side);
PlaceTumour(pathWithHints, tumourLayer, layer, start, end, startT, endT, Math.Max(0, tumourStart), Math.Min(totalLength, tumourEnd), side, initialLength);

current = start;
}

var dist = Math.Max(1, tumourLayer.TumourDistance.GetValue(ToProgress(nextDist, tumourStart, tumourEnd, totalLength)));
if (!tumourLayer.UseAbsoluteRange)
dist *= initialLength / RelativePropertyScale;
nextDist += dist;
}
}
Expand Down Expand Up @@ -187,9 +194,10 @@ public bool TumourGenerate(HitObject ho, CancellationToken ct = default) {
/// <param name="tumourStart">The start distance of the sequence of tumours to tumour layer values</param>
/// <param name="tumourEnd">The end distance of the sequence of tumours to tumour layer values</param>
/// <param name="otherSide">Whether to place the tumour on the other side of the slider</param>
/// <param name="initialLength">The initial pixel length of the slider. Determines the scale of the tumour.</param>
public void PlaceTumour([NotNull]PathWithHints pathWithHints, [NotNull]ITumourLayer tumourLayer, int layer,
[NotNull]LinkedListNode<PathPoint> start, [NotNull]LinkedListNode<PathPoint> end,
double startTemplateT, double endTemplateT, double tumourStart, double tumourEnd, bool otherSide) {
double startTemplateT, double endTemplateT, double tumourStart, double tumourEnd, bool otherSide, double initialLength) {
var path = pathWithHints.Path;
if (start.List != path) {
throw new ArgumentException(@"Start node has to be part of the provided path.", nameof(start));
Expand Down Expand Up @@ -253,6 +261,8 @@ public void PlaceTumour([NotNull]PathWithHints pathWithHints, [NotNull]ITumourLa

var length = Vector2.Distance(start.Value.OgPos, end.Value.OgPos);
var scale = tumourLayer.TumourScale.GetValue(startProg) * Scalar;
if (!tumourLayer.UseAbsoluteRange)
scale *= initialLength / RelativePropertyScale;
var rotation = MathHelper.DegreesToRadians(tumourLayer.TumourRotation.GetValue(startProg));

// Setup tumour template with the correct shape
Expand Down
2 changes: 1 addition & 1 deletion Mapping_Tools/Viewmodels/TumourGeneratorVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public TumourGeneratorVm() {
try {
var newLayer = TumourLayer.GetDefaultLayer();
newLayer.Name = "Layer " + (TumourLayers.Count + 1);
newLayer.TumourEnd = layerRangeSliderMaxes.LastOrDefault() * 10;
newLayer.TumourEnd = layerRangeSliderMaxes.Count > 0 ? layerRangeSliderMaxes.LastOrDefault() : PreviewHitObject.PixelLength;
TumourLayers.Insert(CurrentLayerIndex + 1, newLayer);
CurrentLayerIndex++;
RegeneratePreview();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
SmallChange="{Binding TumourRangeSliderSmallChange}"
ToolTip="The progression along the slider where to end the placement of tumours. 0 is the slider head, 1 is the slider end. If 'Absolute range' is checked, then this distance is expressed in osu! pixels."/>
<CheckBox IsChecked="{Binding CurrentLayer.UseAbsoluteRange}" Margin="0 10 0 0"
Content="Absolute range" ToolTip="Toggle this to change the meaning of the Start and End fields to mean length in osu! pixels instead of length relative to the length of the slider."/>
Content="Absolute range" ToolTip="Enable this to change the meaning of the Scale, Length, Distance, Start, and End fields to mean length in osu! pixels instead of length relative to the length of the slider."/>
<CheckBox IsChecked="{Binding CurrentLayer.Recalculate}" Margin="0 5 0 0"
Content="Recalculate" ToolTip="Whether to recalculate the distances and angles of the slider before applying this layer. If true, tumours will be placed on top of tumours of the previous layers as if they were part of the slider, instead of merging with those tumours."/>
</StackPanel>
Expand Down

0 comments on commit a347d6a

Please sign in to comment.