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

Implement sound action #67

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file added client/src/assets/sounds/bbeating.mp3
Binary file not shown.
Binary file added client/src/assets/sounds/bbjump.mp3
Binary file not shown.
Binary file added client/src/assets/sounds/bbrevive.mp3
Binary file not shown.
Binary file added client/src/assets/sounds/bbshower.mp3
Binary file not shown.
Binary file added client/src/assets/sounds/bbsleeps.mp3
Binary file not shown.
26 changes: 26 additions & 0 deletions client/src/components/Tamagotchi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ import initials from "../../data/initials.tsx";
import Hints from "../Hints/index.tsx";
import dead from '../../assets/img/dead.gif';
import './main.css';
import useSound from 'use-sound';
import feedSound from '../../assets/sounds/bbeating.mp3';
import cleanSound from '../../assets/sounds/bbshower.mp3';
import sleepSound from '../../assets/sounds/bbsleeps.mp3';
import playSound from '../../assets/sounds/bbjump.mp3';
import reviveSound from '../../assets/sounds/bbrevive.mp3';

function Tamagotchi({ sdk }: { sdk: SDK<Schema> }) {
const beast = useBeast(sdk);
const loadingTime = 6000;
const [isLoading, setIsLoading] = useState(false);

// Add sound hooks
const [playFeed] = useSound(feedSound, { volume: 0.7, preload: true });
const [playClean] = useSound(cleanSound, { volume: 0.7, preload: true });
const [playSleep] = useSound(sleepSound, { volume: 0.7, preload: true });
const [playPlay] = useSound(playSound, { volume: 0.7, preload: true });
const [playRevive] = useSound(reviveSound, { volume: 0.7, preload: true });

const {
setup: { client },
} = useDojo();
Expand Down Expand Up @@ -66,6 +79,19 @@ function Tamagotchi({ sdk }: { sdk: SDK<Schema> }) {
const handleAction = async (actionName: string, actionFn: () => Promise<{ transaction_hash: string } | undefined>, animation: string) => {
setIsLoading(true);
showAnimation(animation);

// Trigger sound based on action
switch(actionName) {
case 'Feed': playFeed(); break;
case 'Clean': playClean(); break;
case 'Sleep': playSleep(); break;
case 'Play': playPlay(); break;
case 'Revive': playRevive(); break;
case 'Wake up':
console.warn('Missing sound for awake action');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get a sound for this please? and set it, thanks @juandiegocv27 @jimenezz22

break;
}

try {
await toast.promise(
actionFn(),
Expand Down