ChatTwo/ChatTwo/Chunk.cs

74 lines
1.8 KiB
C#
Raw Normal View History

2022-02-15 18:02:46 +00:00
using ChatTwo.Code;
2021-12-29 19:31:45 +00:00
using Dalamud.Game.Text.SeStringHandling;
2022-02-13 09:36:08 +00:00
using LiteDB;
2021-12-29 19:31:45 +00:00
namespace ChatTwo;
internal abstract class Chunk {
2022-02-13 09:36:08 +00:00
[BsonIgnore]
2022-01-14 18:25:33 +00:00
internal Message? Message { get; set; }
2022-02-13 09:36:08 +00:00
internal ChunkSource Source { get; set; }
2021-12-30 02:53:44 +00:00
internal Payload? Link { get; set; }
2021-12-29 19:44:05 +00:00
2022-02-13 09:36:08 +00:00
protected Chunk(ChunkSource source, Payload? link) {
this.Source = source;
2021-12-29 19:44:05 +00:00
this.Link = link;
}
2022-02-13 09:36:08 +00:00
internal SeString? GetSeString() => this.Source switch {
ChunkSource.None => null,
ChunkSource.Sender => this.Message?.SenderSource,
ChunkSource.Content => this.Message?.ContentSource,
_ => null,
};
2022-06-14 16:33:06 +00:00
/// <summary>
/// Get some basic text for use in generating hashes.
/// </summary>
internal string StringValue() {
switch (this) {
case TextChunk text:
return text.Content;
case IconChunk icon:
return icon.Icon.ToString();
default:
return "";
}
}
2022-02-13 09:36:08 +00:00
}
internal enum ChunkSource {
None,
Sender,
Content,
2021-12-29 19:31:45 +00:00
}
internal class TextChunk : Chunk {
internal ChatType? FallbackColour { get; set; }
internal uint? Foreground { get; set; }
internal uint? Glow { get; set; }
internal bool Italic { get; set; }
internal string Content { get; set; }
2022-02-13 09:36:08 +00:00
internal TextChunk(ChunkSource source, Payload? link, string content) : base(source, link) {
2021-12-29 19:31:45 +00:00
this.Content = content;
}
2022-02-13 09:36:08 +00:00
#pragma warning disable CS8618
public TextChunk() : base(ChunkSource.None, null) {
2021-12-29 19:31:45 +00:00
}
2022-02-13 09:36:08 +00:00
#pragma warning restore CS8618
2021-12-29 19:31:45 +00:00
}
internal class IconChunk : Chunk {
2021-12-30 02:53:44 +00:00
internal BitmapFontIcon Icon { get; set; }
2021-12-29 19:31:45 +00:00
2022-02-13 09:36:08 +00:00
public IconChunk(ChunkSource source, Payload? link, BitmapFontIcon icon) : base(source, link) {
2021-12-29 19:31:45 +00:00
this.Icon = icon;
}
2022-02-13 09:36:08 +00:00
public IconChunk() : base(ChunkSource.None, null) {
}
2021-12-29 19:31:45 +00:00
}