-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBrowsingHistory.lua
74 lines (57 loc) · 1.79 KB
/
BrowsingHistory.lua
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
local _, addon = ...;
addon.BrowsingHistory = {};
local browsingHistory = addon.BrowsingHistory;
function browsingHistory:Load()
KrowiAF_SavedData = KrowiAF_SavedData or {};
KrowiAF_SavedData.BrowsingHistory = --[[KrowiAF_SavedData.BrowsingHistory or]] {};
self.Index = #KrowiAF_SavedData.BrowsingHistory;
end
local lastAddedRecord, lock;
function browsingHistory:Add(category, achievement)
if lock then
lock = nil;
return;
end
if not achievement then
return;
end
if lastAddedRecord and lastAddedRecord.CategoryId == category.Id and lastAddedRecord.AchievementId == achievement.Id then
return;
end
if category.HasFlexibleData then
category = achievement.Category;
end
lastAddedRecord = {
CategoryId = category.Id,
AchievementId = achievement.Id
};
if self.Index ~= #KrowiAF_SavedData.BrowsingHistory then
for i = self.Index + 1, #KrowiAF_SavedData.BrowsingHistory do
KrowiAF_SavedData.BrowsingHistory[i] = nil;
end
end
tinsert(KrowiAF_SavedData.BrowsingHistory, lastAddedRecord);
self.Index = #KrowiAF_SavedData.BrowsingHistory;
end
function browsingHistory:GetMinIndex()
return min(#KrowiAF_SavedData.BrowsingHistory, 1);
end
function browsingHistory:GetMaxIndex()
return #KrowiAF_SavedData.BrowsingHistory;
end
function browsingHistory:GetCurrentIndex()
return self.Index;
end
function browsingHistory:SetIndexOffset(historyOffset)
self.Index = self.Index + historyOffset;
end
function browsingHistory:GetCurrentRecord()
lock = true;
return KrowiAF_SavedData.BrowsingHistory[self.Index];
end
function browsingHistory:Unlock()
lock = nil;
end
function browsingHistory:GetAllRecords()
return KrowiAF_SavedData.BrowsingHistory;
end