Skip to content

Commit

Permalink
[game] opt-in enable haptic feedback settings
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Apr 24, 2024
1 parent 93ea8bc commit ac0cbfd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/game/2048/manager/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_swipe_detector/flutter_swipe_detector.dart';
import 'package:sit/game/2048/save.dart';
import 'package:sit/game/utils.dart';
import 'package:uuid/uuid.dart';

import '../entity/tile.dart';
Expand Down Expand Up @@ -147,7 +148,7 @@ class BoardManager extends StateNotifier<Board> {
if (tile.nextIndex == next.nextIndex || tile.index == next.nextIndex && tile.nextIndex == null) {
value = tile.value + next.value;
merged = true;
HapticFeedback.lightImpact();
applyGameHapticFeedback();
score += tile.value;
i += 1;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/game/minesweeper/widget/cell/button.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:rettulf/build_context.dart';
import 'package:sit/game/utils.dart';
import '../../entity/cell.dart';
import '../../manager/logic.dart';

Expand Down Expand Up @@ -47,7 +47,7 @@ class CellButton extends ConsumerWidget {
// Click a Cover Cell => Blank
if (!flagVisible) {
manager.dig(cell: cell);
HapticFeedback.lightImpact();
applyGameHapticFeedback();
} else {
// Click a Flag Cell => Cancel Flag (Covered)
manager.removeFlag(cell: cell);
Expand All @@ -61,22 +61,22 @@ class CellButton extends ConsumerWidget {
anyChanged |= manager.digAroundBesidesFlagged(cell: cell);
anyChanged |= manager.flagRestCovered(cell: cell);
if (anyChanged) {
HapticFeedback.lightImpact();
applyGameHapticFeedback();
}
refresh();
},
onLongPress: !coverVisible
? null
: () {
manager.toggleFlag(cell: cell);
HapticFeedback.lightImpact();
applyGameHapticFeedback();
refresh();
},
onSecondaryTap: !coverVisible
? null
: () {
manager.toggleFlag(cell: cell);
HapticFeedback.lightImpact();
applyGameHapticFeedback();
refresh();
},
),
Expand Down
4 changes: 2 additions & 2 deletions lib/game/suika/domain/game_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:math';

import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/services.dart';
import 'package:sit/game/utils.dart';
import '../model/fruit.dart';
import '../entity/fruit.dart';
import '../entity/wall.dart';
Expand Down Expand Up @@ -165,7 +165,7 @@ class GameState {
fruit: newFruit,
),
);
HapticFeedback.lightImpact();
applyGameHapticFeedback();
}
}
_gameRepository.clearCollidedFruits();
Expand Down
8 changes: 8 additions & 0 deletions lib/game/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:flutter/services.dart';
import 'package:sit/settings/settings.dart';

Future<void> applyGameHapticFeedback() async {
if (Settings.game.enableHapticFeedback) {
await HapticFeedback.lightImpact();
}
}

0 comments on commit ac0cbfd

Please sign in to comment.