vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[-------------------------------------------------------------------------------- |
2 | ItemSync Optimize Cleaner Framework |
||
3 | |||
4 | Author: Derkyle |
||
5 | Website: http://www.manaflux.com |
||
6 | -----------------------------------------------------------------------------------]] |
||
7 | |||
8 | local ISync_OptCount = 0; |
||
9 | local ISync_OptCount_Current = 0; |
||
10 | local ISync_Opt_List = { }; |
||
11 | |||
12 | --------------------------------------------------- |
||
13 | -- ISync:Optimize_Load |
||
14 | --------------------------------------------------- |
||
15 | function ISync:Optimize_Load() |
||
16 | |||
17 | --initiate the timer variables |
||
18 | ISync_Optimize_Timer.Todo = {}; |
||
19 | ISync_Optimize_Timer.Todo.n = 0; |
||
20 | |||
21 | end |
||
22 | |||
23 | |||
24 | --------------------------------------------------- |
||
25 | -- ISync:Optimize_Update() |
||
26 | --------------------------------------------------- |
||
27 | function ISync:Optimize_Update() |
||
28 | |||
29 | while(ISync_Optimize_Timer.Todo[1] and |
||
30 | |||
31 | ISync_Optimize_Timer.Todo[1].time <= GetTime()) do |
||
32 | |||
33 | --load the todo variable |
||
34 | local todo = table.remove(ISync_Optimize_Timer.Todo,1); |
||
35 | |||
36 | --check if there are arguments if so then load them |
||
37 | if(todo.args) then |
||
38 | todo.handler(unpack(todo.args)); |
||
39 | --otherwise run the function |
||
40 | else |
||
41 | todo.handler(); |
||
42 | end--if(todo.args) then |
||
43 | |||
44 | end--end while |
||
45 | |||
46 | end |
||
47 | |||
48 | |||
49 | --------------------------------------------------- |
||
50 | -- ISync:Optimize_Add() |
||
51 | --------------------------------------------------- |
||
52 | function ISync:Optimize_Add(when,handler,...) |
||
53 | |||
54 | --load the todo variable |
||
55 | local todo = {}; |
||
56 | local i = 1; |
||
57 | |||
58 | --set the time so that we can determine time passed later |
||
59 | todo.time = when + GetTime(); |
||
60 | --save the handler for processing later |
||
61 | todo.handler = handler; |
||
62 | --save the arguements if there are any |
||
63 | todo.args = arg; |
||
64 | |||
65 | --start the while loop |
||
66 | while(ISync_Optimize_Timer.Todo[i] and |
||
67 | |||
68 | --syncronize the time |
||
69 | ISync_Optimize_Timer.Todo[i].time < todo.time) do |
||
70 | i = i + 1; |
||
71 | end |
||
72 | |||
73 | --insert the finished product into the frame's todo array |
||
74 | table.insert(ISync_Optimize_Timer.Todo,i,todo); |
||
75 | |||
76 | end |
||
77 | |||
78 | |||
79 | -------------------------------------------------------------------------------------------------------------------------------- |
||
80 | -------------------------------------------------------------------------------------------------------------------------------- |
||
81 | -------------------------------------------------------------------------------------------------------------------------------- |
||
82 | -------------------------------------------------------------------------------------------------------------------------------- |
||
83 | -------------------------------------------------------------------------------------------------------------------------------- |
||
84 | -------------------------------------------------------------------------------------------------------------------------------- |
||
85 | |||
86 | |||
87 | |||
88 | --------------------------------------------------- |
||
89 | -- ISync:Optimize |
||
90 | --------------------------------------------------- |
||
91 | function ISync:Optimize(sNum) |
||
92 | local upNum = 0; |
||
93 | local sParseLink; |
||
94 | local storeProcessedLink; |
||
95 | |||
96 | if(sNum == 0) then |
||
97 | ISync_Optimize_Timer.Todo = {}; |
||
98 | ISync_Optimize_Timer.Todo.n = 0; |
||
99 | ISync_OptCount = 0; |
||
100 | ISync_OptCount_Current = 0; |
||
101 | ISync_Opt_List = nil; |
||
102 | ISync_Opt_List = { }; |
||
103 | sNum = 1; --MAKE SURE TO SET THIS TO 1 |
||
104 | end |
||
105 | |||
106 | |||
107 | --check on database |
||
108 | if(not ISyncDB) then return nil; end --the database should have been created |
||
109 | if(not ISyncDB[ISYNC_REALM_NUM]) then return nil; end --don't even bother |
||
110 | if(not sNum and ISync_OptCount_Current) then sNum = ISync_OptCount_Current; end |
||
111 | if(not sNum and ISync_OptCount_Current == 0) then return nil; end |
||
112 | if(not ISync_Opt_List) then ISync_Opt_List = { }; end |
||
113 | |||
114 | --disable the button |
||
115 | ISync_OptionsOptimizeButton:Disable(); |
||
116 | |||
117 | --get the itemcount only if it hasn't been done already |
||
118 | if(ISync_OptCount == 0) then |
||
119 | |||
120 | --loop through items |
||
121 | for index, value in ISyncDB[ISYNC_REALM_NUM] do |
||
122 | |||
123 | --it's pointless to do subitems since they share the same basic stats |
||
124 | local sParseLink = ISync:FetchDB(index, "subitem"); |
||
125 | |||
126 | if(not sParseLink) then --this item has no subitems, cause it's subitem value = 0 |
||
127 | |||
128 | table.insert(ISync_Opt_List, index..":0:0:0"); |
||
129 | |||
130 | ISync_OptCount = ISync_OptCount + 1; |
||
131 | |||
132 | end--if(not sParseLink) then |
||
133 | |||
134 | end |
||
135 | |||
136 | --check for errors |
||
137 | if(not ISync_OptCount) then |
||
138 | |||
139 | if( DEFAULT_CHAT_FRAME ) then |
||
140 | DEFAULT_CHAT_FRAME:AddMessage("|c0000FF00ItemSync: There were no items to process."); |
||
141 | end |
||
142 | |||
143 | --Enable the button |
||
144 | ISync_OptionsOptimizeButton:Enable(); |
||
145 | |||
146 | return nil; |
||
147 | |||
148 | elseif(ISync_OptCount == 0) then |
||
149 | |||
150 | if( DEFAULT_CHAT_FRAME ) then |
||
151 | DEFAULT_CHAT_FRAME:AddMessage("|c0000FF00ItemSync: There were no items to process."); |
||
152 | end |
||
153 | |||
154 | --Enable the button |
||
155 | ISync_OptionsOptimizeButton:Enable(); |
||
156 | |||
157 | return nil; |
||
158 | |||
159 | else |
||
160 | --set the status bar |
||
161 | ISync_Optimize_Bar:SetAlpha(1); |
||
162 | ISync_Optimize_BarFrameStatusBar:SetStatusBarColor(1, 1, 0); |
||
163 | ISync_Optimize_BarFrameStatusBar:SetMinMaxValues(0, ISync_OptCount); |
||
164 | ISync_Optimize_Bar:Show(); |
||
165 | end |
||
166 | |||
167 | |||
168 | |||
169 | end |
||
170 | |||
171 | --CHECK AGAIN |
||
172 | --You cannot have an element of zero |
||
173 | if(sNum == 0) then sNum = 1; end |
||
174 | |||
175 | |||
176 | --check count |
||
177 | if(ISync_Opt_List[sNum]) then |
||
178 | |||
179 | --lets do 500 of them |
||
180 | for iCount=sNum , (sNum + 500) , 1 do |
||
181 | |||
182 | --increment |
||
183 | ISync_OptCount_Current = ISync_OptCount_Current + 1; |
||
184 | |||
185 | |||
186 | --do a check |
||
187 | if(ISync_Opt_List[iCount]) then |
||
188 | |||
189 | --check the data |
||
190 | ISync:Optimize_ChkData(ISync_Opt_List[iCount]); |
||
191 | |||
192 | --it doesn't exist so lets break |
||
193 | elseif(not ISync_Opt_List[iCount]) then |
||
194 | |||
195 | break; --break the for loop and end at the bottom |
||
196 | |||
197 | end |
||
198 | |||
199 | |||
200 | --check to repeat |
||
201 | if(ISync_Opt_List[iCount] and iCount >= (sNum + 500)) then |
||
202 | |||
203 | --fix the count |
||
204 | if(ISync_OptCount_Current > ISync_OptCount) then |
||
205 | ISync_Optimize_BarText:SetText( ISync_OptCount.."/"..ISync_OptCount ); |
||
206 | else |
||
207 | ISync_Optimize_BarText:SetText( ISync_OptCount_Current.."/"..ISync_OptCount ); |
||
208 | end |
||
209 | |||
210 | --do the value |
||
211 | ISync_Optimize_BarFrameStatusBar:SetValue(ISync_OptCount_Current); |
||
212 | |||
213 | ISync:Optimize_Add(7, ISync.Optimize, ISync_OptCount_Current); |
||
214 | |||
215 | return nil; |
||
216 | |||
217 | end |
||
218 | |||
219 | |||
220 | |||
221 | |||
222 | end--for iCount=sNum , (sNum + 500) , 1 do |
||
223 | |||
224 | end--if(ISync_Opt_List[sNum]) then |
||
225 | |||
226 | |||
227 | --clear out |
||
228 | ISync_Opt_List = nil; |
||
229 | |||
230 | ISync_Optimize_BarText:SetText( ISync_OptCount_Current.."/"..ISync_OptCount ); |
||
231 | ISync_Optimize_BarFrameStatusBar:SetValue(ISync_OptCount_Current); |
||
232 | ISync_Optimize_Bar:Hide(); --hide it |
||
233 | |||
234 | DEFAULT_CHAT_FRAME:AddMessage("|c0000FF00ItemSync: "..ISYNC_OPTIMIZE_COMPLETE.."!"); |
||
235 | |||
236 | --Enable the button |
||
237 | ISync_OptionsOptimizeButton:Enable(); |
||
238 | |||
239 | end |
||
240 | |||
241 | |||
242 | |||
243 | --------------------------------------------------- |
||
244 | -- ISync:Optimize_ChkData() |
||
245 | --------------------------------------------------- |
||
246 | function ISync:Optimize_ChkData(sName) |
||
247 | |||
248 | if(not sName) then return nil; end |
||
249 | |||
250 | --attach variable |
||
251 | local index = sName; |
||
252 | local sParseLink; |
||
253 | local storeProcessedLink; |
||
254 | local storeLink; |
||
255 | |||
256 | --------------------------------------------------------------------------- |
||
257 | if(index) then |
||
258 | |||
259 | --check link |
||
260 | local name_X, link_X, quality_X, minLevel_X, class_X, subclass_X, maxStack_X = GetItemInfo("item:"..index); |
||
261 | |||
262 | if(sName and link_X) then |
||
263 | |||
264 | ISync:Do_Parse(UIParent, ISyncTooltip, ISync:GetCoreID(index), link_X); |
||
265 | |||
266 | end--if(name_X and link_X and ISYNC_REALM_NUM) then |
||
267 | |||
268 | |||
269 | end |
||
270 | ------------------------------------------------------------------------------ |
||
271 | |||
272 | |||
273 | end |
||
274 |