Skip to content

Commit 7269234

Browse files
committed
Hello
0 parents  commit 7269234

21 files changed

+3201
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
node_modules
3+
public
4+
dist

.hintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": ["development"],
3+
"hints": {
4+
"meta-viewport": "off"
5+
}
6+
}

README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Phaser Sound Watcher Plugin
2+
===========================
3+
4+
Shows sounds in the Sound Manager.
5+
6+
Symbols
7+
-------
8+
9+
| Symbol | Description |
10+
|--------------|---------------------------|
11+
| `#` | locked |
12+
| `▁▂▃▄▅▆▇█` | volume |
13+
| `m` | mute |
14+
| `>` | playing |
15+
| `:` | paused |
16+
| `.` | not playing or paused |
17+
| `<<+>>` | pan |
18+
| `key:marker` | key, marker name |
19+
| `[0.0 / 1.0]`| seek, duration |
20+
| `@(x, y)` | position |
21+
| `a` | has audio tag |
22+
| `-` | has no audio tag |
23+
24+
Module
25+
------
26+
27+
```js
28+
import SoundWatcherPlugin from 'phaser-plugin-sound-watcher'
29+
30+
new Phaser.Game({
31+
plugins: {
32+
global: [
33+
{
34+
key: 'SoundWatcherPlugin',
35+
plugin: SoundWatcherPlugin,
36+
start: true
37+
}
38+
]
39+
}
40+
})
41+
```
42+
43+
UMD
44+
---
45+
46+
```html
47+
<!-- after phaser.js -->
48+
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
49+
```
50+
51+
```js
52+
/* global Phaser, SoundWatcherPlugin */
53+
54+
new Phaser.Game({
55+
plugins: {
56+
global: [
57+
{
58+
key: 'SoundWatcherPlugin',
59+
plugin: SoundWatcherPlugin,
60+
start: true
61+
}
62+
]
63+
}
64+
})
65+
```
66+
67+
- [UMD example](https://codepen.io/samme/pen/WbexawE)
68+
69+
Quick load
70+
----------
71+
72+
```js
73+
this.load.plugin('SoundWatcherPlugin', 'https://cdn.jsdelivr.net/npm/[email protected]')
74+
```
75+
76+
- [Quick load example](https://phaser.io/sandbox/PgZyGawy)
77+
78+
Load from console
79+
-----------------
80+
81+
Given a global `game` variable:
82+
83+
```js
84+
game.scene.systemScene.load.plugin('SoundWatcherPlugin', 'https://cdn.jsdelivr.net/npm/[email protected]').start()
85+
```

biome.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"ignore": []
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentStyle": "space",
15+
"indentWidth": 2
16+
},
17+
"organizeImports": {
18+
"enabled": true
19+
},
20+
"linter": {
21+
"enabled": true,
22+
"rules": {
23+
"recommended": true,
24+
"correctness": {
25+
"noUndeclaredVariables": "error"
26+
}
27+
}
28+
},
29+
"javascript": {
30+
"formatter": {
31+
"quoteStyle": "single",
32+
"semicolons": "asNeeded",
33+
"trailingCommas": "none"
34+
}
35+
}
36+
}

index.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
margin: 0;
3+
font: 1rem/1.5 system-ui;
4+
}

index.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=800">
7+
<link rel="stylesheet" href="/index.css">
8+
<title>Demo of Sound Watcher Plugin</title>
9+
</head>
10+
11+
<body>
12+
<nav>
13+
<a href="/tests.html">tests</a>
14+
<a href="/umd.html">umd</a>
15+
<a href="/load.html">load</a>
16+
</nav>
17+
<script type="module" src="/main.js"></script>
18+
</body>
19+
20+
</html>

load.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Load Tests of Sound Watcher Plugin</title>
7+
8+
<link rel="stylesheet" href="/tests.css">
9+
</head>
10+
11+
<body>
12+
<div id="mocha"></div>
13+
<script type="module" src="/load.js"></script>
14+
</body>
15+
16+
</html>

load.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import 'mocha/mocha.js'
2+
import { assert } from 'chai'
3+
import Phaser from 'phaser'
4+
5+
const { mocha, Mocha } = window
6+
7+
mocha.setup('bdd')
8+
9+
const { describe: context, test, before, after, beforeEach, afterEach } = Mocha
10+
11+
context('Phaser', () => {
12+
test('is an object', () => {
13+
assert.isObject(Phaser)
14+
})
15+
16+
test('is the required version', () => {
17+
assert.propertyVal(Phaser, 'VERSION', '3.87')
18+
})
19+
})
20+
21+
context('load.plugin("SoundWatcherPlugin")', () => {
22+
let game
23+
24+
beforeEach((done) => {
25+
game = new Phaser.Game({
26+
callbacks: {
27+
postBoot: () => {
28+
done()
29+
}
30+
}
31+
})
32+
})
33+
34+
afterEach((done) => {
35+
// biome-ignore lint/performance/noDelete: deglobalize
36+
delete window.SoundWatcherPlugin
37+
38+
game.events.once('destroy', () => {
39+
game = null
40+
done()
41+
})
42+
game.destroy(true)
43+
})
44+
45+
test('load.plugin("SoundWatcherPlugin", url, true) adds and starts the plugin', (done) => {
46+
const scene = game.scene.systemScene
47+
48+
scene.load
49+
.plugin('SoundWatcherPlugin', 'dist/sound-watcher-plugin.umd.js', true)
50+
.start()
51+
52+
scene.load.once('complete', () => {
53+
assert.strictEqual(
54+
scene.plugins.getClass('SoundWatcherPlugin'),
55+
window.SoundWatcherPlugin,
56+
'plugins.getClass("SoundWatcherPlugin") is SoundWatcherPlugin'
57+
)
58+
59+
assert.isObject(
60+
scene.plugins.getEntry('SoundWatcherPlugin'),
61+
'plugins.getEntry("SoundWatcherPlugin") is an object'
62+
)
63+
64+
assert.isTrue(
65+
scene.plugins.isActive('SoundWatcherPlugin'),
66+
'plugins.isActive("SoundWatcherPlugin") is true'
67+
)
68+
69+
done()
70+
})
71+
})
72+
})
73+
74+
mocha.globals(['Phaser', 'SoundWatcherPlugin'])
75+
mocha.checkLeaks()
76+
mocha.run()

main.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import Phaser from 'phaser'
2+
import SoundWatcherPlugin from './src/main'
3+
4+
class Example extends Phaser.Scene {
5+
preload() {
6+
this.load.image('touhou', 'touhou1.png')
7+
this.load.image('seablue', 'seablue.png')
8+
9+
this.load.audio('bass', ['bass.mp3'])
10+
this.load.audio('drums', ['drums.mp3'])
11+
this.load.audio('percussion', ['percussion.mp3'])
12+
this.load.audio('synth1', ['synth1.mp3'])
13+
this.load.audio('synth2', ['synth2.mp3'])
14+
this.load.audio('top1', ['top1.mp3'])
15+
this.load.audio('top2', ['top2.mp3'])
16+
}
17+
18+
create() {
19+
this.add.image(400, 300, 'seablue')
20+
this.add.image(790, 600, 'touhou').setOrigin(1)
21+
22+
const bass = this.sound.add('bass')
23+
const drums = this.sound.add('drums')
24+
const percussion = this.sound.add('percussion')
25+
const synth1 = this.sound.add('synth1')
26+
const synth2 = this.sound.add('synth2')
27+
const top1 = this.sound.add('top1')
28+
const top2 = this.sound.add('top2')
29+
30+
const keys = [
31+
'Press A for Bass',
32+
'Press B for Drums',
33+
'Press C for Percussion',
34+
'Press D for Synth1',
35+
'Press E for Synth2',
36+
'Press F for Top1',
37+
'Press G for Top2',
38+
'',
39+
'SPACE to stop all sounds'
40+
]
41+
42+
const text = this.add.text(10, 300, keys, {
43+
font: '32px Courier',
44+
fill: 'crimson'
45+
})
46+
47+
if (this.sound.locked) {
48+
text.setText('Click to start')
49+
50+
this.sound.once('unlocked', () => {
51+
text.setText(keys)
52+
})
53+
}
54+
55+
this.input.keyboard.on(
56+
'keydown-SPACE',
57+
function () {
58+
this.sound.stopAll()
59+
},
60+
this
61+
)
62+
63+
this.input.keyboard.on('keydown-A', () => {
64+
bass.play()
65+
})
66+
67+
this.input.keyboard.on('keydown-B', () => {
68+
drums.play()
69+
})
70+
71+
this.input.keyboard.on('keydown-C', () => {
72+
percussion.play()
73+
})
74+
75+
this.input.keyboard.on('keydown-D', () => {
76+
synth1.play()
77+
})
78+
79+
this.input.keyboard.on('keydown-E', () => {
80+
synth2.play()
81+
})
82+
83+
this.input.keyboard.on('keydown-F', () => {
84+
top1.play()
85+
})
86+
87+
this.input.keyboard.on('keydown-G', () => {
88+
top2.play()
89+
})
90+
}
91+
}
92+
93+
new Phaser.Game({
94+
plugins: {
95+
global: [
96+
{
97+
key: 'SoundWatcherPlugin',
98+
plugin: SoundWatcherPlugin,
99+
start: true
100+
}
101+
]
102+
},
103+
width: 800,
104+
height: 600,
105+
scene: Example
106+
})

0 commit comments

Comments
 (0)