rngine 0.8.3 → 0.9.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/README.md +28 -21
- package/android/CMakeLists.txt +5 -2
- package/lib/module/GameMethods.js +20 -7
- package/lib/module/GameMethods.js.map +1 -1
- package/lib/module/GameMethods.nitro.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/GameMethods.d.ts +11 -4
- package/lib/typescript/src/GameMethods.d.ts.map +1 -1
- package/lib/typescript/src/GameMethods.nitro.d.ts +8 -2
- package/lib/typescript/src/GameMethods.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/nativeTypes.d.ts +12 -2
- package/lib/typescript/src/nativeTypes.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +2 -2
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.hpp +5 -1
- package/nitrogen/generated/shared/c++/Screen.hpp +9 -1
- package/nitrogen/generated/shared/c++/ScreenUpdate.hpp +120 -0
- package/nitrogen/generated/shared/c++/System.hpp +8 -11
- package/nitrogen/generated/shared/c++/SystemContext.hpp +99 -0
- package/package.json +1 -1
- package/shared/GameLoop.cpp +16 -33
- package/shared/GameMethods.cpp +50 -52
- package/shared/GameMethods.hpp +3 -1
- package/shared/GameRenderer.cpp +26 -131
- package/shared/GameRenderer.hpp +2 -2
- package/shared/utils/AssetUtils.cpp +92 -0
- package/shared/utils/AssetUtils.hpp +11 -0
- package/shared/{CollisionUtils.cpp → utils/CollisionUtils.cpp} +9 -8
- package/shared/utils/CollisionUtils.hpp +10 -0
- package/src/GameMethods.nitro.ts +11 -1
- package/src/GameMethods.ts +20 -8
- package/src/index.tsx +1 -0
- package/src/nativeTypes.ts +13 -2
- package/src/types.ts +2 -2
- package/shared/CollisionUtils.hpp +0 -21
- /package/shared/{ColorUtils.cpp → utils/ColorUtils.cpp} +0 -0
- /package/shared/{ColorUtils.hpp → utils/ColorUtils.hpp} +0 -0
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm install rngine react-native-nitro-modules
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import { GameEngine, configure,
|
|
16
|
+
import { GameEngine, configure, updateEntity } from 'rngine';
|
|
17
17
|
|
|
18
18
|
configure({
|
|
19
19
|
world: { tickRate: 60 },
|
|
20
|
-
screen: { width: 800, height: 800, color: '#1a1a1a' },
|
|
20
|
+
screen: { px: 400, py: 400, width: 800, height: 800, color: '#1a1a1a' },
|
|
21
21
|
entities: [
|
|
22
22
|
{
|
|
23
23
|
id: 'player',
|
|
@@ -47,12 +47,12 @@ configure({
|
|
|
47
47
|
{
|
|
48
48
|
// runs every tick for all enemies
|
|
49
49
|
entities: ['enemy'],
|
|
50
|
-
onTick: (enemies) => {
|
|
50
|
+
onTick: ({ entities: enemies }) => {
|
|
51
51
|
enemies.forEach((enemy) => {
|
|
52
52
|
// reverse direction when reaching screen edges
|
|
53
53
|
const halfWidth = enemy.shape.width / 2;
|
|
54
54
|
if (enemy.px - halfWidth <= 0 || enemy.px + halfWidth >= 800) {
|
|
55
|
-
|
|
55
|
+
updateEntity({ id: enemy.id, vx: -enemy.vx });
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
},
|
|
@@ -74,19 +74,19 @@ export default function App() {
|
|
|
74
74
|
|
|
75
75
|
**Systems** define your game logic. Each system optionally declares which entities it cares about via `entities`, which collision pairs to watch via `collisions`, or both. Systems run every tick receiving the resolved entities and any active collisions. See [`System`](./src/types.ts).
|
|
76
76
|
|
|
77
|
-
**Screen** defines the viewport dimensions and optional background: color/asset. Entities outside the screen bounds are automatically clipped. See [`Screen`](./src/nativeTypes.ts)
|
|
77
|
+
**Screen** defines the viewport dimensions, position and optional background: color/asset. Entities outside the screen bounds are automatically clipped. See [`Screen`](./src/nativeTypes.ts)
|
|
78
78
|
|
|
79
79
|
**World** defines global simulation settings: `tickRate` (game logic updates per second) and optional gravity (`gx`/`gy`, in game units per second²). See [`World`](./src/nativeTypes.ts)
|
|
80
80
|
|
|
81
81
|
## Rendering
|
|
82
82
|
|
|
83
|
-
Rngine renders natively with [Skia](https://skia.org/)
|
|
83
|
+
Rngine renders natively with [Skia](https://skia.org/): every frame is drawn directly in C++ on the game loop thread, with no bridge round-trip per frame. SVG, PNG, and [Lottie](https://airbnb.io/lottie/) animations are all supported as entity/screen assets, decoded and cached natively.
|
|
84
84
|
|
|
85
85
|
## Physics
|
|
86
86
|
|
|
87
|
-
Entities with a `mass` are affected by the world's gravity (`world.gx`/`gy`) and participate in automatic collision resolution: overlapping entities are pushed apart and have their velocities updated via an impulse response. Entities without a `mass` (or `mass: 0`) are treated as immovable (infinite mass) when involved in a collision
|
|
87
|
+
Entities with a `mass` are affected by the world's gravity (`world.gx`/`gy`) and participate in automatic collision resolution: overlapping entities are pushed apart and have their velocities updated via an impulse response. Entities without a `mass` (or `mass: 0`) are treated as immovable (infinite mass) when involved in a collision: useful for static geometry like a ground or walls.
|
|
88
88
|
|
|
89
|
-
Set `isSensor: true` on an entity to still receive collision events (`Collision.depth`, `Collision.nx`/`ny`) without any physical response
|
|
89
|
+
Set `isSensor: true` on an entity to still receive collision events (`Collision.depth`, `Collision.nx`/`ny`) without any physical response: the entity won't be pushed, and other entities won't be pushed by it. This is useful for pickups, triggers, or grid-based games where you want to detect overlap yourself without physics involved.
|
|
90
90
|
|
|
91
91
|
## Entity Querying
|
|
92
92
|
|
|
@@ -108,11 +108,11 @@ This makes it easy to build entity groups naturally through naming. No extra con
|
|
|
108
108
|
{ collisions: [{ a: 'player', b: 'enemy' }], onTick: (_, collisions) => {} }
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
Collision results include a normalized direction vector (`nx`/`ny`) pointing along the minimum separating axis, alongside the penetration `depth
|
|
111
|
+
Collision results include a normalized direction vector (`nx`/`ny`) pointing along the minimum separating axis, alongside the penetration `depth`: useful for resolving collisions manually or reacting to a specific direction of impact.
|
|
112
112
|
|
|
113
113
|
## Assets
|
|
114
114
|
|
|
115
|
-
Assets (SVGs and Lottie animations) must be preloaded with `loadAssets` before being referenced by `id`, `px`/`py`, or any `configure`/`spawn`/`update` call. Loading happens off the JS thread and is cached
|
|
115
|
+
Assets (SVGs, PNGs, and Lottie animations) must be preloaded with `loadAssets` before being referenced by `id`, `px`/`py`, or any `configure`/`spawn`/`update` call. Loading happens off the JS thread and is cached. Calling `loadAssets` again with the same source is a no-op.
|
|
116
116
|
|
|
117
117
|
```ts
|
|
118
118
|
import { loadAssets } from 'rngine';
|
|
@@ -131,17 +131,17 @@ const assets = await loadAssets({
|
|
|
131
131
|
|
|
132
132
|
Sets up the game engine. Call this before anything else.
|
|
133
133
|
|
|
134
|
-
| param | required | type | default | description
|
|
135
|
-
| ---------- | -------- | ---------- | ------- |
|
|
136
|
-
| `world` | ✓ | `World` | - | Tick rate and optional gravity
|
|
137
|
-
| `screen` | ✓ | `Screen` | - | Screen dimensions, background color and asset |
|
|
138
|
-
| `entities` | | `Entity[]` | `[]` | Initial entities to spawn
|
|
139
|
-
| `systems` | | `System[]` | `[]` | Systems to run each tick
|
|
140
|
-
| `paused` | | `boolean` | `true` | Whether to start paused
|
|
134
|
+
| param | required | type | default | description |
|
|
135
|
+
| ---------- | -------- | ---------- | ------- | ------------------------------------------------------- |
|
|
136
|
+
| `world` | ✓ | `World` | - | Tick rate and optional gravity |
|
|
137
|
+
| `screen` | ✓ | `Screen` | - | Screen dimensions, position, background color and asset |
|
|
138
|
+
| `entities` | | `Entity[]` | `[]` | Initial entities to spawn |
|
|
139
|
+
| `systems` | | `System[]` | `[]` | Systems to run each tick |
|
|
140
|
+
| `paused` | | `boolean` | `true` | Whether to start paused |
|
|
141
141
|
|
|
142
142
|
### `loadAssets(assets)`
|
|
143
143
|
|
|
144
|
-
Preloads one or more SVG or Lottie assets ahead of time. Takes an object mapping names to `require(...)` sources (SVG) or imported JSON (Lottie), and resolves to an object of the same shape with numeric asset ids.
|
|
144
|
+
Preloads one or more SVG, PNG or Lottie assets ahead of time. Takes an object mapping names to `require(...)` sources (SVG/PNG) or imported JSON (Lottie), and resolves to an object of the same shape with numeric asset ids.
|
|
145
145
|
|
|
146
146
|
### `spawn(entity | entity[])`
|
|
147
147
|
|
|
@@ -151,10 +151,17 @@ Spawns one or more entities into the world. Skips duplicates by id.
|
|
|
151
151
|
|
|
152
152
|
Removes the entity with the given id, or all entities matching the given prefix.
|
|
153
153
|
|
|
154
|
-
### `
|
|
154
|
+
### `updateEntity(entityUpdate)`
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
Fires one update, applied to entities matching the given id prefix from the world. Only the provided fields are changed.
|
|
157
|
+
|
|
158
|
+
### `updateEntities(entityUpdate[])`
|
|
159
|
+
|
|
160
|
+
Fires multiple updates, each applied to entities matching the given id prefix from the world. Only the provided fields are changed.
|
|
161
|
+
|
|
162
|
+
### `screenUpdate(screenUpdate)`
|
|
163
|
+
|
|
164
|
+
Updates the screen. Only the provided fields are changed.
|
|
158
165
|
|
|
159
166
|
### `pause()`
|
|
160
167
|
|
package/android/CMakeLists.txt
CHANGED
|
@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.9.0)
|
|
|
4
4
|
set(PACKAGE_NAME rngine)
|
|
5
5
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
6
|
set(CMAKE_CXX_STANDARD 20)
|
|
7
|
+
set(UTILS_ROOT ${CMAKE_SOURCE_DIR}/../shared/utils)
|
|
7
8
|
set(SKIA_ROOT ${CMAKE_SOURCE_DIR}/../shared/skia)
|
|
8
9
|
set(SKIA_LIBS_ROOT ${CMAKE_SOURCE_DIR}/../node_modules/react-native-skia-android/libs/${ANDROID_ABI})
|
|
9
10
|
|
|
@@ -40,8 +41,9 @@ add_library(
|
|
|
40
41
|
../shared/GameLoop.cpp
|
|
41
42
|
../shared/GameRenderer.cpp
|
|
42
43
|
../shared/GameMethods.cpp
|
|
43
|
-
../shared/ColorUtils.cpp
|
|
44
|
-
../shared/CollisionUtils.cpp
|
|
44
|
+
../shared/utils/ColorUtils.cpp
|
|
45
|
+
../shared/utils/CollisionUtils.cpp
|
|
46
|
+
../shared/utils/AssetUtils.cpp
|
|
45
47
|
)
|
|
46
48
|
|
|
47
49
|
# Add Nitrogen specs :)
|
|
@@ -51,6 +53,7 @@ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/rngine+autolinking.cma
|
|
|
51
53
|
include_directories(
|
|
52
54
|
"src/main/cpp"
|
|
53
55
|
"../shared"
|
|
56
|
+
"${UTILS_ROOT}"
|
|
54
57
|
"${SKIA_ROOT}"
|
|
55
58
|
)
|
|
56
59
|
|
|
@@ -16,9 +16,9 @@ export const configure = ({
|
|
|
16
16
|
nativeSystems.push({
|
|
17
17
|
entities: system.entities,
|
|
18
18
|
collisions: system.collisions,
|
|
19
|
-
onTick:
|
|
19
|
+
onTick: systemContext => {
|
|
20
20
|
const start = Date.now();
|
|
21
|
-
system.onTick(
|
|
21
|
+
system.onTick(systemContext);
|
|
22
22
|
const finish = Date.now();
|
|
23
23
|
return finish - start;
|
|
24
24
|
}
|
|
@@ -47,13 +47,22 @@ export const spawn = entities => {
|
|
|
47
47
|
gameMethods.spawn(entityArray);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
/** Removes an entity or all entities matching the given id prefix from the world. */
|
|
50
|
+
/** Removes an entity or all entities matching the given id prefix from the world. Only the provided fields are changed. */
|
|
51
51
|
export const despawn = id => gameMethods.despawn(id);
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
export const
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
/** Fires one update, applied to entities matching the given id prefix from the world. Only the provided fields are changed. */
|
|
54
|
+
export const updateEntity = entityUpdate => {
|
|
55
|
+
gameMethods.updateEntities([entityUpdate]);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Fires multiple updates, each applied to entities matching the given id prefix from the world. */
|
|
59
|
+
export const updateEntities = entityUpdates => {
|
|
60
|
+
gameMethods.updateEntities(entityUpdates);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Updates the screen. Only the provided fields are changed. */
|
|
64
|
+
export const updateScreen = screenUpdate => {
|
|
65
|
+
gameMethods.updateScreen(screenUpdate);
|
|
57
66
|
};
|
|
58
67
|
const assetCache = new WeakMap();
|
|
59
68
|
let nextId = -1;
|
|
@@ -89,6 +98,10 @@ const loadAsset = async asset => {
|
|
|
89
98
|
}
|
|
90
99
|
throw new Error(`loadAssets: unsupported asset type "${typeof asset}"`);
|
|
91
100
|
};
|
|
101
|
+
|
|
102
|
+
/** Preloads one or more SVG, PNG or Lottie assets ahead of time.
|
|
103
|
+
* Takes an object mapping names to `require(...)` sources (SVG/PNG) or imported JSON (Lottie),
|
|
104
|
+
* and resolves to an object of the same shape with numeric asset ids. */
|
|
92
105
|
export const loadAssets = async assets => {
|
|
93
106
|
const keys = Object.keys(assets);
|
|
94
107
|
const result = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["gameMethods","Image","configure","world","screen","entities","systems","paused","nativeSystems","system","push","collisions","onTick","
|
|
1
|
+
{"version":3,"names":["gameMethods","Image","configure","world","screen","entities","systems","paused","nativeSystems","system","push","collisions","onTick","systemContext","start","Date","now","finish","setWorld","setScreen","setEntities","setSystems","pause","resume","spawn","entityArray","Array","isArray","despawn","id","updateEntity","entityUpdate","updateEntities","entityUpdates","updateScreen","screenUpdate","assetCache","WeakMap","nextId","loadAsset","asset","Error","has","get","assetId","set","isLottieLoaded","loadLottie","JSON","stringify","isAssetLoaded","assetUri","resolveAssetSource","uri","isLoaded","loadImage","loadAssets","assets","keys","Object","result","key"],"sourceRoot":"../../src","sources":["GameMethods.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,wBAAq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hB,KAAK,QAAQ;MACX,IAAI5C,WAAW,CAACkD,aAAa,CAACV,KAAK,CAAC,EAAE;QACpC,OAAOA,KAAK;MACd;MACA,MAAMW,QAAQ,GAAGlD,KAAK,CAACmD,kBAAkB,CAACZ,KAAK,CAAC,EAAEa,GAAG;MACrD,IAAI,CAACF,QAAQ,EAAE;QACb,MAAM,IAAIV,KAAK,CAAC,+CAA+CD,KAAK,EAAE,CAAC;MACzE;MACA,MAAMc,QAAQ,GAAG,MAAMtD,WAAW,CAACuD,SAAS,CAACf,KAAK,EAAEW,QAAQ,CAAC;MAC7D,IAAI,CAACG,QAAQ,EAAE;QACb,MAAM,IAAIb,KAAK,CAAC,wCAAwC,CAAC;MAC3D;MACA,OAAOD,KAAK;EAChB;EAEA,MAAM,IAAIC,KAAK,CAAC,uCAAuC,OAAOD,KAAK,GAAG,CAAC;AACzE,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMgB,UAAU,GAAG,MACxBC,MAAS,IAC+B;EACxC,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACD,MAAM,CAAgB;EAC/C,MAAMG,MAAM,GAAG,CAAC,CAA+B;EAE/C,KAAK,MAAMC,GAAG,IAAIH,IAAI,EAAE;IACtBE,MAAM,CAACC,GAAG,CAAC,GAAG,MAAMtB,SAAS,CAACkB,MAAM,CAACI,GAAG,CAAC,CAAC;EAC5C;EAEA,OAAOD,MAAM;AACf,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","gameMethods","createHybridObject"],"sourceRoot":"../../src","sources":["GameMethods.nitro.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["NitroModules","gameMethods","createHybridObject"],"sourceRoot":"../../src","sources":["GameMethods.nitro.ts"],"mappings":";;AASA,SAASA,YAAY,QAAQ,4BAA4B;AA8BzD,OAAO,MAAMC,WAAW,GACtBD,YAAY,CAACE,kBAAkB,CAAc,aAAa,CAAC","ignoreList":[]}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GameEngine"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,UAAU,MAAM,iBAAc;AAErC,cAAc,kBAAe;AAC7B,cAAc,YAAS;
|
|
1
|
+
{"version":3,"names":["GameEngine"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,UAAU,MAAM,iBAAc;AAErC,cAAc,kBAAe;AAC7B,cAAc,YAAS;AAUvB,SAASA,UAAU","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entity, EntityUpdate } from './nativeTypes';
|
|
1
|
+
import type { Entity, EntityUpdate, ScreenUpdate } from './nativeTypes';
|
|
2
2
|
import type { Config } from './types';
|
|
3
3
|
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
4
4
|
export declare const configure: ({ world, screen, entities, systems, paused, }: Config) => void;
|
|
@@ -8,9 +8,16 @@ export declare const pause: () => void;
|
|
|
8
8
|
export declare const resume: () => void;
|
|
9
9
|
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
10
10
|
export declare const spawn: (entities: Entity | Entity[]) => void;
|
|
11
|
-
/** Removes an entity or all entities matching the given id prefix from the world. */
|
|
11
|
+
/** Removes an entity or all entities matching the given id prefix from the world. Only the provided fields are changed. */
|
|
12
12
|
export declare const despawn: (id: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
export declare const
|
|
13
|
+
/** Fires one update, applied to entities matching the given id prefix from the world. Only the provided fields are changed. */
|
|
14
|
+
export declare const updateEntity: (entityUpdate: EntityUpdate) => void;
|
|
15
|
+
/** Fires multiple updates, each applied to entities matching the given id prefix from the world. */
|
|
16
|
+
export declare const updateEntities: (entityUpdates: EntityUpdate[]) => void;
|
|
17
|
+
/** Updates the screen. Only the provided fields are changed. */
|
|
18
|
+
export declare const updateScreen: (screenUpdate: ScreenUpdate) => void;
|
|
19
|
+
/** Preloads one or more SVG, PNG or Lottie assets ahead of time.
|
|
20
|
+
* Takes an object mapping names to `require(...)` sources (SVG/PNG) or imported JSON (Lottie),
|
|
21
|
+
* and resolves to an object of the same shape with numeric asset ids. */
|
|
15
22
|
export declare const loadAssets: <T extends Record<string, unknown>>(assets: T) => Promise<{ [K in keyof T]: number; }>;
|
|
16
23
|
//# sourceMappingURL=GameMethods.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameMethods.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAU,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"GameMethods.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAU,MAAM,eAAe,CAAC;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,+CAMvB,MAAM,SAyBR,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,KAAK,YAA4B,CAAC;AAE/C,6BAA6B;AAC7B,eAAO,MAAM,MAAM,YAA6B,CAAC;AAEjD,0EAA0E;AAC1E,eAAO,MAAM,KAAK,GAAI,UAAU,MAAM,GAAG,MAAM,EAAE,SAGhD,CAAC;AAEF,2HAA2H;AAC3H,eAAO,MAAM,OAAO,GAAI,IAAI,MAAM,SAA4B,CAAC;AAE/D,+HAA+H;AAC/H,eAAO,MAAM,YAAY,GAAI,cAAc,YAAY,SAEtD,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,cAAc,GAAI,eAAe,YAAY,EAAE,SAE3D,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,YAAY,GAAI,cAAc,YAAY,SAEtD,CAAC;AA2CF;;yEAEyE;AACzE,eAAO,MAAM,UAAU,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,QAAQ,CAAC,KACR,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAE,CASpC,CAAC"}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
-
import type { Entity, EntityUpdate, System, Screen, World } from './nativeTypes';
|
|
2
|
+
import type { Entity, EntityUpdate, System, Screen, World, ScreenUpdate } from './nativeTypes';
|
|
3
3
|
interface GameMethods extends HybridObject<{
|
|
4
4
|
ios: 'c++';
|
|
5
5
|
android: 'c++';
|
|
6
6
|
}> {
|
|
7
|
+
/** Configuration Methods */
|
|
7
8
|
setWorld(world: World): void;
|
|
8
9
|
setScreen(screen: Screen): void;
|
|
9
10
|
setEntities(entities: Entity[]): void;
|
|
10
11
|
setSystems(systems: System[]): void;
|
|
12
|
+
/** Pause/Resume Methods */
|
|
11
13
|
pause(): void;
|
|
12
14
|
resume(): void;
|
|
15
|
+
/** Entity Update Methods */
|
|
13
16
|
spawn(entities: Entity[]): void;
|
|
14
17
|
despawn(id: string): void;
|
|
15
|
-
|
|
18
|
+
updateEntities(entityUpdates: EntityUpdate[]): void;
|
|
19
|
+
/** Screen Update Methods */
|
|
20
|
+
updateScreen(screenUpdate: ScreenUpdate): void;
|
|
21
|
+
/** Asset Methods */
|
|
16
22
|
isAssetLoaded(id: number): boolean;
|
|
17
23
|
loadLottie(id: number, jsonStr: string): Promise<boolean>;
|
|
18
24
|
loadImage(id: number, imageUri: string): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameMethods.nitro.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,MAAM,EACN,MAA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;CAC3D;AAED,eAAO,MAAM,WAAW,aACqC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import GameEngine from './GameEngine';
|
|
2
2
|
export * from './GameMethods';
|
|
3
3
|
export * from './types';
|
|
4
|
-
export type { World, Screen, Entity, CollisionPair, Collision, EntityUpdate, } from './nativeTypes';
|
|
4
|
+
export type { World, Screen, Entity, CollisionPair, Collision, EntityUpdate, SystemContext, } from './nativeTypes';
|
|
5
5
|
export { GameEngine };
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,KAAK,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,SAAS,EACT,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,KAAK,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,SAAS,EACT,YAAY,EACZ,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -54,7 +54,7 @@ export interface World {
|
|
|
54
54
|
/** Vertical gravitational acceleration in game units per second squared. */
|
|
55
55
|
gy?: number;
|
|
56
56
|
}
|
|
57
|
-
export interface Screen extends Rect, Renderable {
|
|
57
|
+
export interface Screen extends Positioned, Rect, Renderable {
|
|
58
58
|
}
|
|
59
59
|
export interface Entity extends Positioned, Shaped, Renderable, Kinematic {
|
|
60
60
|
/** Unique identifier. Use `_` as a separator for group queries e.g. `'enemy_1'`. */
|
|
@@ -64,6 +64,8 @@ export interface EntityUpdate extends Partial<Positioned & Shaped & Renderable &
|
|
|
64
64
|
/** Unique identifier or prefix of the entities to update. */
|
|
65
65
|
id: string;
|
|
66
66
|
}
|
|
67
|
+
export interface ScreenUpdate extends Partial<Screen> {
|
|
68
|
+
}
|
|
67
69
|
export interface CollisionPair {
|
|
68
70
|
/** Entity id or prefix of the first entity to watch. */
|
|
69
71
|
a: string;
|
|
@@ -82,13 +84,21 @@ export interface Collision {
|
|
|
82
84
|
/** Y component of a normalised vector that represents the direction between the bodies providing the minimum separating distance. */
|
|
83
85
|
ny: number;
|
|
84
86
|
}
|
|
87
|
+
export interface SystemContext {
|
|
88
|
+
/** Current game screen state. */
|
|
89
|
+
screen: Screen;
|
|
90
|
+
/** Entities resolved from the system's entity subscriptions. */
|
|
91
|
+
entities: Entity[];
|
|
92
|
+
/** Collisions matching the system's collision subscriptions. */
|
|
93
|
+
collisions: Collision[];
|
|
94
|
+
}
|
|
85
95
|
export interface System {
|
|
86
96
|
/** Entity ids or prefixes this system subscribes to. */
|
|
87
97
|
entities?: string[];
|
|
88
98
|
/** Collision pairs to watch for every tick. */
|
|
89
99
|
collisions?: CollisionPair[];
|
|
90
100
|
/** Called every tick with the resolved entities and collisions. */
|
|
91
|
-
onTick: (
|
|
101
|
+
onTick: (systemContext: SystemContext) => number;
|
|
92
102
|
}
|
|
93
103
|
export {};
|
|
94
104
|
//# sourceMappingURL=nativeTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeTypes.d.ts","sourceRoot":"","sources":["../../../src/nativeTypes.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,IAAI;IACZ,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;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AAS;IACvE,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO,CAC3C,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAC7C;IACC,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO,CAAC,MAAM,CAAC;CAAG;AAExD,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,CAAC,EAAE,MAAM,CAAC;IACV,yDAAyD;IACzD,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,CAAC,EAAE,MAAM,CAAC;IACV,yDAAyD;IACzD,CAAC,EAAE,MAAM,CAAC;IACV,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,qIAAqI;IACrI,EAAE,EAAE,MAAM,CAAC;IACX,qIAAqI;IACrI,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gEAAgE;IAChE,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,MAAM;IACrB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,mEAAmE;IACnE,MAAM,EAAE,CAAC,aAAa,EAAE,aAAa,KAAK,MAAM,CAAC;CAClD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { System as NativeSystem,
|
|
1
|
+
import type { System as NativeSystem, Screen, Entity, World, SystemContext } from './nativeTypes';
|
|
2
2
|
export type System = Omit<NativeSystem, 'onTick'> & {
|
|
3
3
|
/** Called every tick with the resolved entities and collisions. */
|
|
4
|
-
onTick: (
|
|
4
|
+
onTick: (systemContext: SystemContext) => void;
|
|
5
5
|
};
|
|
6
6
|
export type Config = {
|
|
7
7
|
/** World settings: tick rate and gravity. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,IAAI,YAAY,EACtB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,IAAI,YAAY,EACtB,MAAM,EACN,MAAM,EACN,KAAK,EACL,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;IAClD,mEAAmE;IACnE,MAAM,EAAE,CAAC,aAAa,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,6CAA6C;IAC7C,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,8GAA8G;IAC9G,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,wDAAwD;IACxD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC"}
|
|
@@ -22,7 +22,8 @@ namespace margelo::nitro::rngine {
|
|
|
22
22
|
prototype.registerHybridMethod("resume", &HybridGameMethodsSpec::resume);
|
|
23
23
|
prototype.registerHybridMethod("spawn", &HybridGameMethodsSpec::spawn);
|
|
24
24
|
prototype.registerHybridMethod("despawn", &HybridGameMethodsSpec::despawn);
|
|
25
|
-
prototype.registerHybridMethod("
|
|
25
|
+
prototype.registerHybridMethod("updateEntities", &HybridGameMethodsSpec::updateEntities);
|
|
26
|
+
prototype.registerHybridMethod("updateScreen", &HybridGameMethodsSpec::updateScreen);
|
|
26
27
|
prototype.registerHybridMethod("isAssetLoaded", &HybridGameMethodsSpec::isAssetLoaded);
|
|
27
28
|
prototype.registerHybridMethod("loadLottie", &HybridGameMethodsSpec::loadLottie);
|
|
28
29
|
prototype.registerHybridMethod("loadImage", &HybridGameMethodsSpec::loadImage);
|
|
@@ -23,6 +23,8 @@ namespace margelo::nitro::rngine { struct Entity; }
|
|
|
23
23
|
namespace margelo::nitro::rngine { struct System; }
|
|
24
24
|
// Forward declaration of `EntityUpdate` to properly resolve imports.
|
|
25
25
|
namespace margelo::nitro::rngine { struct EntityUpdate; }
|
|
26
|
+
// Forward declaration of `ScreenUpdate` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::rngine { struct ScreenUpdate; }
|
|
26
28
|
|
|
27
29
|
#include "World.hpp"
|
|
28
30
|
#include "Screen.hpp"
|
|
@@ -31,6 +33,7 @@ namespace margelo::nitro::rngine { struct EntityUpdate; }
|
|
|
31
33
|
#include "System.hpp"
|
|
32
34
|
#include <string>
|
|
33
35
|
#include "EntityUpdate.hpp"
|
|
36
|
+
#include "ScreenUpdate.hpp"
|
|
34
37
|
#include <NitroModules/Promise.hpp>
|
|
35
38
|
|
|
36
39
|
namespace margelo::nitro::rngine {
|
|
@@ -72,7 +75,8 @@ namespace margelo::nitro::rngine {
|
|
|
72
75
|
virtual void resume() = 0;
|
|
73
76
|
virtual void spawn(const std::vector<Entity>& entities) = 0;
|
|
74
77
|
virtual void despawn(const std::string& id) = 0;
|
|
75
|
-
virtual void
|
|
78
|
+
virtual void updateEntities(const std::vector<EntityUpdate>& entityUpdates) = 0;
|
|
79
|
+
virtual void updateScreen(const ScreenUpdate& screenUpdate) = 0;
|
|
76
80
|
virtual bool isAssetLoaded(double id) = 0;
|
|
77
81
|
virtual std::shared_ptr<Promise<bool>> loadLottie(double id, const std::string& jsonStr) = 0;
|
|
78
82
|
virtual std::shared_ptr<Promise<bool>> loadImage(double id, const std::string& imageUri) = 0;
|
|
@@ -40,6 +40,8 @@ namespace margelo::nitro::rngine {
|
|
|
40
40
|
*/
|
|
41
41
|
struct Screen final {
|
|
42
42
|
public:
|
|
43
|
+
double px SWIFT_PRIVATE;
|
|
44
|
+
double py SWIFT_PRIVATE;
|
|
43
45
|
double width SWIFT_PRIVATE;
|
|
44
46
|
double height SWIFT_PRIVATE;
|
|
45
47
|
std::optional<std::string> color SWIFT_PRIVATE;
|
|
@@ -51,7 +53,7 @@ namespace margelo::nitro::rngine {
|
|
|
51
53
|
|
|
52
54
|
public:
|
|
53
55
|
Screen() = default;
|
|
54
|
-
explicit Screen(double width, double height, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<double> progress, std::optional<double> speed): width(width), height(height), color(color), asset(asset), flipH(flipH), flipV(flipV), progress(progress), speed(speed) {}
|
|
56
|
+
explicit Screen(double px, double py, double width, double height, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<double> progress, std::optional<double> speed): px(px), py(py), width(width), height(height), color(color), asset(asset), flipH(flipH), flipV(flipV), progress(progress), speed(speed) {}
|
|
55
57
|
|
|
56
58
|
public:
|
|
57
59
|
friend bool operator==(const Screen& lhs, const Screen& rhs) = default;
|
|
@@ -67,6 +69,8 @@ namespace margelo::nitro {
|
|
|
67
69
|
static inline margelo::nitro::rngine::Screen fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
68
70
|
jsi::Object obj = arg.asObject(runtime);
|
|
69
71
|
return margelo::nitro::rngine::Screen(
|
|
72
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px"))),
|
|
73
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py"))),
|
|
70
74
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
71
75
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
|
|
72
76
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
|
|
@@ -79,6 +83,8 @@ namespace margelo::nitro {
|
|
|
79
83
|
}
|
|
80
84
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::Screen& arg) {
|
|
81
85
|
jsi::Object obj(runtime);
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "px"), JSIConverter<double>::toJSI(runtime, arg.px));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "py"), JSIConverter<double>::toJSI(runtime, arg.py));
|
|
82
88
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
|
|
83
89
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
|
|
84
90
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
|
|
@@ -97,6 +103,8 @@ namespace margelo::nitro {
|
|
|
97
103
|
if (!nitro::isPlainObject(runtime, obj)) {
|
|
98
104
|
return false;
|
|
99
105
|
}
|
|
106
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px")))) return false;
|
|
107
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py")))) return false;
|
|
100
108
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
|
|
101
109
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
|
|
102
110
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ScreenUpdate.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <optional>
|
|
34
|
+
#include <string>
|
|
35
|
+
|
|
36
|
+
namespace margelo::nitro::rngine {
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A struct which can be represented as a JavaScript object (ScreenUpdate).
|
|
40
|
+
*/
|
|
41
|
+
struct ScreenUpdate final {
|
|
42
|
+
public:
|
|
43
|
+
std::optional<double> px SWIFT_PRIVATE;
|
|
44
|
+
std::optional<double> py SWIFT_PRIVATE;
|
|
45
|
+
std::optional<double> width SWIFT_PRIVATE;
|
|
46
|
+
std::optional<double> height SWIFT_PRIVATE;
|
|
47
|
+
std::optional<std::string> color SWIFT_PRIVATE;
|
|
48
|
+
std::optional<double> asset SWIFT_PRIVATE;
|
|
49
|
+
std::optional<bool> flipH SWIFT_PRIVATE;
|
|
50
|
+
std::optional<bool> flipV SWIFT_PRIVATE;
|
|
51
|
+
std::optional<double> progress SWIFT_PRIVATE;
|
|
52
|
+
std::optional<double> speed SWIFT_PRIVATE;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
ScreenUpdate() = default;
|
|
56
|
+
explicit ScreenUpdate(std::optional<double> px, std::optional<double> py, std::optional<double> width, std::optional<double> height, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<double> progress, std::optional<double> speed): px(px), py(py), width(width), height(height), color(color), asset(asset), flipH(flipH), flipV(flipV), progress(progress), speed(speed) {}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
friend bool operator==(const ScreenUpdate& lhs, const ScreenUpdate& rhs) = default;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::rngine
|
|
63
|
+
|
|
64
|
+
namespace margelo::nitro {
|
|
65
|
+
|
|
66
|
+
// C++ ScreenUpdate <> JS ScreenUpdate (object)
|
|
67
|
+
template <>
|
|
68
|
+
struct JSIConverter<margelo::nitro::rngine::ScreenUpdate> final {
|
|
69
|
+
static inline margelo::nitro::rngine::ScreenUpdate fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
70
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
71
|
+
return margelo::nitro::rngine::ScreenUpdate(
|
|
72
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px"))),
|
|
73
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py"))),
|
|
74
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
75
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
|
|
76
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
|
|
77
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
|
|
78
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH"))),
|
|
79
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV"))),
|
|
80
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
|
|
81
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::ScreenUpdate& arg) {
|
|
85
|
+
jsi::Object obj(runtime);
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "px"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.px));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "py"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.py));
|
|
88
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.width));
|
|
89
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.height));
|
|
90
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
|
|
91
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "asset"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.asset));
|
|
92
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipH"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipH));
|
|
93
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipV"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipV));
|
|
94
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
|
|
95
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.speed));
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
99
|
+
if (!value.isObject()) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
jsi::Object obj = value.getObject(runtime);
|
|
103
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px")))) return false;
|
|
107
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py")))) return false;
|
|
108
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
|
|
109
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
|
|
110
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
|
|
111
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset")))) return false;
|
|
112
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH")))) return false;
|
|
113
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV")))) return false;
|
|
114
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
|
|
115
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
} // namespace margelo::nitro
|