@vibuca/synth8-phaser-plugin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sven Hemmer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @vibuca/synth8-phaser
2
+
3
+ Phaser integration for Synth8, an MIT-licensed TypeScript music DSL and playback toolkit.
4
+
5
+ Use Synth8 patterns directly inside Phaser scenes for background music and overlapping sound effects.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @vibuca/synth8-core @vibuca/synth8-player @vibuca/synth8-phaser
11
+ ```
12
+
13
+ You also need Phaser:
14
+
15
+ ```bash
16
+ npm install phaser
17
+ ```
18
+
19
+ ## Register the plugin
20
+
21
+ ```ts
22
+ import Phaser from "phaser";
23
+ import { Synth8Plugin } from "@vibuca/synth8-phaser";
24
+
25
+ const config: Phaser.Types.Core.GameConfig = {
26
+ type: Phaser.AUTO,
27
+ width: 800,
28
+ height: 600,
29
+ scene: [GameScene],
30
+ plugins: {
31
+ scene: [
32
+ {
33
+ key: "Synth8Plugin",
34
+ plugin: Synth8Plugin,
35
+ mapping: "synth8",
36
+ },
37
+ ],
38
+ },
39
+ };
40
+ ```
41
+
42
+ ## TypeScript scene typing
43
+
44
+ ```ts
45
+ declare global {
46
+ namespace Phaser {
47
+ interface Scene {
48
+ synth8: Synth8Plugin;
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ## Play music
55
+
56
+ ```ts
57
+ await this.synth8.startAudio({
58
+ masterVolume: 1,
59
+ musicVolume: 0.7,
60
+ sfxVolume: 1,
61
+ });
62
+
63
+ await this.synth8.playMusic(
64
+ `song(
65
+ melody("c4 e4 g4 c5")
66
+ .preset("chip-lead")
67
+ .loop(),
68
+
69
+ beat("kick _ snare _")
70
+ .bank("arcade")
71
+ .loop()
72
+ )`,
73
+ {
74
+ bpm: 150,
75
+ }
76
+ );
77
+ ```
78
+
79
+ ## Stop music
80
+
81
+ ```ts
82
+ this.synth8.stopMusic();
83
+ ```
84
+
85
+ ## Pause and resume music
86
+
87
+ ```ts
88
+ this.synth8.pauseMusic();
89
+ this.synth8.resumeMusic();
90
+ this.synth8.stopMusic();
91
+ ```
92
+
93
+ ## Sound effects
94
+
95
+ Prepare SFX once:
96
+
97
+ ```ts
98
+ await this.synth8.prepareSfx(
99
+ "laser",
100
+ `melody("c7/16 g6/16 c6/16")
101
+ .preset("arcade-pluck")
102
+ .fast(16)
103
+ .gain(0.5)`,
104
+ {
105
+ bpm: 180,
106
+ voices: 10,
107
+ }
108
+ );
109
+ ```
110
+
111
+ Trigger them during gameplay:
112
+
113
+ ```ts
114
+ this.synth8.playSfx("laser");
115
+ ```
116
+
117
+ ## Volumes
118
+
119
+ ```ts
120
+ this.synth8.setMasterVolume(1);
121
+ this.synth8.setMusicVolume(0.7);
122
+ this.synth8.setSfxVolume(1);
123
+ ```
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,27 @@
1
+ import { default as Phaser } from 'phaser';
2
+ import { GameAudio, GameAudioOptions, GameMusicOptions, GameSfxOptions, PlayOptions, PlaySfxOptions, PreparedPlayback, PreparedSfx } from '@vibuca/synth8-player';
3
+ export declare class Synth8Plugin extends Phaser.Plugins.ScenePlugin {
4
+ private gameAudio?;
5
+ private playback?;
6
+ private music?;
7
+ private sfx;
8
+ play(source: string, options?: PlayOptions): Promise<PreparedPlayback>;
9
+ startAudio(options?: GameAudioOptions): Promise<GameAudio>;
10
+ pause(): void;
11
+ resume(): void;
12
+ stop(): void;
13
+ startGameAudio(options?: GameAudioOptions): Promise<GameAudio>;
14
+ private getGameAudio;
15
+ playMusic(source: string, options?: GameMusicOptions): Promise<PreparedPlayback>;
16
+ pauseMusic(): void;
17
+ resumeMusic(): void;
18
+ stopMusic(): void;
19
+ prepareSfx(key: string, source: string, options?: GameSfxOptions): Promise<PreparedSfx>;
20
+ playSfx(key: string, options?: PlaySfxOptions): Promise<void>;
21
+ setMasterVolume(value: number): void;
22
+ setMusicVolume(value: number): void;
23
+ setSfxVolume(value: number): void;
24
+ shutdown(): void;
25
+ destroy(): void;
26
+ }
27
+ //# sourceMappingURL=Synth8Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Synth8Plugin.d.ts","sourceRoot":"","sources":["../src/Synth8Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,YAAa,SAAQ,MAAM,CAAC,OAAO,CAAC,WAAW;IAC1D,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,QAAQ,CAAC,CAAmB;IACpC,OAAO,CAAC,KAAK,CAAC,CAAmB;IACjC,OAAO,CAAC,GAAG,CAAkC;IAEvC,IAAI,CACR,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,gBAAgB,CAAC;IAStB,UAAU,CAAC,OAAO,CAAC,EAAE,gBAAgB;IAK3C,KAAK;IAIL,MAAM;IAIN,IAAI;IAKE,cAAc,CAAC,OAAO,CAAC,EAAE,gBAAgB;YAIjC,YAAY;IAQpB,SAAS,CACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,gBAAgB,CAAC;IAW5B,UAAU;IAIV,WAAW;IAIX,SAAS;IAKH,UAAU,CACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAmB;IAUxB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc;IAWnD,eAAe,CAAC,KAAK,EAAE,MAAM;IAI7B,cAAc,CAAC,KAAK,EAAE,MAAM;IAI5B,YAAY,CAAC,KAAK,EAAE,MAAM;IAI1B,QAAQ;IAMR,OAAO;CAIR"}
@@ -0,0 +1,2 @@
1
+ export * from './Synth8Plugin';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ import e from "phaser";
2
+ import { compile as t } from "@vibuca/synth8-core";
3
+ import { createGameAudio as n, prepare as r } from "@vibuca/synth8-player";
4
+ //#region src/Synth8Plugin.ts
5
+ var i = class extends e.Plugins.ScenePlugin {
6
+ gameAudio;
7
+ playback;
8
+ music;
9
+ sfx = /* @__PURE__ */ new Map();
10
+ async play(e, n = {}) {
11
+ return this.playback?.stop(), this.playback = await r(t(e), n), this.playback.start(), this.playback;
12
+ }
13
+ async startAudio(e) {
14
+ return this.gameAudio = await n(e), this.gameAudio;
15
+ }
16
+ pause() {
17
+ this.playback?.pause();
18
+ }
19
+ resume() {
20
+ this.playback?.resume();
21
+ }
22
+ stop() {
23
+ this.playback?.stop(), this.playback = void 0;
24
+ }
25
+ async startGameAudio(e) {
26
+ return this.startAudio(e);
27
+ }
28
+ async getGameAudio() {
29
+ return this.gameAudio ||= await n(), this.gameAudio;
30
+ }
31
+ async playMusic(e, n) {
32
+ let r = await this.getGameAudio();
33
+ return this.music?.stop(), this.music = await r.prepareMusic(t(e), n), this.music.start(), this.music;
34
+ }
35
+ pauseMusic() {
36
+ this.music?.pause();
37
+ }
38
+ resumeMusic() {
39
+ this.music?.resume();
40
+ }
41
+ stopMusic() {
42
+ this.music?.stop(), this.music = void 0;
43
+ }
44
+ async prepareSfx(e, n, r = {}) {
45
+ let i = await (await this.getGameAudio()).prepareSfx(t(n), r);
46
+ return this.sfx.set(e, i), i;
47
+ }
48
+ async playSfx(e, t) {
49
+ let n = await this.getGameAudio(), r = this.sfx.get(e);
50
+ if (!r) throw Error(`Unknown Synth8 SFX: ${e}`);
51
+ n.playSfx(r, t);
52
+ }
53
+ setMasterVolume(e) {
54
+ this.gameAudio?.setMasterVolume(e);
55
+ }
56
+ setMusicVolume(e) {
57
+ this.gameAudio?.setMusicVolume(e);
58
+ }
59
+ setSfxVolume(e) {
60
+ this.gameAudio?.setSfxVolume(e);
61
+ }
62
+ shutdown() {
63
+ this.stop(), this.stopMusic(), this.sfx.clear();
64
+ }
65
+ destroy() {
66
+ this.shutdown(), super.destroy();
67
+ }
68
+ };
69
+ //#endregion
70
+ export { i as Synth8Plugin };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@vibuca/synth8-phaser-plugin",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "peerDependencies": {
15
+ "@vibuca/synth8-core": "^1.0.0",
16
+ "@vibuca/synth8-player": "^1.0.2",
17
+ "phaser": "^3.90.0"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "devDependencies": {
25
+ "unplugin-dts": "^1.0.2"
26
+ },
27
+ "scripts": {
28
+ "dev": "vite",
29
+ "build": "vite build"
30
+ }
31
+ }