Add + use text file util

This commit is contained in:
Vortrex
2022-10-15 17:11:35 -05:00
parent bf353c10aa
commit 9c8593e833
5 changed files with 22 additions and 20 deletions

View File

@@ -35,7 +35,7 @@ function getAvailableLocaleOptions() {
// =========================================================================== // ===========================================================================
function loadLocaleConfig() { function loadLocaleConfig() {
let configFile = loadTextFile("config/client/locale.json"); let configFile = getContentsOfTextFile("config/client/locale.json");
getServerData().localeOptions = JSON.parse(configFile); getServerData().localeOptions = JSON.parse(configFile);
//resetLocaleChooserOptions(); //resetLocaleChooserOptions();
@@ -48,7 +48,7 @@ function loadAllLocaleStrings() {
let localeOptions = getServerData().localeOptions; let localeOptions = getServerData().localeOptions;
for (let i in localeOptions) { for (let i in localeOptions) {
logToConsole(LOG_INFO, `[AGRP.Locale] Loading locale strings for ${localeOptions[i].englishName} (${i})`); logToConsole(LOG_INFO, `[AGRP.Locale] Loading locale strings for ${localeOptions[i].englishName} (${i})`);
let localeStringFile = loadTextFile(`locale/${localeOptions[i].stringsFile}`); let localeStringFile = getContentsOfTextFile(`locale/${localeOptions[i].stringsFile}`);
let localeStringData = JSON.parse(localeStringFile); let localeStringData = JSON.parse(localeStringFile);
let localeId = localeOptions[i].id; let localeId = localeOptions[i].id;

View File

@@ -982,7 +982,7 @@ function getServerIntroMusicURL() {
function loadLocaleConfig() { function loadLocaleConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading locale configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading locale configuration");
let localeConfig = JSON.parse(loadTextFile(`config/locale.json`)); let localeConfig = JSON.parse(getContentsOfTextFile(`config/locale.json`));
if (localeConfig != null) { if (localeConfig != null) {
return localeConfig; return localeConfig;
} }
@@ -992,7 +992,7 @@ function loadLocaleConfig() {
function loadEconomyConfig() { function loadEconomyConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading economy configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading economy configuration");
let economyConfig = JSON.parse(loadTextFile(`config/economy.json`)); let economyConfig = JSON.parse(getContentsOfTextFile(`config/economy.json`));
if (economyConfig != null) { if (economyConfig != null) {
return economyConfig; return economyConfig;
} }
@@ -1002,7 +1002,7 @@ function loadEconomyConfig() {
function loadAccentConfig() { function loadAccentConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading accents configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading accents configuration");
let accentConfig = JSON.parse(loadTextFile(`config/accents.json`)); let accentConfig = JSON.parse(getContentsOfTextFile(`config/accents.json`));
if (accentConfig != null) { if (accentConfig != null) {
return accentConfig; return accentConfig;
} }
@@ -1012,7 +1012,7 @@ function loadAccentConfig() {
function loadDiscordConfig() { function loadDiscordConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading discord configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading discord configuration");
let discordConfig = JSON.parse(loadTextFile(`config/discord.json`)); let discordConfig = JSON.parse(getContentsOfTextFile(`config/discord.json`));
if (discordConfig != null) { if (discordConfig != null) {
return discordConfig; return discordConfig;
} }
@@ -1023,7 +1023,7 @@ function loadDiscordConfig() {
function loadDatabaseConfig() { function loadDatabaseConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading database configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading database configuration");
let databaseConfig = JSON.parse(loadTextFile("config/database.json")); let databaseConfig = JSON.parse(getContentsOfTextFile("config/database.json"));
if (databaseConfig != null) { if (databaseConfig != null) {
return databaseConfig; return databaseConfig;
} }
@@ -1034,7 +1034,7 @@ function loadDatabaseConfig() {
function loadKeyBindConfig() { function loadKeyBindConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading keybind configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading keybind configuration");
let keyBindConfig = JSON.parse(loadTextFile("config/keybind.json")); let keyBindConfig = JSON.parse(getContentsOfTextFile("config/keybind.json"));
if (keyBindConfig != null) { if (keyBindConfig != null) {
return keyBindConfig; return keyBindConfig;
} }
@@ -1045,7 +1045,7 @@ function loadKeyBindConfig() {
function loadEmailConfig() { function loadEmailConfig() {
logToConsole(LOG_DEBUG, "[AGRP.Config] Loading email configuration"); logToConsole(LOG_DEBUG, "[AGRP.Config] Loading email configuration");
let emailConfig = JSON.parse(loadTextFile("config/email.json")); let emailConfig = JSON.parse(getContentsOfTextFile("config/email.json"));
if (emailConfig != null) { if (emailConfig != null) {
return emailConfig; return emailConfig;
} }

View File

@@ -164,7 +164,7 @@ function loadAllLocaleStrings() {
let locales = getGlobalConfig().locale.locales; let locales = getGlobalConfig().locale.locales;
for (let i in locales) { for (let i in locales) {
let localeData = locales[i]; let localeData = locales[i];
let localeFile = JSON.parse(loadTextFile(`locale/${localeData.stringsFile}`)); let localeFile = JSON.parse(getContentsOfTextFile(`locale/${localeData.stringsFile}`));
tempLocaleStrings[i] = localeFile; tempLocaleStrings[i] = localeFile;
} }

View File

@@ -1481,4 +1481,10 @@ function shutdownServer() {
server.shutdown(); server.shutdown();
} }
// ===========================================================================
function getContentsOfTextFile(filePath) {
return loadTextFile(filePath);
}
// =========================================================================== // ===========================================================================

View File

@@ -9,16 +9,6 @@
// =========================================================================== // ===========================================================================
let builtInCommands = [ let builtInCommands = [
"refresh",
"restart",
"stop",
"start",
"reconnect",
"setname",
"connect",
"disconnect",
"say",
"dumpdoc",
]; ];
// =========================================================================== // ===========================================================================
@@ -1267,4 +1257,10 @@ function setServerPassword(password) {
server.setPassword(password); server.setPassword(password);
} }
// ===========================================================================
function getContentsOfTextFile(filePath) {
return "";
}
// =========================================================================== // ===========================================================================