mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Refactor filter initialisation
This commit is contained in:
@@ -97,7 +97,33 @@
|
||||
}).catch(handlePromiseError);
|
||||
}
|
||||
|
||||
areAnyFiltersActive() {
|
||||
return this.hideMessagelessPlugins
|
||||
|| this.hideInactivePlugins
|
||||
|| this.conflictingPluginNames
|
||||
|| this.contentSearchString
|
||||
|| this.hideVersionNumbers
|
||||
|| this.hideCRCs
|
||||
|| this.hideBashTags
|
||||
|| this.hideAllPluginMessages
|
||||
|| this.hideNotes
|
||||
|| this.hideDoNotCleanMessages;
|
||||
}
|
||||
|
||||
load(filterSettings) {
|
||||
if (filterSettings) {
|
||||
Object.getOwnPropertyNames(filterSettings).forEach((filter) => {
|
||||
this[filter] = filterSettings[filter];
|
||||
document.getElementById(filter).checked = this[filter];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
apply(plugins) {
|
||||
if (!this.areAnyFiltersActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const filteredPlugins = plugins.filter(this.pluginFilter, this);
|
||||
|
||||
document.getElementById('cardsNav').items = filteredPlugins;
|
||||
|
||||
@@ -117,39 +117,6 @@
|
||||
document.addEventListener('loot-game-plugins-change', Game.onPluginsChange);
|
||||
}
|
||||
|
||||
function applyEnabledFilters(filters, settings, plugins) {
|
||||
if (!filters) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.filters) {
|
||||
Object.getOwnPropertyNames(settings.filters).forEach((filter) => {
|
||||
filters[filter] = settings.filters[filter];
|
||||
document.getElementById(filter).checked = filters[filter];
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.hideMessagelessPlugins
|
||||
|| filters.hideInactivePlugins
|
||||
|| filters.hideNotes
|
||||
|| filters.hideDoNotCleanMessages
|
||||
|| filters.hideAllPluginMessages) {
|
||||
filters.apply(plugins);
|
||||
}
|
||||
|
||||
if (filters.hideVersionNumbers) {
|
||||
document.getElementById('hideVersionNumbers').dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
if (filters.hideCRCs) {
|
||||
document.getElementById('hideCRCs').dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
if (filters.hideBashTags) {
|
||||
document.getElementById('hideBashTags').dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
|
||||
function splitVersion(version) {
|
||||
const lastPeriodIndex = version.lastIndexOf('.');
|
||||
return {
|
||||
@@ -211,7 +178,8 @@
|
||||
document.getElementById('cardsNav').items = appData.game.plugins;
|
||||
document.getElementById('pluginCardList').items = appData.game.plugins;
|
||||
appData.Filters.fillConflictsFilterList(appData.game.plugins);
|
||||
applyEnabledFilters(appData.filters, appData.settings, appData.game.plugins);
|
||||
appData.filters.load(appData.settings.filters);
|
||||
appData.filters.apply(appData.game.plugins);
|
||||
Dialog.closeProgress();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user