Add keygen & change database

This commit is contained in:
Linloir 2022-03-07 12:04:27 +08:00
parent ba918f2b42
commit dda182c22c
15 changed files with 135 additions and 48 deletions

View File

@ -25,6 +25,12 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android { android {
compileSdkVersion flutter.compileSdkVersion compileSdkVersion flutter.compileSdkVersion
@ -50,13 +56,19 @@ android {
versionName flutterVersionName versionName flutterVersionName
} }
buildTypes { signingConfigs {
release { release {
// TODO: Add your own signing config for the release build. keyAlias keystoreProperties['keyAlias']
// Signing with the debug keys for now, so `flutter run --release` works. keyPassword keystoreProperties['keyPassword']
signingConfig signingConfigs.debug storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
} storePassword keystoreProperties['storePassword']
} }
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
} }
flutter { flutter {

View File

@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wordle"> package="com.example.wordle">
<application <application
android:label="wordle" android:label="Wordle"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_launcher">
<activity <activity

BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 544 B

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 B

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:56:05 * @Date : 2022-03-05 20:56:05
* @LastEditTime : 2022-03-07 09:35:24 * @LastEditTime : 2022-03-07 12:03:43
* @Description : The display widget of the wordle game * @Description : The display widget of the wordle game
*/ */
@ -212,6 +212,9 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
c++; c++;
}); });
} }
else {
return true;
}
} }
else if(noti.type == InputType.backSpace) { else if(noti.type == InputType.backSpace) {
if(c > 0 && !onAnimation) { if(c > 0 && !onAnimation) {

View File

@ -1,12 +1,10 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 21:50:33 * @Date : 2022-03-05 21:50:33
* @LastEditTime : 2022-03-05 23:15:18 * @LastEditTime : 2022-03-07 10:26:04
* @Description : Event bus class * @Description : Event bus class
*/ */
import 'package:flutter/material.dart';
typedef EventCallBack = void Function(dynamic args); typedef EventCallBack = void Function(dynamic args);
final EventBus mainBus = EventBus(); final EventBus mainBus = EventBus();

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-06 15:03:57 * @Date : 2022-03-06 15:03:57
* @LastEditTime : 2022-03-07 08:34:56 * @LastEditTime : 2022-03-07 11:16:16
* @Description : Word generator * @Description : Word generator
*/ */
@ -15,13 +15,13 @@ abstract class Words {
static String _cache = ""; static String _cache = "";
//static Map<String, String> explainations = {}; //static Map<String, String> explainations = {};
static Future<void> importWordsDatabase({int length = 5}) async { static Future<bool> importWordsDatabase({int length = 5}) async {
//explainations.clear(); //explainations.clear();
if(length != _length || dataBase.isEmpty){ if(length != _length || dataBase.isEmpty){
_length = length; _length = length;
dataBase.clear(); dataBase.clear();
_cache = ""; _cache = "";
var data = await rootBundle.loadString('popular.txt'); var data = await rootBundle.loadString('assets/popular.txt');
// LineSplitter.split(data).forEach((line) { // LineSplitter.split(data).forEach((line) {
// int seperatePos = line.indexOf(','); // int seperatePos = line.indexOf(',');
// if(seperatePos != length + 2) { // if(seperatePos != length + 2) {
@ -38,14 +38,20 @@ abstract class Words {
} }
_cache = line + "s"; _cache = line + "s";
}); });
print('Imported ${dataBase.length}');
} }
if(dataBase.isEmpty) {
return false;
}
return true;
} }
static Future<String> generateWord() async{ static Future<String?> generateWord() async{
int bound = dataBase.length; int bound = dataBase.length;
if(bound == 0) { if(bound == 0) {
await Words.importWordsDatabase(); var import = await Words.importWordsDatabase();
if(!import) {
return null;
}
bound = dataBase.length; bound = dataBase.length;
} }
var rng = Random(); var rng = Random();

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:41:41 * @Date : 2022-03-05 20:41:41
* @LastEditTime : 2022-03-07 09:30:56 * @LastEditTime : 2022-03-07 11:05:14
* @Description : Offline page * @Description : Offline page
*/ */
@ -40,8 +40,8 @@ class _OfflinePageState extends State<OfflinePage> with TickerProviderStateMixin
actions: [AnimatedSwitcher( actions: [AnimatedSwitcher(
duration: const Duration(milliseconds: 750), duration: const Duration(milliseconds: 750),
reverseDuration: const Duration(milliseconds: 750), reverseDuration: const Duration(milliseconds: 750),
switchInCurve: Curves.bounceInOut, switchInCurve: Curves.bounceOut,
switchOutCurve: Curves.bounceInOut, switchOutCurve: Curves.bounceIn,
transitionBuilder: (child, animation) { transitionBuilder: (child, animation) {
var rotateAnimation = Tween<double>(begin: 0, end: 2 * pi).animate(animation); var rotateAnimation = Tween<double>(begin: 0, end: 2 * pi).animate(animation);
var opacAnimation = Tween<double>(begin: 0, end: 1).animate(animation); var opacAnimation = Tween<double>(begin: 0, end: 1).animate(animation);

54
lib/show_dialogs.dart Normal file
View File

@ -0,0 +1,54 @@
/*
* @Author : Linloir
* @Date : 2022-03-07 10:28:38
* @LastEditTime : 2022-03-07 10:59:46
* @Description : Show import failed dialog
*/
import 'package:flutter/material.dart';
Future<bool?> showFailedDialog({required context}) {
return showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Error Occurred'),
content: const Text('Something went wrong when importing dictionary, nothing is imported.'),
actions: [
TextButton(
child: const Text('Retry'),
onPressed: () => Navigator.of(context).pop(true),
),
TextButton(
child: const Text('Ignore'),
onPressed: () => Navigator.of(context).pop(),
)
],
);
}
);
}
Future<bool?> showLoadingDialog({required context}) {
return showDialog(
context: context,
builder: (context) {
return UnconstrainedBox(
child: SizedBox(
width: 280,
child: AlertDialog(
contentPadding: const EdgeInsets.all(50.0),
content: Align(
alignment: Alignment.center,
child: CircularProgressIndicator(
color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.grey[850],
strokeWidth: 6.0,
),
),
),
),
);
},
barrierDismissible: false,
);
}

View File

@ -1,11 +1,12 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 21:40:51 * @Date : 2022-03-05 21:40:51
* @LastEditTime : 2022-03-07 08:10:08 * @LastEditTime : 2022-03-07 11:15:55
* @Description : Validation Provider class * @Description : Validation Provider class
*/ */
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'show_dialogs.dart';
import './event_bus.dart'; import './event_bus.dart';
import './generator.dart'; import './generator.dart';
@ -39,8 +40,22 @@ class _ValidationProviderState extends State<ValidationProvider> {
} }
void _newGame() async{ void _newGame() async{
answer = await Words.generateWord(); showLoadingDialog(context: context);
print('Generated answer $answer'); var generated = await Words.generateWord();
Navigator.of(context).pop();
while(generated == null) {
var retry = await showFailedDialog(context: context);
if(retry == null) {
Navigator.of(context).popUntil(ModalRoute.withName('/'));
break;
}
else {
showLoadingDialog(context: context);
generated = await Words.generateWord();
Navigator.of(context).pop();
}
}
answer = generated ?? "";
answer = answer.toUpperCase(); answer = answer.toUpperCase();
letterMap = {}; letterMap = {};
answer.split('').forEach((c) { answer.split('').forEach((c) {
@ -95,7 +110,6 @@ class _ValidationProviderState extends State<ValidationProvider> {
@override @override
void initState(){ void initState(){
super.initState(); super.initState();
_newGame();
mainBus.onBus(event: "NewGame", onEvent: _onNewGame); mainBus.onBus(event: "NewGame", onEvent: _onNewGame);
mainBus.onBus(event: "Result", onEvent: _onGameEnd); mainBus.onBus(event: "Result", onEvent: _onGameEnd);
} }

View File

@ -5,56 +5,56 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.8.2" version: "2.8.2"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
characters: characters:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
charcode: charcode:
dependency: transitive dependency: transitive
description: description:
name: charcode name: charcode
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
clock: clock:
dependency: transitive dependency: transitive
description: description:
name: clock name: clock
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" version: "1.15.0"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
name: cupertino_icons name: cupertino_icons
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
name: fake_async name: fake_async
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
flutter: flutter:
@ -66,7 +66,7 @@ packages:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: flutter_lints name: flutter_lints
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
flutter_test: flutter_test:
@ -78,35 +78,35 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: lints name: lints
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.11" version: "0.12.11"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.3"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.0" version: "1.7.0"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.0"
sky_engine: sky_engine:
@ -118,56 +118,56 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: source_span name: source_span
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.10.0" version: "1.10.0"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.8"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0" version: "1.3.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
sdks: sdks:

View File

@ -64,7 +64,7 @@ flutter:
assets: assets:
- assets/unixWords.txt - assets/unixWords.txt
- assets/ospd.txt - assets/ospd.txt
- popular.txt - assets/popular.txt
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware. # https://flutter.dev/assets-and-images/#resolution-aware.