|
| 1 | +using Archipelago.MultiClient.Net.Enums; |
| 2 | +using Archipelago.MultiClient.Net.Helpers; |
| 3 | +using Archipelago.MultiClient.Net.Models; |
| 4 | + |
| 5 | +namespace Archipelago.MultiClient.Net.Colors |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Static utilities for getting the appropriate palette color from various protocol-provided information |
| 9 | + /// </summary> |
| 10 | + public static class ColorUtils |
| 11 | + { |
| 12 | + /// <summary> |
| 13 | + /// The color to be used to represent the currently connected player |
| 14 | + /// </summary> |
| 15 | + public const PaletteColor ActivePlayerColor = PaletteColor.Magenta; |
| 16 | + /// <summary> |
| 17 | + /// The color to be used to represent any player other the currently connected player |
| 18 | + /// </summary> |
| 19 | + public const PaletteColor NonActivePlayerColor = PaletteColor.Yellow; |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Gets the palette color corresponding to a JsonMessagePartColor. |
| 23 | + /// </summary> |
| 24 | + /// <returns>The corresponding palette color, or null if not specified</returns> |
| 25 | + public static PaletteColor? GetColor(JsonMessagePartColor color) |
| 26 | + { |
| 27 | + switch (color) |
| 28 | + { |
| 29 | + case JsonMessagePartColor.Red: |
| 30 | + case JsonMessagePartColor.RedBg: |
| 31 | + return PaletteColor.Red; |
| 32 | + case JsonMessagePartColor.Green: |
| 33 | + case JsonMessagePartColor.GreenBg: |
| 34 | + return PaletteColor.Green; |
| 35 | + case JsonMessagePartColor.Yellow: |
| 36 | + case JsonMessagePartColor.YellowBg: |
| 37 | + return PaletteColor.Yellow; |
| 38 | + case JsonMessagePartColor.Blue: |
| 39 | + case JsonMessagePartColor.BlueBg: |
| 40 | + return PaletteColor.Blue; |
| 41 | + case JsonMessagePartColor.Magenta: |
| 42 | + case JsonMessagePartColor.MagentaBg: |
| 43 | + return PaletteColor.Magenta; |
| 44 | + case JsonMessagePartColor.Cyan: |
| 45 | + case JsonMessagePartColor.CyanBg: |
| 46 | + return PaletteColor.Cyan; |
| 47 | + case JsonMessagePartColor.Black: |
| 48 | + case JsonMessagePartColor.BlackBg: |
| 49 | + return PaletteColor.Black; |
| 50 | + case JsonMessagePartColor.White: |
| 51 | + case JsonMessagePartColor.WhiteBg: |
| 52 | + return PaletteColor.White; |
| 53 | + default: |
| 54 | + return null; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Gets the palette color corresponding to a HintStatus. |
| 60 | + /// </summary> |
| 61 | + /// <returns>The corresponding palette color, or null if not specified</returns> |
| 62 | + public static PaletteColor? GetColor(HintStatus status) |
| 63 | + { |
| 64 | + switch (status) |
| 65 | + { |
| 66 | + case HintStatus.Found: |
| 67 | + return PaletteColor.Green; |
| 68 | + case HintStatus.NoPriority: |
| 69 | + return PaletteColor.SlateBlue; |
| 70 | + case HintStatus.Avoid: |
| 71 | + return PaletteColor.Salmon; |
| 72 | + case HintStatus.Priority: |
| 73 | + return PaletteColor.Plum; |
| 74 | + default: |
| 75 | + return null; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Gets the palette color corresponding to a Hint's status. |
| 81 | + /// </summary> |
| 82 | + /// <returns>The corresponding palette color, or null if not specified</returns> |
| 83 | + public static PaletteColor? GetColor(Hint hint) |
| 84 | + { |
| 85 | + return GetColor(hint.Status); |
| 86 | + } |
| 87 | + |
| 88 | + /// <summary> |
| 89 | + /// Gets the palette color corresponding to an ItemFlags. |
| 90 | + /// </summary> |
| 91 | + /// <returns>The corresponding palette color, or null if not specified</returns> |
| 92 | + public static PaletteColor? GetColor(ItemFlags flags) |
| 93 | + { |
| 94 | + if (HasFlag(flags, ItemFlags.Advancement)) |
| 95 | + return PaletteColor.Plum; |
| 96 | + if (HasFlag(flags, ItemFlags.NeverExclude)) |
| 97 | + return PaletteColor.SlateBlue; |
| 98 | + if (HasFlag(flags, ItemFlags.Trap)) |
| 99 | + return PaletteColor.Salmon; |
| 100 | + |
| 101 | + return PaletteColor.Cyan; |
| 102 | + } |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Gets the palette color corresponding to an ItemInfo's flags. |
| 106 | + /// </summary> |
| 107 | + /// <returns>The corresponding palette color, or null if not specified</returns> |
| 108 | + public static PaletteColor? GetColor(ItemInfo item) |
| 109 | + { |
| 110 | + return GetColor(item.Flags); |
| 111 | + } |
| 112 | + |
| 113 | + /// <summary> |
| 114 | + /// Gets the palette color corresponding to a PlayerInfo. |
| 115 | + /// </summary> |
| 116 | + /// <returns>The corresponding palette color, or null if not specified</returns> |
| 117 | + public static PaletteColor? GetColor(PlayerInfo player, IConnectionInfoProvider connectionInfo) |
| 118 | + { |
| 119 | + bool isActivePlayer = player.Slot == connectionInfo.Slot; |
| 120 | + return isActivePlayer ? ActivePlayerColor : NonActivePlayerColor; |
| 121 | + } |
| 122 | + |
| 123 | + static bool HasFlag(ItemFlags flags, ItemFlags flag) => |
| 124 | +#if NET35 |
| 125 | + (flags & flag) > 0; |
| 126 | +#else |
| 127 | + flags.HasFlag(flag); |
| 128 | +#endif |
| 129 | + } |
| 130 | +} |
0 commit comments