Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mathe-Skribbl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ben Eltschig
Mathe-Skribbl
Commits
bfe57e81
Commit
bfe57e81
authored
3 years ago
by
Florian Kaufmann
Browse files
Options
Downloads
Patches
Plain Diff
Changed coding style
parent
4071b30c
1 merge request
!10
Added sounds & the ability to play them
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/sounds/sounds.js
+22
-28
22 additions, 28 deletions
client/sounds/sounds.js
with
22 additions
and
28 deletions
client/sounds/sounds.js
+
22
−
28
View file @
bfe57e81
/**
* Loads, manages & plays sound files
*/
class
SoundPlayer
{
constructor
()
{
this
.
context
=
new
window
.
AudioContext
();
/** @type {{[key: string]: HTMLAudioElement}} */
this
.
sounds
=
{};
this
.
initSounds
();
}
initSounds
()
{
let
path
=
"
./res/sounds/
"
;
let
extension
=
"
.oga
"
;
let
names
=
[
"
defaultError
"
,
"
defaultSuccess
"
,
"
join
"
,
"
leave
"
,
"
roundOver
"
,
"
selectedWord
"
,
"
timeLow
"
,
"
win
"
,
"
wtfError
"
,
"
yourTurn
"
];
for
(
let
name
of
names
)
{
let
audio
=
document
.
createElement
(
"
audio
"
);
audio
.
controls
=
true
;
audio
.
id
=
name
;
audio
.
src
=
path
+
name
+
extension
;
this
.
sounds
[
name
]
=
audio
;
}
}
/**
*
* @param {string} name
*/
playSound
(
name
)
{
this
.
sounds
[
name
].
currentTime
=
0.0
;
this
.
sounds
[
name
].
play
();
}
/**
*
* @param {"defaultError" | "defaultSuccess" | "join" | "leave" | "roundOver" | "selectedWord" | "timeLow" | "win" | "wtfError" | "yourTurn"} name
*/
export
default
function
playSound
(
name
)
{
sounds
[
name
].
currentTime
=
0.0
;
sounds
[
name
].
play
();
}
export
default
new
SoundPlayer
();
\ No newline at end of file
/** @type {{[key: string]: HTMLAudioElement}} */
let
sounds
=
{};
function
initSounds
()
{
let
path
=
"
./res/sounds/
"
;
let
extension
=
"
.oga
"
;
let
names
=
[
"
defaultError
"
,
"
defaultSuccess
"
,
"
join
"
,
"
leave
"
,
"
roundOver
"
,
"
selectedWord
"
,
"
timeLow
"
,
"
win
"
,
"
wtfError
"
,
"
yourTurn
"
];
for
(
let
name
of
names
)
{
let
audio
=
document
.
createElement
(
"
audio
"
);
audio
.
controls
=
true
;
audio
.
id
=
name
;
audio
.
src
=
path
+
name
+
extension
;
sounds
[
name
]
=
audio
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment