mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: showing achievements queue
This commit is contained in:
parent
cadb9e8dff
commit
f0e0abae8c
2 changed files with 35 additions and 14 deletions
|
@ -66,6 +66,9 @@ export const mergeAchievements = async (
|
||||||
|
|
||||||
if (newAchievements.length && publishNotification) {
|
if (newAchievements.length && publishNotification) {
|
||||||
const achievementsInfo = newAchievements
|
const achievementsInfo = newAchievements
|
||||||
|
.sort((a, b) => {
|
||||||
|
return a.unlockTime - b.unlockTime;
|
||||||
|
})
|
||||||
.map((achievement) => {
|
.map((achievement) => {
|
||||||
return JSON.parse(localGameAchievement?.achievements || "[]").find(
|
return JSON.parse(localGameAchievement?.achievements || "[]").find(
|
||||||
(steamAchievement) => {
|
(steamAchievement) => {
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import achievementSound from "@renderer/assets/audio/achievement.wav";
|
import achievementSound from "@renderer/assets/audio/achievement.wav";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { vars } from "@renderer/theme.css";
|
import { vars } from "@renderer/theme.css";
|
||||||
|
|
||||||
|
interface AchievementInfo {
|
||||||
|
displayName: string;
|
||||||
|
iconUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
export function Achievement() {
|
export function Achievement() {
|
||||||
const { t } = useTranslation("achievement");
|
const { t } = useTranslation("achievement");
|
||||||
|
|
||||||
const [achievementInfo, setAchievementInfo] = useState<{
|
const [achievements, setAchievements] = useState<AchievementInfo[]>([]);
|
||||||
displayName: string;
|
const achievementAnimation = useRef(-1);
|
||||||
icon: string;
|
|
||||||
} | null>(null);
|
|
||||||
|
|
||||||
const audio = useMemo(() => {
|
const audio = useMemo(() => {
|
||||||
const audio = new Audio(achievementSound);
|
const audio = new Audio(achievementSound);
|
||||||
|
@ -24,11 +27,7 @@ export function Achievement() {
|
||||||
if (!achievements) return;
|
if (!achievements) return;
|
||||||
|
|
||||||
if (achievements.length) {
|
if (achievements.length) {
|
||||||
const achievement = achievements[0];
|
setAchievements((ach) => ach.concat(achievements));
|
||||||
setAchievementInfo({
|
|
||||||
displayName: achievement.displayName,
|
|
||||||
icon: achievement.iconUrl,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
audio.play();
|
audio.play();
|
||||||
|
@ -40,7 +39,26 @@ export function Achievement() {
|
||||||
};
|
};
|
||||||
}, [audio]);
|
}, [audio]);
|
||||||
|
|
||||||
if (!achievementInfo) return null;
|
const hasAchievementsPending = achievements.length > 0;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasAchievementsPending) {
|
||||||
|
let zero = performance.now();
|
||||||
|
achievementAnimation.current = requestAnimationFrame(
|
||||||
|
function animateLock(time) {
|
||||||
|
if (time - zero > 3000) {
|
||||||
|
zero = performance.now();
|
||||||
|
setAchievements((ach) => ach.slice(1));
|
||||||
|
}
|
||||||
|
achievementAnimation.current = requestAnimationFrame(animateLock);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
cancelAnimationFrame(achievementAnimation.current);
|
||||||
|
}
|
||||||
|
}, [hasAchievementsPending]);
|
||||||
|
|
||||||
|
if (!hasAchievementsPending) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -53,13 +71,13 @@ export function Achievement() {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={achievementInfo.icon}
|
src={achievements[0].iconUrl}
|
||||||
alt={achievementInfo.displayName}
|
alt={achievements[0].displayName}
|
||||||
style={{ width: 60, height: 60 }}
|
style={{ width: 60, height: 60 }}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p>{t("achievement_unlocked")}</p>
|
<p>{t("achievement_unlocked")}</p>
|
||||||
<p>{achievementInfo.displayName}</p>
|
<p>{achievements[0].displayName}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue