ActivitiesItemModelManager.ts
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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();