rn-gamekit 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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/lib/module/assets/defineAssets.js +48 -0
- package/lib/module/assets/defineAssets.js.map +1 -0
- package/lib/module/assets/errors.js +38 -0
- package/lib/module/assets/errors.js.map +1 -0
- package/lib/module/assets/types.js +2 -0
- package/lib/module/assets/types.js.map +1 -0
- package/lib/module/assets/validation.js +99 -0
- package/lib/module/assets/validation.js.map +1 -0
- package/lib/module/core/frameDriver.js +20 -0
- package/lib/module/core/frameDriver.js.map +1 -0
- package/lib/module/core/input/createInputBuffer.js +296 -0
- package/lib/module/core/input/createInputBuffer.js.map +1 -0
- package/lib/module/core/input/types.js +4 -0
- package/lib/module/core/input/types.js.map +1 -0
- package/lib/module/core/session/createGameSession.js +554 -0
- package/lib/module/core/session/createGameSession.js.map +1 -0
- package/lib/module/core/session/deepFreeze.js +155 -0
- package/lib/module/core/session/deepFreeze.js.map +1 -0
- package/lib/module/core/session/diagnostics.js +2 -0
- package/lib/module/core/session/diagnostics.js.map +1 -0
- package/lib/module/core/session/types.js +43 -0
- package/lib/module/core/session/types.js.map +1 -0
- package/lib/module/definition/defineGame.js +57 -0
- package/lib/module/definition/defineGame.js.map +1 -0
- package/lib/module/definition/types.js +4 -0
- package/lib/module/definition/types.js.map +1 -0
- package/lib/module/geometry/types.js +2 -0
- package/lib/module/geometry/types.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/GamePointerInput.js +385 -0
- package/lib/module/react/GamePointerInput.js.map +1 -0
- package/lib/module/react/GameView.js +223 -0
- package/lib/module/react/GameView.js.map +1 -0
- package/lib/module/react/alphaClock.js +42 -0
- package/lib/module/react/alphaClock.js.map +1 -0
- package/lib/module/react/assets/createGameAssetStore.js +358 -0
- package/lib/module/react/assets/createGameAssetStore.js.map +1 -0
- package/lib/module/react/assets/decodeSkiaImage.js +54 -0
- package/lib/module/react/assets/decodeSkiaImage.js.map +1 -0
- package/lib/module/react/assets/errors.js +10 -0
- package/lib/module/react/assets/errors.js.map +1 -0
- package/lib/module/react/assets/useGameAssets.js +160 -0
- package/lib/module/react/assets/useGameAssets.js.map +1 -0
- package/lib/module/react/bindAppLifecycle.js +58 -0
- package/lib/module/react/bindAppLifecycle.js.map +1 -0
- package/lib/module/react/bindGameSession.js +37 -0
- package/lib/module/react/bindGameSession.js.map +1 -0
- package/lib/module/react/gestureLifecycle.js +68 -0
- package/lib/module/react/gestureLifecycle.js.map +1 -0
- package/lib/module/react/instrumentation.js +4 -0
- package/lib/module/react/instrumentation.js.map +1 -0
- package/lib/module/react/pointerBinding.js +196 -0
- package/lib/module/react/pointerBinding.js.map +1 -0
- package/lib/module/react/pointerCoalescer.js +224 -0
- package/lib/module/react/pointerCoalescer.js.map +1 -0
- package/lib/module/react/pointerContainment.js +27 -0
- package/lib/module/react/pointerContainment.js.map +1 -0
- package/lib/module/react/sprites/GameSprite.js +116 -0
- package/lib/module/react/sprites/GameSprite.js.map +1 -0
- package/lib/module/react/sprites/GameWorld2D.js +44 -0
- package/lib/module/react/sprites/GameWorld2D.js.map +1 -0
- package/lib/module/react/sprites/Sprite.js +147 -0
- package/lib/module/react/sprites/Sprite.js.map +1 -0
- package/lib/module/react/sprites/SpriteBatch.js +173 -0
- package/lib/module/react/sprites/SpriteBatch.js.map +1 -0
- package/lib/module/react/sprites/spriteBatchPolicy.js +25 -0
- package/lib/module/react/sprites/spriteBatchPolicy.js.map +1 -0
- package/lib/module/react/sprites/spriteTransform.js +135 -0
- package/lib/module/react/sprites/spriteTransform.js.map +1 -0
- package/lib/module/react/viewportBinding.js +101 -0
- package/lib/module/react/viewportBinding.js.map +1 -0
- package/lib/module/react.js +13 -0
- package/lib/module/react.js.map +1 -0
- package/lib/module/scene/defineScene.js +29 -0
- package/lib/module/scene/defineScene.js.map +1 -0
- package/lib/module/scene/types.js +4 -0
- package/lib/module/scene/types.js.map +1 -0
- package/lib/module/sprites/sampleSpriteClip.js +50 -0
- package/lib/module/sprites/sampleSpriteClip.js.map +1 -0
- package/lib/module/sprites/spriteAnimationState.js +165 -0
- package/lib/module/sprites/spriteAnimationState.js.map +1 -0
- package/lib/module/testing.js +57 -0
- package/lib/module/testing.js.map +1 -0
- package/lib/module/viewport2d/index.js +4 -0
- package/lib/module/viewport2d/index.js.map +1 -0
- package/lib/module/viewport2d/math.js +129 -0
- package/lib/module/viewport2d/math.js.map +1 -0
- package/lib/module/viewport2d/types.js +2 -0
- package/lib/module/viewport2d/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/assets/defineAssets.d.ts +20 -0
- package/lib/typescript/src/assets/defineAssets.d.ts.map +1 -0
- package/lib/typescript/src/assets/errors.d.ts +20 -0
- package/lib/typescript/src/assets/errors.d.ts.map +1 -0
- package/lib/typescript/src/assets/types.d.ts +138 -0
- package/lib/typescript/src/assets/types.d.ts.map +1 -0
- package/lib/typescript/src/assets/validation.d.ts +15 -0
- package/lib/typescript/src/assets/validation.d.ts.map +1 -0
- package/lib/typescript/src/core/frameDriver.d.ts +12 -0
- package/lib/typescript/src/core/frameDriver.d.ts.map +1 -0
- package/lib/typescript/src/core/input/createInputBuffer.d.ts +12 -0
- package/lib/typescript/src/core/input/createInputBuffer.d.ts.map +1 -0
- package/lib/typescript/src/core/input/types.d.ts +64 -0
- package/lib/typescript/src/core/input/types.d.ts.map +1 -0
- package/lib/typescript/src/core/session/createGameSession.d.ts +18 -0
- package/lib/typescript/src/core/session/createGameSession.d.ts.map +1 -0
- package/lib/typescript/src/core/session/deepFreeze.d.ts +27 -0
- package/lib/typescript/src/core/session/deepFreeze.d.ts.map +1 -0
- package/lib/typescript/src/core/session/diagnostics.d.ts +36 -0
- package/lib/typescript/src/core/session/diagnostics.d.ts.map +1 -0
- package/lib/typescript/src/core/session/types.d.ts +104 -0
- package/lib/typescript/src/core/session/types.d.ts.map +1 -0
- package/lib/typescript/src/definition/defineGame.d.ts +66 -0
- package/lib/typescript/src/definition/defineGame.d.ts.map +1 -0
- package/lib/typescript/src/definition/types.d.ts +56 -0
- package/lib/typescript/src/definition/types.d.ts.map +1 -0
- package/lib/typescript/src/geometry/types.d.ts +8 -0
- package/lib/typescript/src/geometry/types.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +18 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/react/GamePointerInput.d.ts +37 -0
- package/lib/typescript/src/react/GamePointerInput.d.ts.map +1 -0
- package/lib/typescript/src/react/GameView.d.ts +61 -0
- package/lib/typescript/src/react/GameView.d.ts.map +1 -0
- package/lib/typescript/src/react/alphaClock.d.ts +29 -0
- package/lib/typescript/src/react/alphaClock.d.ts.map +1 -0
- package/lib/typescript/src/react/assets/createGameAssetStore.d.ts +33 -0
- package/lib/typescript/src/react/assets/createGameAssetStore.d.ts.map +1 -0
- package/lib/typescript/src/react/assets/decodeSkiaImage.d.ts +12 -0
- package/lib/typescript/src/react/assets/decodeSkiaImage.d.ts.map +1 -0
- package/lib/typescript/src/react/assets/errors.d.ts +8 -0
- package/lib/typescript/src/react/assets/errors.d.ts.map +1 -0
- package/lib/typescript/src/react/assets/useGameAssets.d.ts +35 -0
- package/lib/typescript/src/react/assets/useGameAssets.d.ts.map +1 -0
- package/lib/typescript/src/react/bindAppLifecycle.d.ts +32 -0
- package/lib/typescript/src/react/bindAppLifecycle.d.ts.map +1 -0
- package/lib/typescript/src/react/bindGameSession.d.ts +14 -0
- package/lib/typescript/src/react/bindGameSession.d.ts.map +1 -0
- package/lib/typescript/src/react/gestureLifecycle.d.ts +37 -0
- package/lib/typescript/src/react/gestureLifecycle.d.ts.map +1 -0
- package/lib/typescript/src/react/instrumentation.d.ts +47 -0
- package/lib/typescript/src/react/instrumentation.d.ts.map +1 -0
- package/lib/typescript/src/react/pointerBinding.d.ts +104 -0
- package/lib/typescript/src/react/pointerBinding.d.ts.map +1 -0
- package/lib/typescript/src/react/pointerCoalescer.d.ts +106 -0
- package/lib/typescript/src/react/pointerCoalescer.d.ts.map +1 -0
- package/lib/typescript/src/react/pointerContainment.d.ts +12 -0
- package/lib/typescript/src/react/pointerContainment.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/GameSprite.d.ts +75 -0
- package/lib/typescript/src/react/sprites/GameSprite.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/GameWorld2D.d.ts +29 -0
- package/lib/typescript/src/react/sprites/GameWorld2D.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/Sprite.d.ts +43 -0
- package/lib/typescript/src/react/sprites/Sprite.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/SpriteBatch.d.ts +41 -0
- package/lib/typescript/src/react/sprites/SpriteBatch.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/spriteBatchPolicy.d.ts +10 -0
- package/lib/typescript/src/react/sprites/spriteBatchPolicy.d.ts.map +1 -0
- package/lib/typescript/src/react/sprites/spriteTransform.d.ts +86 -0
- package/lib/typescript/src/react/sprites/spriteTransform.d.ts.map +1 -0
- package/lib/typescript/src/react/viewportBinding.d.ts +42 -0
- package/lib/typescript/src/react/viewportBinding.d.ts.map +1 -0
- package/lib/typescript/src/react.d.ts +20 -0
- package/lib/typescript/src/react.d.ts.map +1 -0
- package/lib/typescript/src/scene/defineScene.d.ts +26 -0
- package/lib/typescript/src/scene/defineScene.d.ts.map +1 -0
- package/lib/typescript/src/scene/types.d.ts +71 -0
- package/lib/typescript/src/scene/types.d.ts.map +1 -0
- package/lib/typescript/src/sprites/sampleSpriteClip.d.ts +24 -0
- package/lib/typescript/src/sprites/sampleSpriteClip.d.ts.map +1 -0
- package/lib/typescript/src/sprites/spriteAnimationState.d.ts +45 -0
- package/lib/typescript/src/sprites/spriteAnimationState.d.ts.map +1 -0
- package/lib/typescript/src/testing.d.ts +28 -0
- package/lib/typescript/src/testing.d.ts.map +1 -0
- package/lib/typescript/src/viewport2d/index.d.ts +3 -0
- package/lib/typescript/src/viewport2d/index.d.ts.map +1 -0
- package/lib/typescript/src/viewport2d/math.d.ts +25 -0
- package/lib/typescript/src/viewport2d/math.d.ts.map +1 -0
- package/lib/typescript/src/viewport2d/types.d.ts +59 -0
- package/lib/typescript/src/viewport2d/types.d.ts.map +1 -0
- package/package.json +120 -0
- package/src/assets/defineAssets.ts +62 -0
- package/src/assets/errors.ts +64 -0
- package/src/assets/types.ts +164 -0
- package/src/assets/validation.ts +158 -0
- package/src/core/frameDriver.ts +31 -0
- package/src/core/input/createInputBuffer.ts +337 -0
- package/src/core/input/types.ts +67 -0
- package/src/core/session/createGameSession.ts +652 -0
- package/src/core/session/deepFreeze.ts +158 -0
- package/src/core/session/diagnostics.ts +35 -0
- package/src/core/session/types.ts +122 -0
- package/src/definition/defineGame.ts +94 -0
- package/src/definition/types.ts +67 -0
- package/src/geometry/types.ts +7 -0
- package/src/index.ts +84 -0
- package/src/react/GamePointerInput.tsx +478 -0
- package/src/react/GameView.tsx +317 -0
- package/src/react/alphaClock.ts +59 -0
- package/src/react/assets/createGameAssetStore.ts +459 -0
- package/src/react/assets/decodeSkiaImage.ts +64 -0
- package/src/react/assets/errors.ts +7 -0
- package/src/react/assets/useGameAssets.ts +171 -0
- package/src/react/bindAppLifecycle.ts +79 -0
- package/src/react/bindGameSession.ts +41 -0
- package/src/react/gestureLifecycle.ts +73 -0
- package/src/react/instrumentation.ts +54 -0
- package/src/react/pointerBinding.ts +226 -0
- package/src/react/pointerCoalescer.ts +234 -0
- package/src/react/pointerContainment.ts +23 -0
- package/src/react/sprites/GameSprite.tsx +192 -0
- package/src/react/sprites/GameWorld2D.tsx +46 -0
- package/src/react/sprites/Sprite.tsx +194 -0
- package/src/react/sprites/SpriteBatch.tsx +219 -0
- package/src/react/sprites/spriteBatchPolicy.ts +21 -0
- package/src/react/sprites/spriteTransform.ts +163 -0
- package/src/react/viewportBinding.ts +104 -0
- package/src/react.ts +37 -0
- package/src/scene/defineScene.ts +38 -0
- package/src/scene/types.ts +79 -0
- package/src/sprites/sampleSpriteClip.ts +51 -0
- package/src/sprites/spriteAnimationState.ts +176 -0
- package/src/testing.ts +61 -0
- package/src/viewport2d/index.ts +7 -0
- package/src/viewport2d/math.ts +134 -0
- package/src/viewport2d/types.ts +63 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to React Native GameKit will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## 0.1.0 - 2026-08-12
|
|
6
|
+
|
|
7
|
+
First public preview.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Fixed-step, headless game sessions with deterministic scene updates.
|
|
12
|
+
- Functional scene definitions, transitions, and immutable snapshots.
|
|
13
|
+
- Semantic button and pointer input with native gesture coalescing.
|
|
14
|
+
- Phone and tablet viewport resolution with `fit`, `fill`, and `extend-world` modes.
|
|
15
|
+
- Skia and Reanimated presentation through `GameView` and `GamePointerInput`.
|
|
16
|
+
- Typed local asset manifests, reference-counted loading, and React delivery.
|
|
17
|
+
- Sprite-sheet animation helpers, retained sprites, and Atlas-backed batching.
|
|
18
|
+
- A native-free root entry and deterministic testing utilities.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 React Native GameKit contributors
|
|
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,131 @@
|
|
|
1
|
+
# React Native GameKit
|
|
2
|
+
|
|
3
|
+
A headless-first 2D game toolkit for React Native and Expo, built for phones
|
|
4
|
+
and tablets.
|
|
5
|
+
|
|
6
|
+
> **0.1 preview:** React Native GameKit is usable for small 2D games and
|
|
7
|
+
> prototypes, but its API may change before 1.0.
|
|
8
|
+
|
|
9
|
+
## What is included
|
|
10
|
+
|
|
11
|
+
- deterministic fixed-step game sessions;
|
|
12
|
+
- immutable functional scenes and scene transitions;
|
|
13
|
+
- semantic button and multi-touch-safe pointer input;
|
|
14
|
+
- phone, tablet, rotation, and split-view viewport mapping;
|
|
15
|
+
- React Native Skia rendering with Reanimated interpolation;
|
|
16
|
+
- typed local images, sprite sheets, animation clips, and asset loading;
|
|
17
|
+
- retained sprites and Atlas-backed sprite batching;
|
|
18
|
+
- a native-free root entry for headless tests.
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
Version 0.1 targets the Expo SDK 57 compatibility set:
|
|
23
|
+
|
|
24
|
+
| Package | Supported version |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| React Native | `~0.86.2` |
|
|
27
|
+
| React | `^19.2.3` |
|
|
28
|
+
| Expo | `~57.0.10` |
|
|
29
|
+
| React Native Skia | `2.11.0` |
|
|
30
|
+
| Gesture Handler | `~3.1.0` |
|
|
31
|
+
| Reanimated | `4.5.3` |
|
|
32
|
+
| Worklets | `0.10.3` |
|
|
33
|
+
|
|
34
|
+
Expo Go is not required or supported. Use an Expo development build and
|
|
35
|
+
`expo prebuild`, or a bare React Native app configured with Expo Modules.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npm install rn-gamekit
|
|
41
|
+
npx expo install expo-asset @shopify/react-native-skia react-native-gesture-handler react-native-reanimated react-native-worklets
|
|
42
|
+
npx expo prebuild
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Wrap the application with Gesture Handler's root view:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
49
|
+
|
|
50
|
+
export default function App() {
|
|
51
|
+
return (
|
|
52
|
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
53
|
+
{/* Your application */}
|
|
54
|
+
</GestureHandlerRootView>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Native libraries are peer dependencies. The application owns them so there is
|
|
60
|
+
exactly one native copy, while GameKit releases declare the versions they were
|
|
61
|
+
validated against.
|
|
62
|
+
|
|
63
|
+
## Define a game
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import {
|
|
67
|
+
createGameSession,
|
|
68
|
+
defineGame,
|
|
69
|
+
defineScene,
|
|
70
|
+
} from 'rn-gamekit';
|
|
71
|
+
|
|
72
|
+
const game = defineGame({
|
|
73
|
+
viewport: {
|
|
74
|
+
logicalSize: { width: 320, height: 480 },
|
|
75
|
+
mode: 'fit',
|
|
76
|
+
},
|
|
77
|
+
input: {
|
|
78
|
+
move: { type: 'pointer' },
|
|
79
|
+
},
|
|
80
|
+
scenes: {
|
|
81
|
+
play: defineScene({
|
|
82
|
+
actions: ['move'],
|
|
83
|
+
create: () => ({ x: 160, y: 240 }),
|
|
84
|
+
update: ({ state, input }) => {
|
|
85
|
+
const pointer = input.pointer('move');
|
|
86
|
+
return pointer.active && pointer.position !== undefined
|
|
87
|
+
? { x: pointer.position.x, y: pointer.position.y }
|
|
88
|
+
: state;
|
|
89
|
+
},
|
|
90
|
+
snapshot: ({ state }) => state,
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
initialScene: 'play',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const session = createGameSession(game);
|
|
97
|
+
session.start();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Mount the session through the native entry point:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import {
|
|
104
|
+
GamePointerInput,
|
|
105
|
+
GameView,
|
|
106
|
+
} from 'rn-gamekit/react';
|
|
107
|
+
|
|
108
|
+
<GameView game={session} renderer={GameRenderer}>
|
|
109
|
+
<GamePointerInput game={session} action="move" />
|
|
110
|
+
</GameView>;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`rn-gamekit` contains the headless definition, session, viewport,
|
|
114
|
+
asset-manifest, and animation APIs. `rn-gamekit/react` contains the
|
|
115
|
+
Skia renderer, native pointer adapter, asset loader, sprites, and sprite
|
|
116
|
+
batching. `rn-gamekit/testing` contains deterministic frame drivers
|
|
117
|
+
for Node tests.
|
|
118
|
+
|
|
119
|
+
See the [repository documentation](https://github.com/OrekuD/react-native-gamekit/tree/main/apps/docs/content/docs)
|
|
120
|
+
and [Expo playground](https://github.com/OrekuD/react-native-gamekit/tree/main/apps/playground)
|
|
121
|
+
for complete examples.
|
|
122
|
+
|
|
123
|
+
## Current scope
|
|
124
|
+
|
|
125
|
+
The 0.1 release focuses on performant 2D foundations. Physics, tilemaps,
|
|
126
|
+
audio, haptics, game-level navigation, save data, and 3D rendering are not yet
|
|
127
|
+
part of the public package.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Asset definition helpers (T7.2).
|
|
5
|
+
*
|
|
6
|
+
* `image(...)` and `spriteSheet(...)` build immutable descriptors;
|
|
7
|
+
* `defineAssets(...)` groups them into a deeply immutable typed manifest.
|
|
8
|
+
* Definition performs no I/O and allocates no native handle.
|
|
9
|
+
*/
|
|
10
|
+
import { createDeepFreeze } from "../core/session/deepFreeze.js";
|
|
11
|
+
import { validateImageSource, validateManifest, validateSpriteSheet } from "./validation.js";
|
|
12
|
+
/** Declare a single full-image asset from a static module handle. */
|
|
13
|
+
export function image(source) {
|
|
14
|
+
validateImageSource(source);
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
kind: 'image',
|
|
17
|
+
source
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Declare a sprite-sheet asset: named source frames plus named animation
|
|
23
|
+
* clips. Frame and clip names are preserved as string literals; clip frame
|
|
24
|
+
* references are restricted to the declared frames.
|
|
25
|
+
*/
|
|
26
|
+
export function spriteSheet(source, spec) {
|
|
27
|
+
validateSpriteSheet(source, spec);
|
|
28
|
+
const freezer = createDeepFreeze();
|
|
29
|
+
return freezer({
|
|
30
|
+
kind: 'sprite-sheet',
|
|
31
|
+
source,
|
|
32
|
+
frames: spec.frames,
|
|
33
|
+
animations: spec.animations
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Declare the game's asset manifest: a deeply immutable, fully typed group
|
|
39
|
+
* map. Group, asset, frame, and clip names are preserved as string literals
|
|
40
|
+
* and every descriptor is branded with the manifest type so lookups stay
|
|
41
|
+
* typed. Allocates no native resources and performs no I/O.
|
|
42
|
+
*/
|
|
43
|
+
export function defineAssets(groups) {
|
|
44
|
+
validateManifest(groups);
|
|
45
|
+
const freezer = createDeepFreeze();
|
|
46
|
+
return freezer(groups);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=defineAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createDeepFreeze","validateImageSource","validateManifest","validateSpriteSheet","image","source","Object","freeze","kind","spriteSheet","spec","freezer","frames","animations","defineAssets","groups"],"sourceRoot":"../../../src","sources":["assets/defineAssets.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,+BAA4B;AAC7D,SAASC,mBAAmB,EAAEC,gBAAgB,EAAEC,mBAAmB,QAAQ,iBAAc;AAUzF;AACA,OAAO,SAASC,KAAKA,CAACC,MAAc,EAAmB;EACrDJ,mBAAmB,CAACI,MAAM,CAAC;EAC3B,OAAOC,MAAM,CAACC,MAAM,CAAC;IAAEC,IAAI,EAAE,OAAO;IAAEH;EAAO,CAAC,CAAC;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,WAAWA,CAIzBJ,MAAc,EACdK,IAGC,EACuC;EACxCP,mBAAmB,CAACE,MAAM,EAAEK,IAAI,CAAC;EACjC,MAAMC,OAAO,GAAGX,gBAAgB,CAAC,CAAC;EAClC,OAAOW,OAAO,CAAC;IACbH,IAAI,EAAE,cAAc;IACpBH,MAAM;IACNO,MAAM,EAAEF,IAAI,CAACE,MAAM;IACnBC,UAAU,EAAEH,IAAI,CAACG;EACnB,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAC1BC,MAAe,EACa;EAC5Bb,gBAAgB,CAACa,MAAM,CAAC;EACxB,MAAMJ,OAAO,GAAGX,gBAAgB,CAAC,CAAC;EAClC,OAAOW,OAAO,CAACI,MAAM,CAAC;AACxB","ignoreList":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structured asset errors (T7.2).
|
|
5
|
+
*
|
|
6
|
+
* Every definition/loading failure carries a stable machine-readable code
|
|
7
|
+
* and the field path that caused it. Paths are documented in the public
|
|
8
|
+
* error reference; messages never embed machine-specific paths.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Stable error codes for asset definition and loading. */
|
|
12
|
+
|
|
13
|
+
/** A structured asset definition or loading failure. */
|
|
14
|
+
export class GameAssetError extends Error {
|
|
15
|
+
/** Stable machine-readable code. */
|
|
16
|
+
|
|
17
|
+
/** Field path within the manifest/descriptor that caused the failure. */
|
|
18
|
+
|
|
19
|
+
constructor(code, path, message) {
|
|
20
|
+
super(`${code}${path.length > 0 ? ` at ${path.join('.')}` : ''}: ${message}`);
|
|
21
|
+
this.name = 'GameAssetError';
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.path = path;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Throw when a definition-time identifier is invalid. */
|
|
28
|
+
export function assertValidIdentifier(path, value) {
|
|
29
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
30
|
+
throw new GameAssetError('ASSET_INVALID_IDENTIFIER', path, 'identifiers must be non-empty strings');
|
|
31
|
+
}
|
|
32
|
+
// '/' is the diagnostic-id separator (group/key); reserving it keeps
|
|
33
|
+
// diagnostic ids unambiguous.
|
|
34
|
+
if (value.includes('/')) {
|
|
35
|
+
throw new GameAssetError('ASSET_INVALID_IDENTIFIER', path, `identifier ${JSON.stringify(value)} contains the reserved separator '/'`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GameAssetError","Error","constructor","code","path","message","length","join","name","assertValidIdentifier","value","includes","JSON","stringify"],"sourceRoot":"../../../src","sources":["assets/errors.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAmBA;AACA,OAAO,MAAMA,cAAc,SAASC,KAAK,CAAC;EACxC;;EAEA;;EAGAC,WAAWA,CAACC,IAAwB,EAAEC,IAAuB,EAAEC,OAAe,EAAE;IAC9E,KAAK,CAAC,GAAGF,IAAI,GAAGC,IAAI,CAACE,MAAM,GAAG,CAAC,GAAG,OAAOF,IAAI,CAACG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAKF,OAAO,EAAE,CAAC;IAC7E,IAAI,CAACG,IAAI,GAAG,gBAAgB;IAC5B,IAAI,CAACL,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,IAAI,GAAGA,IAAI;EAClB;AACF;;AAEA;AACA,OAAO,SAASK,qBAAqBA,CACnCL,IAAuB,EACvBM,KAAa,EACP;EACN,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACJ,MAAM,KAAK,CAAC,EAAE;IACnD,MAAM,IAAIN,cAAc,CACtB,0BAA0B,EAC1BI,IAAI,EACJ,uCACF,CAAC;EACH;EACA;EACA;EACA,IAAIM,KAAK,CAACC,QAAQ,CAAC,GAAG,CAAC,EAAE;IACvB,MAAM,IAAIX,cAAc,CACtB,0BAA0B,EAC1BI,IAAI,EACJ,cAAcQ,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC,sCACrC,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["assets/types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Manifest validation (T7.2).
|
|
5
|
+
*
|
|
6
|
+
* Everything knowable before decoding is validated here with stable error
|
|
7
|
+
* codes and field paths. Rectangles are additionally validated against the
|
|
8
|
+
* decoded image dimensions after load (T7.4).
|
|
9
|
+
*/
|
|
10
|
+
import { GameAssetError, assertValidIdentifier } from "./errors.js";
|
|
11
|
+
/** Validate one frame rectangle. */
|
|
12
|
+
export function validateFrameRect(path, name, rect) {
|
|
13
|
+
assertValidIdentifier(path, name);
|
|
14
|
+
const {
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
width,
|
|
18
|
+
height
|
|
19
|
+
} = rect;
|
|
20
|
+
const values = [x, y, width, height];
|
|
21
|
+
for (const value of values) {
|
|
22
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
23
|
+
throw new GameAssetError('ASSET_INVALID_FRAME_RECT', path, `frame ${JSON.stringify(name)} coordinates must be finite numbers`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (x < 0 || y < 0) {
|
|
27
|
+
throw new GameAssetError('ASSET_INVALID_FRAME_RECT', path, `frame ${JSON.stringify(name)} x/y must be non-negative`);
|
|
28
|
+
}
|
|
29
|
+
if (width <= 0 || height <= 0) {
|
|
30
|
+
throw new GameAssetError('ASSET_INVALID_FRAME_RECT', path, `frame ${JSON.stringify(name)} width/height must be greater than zero`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Validate one animation clip against the sheet's declared frames. */
|
|
35
|
+
export function validateClip(path, name, clip, frames) {
|
|
36
|
+
assertValidIdentifier(path, name);
|
|
37
|
+
if (typeof clip.frames !== 'object' || clip.frames.length === 0) {
|
|
38
|
+
throw new GameAssetError('ASSET_EMPTY_CLIP', path, `clip ${JSON.stringify(name)} must reference at least one frame`);
|
|
39
|
+
}
|
|
40
|
+
for (const frame of clip.frames) {
|
|
41
|
+
if (typeof frame !== 'string' || !(frame in frames)) {
|
|
42
|
+
throw new GameAssetError('ASSET_UNKNOWN_FRAME', [...path, 'frames'], `clip ${JSON.stringify(name)} references unknown frame ${JSON.stringify(frame)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const duration = clip.frameDurationMs;
|
|
46
|
+
if (typeof duration !== 'number' || !Number.isFinite(duration) || duration <= 0) {
|
|
47
|
+
throw new GameAssetError('ASSET_INVALID_DURATION', [...path, 'frameDurationMs'], `clip ${JSON.stringify(name)} duration must be finite and greater than zero`);
|
|
48
|
+
}
|
|
49
|
+
if (clip.mode !== 'loop' && clip.mode !== 'once') {
|
|
50
|
+
throw new GameAssetError('ASSET_INVALID_MODE', [...path, 'mode'], `clip ${JSON.stringify(name)} mode must be 'loop' or 'once'`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Validate a full sprite-sheet descriptor. */
|
|
55
|
+
export function validateSpriteSheet(source, spec) {
|
|
56
|
+
if (typeof source !== 'number' || !Number.isInteger(source) || source < 0) {
|
|
57
|
+
throw new GameAssetError('ASSET_INVALID_SOURCE', [], 'sprite-sheet source must be a static module handle (number)');
|
|
58
|
+
}
|
|
59
|
+
for (const [name, rect] of Object.entries(spec.frames)) {
|
|
60
|
+
validateFrameRect(['frames', name], name, rect);
|
|
61
|
+
}
|
|
62
|
+
for (const [name, clip] of Object.entries(spec.animations)) {
|
|
63
|
+
validateClip(['animations', name], name, clip, spec.frames);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Validate an image descriptor's source. */
|
|
68
|
+
export function validateImageSource(source) {
|
|
69
|
+
if (typeof source !== 'number' || !Number.isInteger(source) || source < 0) {
|
|
70
|
+
throw new GameAssetError('ASSET_INVALID_SOURCE', [], 'image source must be a static module handle (number)');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Validate a full asset manifest. */
|
|
75
|
+
export function validateManifest(manifest) {
|
|
76
|
+
for (const [group, assets] of Object.entries(manifest)) {
|
|
77
|
+
const groupPath = [group];
|
|
78
|
+
assertValidIdentifier([], group);
|
|
79
|
+
if (typeof assets !== 'object' || assets === null) {
|
|
80
|
+
throw new GameAssetError('ASSET_INVALID_IDENTIFIER', groupPath, `group ${JSON.stringify(group)} must be an object of named assets`);
|
|
81
|
+
}
|
|
82
|
+
for (const [name, descriptor] of Object.entries(assets)) {
|
|
83
|
+
const path = [...groupPath, name];
|
|
84
|
+
assertValidIdentifier(groupPath, name);
|
|
85
|
+
if (descriptor === null || typeof descriptor !== 'object') {
|
|
86
|
+
throw new GameAssetError('ASSET_INVALID_IDENTIFIER', path, `asset ${JSON.stringify(name)} must be a descriptor`);
|
|
87
|
+
}
|
|
88
|
+
if (descriptor.kind === 'image') {
|
|
89
|
+
validateImageSource(descriptor.source);
|
|
90
|
+
} else if (descriptor.kind === 'sprite-sheet') {
|
|
91
|
+
const sheet = descriptor;
|
|
92
|
+
validateSpriteSheet(sheet.source, sheet);
|
|
93
|
+
} else {
|
|
94
|
+
throw new GameAssetError('ASSET_INVALID_IDENTIFIER', path, `asset ${JSON.stringify(name)} has unknown descriptor kind`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GameAssetError","assertValidIdentifier","validateFrameRect","path","name","rect","x","y","width","height","values","value","Number","isFinite","JSON","stringify","validateClip","clip","frames","length","frame","duration","frameDurationMs","mode","validateSpriteSheet","source","spec","isInteger","Object","entries","animations","validateImageSource","validateManifest","manifest","group","assets","groupPath","descriptor","kind","sheet"],"sourceRoot":"../../../src","sources":["assets/validation.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,qBAAqB,QAAQ,aAAU;AAQhE;AACA,OAAO,SAASC,iBAAiBA,CAC/BC,IAAuB,EACvBC,IAAY,EACZC,IAAqB,EACf;EACNJ,qBAAqB,CAACE,IAAI,EAAEC,IAAI,CAAC;EACjC,MAAM;IAAEE,CAAC;IAAEC,CAAC;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGJ,IAAI;EACpC,MAAMK,MAAM,GAAG,CAACJ,CAAC,EAAEC,CAAC,EAAEC,KAAK,EAAEC,MAAM,CAAU;EAC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BAC/B,CAAC;MACH;MACA,IAAKiC,UAAU,CAAiCC,IAAI,KAAK,OAAO,EAAE;QAChEP,mBAAmB,CAAEM,UAAU,CAAmCZ,MAAM,CAAC;MAC3E,CAAC,MAAM,IAAKY,UAAU,CAAiCC,IAAI,KAAK,cAAc,EAAE;QAC9E,MAAMC,KAAK,GAAGF,UAA8C;QAC5Db,mBAAmB,CAACe,KAAK,CAACd,MAAM,EAAEc,KAAK,CAAC;MAC1C,CAAC,MAAM;QACL,MAAM,IAAIvC,cAAc,CACtB,0BAA0B,EAC1BG,IAAI,EACJ,SAASW,IAAI,CAACC,SAAS,CAACX,IAAI,CAAC,8BAC/B,CAAC;MACH;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/** Opaque handle returned by an animation-frame driver. */
|
|
4
|
+
|
|
5
|
+
/** Minimal presentation clock used by the fixed-step runtime. */
|
|
6
|
+
|
|
7
|
+
/** Create the platform animation-frame driver used by live sessions. */
|
|
8
|
+
export function createAnimationFrameDriver() {
|
|
9
|
+
const host = globalThis;
|
|
10
|
+
const requestAnimationFrame = host.requestAnimationFrame;
|
|
11
|
+
const cancelAnimationFrame = host.cancelAnimationFrame;
|
|
12
|
+
if (!requestAnimationFrame || !cancelAnimationFrame) {
|
|
13
|
+
throw new Error('GameSession requires requestAnimationFrame on this platform');
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
requestFrame: callback => requestAnimationFrame(callback),
|
|
17
|
+
cancelFrame: handle => cancelAnimationFrame(handle)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=frameDriver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAnimationFrameDriver","host","globalThis","requestAnimationFrame","cancelAnimationFrame","Error","requestFrame","callback","cancelFrame","handle"],"sourceRoot":"../../../src","sources":["core/frameDriver.ts"],"mappings":";;AAAA;;AAGA;;AAaA;AACA,OAAO,SAASA,0BAA0BA,CAAA,EAAgB;EACxD,MAAMC,IAAI,GAAGC,UAAoD;EACjE,MAAMC,qBAAqB,GAAGF,IAAI,CAACE,qBAAqB;EACxD,MAAMC,oBAAoB,GAAGH,IAAI,CAACG,oBAAoB;EAEtD,IAAI,CAACD,qBAAqB,IAAI,CAACC,oBAAoB,EAAE;IACnD,MAAM,IAAIC,KAAK,CAAC,6DAA6D,CAAC;EAChF;EAEA,OAAO;IACLC,YAAY,EAAGC,QAAQ,IAAKJ,qBAAqB,CAACI,QAAQ,CAAC;IAC3DC,WAAW,EAAGC,MAAM,IAAKL,oBAAoB,CAACK,MAAM;EACtD,CAAC;AACH","ignoreList":[]}
|