# Godot 3 {#godot-3}

تستهدف إضافة `zokogames` (‏`packages/sdk-engines/godot3/addons/zokogames`) تصديرات HTML5 في **Godot 3** (المستهدف 3.5 و3.6 LTS، ويُفترض أن يعمل 3.3 و3.4، ولا يُدعم 3.0 إلى 3.2). لها الواجهة العامة نفسها كما في [إضافة Godot 4](https://docs.zokogames.com/ar/engines/godot): الـ autoload نفسه `ZokoGames`، وأسماء الدوال نفسها، والإشارات نفسها، فيمكن للمشروع أن ينتقل بين الإضافتين. كُتبت بـ GDScript 1 (بلا `await` وبلا lambdas) وتستدعي SDK بلغة JavaScript عبر الكائن المفرد `JavaScript`، باستخدام جسر صغير (`window.ZokoBridge`) معرَّف في غلاف HTML الخاص بالتصدير. وخارج المتصفح (في المحرر أو تشغيل على سطح المكتب) يجيب محاكٍ مدمج بدلًا منه، فتعمل الشيفرة نفسها في كل مكان. المصطلحات مثل "midgame" و"rewarded" موجودة في [المسرد](https://docs.zokogames.com/ar/getting-started/glossary).

> [!NOTE]
> الحالة (1.8.0): شُغِّل دون واجهة في محرر Godot 3.6.3 الرسمي على macOS. تُستورد الإضافة دون أخطاء أو تحذيرات (التحذيرات تُعامل كأخطاء)، وتفعيل الـplugin يسجّل الـautoload، وكل دالة عامة وإشارة تتصرف كما هو موثق في وضع المحاكي، ويحتوي تصدير HTML5 على الجسر ويعمل في متصفح. لم يُتحقق من Godot 3.3 إلى 3.5، ولا من تشغيل مقابل البوابة الفعلية. أرسل إصدار Godot ونص الخطأ بدقة إلى [الدعم](https://docs.zokogames.com/ar/business/support) إذا فشل أول استيراد.

على Godot 4 ترفض هذه الإضافة البدء (يفشل `init()` بالرمز `unsupportedEngine`)؛ استخدم هناك [صفحة Godot 4](https://docs.zokogames.com/ar/engines/godot).

## التثبيت {#install}

نزّل إضافة Godot 3: ‏[/sdk-engines/zokogames-godot3-1.8.1.zip](https://www.zokogames.com/sdk-engines/zokogames-godot3-1.8.1.zip) (الملفات نفسها الموجودة في المجلد داخل المستودع).

الملف [/sdk-engines/godot3.zip](https://www.zokogames.com/sdk-engines/godot3.zip) هو دائمًا أحدث إصدار. المجاميع الاختبارية: [`/sdk-engines/SHA256SUMS`](https://www.zokogames.com/sdk-engines/SHA256SUMS). فهرس كل حزم المحركات مع الإصدار والحجم وSHA-256: ‏[`/sdk-engines/engines.json`](https://www.zokogames.com/sdk-engines/engines.json). المصدر منشور أيضًا في [github.com/zokogames/zokogames-godot3](https://github.com/zokogames/zokogames-godot3). وهو متاح أيضًا في Godot Asset Library (المعرّف 5620): ابحث عن ZokoGames في تبويب AssetLib في المحرر (Godot 3)، أو ثبّت من ملف zip.

1. فُكّ ضغط التنزيل وانسخ مجلد `addons/zokogames` منه إلى مجلد `res://addons/` في مشروعك (أنشئ `addons` إن لم يكن موجودًا). يحتوي `plugin.cfg` و`plugin.gd` و`zokogames.gd` (الـ autoload) و`zoko_banner.gd` و`export/zokogames_shell.html`.
2. **Project > Project Settings > Plugins**: فعّل **ZokoGames**. يسجّل هذا الـ autoload باسم `ZokoGames` (‏`res://addons/zokogames/zokogames.gd`) وإعدادات `zokogames/simulator/*`.
3. **Project > Export**: أضف إعدادًا مسبقًا **HTML5** واضبط **Custom HTML Shell** (تبويب Options > HTML) على `res://addons/zokogames/export/zokogames_shell.html`. يحمّل الغلاف `https://sdk.zokogames.com/zokogames-sdk-v1.js` قبل المحرك، وينشئ `window.ZokoBridge`، ويبلّغ شريط التحميل في البوابة بتنزيل المحرك. ومع غلافك الخاص أضف وسم السكربت إلى `<head>` وانسخ كتلة الجسر من الغلاف المرفق.
4. نفّذ `yield(ZokoGames.init_async(), "completed")` مرة واحدة عند بدء التشغيل، قبل أي استدعاء آخر.
5. اختياري: أضف عقدة `ZokoBanner` (‏`zoko_banner.gd`) فوق المساحة التي تستطيع تخصيصها لبانر. يحتوي مجلد `examples/` المجاور للإضافة `zoko_demo.gd` و`zoko_store.gd`.

> [!IMPORTANT]
> بدون الغلاف المخصص لا يوجد `window.ZokoBridge`. تسجّل الإضافة تحذيرًا وتتراجع إلى المحاكي، فتعمل اللعبة لكنها لا تستخدم إعلانات ولا مستخدمين ولا حفظًا حقيقيًا.

### الحزمة التمهيدية {#starter-kit}

مشروع Godot 3 جاهز فيه الإضافة والغلاف ومشهد عرض صغير: ‏[/starter-kits/godot3.zip](https://www.zokogames.com/starter-kits/godot3.zip). راجع صفحة [الحزم التمهيدية](https://docs.zokogames.com/ar/getting-started/starter-kits).

## ما يختلف عن Godot 4 {#what-differs-from-godot-4}

| Godot 4 | Godot 3 |
| --- | --- |
| `await ZokoGames.get_user_async()` | `yield(ZokoGames.get_user_async(), "completed")`، وتعيد Dictionary نفسه |
| `callback: Callable` | `callback`: من نوع `FuncRef`، أي `funcref(self, "_on_done")` |
| `ZokoGames.ad_started.connect(f)` | `ZokoGames.connect("ad_started", self, "_on_ad_started")` |
| توقف الإضافة الشجرة مؤقتًا وتكتم ناقل Master أثناء تشغيل إعلان وتطبّق إعداد الكتم في البوابة (`pause_game_during_ads` و`mute_audio_during_ads` و`follow_portal_mute`، وكلها `true`) | الخصائص والقيم الافتراضية نفسها؛ وتحتاج عُقدك التي يجب أن تستجيب أثناء الإعلان إلى `pause_mode = PAUSE_MODE_PROCESS` |
| `JavaScriptBridge` | `JavaScript` |

يعيد كل استدعاء `_async` كائن طلب (فيه `id` و`done` و`result` والإشارة `completed(result)`)، وتعطي `yield(..., "completed")` الـ Dictionary الناتج. يكتمل كل طلب في إطار لاحق، فلا يمكن أن تفوت الـ `yield` النتيجة.

## سكربت يعمل {#a-working-script}

ضع هذا في سكربت على عقدة في مشهدك الأول (أو في autoload خاص بك). يغطي التهيئة وإعلان منتصف اللعبة وإعلان المكافأة وبدء اللعب وإيقافه والحفظ والتحميل ونتيجة لوحة المتصدرين.

```gdscript
extends Node

func _ready() -> void:
	pause_mode = PAUSE_MODE_PROCESS                            # keep running while an ad pauses the tree
	var res = yield(ZokoGames.init_async(), "completed")
	if not res.ok:
		push_warning("ZokoGames unavailable: %s" % res.error.code)
	# The addon pauses the tree and mutes Master during an ad, and follows the portal's mute setting
	# (pause_game_during_ads, mute_audio_during_ads, follow_portal_mute): no ad or mute handlers needed.
	var level = int(ZokoGames.data_get_item("level", "1"))     # load: synchronous Strings
	start_game(level)

# Call when the player takes control, and when play stops.
func on_play_start() -> void:
	if ZokoGames.is_available():
		ZokoGames.gameplay_start()
func on_play_stop() -> void:
	if ZokoGames.is_available():
		ZokoGames.gameplay_stop()

func show_midgame() -> void:
	var res = yield(ZokoGames.request_ad_async("midgame"), "completed")   # completes after the ad is over
	if not res.ok:
		print("no ad: ", res.error.code)                       # adCooldown, unfilled, adblock ...

func on_reward_button() -> void:
	var res = yield(ZokoGames.request_ad_async("rewarded"), "completed")
	if res.ok:
		grant_reward()                                         # reward only after the ad finished

func save_progress(level: int) -> void:
	var r = ZokoGames.data_set_item("level", str(level))       # synchronous, uploaded in the background
	if not r.ok:
		push_warning(r.error.code)                             # for example dataLimitExceeded

func submit_score(score: float) -> void:
	var user = yield(ZokoGames.get_user_async(), "completed")
	if not user.ok or user.result == null:
		return                                                 # guests are not ranked
	var r = yield(ZokoGames.submit_score_async("", score), "completed")   # "" works only on a board WITHOUT an encryption key
	if not r.ok:
		print(r.error.code)

func start_game(_level: int) -> void:
	pass
func grant_reward() -> void:
	pass
```

## نتائج لوحة المتصدرين والتشفير {#leaderboard-scores-and-encryption}

اللوحة **ذات** مفتاح التشفير لا تحتسب إلا حمولة مشفّرة بشكل صحيح ([لوحات المتصدرين](https://docs.zokogames.com/ar/sdk/leaderboards#client-submission)). منذ الإضافة 1.8.0 تختم `encrypt_score_async(score, KEY)` النتيجة بمفتاح لوحتك وتعيد الحمولة لـ`submit_score_async`؛ ولا تعمل `""` إلا للوحة بلا مفتاح.

```gdscript
const BOARD_KEY = "paste-your-board-key-here"

func submit_secure_score(score: float) -> void:
	var sealed = yield(ZokoGames.encrypt_score_async(score, BOARD_KEY), "completed")
	if not sealed.ok:
		print(sealed.error.code)                               # userNotAuthenticated for guests, invalidArgument for a bad score or key
		return
	var r = yield(ZokoGames.submit_score_async(sealed.result, score), "completed")
	if not r.ok:
		print(r.error.code)
```

الوسيط الثالث الاختياري `earned_at` (بالميلي ثانية بحسب Unix، والافتراضي 0 للعب مباشر) يختم النسخة المؤجلة من النتيجة. والمفتاح الموجود داخل البناء يمنع العبث العارض لا اللاعب المصمّم: وللرهانات الحقيقية احسب النتيجة على خادمك واستخدم واجهة الخادم.

## كيف تعمل الاستدعاءات {#how-calls-work}

<!-- search: headings-only -->

أسماء GDScript بصيغة snake_case. لكل طريقة تخاطب البوابة شكلان:

| الشكل | مثال | استخدمه من أجل |
| --- | --- | --- |
| رد نداء | `ZokoGames.get_user(callback)` | استدعاءات أطلق وانسَ. الـ `FuncRef` اختياري وأخير، عدا في `store_get_catalog_items(callback, limit, offset)` و`store_get_player_inventory(callback, limit, offset)` حيث يأتي أولًا، وفي `get_user_token(signing_key_type, callback)`. |
| طلب | `yield(ZokoGames.get_user_async(), "completed")` | شيفرة متسلسلة. ينتهي الاسم بـ `_async`. |

كلاهما يسلّم Dictionary هو `{ "ok": true, "result": <value> }` أو `{ "ok": false, "error": { "code": "...", "message": "..." } }` (تأخذ `request_ad` بدلًا من ذلك Dictionary من الـ FuncRef). تعيش كل الطرائق مباشرة على الـ autoload؛ ولا توجد كائنات فرعية `ad.` أو `game.` أو `user.`.

| JavaScript | GDScript |
| --- | --- |
| `SDK.init()` | `yield(ZokoGames.init_async(), "completed")` or `ZokoGames.init(callback)`; signal `initialized(ok)` |
| `SDK.environment` | `ZokoGames.environment` (`"local"`, `"zokogames"` or `"disabled"`), `ZokoGames.is_available()`, `ZokoGames.is_simulated`, `ZokoGames.is_qa_tool`, `ZokoGames.VERSION` |
| `SDK.ad.requestAd(type, cbs)` | `ZokoGames.request_ad(type, {"ad_started": f, "ad_finished": f, "ad_error": f})` (FuncRefs) or `yield(ZokoGames.request_ad_async(type), "completed")` |
| `SDK.ad.hasAdblock()` | `ZokoGames.has_adblock(callback)` or `yield(ZokoGames.has_adblock_async(), "completed")` |
| `SDK.banner.requestBanner(...)` | `yield(ZokoGames.request_banner_async(id, width, height, window_rect), "completed")` |
| `SDK.banner.requestResponsiveBanner(id)` | `yield(ZokoGames.request_responsive_banner_async(id, window_rect), "completed")` |
| `SDK.banner.clearBanner(id)` / `clearAllBanners()` | `ZokoGames.clear_banner(id)` / `ZokoGames.clear_all_banners()` |
| `SDK.banner.hideAllBanners()` / `showAllBanners()` (1.8.0) | `ZokoGames.hide_all_banners()` / `ZokoGames.show_all_banners()` (and `_async`) |
| `SDK.game.gameplayStart()` / `gameplayStop()` | `ZokoGames.gameplay_start()` / `ZokoGames.gameplay_stop()` |
| `SDK.game.loadingStart()` / `loadingStop()` / `loadingProgress(n)` | `ZokoGames.loading_start()` / `loading_stop()` / `loading_progress(n)` |
| `SDK.game.happytime()` | `ZokoGames.happytime()` |
| `SDK.game.reportGameCompletedPercentage(n)` | `ZokoGames.report_game_completed_percentage(n)` |
| `SDK.game.setGameContext(obj)` / `clearGameContext()` | `ZokoGames.set_game_context(dict)` / `ZokoGames.clear_game_context()` |
| `SDK.game.updateRoom(u)` / `leftRoom()` | `ZokoGames.update_room(dict)` / `ZokoGames.left_room()` |
| `SDK.game.inviteLink(p)` / `getInviteParam(k)` | `yield(ZokoGames.invite_link_async(dict), "completed")` / `ZokoGames.get_invite_param(key)` |
| `SDK.game.showInviteButton(p)` / `hideInviteButton()` | `yield(ZokoGames.show_invite_button_async(dict), "completed")` / `ZokoGames.hide_invite_button()` |
| `SDK.game.settings` | `ZokoGames.settings` (`disableChat`, `muteAudio`), signal `settings_changed` |
| `SDK.game.isOffline`, offline listener | `ZokoGames.is_offline`, signal `offline_changed(offline)` |
| `SDK.game.isInstantMultiplayer` / `inviteParams` | `ZokoGames.is_instant_multiplayer` (alias `is_instant_join`) / `ZokoGames.invite_params`, signal `join_room(params)` |
| `SDK.user.isUserAccountAvailable` / `systemInfo` | `ZokoGames.is_user_account_available` / `ZokoGames.system_info` |
| `SDK.user.getUser()` | `yield(ZokoGames.get_user_async(), "completed")` |
| `SDK.user.getUserToken(opts)` | `yield(ZokoGames.get_user_token_async(signing_key_type), "completed")` |
| `SDK.user.showAuthPrompt()` | `yield(ZokoGames.show_auth_prompt_async(), "completed")`, signal `auth_changed(user)` |
| `SDK.user.showAccountLinkPrompt()` | `yield(ZokoGames.show_account_link_prompt_async(), "completed")` |
| `SDK.user.listFriends(opts)` | `yield(ZokoGames.list_friends_async(page, size), "completed")` |
| `SDK.user.submitScore(opts)` | `yield(ZokoGames.submit_score_async(encrypted_score, score), "completed")` |
| `SDK.user.encryptScore(score, key)` (1.8.0) | `yield(ZokoGames.encrypt_score_async(score, key), "completed")` |
| `SDK.game.gameId` (1.8.0) | `ZokoGames.game_id` / `get_game_id()` |
| `SDK.data.mirrorIndexedDB()` (1.8.0) | HTML shell option `window.ZOKO_MIRROR_INDEXEDDB = true` (Head Include); `ZokoGames.stop_mirror_indexed_db()` |
| `SDK.data.getItem(k)` / `setItem(k, v)` | `ZokoGames.data_get_item(key, default)` / `ZokoGames.data_set_item(key, value)`; also `data_has_key`, `data_remove_item`, `data_clear` (all synchronous) |
| `SDK.store.*` | `store_get_catalog_items_async`, `store_get_player_inventory_async`, `store_buy_item_async(item_id)`, `store_consume_item_async(sku, qty)`, `store_get_purchase_token_async()`, `is_store_available`, `store_set_sandbox(bool)` (synchronous); signals `purchase_completed(item_id)`, `purchase_failed(error)` |
| `SDK.achievements.list()` / `unlock(key)` / `onUnlock` | `yield(ZokoGames.achievements_list_async(), "completed")` / `achievements_unlock_async(key)`, signal `achievement_unlocked(achievement)`؛ راجع [الإنجازات](https://docs.zokogames.com/ar/sdk/achievements) |
| `SDK.analytics.trackOrder(p, o)` | `yield(ZokoGames.track_order_async(provider, order), "completed")` |
| `SDK.analytics.track(name, params)` (1.7.0) | `ZokoGames.track(name, params)` / `track_async(name, params)` |

الإشارات على الـ autoload: ‏`initialized` و`ad_started` و`ad_finished` و`ad_error(error)` و`auth_changed` و`settings_changed` و`offline_changed` و`join_room` و`purchase_completed` و`purchase_failed`. اربطها بـ `ZokoGames.connect("ad_finished", self, "_on_ad_finished")`. رموز الأخطاء في `ZokoGames.ERROR_CODES` (‏Dictionary مفتاحه الوحدة، مثل `ZokoGames.ERROR_CODES.ad`)؛ وتختبر `ZokoGames.has_error_code(res, "purchaseCancelled")` نتيجة ما. الرمز `unsupportedEngine` إضافي في هذه الإضافة.

**وضع الأطفال.** تكون `ZokoGames.settings.get("kidsMode", false)` بقيمة true عندما تعمل اللعبة في وضع الأطفال (لعبة تحمل علامة الأطفال، أو لاعب في وضع الأطفال)؛ أخفِ حينها الدردشة والغرف وطلبات تسجيل الدخول وشاشات المتجر. واستمر أيضًا في احترام `ZokoGames.settings.disableChat`. لاختباره، فعّل `zokogames/simulator/kids_mode`. راجع [وضع الأطفال](https://docs.zokogames.com/ar/guides/kids-mode).

## حفظ سحابي لـ user:// (مرآة IndexedDB) {#cloud-save-for-user-indexeddb-mirror}

يحتفظ تصدير الويب بملفات `user://` في IndexedDB الخاصة بالمتصفح (‏`/userfs`). ولحفظها في الحفظ السحابي للاعب، أضف هذا السطر في **Export > HTML > Head Include**:

```html
<script>window.ZOKO_MIRROR_INDEXEDDB = true;</script>
```

يستعيد الغلاف النسخة السحابية قبل بدء المحرك ويرفع عمليات الكتابة اللاحقة خلال بضع ثوانٍ. يجب ألا تتجاوز البيانات المنعكسة 1 MiB، ويجب أن تكون وحدة البيانات مفعّلة للعبة. توقف `ZokoGames.stop_mirror_indexed_db()` الانعكاس. أما `ZokoGames.mirror_local_storage({"prefix": "save_"})` فهي المرآة المنفصلة لـ `localStorage` في جانب JavaScript؛ ولا ترى ملفات `user://`.

## قناة بيانات الغرفة {#room-data-channel}

تتيح قناة بيانات الغرفة (SDK 1.3.0) للاعبي غرفة واحدة تبادل رسائل JSON صغيرة ومشاركة حالة صغيرة يكتبها المضيف وحده. وهي لبيانات اللعبة لا للدردشة النصية. الحدود ورموز الأخطاء هي نفسها في Godot 4: راجع [وحدة game](https://docs.zokogames.com/ar/sdk/game#room-data-channel) و[دليل اللعب المتعدد](https://docs.zokogames.com/ar/guides/multiplayer-invites#6-exchange-game-data-in-the-room). تعبر الحمولات الجسر بصيغة JSON (تعود الأرقام بنوع `float`؛ حوّلها بـ `int()`).

| JavaScript | Godot |
| --- | --- |
| `room.send(data, { to })` | `ZokoGames.room_send(data, to, cb)` / `room_send_async(data, to)` / `room_send_to(member_id, data, cb)` |
| `room.onMessage(cb)` | الإشارة `room_message(message)` (‏`from` و`data` و`direct` و`seq` و`ts`) |
| `room.setState(patch)` | `room_set_state(patch, cb)` / `room_set_state_async(patch)` (القيمة `null` تحذف المفتاح) |
| `room.getState()`, `room.onState(cb)` | `room_get_state()` و`room_get_state_value(key, default)`؛ والإشارة `room_state(state, change)` |
| `room.members()`, `room.onMembers(cb)` | `room_get_members()`؛ والإشارة `room_members(members)` |
| `room.isHost()`, `room.onHostChange(cb)`, `room.selfId` | `room_is_host()`؛ والإشارة `room_host_changed(host_id, is_host)`؛ و`room_self_id()` |
| `room.addLeftListener(cb)` (1.7.0) | الإشارة `room_left(reason, room_id)` |
| `room.onError(cb)` | الإشارة `room_error(error)` |

```gdscript
extends Node

func _ready() -> void:
	yield(ZokoGames.init_async(), "completed")
	ZokoGames.connect("room_message", self, "_on_message")
	ZokoGames.connect("room_host_changed", self, "_on_host_changed")
	yield(ZokoGames.update_room_async({"roomId": "match-1", "isJoinable": true}), "completed")

func _on_host_changed(_host_id, is_host) -> void:
	if is_host:
		ZokoGames.room_set_state({"turn": "X"})

func _on_message(message) -> void:
	print(message.from, " played cell ", int(message.data.cell))

func play_cell(cell: int) -> void:
	yield(ZokoGames.room_send_async({"cell": cell, "mark": "X"}), "completed")
```

## البانرات {#banners}

مستطيلات البانر بوحدات بكسل النافذة. ضع عقدة `ZokoBanner` (من نوع `Control`) حيث ينبغي أن يظهر البانر؛ فهي تبلّغ عن مستطيلها على الشاشة (مع احتساب وضع التمدد)، وتطلب البانر في `_ready`، وتمسح نفسها عند مغادرة الشجرة.

| الخاصية | المعنى |
| --- | --- |
| `container_id` | معرّف البانر، الافتراضي `zoko-banner`. |
| `size_mode` | ‏`responsive` (أكبر حجم يناسب) أو أحد `728x90` أو `300x250` أو `320x50` أو `468x60` أو `320x100`. |
| `request_on_ready` | اطلب تلقائيًا في `_ready`. |
| `show_simulator_placeholder` | ارسم مستطيلًا نائبًا أثناء إجابة المحاكي. |

يدويًا: ‏`yield(ZokoGames.request_responsive_banner_async("menu", $BannerSlot.get_global_rect()), "completed")`. اطلب البانرات في شاشات القوائم فقط.

## المشتريات {#purchases}

```gdscript
func buy_first_item() -> void:
	if not ZokoGames.is_store_available:
		return
	var catalog = yield(ZokoGames.store_get_catalog_items_async(), "completed")
	if not catalog.ok or catalog.result.empty():
		return
	var bought = yield(ZokoGames.store_buy_item_async(catalog.result[0].sku), "completed")
	if ZokoGames.has_error_code(bought, "purchaseCancelled"):
		return
	var token = yield(ZokoGames.store_get_purchase_token_async(), "completed")   # send to your server and verify there
```

تحقق من الملكية على خادمك (راجع [المشتريات داخل اللعبة](https://docs.zokogames.com/ar/sdk/purchases)). الملف `examples/zoko_store.gd` هو التدفق الكامل.

## إعدادات تصدير HTML5 المهمة {#html5-export-settings-that-matter}

<!-- search: headings-only -->

- **Custom HTML Shell**: ‏`res://addons/zokogames/export/zokogames_shell.html`، كما سبق. يملأ الـ canvas الإطار، فاستخدم **Canvas Resize Policy** بالقيمة `Adaptive`، وفي Project Settings > Display > Window > Stretch اضبط **Mode** على `2d` أو `viewport` مع aspect بالقيمة `expand` أو `keep`.
- **الخيوط.** ليس في Godot 3 تصدير ويب متعدد الخيوط، فلا شيء تلغي تحديده. صفحات الألعاب غير معزولة عبر الأصول، فاترك أي خيار `SharedArrayBuffer` متوقفًا إن ظهر في بنائك.
- **GDNative.** متوقف. لا تعمل المكتبات الأصلية في بناءات الويب إلا إذا شحنت مكتبة تناسب الويب. **Export With Debug**: متوقف للبناء المرفوع.
- **Focus Canvas on Start**: مفعّل. **Experimental Virtual Keyboard**: مفعّل إن كان في اللعبة إدخال نصي على الهواتف.
- **أسماء الملفات.** صدِّر إلى ملف اسمه `index.html`: تحتاج البوابة إلى `index.html` في جذر الأرشيف، ويسمّي التصدير ملفاته الأخرى على اسمه: `index.js` و`index.wasm` و`index.pck`. **لا** تعِد تسميتها إلى `.br` أو `.gz`: فالمحرك يطلب الأسماء العادية.
- **ضغط الخامات.** فعّل ضغط VRAM لسطح المكتب (S3TC) وللجوال (ETC2) معًا ليجد كل متصفح صيغة.
- **الحجم.** استخدم قالب تصدير مخصصًا مع تعطيل الوحدات غير المستخدمة وأبقِ `.pck` صغيرًا. الحدود: 1,500 ملف، و250 MB بعد فك الضغط، وحوالي 50 MB للتنزيل الأولي (20 MB للجوال).
- **الذاكرة.** لدى متصفحات الجوال كوم صغير؛ حمّل المستويات بـ `ResourceLoader.load_interactive` على شرائح بدلًا من كل الخامات مسبقًا، وحدّد الدقة على الهواتف، راجع [الجوال](https://docs.zokogames.com/ar/guides/mobile).
- **فتح الصوت.** تُبقي المتصفحات الصوت معلّقًا حتى أول نقرة أو ضغطة مفتاح. اعرض شاشة "click to play" وابدأ الموسيقى من ذلك الإدخال لا في `_ready`.
- **ملء الشاشة.** استخدم زر ملء الشاشة في شريط إطار البوابة؛ فـ `OS.window_fullscreen = true` يملأ الشاشة بالـ canvas وحده، فلا تضف زرًا منافسًا.
- **التحميل.** يبلّغ الغلاف أصلًا عن تنزيل المحرك ويستدعي `loadingStop` حين يبدأ المحرك. ولشاشة تحميل أطول داخل اللعبة استدعِ `ZokoGames.loading_start()` و`loading_progress(percent)` و`loading_stop()` بنفسك.

الرفع: **Project > Export**، اختر الإعداد المسبق **HTML5**، وانقر **Export Project...**، واحفظ في مجلد فارغ باسم الملف `index.html`. ضغّط محتويات المجلد في zip بحيث يكون `index.html` في جذر الأرشيف، وارفعه في وحدة تحكم المطوّرين، وشغّل [أداة المعاينة](https://www.zokogames.com/ar/preview) أولًا.

## قواعد الإعلانات {#ad-rules}

لا توجد إعلانات preroll: لا يمكن للعبتك طلب إعلان قبل أن تبدأ. منتصف اللعبة (midgame) هو النوع الوحيد من الإعلانات البينية، لذا يصبح الإعلان البيني (interstitial) أو الفاصل الإعلاني (commercial break) من منصة أخرى إعلان منتصف لعبة (`request_ad("midgame")`)؛ والنوع الآخر الوحيد هو `rewarded`. استدعِ `ZokoGames.gameplay_start()` عندما يتولى اللاعب التحكم: فأول إعلان منتصف لعبة يحتاج إليه (أو 30 ثانية من الوقت المرئي للصفحة)، وفي الوضع المحلي يفشل طلب منتصف اللعبة قبل ذلك بالرمز `adCooldown`. لا تتأثر إعلانات المكافأة بذلك. التفاصيل: [إعلانات الفيديو](https://docs.zokogames.com/ar/sdk/ads#gameplay-first) و[دليل تحقيق الدخل من الإعلانات](https://docs.zokogames.com/ar/guides/ad-monetisation).

## الاختبار محليًا {#test-locally}

- **في المحرر أو تشغيل على سطح المكتب** تكون `ZokoGames.is_simulated` صحيحة. اضبط المحاكي في **Project Settings > zokogames/simulator**: ‏`ad_behaviour` (‏`fill` أو `no_fill` أو `error`) و`ad_duration_seconds` و`adblock` و`disabled` و`account_available` و`logged_in` و`username` و`user_id` و`friend_count` و`mute_audio` و`disable_chat` و`offline` و`store_available` و`verbose`. الحفظ السحابي في `user://zoko_sim_data.json`، والمخزون المحاكى في `user://zoko_sim_inventory.json`. لا يفرض المحاكي فترة التهدئة البالغة ثلاث دقائق لإعلان منتصف اللعبة.
- **تصدير HTML5 على `localhost`.** قدّم مجلد التصدير من خادم ويب محلي (فتح `index.html` من القرص لا يعمل مع WebAssembly). الجسر موجود، فتكون `is_simulated` خطأ وتشغّل SDK بلغة JavaScript [وضعها المحلي](https://docs.zokogames.com/ar/getting-started/local-testing) الخاص.
- **ثم** افتح [أداة المعاينة](https://www.zokogames.com/ar/preview) بعنوانك المحلي وراقب قائمة التحقق وهي تُستوفى.

## مزالق معروفة {#known-pitfalls}

<!-- search: headings-only -->

- **`sdkNotLoaded`.** ليس في الصفحة وسم سكربت SDK؛ استخدم الغلاف المخصص.
- **الـ autoload `ZokoGames` مفقود.** لم تُفعَّل الإضافة.
- **تفشل الاستدعاءات بالرمز `sdkNotInitialized`.** نفّذ `yield(ZokoGames.init_async(), "completed")` أولًا.
- **`unsupportedEngine`.** تشغّل هذه الإضافة على Godot 4؛ استخدم إضافة Godot 4.
- **لا تعود `yield` أبدًا.** تُهمَل `yield` في دالة تُحرَّر قبلها (تغيير مشهد)؛ أبقِ شيفرة الانتظار في عقدة تبقى، أو استخدم شكل رد النداء.
- **تعمل في المحرر لا في المتصفح.** افتح وحدة تحكم المتصفح وتحقق من وجود `window.ZokoBridge` (فالغلاف هو من يعرّفه).
- **تبقى اللعبة متوقفة أو مكتومة بعد إعلان.** غيّر شيء آخر `get_tree().paused` أو ناقل Master أثناء الإعلان. اضبط `pause_game_during_ads` أو `mute_audio_during_ads` على `false` وتولَّ `ad_started` و`ad_finished` و`ad_error` بنفسك. ولا تستخدم `CONNECT_ONESHOT` على `ad_started`: فحين يفشل إعلان لا يُطلَق أبدًا.
- **لا تظهر البانرات أبدًا.** تحتاج عقدة `ZokoBanner` إلى حجم ويجب أن تكون مرئية.
- **حفظات `user://` ليست في السحابة.** استخدم `data_set_item`، أو مرآة IndexedDB أعلاه.

## بلاغات الدردشة ولقطات الشاشة {#chat-reports-and-screenshots}

ترسل `ZokoGames.report_chat({"reportedName": "Trixie", "message": "buy gold", "reason": "spam"}, callback)` (أو `report_chat_async`) بلاغ دردشة. وتستبدل `ZokoGames.set_screenshot_provider(funcref)` الالتقاط الافتراضي لمنفذ العرض (يُسجَّل عند التهيئة بعد `frame_post_draw`)، وتزيل `clear_screenshot_provider()` ما سجّلته. ويقبل محاكي المحرر الاثنين.

## الأحداث المخصصة {#custom-events}

```gdscript
ZokoGames.track("level_complete", {"level": 3, "value": 1250})   # value is summed per event name
```

ينجز الاستدعاء ولا ينتظر نتيجة (fire-and-forget) ولا يرمي استثناءً أبدًا. تجمع البوابة `value` الرقمي لكل اسم حدث، وتعرض الاستدعاءات واللاعبين والمجموع في كتلة **أحداث لعبتك الخاصة** في وحدة تحكم المطوّرين (يتطلب موافقة اللاعب على التحليلات؛ انظر [التحليلات](https://docs.zokogames.com/ar/sdk/analytics#custom-events-track)). يطابق الاسم والمفاتيح `[a-z][a-z0-9_]{0,39}`، وبحد أقصى 10 معاملات. يبلّغ SDK عن الأخطاء غير الملتقطة من تلقاء نفسه، فلا شيء تستدعيه لها.

## التالي {#next}

- افحص بناءك وفق [قواعد التحقق من البناء](https://docs.zokogames.com/ar/requirements/build-validation) و[قائمة تحقق الإطلاق](https://docs.zokogames.com/ar/requirements/checklist).
- الرفع والنشر: [دليل الإرسال](https://docs.zokogames.com/ar/getting-started/submission-walkthrough).
- مشاريع Godot 4: ‏[Godot](https://docs.zokogames.com/ar/engines/godot). المحركات الأخرى والقواعد المشتركة: [نظرة عامة على المحركات](https://docs.zokogames.com/ar/engines/overview).
