Skip to content

Commit

Permalink
frontend: also add support for seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser committed Nov 5, 2023
1 parent e35e5f6 commit 4d51fce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/games/GameControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
let settingsDir = undefined;
let savesDir = undefined;
let isLinux = false;
let playtime = "";
onMount(async () => {
isLinux = (await platform()) === "linux";
Expand All @@ -50,6 +51,7 @@
// calculate the number of hours and minutes
const hours = Math.floor(playtimeRaw / 3600);
const minutes = Math.floor((playtimeRaw % 3600) / 60);
const seconds = Math.floor(playtimeRaw % 60);
// initialize the formatted playtime string
let formattedPlaytime = "";
Expand All @@ -68,12 +70,19 @@
formattedPlaytime += `${minutes} minute${minutes > 1 ? "s" : ""}`;
}
// add the seconds to the formatted playtime string
if (seconds > 0) {
// add a comma if there are already hours or minutes in the formatted playtime string
if (formattedPlaytime.length > 0) {
formattedPlaytime += ", ";
}
formattedPlaytime += `${seconds} second${seconds > 1 ? "s" : ""}`;
}
// return the formatted playtime string
return formattedPlaytime;
}
let playtime = "";
// get the playtime from the backend, format it, and assign it to the playtime variable when the page first loads
getPlaytime(getInternalName(activeGame)).then((result) => {
playtime = formatPlaytime(result);
Expand Down

0 comments on commit 4d51fce

Please sign in to comment.