32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { JungleActivityConfig } from "./JungleTypes";
|
|
|
|
/** 只负责活动进度的本地持久化。 */
|
|
export default class JungleProgress {
|
|
private readonly storagePrefix: string = "jungle_treasure_progress_";
|
|
|
|
public read(config: JungleActivityConfig, previewAnimationOnly: boolean): number {
|
|
if (!config || previewAnimationOnly) {
|
|
return 0;
|
|
}
|
|
const value = parseInt(cc.sys.localStorage.getItem(this.getStorageKey(config)) || "0", 10);
|
|
return Math.max(0, Math.min(isNaN(value) ? 0 : value, config.tiers.length));
|
|
}
|
|
|
|
public save(config: JungleActivityConfig, currentTierIndex: number): void {
|
|
if (!config) {
|
|
return;
|
|
}
|
|
cc.sys.localStorage.setItem(this.getStorageKey(config), currentTierIndex.toString());
|
|
}
|
|
|
|
public reset(config: JungleActivityConfig): void {
|
|
if (config) {
|
|
cc.sys.localStorage.removeItem(this.getStorageKey(config));
|
|
}
|
|
}
|
|
|
|
private getStorageKey(config: JungleActivityConfig): string {
|
|
return this.storagePrefix + (config ? config.activityId : "default");
|
|
}
|
|
}
|