| 1 | using Microsoft.UI; |
| 2 | using Microsoft.UI.Xaml.Media; |
| 3 | |
| 4 | namespace RblxTool.Models; |
| 5 | |
| 6 | public sealed class FeedLine |
| 7 | { |
| 8 | private static readonly SolidColorBrush Neutral = new(Colors.Gainsboro); |
| 9 | private static readonly SolidColorBrush Good = new(Colors.LightGreen); |
| 10 | private static readonly SolidColorBrush Warn = new(Colors.Goldenrod); |
| 11 | private static readonly SolidColorBrush Bad = new(Colors.IndianRed); |
| 12 | private static readonly SolidColorBrush Accent = new(Colors.DeepSkyBlue); |
| 13 | |
| 14 | public FeedLine(string text, FeedTone tone = FeedTone.Neutral) |
| 15 | { |
| 16 | Text = text; |
| 17 | Brush = tone switch |
| 18 | { |
| 19 | FeedTone.Good => Good, |
| 20 | FeedTone.Warn => Warn, |
| 21 | FeedTone.Bad => Bad, |
| 22 | FeedTone.Accent => Accent, |
| 23 | _ => Neutral, |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | public string Text { get; } |
| 28 | |
| 29 | public SolidColorBrush Brush { get; } |
| 30 | |
| 31 | public static FeedLine From(JobEvent item) => item.Type switch |
| 32 | { |
| 33 | "log" => new FeedLine( |
| 34 | $" {item.Message}", |
| 35 | item.Level switch |
| 36 | { |
| 37 | "warn" => FeedTone.Warn, |
| 38 | "error" => FeedTone.Bad, |
| 39 | _ => FeedTone.Neutral, |
| 40 | }), |
| 41 | "item_found" => new FeedLine( |
| 42 | $" found {item.Id,-12} {Clip(item.Name, 44)} {item.Price,6} R$ {Clip(item.Creator, 18)}", |
| 43 | FeedTone.Accent), |
| 44 | "purchase" => new FeedLine( |
| 45 | item.Success |
| 46 | ? $" bought {item.Id,-12} {Clip(item.Name, 44)} {item.Price,6} R$" |
| 47 | : $" skip {item.Id,-12} {Clip(item.Name, 44)} {item.Detail}", |
| 48 | item.Success ? FeedTone.Good : FeedTone.Warn), |
| 49 | "group_found" => new FeedLine( |
| 50 | $" group {item.Id,-12} {Clip(item.Name, 44)} {item.Members,8} members entry {(item.PublicEntry ? "open" : "closed")}", |
| 51 | FeedTone.Accent), |
| 52 | "job_finished" => new FeedLine( |
| 53 | $" done scanned {item.Scanned} matched {item.Matched} acted {item.Purchased} {item.ElapsedMs} ms", |
| 54 | FeedTone.Good), |
| 55 | _ => new FeedLine($" {item.Type}"), |
| 56 | }; |
| 57 | |
| 58 | private static string Clip(string? value, int max) |
| 59 | { |
| 60 | if (string.IsNullOrEmpty(value)) |
| 61 | { |
| 62 | return string.Empty; |
| 63 | } |
| 64 | return value.Length <= max ? value.PadRight(max) : value[..(max - 1)] + "…"; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public enum FeedTone |
| 69 | { |
| 70 | Neutral, |
| 71 | Good, |
| 72 | Warn, |
| 73 | Bad, |
| 74 | Accent, |
| 75 | } |