Skip to content

Commit

Permalink
[game] prompt before load game from QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed May 20, 2024
1 parent d68211c commit 62be5e4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions assets/l10n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ game:
gameOver: Game over
changeGameModeRequest: Changing game mode will also delete your current save
changeGameModeAction: "Change to {}"
loadGame: Load game
loadGameFromQrCode: "Load a game of {} from QR code"
settings:
enableHapticFeedback:
title: Enable haptic feedback
Expand Down
2 changes: 2 additions & 0 deletions assets/l10n/zh-Hans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ game:
gameOver: 游戏结束
changeGameModeRequest: 切换游戏模式会同时删除你当前的存档
changeGameModeAction: "切换至 {}"
loadGame: 加载战局
loadGameFromQrCode: "从二维码中加载游戏 {} 的战局"
settings:
enableHapticFeedback:
title: 开启触觉反馈
Expand Down
2 changes: 2 additions & 0 deletions assets/l10n/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ game:
gameOver: Game over
changeGameModeRequest: 變更遊戲模式會同時刪除你當前的進度
changeGameModeAction: "變更為 {}"
loadGame: 載入戰局
loadGameFromQrCode: "從 QR 碼中載入遊戲 {} 的戰局"
settings:
enableHapticFeedback:
title: 開啟觸覺回饋
Expand Down
6 changes: 6 additions & 0 deletions lib/game/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class _I18n with CommonI18nMixin, CommonGameI18nMixin {
String get navigation => "$_ns.navigation".tr();

String get continueGame => "$_ns.continueGame".tr();

String get loadGame => "$_ns.loadGame".tr();

String loadGameFromQrCode(String gameName) => "$_ns.loadGameFromQrCode".tr(args: [
"game.$gameName.title".tr(),
]);
}

mixin class CommonGameI18nMixin {
Expand Down
9 changes: 9 additions & 0 deletions lib/game/qrcode/blueprint.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:sit/design/adaptive/dialog.dart';
import 'package:sit/qrcode/deep_link.dart';
import 'package:sit/r.dart';

import '../entity/blueprint.dart';
import '../i18n.dart';

class GameBlueprintDeepLink<TBlueprint extends GameBlueprint> implements DeepLinkHandlerProtocol {
static const host = "game";
Expand Down Expand Up @@ -43,6 +45,13 @@ class GameBlueprintDeepLink<TBlueprint extends GameBlueprint> implements DeepLin
required Uri qrCodeData,
}) async {
final blueprint = qrCodeData.query;
final confirm = await context.showActionRequest(
action: i18n.loadGame,
desc: i18n.loadGameFromQrCode(gameName),
cancel: i18n.cancel,
);
if (confirm != true) return;
if (!context.mounted) return;
await onHandleGameBlueprint(
context: context,
blueprint: blueprint,
Expand Down
2 changes: 2 additions & 0 deletions lib/qrcode/deep_link.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:sit/game/minesweeper/qrcode/blueprint.dart';
import 'package:sit/game/sudoku/qrcode/blueprint.dart';
import 'package:sit/r.dart';
import 'package:sit/settings/qrcode/proxy.dart';
import 'package:sit/timetable/qrcode/palette.dart';
Expand All @@ -24,5 +25,6 @@ abstract class DeepLinkHandlerProtocol {
const TimetablePatchDeepLink(),
const TimetableDeepLink(),
blueprintMinesweeperDeepLink,
blueprintSudokuDeepLink,
];
}

0 comments on commit 62be5e4

Please sign in to comment.