@series-inc/stowkit-phaser-loader 0.1.18 → 0.1.20
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 +267 -267
- package/dist/StowKitPhaserPack.d.ts +2 -2
- package/dist/StowKitPhaserPack.d.ts.map +1 -1
- package/dist/stowkit-phaser-loader.esm.js +15 -2
- package/dist/stowkit-phaser-loader.esm.js.map +1 -1
- package/dist/stowkit-phaser-loader.js +15 -2
- package/dist/stowkit-phaser-loader.js.map +1 -1
- package/package.json +58 -55
- package/scripts/postinstall.cjs +37 -0
- package/skill.md +166 -0
package/package.json
CHANGED
|
@@ -1,55 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@series-inc/stowkit-phaser-loader",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Phaser loader for StowKit asset packs with KTX2/Basis Universal compressed texture support",
|
|
5
|
-
"main": "dist/stowkit-phaser-loader.js",
|
|
6
|
-
"module": "dist/stowkit-phaser-loader.esm.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"rollup": "^
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@series-inc/stowkit-phaser-loader",
|
|
3
|
+
"version": "0.1.20",
|
|
4
|
+
"description": "Phaser loader for StowKit asset packs with KTX2/Basis Universal compressed texture support",
|
|
5
|
+
"main": "dist/stowkit-phaser-loader.js",
|
|
6
|
+
"module": "dist/stowkit-phaser-loader.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"scripts",
|
|
11
|
+
"skill.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c",
|
|
15
|
+
"dev": "rollup -c -w",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"postinstall": "node scripts/postinstall.cjs"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@series-inc/stowkit-reader": "^0.1.3"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"phaser": "^3.60.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
28
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
29
|
+
"phaser": "^3.70.0",
|
|
30
|
+
"rollup": "^4.9.1",
|
|
31
|
+
"tslib": "^2.6.2",
|
|
32
|
+
"typescript": "^5.3.3"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/series-ai/stowkit-2.git"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"stowkit",
|
|
43
|
+
"phaser",
|
|
44
|
+
"phaser3",
|
|
45
|
+
"game-engine",
|
|
46
|
+
"asset-loader",
|
|
47
|
+
"ktx2",
|
|
48
|
+
"basis-universal",
|
|
49
|
+
"compressed-textures",
|
|
50
|
+
"webassembly",
|
|
51
|
+
"texture-compression",
|
|
52
|
+
"bc3",
|
|
53
|
+
"dxt5",
|
|
54
|
+
"astc",
|
|
55
|
+
"etc2"
|
|
56
|
+
],
|
|
57
|
+
"author": ""
|
|
58
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const isInNodeModules = __dirname.includes('node_modules');
|
|
5
|
+
const projectRoot = process.env.INIT_CWD || process.cwd();
|
|
6
|
+
|
|
7
|
+
if (isInNodeModules) {
|
|
8
|
+
// Copy AI skill/rule files
|
|
9
|
+
try {
|
|
10
|
+
const skillSrc = path.join(__dirname, '..', 'skill.md');
|
|
11
|
+
|
|
12
|
+
if (fs.existsSync(skillSrc)) {
|
|
13
|
+
// Claude: .claude/skills/stowkit-phaser/SKILL.md
|
|
14
|
+
const claudeSkillDir = path.join(projectRoot, '.claude', 'skills', 'stowkit-phaser');
|
|
15
|
+
fs.mkdirSync(claudeSkillDir, { recursive: true });
|
|
16
|
+
fs.copyFileSync(skillSrc, path.join(claudeSkillDir, 'SKILL.md'));
|
|
17
|
+
console.log('✓ Copied Claude skill to .claude/skills/stowkit-phaser/SKILL.md');
|
|
18
|
+
|
|
19
|
+
// Cursor: .cursor/rules/stowkit-phaser.mdc
|
|
20
|
+
const cursorRulesDir = path.join(projectRoot, '.cursor', 'rules');
|
|
21
|
+
fs.mkdirSync(cursorRulesDir, { recursive: true });
|
|
22
|
+
const skillContent = fs.readFileSync(skillSrc, 'utf-8');
|
|
23
|
+
const cursorRule = [
|
|
24
|
+
'---',
|
|
25
|
+
'description: StowKit Phaser loader — loading KTX2/Basis compressed textures and audio from .stow packs',
|
|
26
|
+
'alwaysApply: true',
|
|
27
|
+
'---',
|
|
28
|
+
'',
|
|
29
|
+
skillContent,
|
|
30
|
+
].join('\n');
|
|
31
|
+
fs.writeFileSync(path.join(cursorRulesDir, 'stowkit-phaser.mdc'), cursorRule);
|
|
32
|
+
console.log('✓ Copied Cursor rule to .cursor/rules/stowkit-phaser.mdc');
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn('Could not copy AI skill/rule files:', error.message);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/skill.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# StowKit Phaser Loader
|
|
2
|
+
|
|
3
|
+
Use `@series-inc/stowkit-phaser-loader` to load `.stow` asset packs in Phaser applications. Supports 2D textures and audio only — for 3D models use `@series-inc/stowkit-three-loader`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @series-inc/stowkit-phaser-loader phaser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Phaser 3.60+ for compressed texture support.
|
|
12
|
+
|
|
13
|
+
## Loading a Pack
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { StowKitPhaserLoader } from '@series-inc/stowkit-phaser-loader';
|
|
17
|
+
|
|
18
|
+
const pack = await StowKitPhaserLoader.load('/assets/game.stow');
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Options (all optional):
|
|
22
|
+
- `basisPath` — path to Basis Universal transcoder dir (default: `'/basis/'`)
|
|
23
|
+
- `wasmPath` — path to `stowkit_reader.wasm` (default: `'/stowkit/stowkit_reader.wasm'`)
|
|
24
|
+
- `gl` — WebGL context to use (if not provided, a temporary canvas is created)
|
|
25
|
+
|
|
26
|
+
Load from memory:
|
|
27
|
+
```typescript
|
|
28
|
+
const buffer = await fetch(url).then(r => r.arrayBuffer());
|
|
29
|
+
const pack = await StowKitPhaserLoader.loadFromMemory(buffer);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Asset Types
|
|
33
|
+
|
|
34
|
+
| Type | Enum | Load Method |
|
|
35
|
+
|------|------|-------------|
|
|
36
|
+
| Texture | `AssetType.TEXTURE_2D` (2) | `pack.loadTexture(path, scene)` / `pack.getPhaserTexture(index, scene)` |
|
|
37
|
+
| Audio | `AssetType.AUDIO` (3) | `pack.loadAudio(path, ctx?)` / `pack.loadAudioByIndex(index, ctx?)` |
|
|
38
|
+
|
|
39
|
+
Assets are referenced by their `stringId` from `.stowmeta` files.
|
|
40
|
+
|
|
41
|
+
## Textures
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
await pack.loadTexture('characters/player', this);
|
|
45
|
+
const player = this.add.sprite(400, 300, 'characters/player');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`loadTexture` registers the texture with Phaser's texture manager using the asset path as the key. Must be called in or after `create()`.
|
|
49
|
+
|
|
50
|
+
KTX2 textures are automatically transcoded to the best GPU-compressed format:
|
|
51
|
+
- **Desktop:** BC7 (BPTC), BC3 (DXT5), BC1 (DXT1)
|
|
52
|
+
- **Mobile:** ASTC 4x4, ETC2, ETC1, PVRTC
|
|
53
|
+
- **Fallback:** RGBA32 uncompressed
|
|
54
|
+
|
|
55
|
+
## Audio
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const buffer = await pack.loadAudio('sounds/bgm');
|
|
59
|
+
|
|
60
|
+
// Or with a specific AudioContext
|
|
61
|
+
const ctx = new AudioContext();
|
|
62
|
+
const buffer = await pack.loadAudio('sounds/bgm', ctx);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For HTML5 preview: `const el = await pack.createAudioPreview(index);`
|
|
66
|
+
|
|
67
|
+
## Pack Manifest
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const assets = pack.listAssets();
|
|
71
|
+
// Each: { index, name, id, type, dataSize, hasMetadata }
|
|
72
|
+
|
|
73
|
+
const count = pack.getAssetCount();
|
|
74
|
+
const info = pack.getAssetInfo(0);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Metadata Helpers
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const tex = pack.getTextureMetadata(index);
|
|
81
|
+
// { width, height, channels, channelFormat }
|
|
82
|
+
|
|
83
|
+
const audio = pack.getAudioMetadata(index);
|
|
84
|
+
// { sampleRate, channels, durationMs }
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Multiple Packs
|
|
88
|
+
|
|
89
|
+
Each pack has its own WASM reader instance — fully isolated:
|
|
90
|
+
```typescript
|
|
91
|
+
const [uiPack, levelPack] = await Promise.all([
|
|
92
|
+
StowKitPhaserLoader.load('/assets/ui.stow'),
|
|
93
|
+
StowKitPhaserLoader.load('/assets/level1.stow'),
|
|
94
|
+
]);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Cleanup
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
pack.dispose(); // Closes WASM reader, frees resources
|
|
101
|
+
StowKitPhaserLoader.dispose(); // Frees shared Basis transcoder + temp WebGL context
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Exports
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import {
|
|
108
|
+
StowKitPhaserLoader, // Static loader class
|
|
109
|
+
StowKitPhaserPack, // Pack instance (returned by load)
|
|
110
|
+
BasisTranscoder, // Basis Universal transcoder
|
|
111
|
+
AssetType, // Enum: STATIC_MESH, TEXTURE_2D, AUDIO, etc.
|
|
112
|
+
PerfLogger // Performance logging
|
|
113
|
+
} from '@series-inc/stowkit-phaser-loader';
|
|
114
|
+
|
|
115
|
+
// Types
|
|
116
|
+
import type {
|
|
117
|
+
StowKitPhaserLoaderOptions,
|
|
118
|
+
TextureData
|
|
119
|
+
} from '@series-inc/stowkit-phaser-loader';
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Complete Example
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import Phaser from 'phaser';
|
|
126
|
+
import { StowKitPhaserLoader } from '@series-inc/stowkit-phaser-loader';
|
|
127
|
+
|
|
128
|
+
class GameScene extends Phaser.Scene {
|
|
129
|
+
constructor() {
|
|
130
|
+
super('GameScene');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async create() {
|
|
134
|
+
const pack = await StowKitPhaserLoader.load('/assets/game.stow');
|
|
135
|
+
|
|
136
|
+
await pack.loadTexture('backgrounds/sky', this);
|
|
137
|
+
await pack.loadTexture('characters/player', this);
|
|
138
|
+
await pack.loadTexture('ui/button', this);
|
|
139
|
+
|
|
140
|
+
this.add.image(400, 300, 'backgrounds/sky');
|
|
141
|
+
const player = this.add.sprite(400, 300, 'characters/player');
|
|
142
|
+
this.add.image(100, 50, 'ui/button');
|
|
143
|
+
|
|
144
|
+
const bgm = await pack.loadAudio('sounds/bgm');
|
|
145
|
+
const source = this.sound.context.createBufferSource();
|
|
146
|
+
source.buffer = bgm;
|
|
147
|
+
source.connect(this.sound.context.destination);
|
|
148
|
+
source.loop = true;
|
|
149
|
+
source.start();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const game = new Phaser.Game({
|
|
154
|
+
type: Phaser.WEBGL,
|
|
155
|
+
width: 800,
|
|
156
|
+
height: 600,
|
|
157
|
+
scene: GameScene
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Troubleshooting
|
|
162
|
+
|
|
163
|
+
- **Textures not loading** — Ensure Basis transcoder files are accessible at the `basisPath` URL
|
|
164
|
+
- **"Scene required" errors** — `loadTexture` must be called in or after `create()`, not in `preload()`
|
|
165
|
+
- **No compressed format supported** — Falls back to RGBA32; check WebGL context is available
|
|
166
|
+
- **Need 3D models?** — Use `@series-inc/stowkit-three-loader` instead; this loader is 2D only
|