","stat_type":"Replace","display_in_table":true,"accomplishment_tasks":[]}],"achievements":[],"challenges":[],"chat_bootstrap_url":"/en/games/Davidasdasda/stay-alive/chat.js","holodeck_url":"/en/games/Davidasdasda/stay-alive/holodeck","accomplishments_bootstrap_url":"/en/games/Davidasdasda/stay-alive/chat_achievements","sticker_drop_url":"/en/games/Davidasdasda/stay-alive/sticker_drop","game_path":"/en/games/Davidasdasda/stay-alive","html_dimensions":{"game_width":1500,"game_height":900,"max_game_width":null,"max_game_height":null,"game_left":0,"game_top":0,"chat_width":300,"chat_height":900,"flash_frame_width":1803,"flash_frame_height":926,"game_frame_width":1500,"game_frame_height":900,"min_chat_width":300,"min_chat_height":527,"divider_width":3,"quicklinks_height":26,"chat_window_non_content_height":254,"avatar_image_gutter_height":120,"chat_pane_tab_height":41},"login_url":"/en/accounts/new/behind_login.js?game_id=306814","shared_content_type_permalinks":[],"shared_content_type_names":[],"permissions":{"session_lookup_key":null,"no_file_size_limit":null,"chat_api":null,"premium_game":null,"served_from_internal":null,"microtransaction_api":false,"save_shared_content":true,"save_external_shared_content":true,"authenticated_users_only":false,"hide_comments":false,"dont_hide_iframe":true,"shout_api":false,"mass_messages_api":null,"shared_links":null,"disallow_cinematic":false,"disable_instart":null,"guilds_api":null,"generate_guest_characters":false,"allow_script_access":false,"periscope_dashboard":false,"incentivized_web_ads":null,"host_in_top_frame":false,"force_localconnection":false,"truex_web_ads":false},"has_game_specific_forum":false,"multiplayer_game":false,"authenticated_only_shared_content_sorts":["by_own","by_friends"],"in_beta":false,"in_preview":false,"extra_interpolation":false}); // Store early messages until holodeck is ready var earlyMessages = []; var holodeckReady = false; // Add postMessage listener IMMEDIATELY (before holodeck:ready) window.addEventListener('message', function(event) { if (event.data && event.data.kongregate_type === 'kongregate:api:message') { // If holodeck is ready, process immediately if (holodeckReady) { var konduit = holodeck.konduit(); if (konduit && konduit.jsAdapter && konduit.jsAdapter.messageConnection) { // Manually trigger MessageConnection to process relayed message konduit.jsAdapter.messageConnection.onMessageReceived(event); } } else { // Store for later processing earlyMessages.push(event); } } }); // Failsafe: If holodeck:ready doesn't fire in 3 seconds (e.g., Ajax failure for guests), // manually fire it so MessageConnection gets set up setTimeout(function() { if (!holodeckReady) { console.log('[Preview Embed] holodeck:ready timeout - forcing initialization'); document.fire('holodeck:ready'); } }, 3000); document.observe('holodeck:ready', function(){ console.log('[holodeck:ready] Event fired - holodeck is now fully initialized'); // Mark as ready IMMEDIATELY so incoming messages are processed holodeckReady = true; // Notify parent window immediately - no polling needed! parent.postMessage({ type: 'holodeckReady' }, '*'); console.log('[holodeck:ready] Notified parent window - shop will work'); // Wait for lightbox to be available, then set reference var setLightboxReference = function() { if (typeof lightbox !== 'undefined') { holodeck._lightbox_reference = lightbox.prototype; } else { document.observe('dom:javascript_loaded', function() { holodeck._lightbox_reference = lightbox.prototype; }); } }; setLightboxReference(); // Get the actual konduit instance (it's a getter function) var konduit = holodeck.konduit(); // Setup konduit if not already done (required for MessageConnection) if (!konduit.setupComplete) { konduit.setup({ eventDispatcher: holodeck._event_dispatcher, chatHost: holodeck._chat_host, chatProxyWebsocket: holodeck._chat_proxy_websocket, chatProxyBosh: holodeck._chat_proxy_bosh }); } // Set holodeck.ready flag (normally done in uiLoaded) if (!holodeck.ready) { holodeck.ready = true; } // Minimal holodeck initialization for preview embed holodeck.loadAdminControls(); holodeck.loadDeveloperControls(); // Load accomplishments to trigger retroactive Badge of the Day award // This calls chat_achievements which checks if user has already earned today's BotD if (holodeck.hasAccomplishments() && holodeck.authenticated()) { holodeck.loadAccomplishments(); } // Setup MessageConnection to send responses to game iframe if (konduit.jsAdapter) { var mc = konduit.jsAdapter.messageConnection; // Override sendMessage to send responses to the game iframe (not parent) var originalSendMessage = mc.sendMessage.bind(mc); mc.sendMessage = function(opcode, params) { // Send via original method var result = originalSendMessage(opcode, params); // Send to game iframe (child window) var gameIframe = document.getElementById('gameiframe'); if (gameIframe && gameIframe.contentWindow) { var payload = { kongregate_type: 'kongregate:api:message', opcode: opcode, params: params }; gameIframe.contentWindow.postMessage(payload, '*'); } return result; }; // Process any stored messages that arrived before holodeck was ready earlyMessages.forEach(function(event) { mc.onMessageReceived(event); }); earlyMessages = []; } }); // Signal to parent window that embed iframe is ready window.addEventListener('load', function() { if (window.parent !== window) { window.parent.postMessage({ type: 'embedIframeReady' }, '*'); } });