2020-03-30 08:18:09 +00: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.
|
|
|
|
|
2020-10-16 03:49:31 +00:00
|
|
|
using System;
|
2020-03-30 08:18:09 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Globalization;
|
2020-03-30 08:36:57 +00:00
|
|
|
using System.Linq;
|
2020-03-30 08:18:09 +00: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)
|
|
|
|
{
|
|
|
|
line = StripComments(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 08:36:57 +00:00
|
|
|
|
|
|
|
// Silently ignore duplicate configurations.
|
|
|
|
if (output.All(c => c.Keys != currentConfig.Keys))
|
|
|
|
output.Add(currentConfig);
|
2020-03-30 08:18:09 +00: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);
|
|
|
|
|
|
|
|
foreach (var line in pendingLines)
|
|
|
|
{
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
switch (pair.Key)
|
|
|
|
{
|
|
|
|
case "ColumnLineWidth":
|
2020-04-21 08:15:06 +00:00
|
|
|
parseArrayValue(pair.Value, currentConfig.ColumnLineWidth, false);
|
2020-03-30 08:18:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "ColumnSpacing":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.ColumnSpacing);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ColumnWidth":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.ColumnWidth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "HitPosition":
|
2020-12-16 09:08:16 +00:00
|
|
|
currentConfig.HitPosition = (480 - Math.Clamp(float.Parse(pair.Value, CultureInfo.InvariantCulture), 240, 480)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-03-30 08:18:09 +00:00
|
|
|
break;
|
2020-03-31 03:26:31 +00:00
|
|
|
|
2020-04-01 07:05:52 +00:00
|
|
|
case "LightPosition":
|
2020-04-02 05:24:09 +00:00
|
|
|
currentConfig.LightPosition = (480 - float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-04-01 07:05:52 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-10 14:11:08 +00:00
|
|
|
case "ScorePosition":
|
2020-12-13 16:43:36 +00:00
|
|
|
currentConfig.ScorePosition = (float.Parse(pair.Value, CultureInfo.InvariantCulture)) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
2020-12-10 14:11:08 +00:00
|
|
|
break;
|
|
|
|
|
2020-03-31 03:26:31 +00:00
|
|
|
case "JudgementLine":
|
|
|
|
currentConfig.ShowJudgementLine = pair.Value == "1";
|
|
|
|
break;
|
2020-04-02 05:29:16 +00:00
|
|
|
|
2020-08-26 06:37:16 +00:00
|
|
|
case "KeysUnderNotes":
|
|
|
|
currentConfig.KeysUnderNotes = pair.Value == "1";
|
|
|
|
break;
|
|
|
|
|
2020-04-02 05:29:16 +00:00
|
|
|
case "LightingNWidth":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.ExplosionWidth);
|
|
|
|
break;
|
2020-04-06 10:04:02 +00:00
|
|
|
|
2020-08-26 11:21:41 +00:00
|
|
|
case "LightingLWidth":
|
|
|
|
parseArrayValue(pair.Value, currentConfig.HoldNoteLightWidth);
|
|
|
|
break;
|
|
|
|
|
2020-04-07 07:07:18 +00:00
|
|
|
case "WidthForNoteHeightScale":
|
2020-04-08 09:17:45 +00:00
|
|
|
float minWidth = float.Parse(pair.Value, CultureInfo.InvariantCulture) * LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR;
|
|
|
|
if (minWidth > 0)
|
|
|
|
currentConfig.MinimumColumnWidth = minWidth;
|
2020-04-07 07:07:18 +00:00
|
|
|
break;
|
2020-04-07 13:41:22 +00:00
|
|
|
|
2020-10-16 03:49:31 +00:00
|
|
|
case string _ when pair.Key.StartsWith("Colour", StringComparison.Ordinal):
|
2020-04-06 10:04:02 +00:00
|
|
|
HandleColours(currentConfig, line);
|
|
|
|
break;
|
|
|
|
|
2020-06-12 14:48:18 +00:00
|
|
|
// Custom sprite paths
|
2020-10-16 03:49:31 +00: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 10:04:02 +00:00
|
|
|
currentConfig.ImageLookups[pair.Key] = pair.Value;
|
|
|
|
break;
|
2020-03-30 08:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-06 09:35:39 +00:00
|
|
|
|
|
|
|
pendingLines.Clear();
|
2020-03-30 08:18:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 08:15:06 +00:00
|
|
|
private void parseArrayValue(string value, float[] output, bool applyScaleFactor = true)
|
2020-03-30 08:18:09 +00:00
|
|
|
{
|
|
|
|
string[] values = value.Split(',');
|
|
|
|
|
|
|
|
for (int i = 0; i < values.Length; i++)
|
|
|
|
{
|
|
|
|
if (i >= output.Length)
|
|
|
|
break;
|
|
|
|
|
2020-04-21 08:15:06 +00:00
|
|
|
output[i] = float.Parse(values[i], CultureInfo.InvariantCulture) * (applyScaleFactor ? LegacyManiaSkinConfiguration.POSITION_SCALE_FACTOR : 1);
|
2020-03-30 08:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|