Skip to content
Snippets Groups Projects
Commit 12d26adc authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '22-fix-get-word-after-length-change' into 'master'

Resolve "Fix get word after length change"

Closes #22

See merge request !14
parents e3f859c4 17f0816f
No related branches found
No related tags found
1 merge request!14Resolve "Fix get word after length change"
Pipeline #2598 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.9
app.versionCode=9
app.versionName=0.0.10
app.versionCode=10
......@@ -7,6 +7,8 @@ import 'package:flutter/services.dart';
class RandomPickWord {
static Set<String> wordList = <String>{};
static Set<String> dictionary = <String>{};
static String _lang = '';
static int _length = 5;
static String _level = '';
......@@ -16,22 +18,18 @@ class RandomPickWord {
String get word => _word;
init(String lang, int length, String level) async {
if (lang != _lang || length != _length || level != _level || wordList.isEmpty || dictionary.isEmpty) {
_lang = lang;
_length = length;
_level = level;
_word = '';
await wordFromLocalFile(lang, length, level);
}
Future<void> wordFromLocalFile(String lang, int length, String level) async {
if (length != _length || level != _level || wordList.isEmpty || dictionary.isEmpty) {
_length = length;
_level = level;
dictionary.clear();
wordList.clear();
String wordBaseFilename = 'words-' + length.toString() + '-' + lang;
// Get full dictionary (eligible words)
print('Reload dictionary');
print('Reload dictionary / ' + lang + ' / ' + length.toString());
try {
String wordsFile = wordBaseFilename + '-' + 'dictionary';
var data = await rootBundle.loadString('assets/files/' + wordsFile + '.txt');
......@@ -45,7 +43,7 @@ class RandomPickWord {
}
// Get guessable words list (will pick random word from)
print('Reload words list (' + level + ')');
print('Reload words list / ' + lang + ' / ' + length.toString() + ' / ' + level);
try {
String wordsFile = wordBaseFilename + '-' + level;
var data = await rootBundle.loadString('assets/files/' + wordsFile + '.txt');
......@@ -57,12 +55,16 @@ class RandomPickWord {
} catch (e) {
throw "Failed loading words database";
}
}
print('Words in dictionary: ' + dictionary.length.toString());
print('Words in words list: ' + wordList.length.toString());
_word = '';
await wordFromLocalFile();
}
Future<void> wordFromLocalFile() async {
// Check we have enough words
if (wordList.length < 1) {
print('Not enough words in list.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment