@littlepartytime/sdk 2.1.0 → 2.2.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/GAME_DEV_GUIDE.md +42 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +34 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/GAME_DEV_GUIDE.md
CHANGED
|
@@ -714,8 +714,8 @@ export default function GameRenderer({ platform, state }: GameRendererProps) {
|
|
|
714
714
|
|
|
715
715
|
| Rule | Limit |
|
|
716
716
|
|------|-------|
|
|
717
|
-
| Single file size | ≤
|
|
718
|
-
| Total assets size | ≤
|
|
717
|
+
| Single file size | ≤ 20MB |
|
|
718
|
+
| Total assets size | ≤ 100MB |
|
|
719
719
|
| Allowed file types | `.png`, `.jpg`, `.jpeg`, `.webp`, `.svg`, `.gif`, `.mp3`, `.wav`, `.ogg`, `.json`, `.woff2`, `.woff` |
|
|
720
720
|
| Path rules | No `..`, no spaces |
|
|
721
721
|
|
|
@@ -749,6 +749,46 @@ export default function GameRenderer({ platform, state }: GameRendererProps) {
|
|
|
749
749
|
| `off(event, handler)` | Removes an event listener |
|
|
750
750
|
| `reportResult(result)` | Reports game results (called by platform, not games) |
|
|
751
751
|
| `getAssetUrl(path)` | Returns the runtime URL for a custom asset (e.g., `"cards/king.png"` → CDN URL) |
|
|
752
|
+
| `getDeviceCapabilities()` | Returns `{ haptics: boolean, motion: boolean }` indicating available device features |
|
|
753
|
+
| `haptic(type, option?)` | Triggers haptic feedback. `type`: `'impact'` / `'notification'` / `'selection'`. Silent no-op if unsupported |
|
|
754
|
+
| `onShake(handler)` | Listens for device shake events. Returns an unsubscribe function |
|
|
755
|
+
| `onTilt(handler)` | Streams device tilt data (`{ alpha, beta, gamma }`) at ~60fps. Returns an unsubscribe function |
|
|
756
|
+
|
|
757
|
+
#### Device Capabilities & Graceful Degradation
|
|
758
|
+
|
|
759
|
+
Games can query runtime capabilities via `getDeviceCapabilities()` and provide fallback UI:
|
|
760
|
+
|
|
761
|
+
```tsx
|
|
762
|
+
const caps = platform.getDeviceCapabilities();
|
|
763
|
+
|
|
764
|
+
// Shake: use motion sensor or fall back to a button
|
|
765
|
+
useEffect(() => {
|
|
766
|
+
if (!caps.motion) return;
|
|
767
|
+
return platform.onShake(() => {
|
|
768
|
+
platform.haptic('impact', 'heavy');
|
|
769
|
+
platform.send({ type: 'ROLL_DICE' });
|
|
770
|
+
});
|
|
771
|
+
}, [platform, caps.motion]);
|
|
772
|
+
|
|
773
|
+
// Tilt: stream orientation data for motion-controlled games
|
|
774
|
+
useEffect(() => {
|
|
775
|
+
if (!caps.motion) return;
|
|
776
|
+
return platform.onTilt((tilt) => {
|
|
777
|
+
// tilt.beta = front/back (-180~180), tilt.gamma = left/right (-90~90)
|
|
778
|
+
updateBallPosition(tilt.gamma, tilt.beta);
|
|
779
|
+
});
|
|
780
|
+
}, [platform, caps.motion]);
|
|
781
|
+
|
|
782
|
+
// Haptic feedback on user action (silent no-op if unsupported)
|
|
783
|
+
platform.haptic('impact', 'light');
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
| Environment | Haptics | Motion (Shake/Tilt) |
|
|
787
|
+
|---|---|---|
|
|
788
|
+
| Native App (iOS/Android) | Full support (Impact/Notification/Selection) | Full support |
|
|
789
|
+
| Web (Android Chrome) | Basic vibration | Supported |
|
|
790
|
+
| Web (iOS Safari) | Not supported (silent) | Requires permission (handled by platform) |
|
|
791
|
+
| Dev-kit preview | Not supported (silent) | Not supported |
|
|
752
792
|
|
|
753
793
|
### Events the renderer should listen for
|
|
754
794
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { Player, GameAction, GameResult, Platform } from './types';
|
|
1
|
+
export type { Player, GameAction, GameResult, Platform, HapticImpactStyle, HapticNotificationType, DeviceTilt, DeviceCapabilities, } from './types';
|
|
2
2
|
export type { PlayerState, GameState, GameAssets, GameConfig, GameEngine, GameRendererProps } from './interfaces';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,MAAM,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,EACV,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -17,6 +17,20 @@ export interface GameResult {
|
|
|
17
17
|
}[];
|
|
18
18
|
data?: Record<string, unknown>;
|
|
19
19
|
}
|
|
20
|
+
export type HapticImpactStyle = 'light' | 'medium' | 'heavy';
|
|
21
|
+
export type HapticNotificationType = 'success' | 'warning' | 'error';
|
|
22
|
+
export interface DeviceTilt {
|
|
23
|
+
/** 绕 z 轴旋转 (0~360) —— 指南针方向 */
|
|
24
|
+
alpha: number;
|
|
25
|
+
/** 绕 x 轴旋转 (-180~180) —— 前后倾斜 */
|
|
26
|
+
beta: number;
|
|
27
|
+
/** 绕 y 轴旋转 (-90~90) —— 左右倾斜 */
|
|
28
|
+
gamma: number;
|
|
29
|
+
}
|
|
30
|
+
export interface DeviceCapabilities {
|
|
31
|
+
haptics: boolean;
|
|
32
|
+
motion: boolean;
|
|
33
|
+
}
|
|
20
34
|
export interface Platform {
|
|
21
35
|
getPlayers(): Player[];
|
|
22
36
|
getLocalPlayer(): Player;
|
|
@@ -30,5 +44,25 @@ export interface Platform {
|
|
|
30
44
|
* @returns 可直接用于 <img src> / <audio src> / fetch() 的完整 URL
|
|
31
45
|
*/
|
|
32
46
|
getAssetUrl(path: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* 查询当前运行环境的设备能力。
|
|
49
|
+
* 游戏可据此决定是否启用某些交互,或提供视觉降级方案。
|
|
50
|
+
*/
|
|
51
|
+
getDeviceCapabilities(): DeviceCapabilities;
|
|
52
|
+
/**
|
|
53
|
+
* 触发震动反馈。不支持时静默忽略。
|
|
54
|
+
*/
|
|
55
|
+
haptic(type: 'impact' | 'notification' | 'selection', option?: HapticImpactStyle | HapticNotificationType): void;
|
|
56
|
+
/**
|
|
57
|
+
* 监听摇晃事件。平台负责处理权限请求和加速度阈值判定。
|
|
58
|
+
* @returns 取消监听的函数
|
|
59
|
+
*/
|
|
60
|
+
onShake(handler: () => void): () => void;
|
|
61
|
+
/**
|
|
62
|
+
* 监听设备倾斜数据流。平台负责处理权限请求。
|
|
63
|
+
* @param handler 约 60fps 回调
|
|
64
|
+
* @returns 取消监听的函数
|
|
65
|
+
*/
|
|
66
|
+
onTilt(handler: (tilt: DeviceTilt) => void): () => void;
|
|
33
67
|
}
|
|
34
68
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,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