godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.71k stars 573 forks source link

Missing methods and functionalities for JavaScriptObject in GDNative #978

Closed 2shady4u closed 1 year ago

2shady4u commented 1 year ago

Godot: 3.5.1 godot-cpp: 316b91c5f5d89d82ae935513c28df78f9e238e8b

I'm trying to port following snippet from GDScript to GDNative:

if OS.get_name() in ["HTML5"]:
    var engine = JavaScript.get_interface("engine")
    var GodotFS = engine.rtenv.GodotFS
    if not GodotFS._syncing:
        GodotFS.sync()

Unfortunately, I can't seem to get the GodotFS in GDNative as that functionality doesn't seem to be implemented? This is how far I've gotten:

#ifdef __EMSCRIPTEN__
            Ref<JavaScriptObject> engine = JavaScript::get_singleton()->get_interface("engine");
            Godot::print("Manually forcing GodotFS to sync!");
#endif

But I have no clue how to access the rtenv from the engine interface... Is it possible to do this? Or has this functionality just not been implemented?

Faless commented 1 year ago

But I have no clue how to access the rtenv from the engine interface... Is it possible to do this? Or has this functionality just not been implemented?

engine->get("rtenv")

should work.

Faless commented 1 year ago

But as I mentioned in the contributor chat:

That code will not work as expected when running official builds (not even the GDScript version), since the closure compiler will most likely rename/minimize both GodotFS and its members (GodotFS is treated as an internal class).

2shady4u commented 1 year ago

Seems like I just need to proper casting and ->get() to make it work 🤦