@series-inc/stowkit-phaser-loader 0.1.18 → 0.1.19

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/README.md CHANGED
@@ -1,267 +1,267 @@
1
- # @series-inc/stowkit-phaser-loader
2
-
3
- Phaser.js loader for StowKit asset packs. Supports loading compressed textures (KTX2/Basis Universal) and audio from `.stow` files.
4
-
5
- ## Features
6
-
7
- - **Compressed Texture Support** - Automatically decodes KTX2 textures to GPU-compressed formats (BC3/DXT5, BC1/DXT1, ASTC, ETC2, etc.)
8
- - **Audio Loading** - Loads audio assets as Web Audio buffers or HTML5 audio elements
9
- - **Multiple Packs** - Load multiple .stow files simultaneously with isolated state
10
- - **Phaser Integration** - Textures are registered with Phaser's texture manager and work with all Phaser game objects
11
- - **Efficient** - Textures remain compressed on the GPU, reducing memory usage
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @series-inc/stowkit-phaser-loader phaser
17
- ```
18
-
19
- ## Quick Start
20
-
21
- ```typescript
22
- import Phaser from 'phaser';
23
- import { StowKitPhaserLoader } from '@series-inc/stowkit-phaser-loader';
24
-
25
- class GameScene extends Phaser.Scene {
26
- constructor() {
27
- super('GameScene');
28
- }
29
-
30
- async create() {
31
- const pack = await StowKitPhaserLoader.load('/assets/game.stow', {
32
- basisPath: '/basis/',
33
- wasmPath: '/stowkit/stowkit_reader.wasm'
34
- });
35
-
36
- await pack.loadTexture('characters/player', this);
37
- await pack.loadTexture('ui/button', this);
38
-
39
- const player = this.add.sprite(400, 300, 'characters/player');
40
- const button = this.add.image(100, 50, 'ui/button');
41
-
42
- const bgmBuffer = await pack.loadAudio('sounds/bgm');
43
- }
44
- }
45
-
46
- const config = {
47
- type: Phaser.WEBGL,
48
- width: 800,
49
- height: 600,
50
- scene: GameScene
51
- };
52
-
53
- const game = new Phaser.Game(config);
54
- ```
55
-
56
- ## API Reference
57
-
58
- ### Exports
59
-
60
- ```typescript
61
- export { StowKitPhaserLoader } from '@series-inc/stowkit-phaser-loader';
62
- export { StowKitPhaserPack } from '@series-inc/stowkit-phaser-loader';
63
- export { BasisTranscoder } from '@series-inc/stowkit-phaser-loader';
64
- export { AssetType, PerfLogger } from '@series-inc/stowkit-phaser-loader';
65
-
66
- export type { StowKitPhaserLoaderOptions } from '@series-inc/stowkit-phaser-loader';
67
- export type { TextureData } from '@series-inc/stowkit-phaser-loader';
68
- ```
69
-
70
- ### StowKitPhaserLoader
71
-
72
- Static loader class for opening `.stow` pack files.
73
-
74
- #### `StowKitPhaserLoader.load(url, options?)`
75
-
76
- Loads a `.stow` pack from a URL.
77
-
78
- ```typescript
79
- const pack = await StowKitPhaserLoader.load('/assets/game.stow', {
80
- basisPath: '/basis/',
81
- wasmPath: '/stowkit/stowkit_reader.wasm'
82
- });
83
- ```
84
-
85
- **Options:**
86
- - `basisPath` (string) - Path to Basis Universal transcoder files (default: `'/basis/'`)
87
- - `wasmPath` (string) - Path to StowKit WASM module (default: `'/stowkit/stowkit_reader.wasm'`)
88
- - `gl` (WebGLRenderingContext | WebGL2RenderingContext) - WebGL context to use. If not provided, a temporary canvas is created.
89
-
90
- **Returns:** `Promise<StowKitPhaserPack>`
91
-
92
- #### `StowKitPhaserLoader.loadFromMemory(data, options?)`
93
-
94
- Loads a `.stow` pack from memory.
95
-
96
- ```typescript
97
- const response = await fetch('/assets/game.stow');
98
- const buffer = await response.arrayBuffer();
99
- const pack = await StowKitPhaserLoader.loadFromMemory(buffer);
100
- ```
101
-
102
- **Parameters:**
103
- - `data` (ArrayBuffer | Blob | File) - The `.stow` file data
104
- - `options` (StowKitPhaserLoaderOptions, optional) - Loader options
105
-
106
- **Returns:** `Promise<StowKitPhaserPack>`
107
-
108
- #### `StowKitPhaserLoader.dispose()`
109
-
110
- Dispose of shared resources (Basis transcoder and temporary WebGL context if one was created).
111
-
112
- ```typescript
113
- StowKitPhaserLoader.dispose();
114
- ```
115
-
116
- ### StowKitPhaserPack
117
-
118
- Represents an opened `.stow` pack file.
119
-
120
- #### `pack.loadTexture(assetPath, scene)`
121
-
122
- Loads a texture by its canonical path and registers it with Phaser's texture manager.
123
-
124
- **Parameters:**
125
- - `assetPath` (string) - The canonical path of the texture (e.g., `"characters/player"`)
126
- - `scene` (Phaser.Scene) - The Phaser scene instance
127
-
128
- **Returns:** `Promise<Phaser.Textures.Texture>`
129
-
130
- Must be called after the Phaser scene is initialized (in or after `create()`).
131
-
132
- ```typescript
133
- await pack.loadTexture('textures/player', this);
134
- this.add.sprite(100, 100, 'textures/player');
135
- ```
136
-
137
- #### `pack.getPhaserTexture(index, scene)`
138
-
139
- Loads a texture by index (useful for asset browsing/previews).
140
-
141
- **Parameters:**
142
- - `index` (number) - Asset index
143
- - `scene` (Phaser.Scene) - The Phaser scene instance
144
-
145
- **Returns:** `Promise<Phaser.Textures.Texture>`
146
-
147
- #### `pack.loadAudio(assetPath, audioContext?)`
148
-
149
- Loads audio by path as an AudioBuffer.
150
-
151
- **Parameters:**
152
- - `assetPath` (string) - The canonical path of the audio asset
153
- - `audioContext` (AudioContext, optional) - Web Audio context to use
154
-
155
- **Returns:** `Promise<AudioBuffer>`
156
-
157
- #### `pack.loadAudioByIndex(index, audioContext?)`
158
-
159
- Loads audio by index as an AudioBuffer.
160
-
161
- **Parameters:**
162
- - `index` (number) - Asset index
163
- - `audioContext` (AudioContext, optional) - Web Audio context to use
164
-
165
- **Returns:** `Promise<AudioBuffer>`
166
-
167
- #### `pack.createAudioPreview(index)`
168
-
169
- Creates an HTML5 audio element for preview.
170
-
171
- **Returns:** `Promise<HTMLAudioElement>`
172
-
173
- #### `pack.listAssets()`
174
-
175
- Returns array of all assets in the pack.
176
-
177
- #### `pack.getAssetCount(): number`
178
-
179
- Returns total number of assets.
180
-
181
- #### `pack.getAssetInfo(index)`
182
-
183
- Get asset info by index.
184
-
185
- #### `pack.getTextureMetadata(index)`
186
-
187
- Get texture metadata (dimensions, format, tags, etc.) using WASM parsing.
188
-
189
- ```typescript
190
- const texData = pack.getTextureMetadata(index);
191
- console.log(`${texData.width}x${texData.height}, ${texData.channels} channels`);
192
- ```
193
-
194
- #### `pack.getAudioMetadata(index)`
195
-
196
- Get audio metadata using WASM parsing.
197
-
198
- ```typescript
199
- const audioData = pack.getAudioMetadata(index);
200
- console.log(`${audioData.sampleRate}Hz, ${audioData.durationMs}ms`);
201
- ```
202
-
203
- #### `pack.dispose()`
204
-
205
- Closes the pack and frees resources.
206
-
207
- ```typescript
208
- pack.dispose();
209
- ```
210
-
211
- ## Loading Multiple Packs
212
-
213
- Each pack is fully isolated with its own WASM reader instance. You can load multiple packs simultaneously:
214
-
215
- ```typescript
216
- class GameScene extends Phaser.Scene {
217
- async create() {
218
- const [uiPack, levelPack, characterPack] = await Promise.all([
219
- StowKitPhaserLoader.load('/assets/ui.stow'),
220
- StowKitPhaserLoader.load('/assets/level1.stow'),
221
- StowKitPhaserLoader.load('/assets/characters.stow')
222
- ]);
223
-
224
- await uiPack.loadTexture('button', this);
225
- await levelPack.loadTexture('background', this);
226
- await characterPack.loadTexture('player', this);
227
-
228
- this.add.image(100, 50, 'button');
229
- this.add.image(0, 0, 'background');
230
- this.add.sprite(400, 300, 'player');
231
-
232
- console.log(`UI Pack: ${uiPack.getAssetCount()} assets`);
233
- console.log(`Level Pack: ${levelPack.getAssetCount()} assets`);
234
- console.log(`Character Pack: ${characterPack.getAssetCount()} assets`);
235
- }
236
- }
237
- ```
238
-
239
- Dispose packs when no longer needed:
240
-
241
- ```typescript
242
- uiPack.dispose();
243
- ```
244
-
245
- ## Compressed Texture Formats
246
-
247
- The loader automatically transcodes KTX2 textures to the best format supported by the device:
248
-
249
- **Desktop (DXT/BC formats):**
250
- - BC7 (BPTC) - Highest quality for UASTC textures with alpha (requires WebGL2 + `EXT_texture_compression_bptc`)
251
- - BC3 (DXT5) - High quality for textures with alpha
252
- - BC1 (DXT1) - For textures without alpha or ETC1S encoded textures
253
-
254
- **Mobile:**
255
- - ASTC 4x4 - Highest quality (iOS, Android with GPU support)
256
- - ETC2 - Good quality (WebGL2 required)
257
- - ETC1 - Legacy Android support
258
- - PVRTC - iOS fallback
259
-
260
- **Fallback:**
261
- - RGBA32 - Uncompressed fallback if no compressed formats are supported
262
-
263
- ## Limitations
264
-
265
- - **No 3D Model Support** - This loader only handles 2D textures and audio. For 3D models, use `@series-inc/stowkit-three-loader`.
266
- - **Phaser 3.60+** - Compressed texture support requires Phaser 3.60 or later.
267
- - **Scene Required** - Textures must be loaded within or after a Phaser scene is initialized.
1
+ # @series-inc/stowkit-phaser-loader
2
+
3
+ Phaser.js loader for StowKit asset packs. Supports loading compressed textures (KTX2/Basis Universal) and audio from `.stow` files.
4
+
5
+ ## Features
6
+
7
+ - **Compressed Texture Support** - Automatically decodes KTX2 textures to GPU-compressed formats (BC3/DXT5, BC1/DXT1, ASTC, ETC2, etc.)
8
+ - **Audio Loading** - Loads audio assets as Web Audio buffers or HTML5 audio elements
9
+ - **Multiple Packs** - Load multiple .stow files simultaneously with isolated state
10
+ - **Phaser Integration** - Textures are registered with Phaser's texture manager and work with all Phaser game objects
11
+ - **Efficient** - Textures remain compressed on the GPU, reducing memory usage
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @series-inc/stowkit-phaser-loader phaser
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import Phaser from 'phaser';
23
+ import { StowKitPhaserLoader } from '@series-inc/stowkit-phaser-loader';
24
+
25
+ class GameScene extends Phaser.Scene {
26
+ constructor() {
27
+ super('GameScene');
28
+ }
29
+
30
+ async create() {
31
+ const pack = await StowKitPhaserLoader.load('/assets/game.stow', {
32
+ basisPath: '/basis/',
33
+ wasmPath: '/stowkit/stowkit_reader.wasm'
34
+ });
35
+
36
+ await pack.loadTexture('characters/player', this);
37
+ await pack.loadTexture('ui/button', this);
38
+
39
+ const player = this.add.sprite(400, 300, 'characters/player');
40
+ const button = this.add.image(100, 50, 'ui/button');
41
+
42
+ const bgmBuffer = await pack.loadAudio('sounds/bgm');
43
+ }
44
+ }
45
+
46
+ const config = {
47
+ type: Phaser.WEBGL,
48
+ width: 800,
49
+ height: 600,
50
+ scene: GameScene
51
+ };
52
+
53
+ const game = new Phaser.Game(config);
54
+ ```
55
+
56
+ ## API Reference
57
+
58
+ ### Exports
59
+
60
+ ```typescript
61
+ export { StowKitPhaserLoader } from '@series-inc/stowkit-phaser-loader';
62
+ export { StowKitPhaserPack } from '@series-inc/stowkit-phaser-loader';
63
+ export { BasisTranscoder } from '@series-inc/stowkit-phaser-loader';
64
+ export { AssetType, PerfLogger } from '@series-inc/stowkit-phaser-loader';
65
+
66
+ export type { StowKitPhaserLoaderOptions } from '@series-inc/stowkit-phaser-loader';
67
+ export type { TextureData } from '@series-inc/stowkit-phaser-loader';
68
+ ```
69
+
70
+ ### StowKitPhaserLoader
71
+
72
+ Static loader class for opening `.stow` pack files.
73
+
74
+ #### `StowKitPhaserLoader.load(url, options?)`
75
+
76
+ Loads a `.stow` pack from a URL.
77
+
78
+ ```typescript
79
+ const pack = await StowKitPhaserLoader.load('/assets/game.stow', {
80
+ basisPath: '/basis/',
81
+ wasmPath: '/stowkit/stowkit_reader.wasm'
82
+ });
83
+ ```
84
+
85
+ **Options:**
86
+ - `basisPath` (string) - Path to Basis Universal transcoder files (default: `'/basis/'`)
87
+ - `wasmPath` (string) - Path to StowKit WASM module (default: `'/stowkit/stowkit_reader.wasm'`)
88
+ - `gl` (WebGLRenderingContext | WebGL2RenderingContext) - WebGL context to use. If not provided, a temporary canvas is created.
89
+
90
+ **Returns:** `Promise<StowKitPhaserPack>`
91
+
92
+ #### `StowKitPhaserLoader.loadFromMemory(data, options?)`
93
+
94
+ Loads a `.stow` pack from memory.
95
+
96
+ ```typescript
97
+ const response = await fetch('/assets/game.stow');
98
+ const buffer = await response.arrayBuffer();
99
+ const pack = await StowKitPhaserLoader.loadFromMemory(buffer);
100
+ ```
101
+
102
+ **Parameters:**
103
+ - `data` (ArrayBuffer | Blob | File) - The `.stow` file data
104
+ - `options` (StowKitPhaserLoaderOptions, optional) - Loader options
105
+
106
+ **Returns:** `Promise<StowKitPhaserPack>`
107
+
108
+ #### `StowKitPhaserLoader.dispose()`
109
+
110
+ Dispose of shared resources (Basis transcoder and temporary WebGL context if one was created).
111
+
112
+ ```typescript
113
+ StowKitPhaserLoader.dispose();
114
+ ```
115
+
116
+ ### StowKitPhaserPack
117
+
118
+ Represents an opened `.stow` pack file.
119
+
120
+ #### `pack.loadTexture(assetPath, scene)`
121
+
122
+ Loads a texture by its canonical path and registers it with Phaser's texture manager.
123
+
124
+ **Parameters:**
125
+ - `assetPath` (string) - The canonical path of the texture (e.g., `"characters/player"`)
126
+ - `scene` (Phaser.Scene) - The Phaser scene instance
127
+
128
+ **Returns:** `Promise<Phaser.Textures.Texture>`
129
+
130
+ Must be called after the Phaser scene is initialized (in or after `create()`).
131
+
132
+ ```typescript
133
+ await pack.loadTexture('textures/player', this);
134
+ this.add.sprite(100, 100, 'textures/player');
135
+ ```
136
+
137
+ #### `pack.getPhaserTexture(index, scene)`
138
+
139
+ Loads a texture by index (useful for asset browsing/previews).
140
+
141
+ **Parameters:**
142
+ - `index` (number) - Asset index
143
+ - `scene` (Phaser.Scene) - The Phaser scene instance
144
+
145
+ **Returns:** `Promise<Phaser.Textures.Texture>`
146
+
147
+ #### `pack.loadAudio(assetPath, audioContext?)`
148
+
149
+ Loads audio by path as an AudioBuffer.
150
+
151
+ **Parameters:**
152
+ - `assetPath` (string) - The canonical path of the audio asset
153
+ - `audioContext` (AudioContext, optional) - Web Audio context to use
154
+
155
+ **Returns:** `Promise<AudioBuffer>`
156
+
157
+ #### `pack.loadAudioByIndex(index, audioContext?)`
158
+
159
+ Loads audio by index as an AudioBuffer.
160
+
161
+ **Parameters:**
162
+ - `index` (number) - Asset index
163
+ - `audioContext` (AudioContext, optional) - Web Audio context to use
164
+
165
+ **Returns:** `Promise<AudioBuffer>`
166
+
167
+ #### `pack.createAudioPreview(index)`
168
+
169
+ Creates an HTML5 audio element for preview.
170
+
171
+ **Returns:** `Promise<HTMLAudioElement>`
172
+
173
+ #### `pack.listAssets()`
174
+
175
+ Returns array of all assets in the pack.
176
+
177
+ #### `pack.getAssetCount(): number`
178
+
179
+ Returns total number of assets.
180
+
181
+ #### `pack.getAssetInfo(index)`
182
+
183
+ Get asset info by index.
184
+
185
+ #### `pack.getTextureMetadata(index)`
186
+
187
+ Get texture metadata (dimensions, format, tags, etc.) using WASM parsing.
188
+
189
+ ```typescript
190
+ const texData = pack.getTextureMetadata(index);
191
+ console.log(`${texData.width}x${texData.height}, ${texData.channels} channels`);
192
+ ```
193
+
194
+ #### `pack.getAudioMetadata(index)`
195
+
196
+ Get audio metadata using WASM parsing.
197
+
198
+ ```typescript
199
+ const audioData = pack.getAudioMetadata(index);
200
+ console.log(`${audioData.sampleRate}Hz, ${audioData.durationMs}ms`);
201
+ ```
202
+
203
+ #### `pack.dispose()`
204
+
205
+ Closes the pack and frees resources.
206
+
207
+ ```typescript
208
+ pack.dispose();
209
+ ```
210
+
211
+ ## Loading Multiple Packs
212
+
213
+ Each pack is fully isolated with its own WASM reader instance. You can load multiple packs simultaneously:
214
+
215
+ ```typescript
216
+ class GameScene extends Phaser.Scene {
217
+ async create() {
218
+ const [uiPack, levelPack, characterPack] = await Promise.all([
219
+ StowKitPhaserLoader.load('/assets/ui.stow'),
220
+ StowKitPhaserLoader.load('/assets/level1.stow'),
221
+ StowKitPhaserLoader.load('/assets/characters.stow')
222
+ ]);
223
+
224
+ await uiPack.loadTexture('button', this);
225
+ await levelPack.loadTexture('background', this);
226
+ await characterPack.loadTexture('player', this);
227
+
228
+ this.add.image(100, 50, 'button');
229
+ this.add.image(0, 0, 'background');
230
+ this.add.sprite(400, 300, 'player');
231
+
232
+ console.log(`UI Pack: ${uiPack.getAssetCount()} assets`);
233
+ console.log(`Level Pack: ${levelPack.getAssetCount()} assets`);
234
+ console.log(`Character Pack: ${characterPack.getAssetCount()} assets`);
235
+ }
236
+ }
237
+ ```
238
+
239
+ Dispose packs when no longer needed:
240
+
241
+ ```typescript
242
+ uiPack.dispose();
243
+ ```
244
+
245
+ ## Compressed Texture Formats
246
+
247
+ The loader automatically transcodes KTX2 textures to the best format supported by the device:
248
+
249
+ **Desktop (DXT/BC formats):**
250
+ - BC7 (BPTC) - Highest quality for UASTC textures with alpha (requires WebGL2 + `EXT_texture_compression_bptc`)
251
+ - BC3 (DXT5) - High quality for textures with alpha
252
+ - BC1 (DXT1) - For textures without alpha or ETC1S encoded textures
253
+
254
+ **Mobile:**
255
+ - ASTC 4x4 - Highest quality (iOS, Android with GPU support)
256
+ - ETC2 - Good quality (WebGL2 required)
257
+ - ETC1 - Legacy Android support
258
+ - PVRTC - iOS fallback
259
+
260
+ **Fallback:**
261
+ - RGBA32 - Uncompressed fallback if no compressed formats are supported
262
+
263
+ ## Limitations
264
+
265
+ - **No 3D Model Support** - This loader only handles 2D textures and audio. For 3D models, use `@series-inc/stowkit-three-loader`.
266
+ - **Phaser 3.60+** - Compressed texture support requires Phaser 3.60 or later.
267
+ - **Scene Required** - Textures must be loaded within or after a Phaser scene is initialized.