You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.4 KiB
110 lines
3.4 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Source: module/sounds.js</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">Source: module/sounds.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/** @module sounds */
|
|
|
|
import { appUrl } from './util.js'
|
|
|
|
/**
|
|
* A thin wrapper for sound effects.
|
|
*/
|
|
class Sound {
|
|
/**
|
|
* Construct the sound.
|
|
* @param {string} src - URL of the file
|
|
*/
|
|
constructor(src) {
|
|
/**
|
|
* The sound element.
|
|
* @type {HTMLAudioElement}
|
|
*/
|
|
this.sound = document.createElement('audio')
|
|
this.sound.src = src
|
|
this.sound.setAttribute('preload', 'auto')
|
|
this.sound.setAttribute('controls', 'none')
|
|
this.sound.style.display = 'none'
|
|
|
|
document.body.appendChild(this.sound)
|
|
}
|
|
|
|
/**
|
|
* Start playing the sound.
|
|
*/
|
|
async play() {
|
|
const duration = this.sound.duration
|
|
|
|
await this.sound.play()
|
|
await new Promise(res => {
|
|
setTimeout(res, duration * 1000)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Pause the sound.
|
|
*/
|
|
stop() {
|
|
this.sound.pause()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Enum of the various sound effects available in the game.
|
|
* @type {object}
|
|
*/
|
|
const GameSounds = {
|
|
Victory: new Sound(appUrl('/lib/sounds/cartoon_success_fanfair.mp3')),
|
|
Fire: new Sound(appUrl('/lib/sounds/zapsplat_warfare_mortar_projectile_launch_002_25232.mp3')),
|
|
Hit: new Sound(appUrl('/lib/sounds/zapsplat_warfare_bomb_whizz_in_hit_close_by_explosion_med_003_48060.mp3')),
|
|
Miss: new Sound(appUrl('/lib/sounds/zapsplat_nature_water_pour_medium_amount_deep_sudden_fast_002_52765.mp3')),
|
|
}
|
|
|
|
export { GameSounds }
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-errors.html">errors</a></li><li><a href="module-lang.html">lang</a></li><li><a href="module-sounds.html">sounds</a></li><li><a href="module-util.html">util</a></li></ul><h3>Classes</h3><ul><li><a href="GameBoardComponent.html">GameBoardComponent</a></li><li><a href="GameStateService.html">GameStateService</a></li><li><a href="GridCellComponent.html">GridCellComponent</a></li><li><a href="module-errors.InvalidAdvanceStateError.html">InvalidAdvanceStateError</a></li><li><a href="module-errors.InvalidMissileFireAttemptError.html">InvalidMissileFireAttemptError</a></li><li><a href="module-errors.InvalidShipPlacementError.html">InvalidShipPlacementError</a></li><li><a href="module-sounds-Sound.html">Sound</a></li><li><a href="ScoreBoardComponent.html">ScoreBoardComponent</a></li><li><a href="TopLevelComponent.html">TopLevelComponent</a></li></ul>
|
|
</nav>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Sat Sep 12 2020 16:40:09 GMT-0500 (Central Daylight Time)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
<script src="scripts/linenumber.js"> </script>
|
|
</body>
|
|
</html>
|