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

Fix get word after parameter change

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