dict control
This commit is contained in:
@@ -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
65
server/src/dictionary.js
Normal 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
|
||||
};
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user