@preeternal/react-native-godot 0.0.0-stage → 0.2.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 (109) hide show
  1. package/LICENSE +22 -0
  2. package/Package.swift +106 -0
  3. package/README.md +590 -2
  4. package/android/build.gradle +291 -0
  5. package/android/consumer-rules.pro +20 -0
  6. package/android/fix-prefab.gradle +54 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/CMakeLists.txt +78 -0
  9. package/android/src/main/cpp/GodotModule.cpp +764 -0
  10. package/android/src/main/cpp/OnLoad.cpp +66 -0
  11. package/android/src/main/cpp/libgodot_android.h +73 -0
  12. package/android/src/main/cpp/libgodot_jni.cpp +658 -0
  13. package/android/src/main/cpp/libgodot_jni.h +116 -0
  14. package/android/src/main/cpp/native_godot_module_jni.cpp +86 -0
  15. package/android/src/main/cpp/native_godot_module_jni.h +58 -0
  16. package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModuleModule.kt +83 -0
  17. package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModulePackage.kt +41 -0
  18. package/android/src/main/java/com/preeternal/reactnativegodot/NativeLibraryLoader.kt +5 -0
  19. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotIO.kt +123 -0
  20. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +92 -0
  21. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotViewManager.kt +34 -0
  22. package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +215 -0
  23. package/android/src/main/res/layout/downloading_expansion.xml +165 -0
  24. package/android/src/main/res/layout/godot_app_layout.xml +5 -0
  25. package/android/src/main/res/layout/snackbar.xml +27 -0
  26. package/android/src/main/res/layout/status_bar_ongoing_event_progress_bar.xml +108 -0
  27. package/android/src/main/res/mipmap/icon.png +0 -0
  28. package/android/src/main/res/mipmap/icon_background.png +0 -0
  29. package/android/src/main/res/mipmap/icon_foreground.png +0 -0
  30. package/android/src/main/res/mipmap/icon_monochrome.png +0 -0
  31. package/android/src/main/res/mipmap-anydpi-v26/icon.xml +8 -0
  32. package/android/src/main/res/mipmap-anydpi-v26/themed_icon.xml +11 -0
  33. package/android/src/main/res/mipmap-hdpi/icon.png +0 -0
  34. package/android/src/main/res/mipmap-hdpi/icon_background.png +0 -0
  35. package/android/src/main/res/mipmap-hdpi/icon_foreground.png +0 -0
  36. package/android/src/main/res/mipmap-hdpi/icon_monochrome.png +0 -0
  37. package/android/src/main/res/mipmap-mdpi/icon.png +0 -0
  38. package/android/src/main/res/mipmap-mdpi/icon_background.png +0 -0
  39. package/android/src/main/res/mipmap-mdpi/icon_foreground.png +0 -0
  40. package/android/src/main/res/mipmap-mdpi/icon_monochrome.png +0 -0
  41. package/android/src/main/res/mipmap-xhdpi/icon.png +0 -0
  42. package/android/src/main/res/mipmap-xhdpi/icon_background.png +0 -0
  43. package/android/src/main/res/mipmap-xhdpi/icon_foreground.png +0 -0
  44. package/android/src/main/res/mipmap-xhdpi/icon_monochrome.png +0 -0
  45. package/android/src/main/res/mipmap-xxhdpi/icon.png +0 -0
  46. package/android/src/main/res/mipmap-xxhdpi/icon_background.png +0 -0
  47. package/android/src/main/res/mipmap-xxhdpi/icon_foreground.png +0 -0
  48. package/android/src/main/res/mipmap-xxhdpi/icon_monochrome.png +0 -0
  49. package/android/src/main/res/mipmap-xxxhdpi/icon.png +0 -0
  50. package/android/src/main/res/mipmap-xxxhdpi/icon_background.png +0 -0
  51. package/android/src/main/res/mipmap-xxxhdpi/icon_foreground.png +0 -0
  52. package/android/src/main/res/mipmap-xxxhdpi/icon_monochrome.png +0 -0
  53. package/android/src/main/res/values/dimens.xml +9 -0
  54. package/android/src/main/res/values/strings.xml +61 -0
  55. package/android/src/main/res/values/styles.xml +25 -0
  56. package/android/src/main/res/values-fa/strings.xml +14 -0
  57. package/android/src/main/res/values-ko/strings.xml +54 -0
  58. package/android/src/main/res/xml/godot_provider_paths.xml +15 -0
  59. package/android/src/test/java/com/preeternal/reactnativegodot/NativeGodotModulePackageTest.kt +26 -0
  60. package/app.plugin.js +169 -0
  61. package/cpp/AppleRendererPolicy.h +95 -0
  62. package/cpp/GodotModule.h +126 -0
  63. package/cpp/LibGodotABI.h +52 -0
  64. package/cpp/NativeGodotModule.cpp +825 -0
  65. package/cpp/NativeGodotModule.h +45 -0
  66. package/cpp/godot-log.h +64 -0
  67. package/ios/GodotModule.mm +695 -0
  68. package/ios/NativeGodotModuleProvider.h +35 -0
  69. package/ios/NativeGodotModuleProvider.mm +42 -0
  70. package/ios/RTNGodotView.h +42 -0
  71. package/ios/RTNGodotView.mm +671 -0
  72. package/ios/log.mm +38 -0
  73. package/lib/module/NativeNativeGodotModule.js +59 -0
  74. package/lib/module/NativeNativeGodotModule.js.map +1 -0
  75. package/lib/module/RTNGodotView.js +6 -0
  76. package/lib/module/RTNGodotView.js.map +1 -0
  77. package/lib/module/RTNGodotView.native.js +5 -0
  78. package/lib/module/RTNGodotView.native.js.map +1 -0
  79. package/lib/module/RTNGodotViewNativeComponent.ts +37 -0
  80. package/lib/module/index.js +30 -0
  81. package/lib/module/index.js.map +1 -0
  82. package/lib/module/package.json +1 -0
  83. package/lib/typescript/package.json +1 -0
  84. package/lib/typescript/src/NativeNativeGodotModule.d.ts +26 -0
  85. package/lib/typescript/src/NativeNativeGodotModule.d.ts.map +1 -0
  86. package/lib/typescript/src/RTNGodotView.d.ts +7 -0
  87. package/lib/typescript/src/RTNGodotView.d.ts.map +1 -0
  88. package/lib/typescript/src/RTNGodotView.native.d.ts +3 -0
  89. package/lib/typescript/src/RTNGodotView.native.d.ts.map +1 -0
  90. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts +11 -0
  91. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts.map +1 -0
  92. package/lib/typescript/src/index.d.ts +6 -0
  93. package/lib/typescript/src/index.d.ts.map +1 -0
  94. package/package.json +282 -4
  95. package/prebuilt-utils.rb +46 -0
  96. package/react-native-godot.podspec +41 -0
  97. package/react-native.config.js +16 -0
  98. package/scripts/check-16kb.sh +136 -0
  99. package/scripts/check-packaged-artifacts.sh +156 -0
  100. package/scripts/ci/verify-ios-simulator.py +48 -0
  101. package/scripts/ci/verify-prebuilt-install.cjs +41 -0
  102. package/scripts/download-prebuilt.js +283 -0
  103. package/scripts/prebuilt-config.js +80 -0
  104. package/scripts/spm-autolinking-plugin.js +87 -0
  105. package/src/NativeNativeGodotModule.ts +90 -0
  106. package/src/RTNGodotView.native.tsx +2 -0
  107. package/src/RTNGodotView.tsx +12 -0
  108. package/src/RTNGodotViewNativeComponent.ts +37 -0
  109. package/src/index.tsx +28 -0
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="godot_project_name_string">godot-project-name</string>
4
+ <string name="text_paused_cellular">Would you like to enable downloading over cellular connections? Depending on your data plan, this may cost you money.</string>
5
+ <string name="text_paused_cellular_2">If you choose not to enable downloading over cellular connections, the download will automatically resume when wi-fi is available.</string>
6
+ <string name="text_button_resume_cellular">Resume download</string>
7
+ <string name="text_button_wifi_settings">Wi-Fi settings</string>
8
+ <string name="text_verifying_download">Verifying Download</string>
9
+ <string name="text_validation_complete">XAPK File Validation Complete. Select OK to exit.</string>
10
+ <string name="text_validation_failed">XAPK File Validation Failed.</string>
11
+ <string name="text_button_pause">Pause Download</string>
12
+ <string name="text_button_resume">Resume Download</string>
13
+ <string name="text_button_cancel">Cancel</string>
14
+ <string name="text_button_cancel_verify">Cancel Verification</string>
15
+ <string name="text_error_title">Error!</string>
16
+ <string name="error_engine_setup_message">Unable to setup the Godot Engine! Aborting…</string>
17
+ <string name="error_missing_vulkan_requirements_message">Warning - this device does not meet the requirements for Vulkan support</string>
18
+
19
+ <!-- APK Expansion Strings -->
20
+
21
+ <!-- When a download completes, a notification is displayed, and this
22
+ string is used to indicate that the download successfully completed.
23
+ Note that such a download could have been initiated by a variety of
24
+ applications, including (but not limited to) the browser, an email
25
+ application, a content marketplace. -->
26
+ <string name="notification_download_complete">Download complete</string>
27
+
28
+ <!-- When a download completes, a notification is displayed, and this
29
+ string is used to indicate that the download failed.
30
+ Note that such a download could have been initiated by a variety of
31
+ applications, including (but not limited to) the browser, an email
32
+ application, a content marketplace. -->
33
+ <string name="notification_download_failed">Download unsuccessful</string>
34
+
35
+
36
+ <string name="state_unknown">Starting…</string>
37
+ <string name="state_idle">Waiting for download to start</string>
38
+ <string name="state_fetching_url">Looking for resources to download</string>
39
+ <string name="state_connecting">Connecting to the download server</string>
40
+ <string name="state_downloading">Downloading resources</string>
41
+ <string name="state_completed">Download finished</string>
42
+ <string name="state_paused_network_unavailable">Download paused because no network is available</string>
43
+ <string name="state_paused_network_setup_failure">Download paused. Test a website in browser</string>
44
+ <string name="state_paused_by_request">Download paused</string>
45
+ <string name="state_paused_wifi_unavailable">Download paused because wifi is unavailable</string>
46
+ <string name="state_paused_wifi_disabled">Download paused because wifi is disabled</string>
47
+ <string name="state_paused_roaming">Download paused because you are roaming</string>
48
+ <string name="state_paused_sdcard_unavailable">Download paused because the external storage is unavailable</string>
49
+ <string name="state_failed_unlicensed">Download failed because you may not have purchased this app</string>
50
+ <string name="state_failed_fetching_url">Download failed because the resources could not be found</string>
51
+ <string name="state_failed_sdcard_full">Download failed because the external storage is full</string>
52
+ <string name="state_failed_cancelled">Download canceled</string>
53
+ <string name="state_failed">Download failed</string>
54
+
55
+ <string name="kilobytes_per_second">%1$s KB/s</string>
56
+ <string name="time_remaining">Time remaining: %1$s</string>
57
+ <string name="time_remaining_notification">%1$s left</string>
58
+
59
+ <!-- Labels for the dialog action buttons -->
60
+ <string name="dialog_ok">OK</string>
61
+ </resources>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+
4
+ <style name="NotificationText">
5
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
6
+ </style>
7
+
8
+ <style name="NotificationTextShadow" parent="NotificationText">
9
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
10
+ <item name="android:shadowColor">@android:color/background_dark</item>
11
+ <item name="android:shadowDx">1.0</item>
12
+ <item name="android:shadowDy">1.0</item>
13
+ <item name="android:shadowRadius">1</item>
14
+ </style>
15
+
16
+ <style name="NotificationTitle">
17
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
18
+ <item name="android:textStyle">bold</item>
19
+ </style>
20
+
21
+ <style name="ButtonBackground">
22
+ <item name="android:background">@android:color/background_dark</item>
23
+ </style>
24
+
25
+ </resources>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="text_paused_cellular">آیا می خواهید بر روی اتصال داده همراه دانلود را شروع کنید؟ بر اساس نوع سطح داده شما این ممکن است برای شما هزینه مالی داشته باشد.</string>
4
+ <string name="text_paused_cellular_2">اگر نمی خواهید بر روی اتصال داده همراه دانلود را شروع کنید ، دانلود به صورت خودکار در زمان دسترسی به وای-فای شروع می شود.</string>
5
+ <string name="text_button_resume_cellular">ادامه دانلود</string>
6
+ <string name="text_button_wifi_settings">تنظیمات وای-فای</string>
7
+ <string name="text_verifying_download">درحال تایید دانلود</string>
8
+ <string name="text_validation_complete">تایید فایل XAPK تکمیل شد. برای خروج تایید کنید.</string>
9
+ <string name="text_validation_failed">اعتبارسنجی فایل XAPK ناموق.</string>
10
+ <string name="text_button_pause">توقف دانلود</string>
11
+ <string name="text_button_resume">ادامه دانلود</string>
12
+ <string name="text_button_cancel">انصراف</string>
13
+ <string name="text_button_cancel_verify">انصراف از تایید شدن</string>
14
+ </resources>
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="text_paused_cellular">모바일 네트워크를 사용하여 다운로드 하시겠습니까? 남은 데이터 사용량에 따라, 요금이 부과될 수 있습니다.</string>
4
+ <string name="text_paused_cellular_2">모바일 네트워크를 사용하여 다운로드 하지 않을 경우, 와이파이 연결이 가능할 때 자동적으로 다운로드가 이루어집니다.</string>
5
+ <string name="text_button_resume_cellular">다운로드 계속하기</string>
6
+ <string name="text_button_wifi_settings">와이파이 설정</string>
7
+ <string name="text_verifying_download">다운로드 확인중</string>
8
+ <string name="text_validation_complete">추가 파일 확인이 완료되었습니다. 확인을 눌러 진행하세요.</string>
9
+ <string name="text_validation_failed">추가 파일 확인에 실패하였습니다.</string>
10
+ <string name="text_button_pause">다운로드 일시정지</string>
11
+ <string name="text_button_resume">다운로드 계속하기</string>
12
+ <string name="text_button_cancel">취소</string>
13
+ <string name="text_button_cancel_verify">파일 확인 취소</string>
14
+
15
+ <!-- APK Expansion Strings -->
16
+
17
+ <!-- When a download completes, a notification is displayed, and this
18
+ string is used to indicate that the download successfully completed.
19
+ Note that such a download could have been initiated by a variety of
20
+ applications, including (but not limited to) the browser, an email
21
+ application, a content marketplace. -->
22
+ <string name="notification_download_complete">다운로드 완료</string>
23
+
24
+ <!-- When a download completes, a notification is displayed, and this
25
+ string is used to indicate that the download failed.
26
+ Note that such a download could have been initiated by a variety of
27
+ applications, including (but not limited to) the browser, an email
28
+ application, a content marketplace. -->
29
+ <string name="notification_download_failed">다운로드 실패</string>
30
+
31
+
32
+ <string name="state_unknown">시작중…</string>
33
+ <string name="state_idle">다운로드 시작을 기다리는 중</string>
34
+ <string name="state_fetching_url">다운로드할 항목을 찾는 중</string>
35
+ <string name="state_connecting">다운로드 서버에 연결 중</string>
36
+ <string name="state_downloading">다운로드 중</string>
37
+ <string name="state_completed">다운로드 종료</string>
38
+ <string name="state_paused_network_unavailable">와이파이를 찾을 수 없어 다운로드가 일시정지 되었습니다.</string>
39
+ <string name="state_paused_network_setup_failure">다운로드가 일시정지 되었습니다. 네트워크 연결 상태를 확인하세요.</string>
40
+ <string name="state_paused_by_request">다운로드 일시정지</string>
41
+ <string name="state_paused_wifi_unavailable">와이파이가 사용하능하지 않아 다운로드가 일시정지 되었습니다.</string>
42
+ <string name="state_paused_wifi_disabled">와이파이가 비활성화 되어 다운로드가 일시정지 되었습니다.</string>
43
+ <string name="state_paused_roaming">로밍 상태이어서 다운로드가 일시정지 되었습니다.</string>
44
+ <string name="state_paused_sdcard_unavailable">외부 저장소를 사용할 수 없어 다운로드가 일시정지 되었습니다.</string>
45
+ <string name="state_failed_unlicensed">이 앱을 구매하지 않아 다운로드가 정지 되었습니다.</string>
46
+ <string name="state_failed_fetching_url">다운로드 항목을 찾을 수 없어 다운로드가 정지 되었습니다.</string>
47
+ <string name="state_failed_sdcard_full">외부 저장소가 가득차서 다운로드가 실패하였습니다.</string>
48
+ <string name="state_failed_cancelled">다운로드 취소</string>
49
+ <string name="state_failed">다운로드 실패</string>
50
+
51
+ <string name="kilobytes_per_second">%1$s KB/s</string>
52
+ <string name="time_remaining">남은 시간: %1$s</string>
53
+ <string name="time_remaining_notification">%1$s 남음</string>
54
+ </resources>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <paths xmlns:android="http://schemas.android.com/apk/res/android">
3
+
4
+ <files-path
5
+ name="filesRoot"
6
+ path="/" />
7
+
8
+ <external-path
9
+ name="public"
10
+ path="." />
11
+
12
+ <external-files-path
13
+ name="app"
14
+ path="." />
15
+ </paths>
@@ -0,0 +1,26 @@
1
+ package com.preeternal.reactnativegodot
2
+
3
+ import org.junit.After
4
+ import org.junit.Assert.assertEquals
5
+ import org.junit.Test
6
+
7
+ class NativeGodotModulePackageTest {
8
+ @After
9
+ fun restoreNativeLibraryLoader() {
10
+ NativeLibraryLoader.load = System::loadLibrary
11
+ }
12
+
13
+ @Test
14
+ fun packageInitializationLoadsNativeLibraryBeforeTurboModuleUse() {
15
+ val loadedLibraries = mutableListOf<String>()
16
+ NativeLibraryLoader.load = { loadedLibraries += it }
17
+
18
+ Class.forName(
19
+ NativeGodotModulePackage::class.java.name,
20
+ true,
21
+ NativeGodotModulePackage::class.java.classLoader,
22
+ )
23
+
24
+ assertEquals(listOf("rtngodot"), loadedLibraries)
25
+ }
26
+ }
package/app.plugin.js ADDED
@@ -0,0 +1,169 @@
1
+ const path = require('node:path');
2
+ function loadExpoConfigPlugins() {
3
+ const searchPaths = [
4
+ __dirname,
5
+ process.cwd(),
6
+ path.join(__dirname, 'example'),
7
+ ];
8
+ for (const searchPath of searchPaths) {
9
+ try {
10
+ return require(
11
+ require.resolve('expo/config-plugins', { paths: [searchPath] })
12
+ );
13
+ } catch {
14
+ // Continue until the plugin is resolved from the consuming app.
15
+ }
16
+ }
17
+ throw new Error(
18
+ 'Expo config plugins are required to use the Godot config plugin.'
19
+ );
20
+ }
21
+
22
+ const {
23
+ IOSConfig,
24
+ withAppBuildGradle,
25
+ withGradleProperties,
26
+ withXcodeProject,
27
+ } = loadExpoConfigPlugins();
28
+ const { resolvePrebuiltConfig } = require('./scripts/prebuilt-config');
29
+
30
+ const ANDROID_PROPERTIES = {
31
+ 'android.minSdkVersion': '29',
32
+ 'reactNativeArchitectures': 'armeabi-v7a,arm64-v8a',
33
+ };
34
+ const GODOT_MAVEN_PROPERTY = 'android.extraMavenRepos';
35
+ const GODOT_ASSET_PATTERN =
36
+ '!.svn:!.git:!.ds_store:!*.scc:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~';
37
+ const GODOT_ASSETS_START = '// @generated begin react-native-godot-assets';
38
+ const GODOT_ASSETS_END = '// @generated end react-native-godot-assets';
39
+
40
+ function setGradleProperty(properties, key, value) {
41
+ const property = properties.find(
42
+ (entry) => entry.type === 'property' && entry.key === key
43
+ );
44
+
45
+ if (property) {
46
+ property.value = value;
47
+ } else {
48
+ properties.push({ type: 'property', key, value });
49
+ }
50
+ }
51
+
52
+ function isGodotMavenRepository(repository) {
53
+ return (
54
+ repository &&
55
+ typeof repository.url === 'string' &&
56
+ /\/android\/libs\/libgodot-android\/[^/]+\/?$/.test(
57
+ repository.url.replaceAll('\\', '/')
58
+ )
59
+ );
60
+ }
61
+
62
+ function addGodotMavenRepository(properties, platformProjectRoot) {
63
+ const libGodotAndroid = resolvePrebuiltConfig(
64
+ platformProjectRoot
65
+ ).prebuiltFiles.find((entry) => entry.name === 'libgodot-android');
66
+ const property = properties.find(
67
+ (entry) => entry.type === 'property' && entry.key === GODOT_MAVEN_PROPERTY
68
+ );
69
+ let repositories = [];
70
+
71
+ if (property) {
72
+ repositories = JSON.parse(property.value);
73
+ if (!Array.isArray(repositories)) {
74
+ throw new Error(`${GODOT_MAVEN_PROPERTY} must be a JSON array`);
75
+ }
76
+ }
77
+
78
+ const repositoryPath = path
79
+ .relative(
80
+ path.join(platformProjectRoot, 'app'),
81
+ path.join(
82
+ __dirname,
83
+ 'android',
84
+ 'libs',
85
+ 'libgodot-android',
86
+ libGodotAndroid.version
87
+ )
88
+ )
89
+ .split(path.sep)
90
+ .join('/');
91
+ repositories = repositories.filter(
92
+ (repository) => !isGodotMavenRepository(repository)
93
+ );
94
+ repositories.push({ url: repositoryPath });
95
+ setGradleProperty(
96
+ properties,
97
+ GODOT_MAVEN_PROPERTY,
98
+ JSON.stringify(repositories)
99
+ );
100
+ }
101
+
102
+ function withGodotAndroid(config) {
103
+ config = withGradleProperties(config, (projectConfig) => {
104
+ for (const [key, value] of Object.entries(ANDROID_PROPERTIES)) {
105
+ setGradleProperty(projectConfig.modResults, key, value);
106
+ }
107
+ addGodotMavenRepository(
108
+ projectConfig.modResults,
109
+ projectConfig.modRequest.platformProjectRoot
110
+ );
111
+
112
+ return projectConfig;
113
+ });
114
+ config = withAppBuildGradle(config, (projectConfig) => {
115
+ const { language, contents } = projectConfig.modResults;
116
+ if (language !== 'groovy' && language !== 'kt') {
117
+ throw new Error(`Unsupported app Gradle language: ${language}`);
118
+ }
119
+ const filter =
120
+ language === 'kt'
121
+ ? '.filter { it != ".*" && it != "<dir>.*" }.joinToString(":")'
122
+ : '.findAll { it != ".*" && it != "<dir>.*" }.join(":")';
123
+ const block = `${GODOT_ASSETS_START}
124
+ android {
125
+ androidResources {
126
+ // Keep Godot's hidden runtime assets while preserving other exclusions.
127
+ ignoreAssetsPattern = (ignoreAssetsPattern ?: "${GODOT_ASSET_PATTERN}").split(":")${filter}
128
+ }
129
+ }
130
+ ${GODOT_ASSETS_END}`;
131
+ // Replace our previous block on repeated prebuilds; place it after existing
132
+ // app configuration so a template's asset pattern cannot override it.
133
+ projectConfig.modResults.contents =
134
+ contents
135
+ .replace(
136
+ /\/\/ @generated begin react-native-godot-assets[\s\S]*?\/\/ @generated end react-native-godot-assets\n?/g,
137
+ ''
138
+ )
139
+ .trimEnd() + `\n\n${block}\n`;
140
+ return projectConfig;
141
+ });
142
+ return config;
143
+ }
144
+
145
+ function withGodotPacks(config, iosPacks) {
146
+ if (!iosPacks.length) {
147
+ return config;
148
+ }
149
+
150
+ return withXcodeProject(config, (projectConfig) => {
151
+ const project = projectConfig.modResults;
152
+ IOSConfig.XcodeUtils.ensureGroupRecursively(project, 'Resources');
153
+
154
+ for (const pack of iosPacks) {
155
+ IOSConfig.XcodeUtils.addResourceFileToGroup({
156
+ filepath: pack,
157
+ groupName: 'Resources',
158
+ isBuildFile: true,
159
+ project,
160
+ verbose: true,
161
+ });
162
+ }
163
+
164
+ return projectConfig;
165
+ });
166
+ }
167
+
168
+ module.exports = (config, { iosPacks = [] } = {}) =>
169
+ withGodotPacks(withGodotAndroid(config), iosPacks);
@@ -0,0 +1,95 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+ #include <string_view>
5
+ #include <utility>
6
+ #include <vector>
7
+
8
+ namespace rn_godot {
9
+
10
+ struct AppleRendererSelection {
11
+ std::string_view driver;
12
+ std::string_view method;
13
+ std::string_view error;
14
+ };
15
+
16
+ // Choose before engine creation; an unsupported explicit request never retries.
17
+ constexpr AppleRendererSelection select_apple_renderer(bool simulator,
18
+ std::string_view driver = {}, std::string_view method = {}) {
19
+ if (driver.empty()) {
20
+ driver = method == "gl_compatibility" ? "opengl3" : (simulator ? "opengl3" : "metal");
21
+ }
22
+ const bool opengl = driver.starts_with("opengl3");
23
+ if (method.empty()) {
24
+ method = opengl ? "gl_compatibility" : "mobile";
25
+ }
26
+ if (simulator && driver == "metal") {
27
+ return {driver, method, "Metal is unavailable in this iOS Simulator slice. Use opengl3/gl_compatibility, or an iPhone/iPad device for Metal."};
28
+ }
29
+ if (opengl && method != "gl_compatibility") {
30
+ return {driver, method, "OpenGL rendering requires gl_compatibility."};
31
+ }
32
+ if (driver == "metal" && method == "gl_compatibility") {
33
+ return {driver, method, "Metal rendering requires mobile or forward_plus."};
34
+ }
35
+ return {driver, method, {}};
36
+ }
37
+
38
+ struct AppleRendererArguments {
39
+ std::string requested_driver;
40
+ std::string requested_method;
41
+ std::string driver;
42
+ std::string method;
43
+ std::string error;
44
+ };
45
+
46
+ inline AppleRendererArguments configure_apple_renderer(std::vector<std::string> &args, bool simulator) {
47
+ AppleRendererArguments result;
48
+ std::vector<std::string> normalized;
49
+ bool has_driver = false;
50
+ bool has_method = false;
51
+ for (size_t i = 0; i < args.size(); ++i) {
52
+ bool is_driver = args[i] == "--rendering-driver" || args[i].starts_with("--rendering-driver=");
53
+ bool is_method = args[i] == "--rendering-method" || args[i].starts_with("--rendering-method=");
54
+ if (!is_driver && !is_method) {
55
+ normalized.push_back(args[i]);
56
+ continue;
57
+ }
58
+ const std::string option = is_driver ? "--rendering-driver" : "--rendering-method";
59
+ std::string value;
60
+ if (args[i] == option) {
61
+ if (i + 1 == args.size() || args[i + 1].starts_with("--")) {
62
+ result.error = option + " requires a value.";
63
+ return result;
64
+ }
65
+ value = args[++i];
66
+ } else {
67
+ value = args[i].substr(option.size() + 1);
68
+ }
69
+ if (value.empty()) {
70
+ result.error = option + " requires a value.";
71
+ return result;
72
+ }
73
+ if (is_driver) {
74
+ has_driver = true;
75
+ result.requested_driver = value;
76
+ } else {
77
+ has_method = true;
78
+ result.requested_method = value;
79
+ }
80
+ normalized.insert(normalized.end(), {option, value});
81
+ }
82
+ const auto selection = select_apple_renderer(simulator, result.requested_driver, result.requested_method);
83
+ result.driver = selection.driver;
84
+ result.method = selection.method;
85
+ result.error = selection.error;
86
+ if (!result.error.empty()) {
87
+ return result;
88
+ }
89
+ if (!has_driver) normalized.insert(normalized.end(), {"--rendering-driver", result.driver});
90
+ if (!has_method) normalized.insert(normalized.end(), {"--rendering-method", result.method});
91
+ args = std::move(normalized);
92
+ return result;
93
+ }
94
+
95
+ } // namespace rn_godot
@@ -0,0 +1,126 @@
1
+ /**************************************************************************/
2
+ /* GodotModule.h */
3
+ /**************************************************************************/
4
+ /* Copyright (c) 2024-2025 Slay GmbH */
5
+ /* */
6
+ /* Permission is hereby granted, free of charge, to any person obtaining */
7
+ /* a copy of this software and associated documentation files (the */
8
+ /* "Software"), to deal in the Software without restriction, including */
9
+ /* without limitation the rights to use, copy, modify, merge, publish, */
10
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
11
+ /* permit persons to whom the Software is furnished to do so, subject to */
12
+ /* the following conditions: */
13
+ /* */
14
+ /* The above copyright notice and this permission notice shall be */
15
+ /* included in all copies or substantial portions of the Software. */
16
+ /* */
17
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
18
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
19
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
20
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
21
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
22
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
23
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
+ /**************************************************************************/
25
+
26
+ #pragma once
27
+
28
+ #include <godot_cpp/classes/godot_instance.hpp>
29
+ #include <godot_cpp/classes/rendering_native_surface.hpp>
30
+
31
+ #include <atomic>
32
+ #include <cstdint>
33
+ #include <future>
34
+ #include <mutex>
35
+ #include <optional>
36
+ #include <utility>
37
+
38
+ struct PlatformData {};
39
+
40
+ class GodotModule {
41
+ godot::GodotInstance *_instance = nullptr;
42
+ PlatformData *_data = nullptr;
43
+
44
+ std::mutex _mutex;
45
+ std::atomic<uint64_t> _instanceGeneration{ 0 };
46
+ uint64_t _lastInstanceGeneration = 0; // Godot thread only.
47
+
48
+ std::function<void(const char *, bool)> logFunction;
49
+
50
+ GodotModule(PlatformData *data) :
51
+ _data(data) {}
52
+
53
+ godot::GodotInstance *get_or_create_instance_on_godot_thread(std::vector<std::string> args);
54
+ void destroy_instance_on_godot_thread();
55
+
56
+ public:
57
+ static GodotModule *get_singleton();
58
+
59
+ godot::GodotInstance *get_or_create_instance(std::vector<std::string> args);
60
+
61
+ // Only use the returned binding on the Godot thread, where Stop is serialized.
62
+ godot::GodotInstance *get_instance() {
63
+ std::unique_lock lock(_mutex);
64
+ return _instance;
65
+ }
66
+
67
+ void destroy_instance();
68
+
69
+ godot::Ref<godot::RenderingNativeSurface> get_main_rendering_surface();
70
+
71
+ void *get_main_rendering_layer();
72
+
73
+ godot::Callable create_callable(std::function<void(const godot::Variant **, int, godot::Variant &, GDExtensionCallError &)> f);
74
+
75
+ double get_content_scale_factor();
76
+
77
+ void focus_out();
78
+
79
+ void focus_in();
80
+
81
+ bool is_paused();
82
+
83
+ void pause();
84
+
85
+ void resume();
86
+
87
+ void appPause();
88
+
89
+ void appResume();
90
+
91
+ void updateState();
92
+
93
+ void registerWindowUpdateCallback(std::string name, void *handle, std::function<void(bool)> f, void *ref);
94
+ void unregisterWindowUpdateCallback(void *handle);
95
+
96
+ void updateWindow(std::string name, bool adding);
97
+
98
+ void updateWindows(bool adding);
99
+
100
+ void runOnGodotThread(std::function<void()> f, bool wait = false);
101
+
102
+ uint64_t get_instance_generation() const {
103
+ return _instanceGeneration.load();
104
+ }
105
+
106
+ void runWithInstance(uint64_t generation, std::function<void()> f) {
107
+ runOnGodotThread([this, generation, f = std::move(f)]() {
108
+ if (generation != 0 && generation == get_instance_generation() &&
109
+ _instance && _instance->is_started()) {
110
+ f();
111
+ }
112
+ });
113
+ }
114
+
115
+ void iterate(std::optional<uint64_t> frameGeneration = std::nullopt);
116
+
117
+ void set_log_callback(std::function<void(const char *, bool)> lf) {
118
+ logFunction = lf;
119
+ }
120
+
121
+ void log(const char *l, bool err) {
122
+ if (logFunction) {
123
+ logFunction(l, err);
124
+ }
125
+ }
126
+ };
@@ -0,0 +1,52 @@
1
+ /**************************************************************************/
2
+ /* LibGodotABI.h */
3
+ /**************************************************************************/
4
+ /* LibGodot C ABI used by the native bridge. */
5
+ /* Keep this bridge-local declaration in sync with the selected LibGodot headers. */
6
+ /**************************************************************************/
7
+
8
+ #pragma once
9
+
10
+ #include <gdextension_interface.h>
11
+ #include <godot_cpp/variant/string.hpp>
12
+ #include <godot_cpp/variant/string_name.hpp>
13
+
14
+ #include <stdbool.h>
15
+
16
+ // Generated builtin layouts depend on the target architecture. Mixing ARM32
17
+ // headers with an ARM64 library corrupts memory even when the C ABI matches.
18
+ static_assert(sizeof(godot::StringName) == sizeof(void *),
19
+ "LibGodot godot-cpp StringName headers do not match the target ABI. Use headers generated for this architecture.");
20
+ static_assert(sizeof(godot::String) == sizeof(void *),
21
+ "LibGodot godot-cpp String headers do not match the target ABI. Use headers generated for this architecture.");
22
+
23
+ #if defined(__ANDROID__) || defined(ANDROID)
24
+ #include <jni.h>
25
+ #endif
26
+
27
+ using RNLibGodotLogCallbackData = void *;
28
+ using RNLibGodotLogCallbackFunction = void (*)(RNLibGodotLogCallbackData p_data, const char *p_log_message, bool p_err);
29
+
30
+ using RNLibGodotCreateFunction = GDExtensionObjectPtr (*)(
31
+ int p_argc,
32
+ char *p_argv[],
33
+ GDExtensionInitializationFunction p_init_func,
34
+ RNLibGodotLogCallbackFunction p_log_func,
35
+ RNLibGodotLogCallbackData p_log_data);
36
+
37
+ using RNLibGodotDestroyFunction = void (*)(GDExtensionObjectPtr p_godot_instance);
38
+
39
+ #if defined(__ANDROID__) || defined(ANDROID)
40
+ using RNLibGodotCreateAndroidFunction = GDExtensionObjectPtr (*)(
41
+ int p_argc,
42
+ char *p_argv[],
43
+ GDExtensionInitializationFunction p_init_func,
44
+ RNLibGodotLogCallbackFunction p_log_func,
45
+ RNLibGodotLogCallbackData p_log_data,
46
+ JNIEnv *p_env,
47
+ jobject p_asset_manager,
48
+ jobject p_net_utils,
49
+ jobject p_directory_access_handler,
50
+ jobject p_file_access_handler,
51
+ jobject p_godot_io_wrapper);
52
+ #endif