rngine 0.4.1 → 0.5.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 +1 -1
- package/android/build.gradle +5 -1
- package/android/src/main/java/com/margelo/nitro/rngine/GameAssets.kt +24 -20
- package/lib/module/GameAssets.js +41 -0
- package/lib/module/GameAssets.js.map +1 -0
- package/lib/module/GameEngine.js +1 -1
- package/lib/module/GameEngine.js.map +1 -1
- package/lib/module/GameMethods.js +43 -0
- package/lib/module/GameMethods.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/GameAssets.d.ts +2 -0
- package/lib/typescript/src/GameAssets.d.ts.map +1 -0
- package/lib/typescript/src/GameAssets.nitro.d.ts +2 -2
- package/lib/typescript/src/GameAssets.nitro.d.ts.map +1 -1
- package/lib/typescript/src/GameMethods.d.ts +8 -0
- package/lib/typescript/src/GameMethods.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/nativeTypes.d.ts +1 -1
- package/lib/typescript/src/nativeTypes.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +4 -13
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridGameAssetsSpec.cpp +31 -6
- package/nitrogen/generated/android/c++/JHybridGameAssetsSpec.hpp +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/HybridGameAssetsSpec.kt +3 -2
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.cpp +16 -0
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.hpp +65 -6
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Umbrella.hpp +1 -0
- package/nitrogen/generated/ios/c++/HybridGameAssetsSpecSwift.hpp +7 -2
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridGameAssetsSpec.swift +2 -2
- package/nitrogen/generated/ios/swift/HybridGameAssetsSpec_cxx.swift +24 -8
- package/nitrogen/generated/shared/c++/HybridGameAssetsSpec.hpp +3 -2
- package/nitrogen/generated/shared/c++/System.hpp +6 -5
- package/package.json +1 -1
- package/shared/GameLoop.cpp +45 -21
- package/shared/GameLoop.hpp +9 -0
- package/shared/GameMethods.cpp +8 -1
- package/src/GameAssets.nitro.ts +2 -2
- package/src/GameAssets.ts +47 -0
- package/src/GameEngine.tsx +1 -1
- package/src/GameMethods.ts +48 -0
- package/src/index.tsx +8 -2
- package/src/nativeTypes.ts +1 -1
- package/src/types.ts +7 -17
- package/lib/module/Shared.js +0 -72
- package/lib/module/Shared.js.map +0 -1
- package/lib/typescript/src/Shared.d.ts +0 -8
- package/lib/typescript/src/Shared.d.ts.map +0 -1
- package/src/Shared.ts +0 -83
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ export default function App() {
|
|
|
72
72
|
|
|
73
73
|
**Entities** are the objects in your game world. Each entity has a position, size, color, and velocity. See [`Entity`](./src/nativeTypes.ts).
|
|
74
74
|
|
|
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/
|
|
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
77
|
**Screen** defines the viewport dimensions and background color. Entities outside the screen bounds are automatically clipped. See [`Screen`](./src/nativeTypes.ts).
|
|
78
78
|
|
package/android/build.gradle
CHANGED
|
@@ -35,7 +35,11 @@ apply plugin: "com.android.library"
|
|
|
35
35
|
apply plugin: "kotlin-android"
|
|
36
36
|
apply from: '../nitrogen/generated/android/rngine+autolinking.gradle'
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if (rootProject.name != "rngine.example") {
|
|
39
|
+
apply plugin: "com.facebook.react"
|
|
40
|
+
} else {
|
|
41
|
+
println("\u001B[33m⚠️ Skipping React Native Gradle plugin in library (example build detected)\u001B[0m")
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
android {
|
|
41
45
|
namespace "com.margelo.nitro.rngine"
|
|
@@ -4,6 +4,7 @@ import android.util.Log
|
|
|
4
4
|
import com.airbnb.lottie.LottieCompositionFactory
|
|
5
5
|
import com.airbnb.lottie.LottieDrawable
|
|
6
6
|
import com.caverock.androidsvg.SVG
|
|
7
|
+
import com.margelo.nitro.core.Promise
|
|
7
8
|
import java.net.URL
|
|
8
9
|
|
|
9
10
|
class GameAssets : HybridGameAssetsSpec() {
|
|
@@ -18,30 +19,33 @@ class GameAssets : HybridGameAssetsSpec() {
|
|
|
18
19
|
return id.toInt() in assetCache
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
override fun registerSvg(id: Double, uri: String) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
override fun registerSvg(id: Double, uri: String): Promise<Unit> {
|
|
23
|
+
return Promise.async {
|
|
24
|
+
try {
|
|
25
|
+
val stream = URL(uri).openStream()
|
|
26
|
+
assetCache[id.toInt()] = Asset.Svg(SVG.getFromInputStream(stream).renderToPicture())
|
|
27
|
+
Log.d("GameAssets", "assetCache: $assetCache")
|
|
28
|
+
} catch (e: Exception) {
|
|
29
|
+
Log.e("GameAssets", "Failed to parse SVG: $uri", e)
|
|
30
|
+
throw e
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
override fun registerLottie(id: Double, json: String) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
override fun registerLottie(id: Double, json: String): Promise<Unit> {
|
|
36
|
+
return Promise.async {
|
|
37
|
+
try {
|
|
38
|
+
val composition = LottieCompositionFactory.fromJsonStringSync(json, null).value
|
|
39
|
+
?: throw IllegalStateException("Failed to parse Lottie JSON for id: $id")
|
|
40
|
+
val drawable = LottieDrawable()
|
|
41
|
+
drawable.composition = composition
|
|
42
|
+
assetCache[id.toInt()] = Asset.Lottie(drawable)
|
|
43
|
+
registerLottieDuration(id, composition.duration.toDouble() / 1000)
|
|
44
|
+
Log.d("GameAssets", "assetCache: $assetCache")
|
|
45
|
+
} catch (e: Exception) {
|
|
46
|
+
Log.e("GameAssets", "Failed to register Lottie: $id", e)
|
|
47
|
+
throw e
|
|
37
48
|
}
|
|
38
|
-
val drawable = LottieDrawable()
|
|
39
|
-
drawable.composition = composition
|
|
40
|
-
assetCache[id.toInt()] = Asset.Lottie(drawable)
|
|
41
|
-
registerLottieDuration(id, composition.duration.toDouble() / 1000)
|
|
42
|
-
Log.d("GameAssets", "assetCache: $assetCache")
|
|
43
|
-
} catch (e: Exception) {
|
|
44
|
-
Log.e("GameAssets", "Failed to register Lottie: $id", e)
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Image } from 'react-native';
|
|
4
|
+
import { gameAssets } from "./GameAssets.nitro.js";
|
|
5
|
+
const assetCache = new WeakMap();
|
|
6
|
+
let nextId = -1;
|
|
7
|
+
const loadAsset = async asset => {
|
|
8
|
+
switch (typeof asset) {
|
|
9
|
+
case 'object':
|
|
10
|
+
if (asset === null) {
|
|
11
|
+
throw new Error('loadAssets: asset cannot be null');
|
|
12
|
+
}
|
|
13
|
+
if (assetCache.has(asset)) {
|
|
14
|
+
return assetCache.get(asset);
|
|
15
|
+
}
|
|
16
|
+
const assetId = nextId--;
|
|
17
|
+
assetCache.set(asset, assetId);
|
|
18
|
+
await gameAssets.registerLottie(assetId, JSON.stringify(asset));
|
|
19
|
+
return assetId;
|
|
20
|
+
case 'number':
|
|
21
|
+
if (gameAssets.isAssetRegistered(asset)) {
|
|
22
|
+
return asset;
|
|
23
|
+
}
|
|
24
|
+
const assetUri = Image.resolveAssetSource(asset)?.uri;
|
|
25
|
+
if (!assetUri) {
|
|
26
|
+
throw new Error(`loadAssets: could not resolve asset URI for ${asset}`);
|
|
27
|
+
}
|
|
28
|
+
await gameAssets.registerSvg(asset, assetUri);
|
|
29
|
+
return asset;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`loadAssets: unsupported asset type "${typeof asset}"`);
|
|
32
|
+
};
|
|
33
|
+
export const loadAssets = async assets => {
|
|
34
|
+
const keys = Object.keys(assets);
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
result[key] = await loadAsset(assets[key]);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=GameAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Image","gameAssets","assetCache","WeakMap","nextId","loadAsset","asset","Error","has","get","assetId","set","registerLottie","JSON","stringify","isAssetRegistered","assetUri","resolveAssetSource","uri","registerSvg","loadAssets","assets","keys","Object","result","key"],"sourceRoot":"../../src","sources":["GameAssets.ts"],"mappings":";;AAAA,SAASA,KAAK,QAAQ,cAAc;AACpC,SAASC,UAAU,QAAQ,uBAAoB;AAE/C,MAAMC,UAAU,GAAG,IAAIC,OAAO,CAAiB,CAAC;AAChD,IAAIC,MAAM,GAAG,CAAC,CAAC;AAEf,MAAMC,SAAS,GAAG,MAAOC,KAAc,IAAK;EAC1C,QAAQ,OAAOA,KAAK;IAClB,KAAK,QAAQ;MACX,IAAIA,KAAK,KAAK,IAAI,EAAE;QAClB,MAAM,IAAIC,KAAK,CAAC,kCAAkC,CAAC;MACrD;MACA,IAAIL,UAAU,CAACM,GAAG,CAACF,KAAK,CAAC,EAAE;QACzB,OAAOJ,UAAU,CAACO,GAAG,CAACH,KAAK,CAAC;MAC9B;MACA,MAAMI,OAAO,GAAGN,MAAM,EAAE;MACxBF,UAAU,CAACS,GAAG,CAACL,KAAK,EAAEI,OAAO,CAAC;MAC9B,MAAMT,UAAU,CAACW,cAAc,CAACF,OAAO,EAAEG,IAAI,CAACC,SAAS,CAACR,KAAK,CAAC,CAAC;MAC/D,OAAOI,OAAO;IAEhB,KAAK,QAAQ;MACX,IAAIT,UAAU,CAACc,iBAAiB,CAACT,KAAK,CAAC,EAAE;QACvC,OAAOA,KAAK;MACd;MACA,MAAMU,QAAQ,GAAGhB,KAAK,CAACiB,kBAAkB,CAACX,KAAK,CAAC,EAAEY,GAAG;MACrD,IAAI,CAACF,QAAQ,EAAE;QACb,MAAM,IAAIT,KAAK,CAAC,+CAA+CD,KAAK,EAAE,CAAC;MACzE;MACA,MAAML,UAAU,CAACkB,WAAW,CAACb,KAAK,EAAEU,QAAQ,CAAC;MAC7C,OAAOV,KAAK;EAChB;EAEA,MAAM,IAAIC,KAAK,CAAC,uCAAuC,OAAOD,KAAK,GAAG,CAAC;AACzE,CAAC;AAED,OAAO,MAAMc,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,MAAMpB,SAAS,CAACgB,MAAM,CAACI,GAAG,CAAC,CAAC;EAC5C;EAEA,OAAOD,MAAM;AACf,CAAC","ignoreList":[]}
|
package/lib/module/GameEngine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { getHostComponent } from 'react-native-nitro-modules';
|
|
4
|
-
|
|
4
|
+
import GameEngineConfig from '../nitrogen/generated/shared/json/GameEngineConfig.json';
|
|
5
5
|
/**
|
|
6
6
|
* A game engine view component that renders the game world.
|
|
7
7
|
* Size it using the style prop like any other React Native view.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getHostComponent","GameEngineConfig"
|
|
1
|
+
{"version":3,"names":["getHostComponent","GameEngineConfig"],"sourceRoot":"../../src","sources":["GameEngine.tsx"],"mappings":";;AAAA,SAASA,gBAAgB,QAAQ,4BAA4B;AAC7D,OAAOC,gBAAgB,MAAM,yDAAyD;AAGtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeD,gBAAgB,CAC7B,YAAY,EACZ,MAAMC,gBACR,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { gameMethods } from "./GameMethods.nitro.js";
|
|
4
|
+
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
5
|
+
export const configure = ({
|
|
6
|
+
tickRate,
|
|
7
|
+
screen,
|
|
8
|
+
entities = [],
|
|
9
|
+
systems = [],
|
|
10
|
+
paused = true
|
|
11
|
+
}) => {
|
|
12
|
+
let nativeSystems = [];
|
|
13
|
+
for (const system of systems) {
|
|
14
|
+
nativeSystems.push({
|
|
15
|
+
entities: system.entities,
|
|
16
|
+
collisions: system.collisions,
|
|
17
|
+
onTick: (e, c) => {
|
|
18
|
+
const start = Date.now();
|
|
19
|
+
system.onTick(e, c);
|
|
20
|
+
const finish = Date.now();
|
|
21
|
+
return finish - start;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
gameMethods.setTickRate(tickRate);
|
|
26
|
+
gameMethods.setScreen(screen);
|
|
27
|
+
gameMethods.setEntities(entities);
|
|
28
|
+
gameMethods.setSystems(nativeSystems);
|
|
29
|
+
if (paused) {
|
|
30
|
+
gameMethods.pause();
|
|
31
|
+
} else {
|
|
32
|
+
gameMethods.resume();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
4
35
|
|
|
5
36
|
/** Pauses the game loop. Systems will stop running. */
|
|
6
37
|
export const pause = () => gameMethods.pause();
|
|
@@ -8,6 +39,18 @@ export const pause = () => gameMethods.pause();
|
|
|
8
39
|
/** Resumes the game loop. */
|
|
9
40
|
export const resume = () => gameMethods.resume();
|
|
10
41
|
|
|
42
|
+
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
43
|
+
export const spawn = entities => {
|
|
44
|
+
const entityArray = Array.isArray(entities) ? entities : [entities];
|
|
45
|
+
gameMethods.spawn(entityArray);
|
|
46
|
+
};
|
|
47
|
+
|
|
11
48
|
/** Removes an entity or all entities matching the given id prefix from the world. */
|
|
12
49
|
export const despawn = id => gameMethods.despawn(id);
|
|
50
|
+
|
|
51
|
+
/** Updates one or more entities. Only the provided fields are changed. */
|
|
52
|
+
export const update = updates => {
|
|
53
|
+
const entityUpdateArray = Array.isArray(updates) ? updates : [updates];
|
|
54
|
+
gameMethods.update(entityUpdateArray);
|
|
55
|
+
};
|
|
13
56
|
//# sourceMappingURL=GameMethods.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["gameMethods","pause","resume","despawn","id"],"sourceRoot":"../../src","sources":["GameMethods.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,wBAAqB
|
|
1
|
+
{"version":3,"names":["gameMethods","configure","tickRate","screen","entities","systems","paused","nativeSystems","system","push","collisions","onTick","e","c","start","Date","now","finish","setTickRate","setScreen","setEntities","setSystems","pause","resume","spawn","entityArray","Array","isArray","despawn","id","update","updates","entityUpdateArray"],"sourceRoot":"../../src","sources":["GameMethods.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,wBAAqB;AAIjD;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAC;EACxBC,QAAQ;EACRC,MAAM;EACNC,QAAQ,GAAG,EAAE;EACbC,OAAO,GAAG,EAAE;EACZC,MAAM,GAAG;AACH,CAAC,KAAK;EACZ,IAAIC,aAAuB,GAAG,EAAE;EAEhC,KAAK,MAAMC,MAAM,IAAIH,OAAO,EAAE;IAC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AAsC,IAAK;EAChE,MAAMC,iBAAiB,GAAGN,KAAK,CAACC,OAAO,CAACI,OAAO,CAAC,GAAGA,OAAO,GAAG,CAACA,OAAO,CAAC;EACtE/B,WAAW,CAAC8B,MAAM,CAACE,iBAAiB,CAAC;AACvC,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
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,
|
|
1
|
+
{"version":3,"names":["GameEngine"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,UAAU,MAAM,iBAAc;AAErC,cAAc,kBAAe;AAC7B,cAAc,iBAAc;AAC5B,cAAc,YAAS;AAQvB,SAASA,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GameAssets.d.ts","sourceRoot":"","sources":["../../../src/GameAssets.ts"],"names":[],"mappings":"AAmCA,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"}
|
|
@@ -4,8 +4,8 @@ interface GameAssets extends HybridObject<{
|
|
|
4
4
|
android: 'kotlin';
|
|
5
5
|
}> {
|
|
6
6
|
isAssetRegistered(id: number): boolean;
|
|
7
|
-
registerSvg(id: number, uri: string): void
|
|
8
|
-
registerLottie(id: number, json: string): void
|
|
7
|
+
registerSvg(id: number, uri: string): Promise<void>;
|
|
8
|
+
registerLottie(id: number, json: string): Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
export declare const gameAssets: GameAssets;
|
|
11
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameAssets.nitro.d.ts","sourceRoot":"","sources":["../../../src/GameAssets.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,UAAU,UAAW,SAAQ,YAAY,CAAC;IACxC,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACvC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"GameAssets.nitro.d.ts","sourceRoot":"","sources":["../../../src/GameAssets.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,UAAU,UAAW,SAAQ,YAAY,CAAC;IACxC,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACvC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED,eAAO,MAAM,UAAU,YACoC,CAAC"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import type { Entity, EntityUpdate } from './nativeTypes';
|
|
2
|
+
import type { Config } from './types';
|
|
3
|
+
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
4
|
+
export declare const configure: ({ tickRate, screen, entities, systems, paused, }: Config) => void;
|
|
1
5
|
/** Pauses the game loop. Systems will stop running. */
|
|
2
6
|
export declare const pause: () => void;
|
|
3
7
|
/** Resumes the game loop. */
|
|
4
8
|
export declare const resume: () => void;
|
|
9
|
+
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
10
|
+
export declare const spawn: (entities: Entity | Entity[]) => void;
|
|
5
11
|
/** Removes an entity or all entities matching the given id prefix from the world. */
|
|
6
12
|
export declare const despawn: (id: string) => void;
|
|
13
|
+
/** Updates one or more entities. Only the provided fields are changed. */
|
|
14
|
+
export declare const update: (updates: EntityUpdate | EntityUpdate[]) => void;
|
|
7
15
|
//# sourceMappingURL=GameMethods.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameMethods.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.ts"],"names":[],"mappings":"
|
|
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;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,kDAMvB,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,qFAAqF;AACrF,eAAO,MAAM,OAAO,GAAI,IAAI,MAAM,SAA4B,CAAC;AAE/D,0EAA0E;AAC1E,eAAO,MAAM,MAAM,GAAI,SAAS,YAAY,GAAG,YAAY,EAAE,SAG5D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import GameEngine from './GameEngine';
|
|
2
2
|
export * from './GameMethods';
|
|
3
|
-
export * from './
|
|
4
|
-
export type { System } from './nativeTypes';
|
|
3
|
+
export * from './GameAssets';
|
|
5
4
|
export * from './types';
|
|
5
|
+
export type { Screen, Entity, CollisionPair, Collision, EntityUpdate, } from './nativeTypes';
|
|
6
6
|
export { GameEngine };
|
|
7
7
|
//# 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,
|
|
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,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,MAAM,EACN,MAAM,EACN,aAAa,EACb,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -52,7 +52,7 @@ export type System = {
|
|
|
52
52
|
/** Collision pairs to watch for every tick. */
|
|
53
53
|
collisions?: CollisionPair[];
|
|
54
54
|
/** Called every tick with the resolved entities and collisions. */
|
|
55
|
-
onTick: (entities: Entity[], collisions: Collision[]) =>
|
|
55
|
+
onTick: (entities: Entity[], collisions: Collision[]) => number;
|
|
56
56
|
};
|
|
57
57
|
export type EntityUpdate = {
|
|
58
58
|
/** Unique identifier or prefix of the entities to update. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeTypes.d.ts","sourceRoot":"","sources":["../../../src/nativeTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IAC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AAmE;IACnE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,MAAM,CAAC;CACjE,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
asset?: Asset;
|
|
6
|
-
};
|
|
7
|
-
export type Entity = Omit<NativeEntity, 'asset'> & {
|
|
8
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
9
|
-
asset?: Asset;
|
|
10
|
-
};
|
|
11
|
-
export type EntityUpdate = Omit<NativeEntityUpdate, 'asset'> & {
|
|
12
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
13
|
-
asset?: Asset;
|
|
1
|
+
import type { System as NativeSystem, Collision, Screen, Entity } from './nativeTypes';
|
|
2
|
+
export type System = Omit<NativeSystem, 'onTick'> & {
|
|
3
|
+
/** Called every tick with the resolved entities and collisions. */
|
|
4
|
+
onTick: (entities: Entity[], collisions: Collision[]) => void;
|
|
14
5
|
};
|
|
15
6
|
export type Config = {
|
|
16
7
|
/** Number of game logic updates per second. */
|
|
@@ -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,SAAS,EACT,MAAM,EACN,MAAM,EACP,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;IAClD,mEAAmE;IACnE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC"}
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
#include <NitroModules/Promise.hpp>
|
|
13
|
+
#include <NitroModules/JPromise.hpp>
|
|
14
|
+
#include <NitroModules/JUnit.hpp>
|
|
12
15
|
#include <string>
|
|
13
16
|
|
|
14
17
|
namespace margelo::nitro::rngine {
|
|
@@ -49,13 +52,35 @@ namespace margelo::nitro::rngine {
|
|
|
49
52
|
auto __result = method(_javaPart, id);
|
|
50
53
|
return static_cast<bool>(__result);
|
|
51
54
|
}
|
|
52
|
-
void JHybridGameAssetsSpec::registerSvg(double id, const std::string& uri) {
|
|
53
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<
|
|
54
|
-
method(_javaPart, id, jni::make_jstring(uri));
|
|
55
|
+
std::shared_ptr<Promise<void>> JHybridGameAssetsSpec::registerSvg(double id, const std::string& uri) {
|
|
56
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(double /* id */, jni::alias_ref<jni::JString> /* uri */)>("registerSvg");
|
|
57
|
+
auto __result = method(_javaPart, id, jni::make_jstring(uri));
|
|
58
|
+
return [&]() {
|
|
59
|
+
auto __promise = Promise<void>::create();
|
|
60
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
61
|
+
__promise->resolve();
|
|
62
|
+
});
|
|
63
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
64
|
+
jni::JniException __jniError(__throwable);
|
|
65
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
66
|
+
});
|
|
67
|
+
return __promise;
|
|
68
|
+
}();
|
|
55
69
|
}
|
|
56
|
-
void JHybridGameAssetsSpec::registerLottie(double id, const std::string& json) {
|
|
57
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<
|
|
58
|
-
method(_javaPart, id, jni::make_jstring(json));
|
|
70
|
+
std::shared_ptr<Promise<void>> JHybridGameAssetsSpec::registerLottie(double id, const std::string& json) {
|
|
71
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(double /* id */, jni::alias_ref<jni::JString> /* json */)>("registerLottie");
|
|
72
|
+
auto __result = method(_javaPart, id, jni::make_jstring(json));
|
|
73
|
+
return [&]() {
|
|
74
|
+
auto __promise = Promise<void>::create();
|
|
75
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
76
|
+
__promise->resolve();
|
|
77
|
+
});
|
|
78
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
79
|
+
jni::JniException __jniError(__throwable);
|
|
80
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
81
|
+
});
|
|
82
|
+
return __promise;
|
|
83
|
+
}();
|
|
59
84
|
}
|
|
60
85
|
|
|
61
86
|
} // namespace margelo::nitro::rngine
|
|
@@ -55,8 +55,8 @@ namespace margelo::nitro::rngine {
|
|
|
55
55
|
public:
|
|
56
56
|
// Methods
|
|
57
57
|
bool isAssetRegistered(double id) override;
|
|
58
|
-
void registerSvg(double id, const std::string& uri) override;
|
|
59
|
-
void registerLottie(double id, const std::string& json) override;
|
|
58
|
+
std::shared_ptr<Promise<void>> registerSvg(double id, const std::string& uri) override;
|
|
59
|
+
std::shared_ptr<Promise<void>> registerLottie(double id, const std::string& json) override;
|
|
60
60
|
|
|
61
61
|
private:
|
|
62
62
|
jni::global_ref<JHybridGameAssetsSpec::JavaPart> _javaPart;
|
|
@@ -10,6 +10,7 @@ package com.margelo.nitro.rngine
|
|
|
10
10
|
import androidx.annotation.Keep
|
|
11
11
|
import com.facebook.jni.HybridData
|
|
12
12
|
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
13
14
|
import com.margelo.nitro.core.HybridObject
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -34,11 +35,11 @@ abstract class HybridGameAssetsSpec: HybridObject() {
|
|
|
34
35
|
|
|
35
36
|
@DoNotStrip
|
|
36
37
|
@Keep
|
|
37
|
-
abstract fun registerSvg(id: Double, uri: String): Unit
|
|
38
|
+
abstract fun registerSvg(id: Double, uri: String): Promise<Unit>
|
|
38
39
|
|
|
39
40
|
@DoNotStrip
|
|
40
41
|
@Keep
|
|
41
|
-
abstract fun registerLottie(id: Double, json: String): Unit
|
|
42
|
+
abstract fun registerLottie(id: Double, json: String): Promise<Unit>
|
|
42
43
|
|
|
43
44
|
// Default implementation of `HybridObject.toString()`
|
|
44
45
|
override fun toString(): String {
|
|
@@ -15,6 +15,22 @@
|
|
|
15
15
|
|
|
16
16
|
namespace margelo::nitro::rngine::bridge::swift {
|
|
17
17
|
|
|
18
|
+
// pragma MARK: std::function<void()>
|
|
19
|
+
Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
20
|
+
auto swiftClosure = Rngine::Func_void::fromUnsafe(swiftClosureWrapper);
|
|
21
|
+
return [swiftClosure = std::move(swiftClosure)]() mutable -> void {
|
|
22
|
+
swiftClosure.call();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
|
|
27
|
+
Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
28
|
+
auto swiftClosure = Rngine::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
|
|
29
|
+
return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void {
|
|
30
|
+
swiftClosure.call(error);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
18
34
|
// pragma MARK: std::shared_ptr<HybridGameAssetsSpec>
|
|
19
35
|
std::shared_ptr<HybridGameAssetsSpec> create_std__shared_ptr_HybridGameAssetsSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
20
36
|
Rngine::HybridGameAssetsSpec_cxx swiftPart = Rngine::HybridGameAssetsSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
@@ -22,8 +22,11 @@ namespace Rngine { class HybridGameEngineSpec_cxx; }
|
|
|
22
22
|
// Include C++ defined types
|
|
23
23
|
#include "HybridGameAssetsSpec.hpp"
|
|
24
24
|
#include "HybridGameEngineSpec.hpp"
|
|
25
|
+
#include <NitroModules/Promise.hpp>
|
|
26
|
+
#include <NitroModules/PromiseHolder.hpp>
|
|
25
27
|
#include <NitroModules/Result.hpp>
|
|
26
28
|
#include <exception>
|
|
29
|
+
#include <functional>
|
|
27
30
|
#include <memory>
|
|
28
31
|
|
|
29
32
|
/**
|
|
@@ -32,6 +35,62 @@ namespace Rngine { class HybridGameEngineSpec_cxx; }
|
|
|
32
35
|
*/
|
|
33
36
|
namespace margelo::nitro::rngine::bridge::swift {
|
|
34
37
|
|
|
38
|
+
// pragma MARK: std::shared_ptr<Promise<void>>
|
|
39
|
+
/**
|
|
40
|
+
* Specialized version of `std::shared_ptr<Promise<void>>`.
|
|
41
|
+
*/
|
|
42
|
+
using std__shared_ptr_Promise_void__ = std::shared_ptr<Promise<void>>;
|
|
43
|
+
inline std::shared_ptr<Promise<void>> create_std__shared_ptr_Promise_void__() noexcept {
|
|
44
|
+
return Promise<void>::create();
|
|
45
|
+
}
|
|
46
|
+
inline PromiseHolder<void> wrap_std__shared_ptr_Promise_void__(std::shared_ptr<Promise<void>> promise) noexcept {
|
|
47
|
+
return PromiseHolder<void>(std::move(promise));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// pragma MARK: std::function<void()>
|
|
51
|
+
/**
|
|
52
|
+
* Specialized version of `std::function<void()>`.
|
|
53
|
+
*/
|
|
54
|
+
using Func_void = std::function<void()>;
|
|
55
|
+
/**
|
|
56
|
+
* Wrapper class for a `std::function<void()>`, this can be used from Swift.
|
|
57
|
+
*/
|
|
58
|
+
class Func_void_Wrapper final {
|
|
59
|
+
public:
|
|
60
|
+
explicit Func_void_Wrapper(std::function<void()>&& func): _function(std::make_unique<std::function<void()>>(std::move(func))) {}
|
|
61
|
+
inline void call() const noexcept {
|
|
62
|
+
_function->operator()();
|
|
63
|
+
}
|
|
64
|
+
private:
|
|
65
|
+
std::unique_ptr<std::function<void()>> _function;
|
|
66
|
+
} SWIFT_NONCOPYABLE;
|
|
67
|
+
Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
68
|
+
inline Func_void_Wrapper wrap_Func_void(Func_void value) noexcept {
|
|
69
|
+
return Func_void_Wrapper(std::move(value));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
|
|
73
|
+
/**
|
|
74
|
+
* Specialized version of `std::function<void(const std::exception_ptr&)>`.
|
|
75
|
+
*/
|
|
76
|
+
using Func_void_std__exception_ptr = std::function<void(const std::exception_ptr& /* error */)>;
|
|
77
|
+
/**
|
|
78
|
+
* Wrapper class for a `std::function<void(const std::exception_ptr& / * error * /)>`, this can be used from Swift.
|
|
79
|
+
*/
|
|
80
|
+
class Func_void_std__exception_ptr_Wrapper final {
|
|
81
|
+
public:
|
|
82
|
+
explicit Func_void_std__exception_ptr_Wrapper(std::function<void(const std::exception_ptr& /* error */)>&& func): _function(std::make_unique<std::function<void(const std::exception_ptr& /* error */)>>(std::move(func))) {}
|
|
83
|
+
inline void call(std::exception_ptr error) const noexcept {
|
|
84
|
+
_function->operator()(error);
|
|
85
|
+
}
|
|
86
|
+
private:
|
|
87
|
+
std::unique_ptr<std::function<void(const std::exception_ptr& /* error */)>> _function;
|
|
88
|
+
} SWIFT_NONCOPYABLE;
|
|
89
|
+
Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
90
|
+
inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) noexcept {
|
|
91
|
+
return Func_void_std__exception_ptr_Wrapper(std::move(value));
|
|
92
|
+
}
|
|
93
|
+
|
|
35
94
|
// pragma MARK: std::shared_ptr<HybridGameAssetsSpec>
|
|
36
95
|
/**
|
|
37
96
|
* Specialized version of `std::shared_ptr<HybridGameAssetsSpec>`.
|
|
@@ -53,13 +112,13 @@ namespace margelo::nitro::rngine::bridge::swift {
|
|
|
53
112
|
return Result<bool>::withError(error);
|
|
54
113
|
}
|
|
55
114
|
|
|
56
|
-
// pragma MARK: Result<void
|
|
57
|
-
using
|
|
58
|
-
inline
|
|
59
|
-
return Result<void
|
|
115
|
+
// pragma MARK: Result<std::shared_ptr<Promise<void>>>
|
|
116
|
+
using Result_std__shared_ptr_Promise_void___ = Result<std::shared_ptr<Promise<void>>>;
|
|
117
|
+
inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::shared_ptr<Promise<void>>& value) noexcept {
|
|
118
|
+
return Result<std::shared_ptr<Promise<void>>>::withValue(value);
|
|
60
119
|
}
|
|
61
|
-
inline
|
|
62
|
-
return Result<void
|
|
120
|
+
inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::exception_ptr& error) noexcept {
|
|
121
|
+
return Result<std::shared_ptr<Promise<void>>>::withError(error);
|
|
63
122
|
}
|
|
64
123
|
|
|
65
124
|
// pragma MARK: std::shared_ptr<HybridGameEngineSpec>
|
|
@@ -16,6 +16,7 @@ namespace margelo::nitro::rngine { class HybridGameEngineSpec; }
|
|
|
16
16
|
// Include C++ defined types
|
|
17
17
|
#include "HybridGameAssetsSpec.hpp"
|
|
18
18
|
#include "HybridGameEngineSpec.hpp"
|
|
19
|
+
#include <NitroModules/Promise.hpp>
|
|
19
20
|
#include <NitroModules/Result.hpp>
|
|
20
21
|
#include <exception>
|
|
21
22
|
#include <memory>
|
|
@@ -14,6 +14,7 @@ namespace Rngine { class HybridGameAssetsSpec_cxx; }
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
#include <NitroModules/Promise.hpp>
|
|
17
18
|
#include <string>
|
|
18
19
|
|
|
19
20
|
#include "Rngine-Swift-Cxx-Umbrella.hpp"
|
|
@@ -74,17 +75,21 @@ namespace margelo::nitro::rngine {
|
|
|
74
75
|
auto __value = std::move(__result.value());
|
|
75
76
|
return __value;
|
|
76
77
|
}
|
|
77
|
-
inline void registerSvg(double id, const std::string& uri) override {
|
|
78
|
+
inline std::shared_ptr<Promise<void>> registerSvg(double id, const std::string& uri) override {
|
|
78
79
|
auto __result = _swiftPart.registerSvg(std::forward<decltype(id)>(id), uri);
|
|
79
80
|
if (__result.hasError()) [[unlikely]] {
|
|
80
81
|
std::rethrow_exception(__result.error());
|
|
81
82
|
}
|
|
83
|
+
auto __value = std::move(__result.value());
|
|
84
|
+
return __value;
|
|
82
85
|
}
|
|
83
|
-
inline void registerLottie(double id, const std::string& json) override {
|
|
86
|
+
inline std::shared_ptr<Promise<void>> registerLottie(double id, const std::string& json) override {
|
|
84
87
|
auto __result = _swiftPart.registerLottie(std::forward<decltype(id)>(id), json);
|
|
85
88
|
if (__result.hasError()) [[unlikely]] {
|
|
86
89
|
std::rethrow_exception(__result.error());
|
|
87
90
|
}
|
|
91
|
+
auto __value = std::move(__result.value());
|
|
92
|
+
return __value;
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
private:
|