-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28c0e5a
commit f69bb51
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Reflection; | ||
|
||
namespace ArcaneLibs.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)] | ||
public class FriendlyNameAttribute : Attribute { | ||
public required string Name { get; set; } | ||
public string? NamePlural { get; set; } | ||
} | ||
|
||
public static class FriendlyNameAttributeExtensions { | ||
public static string? GetFriendlyNameOrNull(this MemberInfo type) { | ||
var attrs = type.GetCustomAttributes(typeof(FriendlyNameAttribute), false); | ||
return attrs.Length == 0 ? null : ((FriendlyNameAttribute)attrs[0]).Name; | ||
} | ||
|
||
public static string? GetFriendlyNamePluralOrNull(this MemberInfo type) { | ||
var attrs = type.GetCustomAttributes(typeof(FriendlyNameAttribute), false); | ||
return attrs.Length == 0 ? null : ((FriendlyNameAttribute)attrs[0]).NamePlural; | ||
} | ||
|
||
public static string GetFriendlyName(this MemberInfo type) => type.GetFriendlyNameOrNull() ?? type.Name; | ||
|
||
public static string GetFriendlyNamePlural(this MemberInfo type) => type.GetFriendlyNamePluralOrNull() ?? type.Name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System.Reflection; | ||
|
||
namespace ArcaneLibs.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)] | ||
public class TableHideAttribute : Attribute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Reflection; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ArcaneLibs.Extensions; | ||
|
||
public static class JsonExtensions { | ||
public static string? GetJsonPropertyNameOrNull(this MemberInfo member) { | ||
var attrs = member.GetCustomAttributes(typeof(JsonPropertyNameAttribute), false); | ||
return attrs.Length == 0 ? null : ((JsonPropertyNameAttribute)attrs[0]).Name; | ||
} | ||
|
||
public static string GetJsonPropertyName(this MemberInfo member) => member.GetJsonPropertyNameOrNull() ?? member.Name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace ArcaneLibs; | ||
|
||
public class RainbowEnumerator(byte skip = 1, int offset = 0, double lengthFactor = 255.0) { | ||
private const double FullRotation = Math.PI * 2; | ||
private readonly double _oneThird = lengthFactor / 3; | ||
private readonly double _twoThirds = lengthFactor / 3 * 2; | ||
|
||
public (byte r, byte g, byte b) Next() { | ||
var v = ( | ||
r: (byte) (128 + 127 * Math.Sin(offset / lengthFactor * FullRotation)), | ||
g: (byte) (128 + 127 * Math.Sin((offset + lengthFactor * _oneThird) / lengthFactor * FullRotation)), | ||
b: (byte) (128 + 127 * Math.Sin((offset + lengthFactor * _twoThirds) / lengthFactor * FullRotation)) | ||
); | ||
offset += skip; | ||
return v; | ||
} | ||
} |