1f7f0945c5
Repository folder, csproj, solution and all CI/build paths now use
the consolidated HellionChat name.
- ChatTwo/ → HellionChat/ (git mv preserves history with --follow)
- ChatTwo.csproj → HellionChat.csproj
- ChatTwo.sln → HellionChat.sln; obsolete Tests project entry removed
(private/untracked sandbox)
- AssemblyInfo.cs InternalsVisibleTo for ChatTwo.Tests removed
(file emptied; can be repopulated when actual tests land)
- repo.json and yaml image URLs updated (ChatTwo/images/ → HellionChat/images/)
- .github/workflows/{build,codeql,release}.yml csproj paths
- .github/dependabot.yml directory path
Functional behavior unchanged.
130 lines
3.4 KiB
C#
Executable File
130 lines
3.4 KiB
C#
Executable File
using HellionChat.Code;
|
|
using Dalamud.Game.Text.SeStringHandling;
|
|
using MessagePack;
|
|
|
|
namespace HellionChat;
|
|
|
|
[Union(0, typeof(TextChunk))]
|
|
[Union(1, typeof(IconChunk))]
|
|
[MessagePackObject]
|
|
public abstract class Chunk
|
|
{
|
|
[IgnoreMember]
|
|
internal Message? Message { get; set; }
|
|
|
|
[Key(0)]
|
|
public ChunkSource Source { get; set; }
|
|
|
|
[Key(1)]
|
|
[MessagePackFormatter(typeof(PayloadMessagePackFormatter))]
|
|
public Payload? Link { get; set; }
|
|
|
|
protected Chunk(ChunkSource source, Payload? link)
|
|
{
|
|
Source = source;
|
|
Link = link;
|
|
}
|
|
|
|
internal SeString? GetSeString() => Source switch
|
|
{
|
|
ChunkSource.None => null,
|
|
ChunkSource.Sender => Message?.SenderSource,
|
|
ChunkSource.Content => Message?.ContentSource,
|
|
_ => null,
|
|
};
|
|
|
|
/// <summary>
|
|
/// Get some basic text for use in generating hashes.
|
|
/// </summary>
|
|
internal string StringValue()
|
|
{
|
|
return this switch
|
|
{
|
|
TextChunk text => text.Content,
|
|
IconChunk icon => icon.Icon.ToString(),
|
|
_ => ""
|
|
};
|
|
}
|
|
}
|
|
|
|
public enum ChunkSource
|
|
{
|
|
None,
|
|
Sender,
|
|
Content,
|
|
}
|
|
|
|
[MessagePackObject(AllowPrivate = true)]
|
|
public class TextChunk : Chunk
|
|
{
|
|
[Key(2)] public ChatType? FallbackColour;
|
|
[Key(3)] public uint? Foreground;
|
|
[Key(4)] public uint? Glow;
|
|
[Key(5)] public bool Italic;
|
|
[Key(6)] public string Content;
|
|
|
|
private TextChunk(Chunk chunk, string content) : base(chunk.Source, chunk.Link)
|
|
{
|
|
Content = content;
|
|
}
|
|
|
|
internal TextChunk(ChunkSource source, Payload? link, string content) : base(source, link)
|
|
{
|
|
// This has been null in the past, and it broke rendering code.
|
|
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
|
|
Content = content ?? "";
|
|
}
|
|
|
|
// ReSharper disable once UnusedMember.Global // Used by MessagePack
|
|
public TextChunk(ChunkSource source, Payload? link, ChatType? fallbackColour, uint? foreground, uint? glow, bool italic, string content) : base(source, link)
|
|
{
|
|
FallbackColour = fallbackColour;
|
|
Foreground = foreground;
|
|
Glow = glow;
|
|
Italic = italic;
|
|
// See above.
|
|
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
|
|
Content = content ?? "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new TextChunk with identical styling to this one.
|
|
/// </summary>
|
|
public TextChunk NewWithStyle(ChunkSource source, Payload? link, string content)
|
|
{
|
|
return new TextChunk(source, link, content)
|
|
{
|
|
FallbackColour = FallbackColour,
|
|
Foreground = Foreground,
|
|
Glow = Glow,
|
|
Italic = Italic,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new TextChunk with identical styling to this one.
|
|
/// </summary>
|
|
public TextChunk NewWithStyle(Chunk chunk, string content)
|
|
{
|
|
return new TextChunk(chunk, content)
|
|
{
|
|
FallbackColour = FallbackColour,
|
|
Foreground = Foreground,
|
|
Glow = Glow,
|
|
Italic = Italic,
|
|
};
|
|
}
|
|
}
|
|
|
|
[MessagePackObject(AllowPrivate = true)]
|
|
public class IconChunk : Chunk
|
|
{
|
|
[Key(2)]
|
|
public BitmapFontIcon Icon { get; set; }
|
|
|
|
public IconChunk(ChunkSource source, Payload? link, BitmapFontIcon icon) : base(source, link)
|
|
{
|
|
Icon = icon;
|
|
}
|
|
}
|