MCPcopy Create free account
hub / github.com/borndotcom/react-native-godot / GodotHostObject

Class GodotHostObject

common/NativeGodotModule.cpp:245–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245class GodotHostObject : public jsi::HostObject {
246 std::shared_ptr<RNWorklet::JsiWorkletContext> _workletContext;
247 godot::Variant _value;
248
249public:
250 static godot::Variant jsiValueToGodotVariant(std::shared_ptr<RNWorklet::JsiWorkletContext> workletContext, jsi::Runtime &rt, const jsi::Value &value) {
251 if (value.isNull() || value.isUndefined()) {
252 return godot::Variant(nullptr);
253 }
254 if (value.isBool()) {
255 return godot::Variant(value.asBool());
256 }
257 if (value.isNumber()) {
258 return godot::Variant(value.asNumber());
259 }
260 if (value.isString()) {
261 std::string s = value.asString(rt).utf8(rt);
262 return godot::Variant(godot::String::utf8(s.c_str()));
263 }
264 if (value.isBigInt()) {
265 jsi::BigInt b = value.asBigInt(rt);
266 return godot::Variant(b.getInt64(rt));
267 }
268 if (value.isObject()) {
269 jsi::Object o = value.asObject(rt);
270 if (o.isHostObject(rt)) {
271 std::shared_ptr<GodotHostObject> ho = o.getHostObject<GodotHostObject>(rt);
272 return ho->_value;
273 }
274 if (o.isFunction(rt)) {
275 godot::Variant v(createJSCallable(workletContext, rt, o.asFunction(rt)));
276 return v;
277 }
278 if (o.isArray(rt)) {
279 throw jsi::JSINativeException("JavaScript Array binding not yet supported");
280 }
281 if (o.isArrayBuffer(rt)) {
282 throw jsi::JSINativeException("JavaScript ArrayBuffer binding not yet supported");
283 }
284 throw jsi::JSINativeException("JavaScript Object binding not yet supported");
285 }
286 throw jsi::JSINativeException("Unhandled Object Type");
287 }
288
289 static jsi::Value godotVariantToJsiValue(std::shared_ptr<RNWorklet::JsiWorkletContext> workletContext, jsi::Runtime &rt, const godot::Variant &variant) {
290 switch (variant.get_type()) {
291 case godot::Variant::Type::NIL: {
292 return jsi::Value::null();
293 }
294 // atomic types
295 case godot::Variant::Type::BOOL: {
296 return jsi::Value((bool)variant);
297 }
298 case godot::Variant::Type::INT: {
299 return jsi::Value((double)variant);
300 }
301 case godot::Variant::Type::FLOAT: {
302 return jsi::Value((double)variant);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected