cleanup and reformatting

This commit is contained in:
Infi
2024-04-11 06:44:23 +02:00
parent 9f771c37e3
commit 48fec7dfaa
9 changed files with 240 additions and 199 deletions
+12 -6
View File
@@ -2,7 +2,8 @@ using LiteDB;
namespace ChatTwo.Code;
internal class ChatCode {
internal class ChatCode
{
private const ushort Clear7 = ~(~0 << 7);
internal ushort Raw { get; }
@@ -12,7 +13,8 @@ internal class ChatCode {
internal ChatSource Target { get; }
private ChatSource SourceFrom(ushort shift) => (ChatSource) (1 << ((Raw >> shift) & 0xF));
internal ChatCode(ushort raw) {
internal ChatCode(ushort raw)
{
Raw = raw;
Type = (ChatType) (Raw & Clear7);
Source = SourceFrom(11);
@@ -20,14 +22,16 @@ internal class ChatCode {
}
[BsonCtor]
public ChatCode(ushort raw, ChatType type, ChatSource source, ChatSource target) {
public ChatCode(ushort raw, ChatType type, ChatSource source, ChatSource target)
{
Raw = raw;
Type = type;
Source = source;
Target = target;
}
internal ChatType Parent() => Type switch {
internal ChatType Parent() => Type switch
{
ChatType.Say => ChatType.Say,
ChatType.GmSay => ChatType.Say,
ChatType.Shout => ChatType.Shout,
@@ -84,8 +88,10 @@ internal class ChatCode {
_ => Type,
};
internal bool IsBattle() {
switch (Type) {
internal bool IsBattle()
{
switch (Type)
{
case ChatType.Damage:
case ChatType.Miss:
case ChatType.Action:
+2 -1
View File
@@ -2,7 +2,8 @@ namespace ChatTwo.Code;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32")]
[Flags]
internal enum ChatSource : ushort {
internal enum ChatSource : ushort
{
Self = 2,
PartyMember = 4,
AllianceMember = 8,
+4 -2
View File
@@ -2,7 +2,8 @@ using ChatTwo.Resources;
namespace ChatTwo.Code;
internal static class ChatSourceExt {
internal static class ChatSourceExt
{
internal const ChatSource All =
ChatSource.Self
| ChatSource.PartyMember
@@ -16,7 +17,8 @@ internal static class ChatSourceExt {
| ChatSource.AlliancePet
| ChatSource.OtherPet;
internal static string Name(this ChatSource source) => source switch {
internal static string Name(this ChatSource source) => source switch
{
ChatSource.Self => Language.ChatSource_Self,
ChatSource.PartyMember => Language.ChatSource_PartyMember,
ChatSource.AllianceMember => Language.ChatSource_AllianceMember,
+3 -2
View File
@@ -1,7 +1,8 @@
namespace ChatTwo.Code;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32")]
internal enum ChatType : ushort {
internal enum ChatType : ushort
{
Debug = 1,
Urgent = 2,
Notice = 3,
@@ -84,7 +85,7 @@ internal enum ChatType : ushort {
CrossLinkshell6 = 105,
CrossLinkshell7 = 106,
CrossLinkshell8 = 107,
// Custom types:
ExtraChatLinkshell1 = 1001,
ExtraChatLinkshell2 = 1002,
+33 -17
View File
@@ -3,14 +3,19 @@ using ChatTwo.Util;
namespace ChatTwo.Code;
internal static class ChatTypeExt {
internal static IEnumerable<(string, ChatType[])> SortOrder => new[] {
(Language.Options_Tabs_ChannelTypes_Special, new[] {
internal static class ChatTypeExt
{
internal static IEnumerable<(string, ChatType[])> SortOrder => new[]
{
(Language.Options_Tabs_ChannelTypes_Special,
[
ChatType.Debug,
ChatType.Urgent,
ChatType.Notice,
}),
(Language.Options_Tabs_ChannelTypes_Chat, new[] {
ChatType.Notice
]),
(Language.Options_Tabs_ChannelTypes_Chat,
[
ChatType.Say,
ChatType.Yell,
ChatType.Shout,
@@ -39,9 +44,11 @@ internal static class ChatTypeExt {
ChatType.Linkshell8,
ChatType.NoviceNetwork,
ChatType.StandardEmote,
ChatType.CustomEmote,
}),
(Language.Options_Tabs_ChannelTypes_Battle, new[] {
ChatType.CustomEmote
]),
(Language.Options_Tabs_ChannelTypes_Battle, new[]
{
ChatType.Damage,
ChatType.Miss,
ChatType.Action,
@@ -52,7 +59,9 @@ internal static class ChatTypeExt {
ChatType.GainDebuff,
ChatType.LoseDebuff,
}),
(Language.Options_Tabs_ChannelTypes_Announcements, new[] {
(Language.Options_Tabs_ChannelTypes_Announcements, new[]
{
ChatType.System,
ChatType.BattleSystem,
ChatType.GatheringSystem,
@@ -80,8 +89,10 @@ internal static class ChatTypeExt {
}),
};
internal static string Name(this ChatType type) {
return type switch {
internal static string Name(this ChatType type)
{
return type switch
{
ChatType.Debug => Language.ChatType_Debug,
ChatType.Urgent => Language.ChatType_Urgent,
ChatType.Notice => Language.ChatType_Notice,
@@ -174,8 +185,10 @@ internal static class ChatTypeExt {
};
}
internal static uint? DefaultColour(this ChatType type) {
switch (type) {
internal static uint? DefaultColour(this ChatType type)
{
switch (type)
{
case ChatType.Debug:
return ColourUtil.ComponentsToRgba(204, 204, 204);
case ChatType.Urgent:
@@ -292,7 +305,8 @@ internal static class ChatTypeExt {
}
}
internal static InputChannel? ToInputChannel(this ChatType type) => type switch {
internal static InputChannel? ToInputChannel(this ChatType type) => type switch
{
ChatType.TellOutgoing => InputChannel.Tell,
ChatType.Say => InputChannel.Say,
ChatType.Party => InputChannel.Party,
@@ -321,7 +335,8 @@ internal static class ChatTypeExt {
_ => null,
};
internal static bool IsGm(this ChatType type) => type switch {
internal static bool IsGm(this ChatType type) => type switch
{
ChatType.GmTell => true,
ChatType.GmSay => true,
ChatType.GmShout => true,
@@ -340,7 +355,8 @@ internal static class ChatTypeExt {
_ => false,
};
internal static bool HasSource(this ChatType type) => type switch {
internal static bool HasSource(this ChatType type) => type switch
{
// Battle
ChatType.Damage => true,
ChatType.Miss => true,
+3 -2
View File
@@ -1,6 +1,7 @@
namespace ChatTwo.Code;
internal enum InputChannel : uint {
internal enum InputChannel : uint
{
Tell = 0,
Say = 1,
Party = 2,
@@ -29,7 +30,7 @@ internal enum InputChannel : uint {
Linkshell6 = 24,
Linkshell7 = 25,
Linkshell8 = 26,
// Custom channels:
ExtraChatLinkshell1 = 1001,
ExtraChatLinkshell2 = 1002,
+46 -45
View File
@@ -3,8 +3,10 @@ using Lumina.Excel.GeneratedSheets;
namespace ChatTwo.Code;
internal static class InputChannelExt {
internal static ChatType ToChatType(this InputChannel input) => input switch {
internal static class InputChannelExt
{
internal static ChatType ToChatType(this InputChannel input) => input switch
{
InputChannel.Tell => ChatType.TellOutgoing,
InputChannel.Say => ChatType.Say,
InputChannel.Party => ChatType.Party,
@@ -41,7 +43,8 @@ internal static class InputChannelExt {
_ => throw new ArgumentOutOfRangeException(nameof(input), input, null),
};
public static uint LinkshellIndex(this InputChannel channel) => channel switch {
public static uint LinkshellIndex(this InputChannel channel) => channel switch
{
InputChannel.Linkshell1 => 0,
InputChannel.Linkshell2 => 1,
InputChannel.Linkshell3 => 2,
@@ -69,7 +72,8 @@ internal static class InputChannelExt {
_ => uint.MaxValue,
};
public static string Prefix(this InputChannel channel) => channel switch {
public static string Prefix(this InputChannel channel) => channel switch
{
InputChannel.Tell => "/tell",
InputChannel.Say => "/say",
InputChannel.Party => "/party",
@@ -106,52 +110,47 @@ internal static class InputChannelExt {
_ => "",
};
public static IEnumerable<TextCommand>? TextCommands(this InputChannel channel, IDataManager data) {
var ids = channel switch {
InputChannel.Tell => new uint[] { 104, 118 },
InputChannel.Say => new uint[] { 102 },
InputChannel.Party => new uint[] { 105 },
InputChannel.Alliance => new uint[] { 119 },
InputChannel.Yell => new uint[] { 117 },
InputChannel.Shout => new uint[] { 103 },
InputChannel.FreeCompany => new uint[] { 115 },
InputChannel.PvpTeam => new uint[] { 91 },
InputChannel.NoviceNetwork => new uint[] { 101 },
InputChannel.CrossLinkshell1 => new uint[] { 13 },
InputChannel.CrossLinkshell2 => new uint[] { 14 },
InputChannel.CrossLinkshell3 => new uint[] { 15 },
InputChannel.CrossLinkshell4 => new uint[] { 16 },
InputChannel.CrossLinkshell5 => new uint[] { 17 },
InputChannel.CrossLinkshell6 => new uint[] { 18 },
InputChannel.CrossLinkshell7 => new uint[] { 19 },
InputChannel.CrossLinkshell8 => new uint[] { 20 },
InputChannel.Linkshell1 => new uint[] { 107 },
InputChannel.Linkshell2 => new uint[] { 108 },
InputChannel.Linkshell3 => new uint[] { 109 },
InputChannel.Linkshell4 => new uint[] { 110 },
InputChannel.Linkshell5 => new uint[] { 111 },
InputChannel.Linkshell6 => new uint[] { 112 },
InputChannel.Linkshell7 => new uint[] { 113 },
InputChannel.Linkshell8 => new uint[] { 114 },
public static IEnumerable<TextCommand>? TextCommands(this InputChannel channel, IDataManager data)
{
var ids = channel switch
{
InputChannel.Tell => [104, 118],
InputChannel.Say => [102],
InputChannel.Party => [105],
InputChannel.Alliance => [119],
InputChannel.Yell => [117],
InputChannel.Shout => [103],
InputChannel.FreeCompany => [115],
InputChannel.PvpTeam => [91],
InputChannel.NoviceNetwork => [101],
InputChannel.CrossLinkshell1 => [13],
InputChannel.CrossLinkshell2 => [14],
InputChannel.CrossLinkshell3 => [15],
InputChannel.CrossLinkshell4 => [16],
InputChannel.CrossLinkshell5 => [17],
InputChannel.CrossLinkshell6 => [18],
InputChannel.CrossLinkshell7 => [19],
InputChannel.CrossLinkshell8 => [20],
InputChannel.Linkshell1 => [107],
InputChannel.Linkshell2 => [108],
InputChannel.Linkshell3 => [109],
InputChannel.Linkshell4 => [110],
InputChannel.Linkshell5 => [111],
InputChannel.Linkshell6 => [112],
InputChannel.Linkshell7 => [113],
InputChannel.Linkshell8 => [114],
_ => Array.Empty<uint>(),
};
if (ids.Length == 0) {
if (ids.Length == 0)
return null;
}
var cmds = data.GetExcelSheet<TextCommand>();
if (cmds == null) {
return null;
}
return ids
.Select(id => cmds.GetRow(id))
.Where(id => id != null)
.Cast<TextCommand>();
return cmds == null ? null : ids.Select(id => cmds.GetRow(id)).Where(id => id != null).Cast<TextCommand>();
}
internal static bool IsLinkshell(this InputChannel channel) => channel switch {
internal static bool IsLinkshell(this InputChannel channel) => channel switch
{
InputChannel.Linkshell1 => true,
InputChannel.Linkshell2 => true,
InputChannel.Linkshell3 => true,
@@ -163,7 +162,8 @@ internal static class InputChannelExt {
_ => false,
};
internal static bool IsCrossLinkshell(this InputChannel channel) => channel switch {
internal static bool IsCrossLinkshell(this InputChannel channel) => channel switch
{
InputChannel.CrossLinkshell1 => true,
InputChannel.CrossLinkshell2 => true,
InputChannel.CrossLinkshell3 => true,
@@ -174,8 +174,9 @@ internal static class InputChannelExt {
InputChannel.CrossLinkshell8 => true,
_ => false,
};
internal static bool IsExtraChatLinkshell(this InputChannel channel) => channel switch {
internal static bool IsExtraChatLinkshell(this InputChannel channel) => channel switch
{
InputChannel.ExtraChatLinkshell1 => true,
InputChannel.ExtraChatLinkshell2 => true,
InputChannel.ExtraChatLinkshell3 => true,