Skip to content

Commit

Permalink
Updated to version 1.2.1
Browse files Browse the repository at this point in the history
Fixed a bug with villager names not showing
  • Loading branch information
GStefanowich committed Jun 5, 2023
1 parent c069731 commit 2670b8a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 46 deletions.
3 changes: 1 addition & 2 deletions ForecasterText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<PropertyGroup>
<AssemblyName>ForecasterText</AssemblyName>
<RootNamespace>ForecasterText</RootNamespace>
<Version>1.1.1</Version>
<Version>1.2.1</Version>
<TargetFramework>net5.0</TargetFramework>
<GamePath>/mnt/gaming/Steam/steamapps/common/Stardew Valley/</GamePath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Objects\Addons" />
<Folder Include="Properties" />
</ItemGroup>
</Project>
83 changes: 83 additions & 0 deletions Objects/Addons/CharacterEmoji.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
}
20 changes: 15 additions & 5 deletions Objects/Messages/ISourceMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

using System.Collections.Generic;
using ForecasterText.Objects.Addons;
using ForecasterText.Objects.Enums;
using StardewModdingAPI;
using StardewValley;
Expand Down Expand Up @@ -52,12 +53,21 @@ public static MessageSource GetBirthdays(IEnumerable<object> 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);
Expand Down
40 changes: 2 additions & 38 deletions Objects/Messages/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<object> list)) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 2670b8a

Please sign in to comment.