Skip to content

Commit

Permalink
add buff timer for xp potions
Browse files Browse the repository at this point in the history
  • Loading branch information
ellielle committed Jun 20, 2024
1 parent 6333751 commit 819110e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
32 changes: 31 additions & 1 deletion frontend/src/components/UI/Inventory.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,51 @@
FrozenFlames,
} from "../../../wailsjs/go/main/App.js";
function calculateXPTimer() {
let endsAt = new Date(endTime);
// @ts-ignore
let timeLeft = endsAt - new Date(Date.now());
let minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
timer = `${minutes}:${seconds}`;
}
let timer = null;
let endTime;
onMount(() => {
// Call all inventory-related functions and load it up
SeerStones().then((result) => ($User.seerStones = result));
BakedSalmon().then((result) => ($User.bakedSalmon = result));
XPPotion().then((result) => {
// Using ts-ignore here as my IDE doesn't like the properties on result
// @ts-ignore
$User.xpPotion = result.NumUnusedXPPotion;
// @ts-ignore
// last entry holds the "newest" xp potion, which has
// the ExpiresAt for when the buff drops off
const timerLen = result.ActiveXPPotions.length - 1;
endTime = result.ActiveXPPotions[timerLen].ExpiresAt;
// @ts-ignore
$User.xpTimer = calculateXPTimer();
});
FrozenFlames().then((result) => ($User.frozenFlame = result));
// If there is a buff timer, display the countdown
const interval = setInterval(calculateXPTimer, 1000);
return () => {
clearInterval(interval);
};
});
</script>

<main>
<div class="flex items-center">
<div class="mr-4 flex">
<div id="timer">{timer !== null ? timer : "00:00"}</div>
<div class="mx-4 flex">
<img
src="src/assets/images/xppotion.webp"
alt="XP Potions"
Expand Down
3 changes: 0 additions & 3 deletions inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"io"
"log"
"net/http"
"strconv"

Expand Down Expand Up @@ -120,8 +119,6 @@ func (a *App) FrozenFlames() (int, error) {
}
defer resp.Body.Close()

log.Printf("frozen flames: %#v", resp.Body)

decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&frozenFlames)

Check failure on line 123 in inventory.go

View workflow job for this annotation

GitHub Actions / Format Go

this value of err is never used (SA4006)

Expand Down

0 comments on commit 819110e

Please sign in to comment.