2020-03-30 16:18:09 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-10-16 11:49:31 +08:00
|
|
|
using System;
|
2020-03-30 16:18:09 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Globalization;
|
2020-03-30 16:36:57 +08:00
|
|
|
using System.Linq;
|
2020-03-30 16:18:09 +08:00
|
|
|
using osu.Game.Beatmaps.Formats;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
public class LegacyManiaSkinDecoder : LegacyDecoder<List<LegacyManiaSkinConfiguration>>
|
|
|
|
{
|
|
|
|
public LegacyManiaSkinDecoder()
|
|
|
|
: base(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly List<string> pendingLines = new List<string>();
|
|
|
|
private LegacyManiaSkinConfiguration currentConfig;
|
|
|
|
|
|
|
|
protected override void OnBeginNewSection(Section section)
|
|
|
|
{
|
|
|
|
base.OnBeginNewSection(section);
|
|
|
|
|
|
|
|
// If a new section is reached with pending lines remaining, they can all be discarded as there isn't a valid configuration to parse them into.
|
|
|
|
pendingLines.Clear();
|
|
|
|
currentConfig = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ParseLine(List<LegacyManiaSkinConfiguration> output, Section section, string line)
|
|
|
|
{
|
|
|
|
switch (section)
|
|
|
|
{
|
|
|
|
case Section.Mania:
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
switch (pair.Key)
|
|
|
|
{
|
|
|
|
case "Keys":
|
|
|
|
currentConfig = new LegacyManiaSkinConfiguration(int.Parse(pair.Value, CultureInfo.InvariantCulture));
|
2020-03-30 16:36:57 +08:00
|
|
|
|
|
|
|
// Silently ignore duplicate configurations.
|
|
|
|
if (output.All(c => c.Keys != currentConfig.Keys))
|
|
|
|
output.Add(currentConfig);
|
2020-03-30 16:18:09 +08:00
|
|
|
|
|
|
|
// All existing lines can be flushed now that we have a valid configuration.
|
|
|
|
flushPendingLines();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pendingLines.Add(line);
|
|
|
|
|
|
|
|
// Hold all lines until a "Keys" item is found.
|
|
|
|
if (currentConfig != null)
|
|
|
|
flushPendingLines();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void flushPendingLines()
|
|
|
|
{
|
|
|
|
Debug.Assert(currentConfig != null);
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
foreach (string line in pendingLines)
|
2020-03-30 16:18:09 +08:00
|
|
|
{
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
switch (pair.Key)
|
|
|
|
{
|
|
|
|
case "ColumnLineWidth":
|
2020-04-21 16:15:06 +08:00
|
|
|
parseArrayValue(pair.Value, currentConfig.ColumnLineWidth, false);
|
2020-03-30 16:18:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "ColumnSpacing":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.ColumnSpacing);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ColumnWidth":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.ColumnWidth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "HitPosition":
|
2020-12-16 17:08:16 +08:00
|
|
|
currentConfig.HitPosition = (480 - Math.Clamp(float.Parse(pair.Value, CultureInfo.InvariantCulture), 240, 480)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-03-30 16:18:09 +08:00
|
|
|
break;
|
2020-03-31 11:26:31 +08:00
|
|
|
|
2020-04-01 15:05:52 +08:00
|
|
|
case "LightPosition":
|
2020-04-02 13:24:09 +08:00
|
|
|
currentConfig.LightPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2023-12-30 10:18:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "ComboPosition":
|
|
|
|
currentConfig.ComboPosition = (float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-04-01 15:05:52 +08:00
|
|
|
break;
|
|
|
|
|
2020-12-10 22:11:08 +08:00
|
|
|
case "ScorePosition":
|
2020-12-14 00:43:36 +08:00
|
|
|
currentConfig.ScorePosition = (float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-12-10 22:11:08 +08:00
|
|
|
break;
|
|
|
|
|
2020-03-31 11:26:31 +08:00
|
|
|
case "JudgementLine":
|
|
|
|
currentConfig.ShowJudgementLine = pair.Value == "1";
|
|
|
|
break;
|
2020-04-02 13:29:16 +08:00
|
|
|
|
2020-08-26 14:37:16 +08:00
|
|
|
case "KeysUnderNotes":
|
|
|
|
currentConfig.KeysUnderNotes = pair.Value == "1";
|
|
|
|
break;
|
|
|
|
|
2020-04-02 13:29:16 +08:00
|
|
|
case "LightingNWidth":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.ExplosionWidth);
|
|
|
|
break;
|
2020-04-06 18:04:02 +08:00
|
|
|
|
2020-08-26 19:21:41 +08:00
|
|
|
case "LightingLWidth":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.HoldNoteLightWidth);
|
|
|
|
break;
|
|
|
|
|
2023-02-10 18:30:41 +08:00
|
|
|
case "NoteBodyStyle":
|
|
|
|
if (Enum.TryParse<LegacyNoteBodyStyle>(pair.Value, out var style))
|
|
|
|
currentConfig.NoteBodyStyle = style;
|
|
|
|
break;
|
|
|
|
|
2020-04-07 15:07:18 +08:00
|
|
|
case "WidthForNoteHeightScale":
|
2023-02-10 18:18:41 +08:00
|
|
|
currentConfig.WidthForNoteHeightScale = (float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-04-07 15:07:18 +08:00
|
|
|
break;
|
2020-04-07 21:41:22 +08:00
|
|
|
|
2023-10-19 01:56:17 +08:00
|
|
|
case "LightFramePerSecond":
|
|
|
|
int lightFramePerSecond = int.Parse(pair.Value, CultureInfo.InvariantCulture);
|
|
|
|
currentConfig.LightFramePerSecond = lightFramePerSecond > 0 ? lightFramePerSecond : 24;
|
|
|
|
break;
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
case string when pair.Key.StartsWith("Colour", StringComparison.Ordinal):
|
2022-09-21 15:04:32 +08:00
|
|
|
HandleColours(currentConfig, line, true);
|
2020-04-06 18:04:02 +08:00
|
|
|
break;
|
|
|
|
|
2020-06-12 22:48:18 +08:00
|
|
|
// Custom sprite paths
|
2022-06-24 20:25:23 +08:00
|
|
|
case string when pair.Key.StartsWith("NoteImage", StringComparison.Ordinal):
|
|
|
|
case string when pair.Key.StartsWith("KeyImage", StringComparison.Ordinal):
|
|
|
|
case string when pair.Key.StartsWith("Hit", StringComparison.Ordinal):
|
|
|
|
case string when pair.Key.StartsWith("Stage", StringComparison.Ordinal):
|
|
|
|
case string when pair.Key.StartsWith("Lighting", StringComparison.Ordinal):
|
2020-04-06 18:04:02 +08:00
|
|
|
currentConfig.ImageLookups[pair.Key] = pair.Value;
|
|
|
|
break;
|
2020-03-30 16:18:09 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-06 17:35:39 +08:00
|
|
|
|
|
|
|
pendingLines.Clear();
|
2020-03-30 16:18:09 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 16:15:06 +08:00
|
|
|
private void parseArrayValue(string value, float[] output, bool applyScaleFactor = true)
|
2020-03-30 16:18:09 +08:00
|
|
|
{
|
|
|
|
string[] values = value.Split(',');
|
|
|
|
|
|
|
|
for (int i = 0; i < values.Length; i++)
|
|
|
|
{
|
|
|
|
if (i >= output.Length)
|
|
|
|
break;
|
|
|
|
|
2024-01-10 22:48:47 +08:00
|
|
|
if (!float.TryParse(values[i], NumberStyles.Float, CultureInfo.InvariantCulture, out float parsedValue))
|
2024-01-10 22:41:58 +08:00
|
|
|
// some skins may provide incorrect entries in array values. to match stable behaviour, read such entries as zero.
|
|
|
|
// see: https://github.com/ppy/osu/issues/26464, stable code: https://github.com/peppy/osu-stable-reference/blob/3ea48705eb67172c430371dcfc8a16a002ed0d3d/osu!/Graphics/Skinning/Components/Section.cs#L134-L137
|
|
|
|
parsedValue = 0;
|
|
|
|
|
|
|
|
if (applyScaleFactor)
|
|
|
|
parsedValue *= LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
|
|
|
|
|
|
|
output[i] = parsedValue;
|
2020-03-30 16:18:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|