rngine 0.8.1 → 0.8.2
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/lib/typescript/src/nativeTypes.d.ts +6 -0
- package/lib/typescript/src/nativeTypes.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/Entity.hpp +13 -1
- package/nitrogen/generated/shared/c++/EntityUpdate.hpp +13 -1
- package/nitrogen/generated/shared/c++/Screen.hpp +14 -2
- package/package.json +1 -1
- package/shared/GameLoop.cpp +12 -6
- package/shared/GameMethods.cpp +15 -2
- package/shared/GameRenderer.cpp +15 -4
- package/src/nativeTypes.ts +6 -0
|
@@ -25,8 +25,14 @@ interface Renderable {
|
|
|
25
25
|
color?: string;
|
|
26
26
|
/** Asset to render, use `require` with the file path to get the id. */
|
|
27
27
|
asset?: number;
|
|
28
|
+
/** Whether to flip the rendered asset horizontally. */
|
|
29
|
+
flipH?: boolean;
|
|
30
|
+
/** Whether to flip the rendered asset vertically. */
|
|
31
|
+
flipV?: boolean;
|
|
28
32
|
/** Animation progress between 0 and 1, automatically advanced each tick for Lottie assets. */
|
|
29
33
|
progress?: number;
|
|
34
|
+
/** Playback speed multiplier for animated assets (1 = normal speed). */
|
|
35
|
+
speed?: number;
|
|
30
36
|
}
|
|
31
37
|
interface Kinematic {
|
|
32
38
|
/** Horizontal velocity in game units per second. */
|
|
@@ -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;AAED,UAAU,MAAM;IACd,4BAA4B;IAC5B,MAAM,EA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AAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,MAAM,CAAC;CACjE"}
|
|
@@ -53,7 +53,10 @@ namespace margelo::nitro::rngine {
|
|
|
53
53
|
std::optional<bool> isSensor SWIFT_PRIVATE;
|
|
54
54
|
std::optional<std::string> color SWIFT_PRIVATE;
|
|
55
55
|
std::optional<double> asset SWIFT_PRIVATE;
|
|
56
|
+
std::optional<bool> flipH SWIFT_PRIVATE;
|
|
57
|
+
std::optional<bool> flipV SWIFT_PRIVATE;
|
|
56
58
|
std::optional<double> progress SWIFT_PRIVATE;
|
|
59
|
+
std::optional<double> speed SWIFT_PRIVATE;
|
|
57
60
|
std::optional<double> vx SWIFT_PRIVATE;
|
|
58
61
|
std::optional<double> vy SWIFT_PRIVATE;
|
|
59
62
|
std::optional<double> ax SWIFT_PRIVATE;
|
|
@@ -62,7 +65,7 @@ namespace margelo::nitro::rngine {
|
|
|
62
65
|
|
|
63
66
|
public:
|
|
64
67
|
Entity() = default;
|
|
65
|
-
explicit Entity(std::string id, double px, double py, std::variant<Rect, Circle> shape, std::optional<bool> isSensor, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass): id(id), px(px), py(py), shape(shape), isSensor(isSensor), color(color), asset(asset), progress(progress), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass) {}
|
|
68
|
+
explicit Entity(std::string id, double px, double py, std::variant<Rect, Circle> shape, std::optional<bool> isSensor, 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, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass): id(id), px(px), py(py), shape(shape), isSensor(isSensor), color(color), asset(asset), flipH(flipH), flipV(flipV), progress(progress), speed(speed), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass) {}
|
|
66
69
|
|
|
67
70
|
public:
|
|
68
71
|
friend bool operator==(const Entity& lhs, const Entity& rhs) = default;
|
|
@@ -85,7 +88,10 @@ namespace margelo::nitro {
|
|
|
85
88
|
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isSensor"))),
|
|
86
89
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
|
|
87
90
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
|
|
91
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH"))),
|
|
92
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV"))),
|
|
88
93
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
|
|
94
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed"))),
|
|
89
95
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
|
|
90
96
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy"))),
|
|
91
97
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax"))),
|
|
@@ -102,7 +108,10 @@ namespace margelo::nitro {
|
|
|
102
108
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "isSensor"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.isSensor));
|
|
103
109
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
|
|
104
110
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "asset"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.asset));
|
|
111
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipH"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipH));
|
|
112
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipV"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipV));
|
|
105
113
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
|
|
114
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.speed));
|
|
106
115
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vx));
|
|
107
116
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vy));
|
|
108
117
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ax"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ax));
|
|
@@ -125,7 +134,10 @@ namespace margelo::nitro {
|
|
|
125
134
|
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isSensor")))) return false;
|
|
126
135
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
|
|
127
136
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset")))) return false;
|
|
137
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH")))) return false;
|
|
138
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV")))) return false;
|
|
128
139
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
|
|
140
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
129
141
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
|
|
130
142
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
|
|
131
143
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax")))) return false;
|
|
@@ -53,7 +53,10 @@ namespace margelo::nitro::rngine {
|
|
|
53
53
|
std::optional<bool> isSensor SWIFT_PRIVATE;
|
|
54
54
|
std::optional<std::string> color SWIFT_PRIVATE;
|
|
55
55
|
std::optional<double> asset SWIFT_PRIVATE;
|
|
56
|
+
std::optional<bool> flipH SWIFT_PRIVATE;
|
|
57
|
+
std::optional<bool> flipV SWIFT_PRIVATE;
|
|
56
58
|
std::optional<double> progress SWIFT_PRIVATE;
|
|
59
|
+
std::optional<double> speed SWIFT_PRIVATE;
|
|
57
60
|
std::optional<double> vx SWIFT_PRIVATE;
|
|
58
61
|
std::optional<double> vy SWIFT_PRIVATE;
|
|
59
62
|
std::optional<double> ax SWIFT_PRIVATE;
|
|
@@ -62,7 +65,7 @@ namespace margelo::nitro::rngine {
|
|
|
62
65
|
|
|
63
66
|
public:
|
|
64
67
|
EntityUpdate() = default;
|
|
65
|
-
explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<std::variant<Rect, Circle>> shape, std::optional<bool> isSensor, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass): id(id), px(px), py(py), shape(shape), isSensor(isSensor), color(color), asset(asset), progress(progress), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass) {}
|
|
68
|
+
explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<std::variant<Rect, Circle>> shape, std::optional<bool> isSensor, 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, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass): id(id), px(px), py(py), shape(shape), isSensor(isSensor), color(color), asset(asset), flipH(flipH), flipV(flipV), progress(progress), speed(speed), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass) {}
|
|
66
69
|
|
|
67
70
|
public:
|
|
68
71
|
friend bool operator==(const EntityUpdate& lhs, const EntityUpdate& rhs) = default;
|
|
@@ -85,7 +88,10 @@ namespace margelo::nitro {
|
|
|
85
88
|
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isSensor"))),
|
|
86
89
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
|
|
87
90
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
|
|
91
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH"))),
|
|
92
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV"))),
|
|
88
93
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
|
|
94
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed"))),
|
|
89
95
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
|
|
90
96
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy"))),
|
|
91
97
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax"))),
|
|
@@ -102,7 +108,10 @@ namespace margelo::nitro {
|
|
|
102
108
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "isSensor"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.isSensor));
|
|
103
109
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
|
|
104
110
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "asset"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.asset));
|
|
111
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipH"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipH));
|
|
112
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipV"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipV));
|
|
105
113
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
|
|
114
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.speed));
|
|
106
115
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vx));
|
|
107
116
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vy));
|
|
108
117
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ax"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ax));
|
|
@@ -125,7 +134,10 @@ namespace margelo::nitro {
|
|
|
125
134
|
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isSensor")))) return false;
|
|
126
135
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
|
|
127
136
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset")))) return false;
|
|
137
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH")))) return false;
|
|
138
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV")))) return false;
|
|
128
139
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
|
|
140
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
129
141
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
|
|
130
142
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
|
|
131
143
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax")))) return false;
|
|
@@ -44,11 +44,14 @@ namespace margelo::nitro::rngine {
|
|
|
44
44
|
double height SWIFT_PRIVATE;
|
|
45
45
|
std::optional<std::string> color SWIFT_PRIVATE;
|
|
46
46
|
std::optional<double> asset SWIFT_PRIVATE;
|
|
47
|
+
std::optional<bool> flipH SWIFT_PRIVATE;
|
|
48
|
+
std::optional<bool> flipV SWIFT_PRIVATE;
|
|
47
49
|
std::optional<double> progress SWIFT_PRIVATE;
|
|
50
|
+
std::optional<double> speed SWIFT_PRIVATE;
|
|
48
51
|
|
|
49
52
|
public:
|
|
50
53
|
Screen() = default;
|
|
51
|
-
explicit Screen(double width, double height, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress): width(width), height(height), color(color), asset(asset), progress(progress) {}
|
|
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) {}
|
|
52
55
|
|
|
53
56
|
public:
|
|
54
57
|
friend bool operator==(const Screen& lhs, const Screen& rhs) = default;
|
|
@@ -68,7 +71,10 @@ namespace margelo::nitro {
|
|
|
68
71
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
|
|
69
72
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
|
|
70
73
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
|
|
71
|
-
JSIConverter<std::optional<
|
|
74
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH"))),
|
|
75
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV"))),
|
|
76
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
|
|
77
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))
|
|
72
78
|
);
|
|
73
79
|
}
|
|
74
80
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::Screen& arg) {
|
|
@@ -77,7 +83,10 @@ namespace margelo::nitro {
|
|
|
77
83
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
|
|
78
84
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.color));
|
|
79
85
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "asset"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.asset));
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipH"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipH));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "flipV"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.flipV));
|
|
80
88
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
|
|
89
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.speed));
|
|
81
90
|
return obj;
|
|
82
91
|
}
|
|
83
92
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -92,7 +101,10 @@ namespace margelo::nitro {
|
|
|
92
101
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
|
|
93
102
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
|
|
94
103
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset")))) return false;
|
|
104
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipH")))) return false;
|
|
105
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "flipV")))) return false;
|
|
95
106
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
|
|
107
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
96
108
|
return true;
|
|
97
109
|
}
|
|
98
110
|
};
|
package/package.json
CHANGED
package/shared/GameLoop.cpp
CHANGED
|
@@ -183,9 +183,12 @@ void GameLoop::updateScreen(double deltaTime) {
|
|
|
183
183
|
auto &lottieCache = GameRenderer::getInstance().getLottieCacheInternal();
|
|
184
184
|
auto it = lottieCache.find(_screen.asset.value());
|
|
185
185
|
if (it != lottieCache.end() && it->second) {
|
|
186
|
-
_screen.
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
if (_screen.speed.has_value() && _screen.speed.value() > 0) {
|
|
187
|
+
_screen.progress = fmod(_screen.progress.value_or(0.0) +
|
|
188
|
+
(deltaTime * _screen.speed.value()) /
|
|
189
|
+
it->second->duration(),
|
|
190
|
+
1.0);
|
|
191
|
+
}
|
|
189
192
|
}
|
|
190
193
|
} else if (_screen.progress.has_value()) {
|
|
191
194
|
_screen.progress.reset();
|
|
@@ -225,9 +228,12 @@ void GameLoop::updateEntities(double deltaTime) {
|
|
|
225
228
|
auto &lottieCache = GameRenderer::getInstance().getLottieCacheInternal();
|
|
226
229
|
auto it = lottieCache.find(entity.asset.value());
|
|
227
230
|
if (it != lottieCache.end() && it->second) {
|
|
228
|
-
entity.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
if (entity.speed.has_value() && entity.speed.value() > 0) {
|
|
232
|
+
entity.progress = fmod(entity.progress.value_or(0.0) +
|
|
233
|
+
(deltaTime * entity.speed.value()) /
|
|
234
|
+
it->second->duration(),
|
|
235
|
+
1.0);
|
|
236
|
+
}
|
|
231
237
|
}
|
|
232
238
|
} else if (entity.progress.has_value()) {
|
|
233
239
|
entity.progress.reset();
|
package/shared/GameMethods.cpp
CHANGED
|
@@ -137,9 +137,18 @@ void GameMethods::update(const std::vector<EntityUpdate> &updates) {
|
|
|
137
137
|
if (update.progress.has_value()) {
|
|
138
138
|
entity->progress = update.progress.value();
|
|
139
139
|
}
|
|
140
|
+
if (update.speed.has_value()) {
|
|
141
|
+
entity->speed = update.speed.value();
|
|
142
|
+
}
|
|
140
143
|
if (update.color.has_value()) {
|
|
141
144
|
entity->color = update.color.value();
|
|
142
145
|
}
|
|
146
|
+
if (update.flipH.has_value()) {
|
|
147
|
+
entity->flipH = update.flipH.value();
|
|
148
|
+
}
|
|
149
|
+
if (update.flipV.has_value()) {
|
|
150
|
+
entity->flipV = update.flipV.value();
|
|
151
|
+
}
|
|
143
152
|
if (update.vx.has_value()) {
|
|
144
153
|
entity->vx = update.vx.value();
|
|
145
154
|
}
|
|
@@ -184,8 +193,12 @@ bool GameMethods::isAssetLoaded(double id) {
|
|
|
184
193
|
std::shared_ptr<Promise<bool>>
|
|
185
194
|
GameMethods::loadLottie(double id, const std::string &jsonStr) {
|
|
186
195
|
return Promise<bool>::async([=]() -> bool {
|
|
187
|
-
auto
|
|
188
|
-
|
|
196
|
+
auto resourceProvider = skresources::DataURIResourceProviderProxy::Make(
|
|
197
|
+
nullptr, skresources::ImageDecodeStrategy::kLazyDecode);
|
|
198
|
+
|
|
199
|
+
auto animation = skottie::Animation::Builder()
|
|
200
|
+
.setResourceProvider(resourceProvider)
|
|
201
|
+
.make(jsonStr.data(), jsonStr.size());
|
|
189
202
|
|
|
190
203
|
if (!animation) {
|
|
191
204
|
return false;
|
package/shared/GameRenderer.cpp
CHANGED
|
@@ -165,6 +165,12 @@ void GameRenderer::render(const Screen &screen,
|
|
|
165
165
|
float scaleY = virtualHeight / intrinsicSize.height();
|
|
166
166
|
|
|
167
167
|
canvas->save();
|
|
168
|
+
if (screen.flipH.has_value() || screen.flipV.has_value()) {
|
|
169
|
+
canvas->translate(virtualWidth / 2.f, virtualHeight / 2.f);
|
|
170
|
+
canvas->scale(screen.flipH.value_or(false) ? -1.f : 1.f,
|
|
171
|
+
screen.flipV.value_or(false) ? -1.f : 1.f);
|
|
172
|
+
canvas->translate(-virtualWidth / 2.f, -virtualHeight / 2.f);
|
|
173
|
+
}
|
|
168
174
|
canvas->scale(scaleX, scaleY);
|
|
169
175
|
svgDom->render(canvas);
|
|
170
176
|
canvas->restore();
|
|
@@ -172,8 +178,7 @@ void GameRenderer::render(const Screen &screen,
|
|
|
172
178
|
auto lottieIt = _lottieCache.find(assetId);
|
|
173
179
|
if (lottieIt != _lottieCache.end() && lottieIt->second) {
|
|
174
180
|
auto &lottie = lottieIt->second;
|
|
175
|
-
lottie->
|
|
176
|
-
lottie->duration());
|
|
181
|
+
lottie->seek(screen.progress.value_or(0.0));
|
|
177
182
|
SkRect dstBounds = SkRect::MakeWH(virtualWidth, virtualHeight);
|
|
178
183
|
lottie->render(canvas, &dstBounds);
|
|
179
184
|
}
|
|
@@ -234,6 +239,13 @@ void GameRenderer::render(const Screen &screen,
|
|
|
234
239
|
SkAutoCanvasRestore autoRestore(canvas, true);
|
|
235
240
|
canvas->translate(px - width / 2, py - height / 2);
|
|
236
241
|
|
|
242
|
+
if (entity.flipH.has_value() || entity.flipV.has_value()) {
|
|
243
|
+
canvas->translate(width / 2.f, height / 2.f);
|
|
244
|
+
canvas->scale(entity.flipH.value_or(false) ? -1.f : 1.f,
|
|
245
|
+
entity.flipV.value_or(false) ? -1.f : 1.f);
|
|
246
|
+
canvas->translate(-width / 2.f, -height / 2.f);
|
|
247
|
+
}
|
|
248
|
+
|
|
237
249
|
auto svgIt = _svgCache.find(assetId);
|
|
238
250
|
if (svgIt != _svgCache.end() && svgIt->second) {
|
|
239
251
|
auto &svgDom = svgIt->second;
|
|
@@ -255,8 +267,7 @@ void GameRenderer::render(const Screen &screen,
|
|
|
255
267
|
auto lottieIt = _lottieCache.find(assetId);
|
|
256
268
|
if (lottieIt != _lottieCache.end() && lottieIt->second) {
|
|
257
269
|
auto &lottie = lottieIt->second;
|
|
258
|
-
lottie->
|
|
259
|
-
lottie->duration());
|
|
270
|
+
lottie->seek(entity.progress.value_or(0.0));
|
|
260
271
|
SkRect dstBounds = SkRect::MakeWH(width, height);
|
|
261
272
|
lottie->render(canvas, &dstBounds);
|
|
262
273
|
}
|
package/src/nativeTypes.ts
CHANGED
|
@@ -29,8 +29,14 @@ interface Renderable {
|
|
|
29
29
|
color?: string;
|
|
30
30
|
/** Asset to render, use `require` with the file path to get the id. */
|
|
31
31
|
asset?: number;
|
|
32
|
+
/** Whether to flip the rendered asset horizontally. */
|
|
33
|
+
flipH?: boolean;
|
|
34
|
+
/** Whether to flip the rendered asset vertically. */
|
|
35
|
+
flipV?: boolean;
|
|
32
36
|
/** Animation progress between 0 and 1, automatically advanced each tick for Lottie assets. */
|
|
33
37
|
progress?: number;
|
|
38
|
+
/** Playback speed multiplier for animated assets (1 = normal speed). */
|
|
39
|
+
speed?: number;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
interface Kinematic {
|