diff --git a/ForecasterText.csproj b/ForecasterText.csproj index 79c6023..aa5a24f 100644 --- a/ForecasterText.csproj +++ b/ForecasterText.csproj @@ -3,7 +3,7 @@ ForecasterText ForecasterText - 1.1.1 + 1.2.1 net5.0 /mnt/gaming/Steam/steamapps/common/Stardew Valley/ @@ -11,7 +11,6 @@ - \ No newline at end of file diff --git a/Objects/Addons/CharacterEmoji.cs b/Objects/Addons/CharacterEmoji.cs new file mode 100644 index 0000000..dcebff7 --- /dev/null +++ b/Objects/Addons/CharacterEmoji.cs @@ -0,0 +1,83 @@ +/* + * This software is licensed under the MIT License + * https://github.com/GStefanowich/SDV-Forecaster + * + * Copyright (c) 2019 Gregory Stefanowich + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +using System.Globalization; +using StardewValley; + +namespace ForecasterText.Objects.Addons { + public static class CharacterEmoji { + public static string GetName(this Character character) + => character switch { + NPC npc => npc.getName(), + _ => character.Name + }; + + public static bool HasEmoji(this Character character) + => GetEmoji(character.GetName()) is not null; + + public static bool HasEmoji(string name) + => GetEmoji(name) is not null; + + public static uint? GetEmoji(string name) + => name.ToLower(CultureInfo.InvariantCulture) switch { + "abigail" => 154u, + "penny" => 155u, + "maru" => 156u, + "leah" => 157u, + "haley" => 158u, + "emily" => 159u, + "alex" => 160u, + "shane" => 161u, + "sebastian" => 162u, + "sam" => 163u, + "harvey" => 164u, + "elliot" => 165u, + "sandy" => 166u, + "evelyn" => 167u, + "marnie" => 168u, + "caroline" => 169u, + "robin" => 170u, + "pierre" => 171u, + "pam" => 172u, + "jodi" => 173u, + "lewis" => 174u, + "linus" => 175u, + "marlon" => 176u, + "willy" => 177u, + "wizard" => 178u, + "morris" => 179u, + "jas" => 180u, + "vincent" => 181u, + "krobus" => 182u, + "dwarf" => 183u, + "gus" => 184u, + "gunther" => 185u, + "george" => 186u, + "demetrius" => 187u, + "clint" => 188u, + _ => null + }; + } +} diff --git a/Objects/Messages/ISourceMessage.cs b/Objects/Messages/ISourceMessage.cs index 1a542c8..bc470e5 100644 --- a/Objects/Messages/ISourceMessage.cs +++ b/Objects/Messages/ISourceMessage.cs @@ -24,6 +24,7 @@ */ using System.Collections.Generic; +using ForecasterText.Objects.Addons; using ForecasterText.Objects.Enums; using StardewModdingAPI; using StardewValley; @@ -52,12 +53,21 @@ public static MessageSource GetBirthdays(IEnumerable characters, Forecas builder ??= new MessageBuilder("tv.birthday") .AddEmoji("icon", MiscEmoji.BIRTHDAY); - if (!config.UseVillagerNames) - _ = obj is Character character ? builder.AddEmoji("...", character) : builder.AddNpcEmoji("...", obj as string); - else { - builder.PadText("...", ' ') // Add a space between names - .AddText("...", obj as string); + // If using Emojis + if (!config.UseVillagerNames) { + // Try adding an emoji + if(obj switch { + Character character when character.HasEmoji() + => builder.AddEmoji("...", character), + string name when CharacterEmoji.HasEmoji(name) + => builder.AddNpcEmoji("...", name), + _ => null + } is not null) + continue; // Continue to next to skip fallback to name (For custom NPCs) } + + builder.PadText("...", ' ') // Add a space between names + .AddText("...", (obj as Character)?.GetName() ?? obj as string); } return MessageSource.Calendar(builder); diff --git a/Objects/Messages/MessageBuilder.cs b/Objects/Messages/MessageBuilder.cs index 8e56d99..02fc42a 100644 --- a/Objects/Messages/MessageBuilder.cs +++ b/Objects/Messages/MessageBuilder.cs @@ -28,6 +28,7 @@ using System.Globalization; using System.Linq; using System.Text; +using ForecasterText.Objects.Addons; using ForecasterText.Objects.Enums; using StardewModdingAPI; using StardewValley; @@ -76,44 +77,7 @@ public MessageBuilder AddEmoji(string key, MiscEmoji icon) NPC npc => this.AddNpcEmoji(key, npc.getName()), _ => this }; - public MessageBuilder AddNpcEmoji(string key, string name) => this.AddEmoji(key, name.ToLower(CultureInfo.InvariantCulture) switch { - "abigail" => 154u, - "penny" => 155u, - "maru" => 156u, - "leah" => 157u, - "haley" => 158u, - "emily" => 159u, - "alex" => 160u, - "shane" => 161u, - "sebastian" => 162u, - "sam" => 163u, - "harvey" => 164u, - "elliot" => 165u, - "sandy" => 166u, - "evelyn" => 167u, - "marnie" => 168u, - "caroline" => 169u, - "robin" => 170u, - "pierre" => 171u, - "pam" => 172u, - "jodi" => 173u, - "lewis" => 174u, - "linus" => 175u, - "marlon" => 176u, - "willy" => 177u, - "wizard" => 178u, - "morris" => 179u, - "jas" => 180u, - "vincent" => 181u, - "krobus" => 182u, - "dwarf" => 183u, - "gus" => 184u, - "gunther" => 185u, - "george" => 186u, - "demetrius" => 187u, - "clint" => 188u, - _ => null - }); + public MessageBuilder AddNpcEmoji(string key, string name) => this.AddEmoji(key, CharacterEmoji.GetEmoji(name)); private MessageBuilder Add(string key, object value) { if (!this.Values.TryGetValue(key, out IList list)) { diff --git a/manifest.json b/manifest.json index 982afd7..4d014ed 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "Name": "Forecaster Text", "Author": "TheElm", - "Version": "1.2.0", + "Version": "1.2.1", "Description": "Receive messages from the News station every day", "UniqueID": "TheElm.ForecasterText", "EntryDll": "ForecasterText.dll",