Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ChartTools.Generator/ChartTools.Generator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion ChartTools/Events/GlobalEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public bool IsKeyboardMovementEvent
/// The event stores text for a syllable of lyrics for karaoke when no vocal track is present
/// </summary>
public bool IsLyricEvent
=> IsPhraseEvent || EventType == EventTypeHelper.Global.Lyric;
=> IsPhraseEvent || EventType is EventTypeHelper.Global.Lyric;

/// <summary>
/// The event represents the start or end of a lyric phrase when no vocal track is present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public bool MoveNext()
return true;
}

void IEnumerator.Reset() => throw new InvalidOperationException();
void IEnumerator.Reset()
=> throw new InvalidOperationException();

void IDisposable.Dispose() { }
}
2 changes: 1 addition & 1 deletion ChartTools/Extensions/Linq/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public static class CollectionExtensions
{
public static int BinarySearchIndex<T, TKey>(this IList<T> source, TKey target, Func<T, TKey> keySelector, out bool exactMatch)
where TKey : notnull, IComparable<TKey>
where TKey : notnull, IComparable<TKey>
{
int
left = 0,
Expand Down
5 changes: 3 additions & 2 deletions ChartTools/IO/Chart/ChartFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ChartTools.IO.Formatting;
using ChartTools.IO.Sources;
using ChartTools.Lyrics;
using ChartTools.Meta;

namespace ChartTools.IO.Chart;

Expand Down Expand Up @@ -516,7 +517,7 @@ private static ChartFileWriter GetMetadataWriter(WritingDataSource source, Metad
=> new(source, null, new MetadataSerializer(metadata));

/// <summary>
/// Replaces the <see cref="Metadata"/> in a chart target.
/// Replaces the <see cref="Meta"/> in a chart target.
/// </summary>
/// <param name="source">File path or stream to write to</param>
/// <param name="metadata">Metadata to write</param>
Expand All @@ -527,7 +528,7 @@ public static void ReplaceMetadata(WritingDataSource source, Metadata metadata)
}

/// <summary>
/// Replaces the <see cref="Metadata"/> in a chart target asynchronously.
/// Replaces the <see cref="Meta"/> in a chart target asynchronously.
/// </summary>
/// <param name="source">File path or stream to write to</param>
/// <param name="metadata">Metadata to write</param>
Expand Down
1 change: 1 addition & 0 deletions ChartTools/IO/Chart/ChartFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ChartTools.IO.Components;
using ChartTools.IO.Configuration;
using ChartTools.IO.Sources;
using ChartTools.Meta;

namespace ChartTools.IO.Chart;

Expand Down
3 changes: 2 additions & 1 deletion ChartTools/IO/Chart/Parsing/MetadataParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace ChartTools.IO.Chart.Parsing;
using ChartTools.Meta;
using ChartTools.Meta.Mapping;

internal class MetadataParser(Metadata? existing = null)
: ChartParser(null! /* Session not used */, ChartFormatting.MetadataHeader.AsMemory())
Expand Down
6 changes: 4 additions & 2 deletions ChartTools/IO/Chart/Serializing/MetadataSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ChartTools.IO.Chart.Serializing;
using ChartTools.Meta;

namespace ChartTools.IO.Chart.Serializing;

internal class MetadataSerializer(Metadata content) : Serializer<Metadata, string>(ChartFormatting.MetadataHeader, content)
{
Expand All @@ -19,7 +21,7 @@ public override IEnumerable<string> Serialize()
if (Content.Year is not null)
yield return ChartFormatting.Line("Year", $"\", {Content.Year}\"");

foreach (UnidentifiedMetadata data in Content.UnidentifiedData.Where(d => d.Origin == FileType.Chart))
foreach (UnidentifiedMetadata data in Content.UnidentifiedData.Where(d => d.Origin is FileType.Chart))
yield return ChartFormatting.Line(data.Key, data.Value);
}
}
2 changes: 1 addition & 1 deletion ChartTools/IO/Chart/Serializing/TrackSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override IEnumerable<TrackObjectEntry>[] LaunchProviders()

// Convert solo and soloend events into star power
if (Session.Configuration.SoloNoStarPowerPolicy is SoloNoStarPowerPolicy.Convert &&
Content.SpecialPhrases.Count == 0 && Content.LocalEvents is not null)
Content.SpecialPhrases.Count is 0 && Content.LocalEvents is not null)
{
TrackSpecialPhrase? starPower = null;

Expand Down
2 changes: 1 addition & 1 deletion ChartTools/IO/Components/ComponentList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public record ComponentList()
};

/// <summary>
/// Include the <see cref="ChartTools.Metadata"/>
/// Include the <see cref="Meta.Metadata"/>
/// </summary>
public bool Metadata { get; set; }

Expand Down
1 change: 1 addition & 0 deletions ChartTools/IO/DirectoryHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ChartTools.IO.Formatting;
using ChartTools.IO.Ini;
using ChartTools.Meta;

namespace ChartTools.IO;

Expand Down
2 changes: 1 addition & 1 deletion ChartTools/IO/Formatting/FormattingEnums.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ChartTools.IO.Formatting;

/// <summary>
/// Key used to serialize <see cref="Metadata.AlbumTrack"/>
/// Key used to serialize <see cref="Meta.AlbumTrack"/>
/// </summary>
[Flags]
public enum AlbumTrackKey : byte
Expand Down
1 change: 1 addition & 0 deletions ChartTools/IO/Ini/IniFile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ChartTools.Extensions.Linq;
using ChartTools.IO.Sources;
using ChartTools.Meta;

namespace ChartTools.IO.Ini;

Expand Down
1 change: 1 addition & 0 deletions ChartTools/IO/Ini/IniFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ChartTools.IO.Parsing;
using ChartTools.IO.Sources;
using ChartTools.Meta;

namespace ChartTools.IO.Ini;

Expand Down
22 changes: 11 additions & 11 deletions ChartTools/IO/Ini/IniFormatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,59 @@ public static class IniFormatting
public const string Header = "[song]";

/// <summary>
/// Value of <see cref="Metadata.Title"/>
/// Value of <see cref="Meta.Title"/>
/// </summary>
public const string Title = "name";

/// <summary>
/// Value of <see cref="Metadata.Artist"/>
/// Value of <see cref="Meta.Artist"/>
/// </summary>
public const string Artist = "artist";

/// <summary>
/// Value of <see cref="Metadata.Album"/>
/// Value of <see cref="Meta.Album"/>
/// </summary>
public const string Album = "album";

/// <summary>
/// Value of <see cref="Metadata.AlbumTrack"/>
/// Value of <see cref="Meta.AlbumTrack"/>
/// </summary>
/// <remarks>Alternate key to <see cref="Track"/></remarks>
public const string AlbumTrack = "album_track";

/// <summary>
/// Value of <see cref="Metadata.AlbumTrack"/>
/// Value of <see cref="Meta.AlbumTrack"/>
/// </summary>
/// <remarks>Alternate key to <see cref="AlbumTrack"/></remarks>
public const string Track = "track";

/// <summary>
/// Value of <see cref="Metadata.Playlist"/>
/// Value of <see cref="Meta.Playlist"/>
/// </summary>
public const string Playlist = "playlist";

/// <summary>
/// Value of <see cref="Metadata.SubPlaylist"/>
/// Value of <see cref="Meta.SubPlaylist"/>
/// </summary>
public const string SubPlaylist = "sub_playlist";

/// <summary>
/// Value of <see cref="Metadata.PlaylistTrack"/>
/// Value of <see cref="Meta.PlaylistTrack"/>
/// </summary>
public const string PlaylistTrack = "playlist_track";

/// <summary>
/// Value of <see cref="Metadata.Genre"/>
/// Value of <see cref="Meta.Genre"/>
/// </summary>
public const string Genre = "genre";

/// <summary>
/// Value of <see cref="Metadata.Explicit"/>
/// Value of <see cref="Meta.Explicit"/>
/// </summary>
public const string Explicit = "explicit_lyrics";

/// <summary>
/// Value of <see cref="Metadata.Year"/>
/// Value of <see cref="Meta.Year"/>
/// </summary>
public const string Year = "year";

Expand Down
1 change: 1 addition & 0 deletions ChartTools/IO/Ini/IniParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ChartTools.IO.Formatting;
using ChartTools.IO.Parsing;
using ChartTools.Meta;
using ChartTools.Tools;

namespace ChartTools.IO.Ini;
Expand Down
1 change: 1 addition & 0 deletions ChartTools/IO/Ini/IniSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChartTools.IO.Formatting;
using ChartTools.Meta;

namespace ChartTools.IO.Ini;

Expand Down
2 changes: 1 addition & 1 deletion ChartTools/IO/Parsers/TextParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ChartTools.IO.Parsing;
using System.Reflection.PortableExecutable;

internal abstract class TextParser(in ReadOnlyMemory<char> header)
: FileParser<ReadOnlyMemory<char>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using ChartTools.IO.Chart.Serializing;
using ChartTools.IO.Ini;

namespace ChartTools;
namespace ChartTools.Meta;

/// <summary>
/// Creator of the chart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ChartTools.IO.Ini;

namespace ChartTools;
namespace ChartTools.Meta;

/// <summary>
/// Stores the estimated difficulties for instruments
Expand Down
104 changes: 104 additions & 0 deletions ChartTools/Meta/Mapping/IMetadataMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using ChartTools.IO;
using ChartTools.IO.Chart;

namespace ChartTools.Meta.Mapping;

internal interface IMetadataMapper
{
public static abstract FileType FileType { get; }

public static abstract string? Get(Metadata metadata, in ReadOnlySpan<char> key);

public static abstract void Set(Metadata metadata, in ReadOnlySpan<char> key, in ReadOnlySpan<char> value);

public static abstract void Remove(Metadata metadata, in ReadOnlySpan<char> key);

protected static string? FindUndentified(Metadata metadata, FileType fileType, in ReadOnlySpan<char> key)
=> metadata.UnidentifiedData.TryGetValue(new()
{
Key = key.ToString(),
Origin = fileType
}, out UnidentifiedMetadata found)
? found.Value
: null;

protected static void Remove(Metadata metadata, FileType fileType, in ReadOnlySpan<char> key)
{
switch (key)
{
case ChartFormatting.Title:
metadata.Title = null;
break;
case ChartFormatting.Artist:
metadata.Artist = null;
break;
case ChartFormatting.Charter:
metadata.Charter.Name = null;
break;
case ChartFormatting.Album:
metadata.Album = null;
break;
case ChartFormatting.Year:
metadata.Year = null;
break;
case ChartFormatting.AudioOffset:
metadata.AudioOffset = null;
break;
case ChartFormatting.Difficulty:
metadata.Difficulty = null;
break;
case ChartFormatting.PreviewStart:
metadata.PreviewStart = null;
break;
case ChartFormatting.PreviewEnd:
metadata.PreviewEnd = null;
break;
case ChartFormatting.Genre:
metadata.Genre = null;
break;
case ChartFormatting.MediaType:
metadata.MediaType = null;
break;
case ChartFormatting.MusicStream:
metadata.Streams.Music = null;
break;
case ChartFormatting.GuitarStream:
metadata.Streams.Guitar = null;
break;
case ChartFormatting.BassStream:
metadata.Streams.Bass = null;
break;
case ChartFormatting.RhythmStream:
metadata.Streams.Rhythm = null;
break;
case ChartFormatting.KeysStream:
metadata.Streams.Keys = null;
break;
case ChartFormatting.DrumStream:
metadata.Streams.Drum = null;
break;
case ChartFormatting.Drum2Stream:
metadata.Streams.Drum2 = null;
break;
case ChartFormatting.Drum3Stream:
metadata.Streams.Drum3 = null;
break;
case ChartFormatting.Drum4Stream:
metadata.Streams.Drum4 = null;
break;
case ChartFormatting.VocalStream:
metadata.Streams.Vocals = null;
break;
case ChartFormatting.CrowdStream:
metadata.Streams.Crowd = null;
break;
default:
metadata.UnidentifiedData.Remove(new()
{
Key = key.ToString(),
Origin = FileType.Chart
});
break;
}
}
}
Loading
Loading