Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TotalTimeLetter tag #34

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into patch-1
Tenebrosful authored Mar 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0973c0ddd4e8654c04e09f9434af9cca2ee1738a
146 changes: 7 additions & 139 deletions RichPresenceMod.cs
Original file line number Diff line number Diff line change
@@ -42,145 +42,12 @@ public override void Entry(IModHelper helper) {
Monitor.Log("Connected to Discord: " + e.User.ToString(), LogLevel.Info);
client.Initialize();

#region Console Commands
Helper.ConsoleCommands.Add("DiscordReload",
"Reloads the config for Discord Rich Presence.",
(string command, string[] args) =>
{
LoadConfig();
Monitor.Log("Config reloaded.", LogLevel.Info);
}
);
Helper.ConsoleCommands.Add("DiscordFormat",
"Formats and prints a provided configuration string.",
(string command, string[] args) =>
{
string text = api.FormatText(string.Join(" ", args));
Monitor.Log("Result: " + text, LogLevel.Info);
}
);
Helper.ConsoleCommands.Add("DiscordTags",
"Lists tags usable for configuration strings.",
(string command, string[] args) =>
{
IDictionary<string, string> tags =
string.Join("", args).ToLower().StartsWith("all") ?
api.ListTags("[NULL]", "[ERROR]") : api.ListTags(removeNull: false);
IDictionary<string, IDictionary<string, string>> groups =
new Dictionary<string, IDictionary<string, string>>();
foreach (KeyValuePair<string, string> tag in tags)
{
string owner = api.GetTagOwner(tag.Key) ?? "Unknown-Mod";
if (!groups.ContainsKey(owner))
groups[owner] = new Dictionary<string, string>();
groups[owner][tag.Key] = tag.Value;
}
IList<string> output = new List<string>(tags.Count + groups.Count) {
"Available Tags:"
};
int longest = 0;
foreach (KeyValuePair<string, string> tag in groups[ModManifest.UniqueID])
if (tag.Value != null)
longest = Math.Max(longest, tag.Key.Length);
int nulls = 0;
foreach (KeyValuePair<string, string> tag in groups[ModManifest.UniqueID])
if (tag.Value is null) nulls++;
else output.Add(" {{ " + tag.Key.PadLeft(longest) + " }}: " + tag.Value);
foreach (KeyValuePair<string, IDictionary<string, string>> group in groups)
{
if (group.Key == ModManifest.UniqueID)
continue;
string head = group.Value.Count + " tag";
if (group.Value.Count != 1)
head += "s";
head += " from " + (Helper.ModRegistry.Get(group.Key)?.Manifest.Name ?? "an unknown mod");
output.Add(head);
longest = 0;
foreach (KeyValuePair<string, string> tag in group.Value)
if (tag.Value != null)
longest = Math.Max(longest, tag.Key.Length);
foreach (KeyValuePair<string, string> tag in group.Value)
if (tag.Value == null) nulls++;
else output.Add(" {{ " + tag.Key.PadLeft(longest) + " }}: " + tag.Value);
}
if (nulls > 0)
output.Add(nulls + " tag" + (nulls != 1 ? "s" : "") + " unavailable; type `DiscordTags all` to show all");
Monitor.Log(string.Join(Environment.NewLine, output), LogLevel.Info);
}
);
#endregion
LoadConfig();

Helper.Events.Input.ButtonReleased += HandleButton;
Helper.Events.GameLoop.UpdateTicked += DoUpdate;
Helper.Events.GameLoop.SaveLoaded += SetTimestamp;
Helper.Events.GameLoop.ReturnedToTitle += SetTimestamp;
Helper.Events.GameLoop.SaveLoaded += (object sender, SaveLoadedEventArgs e) =>
api.GamePresence = "Getting Started";
Helper.Events.GameLoop.SaveCreated += (object sender, SaveCreatedEventArgs e) =>
api.GamePresence = "Starting a New Game";
Helper.Events.GameLoop.GameLaunched += (object sender, GameLaunchedEventArgs e) =>
{
SetTimestamp();
timestampSession = Timestamps.Now;
};

ITagRegister tagReg = api.GetTagRegister(this);

#region Default Tags

tagReg.SetTag("Activity", () => api.GamePresence);
tagReg.SetTag("ModCount", () => Helper.ModRegistry.GetAll().Count());
tagReg.SetTag("SMAPIVersion", () => Constants.ApiVersion.ToString());
tagReg.SetTag("StardewVersion", () => Game1.version);
tagReg.SetTag("Song", () => Utility.getSongTitleFromCueName(Game1.currentSong?.Name ?? api.None));

tagReg.SetWorldTag("Name", () => Game1.player.Name);
tagReg.SetWorldTag("Farm", () => Game1.content.LoadString("Strings\\UI:Inventory_FarmName", api.GetTag("FarmName")));
tagReg.SetWorldTag("FarmName", () => Game1.player.farmName);
tagReg.SetWorldTag("PetName", () => Game1.player.hasPet() ? Game1.player.getPetDisplayName() : api.None);
tagReg.SetWorldTag("Location", () => Game1.currentLocation.Name);
tagReg.SetWorldTag("RomanticInterest", () => Utility.getTopRomanticInterest(Game1.player)?.getName() ?? api.None);
tagReg.SetWorldTag("NonRomanticInterest", () => Utility.getTopNonRomanticInterest(Game1.player)?.getName() ?? api.None);

tagReg.SetWorldTag("Money", () =>
{
// Copied from LoadGameMenu.drawSlotMoney
string cashText = Game1.content.LoadString("Strings\\StringsFromCSFiles:LoadGameMenu.cs.11020", Utility.getNumberWithCommas(Game1.player.Money));
if (Game1.player.Money == 1 && LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.pt)
cashText = cashText.Substring(0, cashText.Length - 1);
return cashText;
});
tagReg.SetWorldTag("MoneyCommas", () => Utility.getNumberWithCommas(Game1.player.Money));
tagReg.SetWorldTag("MoneyNumber", () => Game1.player.Money);
tagReg.SetWorldTag("Level", () => Game1.content.LoadString("Strings\\UI:Inventory_PortraitHover_Level", Game1.player.Level.ToString()));
tagReg.SetWorldTag("LevelNumber", () => Game1.player.Level);
tagReg.SetWorldTag("Title", () => Game1.player.getTitle());
tagReg.SetWorldTag("TotalTime", () => Utility.getHoursMinutesStringFromMilliseconds(Game1.player.millisecondsPlayed));
tagReg.SetWorldTag("TotalTimeLetterFormat", () => (Utility.getHoursMinutesStringFromMilliseconds(Game1.player.millisecondsPlayed)).replace(":", "h"));

tagReg.SetWorldTag("Health", () => Game1.player.health);
tagReg.SetWorldTag("HealthMax", () => Game1.player.maxHealth);
tagReg.SetWorldTag("HealthPercent", () => (double)Game1.player.health / Game1.player.maxHealth * 100, 2);
tagReg.SetWorldTag("Energy", () => Game1.player.Stamina.ToString());
tagReg.SetWorldTag("EnergyMax", () => Game1.player.MaxStamina);
tagReg.SetWorldTag("EnergyPercent", () => (double)Game1.player.Stamina / Game1.player.MaxStamina * 100, 2);

tagReg.SetWorldTag("Time", () => Game1.getTimeOfDayString(Game1.timeOfDay));
tagReg.SetWorldTag("Date", () => Utility.getDateString());
tagReg.SetWorldTag("Season", () => Utility.getSeasonNameFromNumber(SDate.Now().SeasonIndex));
tagReg.SetWorldTag("DayOfWeek", () => Game1.shortDayDisplayNameFromDayOfSeason(SDate.Now().Day));

tagReg.SetWorldTag("Day", () => SDate.Now().Day);
tagReg.SetWorldTag("DayPad", () => $"{SDate.Now().Day:00}");
tagReg.SetWorldTag("DaySuffix", () => Utility.getNumberEnding(SDate.Now().Day));
tagReg.SetWorldTag("Year", () => SDate.Now().Year);
tagReg.SetWorldTag("YearSuffix", () => Utility.getNumberEnding(SDate.Now().Year));

tagReg.SetWorldTag("GameVerb", () => Context.IsMultiplayer && Context.IsMainPlayer ? "Hosting" : "Playing");
tagReg.SetWorldTag("GameNoun", () => Context.IsMultiplayer ? "Co-op" : "Solo");
tagReg.SetWorldTag("GameInfo", () => api.GetTag("GameVerb") + " " + api.GetTag("GameNoun"));
#endregion
#region Console Commands
Helper.ConsoleCommands.Add("DiscordReload",
"Reloads the config for Discord Rich Presence.",
(string command, string[] args) => {
LoadConfig();
Monitor.Log("Config reloaded.", LogLevel.Info);
}
);
Helper.ConsoleCommands.Add("DiscordFormat",
@@ -252,6 +119,7 @@ public override void Entry(IModHelper helper) {
SetTag(mod, "LevelNumber", ReqWorld(() => Game1.player.Level.ToString()));
SetTag(mod, "Title", ReqWorld(() => Game1.player.getTitle().ToString()));
SetTag(mod, "TotalTime", ReqWorld(() => Utility.getHoursMinutesStringFromMilliseconds(Game1.player.millisecondsPlayed)));
SetTag(mod, "TotalTimeLetterFormat", ReqWorld(() => Utility.getHoursMinutesStringFromMilliseconds(Game1.player.millisecondsPlayed).replace(":", "h")));

SetTag(mod, "Health", ReqWorld(() => Game1.player.health.ToString()));
SetTag(mod, "HealthMax", ReqWorld(() => Game1.player.maxHealth.ToString()));
You are viewing a condensed version of this merge commit. You can view the full changes here.