ActivitiesItemModelManager.ts 3.2 KB
import { ConfigManager } from "simba-config-manager";
import { TimeManager } from "simba-sdk";
import { GameRecord } from "../../avg/AVG";
import { activitiesConifg } from "../../config/ActivitiesConifg";
import { activitiesTypeConfig } from "../../config/ActivitiesTypeConfig";

export interface ActivitiesConfig {
    activityId: number,
    index: number,
    activityTypeConfig: {
        activityType: number,
        taobaoTempId: number | undefined,
        pageIndex: number,
    },
    isForever: boolean,
    startTime: number,
    endTime: number,
    canClick: boolean,
    describe: string,
}

class ActivitiesItemModelManager1 {
    /**存档Key */
    private ActivitiesReaded: string = "ActivitiesReaded";

    /**
     * 获取有效的活动配置信息
     * @returns 返回值为有效的活动配置信息
     */
    getValidActivitiesConfigs(): ActivitiesConfig[] {
        let ret: ActivitiesConfig[] = [];
        let cfg = ConfigManager.getAllConfig(activitiesConifg);
        for (let id in cfg) {
            let currentTime: number = TimeManager.getTime();
            if (!cfg[id].isForever && (currentTime < cfg[id].startTime || currentTime > cfg[id].endTime)) {
                continue;
            }
            let typeConfig = ConfigManager.getConfig(activitiesTypeConfig, cfg[id].activityTypeConfig);
            ret.push({
                activityId: cfg[id].activityId,
                index: cfg[id].index,
                activityTypeConfig: {
                    activityType: typeConfig.activityType,
                    taobaoTempId: typeConfig.taobaoTempId,
                    pageIndex: typeConfig.pageIndex,
                },
                isForever: cfg[id].isForever,
                startTime: cfg[id].startTime,
                endTime: cfg[id].endTime,
                canClick: cfg[id].canClick,
                describe: cfg[id].describe,
            });
        }
        //根据活动配置索引进行排序
        ret.sort((a, b) => {
            if (a.index < b.index) {
                return -1;
            } else if (a.index > b.index) {
                return 1;
            }
            return 0;
        });
        return ret;
    }

    /**
     * 保存活动的已读状态
     * @param activityId 活动ID
     */
    setActivitiesReaded(activityId: number) {
        let readed: number[] = GameRecord.globalVariables[this.ActivitiesReaded] as number[];
        readed = readed ? readed : [];
        if (readed.indexOf(activityId) == -1) {
            readed.push(activityId);
        }
        let newReaded: number[] = [...readed];
        GameRecord.globalVariables[this.ActivitiesReaded] = newReaded;
        GameRecord.saveRecord();
    }

    /**
     * 获取活动的已读状态
     * @param activityId 活动ID
     * @returns 返回值为活动是否已读
     */
    getActivitiesReaded(activityId: number): boolean {
        let isReaded: boolean = false;
        let readed: number[] = GameRecord.globalVariables[this.ActivitiesReaded] as number[];
        readed = readed ? readed : [];
        if (readed.indexOf(activityId) !== -1) {
            isReaded = true;
        }
        return isReaded;
    }
}

export let ActivitiesItemModelManager = new ActivitiesItemModelManager1();