Skip to content

Commit

Permalink
Returns objects in instrument share events
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBoxyBear committed Jan 4, 2024
1 parent 51b8be8 commit c1e45d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 2 additions & 6 deletions ChartTools/Exceptions/UndefinedEnumException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
/// <summary>
/// Exception thrown when using an <see cref="Enum"/> value that is not defined
/// </summary>
public class UndefinedEnumException : ArgumentException
public class UndefinedEnumException(Enum value) : ArgumentException($"{value.GetType().Name} \"{value}\" is not defined.")
{
/// <summary>
/// Value used
/// </summary>
public Enum Value { get; }

public UndefinedEnumException(Enum value) : base($"{value.GetType().Name} \"{value}\" is not defined.") => Value = value;


public Enum Value { get; } = value;
}
15 changes: 10 additions & 5 deletions ChartTools/Instruments/Instrument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChartTools.Extensions.Linq;
using ChartTools.Events;
using ChartTools.Extensions.Linq;
using ChartTools.IO;
using ChartTools.IO.Chart;
using ChartTools.IO.Configuration;
Expand Down Expand Up @@ -107,12 +108,14 @@ public InstrumentType InstrumentType
/// <summary>
/// Gives all tracks the same local events.
/// </summary>
public void ShareLocalEvents(TrackObjectSource source) => ShareEventsStarPower(source, track => track.LocalEvents);
public LocalEvent[] ShareLocalEvents(TrackObjectSource source) => ShareEventsSpecial(source, track => track.LocalEvents);

/// <summary>
/// Gives all tracks the same star power
/// Gives all tracks the same special phrases
/// </summary>
public void ShareStarPower(TrackObjectSource source) => ShareEventsStarPower(source, track => track.SpecialPhrases);
private void ShareEventsStarPower<T>(TrackObjectSource source, Func<Track, List<T>> collectionGetter) where T : TrackObjectBase
public SpecialPhrase[] ShareSpecial(TrackObjectSource source) => ShareEventsSpecial(source, track => track.SpecialPhrases);

private T[] ShareEventsSpecial<T>(TrackObjectSource source, Func<Track, List<T>> collectionGetter) where T : TrackObjectBase
{
var collections = GetExistingTracks().Select(track => collectionGetter(track)).ToArray();

Expand All @@ -131,6 +134,8 @@ private void ShareEventsStarPower<T>(TrackObjectSource source, Func<Track, List<
collection.Clear();
collection.AddRange(objects);
}

return objects;
}

#region IO
Expand Down

0 comments on commit c1e45d3

Please sign in to comment.