Skip to content

Commit

Permalink
add sound volume
Browse files Browse the repository at this point in the history
  • Loading branch information
neolao committed Feb 29, 2020
1 parent 10d23e6 commit 765c2fc
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Properties
| `fullscreen` | Fullscreen (default: `false`) |
| `frame` | Application with frame (default: `false`) |
| `background` | Image path of the background |
| `sound.volume` | Sound volume in percent (default: `100`) |
| `sound.background` | File path of the background sound |
| `sound.selectCharacter` | File path of the sound played when selecting a character |
| `sound.selectAILevel` | File path of the sound played when selecting the AI level |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mugen-quick-versus-launcher",
"author": "neolao",
"license": "MIT",
"version": "0.17.0",
"version": "0.18.0",
"description": "Mugen launcher for Quick Versus",
"keywords": [
"mugen",
Expand Down
6 changes: 6 additions & 0 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ export default function App() {
}

if (configuration.sound && configuration.sound.background) {
let volume = 100;
if (configuration.sound.volume) {
volume = configuration.sound.volume;
}

const soundPath = path.resolve(environment.currentDirectory, configuration.sound.background);
if (fs.existsSync(soundPath)) {
const audio = new Audio(soundPath);
audio.volume = volume / 100;
audio.loop = true;
audio.play();

Expand Down
3 changes: 3 additions & 0 deletions src/configuration/useCancelSound.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useMemo } from "react";
import { remote } from "electron";
import useConfiguration from "./useConfiguration.hook";
import useEnvironment from "./useEnvironment.hook";
import useSoundVolume from "./useSoundVolume.hook";
import noSound from "./noSound";
const path = remote.require("path");

export default function useCancelSound() {
const environment = useEnvironment();
const configuration = useConfiguration();
const volume = useSoundVolume();

return useMemo(() => {
if (!configuration.sound) {
Expand All @@ -20,6 +22,7 @@ export default function useCancelSound() {

const filePath = path.resolve(environment.currentDirectory, configuration.sound.cancel);
const audio = new Audio(filePath);
audio.volume = volume / 100;
return {
play: () => {
audio.pause();
Expand Down
3 changes: 3 additions & 0 deletions src/configuration/useMoveCursorSound.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useMemo } from "react";
import { remote } from "electron";
import useConfiguration from "./useConfiguration.hook";
import useEnvironment from "./useEnvironment.hook";
import useSoundVolume from "./useSoundVolume.hook";
import noSound from "./noSound";
const path = remote.require("path");

export default function useMoveCursorSound() {
const environment = useEnvironment();
const configuration = useConfiguration();
const volume = useSoundVolume();

return useMemo(() => {
if (!configuration.sound) {
Expand All @@ -20,6 +22,7 @@ export default function useMoveCursorSound() {

const filePath = path.resolve(environment.currentDirectory, configuration.sound.moveCursor);
const audio = new Audio(filePath);
audio.volume = volume / 100;
return {
play: () => {
audio.pause();
Expand Down
3 changes: 3 additions & 0 deletions src/configuration/useSelectAILevelSound.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useMemo } from "react";
import { remote } from "electron";
import useConfiguration from "./useConfiguration.hook";
import useEnvironment from "./useEnvironment.hook";
import useSoundVolume from "./useSoundVolume.hook";
import noSound from "./noSound";
const path = remote.require("path");

export default function useSelectAILevelSound() {
const environment = useEnvironment();
const configuration = useConfiguration();
const volume = useSoundVolume();

return useMemo(() => {
if (!configuration.sound) {
Expand All @@ -20,6 +22,7 @@ export default function useSelectAILevelSound() {

const filePath = path.resolve(environment.currentDirectory, configuration.sound.selectAILevel);
const audio = new Audio(filePath);
audio.volume = volume / 100;
return {
play: () => {
audio.pause();
Expand Down
3 changes: 3 additions & 0 deletions src/configuration/useSelectCharacterSound.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useMemo } from "react";
import { remote } from "electron";
import useConfiguration from "./useConfiguration.hook";
import useEnvironment from "./useEnvironment.hook";
import useSoundVolume from "./useSoundVolume.hook";
import noSound from "./noSound";
const path = remote.require("path");

export default function useSelectCharacterSound() {
const environment = useEnvironment();
const configuration = useConfiguration();
const volume = useSoundVolume();

return useMemo(() => {
if (!configuration.sound) {
Expand All @@ -20,6 +22,7 @@ export default function useSelectCharacterSound() {

const filePath = path.resolve(environment.currentDirectory, configuration.sound.selectCharacter);
const audio = new Audio(filePath);
audio.volume = volume / 100;
return {
play: () => {
audio.pause();
Expand Down
11 changes: 11 additions & 0 deletions src/configuration/useSoundVolume.hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import useConfiguration from "./useConfiguration.hook";

export default function useSoundVolume() {
const configuration = useConfiguration();

if (configuration.sound && configuration.sound.volume) {
return configuration.sound.volume;
}

return 100;
}
1 change: 1 addition & 0 deletions src/style/window.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ body {
cursor: none;
overflow: hidden;
user-select: none;
transform: translateZ(0);
}

#root {
Expand Down

0 comments on commit 765c2fc

Please sign in to comment.