1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:47:28 +08:00

Implement beatmap encoding for all legacy rulesets

This commit is contained in:
smoogipoo 2020-04-21 16:04:58 +09:00
parent ee278a2e1b
commit ea0ebc8527

View File

@ -13,6 +13,7 @@ using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
namespace osu.Game.Beatmaps.Formats
{
@ -197,32 +198,40 @@ namespace osu.Game.Beatmaps.Formats
writer.WriteLine("[HitObjects]");
// TODO: implement other legacy rulesets
foreach (var h in beatmap.HitObjects)
handleHitObject(writer, h);
}
private void handleHitObject(TextWriter writer, HitObject hitObject)
{
Vector2 position = new Vector2(256, 192);
switch (beatmap.BeatmapInfo.RulesetID)
{
case 0:
foreach (var h in beatmap.HitObjects)
handleOsuHitObject(writer, h);
position = ((IHasPosition)hitObject).Position;
break;
case 2:
position.X = ((IHasXPosition)hitObject).X * 512;
break;
case 3:
int totalColumns = (int)Math.Max(1, beatmap.BeatmapInfo.BaseDifficulty.CircleSize);
position.X = (int)Math.Ceiling(((IHasXPosition)hitObject).X * (512f / totalColumns));
break;
}
}
private void handleOsuHitObject(TextWriter writer, HitObject hitObject)
{
var positionData = (IHasPosition)hitObject;
writer.Write(FormattableString.Invariant($"{positionData.X},"));
writer.Write(FormattableString.Invariant($"{positionData.Y},"));
writer.Write(FormattableString.Invariant($"{position.X},"));
writer.Write(FormattableString.Invariant($"{position.Y},"));
writer.Write(FormattableString.Invariant($"{hitObject.StartTime},"));
writer.Write(FormattableString.Invariant($"{(int)getObjectType(hitObject)},"));
writer.Write(hitObject is IHasCurve
? FormattableString.Invariant($"0,")
: FormattableString.Invariant($"{(int)toLegacyHitSoundType(hitObject.Samples)},"));
writer.Write(FormattableString.Invariant($"{(int)toLegacyHitSoundType(hitObject.Samples)},"));
if (hitObject is IHasCurve curveData)
{
addCurveData(writer, curveData, positionData);
addCurveData(writer, curveData, position);
writer.Write(getSampleBank(hitObject.Samples, zeroBanks: true));
}
else
@ -237,11 +246,15 @@ namespace osu.Game.Beatmaps.Formats
private static LegacyHitObjectType getObjectType(HitObject hitObject)
{
var comboData = (IHasCombo)hitObject;
LegacyHitObjectType type = 0;
var type = (LegacyHitObjectType)(comboData.ComboOffset << 4);
if (hitObject is IHasCombo combo)
{
type = (LegacyHitObjectType)(combo.ComboOffset << 4);
if (comboData.NewCombo) type |= LegacyHitObjectType.NewCombo;
if (combo.NewCombo)
type |= LegacyHitObjectType.NewCombo;
}
switch (hitObject)
{
@ -261,7 +274,7 @@ namespace osu.Game.Beatmaps.Formats
return type;
}
private void addCurveData(TextWriter writer, IHasCurve curveData, IHasPosition positionData)
private void addCurveData(TextWriter writer, IHasCurve curveData, Vector2 position)
{
PathType? lastType = null;
@ -297,13 +310,13 @@ namespace osu.Game.Beatmaps.Formats
else
{
// New segment with the same type - duplicate the control point
writer.Write(FormattableString.Invariant($"{positionData.X + point.Position.Value.X}:{positionData.Y + point.Position.Value.Y}|"));
writer.Write(FormattableString.Invariant($"{position.X + point.Position.Value.X}:{position.Y + point.Position.Value.Y}|"));
}
}
if (i != 0)
{
writer.Write(FormattableString.Invariant($"{positionData.X + point.Position.Value.X}:{positionData.Y + point.Position.Value.Y}"));
writer.Write(FormattableString.Invariant($"{position.X + point.Position.Value.X}:{position.Y + point.Position.Value.Y}"));
writer.Write(i != curveData.Path.ControlPoints.Count - 1 ? "|" : ",");
}
}