BlueGit

projects-timfalken-com meteors

t1193: in-game menu (pause, resume, back to main menu with reward first)

timfa Grok Bot · pushed by timfa

Authored 2026-11-15 · 2 days ago

Hash
6f2e5af69090f2d7ffa769220b83729410dac8cb
Parent
f3664e43
5 files changed +430 −21
build/index.html +17 −6
@@ -71,12 +71,12 @@
71 71
72 72 <div id="online-login" hidden>
73 73 <p data-i18n="online.loginPrompt">To play online, log in with your account on auth.timfalken.com.</p>
74 <a id="btn-login" class="button" href="auth.php" data-i18n="menu.login">Log in</a>
74 <a id="btn-login" class="button" href="auth.php?return=online" data-i18n="menu.login">Log in</a>
75 75 <button type="button" class="btn-secondary" data-back-menu data-i18n="planet.back">Back</button>
76 76 <p id="local-login" class="hint" hidden>
77 77 <span data-i18n="online.localTest">Local test:</span>
78 <a href="auth.php?test=1">test_user_1</a> ·
79 <a href="auth.php?test=2">test_user_2</a>
78 <a href="auth.php?test=1&amp;next=index.html%3Fonline%3D1">test_user_1</a> ·
79 <a href="auth.php?test=2&amp;next=index.html%3Fonline%3D1">test_user_2</a>
80 80 </p>
81 81 </div>
82 82
@@ -172,9 +172,12 @@
172 172 <div class="hud-label" data-i18n="hud.points">Points</div>
173 173 <div id="score">0</div>
174 174 </div>
175 <div class="hud-right">
176 <div id="planet-name">Terra</div>
177 <div id="planet-stats"></div>
175 <div class="hud-right-wrap">
176 <div class="hud-right">
177 <div id="planet-name">Terra</div>
178 <div id="planet-stats"></div>
179 </div>
180 <button type="button" id="btn-game-menu" class="btn-game-menu" hidden aria-haspopup="dialog" aria-controls="game-menu" data-i18n-aria="game.menu" aria-label="Menu" title="Menu"><span aria-hidden="true">&#9776;</span></button>
178 181 </div>
179 182 <div id="offline-hud" class="hud-offline" hidden>
180 183 <span id="offline-round">Round 1</span>
@@ -186,6 +189,14 @@
186 189 <div id="chain-indicator" hidden></div>
187 190 </div>
188 191
192 <div id="game-menu" class="screen overlay" role="dialog" aria-modal="true" aria-labelledby="game-menu-title" hidden>
193 <h2 id="game-menu-title" data-i18n="game.paused">Paused</h2>
194 <div class="game-menu-buttons">
195 <button type="button" id="btn-game-resume" class="btn-secondary btn-primary-ish" data-i18n="game.resume">Resume</button>
196 <button type="button" id="btn-game-quit" class="btn-secondary" data-i18n="game.backToMenu">Back to main menu</button>
197 </div>
198 </div>
199
189 200 <div id="offline-result" class="screen overlay" hidden>
190 201 <h2 data-i18n="offline.resultTitle">Offline Battle</h2>
191 202 <p id="offline-reached-line">You reached round <strong id="offline-reached">1</strong>.</p>
@@ -71,12 +71,12 @@
71
71
72 <div id="online-login" hidden>
72 <div id="online-login" hidden>
73 <p data-i18n="online.loginPrompt">To play online, log in with your account on auth.timfalken.com.</p>
73 <p data-i18n="online.loginPrompt">To play online, log in with your account on auth.timfalken.com.</p>
74 <a id="btn-login" class="button" href="auth.php" data-i18n="menu.login">Log in</a>
74 <a id="btn-login" class="button" href="auth.php?return=online" data-i18n="menu.login">Log in</a>
75 <button type="button" class="btn-secondary" data-back-menu data-i18n="planet.back">Back</button>
75 <button type="button" class="btn-secondary" data-back-menu data-i18n="planet.back">Back</button>
76 <p id="local-login" class="hint" hidden>
76 <p id="local-login" class="hint" hidden>
77 <span data-i18n="online.localTest">Local test:</span>
77 <span data-i18n="online.localTest">Local test:</span>
78 <a href="auth.php?test=1">test_user_1</a> ·
78 <a href="auth.php?test=1&amp;next=index.html%3Fonline%3D1">test_user_1</a> ·
79 <a href="auth.php?test=2">test_user_2</a>
79 <a href="auth.php?test=2&amp;next=index.html%3Fonline%3D1">test_user_2</a>
80 </p>
80 </p>
81 </div>
81 </div>
82
82
@@ -172,9 +172,12 @@
172 <div class="hud-label" data-i18n="hud.points">Points</div>
172 <div class="hud-label" data-i18n="hud.points">Points</div>
173 <div id="score">0</div>
173 <div id="score">0</div>
174 </div>
174 </div>
175 <div class="hud-right">
175 <div class="hud-right-wrap">
176 <div id="planet-name">Terra</div>
176 <div class="hud-right">
177 <div id="planet-stats"></div>
177 <div id="planet-name">Terra</div>
178 <div id="planet-stats"></div>
179 </div>
180 <button type="button" id="btn-game-menu" class="btn-game-menu" hidden aria-haspopup="dialog" aria-controls="game-menu" data-i18n-aria="game.menu" aria-label="Menu" title="Menu"><span aria-hidden="true">&#9776;</span></button>
178 </div>
181 </div>
179 <div id="offline-hud" class="hud-offline" hidden>
182 <div id="offline-hud" class="hud-offline" hidden>
180 <span id="offline-round">Round 1</span>
183 <span id="offline-round">Round 1</span>
@@ -186,6 +189,14 @@
186 <div id="chain-indicator" hidden></div>
189 <div id="chain-indicator" hidden></div>
187 </div>
190 </div>
188
191
192 <div id="game-menu" class="screen overlay" role="dialog" aria-modal="true" aria-labelledby="game-menu-title" hidden>
193 <h2 id="game-menu-title" data-i18n="game.paused">Paused</h2>
194 <div class="game-menu-buttons">
195 <button type="button" id="btn-game-resume" class="btn-secondary btn-primary-ish" data-i18n="game.resume">Resume</button>
196 <button type="button" id="btn-game-quit" class="btn-secondary" data-i18n="game.backToMenu">Back to main menu</button>
197 </div>
198 </div>
199
189 <div id="offline-result" class="screen overlay" hidden>
200 <div id="offline-result" class="screen overlay" hidden>
190 <h2 data-i18n="offline.resultTitle">Offline Battle</h2>
201 <h2 data-i18n="offline.resultTitle">Offline Battle</h2>
191 <p id="offline-reached-line">You reached round <strong id="offline-reached">1</strong>.</p>
202 <p id="offline-reached-line">You reached round <strong id="offline-reached">1</strong>.</p>
build/style.css +53 −1
@@ -46,7 +46,7 @@ html, body {
46 46 text-align: center;
47 47 }
48 48
49 .screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden], #flights-back[hidden], #planet-select[hidden], #offline-result[hidden], #offline-hud[hidden], #chain-indicator[hidden], #designer[hidden], #designer-edit[hidden], #reward[hidden] { display: none !important; }
49 .screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden], #flights-back[hidden], #planet-select[hidden], #offline-result[hidden], #game-menu[hidden], #btn-game-menu[hidden], #offline-hud[hidden], #chain-indicator[hidden], #designer[hidden], #designer-edit[hidden], #reward[hidden] { display: none !important; }
50 50
51 51 h1 {
52 52 font-size: clamp(48px, 14vw, 96px);
@@ -1063,3 +1063,55 @@ html[lang="ja"], html[lang="zh-Hans"], html[lang="ko"] {
1063 1063 color: #8f96b2;
1064 1064 z-index: 3;
1065 1065 }
1066
1067 /* —— t1193 in-game menu (Spelen / Offline Strijd) —— */
1068 .hud-right-wrap {
1069 display: flex;
1070 align-items: flex-start;
1071 gap: 10px;
1072 min-width: 0;
1073 }
1074 .btn-game-menu {
1075 pointer-events: auto;
1076 flex: 0 0 auto;
1077 width: 40px;
1078 height: 40px;
1079 padding: 0;
1080 border: 1px solid #6a7394;
1081 border-radius: 10px;
1082 background: rgba(27, 32, 56, 0.85);
1083 color: #e8eaf2;
1084 font-size: 20px;
1085 line-height: 38px;
1086 cursor: pointer;
1087 touch-action: manipulation;
1088 -webkit-tap-highlight-color: transparent;
1089 }
1090 .btn-game-menu:is(:hover, :focus-visible) {
1091 border-color: #ffe27a;
1092 color: #fff6c8;
1093 }
1094 #game-menu {
1095 z-index: 60;
1096 }
1097 #game-menu h2 {
1098 color: #ffe27a;
1099 }
1100 .game-menu-buttons {
1101 display: flex;
1102 flex-direction: column;
1103 align-items: center;
1104 gap: 4px;
1105 margin-top: 8px;
1106 }
1107 .game-menu-buttons .btn-secondary {
1108 min-width: min(80vw, 300px);
1109 }
1110 .btn-primary-ish {
1111 border-color: #ffe27a !important;
1112 color: #fff6c8 !important;
1113 }
1114 @media (max-width: 520px) {
1115 .hud-right-wrap { gap: 6px; }
1116 .btn-game-menu { width: 36px; height: 36px; line-height: 34px; font-size: 18px; }
1117 }
@@ -46,7 +46,7 @@ html, body {
46 text-align: center;
46 text-align: center;
47}
47}
48
48
49.screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden], #flights-back[hidden], #planet-select[hidden], #offline-result[hidden], #offline-hud[hidden], #chain-indicator[hidden], #designer[hidden], #designer-edit[hidden], #reward[hidden] { display: none !important; }
49.screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden], #flights-back[hidden], #planet-select[hidden], #offline-result[hidden], #game-menu[hidden], #btn-game-menu[hidden], #offline-hud[hidden], #chain-indicator[hidden], #designer[hidden], #designer-edit[hidden], #reward[hidden] { display: none !important; }
50
50
51h1 {
51h1 {
52 font-size: clamp(48px, 14vw, 96px);
52 font-size: clamp(48px, 14vw, 96px);
@@ -1063,3 +1063,55 @@ html[lang="ja"], html[lang="zh-Hans"], html[lang="ko"] {
1063 color: #8f96b2;
1063 color: #8f96b2;
1064 z-index: 3;
1064 z-index: 3;
1065}
1065}
1066
1067/* —— t1193 in-game menu (Spelen / Offline Strijd) —— */
1068.hud-right-wrap {
1069 display: flex;
1070 align-items: flex-start;
1071 gap: 10px;
1072 min-width: 0;
1073}
1074.btn-game-menu {
1075 pointer-events: auto;
1076 flex: 0 0 auto;
1077 width: 40px;
1078 height: 40px;
1079 padding: 0;
1080 border: 1px solid #6a7394;
1081 border-radius: 10px;
1082 background: rgba(27, 32, 56, 0.85);
1083 color: #e8eaf2;
1084 font-size: 20px;
1085 line-height: 38px;
1086 cursor: pointer;
1087 touch-action: manipulation;
1088 -webkit-tap-highlight-color: transparent;
1089}
1090.btn-game-menu:is(:hover, :focus-visible) {
1091 border-color: #ffe27a;
1092 color: #fff6c8;
1093}
1094#game-menu {
1095 z-index: 60;
1096}
1097#game-menu h2 {
1098 color: #ffe27a;
1099}
1100.game-menu-buttons {
1101 display: flex;
1102 flex-direction: column;
1103 align-items: center;
1104 gap: 4px;
1105 margin-top: 8px;
1106}
1107.game-menu-buttons .btn-secondary {
1108 min-width: min(80vw, 300px);
1109}
1110.btn-primary-ish {
1111 border-color: #ffe27a !important;
1112 color: #fff6c8 !important;
1113}
1114@media (max-width: 520px) {
1115 .hud-right-wrap { gap: 6px; }
1116 .btn-game-menu { width: 36px; height: 36px; line-height: 34px; font-size: 18px; }
1117}
server/lib/i18n.json +60 −10
@@ -283,7 +283,12 @@
283 283 "reward.won": "You won!",
284 284 "reward.lost": "You lost...",
285 285 "reward.total": "Total points",
286 "reward.continue": "Tap to continue"
286 "reward.continue": "Tap to continue",
287 "game.menu": "Menu",
288 "game.paused": "Paused",
289 "game.resume": "Resume",
290 "game.backToMenu": "Back to main menu",
291 "reward.ended": "Game ended"
287 292 },
288 293 "nl": {
289 294 "menu.tagline": "Drie op een rij, en je blokjes krijgen raketmotoren.",
@@ -568,7 +573,12 @@
568 573 "reward.won": "Gewonnen!",
569 574 "reward.lost": "Verloren...",
570 575 "reward.total": "Totaal punten",
571 "reward.continue": "Tik om verder te gaan"
576 "reward.continue": "Tik om verder te gaan",
577 "game.menu": "Menu",
578 "game.paused": "Gepauzeerd",
579 "game.resume": "Verder spelen",
580 "game.backToMenu": "Terug naar hoofdmenu",
581 "reward.ended": "Spel gestopt"
572 582 },
573 583 "de": {
574 584 "menu.tagline": "Drei in einer Reihe — und deine Blöcke bekommen Raketenantrieb.",
@@ -853,7 +863,12 @@
853 863 "reward.won": "Gewonnen!",
854 864 "reward.lost": "Verloren...",
855 865 "reward.total": "Punkte gesamt",
856 "reward.continue": "Tippen zum Fortfahren"
866 "reward.continue": "Tippen zum Fortfahren",
867 "game.menu": "Menü",
868 "game.paused": "Pausiert",
869 "game.resume": "Weiterspielen",
870 "game.backToMenu": "Zurück zum Hauptmenü",
871 "reward.ended": "Spiel beendet"
857 872 },
858 873 "fr": {
859 874 "menu.tagline": "Trois d’affilée, et tes blocs s’équipent de propulseurs.",
@@ -1138,7 +1153,12 @@
1138 1153 "reward.won": "Victoire !",
1139 1154 "reward.lost": "Perdu...",
1140 1155 "reward.total": "Total des points",
1141 "reward.continue": "Touchez pour continuer"
1156 "reward.continue": "Touchez pour continuer",
1157 "game.menu": "Menu",
1158 "game.paused": "En pause",
1159 "game.resume": "Reprendre",
1160 "game.backToMenu": "Retour au menu principal",
1161 "reward.ended": "Partie terminée"
1142 1162 },
1143 1163 "ja": {
1144 1164 "menu.tagline": "三つ揃えると、ブロックにロケットが点火します。",
@@ -1423,7 +1443,12 @@
1423 1443 "reward.won": "勝利!",
1424 1444 "reward.lost": "敗北...",
1425 1445 "reward.total": "合計ポイント",
1426 "reward.continue": "タップして続ける"
1446 "reward.continue": "タップして続ける",
1447 "game.menu": "メニュー",
1448 "game.paused": "一時停止中",
1449 "game.resume": "再開",
1450 "game.backToMenu": "メインメニューに戻る",
1451 "reward.ended": "ゲーム終了"
1427 1452 },
1428 1453 "zh": {
1429 1454 "menu.tagline": "三个一排,你的方块就会装上火箭。",
@@ -1708,7 +1733,12 @@
1708 1733 "reward.won": "你赢了!",
1709 1734 "reward.lost": "你输了...",
1710 1735 "reward.total": "总积分",
1711 "reward.continue": "点击继续"
1736 "reward.continue": "点击继续",
1737 "game.menu": "菜单",
1738 "game.paused": "已暂停",
1739 "game.resume": "继续游戏",
1740 "game.backToMenu": "返回主菜单",
1741 "reward.ended": "游戏结束"
1712 1742 },
1713 1743 "ko": {
1714 1744 "menu.tagline": "세 개를 나란히 맞추면 블록에 로켓이 점화됩니다.",
@@ -1993,7 +2023,12 @@
1993 2023 "reward.won": "승리!",
1994 2024 "reward.lost": "패배...",
1995 2025 "reward.total": "총 포인트",
1996 "reward.continue": "탭하여 계속"
2026 "reward.continue": "탭하여 계속",
2027 "game.menu": "메뉴",
2028 "game.paused": "일시정지",
2029 "game.resume": "계속하기",
2030 "game.backToMenu": "메인 메뉴로 돌아가기",
2031 "reward.ended": "게임 종료"
1997 2032 },
1998 2033 "pl": {
1999 2034 "menu.tagline": "Trzy w rzędzie, a twoje klocki dostają napęd rakietowy.",
@@ -2278,7 +2313,12 @@
2278 2313 "reward.won": "Wygrana!",
2279 2314 "reward.lost": "Przegrana...",
2280 2315 "reward.total": "Suma punktów",
2281 "reward.continue": "Dotknij, aby kontynuować"
2316 "reward.continue": "Dotknij, aby kontynuować",
2317 "game.menu": "Menu",
2318 "game.paused": "Pauza",
2319 "game.resume": "Wznów",
2320 "game.backToMenu": "Powrót do menu głównego",
2321 "reward.ended": "Gra zakończona"
2282 2322 },
2283 2323 "ru": {
2284 2324 "menu.tagline": "Три в ряд — и твои блоки получают ракетные двигатели.",
@@ -2563,7 +2603,12 @@
2563 2603 "reward.won": "Победа!",
2564 2604 "reward.lost": "Поражение...",
2565 2605 "reward.total": "Всего очков",
2566 "reward.continue": "Нажмите, чтобы продолжить"
2606 "reward.continue": "Нажмите, чтобы продолжить",
2607 "game.menu": "Меню",
2608 "game.paused": "Пауза",
2609 "game.resume": "Продолжить",
2610 "game.backToMenu": "В главное меню",
2611 "reward.ended": "Игра окончена"
2567 2612 },
2568 2613 "es": {
2569 2614 "menu.tagline": "Tres en raya, y tus bloques ganan motores cohete.",
@@ -2848,7 +2893,12 @@
2848 2893 "reward.won": "¡Has ganado!",
2849 2894 "reward.lost": "Has perdido...",
2850 2895 "reward.total": "Puntos totales",
2851 "reward.continue": "Toca para continuar"
2896 "reward.continue": "Toca para continuar",
2897 "game.menu": "Menú",
2898 "game.paused": "En pausa",
2899 "game.resume": "Continuar",
2900 "game.backToMenu": "Volver al menú principal",
2901 "reward.ended": "Partida terminada"
2852 2902 }
2853 2903 },
2854 2904 "errors": {
@@ -283,7 +283,12 @@
283 "reward.won": "You won!",
283 "reward.won": "You won!",
284 "reward.lost": "You lost...",
284 "reward.lost": "You lost...",
285 "reward.total": "Total points",
285 "reward.total": "Total points",
286 "reward.continue": "Tap to continue"
286 "reward.continue": "Tap to continue",
287 "game.menu": "Menu",
288 "game.paused": "Paused",
289 "game.resume": "Resume",
290 "game.backToMenu": "Back to main menu",
291 "reward.ended": "Game ended"
287 },
292 },
288 "nl": {
293 "nl": {
289 "menu.tagline": "Drie op een rij, en je blokjes krijgen raketmotoren.",
294 "menu.tagline": "Drie op een rij, en je blokjes krijgen raketmotoren.",
@@ -568,7 +573,12 @@
568 "reward.won": "Gewonnen!",
573 "reward.won": "Gewonnen!",
569 "reward.lost": "Verloren...",
574 "reward.lost": "Verloren...",
570 "reward.total": "Totaal punten",
575 "reward.total": "Totaal punten",
571 "reward.continue": "Tik om verder te gaan"
576 "reward.continue": "Tik om verder te gaan",
577 "game.menu": "Menu",
578 "game.paused": "Gepauzeerd",
579 "game.resume": "Verder spelen",
580 "game.backToMenu": "Terug naar hoofdmenu",
581 "reward.ended": "Spel gestopt"
572 },
582 },
573 "de": {
583 "de": {
574 "menu.tagline": "Drei in einer Reihe — und deine Blöcke bekommen Raketenantrieb.",
584 "menu.tagline": "Drei in einer Reihe — und deine Blöcke bekommen Raketenantrieb.",
@@ -853,7 +863,12 @@
853 "reward.won": "Gewonnen!",
863 "reward.won": "Gewonnen!",
854 "reward.lost": "Verloren...",
864 "reward.lost": "Verloren...",
855 "reward.total": "Punkte gesamt",
865 "reward.total": "Punkte gesamt",
856 "reward.continue": "Tippen zum Fortfahren"
866 "reward.continue": "Tippen zum Fortfahren",
867 "game.menu": "Menü",
868 "game.paused": "Pausiert",
869 "game.resume": "Weiterspielen",
870 "game.backToMenu": "Zurück zum Hauptmenü",
871 "reward.ended": "Spiel beendet"
857 },
872 },
858 "fr": {
873 "fr": {
859 "menu.tagline": "Trois d’affilée, et tes blocs s’équipent de propulseurs.",
874 "menu.tagline": "Trois d’affilée, et tes blocs s’équipent de propulseurs.",
@@ -1138,7 +1153,12 @@
1138 "reward.won": "Victoire !",
1153 "reward.won": "Victoire !",
1139 "reward.lost": "Perdu...",
1154 "reward.lost": "Perdu...",
1140 "reward.total": "Total des points",
1155 "reward.total": "Total des points",
1141 "reward.continue": "Touchez pour continuer"
1156 "reward.continue": "Touchez pour continuer",
1157 "game.menu": "Menu",
1158 "game.paused": "En pause",
1159 "game.resume": "Reprendre",
1160 "game.backToMenu": "Retour au menu principal",
1161 "reward.ended": "Partie terminée"
1142 },
1162 },
1143 "ja": {
1163 "ja": {
1144 "menu.tagline": "三つ揃えると、ブロックにロケットが点火します。",
1164 "menu.tagline": "三つ揃えると、ブロックにロケットが点火します。",
@@ -1423,7 +1443,12 @@
1423 "reward.won": "勝利!",
1443 "reward.won": "勝利!",
1424 "reward.lost": "敗北...",
1444 "reward.lost": "敗北...",
1425 "reward.total": "合計ポイント",
1445 "reward.total": "合計ポイント",
1426 "reward.continue": "タップして続ける"
1446 "reward.continue": "タップして続ける",
1447 "game.menu": "メニュー",
1448 "game.paused": "一時停止中",
1449 "game.resume": "再開",
1450 "game.backToMenu": "メインメニューに戻る",
1451 "reward.ended": "ゲーム終了"
1427 },
1452 },
1428 "zh": {
1453 "zh": {
1429 "menu.tagline": "三个一排,你的方块就会装上火箭。",
1454 "menu.tagline": "三个一排,你的方块就会装上火箭。",
@@ -1708,7 +1733,12 @@
1708 "reward.won": "你赢了!",
1733 "reward.won": "你赢了!",
1709 "reward.lost": "你输了...",
1734 "reward.lost": "你输了...",
1710 "reward.total": "总积分",
1735 "reward.total": "总积分",
1711 "reward.continue": "点击继续"
1736 "reward.continue": "点击继续",
1737 "game.menu": "菜单",
1738 "game.paused": "已暂停",
1739 "game.resume": "继续游戏",
1740 "game.backToMenu": "返回主菜单",
1741 "reward.ended": "游戏结束"
1712 },
1742 },
1713 "ko": {
1743 "ko": {
1714 "menu.tagline": "세 개를 나란히 맞추면 블록에 로켓이 점화됩니다.",
1744 "menu.tagline": "세 개를 나란히 맞추면 블록에 로켓이 점화됩니다.",
@@ -1993,7 +2023,12 @@
1993 "reward.won": "승리!",
2023 "reward.won": "승리!",
1994 "reward.lost": "패배...",
2024 "reward.lost": "패배...",
1995 "reward.total": "총 포인트",
2025 "reward.total": "총 포인트",
1996 "reward.continue": "탭하여 계속"
2026 "reward.continue": "탭하여 계속",
2027 "game.menu": "메뉴",
2028 "game.paused": "일시정지",
2029 "game.resume": "계속하기",
2030 "game.backToMenu": "메인 메뉴로 돌아가기",
2031 "reward.ended": "게임 종료"
1997 },
2032 },
1998 "pl": {
2033 "pl": {
1999 "menu.tagline": "Trzy w rzędzie, a twoje klocki dostają napęd rakietowy.",
2034 "menu.tagline": "Trzy w rzędzie, a twoje klocki dostają napęd rakietowy.",
@@ -2278,7 +2313,12 @@
2278 "reward.won": "Wygrana!",
2313 "reward.won": "Wygrana!",
2279 "reward.lost": "Przegrana...",
2314 "reward.lost": "Przegrana...",
2280 "reward.total": "Suma punktów",
2315 "reward.total": "Suma punktów",
2281 "reward.continue": "Dotknij, aby kontynuować"
2316 "reward.continue": "Dotknij, aby kontynuować",
2317 "game.menu": "Menu",
2318 "game.paused": "Pauza",
2319 "game.resume": "Wznów",
2320 "game.backToMenu": "Powrót do menu głównego",
2321 "reward.ended": "Gra zakończona"
2282 },
2322 },
2283 "ru": {
2323 "ru": {
2284 "menu.tagline": "Три в ряд — и твои блоки получают ракетные двигатели.",
2324 "menu.tagline": "Три в ряд — и твои блоки получают ракетные двигатели.",
@@ -2563,7 +2603,12 @@
2563 "reward.won": "Победа!",
2603 "reward.won": "Победа!",
2564 "reward.lost": "Поражение...",
2604 "reward.lost": "Поражение...",
2565 "reward.total": "Всего очков",
2605 "reward.total": "Всего очков",
2566 "reward.continue": "Нажмите, чтобы продолжить"
2606 "reward.continue": "Нажмите, чтобы продолжить",
2607 "game.menu": "Меню",
2608 "game.paused": "Пауза",
2609 "game.resume": "Продолжить",
2610 "game.backToMenu": "В главное меню",
2611 "reward.ended": "Игра окончена"
2567 },
2612 },
2568 "es": {
2613 "es": {
2569 "menu.tagline": "Tres en raya, y tus bloques ganan motores cohete.",
2614 "menu.tagline": "Tres en raya, y tus bloques ganan motores cohete.",
@@ -2848,7 +2893,12 @@
2848 "reward.won": "¡Has ganado!",
2893 "reward.won": "¡Has ganado!",
2849 "reward.lost": "Has perdido...",
2894 "reward.lost": "Has perdido...",
2850 "reward.total": "Puntos totales",
2895 "reward.total": "Puntos totales",
2851 "reward.continue": "Toca para continuar"
2896 "reward.continue": "Toca para continuar",
2897 "game.menu": "Menú",
2898 "game.paused": "En pausa",
2899 "game.resume": "Continuar",
2900 "game.backToMenu": "Volver al menú principal",
2901 "reward.ended": "Partida terminada"
2852 }
2902 }
2853 },
2903 },
2854 "errors": {
2904 "errors": {
src/main.js +141 −4
@@ -98,6 +98,7 @@ window.onload = function ()
98 98 app.debugPhysics = isPhysicsDebugEnabled();
99 99 var play = document.getElementById('btn-play');
100 100 play.addEventListener('click', onPlay);
101 bindGameMenu();
101 102 play.addEventListener('pointerup', function (e)
102 103 {
103 104 // A touch-friendly path: some mobile browsers swallow the click
@@ -228,6 +229,7 @@ function startPlay (opts)
228 229 { bindPointer(app.scene.canvas); }
229 230 refreshHud();
230 231 showEl('hud');
232 setGameMenuButton(!app.online && !app.spectating);
231 233 }
232 234 catch (err)
233 235 {
@@ -327,6 +329,10 @@ function teardownPlay ()
327 329 app.columnWarn = [];
328 330 app.pointerId = null;
329 331 app.gameOverShown = false;
332 app.paused = false;
333 app.quitting = false;
334 hideEl('game-menu');
335 setGameMenuButton(false);
330 336 hideEl('hud');
331 337 hideEl('game-over');
332 338 hideEl('spectator');
@@ -894,6 +900,14 @@ function tickView (dt)
894 900 placeTile(app.cells[i], col, row);
895 901 }
896 902
903 // t1193: in-game menu open (Spelen / Offline Strijd) or quitting:
904 // the field, bots and timers stand still; only the view is kept.
905 if (app.paused)
906 {
907 syncSprites(0);
908 return;
909 }
910
897 911 app.core.tick(dt);
898 912 if (app.offline && app.battle)
899 913 { tickOffline(dt); }
@@ -1095,7 +1109,16 @@ function fieldFromEvent (e)
1095 1109
1096 1110 function playingForDrag ()
1097 1111 {
1098 return app.core && app.core.state === 'playing';
1112 return app.core && app.core.state === 'playing' && !app.paused;
1113 }
1114
1115 /** Touches on HUD buttons / menus are UI taps, not field drags (t1193). */
1116 function isUiTouchTarget (e)
1117 {
1118 var el = e && e.target;
1119 if (!el || !el.closest)
1120 { return false; }
1121 return !!el.closest('button, a, input, select, #game-menu, #reward');
1099 1122 }
1100 1123
1101 1124 function startDragFromEvent (e)
@@ -1245,6 +1268,8 @@ function onTouchStart (e)
1245 1268 {
1246 1269 if (!playingForDrag())
1247 1270 { return; }
1271 if (app.activeTouchId == null && isUiTouchTarget(e))
1272 { return; }
1248 1273 if (app.activeTouchId != null)
1249 1274 {
1250 1275 if (e.preventDefault)
@@ -2143,7 +2168,17 @@ function bindOnlineUi ()
2143 2168
2144 2169 var params = new URLSearchParams(window.location.search);
2145 2170 if (params.get('online') === '1' || params.get('auth') === 'unconfigured')
2146 { openOnlinePanel(); }
2171 {
2172 openOnlinePanel();
2173 // t1193: one-shot; a reload must not jump to online play again.
2174 try
2175 {
2176 params.delete('online');
2177 var rest = params.toString();
2178 window.history.replaceState(null, '', window.location.pathname + (rest ? '?' + rest : '') + window.location.hash);
2179 }
2180 catch (e) { /* ignore */ }
2181 }
2147 2182 }
2148 2183
2149 2184 function openOnlinePanel ()
@@ -2495,6 +2530,102 @@ function refreshMenuAccount ()
2495 2530 { localLogin.hidden = !(typeof Online !== 'undefined' && Online.local); }
2496 2531 }
2497 2532
2533 /* ---------- t1193 in-game menu (Spelen / Offline Strijd) ----------- */
2534
2535 function setGameMenuButton (show)
2536 {
2537 var btn = document.getElementById('btn-game-menu');
2538 if (btn)
2539 { btn.hidden = !show; }
2540 }
2541
2542 /** The menu can open during a running solo / offline field only. */
2543 function canOpenGameMenu ()
2544 {
2545 return app.mode === 'playing' && !!app.core && !app.online && !app.spectating
2546 && app.core.state === 'playing' && !app.rewardActive && !app.quitting
2547 && !(app.offline && app.battle && app.battle.state !== 'playing');
2548 }
2549
2550 function openGameMenu ()
2551 {
2552 if (!canOpenGameMenu())
2553 { return false; }
2554 if (app.core.drag)
2555 { finishDrag({ noLaunch: true }); }
2556 app.paused = true;
2557 showEl('game-menu');
2558 var resume = document.getElementById('btn-game-resume');
2559 if (resume && resume.focus)
2560 { resume.focus(); }
2561 return true;
2562 }
2563
2564 function resumeFromGameMenu ()
2565 {
2566 hideEl('game-menu');
2567 if (!app.quitting)
2568 { app.paused = false; }
2569 }
2570
2571 /**
2572 * "Back to main menu": ends the match now. Logged in, the points so far
2573 * go through the normal play_finish + reward screen first (the server
2574 * still applies its caps); logged out, straight to the menu. Offline
2575 * Strijd ends the whole battle (no next round).
2576 */
2577 function quitToMainMenu ()
2578 {
2579 if (!app.core || app.quitting)
2580 { return; }
2581 hideEl('game-menu');
2582 app.paused = true;
2583 app.quitting = true;
2584 app.gameOverShown = true;
2585 app.lastScore = app.core.score || 0;
2586 setGameMenuButton(false);
2587 var score = app.lastScore;
2588 var done = function ()
2589 {
2590 app.quitting = false;
2591 app.paused = false;
2592 returnToMenu();
2593 };
2594 if (rewardEnabled())
2595 {
2596 var title = (typeof I18n !== 'undefined') ? I18n.t('reward.ended') : 'Game ended';
2597 showReward(false, finishPlaySession(score), done, title);
2598 }
2599 else
2600 {
2601 finishPlaySession(score);
2602 done();
2603 }
2604 }
2605
2606 function bindGameMenu ()
2607 {
2608 var btn = document.getElementById('btn-game-menu');
2609 if (btn)
2610 { btn.addEventListener('click', function () { openGameMenu(); }); }
2611 var resume = document.getElementById('btn-game-resume');
2612 if (resume)
2613 { resume.addEventListener('click', resumeFromGameMenu); }
2614 var quit = document.getElementById('btn-game-quit');
2615 if (quit)
2616 { quit.addEventListener('click', quitToMainMenu); }
2617 document.addEventListener('keydown', function (e)
2618 {
2619 if (e.key !== 'Escape')
2620 { return; }
2621 var menu = document.getElementById('game-menu');
2622 if (menu && !menu.hidden)
2623 { resumeFromGameMenu(); }
2624 else
2625 { openGameMenu(); }
2626 });
2627 }
2628
2498 2629 function beginPlaySession (mode)
2499 2630 {
2500 2631 if (app.playToken)
@@ -2550,7 +2681,7 @@ function rewardEnabled ()
2550 2681 * next() — the same destination the mode used before (menu, next
2551 2682 * offline round, offline result, or the online lobby/podium).
2552 2683 */
2553 function showReward (won, resultPromise, next)
2684 function showReward (won, resultPromise, next, title)
2554 2685 {
2555 2686 app.rewardActive = true;
2556 2687 hideEl('game-over');
@@ -2558,6 +2689,7 @@ function showReward (won, resultPromise, next)
2558 2689 hideEl('podium');
2559 2690 var handle = Reward.play({
2560 2691 won: won,
2692 title: title || null,
2561 2693 planet: app.planet,
2562 2694 result: resultPromise,
2563 2695 onDone: function ()
@@ -2568,7 +2700,12 @@ function showReward (won, resultPromise, next)
2568 2700 }
2569 2701 });
2570 2702 if (!handle)
2571 { app.rewardActive = false; }
2703 {
2704 app.rewardActive = false;
2705 // No reward overlay (e.g. missing DOM): still continue (t1193).
2706 if (title && next)
2707 { next(); }
2708 }
2572 2709 }
2573 2710
2574 2711 function myOnlinePlace (lobby)
@@ -98,6 +98,7 @@ window.onload = function ()
98 app.debugPhysics = isPhysicsDebugEnabled();
98 app.debugPhysics = isPhysicsDebugEnabled();
99 var play = document.getElementById('btn-play');
99 var play = document.getElementById('btn-play');
100 play.addEventListener('click', onPlay);
100 play.addEventListener('click', onPlay);
101 bindGameMenu();
101 play.addEventListener('pointerup', function (e)
102 play.addEventListener('pointerup', function (e)
102 {
103 {
103 // A touch-friendly path: some mobile browsers swallow the click
104 // A touch-friendly path: some mobile browsers swallow the click
@@ -228,6 +229,7 @@ function startPlay (opts)
228 { bindPointer(app.scene.canvas); }
229 { bindPointer(app.scene.canvas); }
229 refreshHud();
230 refreshHud();
230 showEl('hud');
231 showEl('hud');
232 setGameMenuButton(!app.online && !app.spectating);
231 }
233 }
232 catch (err)
234 catch (err)
233 {
235 {
@@ -327,6 +329,10 @@ function teardownPlay ()
327 app.columnWarn = [];
329 app.columnWarn = [];
328 app.pointerId = null;
330 app.pointerId = null;
329 app.gameOverShown = false;
331 app.gameOverShown = false;
332 app.paused = false;
333 app.quitting = false;
334 hideEl('game-menu');
335 setGameMenuButton(false);
330 hideEl('hud');
336 hideEl('hud');
331 hideEl('game-over');
337 hideEl('game-over');
332 hideEl('spectator');
338 hideEl('spectator');
@@ -894,6 +900,14 @@ function tickView (dt)
894 placeTile(app.cells[i], col, row);
900 placeTile(app.cells[i], col, row);
895 }
901 }
896
902
903 // t1193: in-game menu open (Spelen / Offline Strijd) or quitting:
904 // the field, bots and timers stand still; only the view is kept.
905 if (app.paused)
906 {
907 syncSprites(0);
908 return;
909 }
910
897 app.core.tick(dt);
911 app.core.tick(dt);
898 if (app.offline && app.battle)
912 if (app.offline && app.battle)
899 { tickOffline(dt); }
913 { tickOffline(dt); }
@@ -1095,7 +1109,16 @@ function fieldFromEvent (e)
1095
1109
1096function playingForDrag ()
1110function playingForDrag ()
1097{
1111{
1098 return app.core && app.core.state === 'playing';
1112 return app.core && app.core.state === 'playing' && !app.paused;
1113}
1114
1115/** Touches on HUD buttons / menus are UI taps, not field drags (t1193). */
1116function isUiTouchTarget (e)
1117{
1118 var el = e && e.target;
1119 if (!el || !el.closest)
1120 { return false; }
1121 return !!el.closest('button, a, input, select, #game-menu, #reward');
1099}
1122}
1100
1123
1101function startDragFromEvent (e)
1124function startDragFromEvent (e)
@@ -1245,6 +1268,8 @@ function onTouchStart (e)
1245{
1268{
1246 if (!playingForDrag())
1269 if (!playingForDrag())
1247 { return; }
1270 { return; }
1271 if (app.activeTouchId == null && isUiTouchTarget(e))
1272 { return; }
1248 if (app.activeTouchId != null)
1273 if (app.activeTouchId != null)
1249 {
1274 {
1250 if (e.preventDefault)
1275 if (e.preventDefault)
@@ -2143,7 +2168,17 @@ function bindOnlineUi ()
2143
2168
2144 var params = new URLSearchParams(window.location.search);
2169 var params = new URLSearchParams(window.location.search);
2145 if (params.get('online') === '1' || params.get('auth') === 'unconfigured')
2170 if (params.get('online') === '1' || params.get('auth') === 'unconfigured')
2146 { openOnlinePanel(); }
2171 {
2172 openOnlinePanel();
2173 // t1193: one-shot; a reload must not jump to online play again.
2174 try
2175 {
2176 params.delete('online');
2177 var rest = params.toString();
2178 window.history.replaceState(null, '', window.location.pathname + (rest ? '?' + rest : '') + window.location.hash);
2179 }
2180 catch (e) { /* ignore */ }
2181 }
2147}
2182}
2148
2183
2149function openOnlinePanel ()
2184function openOnlinePanel ()
@@ -2495,6 +2530,102 @@ function refreshMenuAccount ()
2495 { localLogin.hidden = !(typeof Online !== 'undefined' && Online.local); }
2530 { localLogin.hidden = !(typeof Online !== 'undefined' && Online.local); }
2496}
2531}
2497
2532
2533/* ---------- t1193 in-game menu (Spelen / Offline Strijd) ----------- */
2534
2535function setGameMenuButton (show)
2536{
2537 var btn = document.getElementById('btn-game-menu');
2538 if (btn)
2539 { btn.hidden = !show; }
2540}
2541
2542/** The menu can open during a running solo / offline field only. */
2543function canOpenGameMenu ()
2544{
2545 return app.mode === 'playing' && !!app.core && !app.online && !app.spectating
2546 && app.core.state === 'playing' && !app.rewardActive && !app.quitting
2547 && !(app.offline && app.battle && app.battle.state !== 'playing');
2548}
2549
2550function openGameMenu ()
2551{
2552 if (!canOpenGameMenu())
2553 { return false; }
2554 if (app.core.drag)
2555 { finishDrag({ noLaunch: true }); }
2556 app.paused = true;
2557 showEl('game-menu');
2558 var resume = document.getElementById('btn-game-resume');
2559 if (resume && resume.focus)
2560 { resume.focus(); }
2561 return true;
2562}
2563
2564function resumeFromGameMenu ()
2565{
2566 hideEl('game-menu');
2567 if (!app.quitting)
2568 { app.paused = false; }
2569}
2570
2571/**
2572 * "Back to main menu": ends the match now. Logged in, the points so far
2573 * go through the normal play_finish + reward screen first (the server
2574 * still applies its caps); logged out, straight to the menu. Offline
2575 * Strijd ends the whole battle (no next round).
2576 */
2577function quitToMainMenu ()
2578{
2579 if (!app.core || app.quitting)
2580 { return; }
2581 hideEl('game-menu');
2582 app.paused = true;
2583 app.quitting = true;
2584 app.gameOverShown = true;
2585 app.lastScore = app.core.score || 0;
2586 setGameMenuButton(false);
2587 var score = app.lastScore;
2588 var done = function ()
2589 {
2590 app.quitting = false;
2591 app.paused = false;
2592 returnToMenu();
2593 };
2594 if (rewardEnabled())
2595 {
2596 var title = (typeof I18n !== 'undefined') ? I18n.t('reward.ended') : 'Game ended';
2597 showReward(false, finishPlaySession(score), done, title);
2598 }
2599 else
2600 {
2601 finishPlaySession(score);
2602 done();
2603 }
2604}
2605
2606function bindGameMenu ()
2607{
2608 var btn = document.getElementById('btn-game-menu');
2609 if (btn)
2610 { btn.addEventListener('click', function () { openGameMenu(); }); }
2611 var resume = document.getElementById('btn-game-resume');
2612 if (resume)
2613 { resume.addEventListener('click', resumeFromGameMenu); }
2614 var quit = document.getElementById('btn-game-quit');
2615 if (quit)
2616 { quit.addEventListener('click', quitToMainMenu); }
2617 document.addEventListener('keydown', function (e)
2618 {
2619 if (e.key !== 'Escape')
2620 { return; }
2621 var menu = document.getElementById('game-menu');
2622 if (menu && !menu.hidden)
2623 { resumeFromGameMenu(); }
2624 else
2625 { openGameMenu(); }
2626 });
2627}
2628
2498function beginPlaySession (mode)
2629function beginPlaySession (mode)
2499{
2630{
2500 if (app.playToken)
2631 if (app.playToken)
@@ -2550,7 +2681,7 @@ function rewardEnabled ()
2550 * next() — the same destination the mode used before (menu, next
2681 * next() — the same destination the mode used before (menu, next
2551 * offline round, offline result, or the online lobby/podium).
2682 * offline round, offline result, or the online lobby/podium).
2552 */
2683 */
2553function showReward (won, resultPromise, next)
2684function showReward (won, resultPromise, next, title)
2554{
2685{
2555 app.rewardActive = true;
2686 app.rewardActive = true;
2556 hideEl('game-over');
2687 hideEl('game-over');
@@ -2558,6 +2689,7 @@ function showReward (won, resultPromise, next)
2558 hideEl('podium');
2689 hideEl('podium');
2559 var handle = Reward.play({
2690 var handle = Reward.play({
2560 won: won,
2691 won: won,
2692 title: title || null,
2561 planet: app.planet,
2693 planet: app.planet,
2562 result: resultPromise,
2694 result: resultPromise,
2563 onDone: function ()
2695 onDone: function ()
@@ -2568,7 +2700,12 @@ function showReward (won, resultPromise, next)
2568 }
2700 }
2569 });
2701 });
2570 if (!handle)
2702 if (!handle)
2571 { app.rewardActive = false; }
2703 {
2704 app.rewardActive = false;
2705 // No reward overlay (e.g. missing DOM): still continue (t1193).
2706 if (title && next)
2707 { next(); }
2708 }
2572}
2709}
2573
2710
2574function myOnlinePlace (lobby)
2711function myOnlinePlace (lobby)
test/t1193-menu-playwright.py added +159 −0
@@ -0,0 +1,159 @@
1 #!/usr/bin/env python3
2 """t1193: in-game menu (pause / resume / back to main menu) and login return.
3
4 Usage: python3 test/t1193-menu-playwright.py URL TAG
5 Logged-out checks run anywhere (live too). With a local dev server
6 (?test= logins) the logged-in reward flow for solo and Offline Strijd and
7 the online-panel login link are checked as well.
8 """
9 import json, sys
10 from pathlib import Path
11 from playwright.sync_api import sync_playwright
12
13 URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
14 if not URL.endswith("/"): URL += "/"
15 TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
16 LOCAL = "127.0.0.1" in URL or "localhost" in URL
17 SHOTS = Path("/workspace/meteors-shots")
18 fails = []
19
20 def check(c, m):
21 print(("OK " if c else "FAIL ") + m)
22 if not c: fails.append(m)
23
24 def shot(page, name):
25 page.screenshot(path=str(SHOTS / f"t1193-{TAG}-{name}.png"))
26
27 def start(page, button="#btn-play"):
28 page.locator(button).click()
29 page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
30 page.wait_for_timeout(200)
31 page.locator("#btn-planet-go").click()
32 page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
33 page.wait_for_timeout(600)
34
35 def rect(page, sel):
36 return page.evaluate("(s) => { const r = document.querySelector(s).getBoundingClientRect(); return [r.left, r.top, r.right, r.bottom]; }", sel)
37
38 def overlap(a, b):
39 return not (a[2] <= b[0] or b[2] <= a[0] or a[3] <= b[1] or b[3] <= a[1])
40
41 def press(page, sel, mobile):
42 if mobile: page.locator(sel).tap()
43 else: page.locator(sel).click()
44
45 def layout_and_pause(page, name, mobile, mode):
46 btn = rect(page, "#btn-game-menu")
47 check(page.evaluate("() => !document.getElementById('btn-game-menu').hidden"), f"{name}/{mode}: menu button visible")
48 vw = page.evaluate("() => innerWidth")
49 check(btn[2] <= vw and btn[2] > vw - 70 and btn[1] < 60, f"{name}/{mode}: button at the top right {btn}")
50 for sel in ("#planet-name", "#planet-stats", "#score", "#offline-hud"):
51 vis = page.evaluate("(s) => { const e = document.querySelector(s); return !!e && !e.closest('[hidden]') && e.getBoundingClientRect().width > 0; }", sel)
52 if vis:
53 check(not overlap(btn, rect(page, sel)), f"{name}/{mode}: button does not overlap {sel}")
54 check(btn[2] - btn[0] >= 36 and btn[3] - btn[1] >= 36, f"{name}/{mode}: touch target ≥ 36 px")
55 shot(page, f"{name}-{mode}-hud")
56 press(page, "#btn-game-menu", mobile)
57 page.wait_for_selector("#game-menu:not([hidden])", timeout=3000)
58 t0 = page.evaluate("() => [app.core.playTime, app.core.blocks.map(b => b.y).join(',')]")
59 page.wait_for_timeout(1200)
60 t1 = page.evaluate("() => [app.core.playTime, app.core.blocks.map(b => b.y).join(','), app.paused]")
61 check(t0[0] == t1[0] and t0[1] == t1[1] and t1[2], f"{name}/{mode}: game paused while the menu is open (playTime {t0[0]:.2f})")
62 texts = page.evaluate("() => [...document.querySelectorAll('#game-menu button')].map(b => b.textContent.trim())")
63 check(len(texts) == 2 and texts[1], f"{name}/{mode}: menu buttons {texts}")
64 shot(page, f"{name}-{mode}-menu")
65 press(page, "#btn-game-resume", mobile)
66 page.wait_for_timeout(700)
67 t2 = page.evaluate("() => [app.core.playTime, app.paused, document.getElementById('game-menu').hidden]")
68 check(t2[0] > t1[0] and not t2[1] and t2[2], f"{name}/{mode}: resume continues ({t1[0]:.2f} → {t2[0]:.2f})")
69
70 def logged_out(br, name, vp, mobile):
71 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
72 page = ctx.new_page(); errs = []
73 page.on("pageerror", lambda e: errs.append(str(e)))
74 page.goto(URL + "index.html?t1193=" + TAG, wait_until="networkidle")
75 check(page.locator("#menu-login").get_attribute("href") == "auth.php", f"{name}: menu login → auth.php (returns to the main menu)")
76 check(page.locator("#btn-login").get_attribute("href") == "auth.php?return=online", f"{name}: Online-screen login → auth.php?return=online")
77 # Solo
78 start(page)
79 layout_and_pause(page, name, mobile, "solo")
80 page.evaluate("() => { app.core.score = 7; }")
81 press(page, "#btn-game-menu", mobile)
82 page.wait_for_selector("#game-menu:not([hidden])")
83 press(page, "#btn-game-quit", mobile)
84 page.wait_for_function("() => !document.getElementById('menu').hidden && app.mode === 'menu'", timeout=5000)
85 last = page.locator("#last-score strong").inner_text()
86 check(last == "7", f"{name}/solo: logged out → straight to the main menu (last score {last})")
87 check(page.evaluate("() => document.getElementById('reward').hidden"), f"{name}/solo: no reward screen when logged out")
88 shot(page, f"{name}-solo-quit-menu")
89 # Offline Strijd
90 start(page, "#btn-offline")
91 layout_and_pause(page, name, mobile, "offline")
92 press(page, "#btn-game-menu", mobile)
93 page.wait_for_selector("#game-menu:not([hidden])")
94 press(page, "#btn-game-quit", mobile)
95 page.wait_for_function("() => !document.getElementById('menu').hidden && app.mode === 'menu'", timeout=5000)
96 st = page.evaluate("() => ({ battle: app.battle, offline: app.offline, result: !document.getElementById('offline-result').hidden })")
97 check(st["battle"] is None and not st["offline"] and not st["result"], f"{name}/offline: battle ended, back in the main menu (no next round) {st}")
98 check(not errs, f"{name}: no page errors {errs[:2]}")
99 # ?online=1 is one-shot
100 page.goto(URL + "index.html?online=1", wait_until="networkidle")
101 page.wait_for_timeout(400)
102 check("online=1" not in page.url, f"{name}: ?online=1 removed from the address after use ({page.url})")
103 ctx.close()
104
105 def logged_in(br, name, vp, mobile):
106 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
107 page = ctx.new_page(); errs = []
108 page.on("pageerror", lambda e: errs.append(str(e)))
109 page.goto(URL + "auth.php?test=1&next=index.html", wait_until="domcontentloaded")
110 page.goto(URL + "index.html", wait_until="networkidle")
111 page.wait_for_function("() => typeof Online !== 'undefined' && Online.me", timeout=15000)
112 check(page.evaluate("() => !document.getElementById('menu').hidden && app.mode !== 'online'"), f"{name}: after login → main menu, logged in")
113 before = int(page.locator("#menu-points").inner_text().strip() or 0)
114 for mode, button in (("solo", "#btn-play"), ("offline", "#btn-offline")):
115 start(page, button)
116 page.wait_for_function("() => app.playToken", timeout=8000)
117 page.wait_for_timeout(3600)
118 page.evaluate("() => { app.core.score = 9; }")
119 press(page, "#btn-game-menu", mobile)
120 page.wait_for_selector("#game-menu:not([hidden])")
121 press(page, "#btn-game-quit", mobile)
122 page.wait_for_function("() => !document.getElementById('reward').hidden", timeout=5000)
123 page.wait_for_timeout(400)
124 title = page.locator("#reward-title").inner_text().strip()
125 check(title == "Game ended", f"{name}/{mode}: reward screen first, title {title!r}")
126 page.wait_for_function("() => Reward.debugState() && Reward.debugState().phase === 'hold'", timeout=30000)
127 d = page.evaluate("() => Reward.debugState()")
128 shot(page, f"{name}-{mode}-loggedin-reward")
129 check(d["after"] - d["before"] == 9, f"{name}/{mode}: 9 points added via play_finish ({d['before']} → {d['after']})")
130 page.wait_for_function("() => !document.getElementById('menu').hidden && app.mode === 'menu'", timeout=8000)
131 pts = int(page.locator("#menu-points").inner_text().strip())
132 check(pts == before + 9, f"{name}/{mode}: main menu shows {pts} == {before + 9}")
133 if mode == "offline":
134 check(page.evaluate("() => app.battle === null"), f"{name}/offline: no next round after quitting")
135 before = pts
136 # Quitting right away (< 3 s): server cap gives 0, cannot farm points.
137 start(page)
138 page.wait_for_function("() => app.playToken", timeout=8000)
139 page.evaluate("() => { app.core.score = 500; }")
140 press(page, "#btn-game-menu", mobile)
141 page.wait_for_selector("#game-menu:not([hidden])")
142 press(page, "#btn-game-quit", mobile)
143 page.wait_for_function("() => Reward.debugState() && Reward.debugState().phase === 'hold'", timeout=30000)
144 d = page.evaluate("() => Reward.debugState()")
145 check(d["after"] - d["before"] == 0, f"{name}: quick quit with a faked score of 500 → 0 points (server cap)")
146 page.wait_for_function("() => !document.getElementById('menu').hidden", timeout=8000)
147 shot(page, f"{name}-loggedin-menu")
148 check(not errs, f"{name}: logged-in no page errors {errs[:2]}")
149 ctx.close()
150
151 with sync_playwright() as pw:
152 br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
153 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
154 logged_out(br, name, vp, mobile)
155 if LOCAL:
156 logged_in(br, name, vp, mobile)
157 br.close()
158 print("ALL OK" if not fails else f"{len(fails)} FAIL")
159 sys.exit(1 if fails else 0)
@@ -0,0 +1,159 @@
1#!/usr/bin/env python3
2"""t1193: in-game menu (pause / resume / back to main menu) and login return.
3
4Usage: python3 test/t1193-menu-playwright.py URL TAG
5Logged-out checks run anywhere (live too). With a local dev server
6(?test= logins) the logged-in reward flow for solo and Offline Strijd and
7the online-panel login link are checked as well.
8"""
9import json, sys
10from pathlib import Path
11from playwright.sync_api import sync_playwright
12
13URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
14if not URL.endswith("/"): URL += "/"
15TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
16LOCAL = "127.0.0.1" in URL or "localhost" in URL
17SHOTS = Path("/workspace/meteors-shots")
18fails = []
19
20def check(c, m):
21 print(("OK " if c else "FAIL ") + m)
22 if not c: fails.append(m)
23
24def shot(page, name):
25 page.screenshot(path=str(SHOTS / f"t1193-{TAG}-{name}.png"))
26
27def start(page, button="#btn-play"):
28 page.locator(button).click()
29 page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
30 page.wait_for_timeout(200)
31 page.locator("#btn-planet-go").click()
32 page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
33 page.wait_for_timeout(600)
34
35def rect(page, sel):
36 return page.evaluate("(s) => { const r = document.querySelector(s).getBoundingClientRect(); return [r.left, r.top, r.right, r.bottom]; }", sel)
37
38def overlap(a, b):
39 return not (a[2] <= b[0] or b[2] <= a[0] or a[3] <= b[1] or b[3] <= a[1])
40
41def press(page, sel, mobile):
42 if mobile: page.locator(sel).tap()
43 else: page.locator(sel).click()
44
45def layout_and_pause(page, name, mobile, mode):
46 btn = rect(page, "#btn-game-menu")
47 check(page.evaluate("() => !document.getElementById('btn-game-menu').hidden"), f"{name}/{mode}: menu button visible")
48 vw = page.evaluate("() => innerWidth")
49 check(btn[2] <= vw and btn[2] > vw - 70 and btn[1] < 60, f"{name}/{mode}: button at the top right {btn}")
50 for sel in ("#planet-name", "#planet-stats", "#score", "#offline-hud"):
51 vis = page.evaluate("(s) => { const e = document.querySelector(s); return !!e && !e.closest('[hidden]') && e.getBoundingClientRect().width > 0; }", sel)
52 if vis:
53 check(not overlap(btn, rect(page, sel)), f"{name}/{mode}: button does not overlap {sel}")
54 check(btn[2] - btn[0] >= 36 and btn[3] - btn[1] >= 36, f"{name}/{mode}: touch target ≥ 36 px")
55 shot(page, f"{name}-{mode}-hud")
56 press(page, "#btn-game-menu", mobile)
57 page.wait_for_selector("#game-menu:not([hidden])", timeout=3000)
58 t0 = page.evaluate("() => [app.core.playTime, app.core.blocks.map(b => b.y).join(',')]")
59 page.wait_for_timeout(1200)
60 t1 = page.evaluate("() => [app.core.playTime, app.core.blocks.map(b => b.y).join(','), app.paused]")
61 check(t0[0] == t1[0] and t0[1] == t1[1] and t1[2], f"{name}/{mode}: game paused while the menu is open (playTime {t0[0]:.2f})")
62 texts = page.evaluate("() => [...document.querySelectorAll('#game-menu button')].map(b => b.textContent.trim())")
63 check(len(texts) == 2 and texts[1], f"{name}/{mode}: menu buttons {texts}")
64 shot(page, f"{name}-{mode}-menu")
65 press(page, "#btn-game-resume", mobile)
66 page.wait_for_timeout(700)
67 t2 = page.evaluate("() => [app.core.playTime, app.paused, document.getElementById('game-menu').hidden]")
68 check(t2[0] > t1[0] and not t2[1] and t2[2], f"{name}/{mode}: resume continues ({t1[0]:.2f} → {t2[0]:.2f})")
69
70def logged_out(br, name, vp, mobile):
71 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
72 page = ctx.new_page(); errs = []
73 page.on("pageerror", lambda e: errs.append(str(e)))
74 page.goto(URL + "index.html?t1193=" + TAG, wait_until="networkidle")
75 check(page.locator("#menu-login").get_attribute("href") == "auth.php", f"{name}: menu login → auth.php (returns to the main menu)")
76 check(page.locator("#btn-login").get_attribute("href") == "auth.php?return=online", f"{name}: Online-screen login → auth.php?return=online")
77 # Solo
78 start(page)
79 layout_and_pause(page, name, mobile, "solo")
80 page.evaluate("() => { app.core.score = 7; }")
81 press(page, "#btn-game-menu", mobile)
82 page.wait_for_selector("#game-menu:not([hidden])")
83 press(page, "#btn-game-quit", mobile)
84 page.wait_for_function("() => !document.getElementById('menu').hidden && app.mode === 'menu'", timeout=5000)
85 last = page.locator("#last-score strong").inner_text()
86 check(last == "7", f"{name}/solo: logged out → straight to the main menu (last score {last})")
87 check(page.evaluate("() => document.getElementById('reward').hidden"), f"{name}/solo: no reward screen when logged out")
88 shot(page, f"{name}-solo-quit-menu")
89 # Offline Strijd
90 start(page, "#btn-offline")
91 layout_and_pause(page, name, mobile, "offline")
92 press(page, "#btn-game-menu", mobile)
93 page.wait_for_selector("#game-menu:not([hidden])")
94 press(page, "#btn-game-quit", mobile)
95 page.wait_for_function("() => !document.getElementById('menu').hidden && app.mode === 'menu'", timeout=5000)
96 st = page.evaluate("() => ({ battle: app.battle, offline: app.offline, result: !document.getElementById('offline-result').hidden })")
97 check(st["battle"] is None and not st["offline"] and not st["result"], f"{name}/offline: battle ended, back in the main menu (no next round) {st}")
98 check(not errs, f"{name}: no page errors {errs[:2]}")
99 # ?online=1 is one-shot
100 page.goto(URL + "index.html?online=1", wait_until="networkidle")
101 page.wait_for_timeout(400)
102 check("online=1" not in page.url, f"{name}: ?online=1 removed from the address after use ({page.url})")
103 ctx.close()
104
105def logged_in(br, name, vp, mobile):
106 ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
107 page = ctx.new_page(); errs = []
108 page.on("pageerror", lambda e: errs.append(str(e)))
109 page.goto(URL + "auth.php?test=1&next=index.html", wait_until="domcontentloaded")
110 page.goto(URL + "index.html", wait_until="networkidle")
111 page.wait_for_function("() => typeof Online !== 'undefined' && Online.me", timeout=15000)
112 check(page.evaluate("() => !document.getElementById('menu').hidden && app.mode !== 'online'"), f"{name}: after login → main menu, logged in")
113 before = int(page.locator("#menu-points").inner_text().strip() or 0)
114 for mode, button in (("solo", "#btn-play"), ("offline", "#btn-offline")):
115 start(page, button)
116 page.wait_for_function("() => app.playToken", timeout=8000)
117 page.wait_for_timeout(3600)
118 page.evaluate("() => { app.core.score = 9; }")
119 press(page, "#btn-game-menu", mobile)
120 page.wait_for_selector("#game-menu:not([hidden])")
121 press(page, "#btn-game-quit", mobile)
122 page.wait_for_function("() => !document.getElementById('reward').hidden", timeout=5000)
123 page.wait_for_timeout(400)
124 title = page.locator("#reward-title").inner_text().strip()
125 check(title == "Game ended", f"{name}/{mode}: reward screen first, title {title!r}")
126 page.wait_for_function("() => Reward.debugState() && Reward.debugState().phase === 'hold'", timeout=30000)
127 d = page.evaluate("() => Reward.debugState()")
128 shot(page, f"{name}-{mode}-loggedin-reward")
129 check(d["after"] - d["before"] == 9, f"{name}/{mode}: 9 points added via play_finish ({d['before']} → {d['after']})")
130 page.wait_for_function("() => !document.getElementById('menu').hidden && app.mode === 'menu'", timeout=8000)
131 pts = int(page.locator("#menu-points").inner_text().strip())
132 check(pts == before + 9, f"{name}/{mode}: main menu shows {pts} == {before + 9}")
133 if mode == "offline":
134 check(page.evaluate("() => app.battle === null"), f"{name}/offline: no next round after quitting")
135 before = pts
136 # Quitting right away (< 3 s): server cap gives 0, cannot farm points.
137 start(page)
138 page.wait_for_function("() => app.playToken", timeout=8000)
139 page.evaluate("() => { app.core.score = 500; }")
140 press(page, "#btn-game-menu", mobile)
141 page.wait_for_selector("#game-menu:not([hidden])")
142 press(page, "#btn-game-quit", mobile)
143 page.wait_for_function("() => Reward.debugState() && Reward.debugState().phase === 'hold'", timeout=30000)
144 d = page.evaluate("() => Reward.debugState()")
145 check(d["after"] - d["before"] == 0, f"{name}: quick quit with a faked score of 500 → 0 points (server cap)")
146 page.wait_for_function("() => !document.getElementById('menu').hidden", timeout=8000)
147 shot(page, f"{name}-loggedin-menu")
148 check(not errs, f"{name}: logged-in no page errors {errs[:2]}")
149 ctx.close()
150
151with sync_playwright() as pw:
152 br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
153 for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
154 logged_out(br, name, vp, mobile)
155 if LOCAL:
156 logged_in(br, name, vp, mobile)
157 br.close()
158print("ALL OK" if not fails else f"{len(fails)} FAIL")
159sys.exit(1 if fails else 0)