aboutsummaryrefslogtreecommitdiff
path: root/src/features/settings/helpDataLoader.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/settings/helpDataLoader.js')
-rw-r--r--src/features/settings/helpDataLoader.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/features/settings/helpDataLoader.js b/src/features/settings/helpDataLoader.js
new file mode 100644
index 0000000..21ca241
--- /dev/null
+++ b/src/features/settings/helpDataLoader.js
@@ -0,0 +1,50 @@
+import { fetch } from "../../utils/networkUtils";
+
+class HelpDataLoader {
+ constructor() {
+ this.availableHelpData = {}
+ this.dataCach = {}
+
+ fetch("http://soopy.dev/api/soopyv2/settingshelpoptions.json").json().then(data => {
+ Object.keys(data).forEach(category => {
+ this.availableHelpData[category] = new Set(data[category])
+ });
+ })
+ }
+
+ hasData(category, id) {
+ return this.availableHelpData[category] && this.availableHelpData[category].has(id)
+ }
+
+ getData(category, id, callback) {
+ if (!this.hasData(category, id)) {
+ callback("")
+ return
+ }
+
+ if (this.dataCach[category] && this.dataCach[category][id]) {
+ callback(this.dataCach[category][id])
+ return
+ }
+
+ fetch("http://soopy.dev/api/soopyv2/settingshelp/" + category + "/" + id).text().then(data => {
+ if (!this.dataCach[category]) {
+ this.dataCach[category] = {}
+ }
+
+ this.dataCach[category][id] = data
+
+ callback(data)
+ })
+ }
+}
+
+if (!global.helpDataLoader) {
+ global.helpDataLoader = new HelpDataLoader();
+
+ register("gameUnload", () => {
+ global.helpDataLoader = undefined
+ })
+}
+
+export default global.helpDataLoader; \ No newline at end of file