diff --git a/client/apps/game/src/hooks/store/useUIStore.tsx b/client/apps/game/src/hooks/store/useUIStore.tsx index 307f1e4bc..e95502349 100644 --- a/client/apps/game/src/hooks/store/useUIStore.tsx +++ b/client/apps/game/src/hooks/store/useUIStore.tsx @@ -4,6 +4,7 @@ import { ContractAddress } from "@bibliothecadao/eternum"; import React from "react"; import { create } from "zustand"; import { subscribeWithSelector } from "zustand/middleware"; +import { tracks } from "../useMusic"; import { BuildModeStore, createBuildModeStoreSlice } from "./_buildModeStore"; import { PopupsStore, createPopupsSlice } from "./_popupsStore"; import { ThreeStore, createThreeStoreSlice } from "./_threeStore"; @@ -73,6 +74,8 @@ interface UIStore { export type AppStore = UIStore & PopupsStore & ThreeStore & BuildModeStore & RealmStore & BlockchainStore & WorldStore; +const initialTrackIndex = Math.floor(Math.random() * tracks.length); + const useUIStore = create( subscribeWithSelector<AppStore>((set, get) => ({ theme: "light", @@ -84,9 +87,9 @@ const useUIStore = create( isSideMenuOpened: true, toggleSideMenu: () => set((state) => ({ isSideMenuOpened: !state.isSideMenuOpened })), isSoundOn: localStorage.getItem("soundEnabled") ? localStorage.getItem("soundEnabled") === "true" : true, - trackName: "Day Break", + trackName: tracks[initialTrackIndex].name, setTrackName: (name) => set({ trackName: name }), - trackIndex: 1, + trackIndex: initialTrackIndex, setTrackIndex: (index) => set({ trackIndex: index }), toggleSound: () => set((state) => { diff --git a/client/apps/game/src/hooks/useMusic.tsx b/client/apps/game/src/hooks/useMusic.tsx index f9479983f..c083c0292 100644 --- a/client/apps/game/src/hooks/useMusic.tsx +++ b/client/apps/game/src/hooks/useMusic.tsx @@ -9,7 +9,7 @@ type Track = { }; // Your tracks list -const tracks: Track[] = [ +export const tracks: Track[] = [ { name: "Day Break", url: "/sound/music/DayBreak.mp3" }, { name: "Morning Ember", url: "/sound/music/MorningEmber.mp3" }, { name: "Beyond The Horizon", url: "/sound/music/BeyondTheHorizon.mp3" }, @@ -22,6 +22,7 @@ const tracks: Track[] = [ { name: "Strangers Arrival", url: "/sound/music/StrangersArrival.mp3" }, { name: "Twilight Harvest", url: "/sound/music/TwilightHarvest.mp3" }, { name: "Wanderers Chronicle", url: "/sound/music/WanderersChronicle.mp3" }, + { name: "Happy Realm", url: "/sound/music/happy_realm.mp3" }, ]; export const useMusicPlayer = () => {