summaryrefslogtreecommitdiff
path: root/plugins/hello_gdextension/src/main/java
diff options
context:
space:
mode:
authorFredia Huya-Kouadio <fhuya@meta.com>2023-08-17 11:49:20 -0700
committerGitHub <noreply@github.com>2023-08-17 11:49:20 -0700
commit1f04b16320add64cea98e33fe541b426ff321713 (patch)
tree741a6563c1795437c0ad5b80c6121b5476861361 /plugins/hello_gdextension/src/main/java
parente61f1555b696b62152787d0fee14435325aee62b (diff)
parent37e27e3db22c0b33d098a0ac1fb2dfe8861be0fb (diff)
downloadgodot-android-samples-1f04b16320add64cea98e33fe541b426ff321713.tar.gz
godot-android-samples-1f04b16320add64cea98e33fe541b426ff321713.tar.bz2
godot-android-samples-1f04b16320add64cea98e33fe541b426ff321713.zip
Merge pull request #2 from m4gr3d/add_gdextension_plugin_sample
Add an Android GDExtension plugin sample
Diffstat (limited to 'plugins/hello_gdextension/src/main/java')
-rw-r--r--plugins/hello_gdextension/src/main/java/fhuyakou/godot/plugin/android/hellogdextension/HelloGDExtensionPlugin.kt48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/hello_gdextension/src/main/java/fhuyakou/godot/plugin/android/hellogdextension/HelloGDExtensionPlugin.kt b/plugins/hello_gdextension/src/main/java/fhuyakou/godot/plugin/android/hellogdextension/HelloGDExtensionPlugin.kt
new file mode 100644
index 0000000..85a28ab
--- /dev/null
+++ b/plugins/hello_gdextension/src/main/java/fhuyakou/godot/plugin/android/hellogdextension/HelloGDExtensionPlugin.kt
@@ -0,0 +1,48 @@
+package fhuyakou.godot.plugin.android.hellogdextension
+
+import android.util.Log
+import org.godotengine.godot.Godot
+import org.godotengine.godot.plugin.GodotPlugin
+import org.godotengine.godot.plugin.UsedByGodot
+
+/**
+ * Entry point for the 'HelloGDExtension' Android plugin.
+ *
+ * This plugin provides a couple of methods to add and manipulate a GDExample node.
+ * The GDExample node is implemented and integrated within Godot using GDExtension.
+ */
+class HelloGDExtensionPlugin(godot: Godot) : GodotPlugin(godot) {
+
+ companion object {
+ val TAG = HelloGDExtensionPlugin::class.java.simpleName
+
+ init {
+ try {
+ Log.v(TAG, "Loading hello_gdextension library")
+ System.loadLibrary("hello_gdextension")
+ } catch (e: UnsatisfiedLinkError) {
+ Log.e(TAG, "Unable to load the hello_gdextension shared library")
+ }
+ }
+ }
+
+ @UsedByGodot
+ private fun addGDExampleNode(parentNodePath: String) {
+ Log.i(TAG, "Adding GDExample node to $parentNodePath")
+ nativeAddGDExampleNode(parentNodePath)
+ }
+
+ @UsedByGodot
+ private fun setGDExampleVisible(visible: Boolean) {
+ Log.i(TAG, "Updating GDExample node visibility to $visible")
+ nativeToggleVisibility(visible)
+ }
+
+ override fun getPluginName() = "HelloGDExtension"
+
+ override fun getPluginGDExtensionModulesPaths() = setOf("res://addons/hello_gdextension_plugin/hello_gdextension.gdextension")
+
+ private external fun nativeAddGDExampleNode(parentNodePath: String)
+
+ private external fun nativeToggleVisibility(visible: Boolean)
+}