### Fetch and Apply Remote Configuration in Godot Source: https://context7.com/playgama/bridge-godot/llms.txt Demonstrates how to retrieve remote configuration settings using the Bridge API. It includes a fallback mechanism to default values if the service is unsupported or the fetch operation fails. ```GDScript extends Node var game_config = {} func _ready(): if Bridge.remote_config.is_supported: load_remote_config() else: print("Remote config not supported") use_default_config() func load_remote_config(): var options = { "clientFeatures": ["premium", "season_1"] } Bridge.remote_config.get(options, funcref(self, "_on_config_loaded")) func _on_config_loaded(success, config): if success: game_config = config print("Remote config loaded:") for key in config: print(" ", key, " = ", config[key]) apply_config() else: print("Failed to load remote config") use_default_config() func apply_config(): var coin_reward = game_config.get("daily_reward_coins", 100) var show_new_feature = game_config.get("enable_new_mode", false) var difficulty = game_config.get("enemy_health_multiplier", 1.0) print("Daily reward: ", coin_reward) print("New feature enabled: ", show_new_feature) print("Difficulty multiplier: ", difficulty) setup_game_with_config(coin_reward, show_new_feature, difficulty) func use_default_config(): game_config = { "daily_reward_coins": 100, "enable_new_mode": false, "enemy_health_multiplier": 1.0 } apply_config() func setup_game_with_config(reward, new_feature, difficulty): pass ``` -------------------------------- ### Initialize Playgama Bridge for Godot Source: https://github.com/playgama/bridge-godot/blob/main/addons/playgama_bridge/template/index.html JavaScript logic to load the Playgama Bridge SDK. It includes a fallback mechanism that switches to a local bridge file if the CDN version fails to load within 2 seconds. ```javascript const GODOT_CONFIG = $GODOT_CONFIG; const ENGINE = new Engine(GODOT_CONFIG); const CANVAS = document.getElementById('canvas'); let bridgeScript = null; let bridgeTimeout = null; let bridgeLoaded = false; function addLocalBridge() { if (bridgeLoaded) return; bridgeLoaded = true; clearTimeout(bridgeTimeout); if (bridgeScript && bridgeScript.parentNode) { bridgeScript.onload = null; bridgeScript.onerror = null; bridgeScript.src = ''; bridgeScript.parentNode.removeChild(bridgeScript); } const scriptElement = document.createElement('script'); scriptElement.src = './playgama-bridge.js'; document.body.appendChild(scriptElement); scriptElement.onload = function() { initializeBridge(); }; } bridgeScript = document.createElement('script'); bridgeScript.src = 'https://bridge.playgama.com/v1/stable/playgama-bridge.js'; bridgeScript.onload = initializeBridge; bridgeScript.onerror = addLocalBridge; bridgeTimeout = setTimeout(() => { console.warn('CDN bridge failed to load within 2 seconds, loading local bridge'); addLocalBridge(); }, 2000); document.head.appendChild(bridgeScript); function initializeBridge() { clearTimeout(bridgeTimeout); bridge.engine = 'godot-3'; bridge.initialize().then(() => { bridge.game.setLoadingProgress(0); ENGINE.startGame({ onProgress: function (current, total) { bridge.game.setLoadingProgress((current / total) * 100); }, }).then(() => { CANVAS.focus(); }); }); } ``` -------------------------------- ### Manage Game Data with Cloud Storage API in GDScript Source: https://context7.com/playgama/bridge-godot/llms.txt Demonstrates how to check for storage support and availability, then implement asynchronous save, load, and delete operations. Uses funcref callbacks to handle the results of storage operations. ```GDScript extends Node func _ready(): # Check storage support and availability var supports_local = Bridge.storage.is_supported(Bridge.StorageType.LOCAL_STORAGE) var supports_cloud = Bridge.storage.is_supported(Bridge.StorageType.PLATFORM_INTERNAL) print("Local storage: ", supports_local, " Cloud: ", supports_cloud) # Check if storage is currently available (ready to use) var local_available = Bridge.storage.is_available(Bridge.StorageType.LOCAL_STORAGE) var cloud_available = Bridge.storage.is_available(Bridge.StorageType.PLATFORM_INTERNAL) print("Local available: ", local_available, " Cloud available: ", cloud_available) # Use default storage type print("Default storage type: ", Bridge.storage.default_type) # Load game data load_game_data() func save_game_data(level, score, coins): var keys = ["level", "score", "coins"] var values = [level, score, coins] Bridge.storage.set(keys, values, funcref(self, "_on_save_complete")) func _on_save_complete(success): if success: print("Game saved successfully") else: print("Save failed") func load_game_data(): var keys = ["level", "score", "coins"] Bridge.storage.get(keys, funcref(self, "_on_load_complete")) func _on_load_complete(success, data): if success: if typeof(data) == TYPE_ARRAY: var level = data[0] if data[0] != null else 1 var score = data[1] if data[1] != null else 0 var coins = data[2] if data[2] != null else 0 print("Loaded: Level ", level, ", Score ", score, ", Coins ", coins) apply_game_data(level, score, coins) else: print("Load failed, using defaults") apply_game_data(1, 0, 0) func delete_save(): Bridge.storage.delete(["level", "score", "coins"], funcref(self, "_on_delete_complete")) func _on_delete_complete(success): print("Delete ", "successful" if success else "failed") func apply_game_data(level, score, coins): # Apply loaded data to game state pass ``` -------------------------------- ### Integrate Leaderboards with Bridge SDK in GDScript Source: https://context7.com/playgama/bridge-godot/llms.txt This snippet shows how to integrate leaderboards using the Bridge SDK in GDScript. It covers checking leaderboard availability and type, submitting scores, fetching leaderboard entries, and displaying native leaderboards or custom UI. It requires the Bridge SDK and potentially platform-specific implementations for native leaderboards. ```gdscript extends Node const LEADERBOARD_ID = "high_scores" func _ready(): # Check leaderboard type match Bridge.leaderboards.type: Bridge.LeaderboardType.NOT_AVAILABLE: print("Leaderboards not available") Bridge.LeaderboardType.IN_GAME: print("Use custom in-game leaderboard") Bridge.LeaderboardType.NATIVE: print("Use native platform leaderboard") Bridge.LeaderboardType.NATIVE_POPUP: print("Platform provides leaderboard popup") func submit_score(score): Bridge.leaderboards.set_score(LEADERBOARD_ID, score, funcref(self, "_on_score_submitted")) func _on_score_submitted(success): if success: print("Score submitted successfully") else: print("Failed to submit score") func show_leaderboard(): if Bridge.leaderboards.type == Bridge.LeaderboardType.NATIVE_POPUP: # Show native platform popup Bridge.leaderboards.show_native_popup(LEADERBOARD_ID, funcref(self, "_on_popup_closed")) else: # Fetch and display custom leaderboard fetch_leaderboard() func fetch_leaderboard(): Bridge.leaderboards.get_entries(LEADERBOARD_ID, funcref(self, "_on_entries_received")) func _on_entries_received(success, entries): if success: print("Top scores:") for i in range(min(10, entries.size())): var entry = entries[i] print(i + 1, ". ", entry["name"], " - ", entry["score"]) display_leaderboard_entry(i, entry) else: print("Failed to fetch leaderboard") func _on_popup_closed(success): print("Leaderboard popup closed") func display_leaderboard_entry(rank, entry): # Display entry in custom UI pass ``` -------------------------------- ### Manage Device Configuration and Visibility in Godot Source: https://context7.com/playgama/bridge-godot/llms.txt Detects hardware type to optimize input controls and monitors visibility state to pause game logic and audio when the game is not active. This ensures efficient resource management across desktop, mobile, tablet, and TV platforms. ```gdscript func _ready(): match Bridge.device.type: Bridge.DeviceType.DESKTOP: setup_desktop_controls() Bridge.DeviceType.MOBILE: setup_mobile_controls() Bridge.game.connect("visibility_state_changed", self, "_on_visibility_changed") func _on_visibility_changed(state): match state: Bridge.VisibilityState.VISIBLE: get_tree().paused = false AudioServer.set_bus_mute(0, false) Bridge.VisibilityState.HIDDEN: get_tree().paused = true AudioServer.set_bus_mute(0, true) save_game() ``` -------------------------------- ### Access Platform Information and Events (GDScript) Source: https://context7.com/playgama/bridge-godot/llms.txt This snippet demonstrates how to access platform-specific information such as ID, language, and payload. It also shows how to connect to platform events like audio and pause state changes, send platform messages, and retrieve server time and game catalog data. The code requires the Bridge SDK and assumes it's accessible globally. ```gdscript extends Node func _ready(): # Access platform properties print("Platform ID: ", Bridge.platform.id) print("Language: ", Bridge.platform.language) print("TLD: ", Bridge.platform.tld) print("Payload: ", Bridge.platform.payload) print("Audio enabled: ", Bridge.platform.is_audio_enabled) # Listen to platform events Bridge.platform.connect("audio_state_changed", self, "_on_audio_changed") Bridge.platform.connect("pause_state_changed", self, "_on_pause_changed") # Send platform message Bridge.platform.send_message(Bridge.PlatformMessage.GAME_READY) # Get server time Bridge.platform.get_server_time(funcref(self, "_on_server_time")) # Get all games from platform catalog if Bridge.platform.is_get_all_games_supported: Bridge.platform.get_all_games(funcref(self, "_on_all_games_loaded")) # Get specific game by ID if Bridge.platform.is_get_game_by_id_supported: var options = {"id": "game_123"} Bridge.platform.get_game_by_id(options, funcref(self, "_on_game_loaded")) func _on_audio_changed(enabled): print("Audio state changed: ", enabled) AudioServer.set_bus_mute(0, !enabled) func _on_pause_changed(paused): print("Pause state changed: ", paused) get_tree().paused = paused func _on_server_time(timestamp): print("Server timestamp: ", timestamp) func _on_all_games_loaded(success, games): if success: print("Available games: ", games.size()) for game in games: print("Game: ", game["title"], " - ", game["url"]) display_game_in_catalog(game) else: print("Failed to load games catalog") func _on_game_loaded(success, game): if success: print("Game loaded: ", game["title"]) print("App ID: ", game["appID"]) print("URL: ", game["url"]) print("Cover: ", game["coverURL"]) else: print("Failed to load game") func display_game_in_catalog(game): # Display game in UI pass ``` -------------------------------- ### Handle Player Authorization and Profile (GDScript) Source: https://context7.com/playgama/bridge-godot/llms.txt This GDScript snippet shows how to manage player authorization and retrieve player information, including ID, name, and photos. It checks for authorization support, initiates authorization if needed, and displays player details. The code also handles platform-specific authorization options and loads player photos using HTTP requests. ```gdscript extends Node onready var player_name_label = $PlayerName onready var player_photo = $PlayerPhoto func _ready(): # Check authorization support if Bridge.player.is_authorization_supported: if !Bridge.player.is_authorized: authorize_player() else: display_player_info() func authorize_player(): var options = null # Platform-specific options match Bridge.platform.id: "yandex": options = {"scopes": true} Bridge.player.authorize(options, funcref(self, "_on_authorize_complete")) func _on_authorize_complete(success): if success: print("Authorization successful") print("Player ID: ", Bridge.player.id) print("Player name: ", Bridge.player.name) display_player_info() else: print("Authorization failed") func display_player_info(): player_name_label.text = Bridge.player.name # Access extra platform-specific data for key in Bridge.player.extra: print(key, ": ", Bridge.player.extra[key]) # Load player photo if Bridge.player.photos.size() > 0: load_photo(Bridge.player.photos[0]) func load_photo(url): var http = HTTPRequest.new() add_child(http) http.connect("request_completed", self, "_on_photo_loaded") http.request(url) func _on_photo_loaded(result, code, headers, body): if result == HTTPRequest.RESULT_SUCCESS: var image = Image.new() image.load_png_from_buffer(body) var texture = ImageTexture.new() texture.create_from_image(image) player_photo.texture = texture ``` -------------------------------- ### Manage Ads with Bridge SDK in GDScript Source: https://context7.com/playgama/bridge-godot/llms.txt This snippet demonstrates how to manage various ad types (banner, interstitial, rewarded video) using the Bridge SDK in GDScript. It includes checking ad support, configuring delays, connecting to state change events, displaying and hiding ads, and handling ad block detection. Dependencies include the Bridge SDK. ```gdscript extends Node func _ready(): # Check ad support print("Banner supported: ", Bridge.advertisement.is_banner_supported) print("Interstitial supported: ", Bridge.advertisement.is_interstitial_supported) print("Rewarded supported: ", Bridge.advertisement.is_rewarded_supported) # Configure minimum delay between interstitials (milliseconds) Bridge.advertisement.set_minimum_delay_between_interstitial(60000) # Connect to ad state events Bridge.advertisement.connect("banner_state_changed", self, "_on_banner_state_changed") Bridge.advertisement.connect("interstitial_state_changed", self, "_on_interstitial_state_changed") Bridge.advertisement.connect("rewarded_state_changed", self, "_on_rewarded_state_changed") # Check for ad blocker Bridge.advertisement.check_adblock(funcref(self, "_on_adblock_check")) func show_banner(): Bridge.advertisement.show_banner(Bridge.BannerPosition.BOTTOM, "main_menu") func hide_banner(): Bridge.advertisement.hide_banner() func show_interstitial_between_levels(): # Automatically respects minimum delay Bridge.advertisement.show_interstitial("level_complete") func show_rewarded_for_coins(): Bridge.advertisement.show_rewarded("extra_coins") func _on_banner_state_changed(state): match state: Bridge.BannerState.LOADING: print("Banner loading") Bridge.BannerState.SHOWN: print("Banner shown") Bridge.BannerState.HIDDEN: print("Banner hidden") Bridge.BannerState.FAILED: print("Banner failed to load") func _on_interstitial_state_changed(state): match state: Bridge.InterstitialState.LOADING: get_tree().paused = true Bridge.InterstitialState.OPENED: print("Interstitial opened") Bridge.InterstitialState.CLOSED: get_tree().paused = false print("Interstitial closed") Bridge.InterstitialState.FAILED: get_tree().paused = false print("Interstitial failed") func _on_rewarded_state_changed(state): match state: Bridge.RewardedState.LOADING: get_tree().paused = true Bridge.RewardedState.OPENED: print("Rewarded ad opened") Bridge.RewardedState.REWARDED: print("Reward granted! Placement: ", Bridge.advertisement.rewarded_placement) grant_reward() Bridge.RewardedState.CLOSED: get_tree().paused = false Bridge.RewardedState.FAILED: get_tree().paused = false print("Rewarded ad failed") func _on_adblock_check(detected): if detected: print("Ad blocker detected - consider alternative monetization") func grant_reward(): # Grant player reward based on placement if Bridge.advertisement.rewarded_placement == "extra_coins": # Add 100 coins pass ``` -------------------------------- ### Implement Achievement System with Godot Source: https://context7.com/playgama/bridge-godot/llms.txt Methods to unlock player achievements, fetch current status, and trigger native platform popups. It demonstrates tracking game progress to unlock specific milestones via the Bridge.achievements API. ```GDScript extends Node func unlock_achievement(achievement_id): var options = {"id": achievement_id} Bridge.achievements.unlock(options, funcref(self, "_on_achievement_unlocked")) Bridge.platform.send_message(Bridge.PlatformMessage.PLAYER_GOT_ACHIEVEMENT) func load_achievements(): Bridge.achievements.get_list(null, funcref(self, "_on_achievements_loaded")) func show_achievements_popup(): if Bridge.achievements.is_native_popup_supported: Bridge.achievements.show_native_popup(null, funcref(self, "_on_popup_closed")) func on_level_completed(level): if level == 10: unlock_achievement("complete_10_levels") ``` -------------------------------- ### Manage In-App Purchases and Consumables with Godot Source: https://context7.com/playgama/bridge-godot/llms.txt Functions to retrieve product catalogs, process user purchases, and handle consumable item logic. This snippet uses the Bridge.payments API to verify platform support and execute transactions asynchronously. ```GDScript extends Node func _ready(): if Bridge.payments.is_supported: load_catalog() load_purchases() else: print("Payments not supported on this platform") func load_catalog(): Bridge.payments.get_catalog(funcref(self, "_on_catalog_loaded")) func _on_catalog_loaded(success, products): if success: for product in products: print("ID: ", product["id"]) else: print("Failed to load catalog") func purchase_product(product_id): var options = {"developerPayload": "user_12345_purchase"} Bridge.payments.purchase(product_id, options, funcref(self, "_on_purchase_complete")) func _on_purchase_complete(success, details): if success: apply_purchase(details) if is_consumable(details["productId"]): consume_purchase(details["purchaseToken"]) func consume_purchase(purchase_token): Bridge.payments.consume_purchase(purchase_token, funcref(self, "_on_consume_complete")) func is_consumable(product_id): return product_id in ["coins_100", "coins_500", "coins_1000"] ``` -------------------------------- ### Style Godot Game Container Source: https://github.com/playgama/bridge-godot/blob/main/addons/playgama_bridge/template/index.html CSS rules to configure the visual presentation of the game canvas. It ensures the canvas is centered, prevents scrolling, and provides a dark theme for the container. ```css html { overflow: hidden; } body { touch-action: none; margin: 0; border: 0 none; padding: 0; text-align: center; background-color: black; overflow: hidden; } #canvas { display: block; margin: 0; color: white; } #canvas:focus { outline: none; } .godot { font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif; color: #e0e0e0; background-color: #3b3943; background-image: linear-gradient(to bottom, #403e48, #35333c); border: 1px solid #45434e; box-shadow: 0 0 1px 1px #2f2d35; } ``` -------------------------------- ### Implement Social Interactions in Godot Source: https://context7.com/playgama/bridge-godot/llms.txt Utilizes the Bridge.social interface to handle game sharing, community joining, and user engagement features. These methods require callback functions to handle completion status and reward logic. ```gdscript extends Node func share_score(score): var options = { "text": "I just scored " + str(score) + " points!", "image": "https://example.com/share_image.png" } Bridge.social.share(options, funcref(self, "_on_share_complete")) func _on_share_complete(success): if success: print("Shared successfully") grant_coins(50) func invite_friends_for_reward(): var options = { "text": "Join me in this awesome game!" } Bridge.social.invite_friends(options, funcref(self, "_on_invite_complete")) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.