Mercurial > wow > breuesk
comparison Lists.lua @ 1:21c58930f74e
Refactoring
author | John@Yosemite-PC |
---|---|
date | Fri, 02 Mar 2012 22:32:12 -0500 |
parents | 47fac96968e1 |
children | 00286ba3b9c4 |
comparison
equal
deleted
inserted
replaced
0:47fac96968e1 | 1:21c58930f74e |
---|---|
36 local u = { } | 36 local u = { } |
37 for k, v in pairs(t) do u[k] = v end | 37 for k, v in pairs(t) do u[k] = v end |
38 return setmetatable(u, getmetatable(t)) | 38 return setmetatable(u, getmetatable(t)) |
39 end | 39 end |
40 | 40 |
41 -- Debugging {{{ | |
42 function bsk:PrintLists() | |
43 bsk:PrintTable(bsk.lists) | |
44 end | |
45 function bsk:PrintChanges() | |
46 bsk:PrintTable(bsk.db.profile.changes) | |
47 end | |
48 function bsk:PrintPlayers() | |
49 bsk:PrintTable(bsk.players) | |
50 end | |
41 function bsk:PrintTable(table, depth) | 51 function bsk:PrintTable(table, depth) |
42 depth = depth or "" | 52 depth = depth or "" |
43 if not table then return end | 53 if not table then return end |
44 for i,v in pairs(table) do | 54 for i,v in pairs(table) do |
45 if( type(v) == "string" ) then | 55 if( type(v) == "string" ) then |
55 self:Print(depth .. i .. " - not sure how to print type: " .. type(v) ) | 65 self:Print(depth .. i .. " - not sure how to print type: " .. type(v) ) |
56 end | 66 end |
57 end | 67 end |
58 end | 68 end |
59 | 69 |
60 -- Debugging {{{ | |
61 function bsk:PrintLists() | |
62 bsk:PrintTable(bsk.lists) | |
63 end | |
64 function bsk:PrintChanges() | |
65 bsk:PrintTable(bsk.db.profile.changes) | |
66 end | |
67 function bsk:PrintPlayers() | |
68 bsk:PrintTable(bsk.players) | |
69 end | |
70 --}}} | 70 --}}} |
71 | 71 |
72 function bsk:CreateWorkingStateFromChanges() | 72 function bsk:CreateWorkingStateFromChanges() |
73 local playerBase = self.db.profile.players | 73 local playerBase = self.db.profile.players |
74 local listBase = self.db.profile.listBase | 74 local listBase = self.db.profile.listBase |
157 bsk:PrintTable(change) | 157 bsk:PrintTable(change) |
158 assert(false) | 158 assert(false) |
159 end | 159 end |
160 end | 160 end |
161 | 161 |
162 | 162 -- Action and DoAction defs {{{ |
163 -- | 163 -- |
164 -- The actual actions for changes start here | 164 -- The actual actions for changes start here |
165 -- | 165 -- |
166 -- Each action occurs as a pair of functions. The bsk:Action() function is from | 166 -- Each action occurs as a pair of functions. The bsk:Action() function is from |
167 -- a list admin's point of view. Each will check for admin status, then create a | 167 -- a list admin's point of view. Each will check for admin status, then create a |
212 if bsk:DoAddPlayer(change) then | 212 if bsk:DoAddPlayer(change) then |
213 bsk:CreateChange(change) | 213 bsk:CreateChange(change) |
214 end | 214 end |
215 end | 215 end |
216 | 216 |
217 function bsk:CreateFakeLists() | |
218 -- testing only | |
219 end | |
220 | |
221 function bsk:DoCreateList(change) | 217 function bsk:DoCreateList(change) |
222 -- TODO: this segment will probably be useful as bsk:SearchForListByName | 218 -- TODO: this segment will probably be useful as bsk:SearchForListByName |
223 local lists = bsk.lists | 219 local lists = bsk.lists |
224 for i,v in pairs(lists) do | 220 for i,v in pairs(lists) do |
225 if v.name == change.arg.name then | 221 if v.name == change.arg.name then |
272 -- return true | 268 -- return true |
273 end | 269 end |
274 | 270 |
275 function bsk:RemovePlayer(name) | 271 function bsk:RemovePlayer(name) |
276 -- from both players and lists | 272 -- from both players and lists |
277 end | |
278 | |
279 function bsk:GetSuicideList(name,list) | |
280 --self:Print("Calculating changeset for "..name.." from list -") | |
281 --self:PrintTable(list) | |
282 local t = {} | |
283 local ret = {} | |
284 local pushing = false | |
285 for i = 1, #list do | |
286 if list[i] == name then | |
287 pushing = true | |
288 end | |
289 if pushing and (RaidList[list[i]] or ReserveList[list[i]]) then | |
290 tinsert(ret,list[i]) | |
291 end | |
292 end | |
293 return ret | |
294 end | |
295 | |
296 function bsk:GetActiveList() | |
297 return bsk.lists[1] -- todo! | |
298 end | 273 end |
299 | 274 |
300 function bsk:DoSuicidePlayer(change) | 275 function bsk:DoSuicidePlayer(change) |
301 local listIndex = change.arg.listIndex | 276 local listIndex = change.arg.listIndex |
302 local list = bsk.lists[listIndex] | 277 local list = bsk.lists[listIndex] |
322 return true | 297 return true |
323 end | 298 end |
324 | 299 |
325 function bsk:SuicidePlayer(name,list) | 300 function bsk:SuicidePlayer(name,list) |
326 -- require admin | 301 -- require admin |
327 local l=bsk:GetActiveList() | |
328 bsk:PopulateRaidList() | 302 bsk:PopulateRaidList() |
329 local slist=bsk:GetSuicideList(name,l) | |
330 local listIndex = bsk:GetListIndex(list) | 303 local listIndex = bsk:GetListIndex(list) |
304 local slist=bsk:GetSuicideList(name,bsk.lists[listIndex]) | |
331 local change = {action="SuicidePlayer",arg={names=names,list=slist,listIndex=listIndex}} | 305 local change = {action="SuicidePlayer",arg={names=names,list=slist,listIndex=listIndex}} |
332 bsk:StartChange(change) | 306 bsk:StartChange(change) |
333 if bsk:DoSuicidePlayer(change) then | 307 if bsk:DoSuicidePlayer(change) then |
334 bsk:CommitChange(change) | 308 bsk:CommitChange(change) |
335 end | 309 end |
336 end | 310 end |
311 --}}} | |
312 -- Higher order actions (ie calls other Doers){{{ | |
313 function bsk:AddMissingPlayers() | |
314 bsk:PopulateRaidList() | |
315 local t = {} | |
316 for i,v in pairs(bsk.players) do | |
317 t[v] = true | |
318 end | |
319 for i,v in pairs(RaidList) do | |
320 if t[v] == nil then | |
321 bsk:Print(sformat("Player % is missing from the players list - adding",v)) | |
322 bsk:AddPlayer(v) | |
323 end | |
324 end | |
325 -- TODO: batch into a single op - no need to spam 25 messages in a row | |
326 end | |
327 --}}} | |
328 | |
329 -- "Soft" actions- ie things that cause nonpermanent state {{{ | |
330 | |
331 -- reserves | |
332 function bsk:AddReserve(name) | |
333 ReserveList[name]=true | |
334 -- TODO: communicate to others. don't store this in any way. | |
335 end | |
336 | |
337 function bsk:RemoveReserve(name) | |
338 ReserveList[name]=false | |
339 -- TODO: communicate to others. don't store this in any way. | |
340 end | |
341 | |
342 | |
343 --function bsk:GetActiveList() | |
344 -- return bsk.lists[1] -- todo! | |
345 --end | |
346 | |
347 --}}} | |
337 | 348 |
338 -- The following code is from Xinhuan (wowace forum member) | 349 -- The following code is from Xinhuan (wowace forum member) |
339 -- Pre-create the unitID strings we will use | 350 -- Pre-create the unitID strings we will use |
340 local pID = {} | 351 local pID = {} |
341 local rID = {} | 352 local rID = {} |
373 -- just find A,B,C in the list and replace in order from the s message | 384 -- just find A,B,C in the list and replace in order from the s message |
374 -- while undo is allowed *per-list*, certain events in the stream will | 385 -- while undo is allowed *per-list*, certain events in the stream will |
375 -- prevent proper undo, such as add/delete player or add/delete list | 386 -- prevent proper undo, such as add/delete player or add/delete list |
376 | 387 |
377 | 388 |
378 | 389 function bsk:GetSuicideList(name,list) |
379 | 390 --self:Print("Calculating changeset for "..name.." from list -") |
380 -- reserves | 391 --self:PrintTable(list) |
381 function bsk:AddReserve(name) | 392 local t = {} |
382 ReserveList[name]=true | 393 local ret = {} |
383 -- TODO: communicate to others. don't store this in any way. | 394 local pushing = false |
384 end | 395 for i = 1, #list do |
385 | 396 if list[i] == name then |
386 function bsk:RemoveReserve(name) | 397 pushing = true |
387 ReserveList[name]=false | 398 end |
388 -- TODO: communicate to others. don't store this in any way. | 399 if pushing and (RaidList[list[i]] or ReserveList[list[i]]) then |
389 end | 400 tinsert(ret,list[i]) |
390 | 401 end |
391 | 402 end |
392 | 403 return ret |
393 | 404 end |
394 | |
395 | |
396 | 405 |
397 | 406 |
398 | 407 |
399 -- Support functions | 408 -- Support functions |
400 | 409 |
404 return i | 413 return i |
405 end | 414 end |
406 end | 415 end |
407 assert(false) | 416 assert(false) |
408 end | 417 end |
418 |