rngine 0.3.2 → 0.4.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.
Files changed (72) hide show
  1. package/README.md +10 -7
  2. package/android/build.gradle +6 -4
  3. package/android/kls_database.db +0 -0
  4. package/android/src/main/cpp/GameLoopJNI.cpp +20 -9
  5. package/android/src/main/java/com/margelo/nitro/rngine/Asset.kt +9 -0
  6. package/android/src/main/java/com/margelo/nitro/rngine/GameAssets.kt +47 -0
  7. package/android/src/main/java/com/margelo/nitro/rngine/GameView.kt +46 -8
  8. package/android/src/main/java/com/margelo/nitro/rngine/Rect.kt +7 -5
  9. package/android/src/main/java/com/margelo/nitro/rngine/RectSerializer.kt +8 -6
  10. package/lib/module/GameAssets.nitro.js +5 -0
  11. package/lib/module/GameAssets.nitro.js.map +1 -0
  12. package/lib/module/GameMethods.js +1 -31
  13. package/lib/module/GameMethods.js.map +1 -1
  14. package/lib/module/GameMethods.nitro.js +2 -1
  15. package/lib/module/GameMethods.nitro.js.map +1 -1
  16. package/lib/module/Shared.js +72 -0
  17. package/lib/module/Shared.js.map +1 -0
  18. package/lib/module/index.js +1 -0
  19. package/lib/module/index.js.map +1 -1
  20. package/lib/module/nativeTypes.js +2 -0
  21. package/lib/module/nativeTypes.js.map +1 -0
  22. package/lib/module/types.js +2 -0
  23. package/lib/typescript/src/GameAssets.nitro.d.ts +12 -0
  24. package/lib/typescript/src/GameAssets.nitro.d.ts.map +1 -0
  25. package/lib/typescript/src/GameMethods.d.ts +0 -7
  26. package/lib/typescript/src/GameMethods.d.ts.map +1 -1
  27. package/lib/typescript/src/GameMethods.nitro.d.ts +4 -2
  28. package/lib/typescript/src/GameMethods.nitro.d.ts.map +1 -1
  29. package/lib/typescript/src/Shared.d.ts +8 -0
  30. package/lib/typescript/src/Shared.d.ts.map +1 -0
  31. package/lib/typescript/src/index.d.ts +2 -0
  32. package/lib/typescript/src/index.d.ts.map +1 -1
  33. package/lib/typescript/src/nativeTypes.d.ts +79 -0
  34. package/lib/typescript/src/nativeTypes.d.ts.map +1 -0
  35. package/lib/typescript/src/types.d.ts +11 -47
  36. package/lib/typescript/src/types.d.ts.map +1 -1
  37. package/nitro.json +10 -0
  38. package/nitrogen/generated/android/c++/JHybridGameAssetsSpec.cpp +61 -0
  39. package/nitrogen/generated/android/c++/JHybridGameAssetsSpec.hpp +65 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/HybridGameAssetsSpec.kt +62 -0
  41. package/nitrogen/generated/android/rngine+autolinking.cmake +2 -0
  42. package/nitrogen/generated/android/rngineOnLoad.cpp +16 -0
  43. package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.cpp +17 -0
  44. package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.hpp +37 -0
  45. package/nitrogen/generated/ios/Rngine-Swift-Cxx-Umbrella.hpp +8 -0
  46. package/nitrogen/generated/ios/RngineAutolinking.mm +8 -0
  47. package/nitrogen/generated/ios/RngineAutolinking.swift +12 -0
  48. package/nitrogen/generated/ios/c++/HybridGameAssetsSpecSwift.cpp +11 -0
  49. package/nitrogen/generated/ios/c++/HybridGameAssetsSpecSwift.hpp +94 -0
  50. package/nitrogen/generated/ios/swift/HybridGameAssetsSpec.swift +57 -0
  51. package/nitrogen/generated/ios/swift/HybridGameAssetsSpec_cxx.swift +160 -0
  52. package/nitrogen/generated/shared/c++/Collision.hpp +91 -0
  53. package/nitrogen/generated/shared/c++/CollisionPair.hpp +87 -0
  54. package/nitrogen/generated/shared/c++/Entity.hpp +13 -5
  55. package/nitrogen/generated/shared/c++/EntityUpdate.hpp +9 -1
  56. package/nitrogen/generated/shared/c++/HybridGameAssetsSpec.cpp +23 -0
  57. package/nitrogen/generated/shared/c++/HybridGameAssetsSpec.hpp +64 -0
  58. package/nitrogen/generated/shared/c++/Screen.hpp +14 -5
  59. package/nitrogen/generated/shared/c++/System.hpp +20 -9
  60. package/package.json +1 -1
  61. package/shared/ColorUtils.hpp +6 -3
  62. package/shared/GameLoop.cpp +75 -12
  63. package/shared/GameLoop.hpp +2 -0
  64. package/shared/GameMethods.cpp +20 -7
  65. package/shared/Rect.hpp +8 -5
  66. package/src/GameAssets.nitro.ts +14 -0
  67. package/src/GameMethods.nitro.ts +6 -2
  68. package/src/GameMethods.ts +1 -34
  69. package/src/Shared.ts +83 -0
  70. package/src/index.tsx +2 -0
  71. package/src/nativeTypes.ts +83 -0
  72. package/src/types.ts +17 -49
@@ -0,0 +1,94 @@
1
+ ///
2
+ /// HybridGameAssetsSpecSwift.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
+ #include "HybridGameAssetsSpec.hpp"
11
+
12
+ // Forward declaration of `HybridGameAssetsSpec_cxx` to properly resolve imports.
13
+ namespace Rngine { class HybridGameAssetsSpec_cxx; }
14
+
15
+
16
+
17
+ #include <string>
18
+
19
+ #include "Rngine-Swift-Cxx-Umbrella.hpp"
20
+
21
+ namespace margelo::nitro::rngine {
22
+
23
+ /**
24
+ * The C++ part of HybridGameAssetsSpec_cxx.swift.
25
+ *
26
+ * HybridGameAssetsSpecSwift (C++) accesses HybridGameAssetsSpec_cxx (Swift), and might
27
+ * contain some additional bridging code for C++ <> Swift interop.
28
+ *
29
+ * Since this obviously introduces an overhead, I hope at some point in
30
+ * the future, HybridGameAssetsSpec_cxx can directly inherit from the C++ class HybridGameAssetsSpec
31
+ * to simplify the whole structure and memory management.
32
+ */
33
+ class HybridGameAssetsSpecSwift: public virtual HybridGameAssetsSpec {
34
+ public:
35
+ // Constructor from a Swift instance
36
+ explicit HybridGameAssetsSpecSwift(const Rngine::HybridGameAssetsSpec_cxx& swiftPart):
37
+ HybridObject(HybridGameAssetsSpec::TAG),
38
+ _swiftPart(swiftPart) { }
39
+
40
+ public:
41
+ // Get the Swift part
42
+ inline Rngine::HybridGameAssetsSpec_cxx& getSwiftPart() noexcept {
43
+ return _swiftPart;
44
+ }
45
+
46
+ public:
47
+ inline size_t getExternalMemorySize() noexcept override {
48
+ return _swiftPart.getMemorySize();
49
+ }
50
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
51
+ if (auto otherCast = std::dynamic_pointer_cast<HybridGameAssetsSpecSwift>(other)) {
52
+ return _swiftPart.equals(otherCast->_swiftPart);
53
+ }
54
+ return false;
55
+ }
56
+ void dispose() noexcept override {
57
+ _swiftPart.dispose();
58
+ }
59
+ std::string toString() override {
60
+ return _swiftPart.toString();
61
+ }
62
+
63
+ public:
64
+ // Properties
65
+
66
+
67
+ public:
68
+ // Methods
69
+ inline bool isAssetRegistered(double id) override {
70
+ auto __result = _swiftPart.isAssetRegistered(std::forward<decltype(id)>(id));
71
+ if (__result.hasError()) [[unlikely]] {
72
+ std::rethrow_exception(__result.error());
73
+ }
74
+ auto __value = std::move(__result.value());
75
+ return __value;
76
+ }
77
+ inline void registerSvg(double id, const std::string& uri) override {
78
+ auto __result = _swiftPart.registerSvg(std::forward<decltype(id)>(id), uri);
79
+ if (__result.hasError()) [[unlikely]] {
80
+ std::rethrow_exception(__result.error());
81
+ }
82
+ }
83
+ inline void registerLottie(double id, const std::string& json) override {
84
+ auto __result = _swiftPart.registerLottie(std::forward<decltype(id)>(id), json);
85
+ if (__result.hasError()) [[unlikely]] {
86
+ std::rethrow_exception(__result.error());
87
+ }
88
+ }
89
+
90
+ private:
91
+ Rngine::HybridGameAssetsSpec_cxx _swiftPart;
92
+ };
93
+
94
+ } // namespace margelo::nitro::rngine
@@ -0,0 +1,57 @@
1
+ ///
2
+ /// HybridGameAssetsSpec.swift
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
+ import NitroModules
9
+
10
+ /// See ``HybridGameAssetsSpec``
11
+ public protocol HybridGameAssetsSpec_protocol: HybridObject {
12
+ // Properties
13
+
14
+
15
+ // Methods
16
+ func isAssetRegistered(id: Double) throws -> Bool
17
+ func registerSvg(id: Double, uri: String) throws -> Void
18
+ func registerLottie(id: Double, json: String) throws -> Void
19
+ }
20
+
21
+ public extension HybridGameAssetsSpec_protocol {
22
+ /// Default implementation of ``HybridObject.toString``
23
+ func toString() -> String {
24
+ return "[HybridObject GameAssets]"
25
+ }
26
+ }
27
+
28
+ /// See ``HybridGameAssetsSpec``
29
+ open class HybridGameAssetsSpec_base {
30
+ private weak var cxxWrapper: HybridGameAssetsSpec_cxx? = nil
31
+ public init() { }
32
+ public func getCxxWrapper() -> HybridGameAssetsSpec_cxx {
33
+ #if DEBUG
34
+ guard self is any HybridGameAssetsSpec else {
35
+ fatalError("`self` is not a `HybridGameAssetsSpec`! Did you accidentally inherit from `HybridGameAssetsSpec_base` instead of `HybridGameAssetsSpec`?")
36
+ }
37
+ #endif
38
+ if let cxxWrapper = self.cxxWrapper {
39
+ return cxxWrapper
40
+ } else {
41
+ let cxxWrapper = HybridGameAssetsSpec_cxx(self as! any HybridGameAssetsSpec)
42
+ self.cxxWrapper = cxxWrapper
43
+ return cxxWrapper
44
+ }
45
+ }
46
+ }
47
+
48
+ /**
49
+ * A Swift base-protocol representing the GameAssets HybridObject.
50
+ * Implement this protocol to create Swift-based instances of GameAssets.
51
+ * ```swift
52
+ * class HybridGameAssets : HybridGameAssetsSpec {
53
+ * // ...
54
+ * }
55
+ * ```
56
+ */
57
+ public typealias HybridGameAssetsSpec = HybridGameAssetsSpec_protocol & HybridGameAssetsSpec_base
@@ -0,0 +1,160 @@
1
+ ///
2
+ /// HybridGameAssetsSpec_cxx.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * A class implementation that bridges HybridGameAssetsSpec over to C++.
12
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
13
+ *
14
+ * Also, some Swift types need to be bridged with special handling:
15
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
16
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
17
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
18
+ */
19
+ open class HybridGameAssetsSpec_cxx {
20
+ /**
21
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::rngine::bridge::swift`)
22
+ * from `Rngine-Swift-Cxx-Bridge.hpp`.
23
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
24
+ */
25
+ public typealias bridge = margelo.nitro.rngine.bridge.swift
26
+
27
+ /**
28
+ * Holds an instance of the `HybridGameAssetsSpec` Swift protocol.
29
+ */
30
+ private var __implementation: any HybridGameAssetsSpec
31
+
32
+ /**
33
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
34
+ */
35
+ private var __cxxPart: bridge.std__weak_ptr_HybridGameAssetsSpec_
36
+
37
+ /**
38
+ * Create a new `HybridGameAssetsSpec_cxx` that wraps the given `HybridGameAssetsSpec`.
39
+ * All properties and methods bridge to C++ types.
40
+ */
41
+ public init(_ implementation: any HybridGameAssetsSpec) {
42
+ self.__implementation = implementation
43
+ self.__cxxPart = .init()
44
+ /* no base class */
45
+ }
46
+
47
+ /**
48
+ * Get the actual `HybridGameAssetsSpec` instance this class wraps.
49
+ */
50
+ @inline(__always)
51
+ public func getHybridGameAssetsSpec() -> any HybridGameAssetsSpec {
52
+ return __implementation
53
+ }
54
+
55
+ /**
56
+ * Casts this instance to a retained unsafe raw pointer.
57
+ * This acquires one additional strong reference on the object!
58
+ */
59
+ public func toUnsafe() -> UnsafeMutableRawPointer {
60
+ return Unmanaged.passRetained(self).toOpaque()
61
+ }
62
+
63
+ /**
64
+ * Casts an unsafe pointer to a `HybridGameAssetsSpec_cxx`.
65
+ * The pointer has to be a retained opaque `Unmanaged<HybridGameAssetsSpec_cxx>`.
66
+ * This removes one strong reference from the object!
67
+ */
68
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridGameAssetsSpec_cxx {
69
+ return Unmanaged<HybridGameAssetsSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
70
+ }
71
+
72
+ /**
73
+ * Gets (or creates) the C++ part of this Hybrid Object.
74
+ * The C++ part is a `std::shared_ptr<HybridGameAssetsSpec>`.
75
+ */
76
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridGameAssetsSpec_ {
77
+ let cachedCxxPart = self.__cxxPart.lock()
78
+ if Bool(fromCxx: cachedCxxPart) {
79
+ return cachedCxxPart
80
+ } else {
81
+ let newCxxPart = bridge.create_std__shared_ptr_HybridGameAssetsSpec_(self.toUnsafe())
82
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridGameAssetsSpec_(newCxxPart)
83
+ return newCxxPart
84
+ }
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Get the memory size of the Swift class (plus size of any other allocations)
91
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
92
+ */
93
+ @inline(__always)
94
+ public var memorySize: Int {
95
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
96
+ }
97
+
98
+ /**
99
+ * Compares this object with the given [other] object for reference equality.
100
+ */
101
+ @inline(__always)
102
+ public func equals(other: HybridGameAssetsSpec_cxx) -> Bool {
103
+ return self.__implementation === other.__implementation
104
+ }
105
+
106
+ /**
107
+ * Call dispose() on the Swift class.
108
+ * This _may_ be called manually from JS.
109
+ */
110
+ @inline(__always)
111
+ public func dispose() {
112
+ self.__implementation.dispose()
113
+ }
114
+
115
+ /**
116
+ * Call toString() on the Swift class.
117
+ */
118
+ @inline(__always)
119
+ public func toString() -> String {
120
+ return self.__implementation.toString()
121
+ }
122
+
123
+ // Properties
124
+
125
+
126
+ // Methods
127
+ @inline(__always)
128
+ public final func isAssetRegistered(id: Double) -> bridge.Result_bool_ {
129
+ do {
130
+ let __result = try self.__implementation.isAssetRegistered(id: id)
131
+ let __resultCpp = __result
132
+ return bridge.create_Result_bool_(__resultCpp)
133
+ } catch (let __error) {
134
+ let __exceptionPtr = __error.toCpp()
135
+ return bridge.create_Result_bool_(__exceptionPtr)
136
+ }
137
+ }
138
+
139
+ @inline(__always)
140
+ public final func registerSvg(id: Double, uri: std.string) -> bridge.Result_void_ {
141
+ do {
142
+ try self.__implementation.registerSvg(id: id, uri: String(uri))
143
+ return bridge.create_Result_void_()
144
+ } catch (let __error) {
145
+ let __exceptionPtr = __error.toCpp()
146
+ return bridge.create_Result_void_(__exceptionPtr)
147
+ }
148
+ }
149
+
150
+ @inline(__always)
151
+ public final func registerLottie(id: Double, json: std.string) -> bridge.Result_void_ {
152
+ do {
153
+ try self.__implementation.registerLottie(id: id, json: String(json))
154
+ return bridge.create_Result_void_()
155
+ } catch (let __error) {
156
+ let __exceptionPtr = __error.toCpp()
157
+ return bridge.create_Result_void_(__exceptionPtr)
158
+ }
159
+ }
160
+ }
@@ -0,0 +1,91 @@
1
+ ///
2
+ /// Collision.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 <string>
34
+
35
+ namespace margelo::nitro::rngine {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (Collision).
39
+ */
40
+ struct Collision final {
41
+ public:
42
+ std::string a SWIFT_PRIVATE;
43
+ std::string b SWIFT_PRIVATE;
44
+ double depth SWIFT_PRIVATE;
45
+
46
+ public:
47
+ Collision() = default;
48
+ explicit Collision(std::string a, std::string b, double depth): a(a), b(b), depth(depth) {}
49
+
50
+ public:
51
+ friend bool operator==(const Collision& lhs, const Collision& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::rngine
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ Collision <> JS Collision (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::rngine::Collision> final {
61
+ static inline margelo::nitro::rngine::Collision fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::rngine::Collision(
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "a"))),
65
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "b"))),
66
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "depth")))
67
+ );
68
+ }
69
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::Collision& arg) {
70
+ jsi::Object obj(runtime);
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "a"), JSIConverter<std::string>::toJSI(runtime, arg.a));
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "b"), JSIConverter<std::string>::toJSI(runtime, arg.b));
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "depth"), JSIConverter<double>::toJSI(runtime, arg.depth));
74
+ return obj;
75
+ }
76
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
77
+ if (!value.isObject()) {
78
+ return false;
79
+ }
80
+ jsi::Object obj = value.getObject(runtime);
81
+ if (!nitro::isPlainObject(runtime, obj)) {
82
+ return false;
83
+ }
84
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "a")))) return false;
85
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "b")))) return false;
86
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "depth")))) return false;
87
+ return true;
88
+ }
89
+ };
90
+
91
+ } // namespace margelo::nitro
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// CollisionPair.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 <string>
34
+
35
+ namespace margelo::nitro::rngine {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (CollisionPair).
39
+ */
40
+ struct CollisionPair final {
41
+ public:
42
+ std::string a SWIFT_PRIVATE;
43
+ std::string b SWIFT_PRIVATE;
44
+
45
+ public:
46
+ CollisionPair() = default;
47
+ explicit CollisionPair(std::string a, std::string b): a(a), b(b) {}
48
+
49
+ public:
50
+ friend bool operator==(const CollisionPair& lhs, const CollisionPair& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::rngine
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ CollisionPair <> JS CollisionPair (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::rngine::CollisionPair> final {
60
+ static inline margelo::nitro::rngine::CollisionPair fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::rngine::CollisionPair(
63
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "a"))),
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "b")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::CollisionPair& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "a"), JSIConverter<std::string>::toJSI(runtime, arg.a));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "b"), JSIConverter<std::string>::toJSI(runtime, arg.b));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "a")))) return false;
82
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "b")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -45,13 +45,15 @@ namespace margelo::nitro::rngine {
45
45
  double py SWIFT_PRIVATE;
46
46
  double width SWIFT_PRIVATE;
47
47
  double height SWIFT_PRIVATE;
48
- std::string color SWIFT_PRIVATE;
48
+ std::optional<std::string> color SWIFT_PRIVATE;
49
+ std::optional<double> asset SWIFT_PRIVATE;
50
+ std::optional<double> progress SWIFT_PRIVATE;
49
51
  std::optional<double> vx SWIFT_PRIVATE;
50
52
  std::optional<double> vy SWIFT_PRIVATE;
51
53
 
52
54
  public:
53
55
  Entity() = default;
54
- explicit Entity(std::string id, double px, double py, double width, double height, std::string color, std::optional<double> vx, std::optional<double> vy): id(id), px(px), py(py), width(width), height(height), color(color), vx(vx), vy(vy) {}
56
+ explicit Entity(std::string id, double px, double py, double width, double height, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy): id(id), px(px), py(py), width(width), height(height), color(color), asset(asset), progress(progress), vx(vx), vy(vy) {}
55
57
 
56
58
  public:
57
59
  friend bool operator==(const Entity& lhs, const Entity& rhs) = default;
@@ -72,7 +74,9 @@ namespace margelo::nitro {
72
74
  JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py"))),
73
75
  JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
74
76
  JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
75
- JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
77
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
78
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
79
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
76
80
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
77
81
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))
78
82
  );
@@ -84,7 +88,9 @@ namespace margelo::nitro {
84
88
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "py"), JSIConverter<double>::toJSI(runtime, arg.py));
85
89
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
86
90
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
87
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::string>::toJSI(runtime, arg.color));
91
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
92
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "asset"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.asset));
93
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
88
94
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vx));
89
95
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vy));
90
96
  return obj;
@@ -102,7 +108,9 @@ namespace margelo::nitro {
102
108
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py")))) return false;
103
109
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
104
110
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
105
- if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
111
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
112
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset")))) return false;
113
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
106
114
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
107
115
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
108
116
  return true;
@@ -46,12 +46,14 @@ namespace margelo::nitro::rngine {
46
46
  std::optional<double> width SWIFT_PRIVATE;
47
47
  std::optional<double> height SWIFT_PRIVATE;
48
48
  std::optional<std::string> color SWIFT_PRIVATE;
49
+ std::optional<double> asset SWIFT_PRIVATE;
50
+ std::optional<double> progress SWIFT_PRIVATE;
49
51
  std::optional<double> vx SWIFT_PRIVATE;
50
52
  std::optional<double> vy SWIFT_PRIVATE;
51
53
 
52
54
  public:
53
55
  EntityUpdate() = default;
54
- explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<double> width, std::optional<double> height, std::optional<std::string> color, std::optional<double> vx, std::optional<double> vy): id(id), px(px), py(py), width(width), height(height), color(color), vx(vx), vy(vy) {}
56
+ explicit EntityUpdate(std::string id, 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<double> progress, std::optional<double> vx, std::optional<double> vy): id(id), px(px), py(py), width(width), height(height), color(color), asset(asset), progress(progress), vx(vx), vy(vy) {}
55
57
 
56
58
  public:
57
59
  friend bool operator==(const EntityUpdate& lhs, const EntityUpdate& rhs) = default;
@@ -73,6 +75,8 @@ namespace margelo::nitro {
73
75
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
74
76
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
75
77
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
78
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
79
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
76
80
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
77
81
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))
78
82
  );
@@ -85,6 +89,8 @@ namespace margelo::nitro {
85
89
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.width));
86
90
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.height));
87
91
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
92
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "asset"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.asset));
93
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
88
94
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vx));
89
95
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vy));
90
96
  return obj;
@@ -103,6 +109,8 @@ namespace margelo::nitro {
103
109
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
104
110
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
105
111
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
112
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset")))) return false;
113
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
106
114
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
107
115
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
108
116
  return true;
@@ -0,0 +1,23 @@
1
+ ///
2
+ /// HybridGameAssetsSpec.cpp
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
+ #include "HybridGameAssetsSpec.hpp"
9
+
10
+ namespace margelo::nitro::rngine {
11
+
12
+ void HybridGameAssetsSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("isAssetRegistered", &HybridGameAssetsSpec::isAssetRegistered);
18
+ prototype.registerHybridMethod("registerSvg", &HybridGameAssetsSpec::registerSvg);
19
+ prototype.registerHybridMethod("registerLottie", &HybridGameAssetsSpec::registerLottie);
20
+ });
21
+ }
22
+
23
+ } // namespace margelo::nitro::rngine
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// HybridGameAssetsSpec.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/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+ #include <string>
19
+
20
+ namespace margelo::nitro::rngine {
21
+
22
+ using namespace margelo::nitro;
23
+
24
+ /**
25
+ * An abstract base class for `GameAssets`
26
+ * Inherit this class to create instances of `HybridGameAssetsSpec` in C++.
27
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
28
+ * @example
29
+ * ```cpp
30
+ * class HybridGameAssets: public HybridGameAssetsSpec {
31
+ * public:
32
+ * HybridGameAssets(...): HybridObject(TAG) { ... }
33
+ * // ...
34
+ * };
35
+ * ```
36
+ */
37
+ class HybridGameAssetsSpec: public virtual HybridObject {
38
+ public:
39
+ // Constructor
40
+ explicit HybridGameAssetsSpec(): HybridObject(TAG) { }
41
+
42
+ // Destructor
43
+ ~HybridGameAssetsSpec() override = default;
44
+
45
+ public:
46
+ // Properties
47
+
48
+
49
+ public:
50
+ // Methods
51
+ virtual bool isAssetRegistered(double id) = 0;
52
+ virtual void registerSvg(double id, const std::string& uri) = 0;
53
+ virtual void registerLottie(double id, const std::string& json) = 0;
54
+
55
+ protected:
56
+ // Hybrid Setup
57
+ void loadHybridMethods() override;
58
+
59
+ protected:
60
+ // Tag for logging
61
+ static constexpr auto TAG = "GameAssets";
62
+ };
63
+
64
+ } // namespace margelo::nitro::rngine