Tạo plugin mới
Mọi plugin theo cùng một chuẩn: cùng cấu trúc thư mục, cùng quy ước đặt tên, cùng cách export. plugins/nativeutils là bản mẫu tham chiếu.
Dùng Claude Code
Repo có sẵn skill leono-new-plugin trong .claude/skills/. Chỉ cần mô tả bằng lời:
tạo plugin Firebase Analytics + Remote Config
port plugin IAP từ super-godot-plugins sang
Skill sẽ chốt API cùng bạn, sinh khung, viết code Android và iOS, thêm nút vào demo, viết README và trang tài liệu.
Sinh khung bằng tay
python .claude/skills/leono-new-plugin/scripts/new_plugin.py firebase
python .claude/skills/leono-new-plugin/scripts/new_plugin.py iap --pascal IAP --autoload Billing
Script tạo đủ 13 file với tên đã thay sẵn, kèm ví dụ một hàm đồng bộ (get_example) và một hàm bất đồng bộ (request_example → signal example_finished). Gradle tự nhận module mới.
Quy ước
| Thành phần | Giá trị |
|---|---|
| Thư mục / Java package | plugins/<tên>/ · com.leono.<tên> |
| Singleton native | Leono<Tên> |
| Thư mục addon | addons/leono_<tên>/ |
| AAR | bin/android/leono_<tên>.aar |
| xcframework | bin/ios/leono_<tên>.ios.template_{debug,release}.xcframework |
| GDExtension entry | leono_<tên>_init |
| Project Settings | leono/<tên>/<key> |
| Tên hàm / signal | snake_case, giống hệt trên Android và iOS |
Checklist
- Chốt APITên singleton, autoload, hàm, signal, dữ liệu trả về — chung cho 2 nền tảng. Thứ Godot đã có thì chuyển tiếp, không viết native.
- AndroidKotlin
@UsedByGodot fun snake_case(). Signal emit quarunOnRenderThread, thao tác UI quarunOnUiThread. Thư viện Maven chỉ khai báo trongdeps.json. - iOSObjC++ bind hàm trong
_bind_methods, emit signal trên main thread. Framework/Info.plist thêm trong_export_begincủaplugin.gd. - AutoloadFallback cho editor, hàm async dùng được với
await, connect signal native theo tên. Tính năng nhạy cảm chính sách là setting opt-in, mặc định tắt. - DemoBật plugin trong
demo/project.godot, thêm nút trongdemo/main.gd, mở rộng_self_check(). - Tài liệuREADME plugin; trang
docs/plugins/<tên>.html(copy từ trang NativeUtils); thêm vàoNAVvàAPItrongdocs/assets/docs.js; thêm thẻ ở trang chủ; chạydeploy_docs.batđể đưa lên addons.leonogames.com. - Build & kiểm tra
build_android.bat <tên>, self-check headless; iOS build trên Mac bằngscripts/build_ios.sh <tên>.
Thêm trang tài liệu
Sidebar, tìm kiếm và nút Trước/Tiếp đều sinh từ cấu hình trong docs/assets/docs.js:
{ title: 'Plugins', items: [
{ id: 'nativeutils', title: 'NativeUtils', href: 'plugins/nativeutils.html', tag: 'v1.0' },
{ id: 'firebase', title: 'Firebase', href: 'plugins/firebase.html', tag: 'v0.1' }, // thêm dòng này
] },
Trang mới đặt <body data-page="firebase" data-root="../"> và các thẻ .method có id trùng tên hàm để tìm kiếm nhảy đúng chỗ.