dict control

This commit is contained in:
Ben Kyd
2021-04-12 22:49:18 +01:00
parent 7554e93ec8
commit 932a530ab3
3 changed files with 70 additions and 3 deletions

View File

@@ -3,8 +3,9 @@ const Server = require('./src/webserver.js');
const Router = require('./src/router.js');
const Socket = require('./src/socketserver.js');
const Locale = require('./src/locale.js');
const Dict = require('./src/dictionary.js');
require('dotenv').config()
require('dotenv').config();
async function main()
{
@@ -12,11 +13,11 @@ async function main()
Logger.init();
await Locale.init();
await Dict.LoadTextDictionaries();
await Server.init();
await Socket.init();
await Router.init();
// await Server.
Logger.ready();
}

65
server/src/dictionary.js Normal file
View File

@@ -0,0 +1,65 @@
const Logger = require('./logger.js');
const FS = require('fs');
/*
DICTIONARY OBJECT
{
lang: code,
optimised: true,
data: {}
}
NOTES
- Data can be hashmap (not actually a hashmap, because JS or
n-ary tree, findword deals with this based on the optimised flag
*/
let Dictionaries = [];
function LoadTextDictionaries()
{
Logger.info('LOADING SCRABBLE DICTIONARIES');
let langsToLoad = [];
FS.readdirSync('../data/').map(e => {
if (e.endsWith('.dict')) langsToLoad.push(e);
});
for (let lang of langsToLoad)
{
Logger.info(`LOADING ${lang} ...`);
Dictionaries.push({
lang: lang.split('-')[0],
optimised: false,
data: FS.readFileSync(`../data/${lang}`).toString().split('\n')
});
}
}
function GenerateDictionaryTrees()
{
}
function FindWord(lang, word)
{
let ret = "";
for (const language of Dictionaries)
{
if (language.lang !== lang) continue;
}
}
module.exports = {
LoadTextDictionaries: LoadTextDictionaries,
GenerateDictionaryTrees: GenerateDictionaryTrees,
FindWord: FindWord
};

View File

@@ -6,8 +6,9 @@ let locales = {};
async function init()
{
Logger.info('LOADING LOCALES');
locales = JSON.parse(FS.readFileSync('../data/locale.json'));
Logger.info('LOCALES LOADED');
Logger.info(`LOADING locale.json ...`);
}
function GetLocaleListJSON()