1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:57:24 +08:00

Merge branch 'master' into midi-keybinds

This commit is contained in:
Dean Herbert 2020-05-11 18:43:46 +09:00 committed by GitHub
commit cd2127d406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 24 deletions

View File

@ -167,13 +167,15 @@ namespace osu.Game.Rulesets.Taiko.Beatmaps
default: default:
{ {
bool isRim = samples.Any(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE); bool isRimDefinition(HitSampleInfo s) => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE;
bool isRim = samples.Any(isRimDefinition);
yield return new Hit yield return new Hit
{ {
StartTime = obj.StartTime, StartTime = obj.StartTime,
Type = isRim ? HitType.Rim : HitType.Centre, Type = isRim ? HitType.Rim : HitType.Centre,
Samples = obj.Samples, Samples = samples,
IsStrong = strong IsStrong = strong
}; };

View File

@ -2,9 +2,11 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
@ -47,6 +49,37 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
? new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.CentreHit), _ => new CentreHitCirclePiece(), confineMode: ConfineMode.ScaleToFit) ? new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.CentreHit), _ => new CentreHitCirclePiece(), confineMode: ConfineMode.ScaleToFit)
: new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.RimHit), _ => new RimHitCirclePiece(), confineMode: ConfineMode.ScaleToFit); : new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.RimHit), _ => new RimHitCirclePiece(), confineMode: ConfineMode.ScaleToFit);
protected override IEnumerable<HitSampleInfo> GetSamples()
{
// normal and claps are always handled by the drum (see DrumSampleMapping).
var samples = HitObject.Samples.Where(s => s.Name != HitSampleInfo.HIT_NORMAL && s.Name != HitSampleInfo.HIT_CLAP);
if (HitObject.Type == HitType.Rim && HitObject.IsStrong)
{
// strong + rim always maps to whistle.
// TODO: this should really be in the legacy decoder, but can't be because legacy encoding parity would be broken.
// when we add a taiko editor, this is probably not going to play nice.
var corrected = samples.ToList();
for (var i = 0; i < corrected.Count; i++)
{
var s = corrected[i];
if (s.Name != HitSampleInfo.HIT_FINISH)
continue;
var sClone = s.Clone();
sClone.Name = HitSampleInfo.HIT_WHISTLE;
corrected[i] = sClone;
}
return corrected;
}
return samples;
}
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)
{ {
Debug.Assert(HitObject.HitWindows != null); Debug.Assert(HitObject.HitWindows != null);

View File

@ -165,8 +165,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return base.CreateNestedHitObject(hitObject); return base.CreateNestedHitObject(hitObject);
} }
// Normal and clap samples are handled by the drum // Most osu!taiko hitsounds are managed by the drum (see DrumSampleMapping).
protected override IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples.Where(s => s.Name != HitSampleInfo.HIT_NORMAL && s.Name != HitSampleInfo.HIT_CLAP); protected override IEnumerable<HitSampleInfo> GetSamples() => Enumerable.Empty<HitSampleInfo>();
protected abstract SkinnableDrawable CreateMainPiece(); protected abstract SkinnableDrawable CreateMainPiece();

View File

@ -6,6 +6,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -28,14 +29,15 @@ namespace osu.Game.Tests.Beatmaps.Formats
private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu")); private static IEnumerable<string> allBeatmaps => TestResources.GetStore().GetAvailableResources().Where(res => res.EndsWith(".osu"));
[TestCaseSource(nameof(allBeatmaps))] [TestCaseSource(nameof(allBeatmaps))]
public void TestBeatmap(string name) public void TestEncodeDecodeStability(string name)
{ {
var decoded = decode(name, out var encoded); var decoded = decodeFromLegacy(TestResources.GetStore().GetStream(name));
var decodedAfterEncode = decodeFromLegacy(encodeToLegacy(decoded));
sort(decoded); sort(decoded);
sort(encoded); sort(decodedAfterEncode);
Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize())); Assert.That(decodedAfterEncode.Serialize(), Is.EqualTo(decoded.Serialize()));
} }
private void sort(IBeatmap beatmap) private void sort(IBeatmap beatmap)
@ -48,27 +50,22 @@ namespace osu.Game.Tests.Beatmaps.Formats
} }
} }
private IBeatmap decode(string filename, out IBeatmap encoded) private IBeatmap decodeFromLegacy(Stream stream)
{ {
using (var stream = TestResources.GetStore().GetStream(filename)) using (var reader = new LineBufferedReader(stream))
using (var sr = new LineBufferedReader(stream)) return convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(reader));
{ }
var legacyDecoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr));
using (var ms = new MemoryStream()) private Stream encodeToLegacy(IBeatmap beatmap)
using (var sw = new StreamWriter(ms)) {
using (var sr2 = new LineBufferedReader(ms, true)) var stream = new MemoryStream();
{
new LegacyBeatmapEncoder(legacyDecoded).Encode(sw);
sw.Flush(); using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
ms.Position = 0; new LegacyBeatmapEncoder(beatmap).Encode(writer);
encoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr2)); stream.Position = 0;
return legacyDecoded; return stream;
}
}
} }
private IBeatmap convert(IBeatmap beatmap) private IBeatmap convert(IBeatmap beatmap)