1 |
- {"ast":null,"code":"/**\n * Class for storing data to local storage if available or in-memory storage otherwise\n */\nexport class DataStorage {\n static _GetStorage() {\n try {\n localStorage.setItem(\"test\", \"\");\n localStorage.removeItem(\"test\");\n return localStorage;\n } catch {\n const inMemoryStorage = {};\n return {\n getItem: key => {\n const value = inMemoryStorage[key];\n return value === undefined ? null : value;\n },\n setItem: (key, value) => {\n inMemoryStorage[key] = value;\n }\n };\n }\n }\n /**\n * Reads a string from the data storage\n * @param key The key to read\n * @param defaultValue The value if the key doesn't exist\n * @returns The string value\n */\n static ReadString(key, defaultValue) {\n const value = this._Storage.getItem(key);\n return value !== null ? value : defaultValue;\n }\n /**\n * Writes a string to the data storage\n * @param key The key to write\n * @param value The value to write\n */\n static WriteString(key, value) {\n this._Storage.setItem(key, value);\n }\n /**\n * Reads a boolean from the data storage\n * @param key The key to read\n * @param defaultValue The value if the key doesn't exist\n * @returns The boolean value\n */\n static ReadBoolean(key, defaultValue) {\n const value = this._Storage.getItem(key);\n return value !== null ? value === \"true\" : defaultValue;\n }\n /**\n * Writes a boolean to the data storage\n * @param key The key to write\n * @param value The value to write\n */\n static WriteBoolean(key, value) {\n this._Storage.setItem(key, value ? \"true\" : \"false\");\n }\n /**\n * Reads a number from the data storage\n * @param key The key to read\n * @param defaultValue The value if the key doesn't exist\n * @returns The number value\n */\n static ReadNumber(key, defaultValue) {\n const value = this._Storage.getItem(key);\n return value !== null ? parseFloat(value) : defaultValue;\n }\n /**\n * Writes a number to the data storage\n * @param key The key to write\n * @param value The value to write\n */\n static WriteNumber(key, value) {\n this._Storage.setItem(key, value.toString());\n }\n}\nDataStorage._Storage = DataStorage._GetStorage();","map":{"version":3,"names":["DataStorage","_GetStorage","localStorage","setItem","removeItem","inMemoryStorage","getItem","key","value","undefined","ReadString","defaultValue","_Storage","WriteString","ReadBoolean","WriteBoolean","ReadNumber","parseFloat","WriteNumber","toString"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Misc/dataStorage.js"],"sourcesContent":["/**\n * Class for storing data to local storage if available or in-memory storage otherwise\n */\nexport class DataStorage {\n static _GetStorage() {\n try {\n localStorage.setItem(\"test\", \"\");\n localStorage.removeItem(\"test\");\n return localStorage;\n }\n catch {\n const inMemoryStorage = {};\n return {\n getItem: (key) => {\n const value = inMemoryStorage[key];\n return value === undefined ? null : value;\n },\n setItem: (key, value) => {\n inMemoryStorage[key] = value;\n },\n };\n }\n }\n /**\n * Reads a string from the data storage\n * @param key The key to read\n * @param defaultValue The value if the key doesn't exist\n * @returns The string value\n */\n static ReadString(key, defaultValue) {\n const value = this._Storage.getItem(key);\n return value !== null ? value : defaultValue;\n }\n /**\n * Writes a string to the data storage\n * @param key The key to write\n * @param value The value to write\n */\n static WriteString(key, value) {\n this._Storage.setItem(key, value);\n }\n /**\n * Reads a boolean from the data storage\n * @param key The key to read\n * @param defaultValue The value if the key doesn't exist\n * @returns The boolean value\n */\n static ReadBoolean(key, defaultValue) {\n const value = this._Storage.getItem(key);\n return value !== null ? value === \"true\" : defaultValue;\n }\n /**\n * Writes a boolean to the data storage\n * @param key The key to write\n * @param value The value to write\n */\n static WriteBoolean(key, value) {\n this._Storage.setItem(key, value ? \"true\" : \"false\");\n }\n /**\n * Reads a number from the data storage\n * @param key The key to read\n * @param defaultValue The value if the key doesn't exist\n * @returns The number value\n */\n static ReadNumber(key, defaultValue) {\n const value = this._Storage.getItem(key);\n return value !== null ? parseFloat(value) : defaultValue;\n }\n /**\n * Writes a number to the data storage\n * @param key The key to write\n * @param value The value to write\n */\n static WriteNumber(key, value) {\n this._Storage.setItem(key, value.toString());\n }\n}\nDataStorage._Storage = DataStorage._GetStorage();\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,MAAMA,WAAW,CAAC;EACrB,OAAOC,WAAWA,CAAA,EAAG;IACjB,IAAI;MACAC,YAAY,CAACC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;MAChCD,YAAY,CAACE,UAAU,CAAC,MAAM,CAAC;MAC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