mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 14:33:21 +08:00
Fix up combo colours + a few nullrefs.
This commit is contained in:
parent
854212a7aa
commit
072eea82ea
@ -9,6 +9,7 @@ using osu.Game.Modes.Osu.Objects.Drawables;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
using OpenTK.Graphics;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Beatmaps
|
||||
{
|
||||
@ -16,12 +17,25 @@ namespace osu.Game.Modes.Osu.Beatmaps
|
||||
{
|
||||
public Beatmap<OsuHitObject> Convert(Beatmap original)
|
||||
{
|
||||
List<OsuHitObject> converted = convertHitObjects(original.HitObjects, original.BeatmapInfo?.StackLeniency ?? 0.7f);
|
||||
|
||||
converted.ForEach(c => c.SetDefaultsFromBeatmap(original));
|
||||
|
||||
return new Beatmap<OsuHitObject>(original)
|
||||
{
|
||||
HitObjects = convertHitObjects(original.HitObjects, original.BeatmapInfo?.StackLeniency ?? 0.7f)
|
||||
HitObjects = converted
|
||||
};
|
||||
}
|
||||
|
||||
private List<OsuHitObject> convertHitObjects(List<HitObject> hitObjects, float stackLeniency)
|
||||
{
|
||||
List<OsuHitObject> converted = hitObjects.Select(h => convertHitObject(h)).ToList();
|
||||
|
||||
updateStacking(converted, stackLeniency);
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
private OsuHitObject convertHitObject(HitObject original)
|
||||
{
|
||||
IHasCurve curveData = original as IHasCurve;
|
||||
@ -82,28 +96,6 @@ namespace osu.Game.Modes.Osu.Beatmaps
|
||||
};
|
||||
}
|
||||
|
||||
private List<OsuHitObject> convertHitObjects(List<HitObject> hitObjects, float stackLeniency)
|
||||
{
|
||||
List<OsuHitObject> converted = new List<OsuHitObject>();
|
||||
|
||||
int combo = 0;
|
||||
foreach (HitObject h in hitObjects)
|
||||
{
|
||||
OsuHitObject c = convertHitObject(h);
|
||||
|
||||
if (c.NewCombo)
|
||||
combo = 0;
|
||||
|
||||
c.ComboIndex = combo++;
|
||||
|
||||
converted.Add(c);
|
||||
}
|
||||
|
||||
updateStacking(converted, stackLeniency);
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
private void updateStacking(List<OsuHitObject> hitObjects, float stackLeniency, int startIndex = 0, int endIndex = -1)
|
||||
{
|
||||
if (endIndex == -1)
|
||||
|
@ -44,7 +44,25 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
public virtual Beatmap Process(Beatmap beatmap)
|
||||
{
|
||||
ApplyColours(beatmap);
|
||||
int comboIndex = 0;
|
||||
int colourIndex = 0;
|
||||
|
||||
foreach (var obj in beatmap.HitObjects)
|
||||
{
|
||||
HitObjectWithCombo comboObject = obj as HitObjectWithCombo;
|
||||
|
||||
if (comboObject == null || comboObject.NewCombo)
|
||||
{
|
||||
comboIndex = 0;
|
||||
colourIndex = (colourIndex + 1) % beatmap.ComboColors.Count;
|
||||
}
|
||||
|
||||
if (comboObject != null)
|
||||
{
|
||||
comboObject.ComboIndex = comboIndex++;
|
||||
comboObject.ComboColour = beatmap.ComboColors[colourIndex];
|
||||
}
|
||||
}
|
||||
|
||||
return beatmap;
|
||||
}
|
||||
@ -55,7 +73,12 @@ namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
HitObjects = new List<HitObject>(),
|
||||
ControlPoints = new List<ControlPoint>(),
|
||||
ComboColors = new List<Color4>(),
|
||||
ComboColors = new List<Color4> {
|
||||
new Color4(17, 136, 170, 255),
|
||||
new Color4(102, 136, 0, 255),
|
||||
new Color4(204, 102, 0, 255),
|
||||
new Color4(121, 9, 13, 255),
|
||||
},
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata(),
|
||||
@ -66,30 +89,5 @@ namespace osu.Game.Beatmaps.Formats
|
||||
return beatmap;
|
||||
}
|
||||
protected abstract void ParseFile(TextReader stream, Beatmap beatmap);
|
||||
|
||||
public virtual void ApplyColours(Beatmap b)
|
||||
{
|
||||
List<Color4> colours = b.ComboColors ?? new List<Color4> {
|
||||
new Color4(17, 136, 170, 255),
|
||||
new Color4(102, 136, 0, 255),
|
||||
new Color4(204, 102, 0, 255),
|
||||
new Color4(121, 9, 13, 255),
|
||||
};
|
||||
|
||||
if (colours.Count == 0) return;
|
||||
|
||||
int i = -1;
|
||||
|
||||
foreach (HitObject h in b.HitObjects)
|
||||
{
|
||||
IHasCombo ihc = h as IHasCombo;
|
||||
|
||||
if (ihc == null)
|
||||
continue;
|
||||
|
||||
if (ihc.NewCombo || i == -1) i = (i + 1) % colours.Count;
|
||||
ihc.ComboColour = colours[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using osu.Game.Beatmaps.Samples;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.Modes;
|
||||
using osu.Game.Modes.Objects;
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
@ -212,14 +213,23 @@ namespace osu.Game.Beatmaps.Formats
|
||||
beatmap.ControlPoints.Add(cp);
|
||||
}
|
||||
|
||||
private void handleColours(Beatmap beatmap, string key, string val)
|
||||
private void handleColours(Beatmap beatmap, string key, string val, ref bool hasCustomColours)
|
||||
{
|
||||
string[] split = val.Split(',');
|
||||
|
||||
if (split.Length != 3)
|
||||
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {val}");
|
||||
|
||||
byte r, g, b;
|
||||
if (!byte.TryParse(split[0], out r) || !byte.TryParse(split[1], out g) || !byte.TryParse(split[2], out b))
|
||||
throw new InvalidOperationException(@"Color must be specified with 8-bit integer components");
|
||||
|
||||
if (!hasCustomColours)
|
||||
{
|
||||
beatmap.ComboColors.Clear();
|
||||
hasCustomColours = true;
|
||||
}
|
||||
|
||||
// Note: the combo index specified in the beatmap is discarded
|
||||
if (key.StartsWith(@"Combo"))
|
||||
{
|
||||
@ -237,6 +247,8 @@ namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
HitObjectParser parser = null;
|
||||
|
||||
bool hasCustomColours = false;
|
||||
|
||||
var section = Section.None;
|
||||
while (true)
|
||||
{
|
||||
@ -283,16 +295,14 @@ namespace osu.Game.Beatmaps.Formats
|
||||
handleTimingPoints(beatmap, val);
|
||||
break;
|
||||
case Section.Colours:
|
||||
handleColours(beatmap, key, val);
|
||||
handleColours(beatmap, key, val, ref hasCustomColours);
|
||||
break;
|
||||
case Section.HitObjects:
|
||||
var obj = parser?.Parse(val);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
obj.SetDefaultsFromBeatmap(beatmap);
|
||||
beatmap.HitObjects.Add(obj);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,8 @@ using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Modes.Objects
|
||||
{
|
||||
internal class Hit : HitObject, IHasPosition, IHasCombo
|
||||
internal class Hit : HitObjectWithCombo, IHasPosition
|
||||
{
|
||||
public Vector2 Position { get; set; }
|
||||
public Color4 ComboColour { get; set; }
|
||||
|
||||
public bool NewCombo { get; set; }
|
||||
public int ComboIndex { get; set; }
|
||||
}
|
||||
}
|
||||
|
18
osu.Game/Modes/Objects/HitObjectWithCombo.cs
Normal file
18
osu.Game/Modes/Objects/HitObjectWithCombo.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Modes.Objects
|
||||
{
|
||||
internal class HitObjectWithCombo : HitObject, IHasCombo
|
||||
{
|
||||
public Color4 ComboColour { get; set; }
|
||||
public bool NewCombo { get; set; }
|
||||
public int ComboIndex { get; set; }
|
||||
}
|
||||
}
|
@ -8,18 +8,14 @@ using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Modes.Objects
|
||||
{
|
||||
internal class Slider : HitObject, IHasCurve, IHasDistance, IHasPosition, IHasCombo, IHasRepeats
|
||||
internal class Slider : HitObjectWithCombo, IHasCurve, IHasPosition, IHasDistance, IHasRepeats
|
||||
{
|
||||
public List<Vector2> ControlPoints { get; set; }
|
||||
public CurveType CurveType { get; set; }
|
||||
|
||||
public double Distance { get; set; }
|
||||
|
||||
public Vector2 Position { get; set; }
|
||||
|
||||
public Color4 ComboColour { get; set; }
|
||||
public bool NewCombo { get; set; }
|
||||
public int ComboIndex { get; set; }
|
||||
public double Distance { get; set; }
|
||||
|
||||
public int RepeatCount { get; set; }
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace osu.Game.Modes.Objects.Types
|
||||
/// <summary>
|
||||
/// The colour of this HitObject in the combo.
|
||||
/// </summary>
|
||||
Color4 ComboColour { get; set; }
|
||||
Color4 ComboColour { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the HitObject starts a new combo.
|
||||
|
@ -94,6 +94,7 @@
|
||||
<Compile Include="Modes\Mods\IApplicableMod.cs" />
|
||||
<Compile Include="Modes\Mods\ModType.cs" />
|
||||
<Compile Include="Modes\Objects\Hit.cs" />
|
||||
<Compile Include="Modes\Objects\HitObjectWithCombo.cs" />
|
||||
<Compile Include="Modes\Objects\IHitObjectConverter.cs" />
|
||||
<Compile Include="Modes\Objects\LegacyHitObjectParser.cs" />
|
||||
<Compile Include="Modes\Objects\Slider.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user