mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Misc. JS style tweaks
Mostly arrow function shorthand changes.
This commit is contained in:
@@ -20,11 +20,9 @@ rules:
|
||||
strict:
|
||||
- 2
|
||||
- global
|
||||
guard-for-in: 1
|
||||
no-param-reassign:
|
||||
- 2
|
||||
- props: false
|
||||
arrow-body-style: 1
|
||||
max-len: 1
|
||||
|
||||
plugins:
|
||||
|
||||
+33
-35
@@ -8,46 +8,44 @@
|
||||
root.loot = root.loot || {};
|
||||
root.loot.Dialog = factory();
|
||||
}
|
||||
}(this, () => {
|
||||
return class {
|
||||
static showProgress(text) {
|
||||
const progressDialog = document.getElementById('progressDialog');
|
||||
progressDialog.getElementsByTagName('p')[0].textContent = text;
|
||||
if (!progressDialog.opened) {
|
||||
progressDialog.open();
|
||||
} else {
|
||||
progressDialog.refit();
|
||||
}
|
||||
}(this, () => class {
|
||||
static showProgress(text) {
|
||||
const progressDialog = document.getElementById('progressDialog');
|
||||
progressDialog.getElementsByTagName('p')[0].textContent = text;
|
||||
if (!progressDialog.opened) {
|
||||
progressDialog.open();
|
||||
} else {
|
||||
progressDialog.refit();
|
||||
}
|
||||
}
|
||||
|
||||
static closeProgress() {
|
||||
const progressDialog = document.getElementById('progressDialog');
|
||||
if (progressDialog.opened) {
|
||||
progressDialog.refit();
|
||||
progressDialog.close();
|
||||
}
|
||||
static closeProgress() {
|
||||
const progressDialog = document.getElementById('progressDialog');
|
||||
if (progressDialog.opened) {
|
||||
progressDialog.refit();
|
||||
progressDialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
static showMessage(title, text) {
|
||||
const dialog = document.createElement('loot-message-dialog');
|
||||
document.body.appendChild(dialog);
|
||||
dialog.setDismissable(false);
|
||||
dialog.showModal(title, text);
|
||||
}
|
||||
static showMessage(title, text) {
|
||||
const dialog = document.createElement('loot-message-dialog');
|
||||
document.body.appendChild(dialog);
|
||||
dialog.setDismissable(false);
|
||||
dialog.showModal(title, text);
|
||||
}
|
||||
|
||||
static askQuestion(title, text, confirmText, closeCallback) {
|
||||
const dialog = document.createElement('loot-message-dialog');
|
||||
document.body.appendChild(dialog);
|
||||
dialog.setConfirmText(confirmText);
|
||||
dialog.showModal(title, text, closeCallback);
|
||||
}
|
||||
static askQuestion(title, text, confirmText, closeCallback) {
|
||||
const dialog = document.createElement('loot-message-dialog');
|
||||
document.body.appendChild(dialog);
|
||||
dialog.setConfirmText(confirmText);
|
||||
dialog.showModal(title, text, closeCallback);
|
||||
}
|
||||
|
||||
static showNotification(text) {
|
||||
const toast = document.getElementById('toast');
|
||||
if (toast.opened) {
|
||||
toast.hide();
|
||||
}
|
||||
toast.show(text);
|
||||
static showNotification(text) {
|
||||
const toast = document.getElementById('toast');
|
||||
if (toast.opened) {
|
||||
toast.hide();
|
||||
}
|
||||
};
|
||||
toast.show(text);
|
||||
}
|
||||
}));
|
||||
|
||||
+78
-79
@@ -8,97 +8,96 @@
|
||||
root.loot = root.loot || {};
|
||||
root.loot.DOM = factory();
|
||||
}
|
||||
}(this, () => {
|
||||
return class {
|
||||
static getElementInTableRowTemplate(rowTemplateId, elementClass) {
|
||||
const select = document.querySelector('link[rel="import"][href$="editable-table.html"]');
|
||||
if (select) {
|
||||
return select.import.querySelector(`#${rowTemplateId}`).content.querySelector(`.${elementClass}`);
|
||||
}(this, () => class {
|
||||
static getElementInTableRowTemplate(rowTemplateId, elementClass) {
|
||||
const select = document.querySelector('link[rel="import"][href$="editable-table.html"]');
|
||||
if (select) {
|
||||
return select.import.querySelector(`#${rowTemplateId}`).content
|
||||
.querySelector(`.${elementClass}`);
|
||||
}
|
||||
return document.querySelector(`#${rowTemplateId}`).content.querySelector(`.${elementClass}`);
|
||||
}
|
||||
|
||||
static show(elementId, showElement = true) {
|
||||
document.getElementById(elementId).hidden = !showElement;
|
||||
}
|
||||
|
||||
static enable(elementId, enableElement = true) {
|
||||
if (enableElement) {
|
||||
document.getElementById(elementId).removeAttribute('disabled');
|
||||
} else {
|
||||
document.getElementById(elementId).setAttribute('disabled', '');
|
||||
}
|
||||
}
|
||||
|
||||
static updateSelectedGame(gameFolder) {
|
||||
document.getElementById('gameMenu').value = gameFolder;
|
||||
|
||||
/* Also disable deletion of the game's row in the settings dialog. */
|
||||
const table = document.getElementById('gameTable');
|
||||
for (let i = 0; i < table.tBodies[0].rows.length; ++i) {
|
||||
const folderElements = table.tBodies[0].rows[i].getElementsByClassName('folder');
|
||||
if (folderElements.length === 1) {
|
||||
table.setReadOnly(table.tBodies[0].rows[i],
|
||||
['delete'],
|
||||
folderElements[0].value === gameFolder);
|
||||
}
|
||||
return document.querySelector(`#${rowTemplateId}`).content.querySelector(`.${elementClass}`);
|
||||
}
|
||||
}
|
||||
|
||||
static show(elementId, showElement = true) {
|
||||
document.getElementById(elementId).hidden = !showElement;
|
||||
}
|
||||
|
||||
static enable(elementId, enableElement = true) {
|
||||
if (enableElement) {
|
||||
document.getElementById(elementId).removeAttribute('disabled');
|
||||
static updateEnabledGames(installedGames) {
|
||||
const gameMenuItems = document.getElementById('gameMenu').children;
|
||||
for (let i = 0; i < gameMenuItems.length; ++i) {
|
||||
if (installedGames.indexOf(gameMenuItems[i].getAttribute('value')) === -1) {
|
||||
gameMenuItems[i].setAttribute('disabled', true);
|
||||
} else {
|
||||
document.getElementById(elementId).setAttribute('disabled', '');
|
||||
gameMenuItems[i].removeAttribute('disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static updateSelectedGame(gameFolder) {
|
||||
document.getElementById('gameMenu').value = gameFolder;
|
||||
static createGameItem(game) {
|
||||
const menuItem = document.createElement('paper-item');
|
||||
menuItem.setAttribute('value', game.folder);
|
||||
menuItem.textContent = game.name;
|
||||
|
||||
/* Also disable deletion of the game's row in the settings dialog. */
|
||||
const table = document.getElementById('gameTable');
|
||||
for (let i = 0; i < table.tBodies[0].rows.length; ++i) {
|
||||
const folderElements = table.tBodies[0].rows[i].getElementsByClassName('folder');
|
||||
if (folderElements.length === 1) {
|
||||
table.setReadOnly(table.tBodies[0].rows[i],
|
||||
['delete'],
|
||||
folderElements[0].value === gameFolder);
|
||||
}
|
||||
}
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
static setGameMenuItems(games) {
|
||||
const gameMenu = document.getElementById('gameMenu');
|
||||
|
||||
/* First make sure game listing elements don't have any existing entries. */
|
||||
while (gameMenu.firstElementChild) {
|
||||
gameMenu.removeChild(gameMenu.firstElementChild);
|
||||
}
|
||||
|
||||
static updateEnabledGames(installedGames) {
|
||||
const gameMenuItems = document.getElementById('gameMenu').children;
|
||||
for (let i = 0; i < gameMenuItems.length; ++i) {
|
||||
if (installedGames.indexOf(gameMenuItems[i].getAttribute('value')) === -1) {
|
||||
gameMenuItems[i].setAttribute('disabled', true);
|
||||
} else {
|
||||
gameMenuItems[i].removeAttribute('disabled');
|
||||
}
|
||||
}
|
||||
games.forEach((game) => {
|
||||
gameMenu.appendChild(this.createGameItem(game));
|
||||
});
|
||||
}
|
||||
|
||||
static updateSettingsDialog(settings) {
|
||||
const gameSelect = document.getElementById('defaultGameSelect');
|
||||
const gameTable = document.getElementById('gameTable');
|
||||
|
||||
/* First make sure game listing elements don't have any existing entries. */
|
||||
while (gameSelect.children.length > 1) {
|
||||
gameSelect.removeChild(gameSelect.lastElementChild);
|
||||
}
|
||||
gameTable.clear();
|
||||
|
||||
static createGameItem(game) {
|
||||
const menuItem = document.createElement('paper-item');
|
||||
menuItem.setAttribute('value', game.folder);
|
||||
menuItem.textContent = game.name;
|
||||
/* Now fill with new values. */
|
||||
settings.games.forEach((game) => {
|
||||
gameSelect.appendChild(this.createGameItem(game));
|
||||
|
||||
return menuItem;
|
||||
}
|
||||
const row = gameTable.addRow(game);
|
||||
gameTable.setReadOnly(row, ['name', 'folder', 'type']);
|
||||
});
|
||||
|
||||
static setGameMenuItems(games) {
|
||||
const gameMenu = document.getElementById('gameMenu');
|
||||
|
||||
/* First make sure game listing elements don't have any existing entries. */
|
||||
while (gameMenu.firstElementChild) {
|
||||
gameMenu.removeChild(gameMenu.firstElementChild);
|
||||
}
|
||||
|
||||
games.forEach((game) => {
|
||||
gameMenu.appendChild(this.createGameItem(game));
|
||||
});
|
||||
}
|
||||
|
||||
static updateSettingsDialog(settings) {
|
||||
const gameSelect = document.getElementById('defaultGameSelect');
|
||||
const gameTable = document.getElementById('gameTable');
|
||||
|
||||
/* First make sure game listing elements don't have any existing entries. */
|
||||
while (gameSelect.children.length > 1) {
|
||||
gameSelect.removeChild(gameSelect.lastElementChild);
|
||||
}
|
||||
gameTable.clear();
|
||||
|
||||
/* Now fill with new values. */
|
||||
settings.games.forEach((game) => {
|
||||
gameSelect.appendChild(this.createGameItem(game));
|
||||
|
||||
const row = gameTable.addRow(game);
|
||||
gameTable.setReadOnly(row, ['name', 'folder', 'type']);
|
||||
});
|
||||
|
||||
gameSelect.value = settings.game;
|
||||
document.getElementById('languageSelect').value = settings.language;
|
||||
document.getElementById('enableDebugLogging').checked = settings.enableDebugLogging;
|
||||
document.getElementById('updateMasterlist').checked = settings.updateMasterlist;
|
||||
}
|
||||
};
|
||||
gameSelect.value = settings.game;
|
||||
document.getElementById('languageSelect').value = settings.language;
|
||||
document.getElementById('enableDebugLogging').checked = settings.enableDebugLogging;
|
||||
document.getElementById('updateMasterlist').checked = settings.updateMasterlist;
|
||||
}
|
||||
}));
|
||||
|
||||
+20
-27
@@ -57,9 +57,7 @@ function updateMasterlist() {
|
||||
loot.game.globalMessages = result.globalMessages;
|
||||
|
||||
result.plugins.forEach((resultPlugin) => {
|
||||
const existingPlugin = loot.game.plugins.find((plugin) => {
|
||||
return plugin.name === resultPlugin.name;
|
||||
});
|
||||
const existingPlugin = loot.game.plugins.find(plugin => plugin.name === resultPlugin.name);
|
||||
if (existingPlugin) {
|
||||
existingPlugin.isDirty = resultPlugin.isDirty;
|
||||
existingPlugin.isPriorityGlobal = resultPlugin.isPriorityGlobal;
|
||||
@@ -70,7 +68,8 @@ function updateMasterlist() {
|
||||
}
|
||||
});
|
||||
|
||||
loot.Dialog.showNotification(loot.l10n.translate('Masterlist updated to revision %s.', loot.game.masterlist.revision));
|
||||
loot.Dialog.showNotification(loot.l10n.translate('Masterlist updated to revision %s.',
|
||||
loot.game.masterlist.revision));
|
||||
} else {
|
||||
loot.Dialog.showNotification(loot.l10n.translate('No masterlist update was necessary.'));
|
||||
}
|
||||
@@ -99,21 +98,21 @@ function onSortPlugins() {
|
||||
loot.game.globalMessages = result.globalMessages;
|
||||
|
||||
if (!result.plugins) {
|
||||
const message = result.globalMessages.find((item) => {
|
||||
return item.content[0].str.startsWith('Cyclic interaction detected');
|
||||
});
|
||||
throw new Error(loot.l10n.translate('Failed to sort plugins. Details: ' + message.content[0].str));
|
||||
const message = result.globalMessages.find(item => (
|
||||
item.content[0].str.startsWith('Cyclic interaction detected'
|
||||
))).content[0].str;
|
||||
throw new Error(loot.l10n.translate(`Failed to sort plugins. Details: ${message}`));
|
||||
}
|
||||
|
||||
/* Check if sorted load order differs from current load order. */
|
||||
const loadOrderIsUnchanged = result.plugins.every((plugin, index) => {
|
||||
return plugin.name === loot.game.plugins[index].name;
|
||||
});
|
||||
const loadOrderIsUnchanged = result.plugins.every((plugin, index) => (
|
||||
plugin.name === loot.game.plugins[index].name
|
||||
));
|
||||
if (loadOrderIsUnchanged) {
|
||||
result.plugins.forEach((plugin) => {
|
||||
const existingPlugin = loot.game.plugins.find((item) => {
|
||||
return item.name === plugin.name;
|
||||
});
|
||||
const existingPlugin = loot.game.plugins.find((item) => (
|
||||
item.name === plugin.name
|
||||
));
|
||||
if (existingPlugin) {
|
||||
existingPlugin.crc = plugin.crc;
|
||||
existingPlugin.isEmpty = plugin.isEmpty;
|
||||
@@ -129,9 +128,7 @@ function onSortPlugins() {
|
||||
loot.game.oldLoadOrder = loot.game.plugins;
|
||||
loot.game.loadOrder = [];
|
||||
result.plugins.forEach((plugin) => {
|
||||
let existingPlugin = loot.game.plugins.find((item) => {
|
||||
return item.name === plugin.name;
|
||||
});
|
||||
let existingPlugin = loot.game.plugins.find(item => item.name === plugin.name);
|
||||
if (existingPlugin) {
|
||||
existingPlugin.crc = plugin.crc;
|
||||
existingPlugin.isEmpty = plugin.isEmpty;
|
||||
@@ -195,9 +192,7 @@ function onClearAllMetadata() {
|
||||
}
|
||||
/* Need to empty the UI-side user metadata. */
|
||||
plugins.forEach((plugin) => {
|
||||
const existingPlugin = loot.game.plugins.find((item) => {
|
||||
return item.name === plugin.name;
|
||||
});
|
||||
const existingPlugin = loot.game.plugins.find(item => item.name === plugin.name);
|
||||
if (existingPlugin) {
|
||||
existingPlugin.userlist = undefined;
|
||||
existingPlugin.editor = undefined;
|
||||
@@ -381,9 +376,9 @@ function onEditorOpen(evt) {
|
||||
return loot.query('editorOpened').catch(handlePromiseError);
|
||||
}
|
||||
function onEditorClose(evt) {
|
||||
const plugin = loot.game.plugins.find((item) => {
|
||||
return item.name === evt.target.querySelector('h1').textContent;
|
||||
});
|
||||
const plugin = loot.game.plugins.find((item) => (
|
||||
item.name === evt.target.querySelector('h1').textContent
|
||||
));
|
||||
/* Update the plugin's editor state tracker */
|
||||
plugin.isEditorOpen = false;
|
||||
|
||||
@@ -430,7 +425,7 @@ function onEditorClose(evt) {
|
||||
}).catch(handlePromiseError);
|
||||
}
|
||||
function undoConflictsFilter() {
|
||||
let wasConflictsFilterEnabled = (loot.filters.conflictTargetPluginName);
|
||||
const wasConflictsFilterEnabled = (loot.filters.conflictTargetPluginName);
|
||||
|
||||
loot.filters.conflictTargetPluginName = undefined;
|
||||
/* Deactivate any existing plugin conflict filter. */
|
||||
@@ -473,9 +468,7 @@ function onClearMetadata(evt) {
|
||||
return;
|
||||
}
|
||||
/* Need to empty the UI-side user metadata. */
|
||||
const existingPlugin = loot.game.plugins.find((item) => {
|
||||
return item.id === evt.target.id;
|
||||
});
|
||||
const existingPlugin = loot.game.plugins.find(item => item.id === evt.target.id);
|
||||
if (existingPlugin) {
|
||||
existingPlugin.userlist = undefined;
|
||||
existingPlugin.editor = undefined;
|
||||
|
||||
+51
-53
@@ -8,64 +8,62 @@
|
||||
root.loot = root.loot || {};
|
||||
root.loot.Filters = factory();
|
||||
}
|
||||
}(this, () => {
|
||||
return class {
|
||||
constructor(l10n) {
|
||||
/* Plugin filters */
|
||||
this.hideMessagelessPlugins = false;
|
||||
this.hideInactivePlugins = false;
|
||||
this.conflictingPluginNames = [];
|
||||
this.contentSearchString = '';
|
||||
}(this, () => class {
|
||||
constructor(l10n) {
|
||||
/* Plugin filters */
|
||||
this.hideMessagelessPlugins = false;
|
||||
this.hideInactivePlugins = false;
|
||||
this.conflictingPluginNames = [];
|
||||
this.contentSearchString = '';
|
||||
|
||||
/* Plugin content filters */
|
||||
this.hideVersionNumbers = false;
|
||||
this.hideCRCs = false;
|
||||
this.hideBashTags = false;
|
||||
this.hideAllPluginMessages = false;
|
||||
this.hideNotes = false;
|
||||
this.hideDoNotCleanMessages = false;
|
||||
/* Plugin content filters */
|
||||
this.hideVersionNumbers = false;
|
||||
this.hideCRCs = false;
|
||||
this.hideBashTags = false;
|
||||
this.hideAllPluginMessages = false;
|
||||
this.hideNotes = false;
|
||||
this.hideDoNotCleanMessages = false;
|
||||
|
||||
this._doNotCleanString = l10n.translate('Do not clean').toLowerCase();
|
||||
this._doNotCleanString = l10n.translate('Do not clean').toLowerCase();
|
||||
}
|
||||
|
||||
pluginFilter(plugin) {
|
||||
if (this.hideInactivePlugins && !plugin.isActive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pluginFilter(plugin) {
|
||||
if (this.hideInactivePlugins && !plugin.isActive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.conflictingPluginNames.length !== 0
|
||||
&& this.conflictingPluginNames.indexOf(plugin.name) === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.hideMessagelessPlugins
|
||||
&& plugin.getCardContent(this).messages.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.contentSearchString.length !== 0
|
||||
&& !plugin.getCardContent(this).containsText(this.contentSearchString)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (this.conflictingPluginNames.length !== 0
|
||||
&& this.conflictingPluginNames.indexOf(plugin.name) === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
messageFilter(message) {
|
||||
if (this.hideAllPluginMessages) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.hideNotes && message.type === 'say') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.hideDoNotCleanMessages
|
||||
&& message.content.toLowerCase().indexOf(this._doNotCleanString) !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (this.hideMessagelessPlugins
|
||||
&& plugin.getCardContent(this).messages.length === 0) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
if (this.contentSearchString.length !== 0
|
||||
&& !plugin.getCardContent(this).containsText(this.contentSearchString)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
messageFilter(message) {
|
||||
if (this.hideAllPluginMessages) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.hideNotes && message.type === 'say') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.hideDoNotCleanMessages
|
||||
&& message.content.toLowerCase().indexOf(this._doNotCleanString) !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
||||
+299
-303
File diff suppressed because it is too large
Load Diff
@@ -22,9 +22,7 @@ function getConflictingPlugins(pluginName) {
|
||||
if (result[key].conflicts) {
|
||||
conflicts.push(key);
|
||||
}
|
||||
const plugin = loot.game.plugins.find((item) => {
|
||||
return item.name === key;
|
||||
});
|
||||
const plugin = loot.game.plugins.find(item => item.name === key);
|
||||
if (plugin) {
|
||||
plugin.crc = result[key].crc;
|
||||
plugin.isEmpty = result[key].isEmpty;
|
||||
|
||||
@@ -115,10 +115,10 @@
|
||||
}
|
||||
|
||||
if (settings.filters) {
|
||||
for (const filter in settings.filters) {
|
||||
Object.getOwnPropertyNames(settings.filters).forEach((filter) => {
|
||||
filters[filter] = settings.filters[filter];
|
||||
document.getElementById(filter).checked = filters[filter];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.hideMessagelessPlugins
|
||||
@@ -271,9 +271,7 @@
|
||||
loot.DOM.setGameMenuItems(loot.settings.games);
|
||||
loot.DOM.updateEnabledGames(loot.installedGames);
|
||||
loot.DOM.updateSelectedGame(loot.game.folder);
|
||||
}).then(() => {
|
||||
return displayInitErrors();
|
||||
}).then((result) => {
|
||||
}).then(displayInitErrors).then((result) => {
|
||||
if (result) {
|
||||
Dialog.closeProgress();
|
||||
document.getElementById('settingsButton').click();
|
||||
|
||||
@@ -61,12 +61,10 @@
|
||||
this._tags = [];
|
||||
}
|
||||
|
||||
this._messages = plugin.messages.map((message) => {
|
||||
return {
|
||||
type: message.type,
|
||||
content: message.content[0].str,
|
||||
};
|
||||
}).filter(filters.messageFilter, filters);
|
||||
this._messages = plugin.messages.map(message => ({
|
||||
type: message.type,
|
||||
content: message.content[0].str,
|
||||
})).filter(filters.messageFilter, filters);
|
||||
}
|
||||
|
||||
get name() {
|
||||
|
||||
+22
-24
@@ -8,29 +8,27 @@
|
||||
root.loot = root.loot || {};
|
||||
root.loot.query = factory();
|
||||
}
|
||||
}(this, () => {
|
||||
return (requestName, ...args) => {
|
||||
if (!requestName) {
|
||||
throw new Error('No request name passed');
|
||||
}
|
||||
let request;
|
||||
if (args.length === 0) {
|
||||
request = requestName;
|
||||
} else {
|
||||
request = JSON.stringify({
|
||||
name: requestName,
|
||||
args,
|
||||
});
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
window.cefQuery({
|
||||
request,
|
||||
persistent: false,
|
||||
onSuccess: resolve,
|
||||
onFailure: (errorCode, errorMessage) => {
|
||||
reject(new Error(`Error code: ${errorCode}; ${errorMessage}`));
|
||||
},
|
||||
});
|
||||
}(this, () => (requestName, ...args) => {
|
||||
if (!requestName) {
|
||||
throw new Error('No request name passed');
|
||||
}
|
||||
let request;
|
||||
if (args.length === 0) {
|
||||
request = requestName;
|
||||
} else {
|
||||
request = JSON.stringify({
|
||||
name: requestName,
|
||||
args,
|
||||
});
|
||||
};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
window.cefQuery({
|
||||
request,
|
||||
persistent: false,
|
||||
onSuccess: resolve,
|
||||
onFailure: (errorCode, errorMessage) => {
|
||||
reject(new Error(`Error code: ${errorCode}; ${errorMessage}`));
|
||||
},
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
+102
-105
@@ -9,119 +9,116 @@
|
||||
root.loot.State = factory(root.loot.DOM);
|
||||
root.loot.state = new root.loot.State();
|
||||
}
|
||||
}(this, (dom) => {
|
||||
return class State {
|
||||
}(this, dom => class State {
|
||||
static get DEFAULT_STATE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static get DEFAULT_STATE() {
|
||||
return 0;
|
||||
static get SORTING_STATE() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static get EDITING_STATE() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.currentState = State.DEFAULT_STATE;
|
||||
}
|
||||
|
||||
isInDefaultState() {
|
||||
return this.currentState === State.DEFAULT_STATE;
|
||||
}
|
||||
|
||||
isInEditingState() {
|
||||
return this.currentState === State.EDITING_STATE;
|
||||
}
|
||||
|
||||
isInSortingState() {
|
||||
return this.currentState === State.SORTING_STATE;
|
||||
}
|
||||
|
||||
enterSortingState() {
|
||||
if (this.isInSortingState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInEditingState()) {
|
||||
throw new Error('Cannot enter sorting state from editing state');
|
||||
}
|
||||
|
||||
static get SORTING_STATE() {
|
||||
return 1;
|
||||
/* Hide the masterlist update buttons, and display the accept and
|
||||
cancel sort buttons. */
|
||||
dom.show('updateMasterlistButton', false);
|
||||
dom.show('sortButton', false);
|
||||
dom.show('applySortButton');
|
||||
dom.show('cancelSortButton');
|
||||
|
||||
/* Disable changing game. */
|
||||
dom.enable('gameMenu', false);
|
||||
dom.enable('refreshContentButton', false);
|
||||
|
||||
this.currentState = State.SORTING_STATE;
|
||||
}
|
||||
|
||||
exitSortingState() {
|
||||
if (this.isInDefaultState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInEditingState()) {
|
||||
throw new Error('Cannot exit sorting state from editing state');
|
||||
}
|
||||
|
||||
static get EDITING_STATE() {
|
||||
return 2;
|
||||
/* Show the masterlist update buttons, and hide the accept and
|
||||
cancel sort buttons. */
|
||||
dom.show('updateMasterlistButton');
|
||||
dom.show('sortButton');
|
||||
dom.show('applySortButton', false);
|
||||
dom.show('cancelSortButton', false);
|
||||
|
||||
/* Enable changing game. */
|
||||
dom.enable('gameMenu');
|
||||
dom.enable('refreshContentButton');
|
||||
|
||||
this.currentState = State.DEFAULT_STATE;
|
||||
}
|
||||
|
||||
enterEditingState() {
|
||||
if (this.isInEditingState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInSortingState()) {
|
||||
throw new Error('Cannot enter editing state from sorting state');
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.currentState = State.DEFAULT_STATE;
|
||||
/* Disable the toolbar elements. */
|
||||
dom.enable('wipeUserlistButton', false);
|
||||
dom.enable('copyContentButton', false);
|
||||
dom.enable('refreshContentButton', false);
|
||||
dom.enable('settingsButton', false);
|
||||
dom.enable('gameMenu', false);
|
||||
dom.enable('updateMasterlistButton', false);
|
||||
dom.enable('sortButton', false);
|
||||
|
||||
this.currentState = State.EDITING_STATE;
|
||||
}
|
||||
|
||||
exitEditingState() {
|
||||
if (this.isInDefaultState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInSortingState()) {
|
||||
throw new Error('Cannot exit editing state from sorting state');
|
||||
}
|
||||
|
||||
isInDefaultState() {
|
||||
return this.currentState === State.DEFAULT_STATE;
|
||||
}
|
||||
/* Re-enable toolbar elements. */
|
||||
dom.enable('wipeUserlistButton');
|
||||
dom.enable('copyContentButton');
|
||||
dom.enable('refreshContentButton');
|
||||
dom.enable('settingsButton');
|
||||
dom.enable('gameMenu');
|
||||
dom.enable('updateMasterlistButton');
|
||||
dom.enable('sortButton');
|
||||
|
||||
isInEditingState() {
|
||||
return this.currentState === State.EDITING_STATE;
|
||||
}
|
||||
|
||||
isInSortingState() {
|
||||
return this.currentState === State.SORTING_STATE;
|
||||
}
|
||||
|
||||
enterSortingState() {
|
||||
if (this.isInSortingState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInEditingState()) {
|
||||
throw new Error('Cannot enter sorting state from editing state');
|
||||
}
|
||||
|
||||
/* Hide the masterlist update buttons, and display the accept and
|
||||
cancel sort buttons. */
|
||||
loot.DOM.show('updateMasterlistButton', false);
|
||||
loot.DOM.show('sortButton', false);
|
||||
loot.DOM.show('applySortButton');
|
||||
loot.DOM.show('cancelSortButton');
|
||||
|
||||
/* Disable changing game. */
|
||||
loot.DOM.enable('gameMenu', false);
|
||||
loot.DOM.enable('refreshContentButton', false);
|
||||
|
||||
this.currentState = State.SORTING_STATE;
|
||||
}
|
||||
|
||||
exitSortingState() {
|
||||
if (this.isInDefaultState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInEditingState()) {
|
||||
throw new Error('Cannot exit sorting state from editing state');
|
||||
}
|
||||
|
||||
/* Show the masterlist update buttons, and hide the accept and
|
||||
cancel sort buttons. */
|
||||
loot.DOM.show('updateMasterlistButton');
|
||||
loot.DOM.show('sortButton');
|
||||
loot.DOM.show('applySortButton', false);
|
||||
loot.DOM.show('cancelSortButton', false);
|
||||
|
||||
/* Enable changing game. */
|
||||
loot.DOM.enable('gameMenu');
|
||||
loot.DOM.enable('refreshContentButton');
|
||||
|
||||
this.currentState = State.DEFAULT_STATE;
|
||||
}
|
||||
|
||||
enterEditingState() {
|
||||
if (this.isInEditingState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInSortingState()) {
|
||||
throw new Error('Cannot enter editing state from sorting state');
|
||||
}
|
||||
|
||||
/* Disable the toolbar elements. */
|
||||
loot.DOM.enable('wipeUserlistButton', false);
|
||||
loot.DOM.enable('copyContentButton', false);
|
||||
loot.DOM.enable('refreshContentButton', false);
|
||||
loot.DOM.enable('settingsButton', false);
|
||||
loot.DOM.enable('gameMenu', false);
|
||||
loot.DOM.enable('updateMasterlistButton', false);
|
||||
loot.DOM.enable('sortButton', false);
|
||||
|
||||
this.currentState = State.EDITING_STATE;
|
||||
}
|
||||
|
||||
exitEditingState() {
|
||||
if (this.isInDefaultState()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInSortingState()) {
|
||||
throw new Error('Cannot exit editing state from sorting state');
|
||||
}
|
||||
|
||||
/* Re-enable toolbar elements. */
|
||||
loot.DOM.enable('wipeUserlistButton');
|
||||
loot.DOM.enable('copyContentButton');
|
||||
loot.DOM.enable('refreshContentButton');
|
||||
loot.DOM.enable('settingsButton');
|
||||
loot.DOM.enable('gameMenu');
|
||||
loot.DOM.enable('updateMasterlistButton');
|
||||
loot.DOM.enable('sortButton');
|
||||
|
||||
this.currentState = State.DEFAULT_STATE;
|
||||
}
|
||||
};
|
||||
this.currentState = State.DEFAULT_STATE;
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -11,69 +11,67 @@
|
||||
root.loot = root.loot || {};
|
||||
root.loot.Translator = factory(root.Jed, root.jedGettextParser);
|
||||
}
|
||||
}(this, (Jed, jedGettextParser) => {
|
||||
return class {
|
||||
/* Returns a Promise */
|
||||
constructor(locale) {
|
||||
this.locale = locale || 'en';
|
||||
this.jed = undefined;
|
||||
}
|
||||
}(this, (Jed, jedGettextParser) => class {
|
||||
/* Returns a Promise */
|
||||
constructor(locale) {
|
||||
this.locale = locale || 'en';
|
||||
this.jed = undefined;
|
||||
}
|
||||
|
||||
load() {
|
||||
const defaultTranslationData = {
|
||||
messages: {
|
||||
'': {
|
||||
domain: 'messages',
|
||||
lang: 'en',
|
||||
plural_forms: 'nplurals=2; plural=(n != 1);',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let translationDataPromise;
|
||||
if (this.locale === 'en') {
|
||||
/* Just resolve to an empty data set. */
|
||||
translationDataPromise = Promise.resolve(defaultTranslationData);
|
||||
} else {
|
||||
translationDataPromise = new Promise((resolve, reject) => {
|
||||
const url = `loot://l10n/${this.locale}/LC_MESSAGES/loot.mo`;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.addEventListener('readystatechange', (evt) => {
|
||||
if (evt.target.readyState === 4) {
|
||||
/* Status is 0 for local file URL loading. */
|
||||
if (evt.target.status >= 200 && evt.target.status < 400) {
|
||||
resolve(jedGettextParser.mo.parse(evt.target.response));
|
||||
} else {
|
||||
reject(new Error(evt.target.statusText));
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
return translationDataPromise.catch((error) => {
|
||||
console.log(`Error loading translation data: ${error.message}`); // eslint-disable-line no-console
|
||||
return defaultTranslationData;
|
||||
}).then((result) => {
|
||||
this.jed = new Jed({
|
||||
locale_data: result,
|
||||
load() {
|
||||
const defaultTranslationData = {
|
||||
messages: {
|
||||
'': {
|
||||
domain: 'messages',
|
||||
});
|
||||
lang: 'en',
|
||||
plural_forms: 'nplurals=2; plural=(n != 1);',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let translationDataPromise;
|
||||
if (this.locale === 'en') {
|
||||
/* Just resolve to an empty data set. */
|
||||
translationDataPromise = Promise.resolve(defaultTranslationData);
|
||||
} else {
|
||||
translationDataPromise = new Promise((resolve, reject) => {
|
||||
const url = `loot://l10n/${this.locale}/LC_MESSAGES/loot.mo`;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.addEventListener('readystatechange', (evt) => {
|
||||
if (evt.target.readyState === 4) {
|
||||
/* Status is 0 for local file URL loading. */
|
||||
if (evt.target.status >= 200 && evt.target.status < 400) {
|
||||
resolve(jedGettextParser.mo.parse(evt.target.response));
|
||||
} else {
|
||||
reject(new Error(evt.target.statusText));
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
translate(text, ...substitutions) {
|
||||
if (text === undefined) {
|
||||
return '';
|
||||
}
|
||||
if (this.jed === undefined) {
|
||||
return text;
|
||||
}
|
||||
const func = this.jed.translate(text);
|
||||
return func.fetch.apply(func, substitutions);
|
||||
return translationDataPromise.catch((error) => {
|
||||
console.log(`Error loading translation data: ${error.message}`); // eslint-disable-line no-console
|
||||
return defaultTranslationData;
|
||||
}).then((result) => {
|
||||
this.jed = new Jed({
|
||||
locale_data: result,
|
||||
domain: 'messages',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
translate(text, ...substitutions) {
|
||||
if (text === undefined) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
if (this.jed === undefined) {
|
||||
return text;
|
||||
}
|
||||
const func = this.jed.translate(text);
|
||||
return func.fetch.apply(func, substitutions);
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user