56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { sys } from 'cc'
|
|
|
|
export default class LocalStorage {
|
|
public static GamePreFlag: string = 'fengshen-game-HaoLocalStorage'
|
|
|
|
public static setItem(key: string, value: string): void {
|
|
sys.localStorage.setItem(LocalStorage.GamePreFlag + key, value)
|
|
}
|
|
|
|
public static getItem(key: string): string {
|
|
return sys.localStorage.getItem(LocalStorage.GamePreFlag + key)
|
|
}
|
|
|
|
public static removeItem(key: string): void {
|
|
sys.localStorage.removeItem(LocalStorage.GamePreFlag + key)
|
|
}
|
|
|
|
public static getInt(key: string): number {
|
|
const tempValue: string = LocalStorage.getItem(key)
|
|
let result: number = 0
|
|
if (tempValue) result = Number.parseInt(tempValue)
|
|
|
|
return result
|
|
}
|
|
|
|
public static setInt(key: string, value: number): void {
|
|
LocalStorage.setItem(key, value.toString())
|
|
}
|
|
|
|
public static getFloat(key: string): number {
|
|
const tempValue: string = LocalStorage.getItem(key)
|
|
let result: number = 0
|
|
if (tempValue) result = Number.parseFloat(tempValue)
|
|
|
|
return result
|
|
}
|
|
|
|
public static setFloat(key: string, value: number): void {
|
|
LocalStorage.setItem(key, value.toString())
|
|
}
|
|
|
|
public static getBoolean(key: string): boolean {
|
|
const temp: number = LocalStorage.getInt(key)
|
|
return temp === 1
|
|
}
|
|
|
|
public static setBoolean(key: string, value: boolean) {
|
|
if (value) LocalStorage.setInt(key, 1)
|
|
else LocalStorage.setInt(key, 0)
|
|
}
|
|
|
|
public static clear() {
|
|
sys.localStorage.clear()
|
|
}
|
|
}
|