mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 20:43:21 +08:00
Implement beatmap encoding for all legacy rulesets
This commit is contained in:
parent
ee278a2e1b
commit
ea0ebc8527
@ -13,6 +13,7 @@ using osu.Game.Beatmaps.Legacy;
|
|||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Objects.Legacy;
|
using osu.Game.Rulesets.Objects.Legacy;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Formats
|
namespace osu.Game.Beatmaps.Formats
|
||||||
{
|
{
|
||||||
@ -197,32 +198,40 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
|
|
||||||
writer.WriteLine("[HitObjects]");
|
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)
|
switch (beatmap.BeatmapInfo.RulesetID)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
foreach (var h in beatmap.HitObjects)
|
position = ((IHasPosition)hitObject).Position;
|
||||||
handleOsuHitObject(writer, h);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void handleOsuHitObject(TextWriter writer, HitObject hitObject)
|
writer.Write(FormattableString.Invariant($"{position.X},"));
|
||||||
{
|
writer.Write(FormattableString.Invariant($"{position.Y},"));
|
||||||
var positionData = (IHasPosition)hitObject;
|
|
||||||
|
|
||||||
writer.Write(FormattableString.Invariant($"{positionData.X},"));
|
|
||||||
writer.Write(FormattableString.Invariant($"{positionData.Y},"));
|
|
||||||
writer.Write(FormattableString.Invariant($"{hitObject.StartTime},"));
|
writer.Write(FormattableString.Invariant($"{hitObject.StartTime},"));
|
||||||
writer.Write(FormattableString.Invariant($"{(int)getObjectType(hitObject)},"));
|
writer.Write(FormattableString.Invariant($"{(int)getObjectType(hitObject)},"));
|
||||||
|
|
||||||
writer.Write(hitObject is IHasCurve
|
writer.Write(FormattableString.Invariant($"{(int)toLegacyHitSoundType(hitObject.Samples)},"));
|
||||||
? FormattableString.Invariant($"0,")
|
|
||||||
: FormattableString.Invariant($"{(int)toLegacyHitSoundType(hitObject.Samples)},"));
|
|
||||||
|
|
||||||
if (hitObject is IHasCurve curveData)
|
if (hitObject is IHasCurve curveData)
|
||||||
{
|
{
|
||||||
addCurveData(writer, curveData, positionData);
|
addCurveData(writer, curveData, position);
|
||||||
writer.Write(getSampleBank(hitObject.Samples, zeroBanks: true));
|
writer.Write(getSampleBank(hitObject.Samples, zeroBanks: true));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -237,11 +246,15 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
|
|
||||||
private static LegacyHitObjectType getObjectType(HitObject hitObject)
|
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)
|
switch (hitObject)
|
||||||
{
|
{
|
||||||
@ -261,7 +274,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCurveData(TextWriter writer, IHasCurve curveData, IHasPosition positionData)
|
private void addCurveData(TextWriter writer, IHasCurve curveData, Vector2 position)
|
||||||
{
|
{
|
||||||
PathType? lastType = null;
|
PathType? lastType = null;
|
||||||
|
|
||||||
@ -297,13 +310,13 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// New segment with the same type - duplicate the control point
|
// 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)
|
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 ? "|" : ",");
|
writer.Write(i != curveData.Path.ControlPoints.Count - 1 ? "|" : ",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user