rule: Set default rule to Twelve Men's Morris if country is Iran

This commit is contained in:
Calcitem 2021-07-11 21:43:16 +08:00
parent 19cc17215c
commit e7071bac63
No known key found for this signature in database
GPG Key ID: C596FAD04B1A465B
8 changed files with 44 additions and 14 deletions

View File

@ -17,6 +17,7 @@
*/
import 'package:sanmill/common/constants.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/style/app_theme.dart';
@ -67,10 +68,11 @@ class Config {
static int messageColor = AppTheme.messageColor.value;
// Rules
static int piecesCount = 9;
static int piecesCount = specialCountryAndRegion == "Iran" ? 12 : 9;
static int flyPieceCount = 3;
static int piecesAtLeastCount = 3;
static bool hasDiagonalLines = false;
static bool hasDiagonalLines =
specialCountryAndRegion == "Iran" ? true : false;
static bool hasBannedLocations = false;
static bool mayMoveInPlacingPhase = false;
static bool isDefenderMoveFirst = false;
@ -139,12 +141,14 @@ class Config {
settings['MessageColor'] ?? AppTheme.messageColor.value;
// Rules
rule.piecesCount = Config.piecesCount = settings['PiecesCount'] ?? 9;
rule.piecesCount = Config.piecesCount =
settings['PiecesCount'] ?? (specialCountryAndRegion == "Iran" ? 12 : 9);
rule.flyPieceCount = Config.flyPieceCount = settings['FlyPieceCount'] ?? 3;
rule.piecesAtLeastCount =
Config.piecesAtLeastCount = settings['PiecesAtLeastCount'] ?? 3;
rule.hasDiagonalLines =
Config.hasDiagonalLines = settings['HasDiagonalLines'] ?? false;
rule.hasDiagonalLines = Config.hasDiagonalLines =
settings['HasDiagonalLines'] ??
(specialCountryAndRegion == "Iran" ? true : false);
rule.hasBannedLocations =
Config.hasBannedLocations = settings['HasBannedLocations'] ?? false;
rule.mayMoveInPlacingPhase = Config.mayMoveInPlacingPhase =

View File

@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:sanmill/mill/position.dart';
enum EngineType {
@ -35,7 +36,7 @@ class EngineResponse {
}
abstract class Engine {
Future<void> setOptions() async {}
Future<void> setOptions(BuildContext context) async {}
Future<void> startup() async {}
Future<void> shutdown() async {}
Future<EngineResponse> search(Position? position);

View File

@ -18,8 +18,10 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
@ -131,7 +133,7 @@ class NativeEngine extends Engine {
await send('stop');
}
Future<void> setOptions() async {
Future<void> setOptions(BuildContext context) async {
if (Config.settingsLoaded == false) {
print("[engine] Settings is not loaded yet, now load settings...");
await Config.loadSettings();

View File

@ -565,3 +565,20 @@ Bidirectionality getBidirectionality(BuildContext context) {
return Bidirectionality.leftToRight;
}
}
String specialCountryAndRegion = "";
setSpecialCountryAndRegion(BuildContext context) {
Locale currentLocale = Localizations.localeOf(context);
switch (currentLocale.countryCode) {
case "IR":
specialCountryAndRegion = "Iran";
break;
default:
specialCountryAndRegion = "";
break;
}
print("Set Special Country and Region to $specialCountryAndRegion.");
}

View File

@ -126,6 +126,8 @@ class _SanmillAppState extends State<SanmillApp> {
@override
Widget build(BuildContext context) {
setSpecialCountryAndRegion(context);
return MaterialApp(
/// Add navigator key from Catcher.
/// It will be used to navigate user to report page or to show dialog.

View File

@ -16,13 +16,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:sanmill/l10n/resources.dart';
class Rule {
String name = "Nine Men's Morris";
String name = "Default Rule";
String description = "";
int piecesCount = 9;
int piecesCount = specialCountryAndRegion == "Iran" ? 12 : 9;
int flyPieceCount = 3;
int piecesAtLeastCount = 3;
bool hasDiagonalLines = false;
bool hasDiagonalLines = specialCountryAndRegion == "Iran" ? true : false;
bool hasBannedLocations = false;
bool mayMoveInPlacingPhase = false;
bool isDefenderMoveFirst = false;

View File

@ -1631,7 +1631,7 @@ class _GamePageState extends State<GamePage>
void didPush() async {
final route = ModalRoute.of(context)!.settings.name;
print('$tag Game Page didPush route: $route');
await widget.engine.setOptions();
await widget.engine.setOptions(context);
if (Config.languageCode != Constants.defaultLanguageCodeName) {
S.load(Locale(Config.languageCode));
setState(() {});
@ -1642,7 +1642,7 @@ class _GamePageState extends State<GamePage>
void didPopNext() async {
final route = ModalRoute.of(context)!.settings.name;
print('$tag Game Page didPopNext route: $route');
await widget.engine.setOptions();
await widget.engine.setOptions(context);
if (Config.languageCode != Constants.defaultLanguageCodeName) {
S.load(Locale(Config.languageCode));
}
@ -1652,7 +1652,7 @@ class _GamePageState extends State<GamePage>
void didPushNext() async {
final route = ModalRoute.of(context)!.settings.name;
print('$tag Game Page didPushNext route: $route');
await widget.engine.setOptions();
await widget.engine.setOptions(context);
if (Config.languageCode != Constants.defaultLanguageCodeName) {
S.load(Locale(Config.languageCode));
}

View File

@ -19,6 +19,7 @@
import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/style/app_theme.dart';
import 'package:sanmill/widgets/settings_card.dart';
@ -200,7 +201,8 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
Navigator.of(context).pop();
setState(() {
rule.piecesCount = Config.piecesCount = piecesCount ?? 9;
rule.piecesCount = Config.piecesCount =
piecesCount ?? (specialCountryAndRegion == "Iran" ? 12 : 9);
});
print("[config] rule.piecesCount: ${rule.piecesCount}");