diff options
| author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 23:47:59 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-17 23:47:59 +0800 |
| commit | 364caae9b6e47b8d5e1bab950aebc5b35bc4baad (patch) | |
| tree | e554b5859e0135b8f644986768306d5f3ee5683e /src/features/settings/helpDataLoader.js | |
| parent | eb8bc77bf2d790e97fe793eb96ad77e1b4d2bbbf (diff) | |
| parent | 12f3a81cf12c6ffc24a7f2a0e8102dfba3fddf82 (diff) | |
| download | SoopyV2-364caae9b6e47b8d5e1bab950aebc5b35bc4baad.tar.gz SoopyV2-364caae9b6e47b8d5e1bab950aebc5b35bc4baad.tar.bz2 SoopyV2-364caae9b6e47b8d5e1bab950aebc5b35bc4baad.zip | |
Merge pull request #71 from Soopyboo32/Babel
Diffstat (limited to 'src/features/settings/helpDataLoader.js')
| -rw-r--r-- | src/features/settings/helpDataLoader.js | 50 |
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 |
