|
| 1 | +/** |
| 2 | + * Viz Magic — Developers / Support Screen |
| 3 | + * Shows who builds the game and lets a player voluntarily award the developer. |
| 4 | + */ |
| 5 | +var DevelopersScreen = (function() { |
| 6 | + 'use strict'; |
| 7 | + |
| 8 | + var DEVELOPER_ACCOUNT = 'denis-skripnik'; |
| 9 | + var REWARD_OPTIONS = [50, 100, 250]; // basis points: 0.50%, 1.00%, 2.50% |
| 10 | + |
| 11 | + function render() { |
| 12 | + var t = Helpers.t; |
| 13 | + var el = Helpers.$('screen-developers'); |
| 14 | + if (!el) return; |
| 15 | + |
| 16 | + var user = typeof VizAccount !== 'undefined' ? VizAccount.getCurrentUser() : ''; |
| 17 | + var html = '<div class="developers-screen">'; |
| 18 | + html += '<h1>🛠️ ' + t('developers_title') + '</h1>'; |
| 19 | + html += '<section class="developers-card" aria-label="' + t('developers_about_title') + '">'; |
| 20 | + html += '<h2>' + t('developers_about_title') + '</h2>'; |
| 21 | + html += '<p>' + t('developers_about_text') + '</p>'; |
| 22 | + html += '<p><strong>' + t('developers_primary_dev') + ':</strong> @' + DEVELOPER_ACCOUNT + '</p>'; |
| 23 | + html += '</section>'; |
| 24 | + |
| 25 | + html += '<section class="developers-card" aria-label="' + t('developers_reward_title') + '">'; |
| 26 | + html += '<h2>💎 ' + t('developers_reward_title') + '</h2>'; |
| 27 | + html += '<p>' + t('developers_reward_text') + '</p>'; |
| 28 | + html += '<p class="developers-note">' + t('developers_reward_note') + '</p>'; |
| 29 | + if (!user) { |
| 30 | + html += '<div class="empty-state">' + t('developers_login_required') + '</div>'; |
| 31 | + } else { |
| 32 | + html += '<div class="developers-reward-options" role="group" aria-label="' + t('developers_reward_title') + '">'; |
| 33 | + for (var i = 0; i < REWARD_OPTIONS.length; i++) { |
| 34 | + html += '<button type="button" class="btn btn-primary dev-reward-btn" data-energy="' + REWARD_OPTIONS[i] + '">' + |
| 35 | + t('developers_reward_button', { amount: Helpers.bpToPercent(REWARD_OPTIONS[i]) }) + '</button>'; |
| 36 | + } |
| 37 | + html += '</div>'; |
| 38 | + } |
| 39 | + html += '</section>'; |
| 40 | + html += '</div>'; |
| 41 | + el.innerHTML = html; |
| 42 | + _bindEvents(el); |
| 43 | + } |
| 44 | + |
| 45 | + function _bindEvents(el) { |
| 46 | + var buttons = el.querySelectorAll('.dev-reward-btn'); |
| 47 | + for (var i = 0; i < buttons.length; i++) { |
| 48 | + buttons[i].addEventListener('click', function() { |
| 49 | + var energy = parseInt(this.getAttribute('data-energy'), 10) || 0; |
| 50 | + _confirmReward(energy); |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + function _confirmReward(energy) { |
| 56 | + var t = Helpers.t; |
| 57 | + SoundManager.play('tap'); |
| 58 | + Modal.show({ |
| 59 | + title: t('developers_reward_confirm_title'), |
| 60 | + text: t('developers_reward_confirm_text', { amount: Helpers.bpToPercent(energy), account: DEVELOPER_ACCOUNT }), |
| 61 | + buttons: [ |
| 62 | + { |
| 63 | + text: t('developers_reward_confirm_button'), |
| 64 | + className: 'btn-primary', |
| 65 | + action: function() { _sendReward(energy); } |
| 66 | + }, |
| 67 | + { |
| 68 | + text: t('cancel'), |
| 69 | + className: 'btn-secondary', |
| 70 | + action: function() {} |
| 71 | + } |
| 72 | + ] |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + function _sendReward(energy) { |
| 77 | + var t = Helpers.t; |
| 78 | + var memo = 'viz://vm/developers/thanks — ' + t('developers_reward_memo'); |
| 79 | + VizBroadcast.award(DEVELOPER_ACCOUNT, energy, 0, memo, [], function(err) { |
| 80 | + if (err) { |
| 81 | + Toast.error(t('developers_reward_error')); |
| 82 | + SoundManager.play('error'); |
| 83 | + return; |
| 84 | + } |
| 85 | + Toast.success(t('developers_reward_success')); |
| 86 | + SoundManager.play('success'); |
| 87 | + SoundManager.vibrate('success'); |
| 88 | + }); |
| 89 | + } |
| 90 | + |
| 91 | + return { render: render }; |
| 92 | +})(); |
0 commit comments