mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: update achievement audio and refactors
This commit is contained in:
parent
084b7f5b9c
commit
c18c41ac95
13 changed files with 99 additions and 55 deletions
BIN
src/renderer/src/assets/audio/achievement.wav
Normal file
BIN
src/renderer/src/assets/audio/achievement.wav
Normal file
Binary file not shown.
|
@ -179,6 +179,8 @@ export function GameDetailsContextProvider({
|
|||
}, [game?.id, isGameRunning, updateGame]);
|
||||
|
||||
useEffect(() => {
|
||||
window.electron.updateGameUnlockedAchievements(objectID!).catch(() => {});
|
||||
|
||||
const unsubscribe = window.electron.onAchievementUnlocked(
|
||||
(objectId, shop) => {
|
||||
if (objectID !== objectId || shop !== shop) return;
|
||||
|
|
4
src/renderer/src/declaration.d.ts
vendored
4
src/renderer/src/declaration.d.ts
vendored
|
@ -70,12 +70,12 @@ declare global {
|
|||
objectId: string,
|
||||
shop: GameShop
|
||||
) => Promise<GameAchievement[]>;
|
||||
updateGameUnlockedAchievements: (objectId: string) => Promise<void>;
|
||||
onAchievementUnlocked: (
|
||||
cb: (
|
||||
objectId: string,
|
||||
shop: GameShop,
|
||||
displayName: string,
|
||||
iconUrl: string
|
||||
achievements?: { displayName: string; iconUrl: string }[]
|
||||
) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
|
||||
|
|
|
@ -1,27 +1,34 @@
|
|||
import { useEffect, useMemo, useState } from "react";
|
||||
import achievementSound from "@renderer/assets/audio/achievement.wav";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export function Achievemnt() {
|
||||
const { t } = useTranslation("achievement");
|
||||
|
||||
const [achievementInfo, setAchievementInfo] = useState<{
|
||||
displayName: string;
|
||||
icon: string;
|
||||
} | null>(null);
|
||||
|
||||
const audio = useMemo(() => {
|
||||
const audio = new Audio(
|
||||
"https://cms-public-artifacts.artlist.io/content/sfx/aac/94201_690187_Classics_-_Achievement_Unlocked_-_MASTERED_-_2496.aac"
|
||||
);
|
||||
|
||||
const audio = new Audio(achievementSound);
|
||||
audio.volume = 0.2;
|
||||
audio.preload = "auto";
|
||||
return audio;
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = window.electron.onAchievementUnlocked(
|
||||
(_object, _shop, displayName, icon) => {
|
||||
setAchievementInfo({
|
||||
displayName,
|
||||
icon,
|
||||
});
|
||||
(_object, _shop, achievements) => {
|
||||
if (!achievements) return;
|
||||
|
||||
if (achievements.length) {
|
||||
const achievement = achievements[0];
|
||||
setAchievementInfo({
|
||||
displayName: achievement.displayName,
|
||||
icon: achievement.iconUrl,
|
||||
});
|
||||
}
|
||||
|
||||
audio.play();
|
||||
}
|
||||
|
@ -49,7 +56,7 @@ export function Achievemnt() {
|
|||
style={{ width: 60, height: 60 }}
|
||||
/>
|
||||
<div>
|
||||
<p>Achievement unlocked</p>
|
||||
<p>{t("achievement_unlocked")}</p>
|
||||
<p>{achievementInfo.displayName}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue