aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 4e0cc671..888bcb33 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -116,3 +116,27 @@ function applyTagMeta(tag, meta) {
function splitField(field) {
return field.length === 0 ? [] : field.split(' ');
}
+
+function importJsonDb(indexUrl, entitiesLoaded, entriesLoaded) {
+ const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/'));
+ return loadJson(indexUrl).then(index => {
+ if (entitiesLoaded !== null) {
+ return entitiesLoaded(index.entities, index.banks).then(() => index);
+ }
+
+ return index;
+ }).then(index => {
+ const loaders = [];
+ for (let i = 1; i <= index.banks; ++i) {
+ const bankUrl = `${indexDir}/bank_${i}.json`;
+ loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(entries, index.banks, i)));
+ }
+
+ let chain = Promise.resolve();
+ for (const loader of loaders) {
+ chain = chain.then(loader);
+ }
+
+ return chain;
+ });
+}