44 lines
1.0 KiB
JavaScript
Executable File
44 lines
1.0 KiB
JavaScript
Executable File
DPTW.Dictionary = function(dptw, input){
|
|
|
|
const self = this,
|
|
words = [];
|
|
let started = false;
|
|
|
|
this.maximum_characters = 0;
|
|
|
|
const construct = () => {};
|
|
|
|
this.start = callback => {
|
|
|
|
const end = status => typeof callback == "function" && callback(status);
|
|
|
|
if(started){
|
|
end(false);
|
|
return false;
|
|
};
|
|
started = true;
|
|
|
|
self.add(dptw.settings("dictionary_files"), () => {
|
|
end(true);
|
|
});
|
|
|
|
return true;
|
|
};
|
|
|
|
this.add = (inputs, callback) => dptw.load_blocks(
|
|
dptw.set_array(inputs),
|
|
json => json.words.forEach(word => {
|
|
if(!words.includes(word)){
|
|
words.push(word);
|
|
word.length > self.maximum_characters && (self.maximum_characters = word.length);
|
|
};
|
|
}),
|
|
callback,
|
|
0
|
|
);
|
|
|
|
this.get_random_word = () => words[Math.random() * words.length >> 0];
|
|
|
|
construct();
|
|
|
|
}; |