Add volume control
Fix random seed at start Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
3648b58f5c
commit
bedea71cb3
@ -82,6 +82,7 @@ const Table = () => {
|
|||||||
const [winnerDismissed, setWinnerDismissed] = useState(undefined);
|
const [winnerDismissed, setWinnerDismissed] = useState(undefined);
|
||||||
const [global, setGlobal] = useState({});
|
const [global, setGlobal] = useState({});
|
||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
|
const [volume, setVolume] = useState(0.5);
|
||||||
const fields = [ 'id', 'state', 'color', 'name', 'private', 'dice', 'turn' ];
|
const fields = [ 'id', 'state', 'color', 'name', 'private', 'dice', 'turn' ];
|
||||||
|
|
||||||
const onWsOpen = (event) => {
|
const onWsOpen = (event) => {
|
||||||
@ -353,6 +354,7 @@ const Table = () => {
|
|||||||
if (state === 'volcano') {
|
if (state === 'volcano') {
|
||||||
if (!audioEffects.volcano) {
|
if (!audioEffects.volcano) {
|
||||||
audioEffects.volcano = loadAudio('volcano-eruption.mp3');
|
audioEffects.volcano = loadAudio('volcano-eruption.mp3');
|
||||||
|
audioEffects.volcano.volume = volume * volume;
|
||||||
} else {
|
} else {
|
||||||
if (!audioEffects.volcano.hasPlayed) {
|
if (!audioEffects.volcano.hasPlayed) {
|
||||||
audioEffects.volcano.hasPlayed = true;
|
audioEffects.volcano.hasPlayed = true;
|
||||||
@ -370,6 +372,7 @@ const Table = () => {
|
|||||||
if (turn && turn.color === color) {
|
if (turn && turn.color === color) {
|
||||||
if (!audioEffects.yourTurn) {
|
if (!audioEffects.yourTurn) {
|
||||||
audioEffects.yourTurn = loadAudio('its-your-turn.mp3');
|
audioEffects.yourTurn = loadAudio('its-your-turn.mp3');
|
||||||
|
audioEffects.yourTurn.volume = volume * volume;
|
||||||
} else {
|
} else {
|
||||||
if (!audioEffects.yourTurn.hasPlayed) {
|
if (!audioEffects.yourTurn.hasPlayed) {
|
||||||
audioEffects.yourTurn.hasPlayed = true;
|
audioEffects.yourTurn.hasPlayed = true;
|
||||||
@ -385,6 +388,7 @@ const Table = () => {
|
|||||||
if (turn && turn.roll === 7) {
|
if (turn && turn.roll === 7) {
|
||||||
if (!audioEffects.robber) {
|
if (!audioEffects.robber) {
|
||||||
audioEffects.robber = loadAudio('robber.mp3');
|
audioEffects.robber = loadAudio('robber.mp3');
|
||||||
|
audioEffects.robber.volume = volume * volume;
|
||||||
} else {
|
} else {
|
||||||
if (!audioEffects.robber.hasPlayed) {
|
if (!audioEffects.robber.hasPlayed) {
|
||||||
audioEffects.robber.hasPlayed = true;
|
audioEffects.robber.hasPlayed = true;
|
||||||
@ -400,6 +404,7 @@ const Table = () => {
|
|||||||
if (turn && turn.actions && turn.actions.indexOf('playing-knight') !== -1) {
|
if (turn && turn.actions && turn.actions.indexOf('playing-knight') !== -1) {
|
||||||
if (!audioEffects.knights) {
|
if (!audioEffects.knights) {
|
||||||
audioEffects.knights = loadAudio('the-knights-who-say-ni.mp3');
|
audioEffects.knights = loadAudio('the-knights-who-say-ni.mp3');
|
||||||
|
audioEffects.knights.volume = volume * volume;
|
||||||
} else {
|
} else {
|
||||||
if (!audioEffects.knights.hasPlayed) {
|
if (!audioEffects.knights.hasPlayed) {
|
||||||
audioEffects.knights.hasPlayed = true;
|
audioEffects.knights.hasPlayed = true;
|
||||||
@ -411,7 +416,13 @@ const Table = () => {
|
|||||||
audioEffects.knights.hasPlayed = false;
|
audioEffects.knights.hasPlayed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [turn, color]);
|
}, [turn, color, volume]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
for (let key in audioEffects) {
|
||||||
|
audioEffects[key].volume = volume * volume;
|
||||||
|
}
|
||||||
|
}, [volume]);
|
||||||
|
|
||||||
return <GlobalContext.Provider value={global}>
|
return <GlobalContext.Provider value={global}>
|
||||||
{ /* <PingPong/> */ }
|
{ /* <PingPong/> */ }
|
||||||
@ -463,6 +474,15 @@ const Table = () => {
|
|||||||
<Hand {...{buildActive, setBuildActive, setCardActive}}/>
|
<Hand {...{buildActive, setBuildActive, setCardActive}}/>
|
||||||
</div>
|
</div>
|
||||||
<div className="Sidebar">
|
<div className="Sidebar">
|
||||||
|
{ name !== "" && volume !== undefined && <Paper className="Volume">
|
||||||
|
<div>Sound effects volume</div> <input type="range" id="volume" name="volume"
|
||||||
|
value={volume * 100}
|
||||||
|
min="0" max="100" onInput={(e) => {
|
||||||
|
const alpha = e.currentTarget.value / 100;
|
||||||
|
|
||||||
|
setVolume(alpha);
|
||||||
|
}}/>
|
||||||
|
</Paper>}
|
||||||
{ name !== "" && <PlayerList/> }
|
{ name !== "" && <PlayerList/> }
|
||||||
<Trade {...{tradeActive, setTradeActive}}/>
|
<Trade {...{tradeActive, setTradeActive}}/>
|
||||||
{ name !== "" && <Chat/> }
|
{ name !== "" && <Chat/> }
|
||||||
|
@ -49,6 +49,14 @@
|
|||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Volume {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 0.1rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.Pip {
|
.Pip {
|
||||||
z-index: 50; /* Above Tile (5,10), Road (12), Corner (20) */
|
z-index: 50; /* Above Tile (5,10), Road (12), Corner (20) */
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -123,6 +123,7 @@ const Board = () => {
|
|||||||
console.log(`board - setting new animationSeeds`);
|
console.log(`board - setting new animationSeeds`);
|
||||||
setAnimationSeeds(data.update.animationSeeds);
|
setAnimationSeeds(data.update.animationSeeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('tileOrder' in data.update && !equal(data.update.tileOrder, tileOrder)) {
|
if ('tileOrder' in data.update && !equal(data.update.tileOrder, tileOrder)) {
|
||||||
console.log(`board - setting new tileOrder`);
|
console.log(`board - setting new tileOrder`);
|
||||||
setTileOrder(data.update.tileOrder);
|
setTileOrder(data.update.tileOrder);
|
||||||
|
@ -4711,7 +4711,10 @@ const setBeginnerGame = (game) => {
|
|||||||
18, 8, 15
|
18, 8, 15
|
||||||
];
|
];
|
||||||
game.robber = 9;
|
game.robber = 9;
|
||||||
|
game.animationSeeds = [];
|
||||||
|
for (let i = 0, p = 0; i < game.tileOrder.length; i++) {
|
||||||
|
game.animationSeeds.push(Math.random());
|
||||||
|
}
|
||||||
game.pipOrder = [
|
game.pipOrder = [
|
||||||
5, 1, 6,
|
5, 1, 6,
|
||||||
7, 2, 9, 11,
|
7, 2, 9, 11,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user